eslint-plugin-woodpecker 1.0.1 → 1.1.0

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 CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ESLint rules for Woodpecker CI (including shell commands).
14
14
 
15
- <!-- Add VS Code squiggles screenshot here -->
15
+ <img src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-woodpecker/02a07386aa/assets/images/screenshots/vs-code/squiggles.png">
16
16
 
17
17
  ---
18
18
 
@@ -43,7 +43,7 @@ export default [
43
43
  ]
44
44
  ```
45
45
 
46
- Available bundles: `recommended`, `strict`, `problem` (deterministic bugs only)
46
+ Available bundles: `recommended`, `strict` (everything), `problem` (deterministic bugs only)
47
47
 
48
48
  **Note:** Rule config is either a severity string (`'off'`, `'warn'`, `'error'`) or an array `[severity, options]` when the rule accepts options:
49
49
 
@@ -54,9 +54,9 @@ import woodpecker from 'eslint-plugin-woodpecker'
54
54
  export default [
55
55
  // other configs
56
56
  {
57
- ...woodpecker.configs.recommended,
57
+ ...woodpecker.configs.strict,
58
58
  rules: {
59
- ...woodpecker.configs.recommended.rules,
59
+ ...woodpecker.configs.strict.rules,
60
60
  'woodpecker/require-event-filter': 'off', // selectively disable rule
61
61
  'woodpecker/shellcheck-commands': ['error', { ignoreCodes: ['SC2086'] }] // selectively tweak rule
62
62
  }
@@ -129,8 +129,8 @@ If you intentionally duplicate step names.
129
129
 
130
130
  <h3 id="require-event-filter">
131
131
  <code>require-event-filter</code>
132
- <a title="Only included in strict config" href="#usage">
133
- <img height=18 alt="[Strict only]" src="https://img.shields.io/badge/Strict_only-ff8c42?style=flat-square" align="middle"></a>
132
+ <a title="Included in recommended config" href="#usage">
133
+ <img height=18 alt="[Recommended]" src="https://img.shields.io/badge/Recommended-f1f20a?style=flat-square" align="middle"></a>
134
134
  <a title="Copy rule URL" target="_blank"
135
135
  href="https://copy-to-clipboard.onrender.com/copy/https%3A%2F%2Fcodeberg.org%2Fadamlui%2Feslint-plugin-woodpecker%2F%23require-event-filter">
136
136
  <img height=16 width=21 alt="[Copy rule URL]" src="https://api.iconify.design/mdi/content-copy.svg?color=%23cccccc" align="middle"></a>
@@ -186,6 +186,8 @@ If you intentionally trigger your pipeline on every event, or if you filter per-
186
186
  <img height=18 alt="[Strict only]" src="https://img.shields.io/badge/Strict_only-ff8c42?style=flat-square" align="middle"></a>
187
187
  <a title="Accepts array w/ options" href="#usage">
188
188
  <img height=18 alt="[Configurable]" src="https://img.shields.io/badge/Configurable-black?style=flat-square" align="middle"></a>
189
+ <a title="Uses 400+ ShellCheck rules" target="_blank" href="https://www.shellcheck.net/wiki/">
190
+ <img height=18 alt="[400+ rules]" src="https://img.shields.io/badge/400%2B_rules-3b5bdb?style=flat-square" align="middle"></a>
189
191
  <a title="Copy rule URL" target="_blank"
190
192
  href="https://copy-to-clipboard.onrender.com/copy/https%3A%2F%2Fcodeberg.org%2Fadamlui%2Feslint-plugin-woodpecker%2F%23shellcheck-commands">
191
193
  <img height=16 width=21 alt="[Copy rule URL]" src="https://api.iconify.design/mdi/content-copy.svg?color=%23cccccc" align="middle"></a>
@@ -225,7 +227,7 @@ If you intentionally trigger your pipeline on every event, or if you filter per-
225
227
 
226
228
  #### When not to use it
227
229
 
228
- If you don't have the ShellCheck binary installed, or you already run ShellCheck via separate hook.
230
+ If you don't have the ShellCheck binary installed, or you don't want shell linting.
229
231
 
230
232
  #### Introduced in
231
233
 
@@ -233,7 +235,7 @@ If you don't have the ShellCheck binary installed, or you already run ShellCheck
233
235
 
234
236
  #### See also
235
237
 
236
- - <img height=12 src="https://www.google.com/s2/favicons?domain=github.com&sz=64">&ensp;<a target="_blank" href="https://github.com/koalaman/shellcheck/wiki">ShellCheck — Wiki</a>
238
+ - <img height=12 src="https://www.google.com/s2/favicons?domain=shellcheck.net&sz=64">&ensp;<a target="_blank" href="https://www.shellcheck.net/wiki/">ShellCheck — Wiki</a>
237
239
 
238
240
  <div align="center">
239
241
 
@@ -378,8 +380,8 @@ If you use a modified schema.
378
380
 
379
381
  ## <img height=30 width=27 align="top" src="https://api.iconify.design/ic/baseline-account-balance.svg?color=%232b2b2a"> License
380
382
 
381
- <a target="_blank" href="https://codeberg.org/adamlui/eslint-plugin-woodpecker/src/branch/main/docs/LICENSE.md">
382
- <img height=80 src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-greasemonkey/9e820e5d51/assets/images/logos/mit-license/red-pixelated.png"></a>
383
+ <a href="https://codeberg.org/adamlui/eslint-plugin-woodpecker/src/branch/main/docs/LICENSE.md">
384
+ <img height=88 src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-chrome-extensions/d79e1db7e2/assets/images/banners/mit-license/banner.png"></a>
383
385
  <br><br>
384
386
 
385
387
  <details>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-woodpecker",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "ESLint rules for Woodpecker CI (including shell commands)",
5
5
  "keywords": [
6
6
  "ci",
@@ -53,10 +53,10 @@
53
53
  "bump:major": "bash utils/bump.sh major",
54
54
  "bump:minor": "bash utils/bump.sh minor",
55
55
  "bump:patch": "bash utils/bump.sh patch",
56
- "demo": "node demo/run.js",
56
+ "demo": "eslint demo",
57
57
  "lint": "pre-commit run",
58
58
  "lint:all": "pre-commit run --all-files",
59
- "test": "node tests/run.js"
59
+ "test": "node tests/run"
60
60
  },
61
61
  "dependencies": {
62
62
  "ajv": "^8.20.0",
@@ -64,12 +64,11 @@
64
64
  },
65
65
  "devDependencies": {
66
66
  "@e18e/eslint-plugin": "^0.8.1",
67
- "@eslint/js": "^10.0.1",
68
67
  "@eslint/json": "^2.1.1",
69
68
  "@eslint/markdown": "^7.5.1",
70
69
  "@stylistic/eslint-plugin": "^5.10.0",
71
- "eslint": "^10.12.0",
72
- "eslint-plugin-constructors": "^1.4.3",
70
+ "eslint": "^10.13.0",
71
+ "eslint-plugin-constructors": "^1.5.0",
73
72
  "eslint-plugin-eslint-plugin": "^7.6.2",
74
73
  "eslint-plugin-import-x": "^4.17.1",
75
74
  "eslint-plugin-n": "^18.4.1",
@@ -81,6 +80,7 @@
81
80
  "eslint-plugin-security": "^4.2.0",
82
81
  "eslint-plugin-yml": "^3.9.0",
83
82
  "globals": "^17.13.0",
83
+ "oxlint": "^1.88.0",
84
84
  "yaml-eslint-parser": "^2.1.0"
85
85
  },
86
86
  "peerDependencies": {
@@ -1,60 +1,392 @@
1
+ // https://raw.githubusercontent.com/woodpecker-ci/woodpecker/main/pipeline/frontend/yaml/linter/schema/schema.json
2
+
1
3
  export default {
4
+ title: 'Woodpecker CI configuration file',
2
5
  $schema: 'http://json-schema.org/draft-07/schema#',
3
- $id: 'https://woodpecker-ci.org/schema.json',
4
- title: 'Woodpecker CI configuration',
6
+ $id: 'https://raw.githubusercontent.com/woodpecker-ci/woodpecker/main/pipeline/frontend/yaml/linter/schema/schema.json',
7
+ description: 'Schema of a Woodpecker pipeline file. Read more: https://woodpecker-ci.org/docs/usage/workflow-syntax',
5
8
  type: 'object',
6
9
  required: ['steps'],
7
10
  additionalProperties: false,
8
11
  properties: {
9
- steps: {
12
+ // $schema: { type: 'string', format: 'uri' }, // to silence benign Ajv warning can't validate it
13
+ variables: { description: 'Use yaml aliases to define variables. Read more: https://woodpecker-ci.org/docs/usage/advanced-usage' },
14
+ clone: { $ref: '#/definitions/clone' },
15
+ skip_clone: { type: 'boolean' },
16
+ when: { $ref: '#/definitions/workflow_when' },
17
+ steps: { $ref: '#/definitions/step_list' },
18
+ services: { $ref: '#/definitions/services' },
19
+ workspace: { $ref: '#/definitions/workspace' },
20
+ matrix: { $ref: '#/definitions/matrix' },
21
+ labels: { $ref: '#/definitions/labels' },
22
+ depends_on: { $ref: '#/definitions/depends_on_list' },
23
+ concurrency: { $ref: '#/definitions/concurrency' },
24
+ runs_on: {
25
+ type: 'array',
26
+ description: 'Deprecated: use `when.status` instead. Read more: https://woodpecker-ci.org/docs/usage/workflows#flow-control',
27
+ minLength: 1,
28
+ items: { type: 'string' }
29
+ }
30
+ },
31
+ definitions: {
32
+ string_or_string_slice: {
33
+ oneOf: [
34
+ { type: 'array', minLength: 1, items: { type: 'string' } },
35
+ { type: 'string' }
36
+ ]
37
+ },
38
+ depends_on_item: {
39
+ oneOf: [
40
+ { type: 'string' },
41
+ {
42
+ type: 'object',
43
+ required: ['name'],
44
+ additionalProperties: false,
45
+ properties: {
46
+ name: { type: 'string' },
47
+ optional: { type: 'boolean', default: false }
48
+ }
49
+ }
50
+ ]
51
+ },
52
+ depends_on_list: {
53
+ oneOf: [
54
+ { type: 'string' },
55
+ { type: 'array', minLength: 1, items: { $ref: '#/definitions/depends_on_item' } }
56
+ ]
57
+ },
58
+ concurrency: {
59
+ oneOf: [
60
+ { type: 'integer', minimum: 1 },
61
+ {
62
+ type: 'object',
63
+ additionalProperties: false,
64
+ required: ['limit'],
65
+ properties: {
66
+ limit: { type: 'integer', minimum: 1 },
67
+ group: { type: 'string' }
68
+ }
69
+ }
70
+ ]
71
+ },
72
+ clone: {
10
73
  oneOf: [
11
- { type: 'array', items: { $ref: '#/definitions/step' }},
12
- { type: 'object', additionalProperties: { $ref: '#/definitions/step' }}
74
+ {
75
+ type: 'object',
76
+ additionalProperties: false,
77
+ properties: {
78
+ git: {
79
+ type: 'object',
80
+ properties: {
81
+ image: { $ref: '#/definitions/step_image' },
82
+ settings: { $ref: '#/definitions/clone_settings' }
83
+ }
84
+ }
85
+ }
86
+ },
87
+ { type: 'array', items: { $ref: '#/definitions/step' }, minLength: 1 }
88
+ ]
89
+ },
90
+ clone_settings: {
91
+ type: 'object',
92
+ properties: {
93
+ depth: { type: 'number' },
94
+ recursive: { type: 'boolean', default: false },
95
+ partial: { type: 'boolean' },
96
+ lfs: { type: 'boolean', default: true },
97
+ tags: { type: 'boolean' }
98
+ },
99
+ additionalProperties: { type: ['boolean', 'string', 'number', 'array', 'object'] }
100
+ },
101
+ step_list: {
102
+ oneOf: [
103
+ { type: 'object', additionalProperties: { $ref: '#/definitions/step' }, minProperties: 1 },
104
+ { type: 'array', items: { $ref: '#/definitions/step' }, minLength: 1 }
13
105
  ]
14
106
  },
15
107
  services: {
16
108
  oneOf: [
17
- { type: 'array', items: { $ref: '#/definitions/step' }},
18
- { type: 'object', additionalProperties: { $ref: '#/definitions/step' }}
109
+ { type: 'object', additionalProperties: { $ref: '#/definitions/step' }, minProperties: 1 },
110
+ { type: 'array', items: { $ref: '#/definitions/step' }, minLength: 1 }
19
111
  ]
20
112
  },
21
- when: { $ref: '#/definitions/when' },
22
- depends_on: { type: 'array', items: { type: 'string' }},
23
- clone: { type: 'object' },
24
- labels: { type: 'object' },
25
- matrix: { oneOf: [{ type: 'object' }, { type: 'array' }] },
26
- platform: { type: 'string' },
27
- variables: { type: 'object' },
28
- skip_clone: { type: 'boolean' }
29
- },
30
- definitions: {
113
+ workspace: {
114
+ type: 'object',
115
+ additionalProperties: false,
116
+ properties: {
117
+ base: { type: 'string' },
118
+ path: { type: 'string' }
119
+ }
120
+ },
121
+ matrix: {
122
+ oneOf: [
123
+ { type: 'object', additionalProperties: { type: ['boolean', 'string', 'number'] } },
124
+ { type: 'array' }
125
+ ]
126
+ },
127
+ labels: {
128
+ type: 'object',
129
+ additionalProperties: { type: 'string' }
130
+ },
131
+ workflow_when: {
132
+ oneOf: [
133
+ { type: 'array', minLength: 1, items: { $ref: '#/definitions/workflow_when_condition' } },
134
+ { $ref: '#/definitions/workflow_when_condition' }
135
+ ]
136
+ },
137
+ workflow_when_condition: {
138
+ type: 'object',
139
+ additionalProperties: false,
140
+ properties: {
141
+ repo: { $ref: '#/definitions/constraint_list' },
142
+ branch: { $ref: '#/definitions/constraint_list' },
143
+ event: { $ref: '#/definitions/event_constraint_list' },
144
+ ref: { $ref: '#/definitions/constraint_list' },
145
+ cron: { $ref: '#/definitions/constraint_list' },
146
+ status: {
147
+ oneOf: [
148
+ { type: 'array', minLength: 1, items: { type: 'string', enum: ['success', 'failure'] } },
149
+ { type: 'string', enum: ['success', 'failure'] }
150
+ ]
151
+ },
152
+ platform: { $ref: '#/definitions/constraint_list' },
153
+ instance: { $ref: '#/definitions/constraint_list' },
154
+ path: {
155
+ oneOf: [
156
+ { type: 'string' },
157
+ { type: 'array', items: { type: 'string' } },
158
+ {
159
+ type: 'object',
160
+ properties: {
161
+ include: { type: 'array', items: { type: 'string' } },
162
+ exclude: { type: 'array', items: { type: 'string' } },
163
+ ignore_message: { type: 'string' },
164
+ on_empty: { type: 'boolean' }
165
+ },
166
+ additionalProperties: false
167
+ }
168
+ ]
169
+ },
170
+ evaluate: { type: 'string' }
171
+ }
172
+ },
31
173
  step: {
174
+ anyOf: [
175
+ { $ref: '#/definitions/commands_step' },
176
+ { $ref: '#/definitions/plugin_step' }
177
+ ]
178
+ },
179
+ commands_step: {
32
180
  type: 'object',
181
+ additionalProperties: false,
33
182
  required: ['image'],
183
+ allOf: [
184
+ {
185
+ if: { properties: { detach: { const: true } } },
186
+ then: {}, // oxlint-disable-line unicorn/no-thenable
187
+ else: {
188
+ anyOf: [
189
+ { required: ['commands'] },
190
+ { required: ['entrypoint'] }
191
+ ]
192
+ }
193
+ }
194
+ ],
34
195
  properties: {
35
196
  name: { type: 'string' },
36
- image: { type: 'string' },
37
- commands: { type: 'array', items: { type: 'string' }},
38
- environment: { oneOf: [{ type: 'object' }, { type: 'array' }] },
39
- depends_on: { type: 'array', items: { type: 'string' }},
40
- when: { $ref: '#/definitions/when' },
41
- volumes: { type: 'array' },
42
- ports: { type: 'array' },
43
- pull: { enum: ['always', 'if-not-exists', 'never'] },
44
- privileged: { type: 'boolean' },
45
- settings: { type: 'object' },
46
- failure: { enum: ['fail', 'ignore'] }
197
+ image: { $ref: '#/definitions/step_image' },
198
+ privileged: { $ref: '#/definitions/step_privileged' },
199
+ pull: { $ref: '#/definitions/step_pull' },
200
+ commands: { $ref: '#/definitions/step_commands' },
201
+ environment: { $ref: '#/definitions/step_environment' },
202
+ directory: { $ref: '#/definitions/step_directory' },
203
+ when: { $ref: '#/definitions/step_when' },
204
+ volumes: { $ref: '#/definitions/step_volumes' },
205
+ depends_on: { $ref: '#/definitions/depends_on_list' },
206
+ detach: { type: 'boolean' },
207
+ failure: { type: 'string', enum: ['fail', 'ignore', 'cancel'], default: 'fail' },
208
+ backend_options: { $ref: '#/definitions/step_backend_options' },
209
+ entrypoint: { $ref: '#/definitions/step_entrypoint' },
210
+ dns: { $ref: '#/definitions/string_or_string_slice' },
211
+ dns_search: { $ref: '#/definitions/string_or_string_slice' }
47
212
  }
48
213
  },
49
- when: {
214
+ plugin_step: {
50
215
  type: 'object',
216
+ additionalProperties: false,
217
+ required: ['image'],
51
218
  properties: {
52
- event: { oneOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' }}] },
53
- branch: { oneOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' }}] },
54
- ref: { oneOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' }}] },
55
- status: { oneOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' }}] },
56
- platform: { oneOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' }}] },
57
- path: { oneOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' }}] }
219
+ name: { type: 'string' },
220
+ image: { $ref: '#/definitions/step_image' },
221
+ privileged: { $ref: '#/definitions/step_privileged' },
222
+ pull: { $ref: '#/definitions/step_pull' },
223
+ directory: { $ref: '#/definitions/step_directory' },
224
+ settings: { $ref: '#/definitions/step_settings' },
225
+ when: { $ref: '#/definitions/step_when' },
226
+ volumes: { $ref: '#/definitions/step_volumes' },
227
+ depends_on: { $ref: '#/definitions/depends_on_list' },
228
+ detach: { type: 'boolean' },
229
+ failure: { type: 'string', enum: ['fail', 'ignore'], default: 'fail' },
230
+ backend_options: { $ref: '#/definitions/step_backend_options' }
231
+ }
232
+ },
233
+ step_when: {
234
+ oneOf: [
235
+ { type: 'array', minLength: 1, items: { $ref: '#/definitions/step_when_condition' } },
236
+ { $ref: '#/definitions/step_when_condition' }
237
+ ]
238
+ },
239
+ step_when_condition: {
240
+ type: 'object',
241
+ additionalProperties: false,
242
+ properties: {
243
+ repo: { $ref: '#/definitions/constraint_list' },
244
+ branch: { $ref: '#/definitions/constraint_list' },
245
+ event: { $ref: '#/definitions/event_constraint_list' },
246
+ ref: { $ref: '#/definitions/constraint_list' },
247
+ cron: { $ref: '#/definitions/constraint_list' },
248
+ status: {
249
+ oneOf: [
250
+ { type: 'array', minLength: 1, items: { type: 'string', enum: ['success', 'failure'] } },
251
+ { type: 'string', enum: ['success', 'failure'] }
252
+ ]
253
+ },
254
+ platform: { $ref: '#/definitions/constraint_list' },
255
+ matrix: {
256
+ type: 'object',
257
+ additionalProperties: { type: ['boolean', 'string', 'number'] }
258
+ },
259
+ instance: { $ref: '#/definitions/constraint_list' },
260
+ path: {
261
+ oneOf: [
262
+ { type: 'string' },
263
+ { type: 'array', items: { type: 'string' } },
264
+ {
265
+ type: 'object',
266
+ properties: {
267
+ include: { type: 'array', items: { type: 'string' } },
268
+ exclude: { type: 'array', items: { type: 'string' } },
269
+ ignore_message: { type: 'string' },
270
+ on_empty: { type: 'boolean' }
271
+ },
272
+ additionalProperties: false
273
+ }
274
+ ]
275
+ },
276
+ evaluate: { type: 'string' }
277
+ }
278
+ },
279
+ event_enum: {
280
+ enum: [
281
+ 'push', 'pull_request', 'pull_request_closed', 'pull_request_metadata',
282
+ 'tag', 'deployment', 'cron', 'manual', 'release'
283
+ ]
284
+ },
285
+ event_constraint_list: {
286
+ oneOf: [
287
+ { $ref: '#/definitions/event_enum' },
288
+ { type: 'array', minLength: 1, items: { $ref: '#/definitions/event_enum' } }
289
+ ]
290
+ },
291
+ constraint_list: {
292
+ oneOf: [
293
+ { type: 'string' },
294
+ { type: 'array', minLength: 1, items: { type: 'string' } },
295
+ {
296
+ type: 'object',
297
+ additionalProperties: false,
298
+ properties: {
299
+ include: {
300
+ oneOf: [
301
+ { type: 'string' },
302
+ { type: 'array', minLength: 1, items: { type: 'string' } }
303
+ ]
304
+ },
305
+ exclude: {
306
+ oneOf: [
307
+ { type: 'string' },
308
+ { type: 'array', minLength: 1, items: { type: 'string' } }
309
+ ]
310
+ }
311
+ }
312
+ }
313
+ ]
314
+ },
315
+ step_image: { type: 'string' },
316
+ step_privileged: { type: 'boolean', default: false },
317
+ step_pull: { type: 'boolean' },
318
+ step_commands: {
319
+ oneOf: [
320
+ { type: 'array', items: { type: 'string' }, minLength: 1 },
321
+ { type: 'string' }
322
+ ]
323
+ },
324
+ step_environment: {
325
+ type: 'object',
326
+ additionalProperties: { type: ['boolean', 'string', 'number', 'array', 'object'] }
327
+ },
328
+ step_entrypoint: { $ref: '#/definitions/string_or_string_slice' },
329
+ step_settings: {
330
+ type: 'object',
331
+ additionalProperties: { type: ['boolean', 'string', 'number', 'array', 'object'] }
332
+ },
333
+ step_volumes: { type: 'array', items: { type: 'string' }, minLength: 1 },
334
+ step_directory: { type: 'string' },
335
+ step_backend_options: {
336
+ type: 'object',
337
+ properties: {
338
+ docker: { $ref: '#/definitions/step_backend_docker' },
339
+ kubernetes: { $ref: '#/definitions/step_backend_kubernetes' }
340
+ }
341
+ },
342
+ step_backend_docker: {
343
+ type: 'object',
344
+ properties: {
345
+ user: { type: 'string' }
346
+ }
347
+ },
348
+ step_backend_kubernetes: {
349
+ type: 'object',
350
+ properties: {
351
+ resources: { $ref: '#/definitions/step_backend_kubernetes_resources' },
352
+ labels: { type: 'object', additionalProperties: { type: ['boolean', 'string', 'number'] } },
353
+ annotations: { type: 'object', additionalProperties: { type: ['boolean', 'string', 'number'] } },
354
+ tolerations: { type: 'array', minLength: 1, items: { type: 'object' } },
355
+ securityContext: { $ref: '#/definitions/step_backend_kubernetes_security_context' },
356
+ runtimeClassName: { type: 'string' },
357
+ serviceAccountName: { type: 'string' },
358
+ workspaceVolume: { type: 'boolean' },
359
+ hostUsers: { type: 'boolean' },
360
+ nodeSelector: { type: 'object', additionalProperties: { type: 'string' } },
361
+ affinity: { type: 'object' },
362
+ secrets: { type: 'array', minLength: 1, items: { type: 'object' } }
363
+ }
364
+ },
365
+ step_backend_kubernetes_resources: {
366
+ type: 'object',
367
+ properties: {
368
+ requests: { type: 'object' },
369
+ limits: { type: 'object' }
370
+ }
371
+ },
372
+ step_backend_kubernetes_security_context: {
373
+ type: 'object',
374
+ properties: {
375
+ privileged: { type: 'boolean' },
376
+ runAsNonRoot: { type: 'boolean' },
377
+ runAsUser: { type: 'number' },
378
+ runAsGroup: { type: 'number' },
379
+ fsGroup: { type: 'number' },
380
+ fsGroupChangePolicy: { type: 'string' },
381
+ seccompProfile: { type: 'object' },
382
+ apparmorProfile: { type: 'object' },
383
+ allowPrivilegeEscalation: { type: 'boolean' },
384
+ capabilities: {
385
+ type: 'object',
386
+ properties: {
387
+ drop: { type: 'array', items: { type: 'string' } }
388
+ }
389
+ }
58
390
  }
59
391
  }
60
392
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ type RuleSeverity = 0 | 1 | 2 | 'off' | 'warn' | 'error'
2
+ type RuleSetting = RuleSeverity | [RuleSeverity, ...unknown[]]
3
+
4
+ type ConfigName =
5
+ | 'recommended'
6
+ | 'strict'
7
+ | 'problem'
8
+
9
+ interface PluginConfig {
10
+ files: string[]
11
+ plugins: Record<string, unknown>
12
+ languageOptions: Record<string, unknown>
13
+ rules: Record<string, RuleSetting>
14
+ }
15
+
16
+ interface PluginRule {
17
+ meta: {
18
+ type?: 'problem' | 'suggestion' | 'layout'
19
+ deprecated?: boolean | {
20
+ message?: string
21
+ replacedBy?: Array<{ rule: { name: string } }>
22
+ }
23
+ docs?: Record<string, unknown>
24
+ }
25
+ create: (context: unknown) => Record<string, (...args: unknown[]) => void>
26
+ }
27
+
28
+ declare const plugin: {
29
+ rules: Record<string, PluginRule>
30
+ configs: Record<ConfigName, PluginConfig>
31
+ }
32
+
33
+ export { plugin as default, plugin as woodpecker }
@@ -7,13 +7,10 @@ export default {
7
7
  docs: {
8
8
  description: 'Disallow duplicate step names',
9
9
  category: 'Possible Errors',
10
- recommended: true,
11
- yaml: true
10
+ recommended: true
12
11
  },
13
12
  schema: [],
14
- messages: {
15
- duplicate: 'Step name "{{name}}" is used more than once.'
16
- }
13
+ messages: { duplicate: 'Step name "{{name}}" is used more than once.' }
17
14
  },
18
15
 
19
16
  create(context) {
@@ -25,10 +22,12 @@ export default {
25
22
  const seen = new Set()
26
23
  for (const step of woodpecker.getSteps(parsed)) {
27
24
  if (!step.name) continue
28
- if (seen.has(step.name))
29
- context.report({ loc: { line: 1, column: 1 }, messageId: 'duplicate',
30
- data: { name: step.name }})
31
- else seen.add(step.name)
25
+ if (seen.has(step.name)) {
26
+ const loc = woodpecker.getLocation(parsed, [...step.path, 'name'])
27
+ || woodpecker.getLocation(parsed, step.path)
28
+ || { line: 1, column: 1 }
29
+ context.report({ loc, messageId: 'duplicate', data: { name: step.name }})
30
+ } else seen.add(step.name)
32
31
  }
33
32
  }
34
33
  }
@@ -7,8 +7,7 @@ export default {
7
7
  docs: {
8
8
  description: 'Require an `event` filter so the pipeline does not run on every event',
9
9
  category: 'Best Practices',
10
- recommended: false,
11
- yaml: true
10
+ recommended: true
12
11
  },
13
12
  schema: [],
14
13
  messages: {
@@ -26,7 +25,8 @@ export default {
26
25
  if (woodpecker.getWhen(parsed.data.when)) return
27
26
  const anyStepFiltered = woodpecker.getSteps(parsed).some(step => woodpecker.getWhen(step.node.when))
28
27
  if (anyStepFiltered) return
29
- context.report({ loc: { line: 1, column: 1 }, messageId: 'noEventFilter' })
28
+ const loc = woodpecker.getLocation(parsed, ['steps']) || { line: 1, column: 1 }
29
+ context.report({ loc, messageId: 'noEventFilter' })
30
30
  }
31
31
  }
32
32
  }
@@ -10,9 +10,7 @@ export default {
10
10
  type: 'problem',
11
11
  docs: {
12
12
  description: 'Run ShellCheck against every `commands:` entry',
13
- category: 'Possible Errors',
14
- recommended: false,
15
- yaml: true
13
+ category: 'Possible Errors'
16
14
  },
17
15
  schema: [{
18
16
  type: 'object',
@@ -58,14 +56,21 @@ export default {
58
56
  return {
59
57
  'Program:exit'() {
60
58
  const parsed = woodpecker.parse(context.sourceCode.text) ; if (!parsed) return
61
- for (const step of woodpecker.getSteps(parsed))
62
- for (const cmd of woodpecker.getStringArray(step.node.commands)) {
63
- const comments = shellcheck.run(cmd, opts)
64
- if (!comments) continue
65
- for (const c of comments)
66
- context.report({ loc: { line: 1, column: 1 }, messageId: 'finding',
67
- data: { code: `SC${c.code}`, message: c.message }})
59
+ for (const step of woodpecker.getSteps(parsed)) {
60
+ const cmds = Array.isArray(step.node.commands) ? step.node.commands : []
61
+ for (let i = 0 ; i < cmds.length ; i++) {
62
+ const cmd = cmds[i] // oxlint-disable-line security/detect-object-injection
63
+ if (typeof cmd != 'string') continue
64
+ const comments = shellcheck.run(cmd, opts) ; if (!comments) continue
65
+ for (const cmt of comments) {
66
+ const loc = woodpecker.getLocation(parsed, [...step.path, 'commands', i])
67
+ || woodpecker.getLocation(parsed, step.path)
68
+ || { line: 1, column: 1 }
69
+ context.report({ loc, messageId: 'finding',
70
+ data: { code: `SC${cmt.code}`, message: cmt.message }})
71
+ }
68
72
  }
73
+ }
69
74
  }
70
75
  }
71
76
  }
@@ -7,13 +7,10 @@ export default {
7
7
  docs: {
8
8
  description: 'Disallow `depends_on` entries referencing unknown step names',
9
9
  category: 'Possible Errors',
10
- recommended: true,
11
- yaml: true
10
+ recommended: true
12
11
  },
13
12
  schema: [],
14
- messages: {
15
- unknown: '`depends_on` references unknown step "{{name}}".'
16
- }
13
+ messages: { unknown: '`depends_on` references unknown step "{{name}}".' }
17
14
  },
18
15
 
19
16
  create(context) {
@@ -23,11 +20,19 @@ export default {
23
20
  'Program:exit'() {
24
21
  const parsed = woodpecker.parse(context.sourceCode.text) ; if (!parsed) return
25
22
  const steps = woodpecker.getSteps(parsed),
26
- knownNames = new Set(steps.map(s => s.name).filter(Boolean))
27
- for (const step of steps)
28
- for (const dep of woodpecker.getStringArray(step.node.depends_on))
29
- if (!knownNames.has(dep))
30
- context.report({ loc: { line: 1, column: 1 }, messageId: 'unknown', data: { name: dep }})
23
+ knownNames = new Set(steps.map(step => step.name).filter(Boolean))
24
+ for (const step of steps) {
25
+ const deps = Array.isArray(step.node.depends_on) ? step.node.depends_on : []
26
+ for (let i = 0 ; i < deps.length ; i++) {
27
+ const dep = deps[i] // oxlint-disable-line security/detect-object-injection
28
+ if (typeof dep != 'string' || knownNames.has(dep)) continue
29
+ const loc = woodpecker.getLocation(parsed, [...step.path, 'depends_on', i])
30
+ || woodpecker.getLocation(parsed, [...step.path, 'depends_on'])
31
+ || woodpecker.getLocation(parsed, step.path)
32
+ || { line: 1, column: 1 }
33
+ context.report({ loc, messageId: 'unknown', data: { name: dep }})
34
+ }
35
+ }
31
36
  }
32
37
  }
33
38
  }
@@ -9,13 +9,10 @@ export default {
9
9
  docs: {
10
10
  description: 'Validate `.woodpecker.yml` against the Woodpecker CI schema',
11
11
  category: 'Possible Errors',
12
- recommended: true,
13
- yaml: true
12
+ recommended: true
14
13
  },
15
14
  schema: [],
16
- messages: {
17
- invalid: 'Schema: {{message}} at `{{path}}`'
18
- }
15
+ messages: { invalid: 'Schema: {{message}} at `{{path}}`' }
19
16
  },
20
17
 
21
18
  create(context) {
@@ -23,15 +20,16 @@ export default {
23
20
  if (!filename || !regex.filename.woodpecker.test(filename)) return {}
24
21
  return {
25
22
  'Program:exit'() {
26
- const parsed = woodpecker.parse(context.sourceCode.text); if (!parsed) return
27
- if (Array.isArray(parsed.data.when))
28
- parsed.data.when = parsed.data.when.reduce((acc, item) => ({ ...acc, ...item }), {})
29
- const { valid, errors } = schemaUtils.validate(parsed.data); if (valid) return
30
- for (const err of errors)
31
- context.report({
32
- loc: { line: 1, column: 1 }, messageId: 'invalid',
33
- data: { path: err.instancePath || '(root)', message: err.message || 'invalid' }
34
- })
23
+ const parsed = woodpecker.parse(context.sourceCode.text) ; if (!parsed) return
24
+ const { valid, errors } = schemaUtils.validate(parsed.data) ; if (valid) return
25
+ const reported = new Set()
26
+ for (const err of errors) {
27
+ const path = err.instancePath || '(root)' ; if (reported.has(path)) continue
28
+ reported.add(path)
29
+ const segments = err.instancePath.split('/').filter(Boolean),
30
+ loc = woodpecker.getLocation(parsed, segments) || { line: 1, column: 1 }
31
+ context.report({ loc, messageId: 'invalid', data: { path, message: err.message || 'invalid' }})
32
+ }
35
33
  }
36
34
  }
37
35
  }
package/src/utils/init.js CHANGED
@@ -1,3 +1,4 @@
1
+ import pkg from './pkg.js'
1
2
  import rulesUtils from './rules.js'
2
3
  import * as yamlParserMod from 'yaml-eslint-parser'
3
4
  import yml from 'eslint-plugin-yml'
@@ -8,7 +9,8 @@ import shellcheckCommands from '../rules/shellcheck-commands.js'
8
9
  import validDependsOn from '../rules/valid-depends-on.js'
9
10
  import validSchema from '../rules/valid-schema.js'
10
11
 
11
- const namespace = 'woodpecker',
12
+ const pkgName = pkg.getName(),
13
+ namespace = pkgName.replace(/^@[^/]+\//, '').replace(/^eslint-plugin-/, ''),
12
14
  yamlFiles = ['**/.woodpecker.yml', '**/.woodpecker.yaml', '**/.woodpecker/*.yml', '**/.woodpecker/*.yaml'],
13
15
  yamlParser = yamlParserMod.default || yamlParserMod // eslint-disable-line import-x/namespace
14
16
 
@@ -28,7 +30,7 @@ export default {
28
30
  }
29
31
  },
30
32
 
31
- plugin() { return { rules: {}, configs: {} }},
33
+ plugin() { return { meta: { name: pkgName }, rules: {}, configs: {} }},
32
34
 
33
35
  rules(plugin) {
34
36
  plugin.rules = {
@@ -39,6 +41,6 @@ export default {
39
41
  'valid-schema': validSchema
40
42
  }
41
43
  for (const [ruleId, rule] of Object.entries(plugin.rules))
42
- rule.meta.docs.url = `https://codeberg.org/adamlui/eslint-plugin-${namespace}/#${ruleId}`
44
+ rule.meta.docs.url = `https://codeberg.org/adamlui/${pkgName}/#${ruleId}`
43
45
  }
