eslint-plugin-th-rules 1.15.2 → 1.15.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.15.3](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.15.2...v1.15.3) (2024-12-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* enhance top-level functions rule to handle arrow and function expressions ([0bdcc2c](https://github.com/tomerh2001/eslint-plugin-th-rules/commit/0bdcc2cbe2bd9e790ca2965001c786e3a8518a60))
|
|
7
|
+
|
|
1
8
|
## [1.15.2](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.15.1...v1.15.2) (2024-12-30)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -17,22 +17,35 @@ function create(context) {
|
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const sourceCode = context.getSourceCode();
|
|
21
|
+
|
|
22
|
+
if (node.init && node.init.type === 'ArrowFunctionExpression') {
|
|
23
|
+
const functionName = node.id.name;
|
|
24
|
+
const functionText = sourceCode.getText(node.init);
|
|
25
|
+
|
|
26
|
+
context.report({
|
|
27
|
+
node: node.init,
|
|
28
|
+
message: 'Top-level functions must be named/regular functions.',
|
|
29
|
+
fix(fixer) {
|
|
30
|
+
const fixedCode = `function ${functionName}${functionText.slice(functionText.indexOf('('))}`;
|
|
31
|
+
return fixer.replaceText(node.parent, fixedCode);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
22
34
|
}
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
if (node.init && node.init.type === 'FunctionExpression') {
|
|
37
|
+
const functionName = node.id.name;
|
|
38
|
+
const functionText = sourceCode.getText(node.init);
|
|
27
39
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
context.report({
|
|
41
|
+
node: node.init,
|
|
42
|
+
message: 'Top-level functions must be named/regular functions.',
|
|
43
|
+
fix(fixer) {
|
|
44
|
+
const fixedCode = `function ${functionName}${functionText.slice(functionText.indexOf('('))}`;
|
|
45
|
+
return fixer.replaceText(node.parent, fixedCode);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
36
49
|
},
|
|
37
50
|
|
|
38
51
|
FunctionDeclaration(node) {
|
|
@@ -48,6 +61,7 @@ function create(context) {
|
|
|
48
61
|
const functionName = 'defaultFunction';
|
|
49
62
|
const sourceCode = context.getSourceCode();
|
|
50
63
|
const functionText = sourceCode.getText(node);
|
|
64
|
+
|
|
51
65
|
const fixedCode = functionText.replace('function (', `function ${functionName}(`);
|
|
52
66
|
|
|
53
67
|
return fixer.replaceText(node, fixedCode);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const {RuleTester} = require('eslint');
|
|
2
|
-
const rule = require('../src/rules/top-level-functions');
|
|
3
|
-
|
|
4
|
-
const ruleTester = new RuleTester({
|
|
5
|
-
parserOptions: {ecmaVersion: 2021, sourceType: 'module'},
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
ruleTester.run('top-level-functions', rule, {
|
|
9
|
-
valid: [
|
|
10
|
-
'function test() {}',
|
|
11
|
-
'function anotherFunction() {}',
|
|
12
|
-
],
|
|
13
|
-
invalid: [
|
|
14
|
-
{
|
|
15
|
-
code: 'const test = () => {};',
|
|
16
|
-
errors: [{message: 'Top-level functions must be named/regular functions.'}],
|
|
17
|
-
output: 'function test() {}',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
code: 'const response = (res, parameters = {}) => {};',
|
|
21
|
-
errors: [{message: 'Top-level functions must be named/regular functions.'}],
|
|
22
|
-
output: 'function response(res, parameters = {}) {}',
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
code: 'const func = function () {};',
|
|
26
|
-
errors: [{message: 'Top-level functions must be named/regular functions.'}],
|
|
27
|
-
output: 'function func() {}',
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
});
|