eslint-plugin-woodpecker 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -2
- package/package.json +5 -9
- package/src/rules/require-event-filter.js +7 -6
- package/src/rules/shellcheck-commands.js +2 -1
- package/src/utils/init.js +9 -12
- package/src/utils/yaml.js +62 -0
package/README.md
CHANGED
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
<img alt="[Latest Build]" src="https://img.shields.io/npm/v/eslint-plugin-woodpecker?logo=icinga&style=for-the-badge&label=Latest%20Build&color=32fcee"></a>
|
|
7
7
|
<a href="https://codeberg.org/adamlui/eslint-plugin-woodpecker/src/branch/main/docs/LICENSE.md">
|
|
8
8
|
<img alt="[License: MIT]" src="https://img.shields.io/badge/License-MIT-f1f20a.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
9
|
+
<a target="_blank" href="https://getnpmstats.com/?package=eslint-plugin-woodpecker&range=last-year&interval=monthly">
|
|
10
|
+
<img alt="[Monthly npm downloads]" src="https://img.shields.io/npm/dm/eslint-plugin-woodpecker?style=for-the-badge&logo=npm&color=black"></a>
|
|
9
11
|
<a target="_blank" href="https://eslint.org/">
|
|
10
12
|
<img alt="[Requires ESLint >=9.0.0]" src="https://img.shields.io/badge/Requires-ESLint_%3E%3D9.0.0-4B32C3?style=for-the-badge&logo=eslint"></a>
|
|
11
13
|
<br><br>
|
|
12
14
|
|
|
13
|
-
ESLint rules for Woodpecker CI (including shell commands).
|
|
15
|
+
ESLint rules for Woodpecker CI files (including shell commands).
|
|
14
16
|
|
|
15
17
|
<img src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-woodpecker/02a07386aa/assets/images/screenshots/vs-code/squiggles.png">
|
|
16
18
|
|
|
@@ -66,6 +68,28 @@ export default [
|
|
|
66
68
|
|
|
67
69
|
---
|
|
68
70
|
|
|
71
|
+
<h2 id="disabling-rules">
|
|
72
|
+
<img height=25 width=25 align="top" src="https://api.iconify.design/mdi/cancel.svg?color=%232b2b2a">
|
|
73
|
+
Disabling rules
|
|
74
|
+
</h2>
|
|
75
|
+
|
|
76
|
+
Aside from editing `eslint.config.*js`, rules can also be disabled via <a target="_blank" href="https://eslint.org/docs/latest/use/configure/rules#disable-rules">standard ESLint directives</a> within Woodpecker YAML itself using `#` comments:
|
|
77
|
+
|
|
78
|
+
```yaml
|
|
79
|
+
# eslint-disable woodpecker/require-event-filter
|
|
80
|
+
|
|
81
|
+
steps:
|
|
82
|
+
- name: pre-commit
|
|
83
|
+
image: node:26.13.0-alpine@sha256:8996bb5821d62a8fd9bb27c1cb07462f3fdce6e47d640c6a881ead0b064ce216
|
|
84
|
+
commands: # eslint-disable-next-line woodpecker/shellcheck-commands -- `APK_DEPS` unquoted to force multi args
|
|
85
|
+
- apk add --no-cache $${APK_DEPS}
|
|
86
|
+
- pip install --no-cache-dir --break-system-packages -r requirements-dev.txt
|
|
87
|
+
- npm ci --ignore-scripts --no-audit
|
|
88
|
+
- npm run lint:all
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
69
93
|
<h2 id="supported-rules">
|
|
70
94
|
<img height=30 width=27 align="top" src="https://api.iconify.design/mdi/format-list-checks.svg?color=%232b2b2a">
|
|
71
95
|
Supported rules
|
|
@@ -160,7 +184,7 @@ If you intentionally duplicate step names.
|
|
|
160
184
|
|
|
161
185
|
#### When not to use it
|
|
162
186
|
|
|
163
|
-
If you intentionally trigger your pipeline on every event
|
|
187
|
+
If you intentionally trigger your pipeline on every event.
|
|
164
188
|
|
|
165
189
|
#### Introduced in
|
|
166
190
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-woodpecker",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "ESLint rules for Woodpecker CI (including shell commands)",
|
|
3
|
+
"version": "1.1.6",
|
|
4
|
+
"description": "ESLint rules for Woodpecker CI files (including shell commands)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
7
7
|
"eslint",
|
|
@@ -92,16 +92,12 @@
|
|
|
92
92
|
"eslint-plugin-regexp": "^3.3.3",
|
|
93
93
|
"eslint-plugin-security": "^4.2.1",
|
|
94
94
|
"eslint-plugin-sonarjs": "^4.2.2",
|
|
95
|
-
"
|
|
96
|
-
"oxlint": "^1.91.0",
|
|
95
|
+
"oxlint": "^1.92.0",
|
|
97
96
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
98
|
-
"typescript-latest": "npm:typescript@^7.0.2"
|
|
99
|
-
"yaml-eslint-parser": "^2.1.0"
|
|
97
|
+
"typescript-latest": "npm:typescript@^7.0.2"
|
|
100
98
|
},
|
|
101
99
|
"peerDependencies": {
|
|
102
|
-
"eslint": ">=9.0.0"
|
|
103
|
-
"eslint-plugin-yml": ">=1.14.0",
|
|
104
|
-
"yaml-eslint-parser": ">=1.2.3"
|
|
100
|
+
"eslint": ">=9.0.0"
|
|
105
101
|
},
|
|
106
102
|
"engines": {
|
|
107
103
|
"node": ">=18.18.0"
|
|
@@ -11,8 +11,8 @@ export default {
|
|
|
11
11
|
},
|
|
12
12
|
schema: [],
|
|
13
13
|
messages: {
|
|
14
|
-
noEventFilter: '
|
|
15
|
-
+ '
|
|
14
|
+
noEventFilter: '`when.event` filter missing at top level and from at least one step. '
|
|
15
|
+
+ 'Uncovered steps will run on every event.'
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
|
|
@@ -21,10 +21,11 @@ export default {
|
|
|
21
21
|
if (!filename || !regex.filename.woodpecker.test(filename)) return {}
|
|
22
22
|
return {
|
|
23
23
|
'Program:exit'() {
|
|
24
|
-
const parsed = woodpecker.parse(context.sourceCode.text)
|
|
25
|
-
if (woodpecker.getWhen(parsed.data.when)) return
|
|
26
|
-
const
|
|
27
|
-
|
|
24
|
+
const parsed = woodpecker.parse(context.sourceCode.text)
|
|
25
|
+
if (!parsed || woodpecker.getWhen(parsed.data.when)) return
|
|
26
|
+
const steps = woodpecker.getSteps(parsed),
|
|
27
|
+
allStepsFiltered = steps.length > 0 && steps.every(step => woodpecker.getWhen(step.node.when))
|
|
28
|
+
if (allStepsFiltered) return
|
|
28
29
|
const loc = woodpecker.getLocation(parsed, ['steps']) || { line: 1, column: 1 }
|
|
29
30
|
context.report({ loc, messageId: 'noEventFilter' })
|
|
30
31
|
}
|
|
@@ -62,7 +62,8 @@ export default {
|
|
|
62
62
|
for (let i = 0 ; i < cmds.length ; i++) {
|
|
63
63
|
const cmd = cmds[i] // oxlint-disable-line security/detect-object-injection
|
|
64
64
|
if (typeof cmd != 'string') continue
|
|
65
|
-
const
|
|
65
|
+
const shellCmd = cmd.replaceAll('$$', '$')
|
|
66
|
+
const comments = shellcheck.run(shellCmd, options) ; if (!comments) continue
|
|
66
67
|
for (const cmt of comments) {
|
|
67
68
|
const loc = woodpecker.getLocation(parsed, [...step.path, 'commands', i])
|
|
68
69
|
|| woodpecker.getLocation(parsed, step.path)
|
package/src/utils/init.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import pkg from './pkg.js'
|
|
2
2
|
import rulesUtils from './rules.js'
|
|
3
|
-
import
|
|
4
|
-
import yml from 'eslint-plugin-yml'
|
|
3
|
+
import yaml from './yaml.js'
|
|
5
4
|
|
|
6
5
|
import noDuplicateStepNames from '../rules/no-duplicate-step-names.js'
|
|
7
6
|
import requireEventFilter from '../rules/require-event-filter.js'
|
|
@@ -10,19 +9,17 @@ import validDependsOn from '../rules/valid-depends-on.js'
|
|
|
10
9
|
import validSchema from '../rules/valid-schema.js'
|
|
11
10
|
|
|
12
11
|
const pkgName = pkg.getName(),
|
|
13
|
-
namespace = pkgName.replace(/^@[^/]+\//, '').replace(/^eslint-plugin-/, '')
|
|
14
|
-
yamlFiles = ['**/.woodpecker.yml', '**/.woodpecker.yaml', '**/.woodpecker/*.yml', '**/.woodpecker/*.yaml'],
|
|
15
|
-
yamlParser = yamlParserMod.default || yamlParserMod // eslint-disable-line import-x/namespace
|
|
12
|
+
namespace = pkgName.replace(/^@[^/]+\//, '').replace(/^eslint-plugin-/, '')
|
|
16
13
|
|
|
17
14
|
export default {
|
|
18
15
|
configs(plugin) {
|
|
19
|
-
const rules = plugin.rules
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
const rules = plugin.rules
|
|
17
|
+
const make = (predicate, extraRules = {}) => ({
|
|
18
|
+
files: ['.woodpecker.{yml,yaml}', '.woodpecker/*.{yml,yaml}'],
|
|
19
|
+
plugins: { [namespace]: plugin },
|
|
20
|
+
languageOptions: { parser: yaml.parser },
|
|
21
|
+
rules: { ...extraRules, ...rulesUtils.bundle(rules, predicate, namespace) }
|
|
22
|
+
})
|
|
26
23
|
plugin.configs = {
|
|
27
24
|
recommended: make(rule => rule.meta.docs.recommended),
|
|
28
25
|
strict: make(() => true),
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isMap, isSeq, LineCounter, parseDocument } from 'yaml'
|
|
2
|
+
import pkg from './pkg.js'
|
|
3
|
+
|
|
4
|
+
function extractComments(text) {
|
|
5
|
+
const lineCounter = new LineCounter(),
|
|
6
|
+
commentTexts = [],
|
|
7
|
+
doc = parseDocument(text, { lineCounter })
|
|
8
|
+
|
|
9
|
+
if (doc.errors.length) {
|
|
10
|
+
const err = doc.errors[0],
|
|
11
|
+
error = new Error(err.message)
|
|
12
|
+
error.lineNumber = err.linePos?.[0]?.line ?? 1
|
|
13
|
+
error.column = (err.linePos?.[0]?.col ?? 1) -1
|
|
14
|
+
throw error
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
;(function walk(node) {
|
|
18
|
+
if (!node) return
|
|
19
|
+
for (const comment of [node.commentBefore, node.comment])
|
|
20
|
+
if (typeof comment == 'string')
|
|
21
|
+
for (const line of comment.split('\n'))
|
|
22
|
+
if (line.trim()) commentTexts.push(line)
|
|
23
|
+
if (node.contents) walk(node.contents)
|
|
24
|
+
if (isMap(node)) for (const { key, value } of node.items) { walk(key) ; walk(value) }
|
|
25
|
+
else if (isSeq(node)) for (const item of node.items) walk(item)
|
|
26
|
+
})(doc)
|
|
27
|
+
|
|
28
|
+
const comments = [] ; let cursor = 0
|
|
29
|
+
for (const commentText of commentTexts) {
|
|
30
|
+
const needle = `#${commentText}`
|
|
31
|
+
let idx = text.indexOf(needle, cursor)
|
|
32
|
+
while (idx > 0 && !' \t\n\r'.includes(text[idx -1]))
|
|
33
|
+
idx = text.indexOf(needle, idx +1)
|
|
34
|
+
if (idx < 0) continue
|
|
35
|
+
cursor = idx + needle.length
|
|
36
|
+
const start = lineCounter.linePos(idx),
|
|
37
|
+
end = lineCounter.linePos(idx + needle.length)
|
|
38
|
+
comments.push({
|
|
39
|
+
type: 'Block', value: commentText,
|
|
40
|
+
range: [idx, idx + needle.length],
|
|
41
|
+
loc: { start: { line: start.line, column: start.col -1 },
|
|
42
|
+
end: { line: end.line, column: end.col -1 }}
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return comments.sort((a, b) => a.range[0] - b.range[0])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
parser: {
|
|
51
|
+
meta: { name: `${pkg.getName()}-yaml-parser`, version: '2026.11.10' },
|
|
52
|
+
parse: text => ({
|
|
53
|
+
type: 'Program',
|
|
54
|
+
body: [],
|
|
55
|
+
sourceType: 'module',
|
|
56
|
+
range: [0, text.length],
|
|
57
|
+
loc: { start: { line: 1, column: 0 }, end: { line: text.split('\n').length, column: 0 }},
|
|
58
|
+
tokens: [],
|
|
59
|
+
comments: extractComments(text)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|