44
46
  }
@@ -0,0 +1,23 @@
1
+ // oxlint-disable security/detect-non-literal-fs-filename
2
+
3
+ import { fileURLToPath } from 'node:url'
4
+ import fs from 'node:fs'
5
+ import path from 'node:path'
6
+
7
+ export default {
8
+ getName() {
9
+ let current = path.dirname(fileURLToPath(import.meta.url))
10
+ while (current) {
11
+ const pkgPath = path.join(current, 'package.json')
12
+ if (fs.existsSync(pkgPath))
13
+ try {
14
+ const { name } = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
15
+ if (name) return name
16
+ } catch { /* malformed, keep walking */ }
17
+ const parent = path.dirname(current)
18
+ if (parent === current) return null
19
+ current = parent
20
+ }
21
+ return null
22
+ }
23
+ }
@@ -1,8 +1,7 @@
1
1
  export default {
2
- bundle(rules, predicate, namespace) {
3
- const bundled = {}
4
- for (const [ruleId, rule] of Object.entries(rules))
5
- if (predicate(rule)) bundled[`${namespace}/${ruleId}`] = 'error'
6
- return bundled
2
+ bundle(rules, predicate, pluginName) {
3
+ return Object.fromEntries(Object.entries(rules)
4
+ .filter(([, rule]) => !rule.meta.deprecated && predicate(rule))
5
+ .map(([ruleId]) => [`${pluginName}/${ruleId}`, 'error']))
7
6
  }
8
7
  }
@@ -1,7 +1,7 @@
1
1
  import { execFileSync, spawnSync } from 'node:child_process'
2
2
 
3
3
  const re = { lineBreak: /\r?\n/ }
4
- let cachedPath = undefined
4
+ let cachedPath
5
5
 
6
6
  function which(bin) {
7
7
  try {
@@ -24,8 +24,7 @@ export default {
24
24
  const args = ['--format=json1']
25
25
  for (const code of opts.ignoreCodes || []) args.push(`--exclude=${code}`)
26
26
  for (const name of opts.enableChecks || []) args.push(`--enable=${name}`)
27
- args.push(`--shell=${opts.shell || 'sh'}`)
28
- args.push('-')
27
+ args.push(`--shell=${opts.shell || 'sh'}`, '-')
29
28
  const result = spawnSync(bin, args, { input: text, encoding: 'utf8', maxBuffer: 10 * 1024 * 1024 })
30
29
  if (result.error) return null
31
30
  if (result.status != 0 && result.status != 1) return null
@@ -1,4 +1,6 @@
1
- import { parseDocument, LineCounter } from 'yaml'
1
+ import { parseDocument, LineCounter, isMap, isSeq } from 'yaml'
2
+
3
+ const re = { digitsOnly: /^\d+$/ }
2
4
 
3
5
  export default {
4
6
  file: { getName(context) { return context.filename || context.getFilename?.() || '' }},
@@ -7,13 +9,15 @@ export default {
7
9
  const steps = parsed?.data?.steps ; if (!steps) return []
8
10
  const result = []
9
11
  if (Array.isArray(steps)) {
10
- for (const step of steps) {
12
+ for (let i = 0 ; i < steps.length ; i++) {
13
+ const step = steps[i] // oxlint-disable-line security/detect-object-injection
11
14
  if (!step || typeof step != 'object') continue
12
- result.push({ name: step.name, node: step })
15
+ result.push({ name: step.name, node: step, path: ['steps', i] })
13
16
  }
14
17
  } else if (typeof steps == 'object') {
15
18
  for (const [name, step] of Object.entries(steps))
16
- if (step && typeof step == 'object') result.push({ name, node: step })
19
+ if (step && typeof step == 'object')
20
+ result.push({ name, node: step, path: ['steps', name] })
17
21
  }
18
22
  return result
19
23
  },
@@ -23,10 +27,35 @@ export default {
23
27
  return value.filter(v => typeof v == 'string')
24
28
  },
25
29
 
26
- getWhen(value) {
27
- if (!value || typeof value != 'object') return null
28
- if (typeof value.event == 'string' || Array.isArray(value.event)) return value
29
- return null
30
+ getWhen(when) {
31
+ if (!when) return null
32
+ else if (Array.isArray(when)) return when.map(when => this.getWhen(when)).find(Boolean) || null
33
+ else if (typeof when != 'object') return null
34
+ else if (typeof when.event == 'string' || Array.isArray(when.event)) return when
35
+ else return null
36
+ },
37
+
38
+ getYamlNode(parsed, path = []) {
39
+ let node = parsed?.doc?.contents ; if (!node) return null
40
+ for (const key of path) {
41
+ if (isMap(node)) {
42
+ const pair = node.items.find(entry => String(entry?.key?.value) === String(key))
43
+ if (!pair) return null
44
+ node = pair.value
45
+ } else if (isSeq(node)) {
46
+ const idx = typeof key == 'number' ? key : re.digitsOnly.test(String(key)) ? Number(key) : NaN
47
+ if (!Number.isInteger(idx) || idx < 0 || idx >= node.items.length) return null
48
+ node = node.items[idx] // oxlint-disable-line security/detect-object-injection
49
+ } else return null
50
+ if (!node) return null
51
+ }
52
+ return node
53
+ },
54
+
55
+ getLocation(parsed, path) {
56
+ const node = this.getYamlNode(parsed, path) ; if (!node?.range) return null
57
+ const { line, col } = parsed.lineCounter.linePos(node.range[0])
58
+ return { line, column: col }
30
59
  },
31
60
 
32
61
  parse(text) {