-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mbwhite <[email protected]>
- Loading branch information
Showing
12 changed files
with
575 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Tekton Lint custom rules | ||
|
||
- Create a regular node module | ||
- Default export from this of an object | ||
```js | ||
module.exports = { | ||
rules: [ | ||
{ | ||
name: 'no-tasks-called-task', | ||
reportDefault: 'error', | ||
ruleFn: forbidTasksWithTaskInTheName | ||
} | ||
] | ||
} | ||
``` | ||
- Must contain a field called `rules` that is a array of objects | ||
- Each 'rule' object, must hava name (kebab case preferred) | ||
- Default report type (off/error/warning) | ||
- Reference to the rules function | ||
|
||
- Rules are implemented in a function | ||
|
||
```js | ||
// Example rule to check a name of a task, note this isn't meant | ||
// to be a serious rule - rather as an example | ||
const forbidTasksWithTaskInTheName = (docs, tekton, report) => { | ||
|
||
// try to always code defensively | ||
if (tekton.tasks) { | ||
for (const t of Object.values(tekton.tasks)) { | ||
if (t.metadata.name.startsWith("Task")) { | ||
report("Tasks should not start with word 'Task'", t) | ||
} | ||
} | ||
} | ||
}; | ||
``` | ||
|
||
- `docs` are the full yaml docs | ||
- `tekton` is the object with the parsed elements of the yaml files | ||
- `report` is a fn to report rule breaks | ||
|
||
|
||
## Development Notes: | ||
|
||
- As well as the yaml files from the project being tested, the rule will also see the cached elements | ||
- try and code as defensively as possible, eg a set of files might not have Tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
// Example rule to check a name of a task, note this isn't meant | ||
// to be a serious rule - rather as an example | ||
const forbidTasksWithTaskInTheName = (docs, tekton, report) => { | ||
|
||
// try to always code defensively | ||
if (tekton.tasks) { | ||
for (const t of Object.values(tekton.tasks)) { | ||
if (t.metadata.name.startsWith("Task")) { | ||
report("Tasks should not start with word 'Task'", t) | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// could export multiple rules if you wished here. | ||
module.exports = { | ||
rules: [ | ||
{ | ||
name: 'no-tasks-called-task', | ||
reportDefault: 'error', | ||
ruleFn: forbidTasksWithTaskInTheName | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "custom_rules", | ||
"version": "1.0.0", | ||
"description": "Example of a custom rule", | ||
"main": "my_rules.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.