@lvce-editor/eslint-plugin-github-actions 2.0.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/dist/index.js +164 -0
- package/package.json +13 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import * as parserYAML from 'yaml-eslint-parser';
|
|
2
|
+
import { getSourceCode } from 'eslint-compat-utils';
|
|
3
|
+
|
|
4
|
+
const config = {
|
|
5
|
+
ubuntu: ['ubuntu-24.04'],
|
|
6
|
+
macos: ['macos-15', 'macos-26'],
|
|
7
|
+
windows: ['windows-2025']
|
|
8
|
+
};
|
|
9
|
+
const platforms = {
|
|
10
|
+
windows: 'windows',
|
|
11
|
+
ubuntu: 'ubuntu',
|
|
12
|
+
macos: 'macos'
|
|
13
|
+
};
|
|
14
|
+
const actions = {
|
|
15
|
+
'actions/checkout': ['actions/checkout@v4'],
|
|
16
|
+
'actions/setup-node': ['actions/setup-node@v6'],
|
|
17
|
+
'actions/cache': ['actions/cache@v4']
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const isSupported = (actions, value) => {
|
|
21
|
+
return actions.includes(value);
|
|
22
|
+
};
|
|
23
|
+
const meta$1 = {
|
|
24
|
+
type: 'problem',
|
|
25
|
+
docs: {
|
|
26
|
+
description: 'Disallow unsupported action versions'
|
|
27
|
+
},
|
|
28
|
+
messages: {
|
|
29
|
+
unsupportedActionVersion: 'Unsupported action version: {{value}}'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const create$1 = context => {
|
|
33
|
+
const sourceCode = getSourceCode(context);
|
|
34
|
+
if (!sourceCode.parserServices?.isYAML) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
YAMLPair(node) {
|
|
39
|
+
if (node && node.type === 'YAMLPair' && node.key && typeof node.key === 'object' && 'type' in node.key && node.key.type === 'YAMLScalar' && typeof node.key.value === 'string' && node.value && typeof node.value === 'object' && 'type' in node.value && node.value.type === 'YAMLScalar' && typeof node.value.value === 'string') {
|
|
40
|
+
const nodeValue = node.value.value;
|
|
41
|
+
for (const [key, value] of Object.entries(actions)) {
|
|
42
|
+
if (nodeValue.startsWith(key) && !isSupported(value, nodeValue)) {
|
|
43
|
+
context.report({
|
|
44
|
+
node,
|
|
45
|
+
messageId: 'unsupportedActionVersion',
|
|
46
|
+
data: {
|
|
47
|
+
value: nodeValue
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const actionVersions = {
|
|
58
|
+
__proto__: null,
|
|
59
|
+
create: create$1,
|
|
60
|
+
meta: meta$1
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const parseVersion = (value, prefix) => {
|
|
64
|
+
return value;
|
|
65
|
+
};
|
|
66
|
+
const parseUbuntuVersion = value => {
|
|
67
|
+
return parseVersion(value);
|
|
68
|
+
};
|
|
69
|
+
const parseWindowsVersion = value => {
|
|
70
|
+
return parseVersion(value);
|
|
71
|
+
};
|
|
72
|
+
const parseMacosVersion = value => {
|
|
73
|
+
return parseVersion(value);
|
|
74
|
+
};
|
|
75
|
+
const isSupportedUbuntuVersion = version => {
|
|
76
|
+
return config.ubuntu.includes(version);
|
|
77
|
+
};
|
|
78
|
+
const isSupportedMacosversion = version => {
|
|
79
|
+
return config.macos.includes(version);
|
|
80
|
+
};
|
|
81
|
+
const isSupportedWindowsVersion = version => {
|
|
82
|
+
return config.windows.includes(version);
|
|
83
|
+
};
|
|
84
|
+
const meta = {
|
|
85
|
+
type: 'problem',
|
|
86
|
+
docs: {
|
|
87
|
+
description: 'Disallow unsupported ci versions'
|
|
88
|
+
},
|
|
89
|
+
messages: {
|
|
90
|
+
unsupportedCiVersion: 'Unsupported ci version: {{value}}'
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const create = context => {
|
|
94
|
+
const sourceCode = getSourceCode(context);
|
|
95
|
+
if (!sourceCode.parserServices?.isYAML) {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
const checks = [{
|
|
99
|
+
prefix: `${platforms.ubuntu}-`,
|
|
100
|
+
parseVersion: parseUbuntuVersion,
|
|
101
|
+
isSupported: isSupportedUbuntuVersion
|
|
102
|
+
}, {
|
|
103
|
+
prefix: `${platforms.macos}-`,
|
|
104
|
+
parseVersion: parseMacosVersion,
|
|
105
|
+
isSupported: isSupportedMacosversion
|
|
106
|
+
}, {
|
|
107
|
+
prefix: `${platforms.windows}-`,
|
|
108
|
+
parseVersion: parseWindowsVersion,
|
|
109
|
+
isSupported: isSupportedWindowsVersion
|
|
110
|
+
}];
|
|
111
|
+
return {
|
|
112
|
+
YAMLScalar(node) {
|
|
113
|
+
if (node && node.type === 'YAMLScalar' && typeof node.value === 'string') {
|
|
114
|
+
for (const check of checks) {
|
|
115
|
+
if (node.value.startsWith(check.prefix)) {
|
|
116
|
+
const version = check.parseVersion(node.value);
|
|
117
|
+
const isSupported = check.isSupported(version);
|
|
118
|
+
if (!isSupported) {
|
|
119
|
+
context.report({
|
|
120
|
+
node,
|
|
121
|
+
messageId: 'unsupportedCiVersion',
|
|
122
|
+
data: {
|
|
123
|
+
value: node.value
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const ciVersions = {
|
|
135
|
+
__proto__: null,
|
|
136
|
+
create,
|
|
137
|
+
meta
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const plugin = {
|
|
141
|
+
meta: {
|
|
142
|
+
name: 'github-actions',
|
|
143
|
+
version: '0.0.1'
|
|
144
|
+
},
|
|
145
|
+
rules: {
|
|
146
|
+
'ci-versions': ciVersions,
|
|
147
|
+
'action-versions': actionVersions
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const recommended = [{
|
|
151
|
+
plugins: {
|
|
152
|
+
'github-actions': plugin
|
|
153
|
+
},
|
|
154
|
+
files: ['**/.github/workflows/*.y?(a)ml'],
|
|
155
|
+
languageOptions: {
|
|
156
|
+
parser: parserYAML
|
|
157
|
+
},
|
|
158
|
+
rules: {
|
|
159
|
+
'github-actions/ci-versions': 'error',
|
|
160
|
+
'github-actions/action-versions': 'error'
|
|
161
|
+
}
|
|
162
|
+
}];
|
|
163
|
+
|
|
164
|
+
export { recommended as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lvce-editor/eslint-plugin-github-actions",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"description": "Lint github action workflows.",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"eslint-compat-utils": "0.6.5",
|
|
11
|
+
"yaml-eslint-parser": "1.3.0"
|
|
12
|
+
}
|
|
13
|
+
}
|