eslint-plugin-stratified-design 0.12.0 → 0.12.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.
@@ -136,8 +136,10 @@ module.exports = {
136
136
  return [theMember, theImportSpec];
137
137
  }
138
138
 
139
+ const isModulePathMatched = match(fromCwd(context.cwd, modulePath))(importSpec.import.from)
140
+
139
141
  if (importSpec.import.member === ANY_MEMBER) {
140
- return ['Any member', importSpec]
142
+ return isModulePathMatched ? ['Any member', importSpec] : [undefined, undefined]
141
143
  }
142
144
 
143
145
  const importedSpecifiers = node.specifiers.map((specifier) => {
@@ -152,10 +154,7 @@ module.exports = {
152
154
  importedSpecifiers.some((sp) => sp === specifier)
153
155
  );
154
156
 
155
- if (
156
- member &&
157
- match(fromCwd(context.cwd, modulePath))(importSpec.import.from)
158
- ) {
157
+ if (member && isModulePathMatched) {
159
158
  if (member === DEFAULT || member === NAMESPACE) {
160
159
  const theMember = node.specifiers.find(
161
160
  ({ type }) =>
@@ -140,21 +140,22 @@ module.exports = {
140
140
  return {
141
141
  Program(node) {
142
142
  node.body.forEach((token) => {
143
- const isFuncDeclaration = token.type === "FunctionDeclaration";
143
+ const declaration = token.type === 'ExportNamedDeclaration' || token.type === 'ExportDefaultDeclaration' ? token.declaration : token
144
+ const isFuncDeclaration = declaration.type === "FunctionDeclaration";
144
145
  const isVarDeclaration =
145
- token.type === "VariableDeclaration" &&
146
+ declaration.type === "VariableDeclaration" &&
146
147
  [
147
148
  "ArrowFunctionExpression",
148
149
  "FunctionExpression",
149
150
  "CallExpression",
150
151
  "TaggedTemplateExpression",
151
- ].includes(token.declarations[0].init.type);
152
+ ].includes(declaration.declarations[0].init.type);
152
153
 
153
154
  if (isFuncDeclaration || isVarDeclaration) {
154
- const level = deriveLevel(sourceCode, token);
155
+ const level = deriveLevel(sourceCode, declaration);
155
156
  const name = isFuncDeclaration
156
- ? token.id.name
157
- : token.declarations[0].id.name;
157
+ ? declaration.id.name
158
+ : declaration.declarations[0].id.name;
158
159
  levels[name] = level;
159
160
  }
160
161
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-stratified-design",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
4
4
  "description": "ESlint rules for stratified design",
5
5
  "keywords": [
6
6
  "eslint",
@@ -131,6 +131,20 @@ 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
+ },
134
148
  {
135
149
  code: "import { anyMember } from './fileA'",
136
150
  filename: "./src/fileB.js",
@@ -159,6 +173,48 @@ ruleTester.run("no-disallowed-imports", rule, {
159
173
  },
160
174
  ],
161
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
+ },
162
218
  ],
163
219
  invalid: [
164
220
  {
@@ -240,20 +296,20 @@ ruleTester.run("no-disallowed-imports", rule, {
240
296
  ],
241
297
  },
242
298
  {
243
- code: "import { anyMember } from './fileA'",
244
- filename: "./src/fileB.js",
299
+ code: "import { anyMember } from './fileA.act'",
300
+ filename: "./src/fileB.cal.js",
245
301
  options: [
246
302
  {
247
303
  imports: [
248
304
  {
249
- import: { member: "*", from: "src/fileA" },
250
- disallow: ["src/**/*.js"],
305
+ import: { member: "*", from: "**/*.act" },
306
+ disallow: ["**/*.cal.js"],
251
307
  },
252
308
  ],
253
309
  },
254
310
  ],
255
311
  errors: [
256
- { messageId: "no-disallowed-imports", data: { member: "Any member", from: "src/fileA" } },
312
+ { messageId: "no-disallowed-imports", data: { member: "Any member", from: "**/*.act" } },
257
313
  ],
258
314
  },
259
315
  ],
@@ -81,31 +81,77 @@ ruleTester.run("no-same-level-funcs", rule, {
81
81
  filename: "./src/foo.js",
82
82
  errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
83
83
  },
84
+ {
85
+ code: "export function func1(){}; function func2(){ func1(); }",
86
+ filename: "./src/foo.js",
87
+ errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
88
+ },
89
+ {
90
+ code: "export default function func1(){}; function func2(){ func1(); }",
91
+ filename: "./src/foo.js",
92
+ errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
93
+ },
94
+
84
95
  {
85
96
  code: "function func2(){ func1(); }; function func1(){}",
86
97
  filename: "./src/foo.js",
87
98
  errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
88
99
  },
100
+
101
+ {
102
+ code: "export function func2(){ func1(); }; function func1(){}",
103
+ filename: "./src/foo.js",
104
+ errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
105
+ },
106
+ {
107
+ code: "export default function func2(){ func1(); }; function func1(){}",
108
+ filename: "./src/foo.js",
109
+ errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
110
+ },
111
+
89
112
  {
90
113
  code: "const func1 = () => {}; const func2 = () => { func1(); }",
91
114
  filename: "./src/foo.js",
92
115
  errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
93
116
  },
117
+ {
118
+ code: "export const func1 = () => {}; const func2 = () => { func1(); }",
119
+ filename: "./src/foo.js",
120
+ errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
121
+ },
122
+
94
123
  {
95
124
  code: "const func1 = function(){}; const func2 = function(){ func1(); }",
96
125
  filename: "./src/foo.js",
97
126
  errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
98
127
  },
128
+ {
129
+ code: "export const func1 = function(){}; const func2 = function(){ func1(); }",
130
+ filename: "./src/foo.js",
131
+ errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
132
+ },
133
+
99
134
  {
100
135
  code: "const func1 = function func1(){}; const func2 = function func2(){ func1(); }",
101
136
  filename: "./src/foo.js",
102
137
  errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
103
138
  },
139
+ {
140
+ code: "export const func1 = function func1(){}; const func2 = function func2(){ func1(); }",
141
+ filename: "./src/foo.js",
142
+ errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
143
+ },
144
+
104
145
  {
105
146
  code: "const fn = () => 1; const value = fn()",
106
147
  filename: "./src/foo.js",
107
148
  errors: [{ messageId: "no-same-level-funcs", data: { func: "fn" } }],
108
149
  },
150
+ {
151
+ code: "export const fn = () => 1; const value = fn()",
152
+ filename: "./src/foo.js",
153
+ errors: [{ messageId: "no-same-level-funcs", data: { func: "fn" } }],
154
+ },
109
155
  {
110
156
  code: "const hof = (fn) => fn(); const fnByHof = hof(() => 1);",
111
157
  filename: "./src/foo.js",