eslint-plugin-stratified-design 0.11.0 → 0.12.1
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.
|
@@ -16,7 +16,7 @@ const { createAliases, fromCwd, match } = require("../helpers/common");
|
|
|
16
16
|
* @typedef {import('eslint').AST.Token} Token
|
|
17
17
|
* @typedef {import('eslint').SourceCode} SourceCode
|
|
18
18
|
* @typedef {{
|
|
19
|
-
* import: { member: string[], from: string },
|
|
19
|
+
* import: { member: '*' | string[], from: string },
|
|
20
20
|
* allow: string[],
|
|
21
21
|
* disallow: string[],
|
|
22
22
|
* }} ImportPath
|
|
@@ -30,6 +30,8 @@ const DEFAULT = "default";
|
|
|
30
30
|
|
|
31
31
|
const NAMESPACE = "*";
|
|
32
32
|
|
|
33
|
+
const ANY_MEMBER = "*";
|
|
34
|
+
|
|
33
35
|
const importSchema = {
|
|
34
36
|
type: "object",
|
|
35
37
|
properties: {
|
|
@@ -37,8 +39,16 @@ const importSchema = {
|
|
|
37
39
|
type: "object",
|
|
38
40
|
properties: {
|
|
39
41
|
member: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
oneOf: [
|
|
43
|
+
{
|
|
44
|
+
type: "array",
|
|
45
|
+
items: [{ type: "string" }], // 'default' means default specifier
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: "string",
|
|
49
|
+
pattern: `^[${ANY_MEMBER}]$`
|
|
50
|
+
}
|
|
51
|
+
]
|
|
42
52
|
},
|
|
43
53
|
from: { type: "string" },
|
|
44
54
|
},
|
|
@@ -93,7 +103,7 @@ module.exports = {
|
|
|
93
103
|
additionalItems: false,
|
|
94
104
|
},
|
|
95
105
|
messages: {
|
|
96
|
-
"no-disallowed-imports": "
|
|
106
|
+
"no-disallowed-imports": "{{member}} should NOT be imported from '{{from}}'",
|
|
97
107
|
},
|
|
98
108
|
},
|
|
99
109
|
create(context) {
|
|
@@ -126,6 +136,12 @@ module.exports = {
|
|
|
126
136
|
return [theMember, theImportSpec];
|
|
127
137
|
}
|
|
128
138
|
|
|
139
|
+
const isModulePathMatched = match(fromCwd(context.cwd, modulePath))(importSpec.import.from)
|
|
140
|
+
|
|
141
|
+
if (importSpec.import.member === ANY_MEMBER) {
|
|
142
|
+
return isModulePathMatched ? ['Any member', importSpec] : [undefined, undefined]
|
|
143
|
+
}
|
|
144
|
+
|
|
129
145
|
const importedSpecifiers = node.specifiers.map((specifier) => {
|
|
130
146
|
if (specifier.type === "ImportSpecifier")
|
|
131
147
|
return specifier.imported.name;
|
|
@@ -138,21 +154,16 @@ module.exports = {
|
|
|
138
154
|
importedSpecifiers.some((sp) => sp === specifier)
|
|
139
155
|
);
|
|
140
156
|
|
|
141
|
-
if (
|
|
142
|
-
member &&
|
|
143
|
-
match(fromCwd(context.cwd, modulePath))(importSpec.import.from)
|
|
144
|
-
) {
|
|
157
|
+
if (member && isModulePathMatched) {
|
|
145
158
|
if (member === DEFAULT || member === NAMESPACE) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
importSpec,
|
|
153
|
-
];
|
|
159
|
+
const theMember = node.specifiers.find(
|
|
160
|
+
({ type }) =>
|
|
161
|
+
type === "ImportDefaultSpecifier" ||
|
|
162
|
+
type === "ImportNamespaceSpecifier"
|
|
163
|
+
).local.name
|
|
164
|
+
return [`'${theMember}'`, importSpec];
|
|
154
165
|
}
|
|
155
|
-
return [member
|
|
166
|
+
return [`'${member}'`, importSpec];
|
|
156
167
|
}
|
|
157
168
|
|
|
158
169
|
return [undefined, undefined];
|
|
@@ -174,7 +185,7 @@ module.exports = {
|
|
|
174
185
|
context.report({
|
|
175
186
|
node,
|
|
176
187
|
messageId: "no-disallowed-imports",
|
|
177
|
-
data: { member: theMember },
|
|
188
|
+
data: { member: theMember, from: theImportSpec.import.from },
|
|
178
189
|
});
|
|
179
190
|
},
|
|
180
191
|
};
|
package/package.json
CHANGED
|
@@ -131,6 +131,90 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
131
131
|
},
|
|
132
132
|
],
|
|
133
133
|
},
|
|
134
|
+
{
|
|
135
|
+
code: "import { foo } from 'nodeModule'",
|
|
136
|
+
filename: "./src/fileB.js",
|
|
137
|
+
options: [
|
|
138
|
+
{
|
|
139
|
+
imports: [
|
|
140
|
+
{
|
|
141
|
+
import: { member: ["*"], from: "src/fileA" },
|
|
142
|
+
disallow: ["src/**/*.js"],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
code: "import { anyMember } from './fileA'",
|
|
150
|
+
filename: "./src/fileB.js",
|
|
151
|
+
options: [
|
|
152
|
+
{
|
|
153
|
+
imports: [
|
|
154
|
+
{
|
|
155
|
+
import: { member: "*", from: "src/fileA" },
|
|
156
|
+
allow: ["src/**/*.js"],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
code: "import * as namespace from './fileA'",
|
|
164
|
+
filename: "./src/fileB.js",
|
|
165
|
+
options: [
|
|
166
|
+
{
|
|
167
|
+
imports: [
|
|
168
|
+
{
|
|
169
|
+
import: { member: "*", from: "src/fileA" },
|
|
170
|
+
allow: ["src/**/*.js"],
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
code: "import { anyMember } from './fileA.act'",
|
|
178
|
+
filename: "./src/fileB.cal.js",
|
|
179
|
+
options: [
|
|
180
|
+
{
|
|
181
|
+
imports: [
|
|
182
|
+
{
|
|
183
|
+
import: { member: "*", from: "**/*.act" },
|
|
184
|
+
allow: ["src/**/*.cal.js"],
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
code: "import { anyMember } from 'fileA.cal'",
|
|
192
|
+
filename: "./src/fileB.act.js",
|
|
193
|
+
options: [
|
|
194
|
+
{
|
|
195
|
+
imports: [
|
|
196
|
+
{
|
|
197
|
+
import: { member: "*", from: "**/*.act" },
|
|
198
|
+
disallow: ["src/**/*.cal.js"],
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
code: "import { anyMember } from 'nodeModule'",
|
|
206
|
+
filename: "./src/fileB.cal.js",
|
|
207
|
+
options: [
|
|
208
|
+
{
|
|
209
|
+
imports: [
|
|
210
|
+
{
|
|
211
|
+
import: { member: "*", from: "**/*.act" },
|
|
212
|
+
disallow: ["src/**/*.cal.js"],
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
},
|
|
134
218
|
],
|
|
135
219
|
invalid: [
|
|
136
220
|
{
|
|
@@ -146,7 +230,7 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
146
230
|
],
|
|
147
231
|
},
|
|
148
232
|
],
|
|
149
|
-
errors: [{ messageId: "no-disallowed-imports", data: { member: "foo" } }],
|
|
233
|
+
errors: [{ messageId: "no-disallowed-imports", data: { member: "'foo'", from: "src/fileA" } }],
|
|
150
234
|
},
|
|
151
235
|
{
|
|
152
236
|
code: "import { foo } from './fileA'",
|
|
@@ -161,7 +245,7 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
161
245
|
],
|
|
162
246
|
},
|
|
163
247
|
],
|
|
164
|
-
errors: [{ messageId: "no-disallowed-imports", data: { member: "foo" } }],
|
|
248
|
+
errors: [{ messageId: "no-disallowed-imports", data: { member: "'foo'", from: "src/fileA" } }],
|
|
165
249
|
},
|
|
166
250
|
{
|
|
167
251
|
code: "import { foo } from './fileA'",
|
|
@@ -177,7 +261,7 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
177
261
|
],
|
|
178
262
|
},
|
|
179
263
|
],
|
|
180
|
-
errors: [{ messageId: "no-disallowed-imports", data: { member: "foo" } }],
|
|
264
|
+
errors: [{ messageId: "no-disallowed-imports", data: { member: "'foo'", from: "src/fileA" } }],
|
|
181
265
|
},
|
|
182
266
|
{
|
|
183
267
|
code: "import foo from './fileA'",
|
|
@@ -192,7 +276,7 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
192
276
|
],
|
|
193
277
|
},
|
|
194
278
|
],
|
|
195
|
-
errors: [{ messageId: "no-disallowed-imports", data: { member: "foo" } }],
|
|
279
|
+
errors: [{ messageId: "no-disallowed-imports", data: { member: "'foo'", from: "src/fileA" } }],
|
|
196
280
|
},
|
|
197
281
|
{
|
|
198
282
|
code: "import * as name from './fileA'",
|
|
@@ -208,7 +292,24 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
208
292
|
},
|
|
209
293
|
],
|
|
210
294
|
errors: [
|
|
211
|
-
{ messageId: "no-disallowed-imports", data: { member: "name" } },
|
|
295
|
+
{ messageId: "no-disallowed-imports", data: { member: "'name'", from: "src/fileA" } },
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
code: "import { anyMember } from './fileA.act'",
|
|
300
|
+
filename: "./src/fileB.cal.js",
|
|
301
|
+
options: [
|
|
302
|
+
{
|
|
303
|
+
imports: [
|
|
304
|
+
{
|
|
305
|
+
import: { member: "*", from: "**/*.act" },
|
|
306
|
+
disallow: ["**/*.cal.js"],
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
errors: [
|
|
312
|
+
{ messageId: "no-disallowed-imports", data: { member: "Any member", from: "**/*.act" } },
|
|
212
313
|
],
|
|
213
314
|
},
|
|
214
315
|
],
|