eslint-plugin-stratified-design 0.12.1 → 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.
|
@@ -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' ? 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
|
-
const level = deriveLevel(sourceCode,
|
|
155
|
+
const level = deriveLevel(sourceCode, declaration);
|
|
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
|
@@ -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",
|