eslint-plugin-stratified-design 0.5.2 → 0.6.1-beta
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.
|
@@ -65,6 +65,20 @@ const createModulePath = (cwd, fileDir, aliases) => {
|
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @param {*} options
|
|
70
|
+
* @param {string} fileDor
|
|
71
|
+
* @param {string} modulePath
|
|
72
|
+
*/
|
|
73
|
+
const isFileIndexOfModule = (options, fileDir, filePath) => (modulePath) => {
|
|
74
|
+
if (!options.isIndexHighest || parsePath(filePath).name !== "index") {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const segments = toSegments(toRelative(fileDir, modulePath));
|
|
78
|
+
if (segments.length === 2 && segments[0] === ".") return true;
|
|
79
|
+
return false;
|
|
80
|
+
};
|
|
81
|
+
|
|
68
82
|
/**
|
|
69
83
|
* Report error about using `options.useLevelNumber`
|
|
70
84
|
* @param {import('eslint').Rule.RuleContext} context
|
|
@@ -222,6 +236,7 @@ module.exports = {
|
|
|
222
236
|
createRootDir,
|
|
223
237
|
parseFileSource,
|
|
224
238
|
createModulePath,
|
|
239
|
+
isFileIndexOfModule,
|
|
225
240
|
reportHasProperLevelNumber,
|
|
226
241
|
reportInSubDirOfFileDir,
|
|
227
242
|
reportHasProperLevel,
|
|
@@ -21,6 +21,7 @@ const {
|
|
|
21
21
|
parseFileSource,
|
|
22
22
|
createRootDir,
|
|
23
23
|
} = require("../helpers/lowerLevelImports/");
|
|
24
|
+
const { isFileIndexOfModule } = require("../helpers/lowerLevelImports/1 layer");
|
|
24
25
|
|
|
25
26
|
//------------------------------------------------------------------------------
|
|
26
27
|
// Rule Definition
|
|
@@ -89,6 +90,9 @@ module.exports = {
|
|
|
89
90
|
useLevelNumber: {
|
|
90
91
|
type: "boolean",
|
|
91
92
|
},
|
|
93
|
+
isIndexHighest: {
|
|
94
|
+
type: "boolean",
|
|
95
|
+
},
|
|
92
96
|
},
|
|
93
97
|
additionalProperties: false,
|
|
94
98
|
},
|
|
@@ -151,17 +155,31 @@ module.exports = {
|
|
|
151
155
|
filePath
|
|
152
156
|
);
|
|
153
157
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
const isFileIndex = isFileIndexOfModule(options, fileDir, filePath);
|
|
159
|
+
|
|
160
|
+
const report = (node) => {
|
|
161
|
+
if (isExcludedFile) return;
|
|
162
|
+
|
|
163
|
+
const modulePath = createModulePath(node.source.value);
|
|
157
164
|
|
|
158
|
-
|
|
165
|
+
if (isFileIndex(modulePath)) return;
|
|
159
166
|
|
|
160
|
-
|
|
167
|
+
if (reportHasProperLevelNumber(node, modulePath) === FINISHED) return;
|
|
161
168
|
|
|
162
|
-
|
|
169
|
+
if (reportInSubDirOfFileDir(node, modulePath) === FINISHED) return;
|
|
163
170
|
|
|
164
|
-
|
|
171
|
+
reportHasProperLevel(node, modulePath);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
ImportDeclaration(node) {
|
|
176
|
+
report(node);
|
|
177
|
+
},
|
|
178
|
+
ExportNamedDeclaration(node) {
|
|
179
|
+
if (node.source) report(node);
|
|
180
|
+
},
|
|
181
|
+
ExportAllDeclaration(node) {
|
|
182
|
+
if (node.source) report(node);
|
|
165
183
|
},
|
|
166
184
|
};
|
|
167
185
|
},
|
package/package.json
CHANGED
|
@@ -37,6 +37,21 @@ ruleTester.run("lower-level-imports", rule, {
|
|
|
37
37
|
filename: "./src/otherLayerA.js",
|
|
38
38
|
options: [{ structure, root: "./src" }],
|
|
39
39
|
},
|
|
40
|
+
{
|
|
41
|
+
code: "export { func } from './otherLayerB/otherSubLayer'",
|
|
42
|
+
filename: "./src/otherLayerA.js",
|
|
43
|
+
options: [{ structure, root: "./src" }],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
code: "export * from './otherLayerB/otherSubLayer'",
|
|
47
|
+
filename: "./src/otherLayerA.js",
|
|
48
|
+
options: [{ structure, root: "./src" }],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
code: "const func = () => null; export { func }; ",
|
|
52
|
+
filename: "./src/otherLayerA.js",
|
|
53
|
+
options: [{ structure, root: "./src" }],
|
|
54
|
+
},
|
|
40
55
|
{
|
|
41
56
|
code: "import { func } from '../layer1/subLayer2'",
|
|
42
57
|
filename: "./src/layer1/subLayer1.js",
|
|
@@ -199,6 +214,18 @@ ruleTester.run("lower-level-imports", rule, {
|
|
|
199
214
|
},
|
|
200
215
|
],
|
|
201
216
|
},
|
|
217
|
+
{
|
|
218
|
+
code: "import { func } from '@/other/file.js'",
|
|
219
|
+
filename: "./src/other/index.js",
|
|
220
|
+
options: [
|
|
221
|
+
{
|
|
222
|
+
structure,
|
|
223
|
+
root: "./src",
|
|
224
|
+
aliases: { "@/": "./src/" },
|
|
225
|
+
isIndexHighest: true,
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
},
|
|
202
229
|
],
|
|
203
230
|
invalid: [
|
|
204
231
|
{
|
|
@@ -212,6 +239,28 @@ ruleTester.run("lower-level-imports", rule, {
|
|
|
212
239
|
},
|
|
213
240
|
],
|
|
214
241
|
},
|
|
242
|
+
{
|
|
243
|
+
code: "export { func } from './otherLayerB'",
|
|
244
|
+
filename: "./src/otherLayerA.js",
|
|
245
|
+
options: [{ structure, root: "./src" }],
|
|
246
|
+
errors: [
|
|
247
|
+
{
|
|
248
|
+
messageId: "not-registered:file",
|
|
249
|
+
data: { module: "./otherLayerB", file: "./otherLayerA" },
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
code: "export * from './otherLayerB'",
|
|
255
|
+
filename: "./src/otherLayerA.js",
|
|
256
|
+
options: [{ structure, root: "./src" }],
|
|
257
|
+
errors: [
|
|
258
|
+
{
|
|
259
|
+
messageId: "not-registered:file",
|
|
260
|
+
data: { module: "./otherLayerB", file: "./otherLayerA" },
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
},
|
|
215
264
|
{
|
|
216
265
|
code: "import { func } from 'node-module'",
|
|
217
266
|
filename: "./src/layer3/subLayer1.js",
|
|
@@ -350,5 +399,22 @@ ruleTester.run("lower-level-imports", rule, {
|
|
|
350
399
|
},
|
|
351
400
|
],
|
|
352
401
|
},
|
|
402
|
+
{
|
|
403
|
+
code: "import { func } from '@/other/file.js'",
|
|
404
|
+
filename: "./src/other/index.js",
|
|
405
|
+
options: [
|
|
406
|
+
{
|
|
407
|
+
structure,
|
|
408
|
+
root: "./src",
|
|
409
|
+
aliases: { "@/": "./src/" },
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
errors: [
|
|
413
|
+
{
|
|
414
|
+
messageId: "not-registered:file",
|
|
415
|
+
data: { module: "./other/file.js", file: "./other/index" },
|
|
416
|
+
},
|
|
417
|
+
],
|
|
418
|
+
},
|
|
353
419
|
],
|
|
354
420
|
});
|