eslint-plugin-stratified-design 0.12.1 → 0.12.3
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.
|
@@ -140,21 +140,22 @@ module.exports = {
|
|
|
140
140
|
return {
|
|
141
141
|
Program(node) {
|
|
142
142
|
node.body.forEach((token) => {
|
|
143
|
-
const
|
|
143
|
+
const declaration = (token.type === 'ExportNamedDeclaration' || token.type === 'ExportDefaultDeclaration') && Boolean(token.declaration) ? token.declaration : token
|
|
144
|
+
const isFuncDeclaration = declaration.type === "FunctionDeclaration";
|
|
144
145
|
const isVarDeclaration =
|
|
145
|
-
|
|
146
|
+
declaration.type === "VariableDeclaration" &&
|
|
146
147
|
[
|
|
147
148
|
"ArrowFunctionExpression",
|
|
148
149
|
"FunctionExpression",
|
|
149
150
|
"CallExpression",
|
|
150
151
|
"TaggedTemplateExpression",
|
|
151
|
-
].includes(
|
|
152
|
+
].includes(declaration.declarations[0].init.type);
|
|
152
153
|
|
|
153
154
|
if (isFuncDeclaration || isVarDeclaration) {
|
|
154
155
|
const level = deriveLevel(sourceCode, token);
|
|
155
156
|
const name = isFuncDeclaration
|
|
156
|
-
?
|
|
157
|
-
:
|
|
157
|
+
? declaration.id.name
|
|
158
|
+
: declaration.declarations[0].id.name;
|
|
158
159
|
levels[name] = level;
|
|
159
160
|
}
|
|
160
161
|
});
|
package/package.json
CHANGED
|
@@ -50,30 +50,60 @@ ruleTester.run("no-same-level-funcs", rule, {
|
|
|
50
50
|
filename: "./src/foo.js",
|
|
51
51
|
options: [{ include: ["src/**/*.*"], exclude: ["src/foo.js"] }],
|
|
52
52
|
},
|
|
53
|
+
|
|
53
54
|
{
|
|
54
55
|
code: "// @level 2\nfunction func2(){};\n// @level 1\nfunction func1(){ func2(); }",
|
|
55
56
|
filename: "./src/foo.js",
|
|
56
57
|
},
|
|
58
|
+
{
|
|
59
|
+
code: "// @level 2\nexport function func2(){};\n// @level 1\nfunction func1(){ func2(); }",
|
|
60
|
+
filename: "./src/foo.js",
|
|
61
|
+
},
|
|
62
|
+
|
|
57
63
|
{
|
|
58
64
|
code: "// @level 2\nconst func2 = () => {};\n// @level 1\nfunction func1(){ func2(); }",
|
|
59
65
|
filename: "./src/foo.js",
|
|
60
66
|
},
|
|
67
|
+
{
|
|
68
|
+
code: "// @level 2\nexport const func2 = () => {};\n// @level 1\nfunction func1(){ func2(); }",
|
|
69
|
+
filename: "./src/foo.js",
|
|
70
|
+
},
|
|
71
|
+
|
|
61
72
|
{
|
|
62
73
|
code: "// @level 2\nconst func2 = () => {};\n// @level 1\nconst func1 = () => func2();",
|
|
63
74
|
filename: "./src/foo.js",
|
|
64
75
|
},
|
|
76
|
+
{
|
|
77
|
+
code: "// @level 2\nexport const func2 = () => {};\n// @level 1\nconst func1 = () => func2();",
|
|
78
|
+
filename: "./src/foo.js",
|
|
79
|
+
},
|
|
80
|
+
|
|
65
81
|
{
|
|
66
82
|
code: "/*@level 2*/\nconst func2 = () => {};\n/*@level 1*/\nconst func1 = () => func2();",
|
|
67
83
|
filename: "./src/foo.js",
|
|
68
84
|
},
|
|
85
|
+
{
|
|
86
|
+
code: "/*@level 2*/\nexport const func2 = () => {};\n/*@level 1*/\nconst func1 = () => func2();",
|
|
87
|
+
filename: "./src/foo.js",
|
|
88
|
+
},
|
|
89
|
+
|
|
69
90
|
{
|
|
70
91
|
code: "// @level 2 something\nconst func2 = () => {};\n// @level 1 something\nconst func1 = () => func2();",
|
|
71
92
|
filename: "./src/foo.js",
|
|
72
93
|
},
|
|
94
|
+
{
|
|
95
|
+
code: "// @level 2 something\nexport const func2 = () => {};\n// @level 1 something\nconst func1 = () => func2();",
|
|
96
|
+
filename: "./src/foo.js",
|
|
97
|
+
},
|
|
98
|
+
|
|
73
99
|
{
|
|
74
100
|
code: "/*\n@level 2\nsomething\n*/\nconst func2 = () => {};\n/*something\n@level 1\n*/\nconst func1 = () => func2();",
|
|
75
101
|
filename: "./src/foo.js",
|
|
76
102
|
},
|
|
103
|
+
{
|
|
104
|
+
code: "/*\n@level 2\nsomething\n*/\nexport const func2 = () => {};\n/*something\n@level 1\n*/\nconst func1 = () => func2();",
|
|
105
|
+
filename: "./src/foo.js",
|
|
106
|
+
},
|
|
77
107
|
],
|
|
78
108
|
invalid: [
|
|
79
109
|
{
|
|
@@ -81,31 +111,77 @@ ruleTester.run("no-same-level-funcs", rule, {
|
|
|
81
111
|
filename: "./src/foo.js",
|
|
82
112
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
83
113
|
},
|
|
114
|
+
{
|
|
115
|
+
code: "export function func1(){}; function func2(){ func1(); }",
|
|
116
|
+
filename: "./src/foo.js",
|
|
117
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
code: "export default function func1(){}; function func2(){ func1(); }",
|
|
121
|
+
filename: "./src/foo.js",
|
|
122
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
123
|
+
},
|
|
124
|
+
|
|
84
125
|
{
|
|
85
126
|
code: "function func2(){ func1(); }; function func1(){}",
|
|
86
127
|
filename: "./src/foo.js",
|
|
87
128
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
88
129
|
},
|
|
130
|
+
|
|
131
|
+
{
|
|
132
|
+
code: "export function func2(){ func1(); }; function func1(){}",
|
|
133
|
+
filename: "./src/foo.js",
|
|
134
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
code: "export default function func2(){ func1(); }; function func1(){}",
|
|
138
|
+
filename: "./src/foo.js",
|
|
139
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
140
|
+
},
|
|
141
|
+
|
|
89
142
|
{
|
|
90
143
|
code: "const func1 = () => {}; const func2 = () => { func1(); }",
|
|
91
144
|
filename: "./src/foo.js",
|
|
92
145
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
93
146
|
},
|
|
147
|
+
{
|
|
148
|
+
code: "export const func1 = () => {}; const func2 = () => { func1(); }",
|
|
149
|
+
filename: "./src/foo.js",
|
|
150
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
151
|
+
},
|
|
152
|
+
|
|
94
153
|
{
|
|
95
154
|
code: "const func1 = function(){}; const func2 = function(){ func1(); }",
|
|
96
155
|
filename: "./src/foo.js",
|
|
97
156
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
98
157
|
},
|
|
158
|
+
{
|
|
159
|
+
code: "export const func1 = function(){}; const func2 = function(){ func1(); }",
|
|
160
|
+
filename: "./src/foo.js",
|
|
161
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
162
|
+
},
|
|
163
|
+
|
|
99
164
|
{
|
|
100
165
|
code: "const func1 = function func1(){}; const func2 = function func2(){ func1(); }",
|
|
101
166
|
filename: "./src/foo.js",
|
|
102
167
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
103
168
|
},
|
|
169
|
+
{
|
|
170
|
+
code: "export const func1 = function func1(){}; const func2 = function func2(){ func1(); }",
|
|
171
|
+
filename: "./src/foo.js",
|
|
172
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
173
|
+
},
|
|
174
|
+
|
|
104
175
|
{
|
|
105
176
|
code: "const fn = () => 1; const value = fn()",
|
|
106
177
|
filename: "./src/foo.js",
|
|
107
178
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "fn" } }],
|
|
108
179
|
},
|
|
180
|
+
{
|
|
181
|
+
code: "export const fn = () => 1; const value = fn()",
|
|
182
|
+
filename: "./src/foo.js",
|
|
183
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "fn" } }],
|
|
184
|
+
},
|
|
109
185
|
{
|
|
110
186
|
code: "const hof = (fn) => fn(); const fnByHof = hof(() => 1);",
|
|
111
187
|
filename: "./src/foo.js",
|
|
@@ -146,11 +222,18 @@ ruleTester.run("no-same-level-funcs", rule, {
|
|
|
146
222
|
filename: "./src/foo.js",
|
|
147
223
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func1" } }],
|
|
148
224
|
},
|
|
225
|
+
|
|
149
226
|
{
|
|
150
227
|
code: "// @level 2\nfunction func2(){};\nfunction func1(){ func2(); }",
|
|
151
228
|
filename: "./src/foo.js",
|
|
152
229
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "func2" } }],
|
|
153
230
|
},
|
|
231
|
+
{
|
|
232
|
+
code: "// @level 2\nexport function func2(){};\nfunction func1(){ func2(); }",
|
|
233
|
+
filename: "./src/foo.js",
|
|
234
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "func2" } }],
|
|
235
|
+
},
|
|
236
|
+
|
|
154
237
|
{
|
|
155
238
|
code: "function func2(){};\n// @level 1\nfunction func1(){ func2(); }",
|
|
156
239
|
filename: "./src/foo.js",
|