eslint-plugin-stratified-design 0.11.0 → 0.12.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.
|
@@ -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,10 @@ module.exports = {
|
|
|
126
136
|
return [theMember, theImportSpec];
|
|
127
137
|
}
|
|
128
138
|
|
|
139
|
+
if (importSpec.import.member === ANY_MEMBER) {
|
|
140
|
+
return ['Any member', importSpec]
|
|
141
|
+
}
|
|
142
|
+
|
|
129
143
|
const importedSpecifiers = node.specifiers.map((specifier) => {
|
|
130
144
|
if (specifier.type === "ImportSpecifier")
|
|
131
145
|
return specifier.imported.name;
|
|
@@ -143,16 +157,14 @@ module.exports = {
|
|
|
143
157
|
match(fromCwd(context.cwd, modulePath))(importSpec.import.from)
|
|
144
158
|
) {
|
|
145
159
|
if (member === DEFAULT || member === NAMESPACE) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
importSpec,
|
|
153
|
-
];
|
|
160
|
+
const theMember = node.specifiers.find(
|
|
161
|
+
({ type }) =>
|
|
162
|
+
type === "ImportDefaultSpecifier" ||
|
|
163
|
+
type === "ImportNamespaceSpecifier"
|
|
164
|
+
).local.name
|
|
165
|
+
return [`'${theMember}'`, importSpec];
|
|
154
166
|
}
|
|
155
|
-
return [member
|
|
167
|
+
return [`'${member}'`, importSpec];
|
|
156
168
|
}
|
|
157
169
|
|
|
158
170
|
return [undefined, undefined];
|
|
@@ -174,7 +186,7 @@ module.exports = {
|
|
|
174
186
|
context.report({
|
|
175
187
|
node,
|
|
176
188
|
messageId: "no-disallowed-imports",
|
|
177
|
-
data: { member: theMember },
|
|
189
|
+
data: { member: theMember, from: theImportSpec.import.from },
|
|
178
190
|
});
|
|
179
191
|
},
|
|
180
192
|
};
|
package/package.json
CHANGED
|
@@ -131,6 +131,34 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
131
131
|
},
|
|
132
132
|
],
|
|
133
133
|
},
|
|
134
|
+
{
|
|
135
|
+
code: "import { anyMember } from './fileA'",
|
|
136
|
+
filename: "./src/fileB.js",
|
|
137
|
+
options: [
|
|
138
|
+
{
|
|
139
|
+
imports: [
|
|
140
|
+
{
|
|
141
|
+
import: { member: "*", from: "src/fileA" },
|
|
142
|
+
allow: ["src/**/*.js"],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
code: "import * as namespace 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
|
+
},
|
|
134
162
|
],
|
|
135
163
|
invalid: [
|
|
136
164
|
{
|
|
@@ -146,7 +174,7 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
146
174
|
],
|
|
147
175
|
},
|
|
148
176
|
],
|
|
149
|
-
errors: [{ messageId: "no-disallowed-imports", data: { member: "foo" } }],
|
|
177
|
+
errors: [{ messageId: "no-disallowed-imports", data: { member: "'foo'", from: "src/fileA" } }],
|
|
150
178
|
},
|
|
151
179
|
{
|
|
152
180
|
code: "import { foo } from './fileA'",
|
|
@@ -161,7 +189,7 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
161
189
|
],
|
|
162
190
|
},
|
|
163
191
|
],
|
|
164
|
-
errors: [{ messageId: "no-disallowed-imports", data: { member: "foo" } }],
|
|
192
|
+
errors: [{ messageId: "no-disallowed-imports", data: { member: "'foo'", from: "src/fileA" } }],
|
|
165
193
|
},
|
|
166
194
|
{
|
|
167
195
|
code: "import { foo } from './fileA'",
|
|
@@ -177,7 +205,7 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
177
205
|
],
|
|
178
206
|
},
|
|
179
207
|
],
|
|
180
|
-
errors: [{ messageId: "no-disallowed-imports", data: { member: "foo" } }],
|
|
208
|
+
errors: [{ messageId: "no-disallowed-imports", data: { member: "'foo'", from: "src/fileA" } }],
|
|
181
209
|
},
|
|
182
210
|
{
|
|
183
211
|
code: "import foo from './fileA'",
|
|
@@ -192,7 +220,7 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
192
220
|
],
|
|
193
221
|
},
|
|
194
222
|
],
|
|
195
|
-
errors: [{ messageId: "no-disallowed-imports", data: { member: "foo" } }],
|
|
223
|
+
errors: [{ messageId: "no-disallowed-imports", data: { member: "'foo'", from: "src/fileA" } }],
|
|
196
224
|
},
|
|
197
225
|
{
|
|
198
226
|
code: "import * as name from './fileA'",
|
|
@@ -208,7 +236,24 @@ ruleTester.run("no-disallowed-imports", rule, {
|
|
|
208
236
|
},
|
|
209
237
|
],
|
|
210
238
|
errors: [
|
|
211
|
-
{ messageId: "no-disallowed-imports", data: { member: "name" } },
|
|
239
|
+
{ messageId: "no-disallowed-imports", data: { member: "'name'", from: "src/fileA" } },
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
code: "import { anyMember } from './fileA'",
|
|
244
|
+
filename: "./src/fileB.js",
|
|
245
|
+
options: [
|
|
246
|
+
{
|
|
247
|
+
imports: [
|
|
248
|
+
{
|
|
249
|
+
import: { member: "*", from: "src/fileA" },
|
|
250
|
+
disallow: ["src/**/*.js"],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
errors: [
|
|
256
|
+
{ messageId: "no-disallowed-imports", data: { member: "Any member", from: "src/fileA" } },
|
|
212
257
|
],
|
|
213
258
|
},
|
|
214
259
|
],
|