eslint-plugin-stratified-design 0.12.4 → 0.12.5

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.
@@ -142,7 +142,7 @@ The default is as follows:
142
142
  }
143
143
  ```
144
144
 
145
- Imported modules can be excluded from the rule (`lower-level-imports`) using the `excludeImports` option:
145
+ Imported modules are excluded from the rule (`lower-level-imports`) using the `excludeImports` option:
146
146
 
147
147
  ```json
148
148
  {
@@ -153,6 +153,18 @@ Imported modules can be excluded from the rule (`lower-level-imports`) using the
153
153
  }
154
154
  ```
155
155
 
156
+ Explicitly imported types are excluded using `ignoreType` option:
157
+
158
+ ```json
159
+ {
160
+ "stratified-design/stratified-imports": ["error", { "ignoreType": true }]
161
+ }
162
+ ```
163
+
164
+ ```js
165
+ import type { SomeType } from "./type"; // Explicitly imported types are excluded
166
+ ```
167
+
156
168
  ## Rule Details
157
169
 
158
170
  If a file structure is as follows:
@@ -87,7 +87,7 @@ The default configuration is as follows:
87
87
  }
88
88
  ```
89
89
 
90
- Imported modules can be excluded from the rule (`stratified-imports`) using the `excludeImports` option:
90
+ Imported modules are excluded from the rule (`stratified-imports`) using the `excludeImports` option:
91
91
 
92
92
  ```json
93
93
  {
@@ -98,6 +98,18 @@ Imported modules can be excluded from the rule (`stratified-imports`) using the
98
98
  }
99
99
  ```
100
100
 
101
+ Explicitly imported types are excluded using `ignoreType` option:
102
+
103
+ ```json
104
+ {
105
+ "stratified-design/stratified-imports": ["error", { "ignoreType": true }]
106
+ }
107
+ ```
108
+
109
+ ```js
110
+ import type { SomeType } from "./type"; // Explicitly imported types are excluded
111
+ ```
112
+
101
113
  ## Rule Details
102
114
 
103
115
  Consider the following folder structure:
@@ -98,6 +98,9 @@ module.exports = {
98
98
  isIndexHighest: {
99
99
  type: "boolean",
100
100
  },
101
+ ignoreType: {
102
+ type: "boolean",
103
+ },
101
104
  },
102
105
  additionalProperties: false,
103
106
  },
@@ -124,6 +127,7 @@ module.exports = {
124
127
  aliases: {},
125
128
  useLevelNumber: false,
126
129
  isIndexHighest: false,
130
+ ignoreType: false,
127
131
  ...(context.options[0] || {}),
128
132
  };
129
133
 
