eslint-plugin-stratified-design 0.5.0 → 0.5.2

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.
@@ -79,6 +79,7 @@ const reportHasProperLevelNumber = (context, options, rootDir, filePath) => {
79
79
  */
80
80
  return (node, modulePath) => {
81
81
  if (!options.useLevelNumber) return;
82
+ if (isNodeModule(rootDir)(modulePath)) return;
82
83
 
83
84
  const report = (messageId) =>
84
85
  reportError(context, rootDir, filePath)(node, messageId, modulePath);
@@ -98,16 +99,20 @@ const reportHasProperLevelNumber = (context, options, rootDir, filePath) => {
98
99
  return toPath(parent);
99
100
  })();
100
101
 
101
- const { moduleLevel, isInterfaceError } = (() => {
102
+ const { moduleLevel, isBarrierError } = (() => {
102
103
  const segments = toSegments(toRelative(parentPath, modulePath));
103
- const level = extractLevel(segments[1]);
104
+ const moduleLevel = extractLevel(segments[1]);
105
+ const isBarrierError =
106
+ segments.length === 2
107
+ ? false
108
+ : segments.some((seg) => extractLevel(seg) !== null);
104
109
  return {
105
- moduleLevel: level,
106
- isInterfaceError: segments.length > 2,
110
+ moduleLevel,
111
+ isBarrierError,
107
112
  };
108
113
  })();
109
114
 
110
- if (isInterfaceError) {
115
+ if (isBarrierError) {
111
116
  report("barrier");
112
117
  return FINISHED;
113
118
  }
@@ -184,12 +189,15 @@ const reportHasProperLevel = (
184
189
 
185
190
  const isNodeModulePath = isNodeModule(rootDir)(modulePath);
186
191
 
192
+ const moduleLevel = findLevel(modulePath);
193
+
187
194
  if (fileLevel === null) {
188
- if (!isNodeModulePath) report("not-registered:file");
195
+ if (moduleLevel !== null || !isNodeModulePath) {
196
+ report("not-registered:file");
197
+ }
189
198
  return FINISHED;
190
199
  }
191
200
 
192
- const moduleLevel = findLevel(modulePath);
193
201
  if (moduleLevel === null) {
194
202
  if (!isNodeModulePath) report("not-registered:module");
195
203
  return FINISHED;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-stratified-design",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "ESlint rules for stratified design",
5
5
  "keywords": [
6
6
  "eslint",
@@ -58,7 +58,7 @@ ruleTester.run("lower-level-imports", rule, {
58
58
  options: [{ structure, root: "./src", aliases: { "@/": "./src/" } }],
59
59
  },
60
60
  {
61
- code: "import { func } from 'node-module'",
61
+ code: "import { func } from 'other-node-module'",
62
62
  filename: "./src/otherLayerA.js",
63
63
  options: [{ structure, root: "./src" }],
64
64
  },
@@ -170,6 +170,35 @@ ruleTester.run("lower-level-imports", rule, {
170
170
  },
171
171
  ],
172
172
  },
173
+ {
174
+ code: "import { func } from 'other-node-module'",
175
+ filename: "./src/1 otherLayerA.js",
176
+ options: [{ structure, root: "./src", useLevelNumber: true }],
177
+ },
178
+ {
179
+ code: "import { func } from 'node-module'",
180
+ filename: "./src/layer2/subLayer1/1 layer.js",
181
+ options: [
182
+ {
183
+ structure,
184
+ root: "./src",
185
+ aliases: { "@/": "./src/" },
186
+ useLevelNumber: true,
187
+ },
188
+ ],
189
+ },
190
+ {
191
+ code: "import { func } from '@/layer1/subLayer2/sub'",
192
+ filename: "./src/layer1/subLayer1/1 layer.js",
193
+ options: [
194
+ {
195
+ structure,
196
+ root: "./src",
197
+ aliases: { "@/": "./src/" },
198
+ useLevelNumber: true,
199
+ },
200
+ ],
201
+ },
173
202
  ],
174
203
  invalid: [
175
204
  {
@@ -310,5 +339,16 @@ ruleTester.run("lower-level-imports", rule, {
310
339
  },
311
340
  ],
312
341
  },
342
+ {
343
+ code: "import { func } from 'node-module'",
344
+ filename: "./src/layer3/subLayer1/1 layer.js",
345
+ options: [{ structure, root: "./src", useLevelNumber: true }],
346
+ errors: [
347
+ {
348
+ messageId: "not-lower-level",
349
+ data: { module: "node-module", file: "./layer3/subLayer1/1 layer" },
350
+ },
351
+ ],
352
+ },
313
353
  ],
314
354
  });