eslint-plugin-th-rules 1.13.1 → 1.13.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.
- package/CHANGELOG.md +7 -0
- package/README.md +0 -1
- package/bun.lockb +0 -0
- package/package.json +1 -1
- package/docs/rules/named-functions.md +0 -7
- package/src/rules/named-functions.js +0 -84
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.13.2](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.13.1...v1.13.2) (2024-08-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Remove named-functions rule and related files ([9d0f23d](https://github.com/tomerh2001/eslint-plugin-th-rules/commit/9d0f23d1f705eb3ddbe41e9def152e182729e1d4))
|
|
7
|
+
|
|
1
8
|
## [1.13.1](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.13.0...v1.13.1) (2024-08-19)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -20,7 +20,6 @@ This repository contains custom ESLint rules to enhance code quality and consist
|
|
|
20
20
|
|
|
21
21
|
| Name | Description | 💼 | 🔧 |
|
|
22
22
|
| :--------------------------------------------------- | :------------------------------------------------------------------------------- | :---------------------------------- | :- |
|
|
23
|
-
| [named-functions](docs/rules/named-functions.md) | Enforce top-level functions to be named function declarations | ✅ ![badge-recommended-typescript][] | 🔧 |
|
|
24
23
|
| [no-comments](docs/rules/no-comments.md) | Disallow comments except for specified allowed patterns. | ✅ ![badge-recommended-typescript][] | 🔧 |
|
|
25
24
|
| [no-default-export](docs/rules/no-default-export.md) | Convert unnamed default exports to named default exports based on the file name. | ✅ ![badge-recommended-typescript][] | 🔧 |
|
|
26
25
|
| [no-destructuring](docs/rules/no-destructuring.md) | Disallow destructuring that does not meet certain conditions | ✅ ![badge-recommended-typescript][] | |
|
package/bun.lockb
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# Enforce top-level functions to be named function declarations (`th-rules/named-functions`)
|
|
2
|
-
|
|
3
|
-
💼 This rule is enabled in the following configs: ✅ `recommended`, `recommended-typescript`.
|
|
4
|
-
|
|
5
|
-
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
6
|
-
|
|
7
|
-
<!-- end auto-generated rule header -->
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
meta: {
|
|
3
|
-
type: 'problem',
|
|
4
|
-
docs: {
|
|
5
|
-
description: 'Enforce top-level functions to be named function declarations',
|
|
6
|
-
url: 'https://github.com/tomerh2001/eslint-plugin-th-rules/blob/main/docs/rules/named-functions.md',
|
|
7
|
-
},
|
|
8
|
-
fixable: 'code',
|
|
9
|
-
schema: [],
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
create(context) {
|
|
13
|
-
function reportAndFix(node, varName) {
|
|
14
|
-
context.report({
|
|
15
|
-
node,
|
|
16
|
-
message: 'Top-level functions must be named function declarations.',
|
|
17
|
-
fix(fixer) {
|
|
18
|
-
const sourceCode = context.getSourceCode();
|
|
19
|
-
|
|
20
|
-
if (node.type === 'ArrowFunctionExpression') {
|
|
21
|
-
// Convert arrow function to a named function declaration
|
|
22
|
-
const functionBody = sourceCode.getText(node.body);
|
|
23
|
-
const functionParams = sourceCode.getText(node.params);
|
|
24
|
-
const asyncKeyword = node.async ? 'async ' : '';
|
|
25
|
-
|
|
26
|
-
let functionDeclaration;
|
|
27
|
-
|
|
28
|
-
if (node.body.type === 'BlockStatement') {
|
|
29
|
-
functionDeclaration = `${asyncKeyword}function ${varName}(${functionParams}) ${functionBody}`;
|
|
30
|
-
} else {
|
|
31
|
-
// For concise body (single expression)
|
|
32
|
-
functionDeclaration = `${asyncKeyword}function ${varName}(${functionParams}) { return ${functionBody}; }`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return fixer.replaceText(node.parent, functionDeclaration);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (node.type === 'FunctionExpression') {
|
|
39
|
-
// Convert anonymous function expression to named function declaration
|
|
40
|
-
const functionBody = sourceCode.getText(node.body);
|
|
41
|
-
const functionParams = sourceCode.getText(node.params);
|
|
42
|
-
const asyncKeyword = node.async ? 'async ' : '';
|
|
43
|
-
const generatorKeyword = node.generator ? '*' : '';
|
|
44
|
-
|
|
45
|
-
const functionDeclaration = `${asyncKeyword}function ${generatorKeyword}${varName}(${functionParams}) ${functionBody}`;
|
|
46
|
-
return fixer.replaceText(node.parent, functionDeclaration);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return null;
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
Program(programNode) {
|
|
56
|
-
programNode.body.forEach((node) => {
|
|
57
|
-
// Handle VariableDeclaration (e.g. const function_ = () => {})
|
|
58
|
-
if (node.type === 'VariableDeclaration') {
|
|
59
|
-
node.declarations.forEach((declaration) => {
|
|
60
|
-
// Ensure that declaration.init is defined and that it's a function expression or arrow function
|
|
61
|
-
if (
|
|
62
|
-
declaration.init &&
|
|
63
|
-
(declaration.init.type === 'ArrowFunctionExpression' || declaration.init.type === 'FunctionExpression')
|
|
64
|
-
) {
|
|
65
|
-
const varName = declaration.id.name;
|
|
66
|
-
reportAndFix(declaration.init, varName);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Handle anonymous top-level function declarations
|
|
72
|
-
if (node.type === 'FunctionDeclaration' && !node.id) {
|
|
73
|
-
reportAndFix(node, 'Anonymous');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Handle ExpressionStatement for top-level arrow function (though uncommon)
|
|
77
|
-
if (node.type === 'ExpressionStatement' && node.expression.type === 'ArrowFunctionExpression') {
|
|
78
|
-
reportAndFix(node.expression, 'Anonymous');
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
},
|
|
84
|
-
};
|