@@ -167,7 +171,7 @@ module.exports = {
167
171
  const isFileIndex = isFileIndexOfModule(options, fileDir, filePath);
168
172
 
169
173
  const report = (node) => {
170
- if (node.importKind === "type") return;
174
+ if (options.ignoreType && node.importKind === "type") return;
171
175
 
172
176
  if (isExcludedFile) return;
173
177
 
@@ -16,6 +16,16 @@ const helper = require("../helpers/stratifiedImports");
16
16
  // Rule Definition
17
17
  //------------------------------------------------------------------------------
18
18
 
19
+ /**
20
+ * @typedef {{
21
+ * aliases: Record<string, string>,
22
+ * exclude: string[],
23
+ * include: string[],
24
+ * excludeImports: string[],
25
+ * ignoreType: boolean,
26
+ * }} Options
27
+ */
28
+
19
29
  /** @type {import('eslint').Rule.RuleModule} */
20
30
  module.exports = {
21
31
  meta: {
@@ -49,6 +59,9 @@ module.exports = {
49
59
  type: "array",
50
60
  items: [{ type: "string" }],
51
61
  },
62
+ ignoreType: {
63
+ type: "boolean",
64
+ },
52
65
  },
53
66
  additionalProperties: false,
54
67
  },
@@ -64,10 +77,14 @@ module.exports = {
64
77
  },
65
78
  },
66
79
  create(context) {
80
+ /**
81
+ * @type {Options}
82
+ */
67
83
  const options = {
68
84
  exclude: ["**/*.{test,spec}.{js,ts,jsx,tsx}"],
69
85
  include: ["**/*.{js,ts,jsx,tsx}"],
70
86
  excludeImports: [],
87
+ ignoreType: false,
71
88
  aliases: {},
72
89
  ...(context.options[0] || {}),
73
90
  };
@@ -124,7 +141,7 @@ module.exports = {
124
141
  * @returns
125
142
  */
126
143
  const report = (node) => {
127
- if (node.importKind === "type") return;
144
+ if (options.ignoreType && node.importKind === "type") return;
128
145
 
129
146
  if (!isStructureValid) {
130
147
  reportError(node, "invalid-json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-stratified-design",
3
- "version": "0.12.4",
3
+ "version": "0.12.5",
4
4
  "description": "ESlint rules for stratified design",
5
5
  "keywords": [
6
6
  "eslint",
@@ -220,7 +220,7 @@ ruleTester.run("lower-level-imports", rule, {
220
220
  ],
221
221
  },
222
222
  {
223
- code: "import { func } from '@/other/file.js'",
223
+ code: "import { func } from '@/other/file'",
224
224
  filename: "./src/other/index.js",
225
225
  options: [
226
226
  {
@@ -239,7 +239,14 @@ ruleTester.run("lower-level-imports", rule, {
239
239
  {
240
240
  code: "import type { SomeType } from '@/layer2/subLayer2'",
241
241
  filename: "./src/layer1/subLayer2.js",
242
- options: [{ structure, root: "./src", aliases: { "@/": "./src/" } }],
242
+ options: [
243
+ {
244
+ structure,
245
+ root: "./src",
246
+ aliases: { "@/": "./src/" },
247
+ ignoreType: true,
248
+ },
249
+ ],
243
250
  },
244
251
  ],
245
252
  invalid: [
@@ -415,7 +422,7 @@ ruleTester.run("lower-level-imports", rule, {
415
422
  ],
416
423
  },
417
424
  {
418
- code: "import { func } from '@/other/file.js'",
425
+ code: "import { func } from '@/other/file'",
419
426
  filename: "./src/other/index.js",
420
427
  options: [
421
428
  {
@@ -427,7 +434,24 @@ ruleTester.run("lower-level-imports", rule, {
427
434
  errors: [
428
435
  {
429
436
  messageId: "not-registered:file",
430
- data: { module: "./other/file.js", file: "./other/index" },
437
+ data: { module: "./other/file", file: "./other/index" },
438
+ },
439
+ ],
440
+ },
441
+ {
442
+ code: "import type { SomeType } from '@/layer2/subLayer2'",
443
+ filename: "./src/layer1/subLayer2.js",
444
+ options: [
445
+ {
446
+ structure,
447
+ root: "./src",
448
+ aliases: { "@/": "./src/" },
449
+ },
450
+ ],
451
+ errors: [
452
+ {
453
+ messageId: "barrier",
454
+ data: { module: "./layer2/subLayer2", file: "./layer1/subLayer2" },
431
455
  },
432
456
  ],
433
457
  },
@@ -169,7 +169,7 @@ ruleTester.run("stratified-imports", rule, {
169
169
  {
170
170
  code: "import type { SomeType } from './layerA'",
171
171
  filename: "./mocked/stratified-imports/layerB.js",
172
- options: [],
172
+ options: [{ ignoreType: true }],
173
173
  },
174
174
  ],
175
175
  invalid: [
@@ -316,5 +316,15 @@ ruleTester.run("stratified-imports", rule, {
316
316
  },
317
317
  ],
318
318
  },
319
+ {
320
+ code: "import type { SomeType } from './layerA'",
321
+ filename: "./mocked/stratified-imports/layerB.js",
322
+ errors: [
323
+ {
324
+ messageId: "not-lower-level",
325
+ data: { module: "layerA", file: "layerB" },
326
+ },
327
+ ],
328
+ },
319
329
  ],
320
330
  });