eslint-plugin-th-rules 1.15.3 → 1.15.4
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 +7 -0
- package/package.json +1 -1
- package/src/rules/top-level-functions.js +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.15.4](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.15.3...v1.15.4) (2024-12-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* improve top-level functions rule to support single-expression functions ([da75c58](https://github.com/tomerh2001/eslint-plugin-th-rules/commit/da75c5823445b54eac9ab6cc7717e007e8a797a6))
|
|
7
|
+
|
|
1
8
|
## [1.15.3](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.15.2...v1.15.3) (2024-12-30)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -27,7 +27,13 @@ function create(context) {
|
|
|
27
27
|
node: node.init,
|
|
28
28
|
message: 'Top-level functions must be named/regular functions.',
|
|
29
29
|
fix(fixer) {
|
|
30
|
-
const
|
|
30
|
+
const isSingleExpression = node.init.body.type !== 'BlockStatement';
|
|
31
|
+
const functionBody = isSingleExpression
|
|
32
|
+
? `{ return ${functionText.slice(functionText.indexOf('=>') + 3)}; }`
|
|
33
|
+
: functionText.slice(functionText.indexOf('{'));
|
|
34
|
+
const functionParameters = functionText.slice(0, functionText.indexOf('=>')).trim();
|
|
35
|
+
|
|
36
|
+
const fixedCode = `function ${functionName}${functionParameters} ${functionBody}`;
|
|
31
37
|
return fixer.replaceText(node.parent, fixedCode);
|
|
32
38
|
},
|
|
33
39
|
});
|
|
@@ -61,7 +67,6 @@ function create(context) {
|
|
|
61
67
|
const functionName = 'defaultFunction';
|
|
62
68
|
const sourceCode = context.getSourceCode();
|
|
63
69
|
const functionText = sourceCode.getText(node);
|
|
64
|
-
|
|
65
70
|
const fixedCode = functionText.replace('function (', `function ${functionName}(`);
|
|
66
71
|
|
|
67
72
|
return fixer.replaceText(node, fixedCode);
|