@lvce-editor/eslint-plugin-devcontainer 18.15.1 → 18.16.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 +62 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import json from '@eslint/json';
|
|
2
|
-
import {
|
|
3
|
-
import { join } from 'node:path';
|
|
2
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
3
|
+
import { join, dirname } from 'node:path';
|
|
4
4
|
|
|
5
5
|
const isObjectNode = node => {
|
|
6
6
|
return node && node.type === 'Object';
|
|
@@ -30,7 +30,7 @@ const findMember = (node, name) => {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
const defaultAllowedImages = ['mcr.microsoft.com/devcontainers/javascript-node:24', 'mcr.microsoft.com/devcontainers/javascript-node:26'];
|
|
33
|
-
const meta$
|
|
33
|
+
const meta$4 = {
|
|
34
34
|
docs: {
|
|
35
35
|
description: 'Ensure that the devcontainer image is allowed'
|
|
36
36
|
},
|
|
@@ -61,7 +61,7 @@ const getAllowedImages = context => {
|
|
|
61
61
|
}
|
|
62
62
|
return defaultAllowedImages;
|
|
63
63
|
};
|
|
64
|
-
const create$
|
|
64
|
+
const create$4 = context => {
|
|
65
65
|
const allowedImages = new Set(getAllowedImages(context));
|
|
66
66
|
return {
|
|
67
67
|
Document(node) {
|
|
@@ -102,16 +102,16 @@ const create$3 = context => {
|
|
|
102
102
|
|
|
103
103
|
const allowedImage = {
|
|
104
104
|
__proto__: null,
|
|
105
|
-
create: create$
|
|
105
|
+
create: create$4,
|
|
106
106
|
defaultAllowedImages,
|
|
107
|
-
meta: meta$
|
|
107
|
+
meta: meta$4
|
|
108
108
|
};
|
|
109
109
|
|
|
110
110
|
// cspell:ignore moby
|
|
111
111
|
|
|
112
112
|
const dockerInDockerFeature = 'ghcr.io/devcontainers/features/docker-in-docker';
|
|
113
113
|
const expectedFeature = `${dockerInDockerFeature}:4`;
|
|
114
|
-
const meta$
|
|
114
|
+
const meta$3 = {
|
|
115
115
|
docs: {
|
|
116
116
|
description: 'Require docker-in-docker version 4 with moby disabled'
|
|
117
117
|
},
|
|
@@ -122,7 +122,7 @@ const meta$2 = {
|
|
|
122
122
|
schema: [],
|
|
123
123
|
type: 'problem'
|
|
124
124
|
};
|
|
125
|
-
const create$
|
|
125
|
+
const create$3 = context => {
|
|
126
126
|
return {
|
|
127
127
|
Document(node) {
|
|
128
128
|
const features = findMember(node.body, 'features');
|
|
@@ -156,6 +156,58 @@ const create$2 = context => {
|
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
const dockerInDocker = {
|
|
159
|
+
__proto__: null,
|
|
160
|
+
create: create$3,
|
|
161
|
+
meta: meta$3
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const nodeImagePattern = /^mcr\.microsoft\.com\/devcontainers\/javascript-node:(\d+)(?:\.|$)/u;
|
|
165
|
+
const nvmrcPattern = /^v?(\d+)(?:\.|$)/u;
|
|
166
|
+
const meta$2 = {
|
|
167
|
+
docs: {
|
|
168
|
+
description: 'Ensure that the devcontainer Node.js image major matches .nvmrc'
|
|
169
|
+
},
|
|
170
|
+
messages: {
|
|
171
|
+
nodeMajorMismatch: 'devcontainer image Node.js major ({{imageMajor}}) must match .nvmrc major ({{nvmrcMajor}})'
|
|
172
|
+
},
|
|
173
|
+
type: 'problem'
|
|
174
|
+
};
|
|
175
|
+
const getRepositoryRoot = filename => dirname(dirname(filename));
|
|
176
|
+
const readNvmrcMajor = filename => {
|
|
177
|
+
try {
|
|
178
|
+
const nvmrc = readFileSync(join(getRepositoryRoot(filename), '.nvmrc'), 'utf8').trim();
|
|
179
|
+
return nvmrc.match(nvmrcPattern)?.[1];
|
|
180
|
+
} catch {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const create$2 = context => {
|
|
185
|
+
return {
|
|
186
|
+
Document(node) {
|
|
187
|
+
if (!isObjectNode(node.body)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const image = findMember(node.body, 'image');
|
|
191
|
+
if (!image || !isStringNode(image.value)) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const imageMajor = image.value.value.match(nodeImagePattern)?.[1];
|
|
195
|
+
const nvmrcMajor = readNvmrcMajor(context.filename);
|
|
196
|
+
if (imageMajor && nvmrcMajor && imageMajor !== nvmrcMajor) {
|
|
197
|
+
context.report({
|
|
198
|
+
data: {
|
|
199
|
+
imageMajor,
|
|
200
|
+
nvmrcMajor
|
|
201
|
+
},
|
|
202
|
+
loc: image.value.loc,
|
|
203
|
+
messageId: 'nodeMajorMismatch'
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const nodeVersion = {
|
|
159
211
|
__proto__: null,
|
|
160
212
|
create: create$2,
|
|
161
213
|
meta: meta$2
|
|
@@ -320,6 +372,7 @@ const plugin = {
|
|
|
320
372
|
rules: {
|
|
321
373
|
'allowed-image': allowedImage,
|
|
322
374
|
'docker-in-docker': dockerInDocker,
|
|
375
|
+
'node-version': nodeVersion,
|
|
323
376
|
'post-create-command': postCreateCommand,
|
|
324
377
|
'require-desktop-lite-feature': requireDesktopLiteFeature
|
|
325
378
|
}
|
|
@@ -338,6 +391,7 @@ const recommended = [{
|
|
|
338
391
|
rules: {
|
|
339
392
|
'devcontainer/allowed-image': 'error',
|
|
340
393
|
'devcontainer/docker-in-docker': 'error',
|
|
394
|
+
'devcontainer/node-version': 'error',
|
|
341
395
|
'devcontainer/post-create-command': 'off',
|
|
342
396
|
'devcontainer/require-desktop-lite-feature': 'error'
|
|
343
397
|
}
|