eslint-plugin-th-rules 1.13.4 → 1.14.0
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 +5 -5
- package/bun.lockb +0 -0
- package/docs/rules/no-comments.md +1 -1
- package/docs/rules/no-default-export.md +1 -1
- package/docs/rules/no-destructuring.md +1 -1
- package/package.json +11 -11
- package/src/index.js +42 -30
- package/src/rules/no-comments.js +76 -76
- package/src/rules/no-default-export.js +1 -1
- package/src/rules/no-destructuring.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.14.0](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.13.4...v1.14.0) (2024-09-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Added `recommended-react` config ([2238f59](https://github.com/tomerh2001/eslint-plugin-th-rules/commit/2238f59649a1a3ad7368aa6a2feaca0e98391d2f))
|
|
7
|
+
|
|
1
8
|
## [1.13.4](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.13.3...v1.13.4) (2024-08-22)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -18,11 +18,11 @@ This repository contains custom ESLint rules to enhance code quality and consist
|
|
|
18
18
|
✅ Set in the `recommended` configuration.\
|
|
19
19
|
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
|
|
20
20
|
|
|
21
|
-
| Name | Description | 💼
|
|
22
|
-
| :--------------------------------------------------- | :------------------------------------------------------------------------------- |
|
|
23
|
-
| [no-comments](docs/rules/no-comments.md) | Disallow comments except for specified allowed patterns. | ✅ ![badge-recommended-typescript][] | 🔧 |
|
|
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][] | 🔧 |
|
|
25
|
-
| [no-destructuring](docs/rules/no-destructuring.md) | Disallow destructuring that does not meet certain conditions | ✅ ![badge-recommended-typescript][] | |
|
|
21
|
+
| Name | Description | 💼 | 🔧 |
|
|
22
|
+
| :--------------------------------------------------- | :------------------------------------------------------------------------------- | :--------------------------------------------------------------- | :- |
|
|
23
|
+
| [no-comments](docs/rules/no-comments.md) | Disallow comments except for specified allowed patterns. | ✅ ![badge-recommended-react][] ![badge-recommended-typescript][] | 🔧 |
|
|
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-react][] ![badge-recommended-typescript][] | 🔧 |
|
|
25
|
+
| [no-destructuring](docs/rules/no-destructuring.md) | Disallow destructuring that does not meet certain conditions | ✅ ![badge-recommended-react][] ![badge-recommended-typescript][] | |
|
|
26
26
|
|
|
27
27
|
<!-- end auto-generated rules list -->
|
|
28
28
|
|
package/bun.lockb
CHANGED
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Disallow comments except for specified allowed patterns (`th-rules/no-comments`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the following configs: ✅ `recommended`, `recommended-typescript`.
|
|
3
|
+
💼 This rule is enabled in the following configs: ✅ `recommended`, `recommended-react`, `recommended-typescript`.
|
|
4
4
|
|
|
5
5
|
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Convert unnamed default exports to named default exports based on the file name (`th-rules/no-default-export`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the following configs: ✅ `recommended`, `recommended-typescript`.
|
|
3
|
+
💼 This rule is enabled in the following configs: ✅ `recommended`, `recommended-react`, `recommended-typescript`.
|
|
4
4
|
|
|
5
5
|
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Disallow destructuring that does not meet certain conditions (`th-rules/no-destructuring`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the following configs: ✅ `recommended`, `recommended-typescript`.
|
|
3
|
+
💼 This rule is enabled in the following configs: ✅ `recommended`, `recommended-react`, `recommended-typescript`.
|
|
4
4
|
|
|
5
5
|
<!-- end auto-generated rule header -->
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-th-rules",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "A List of custom ESLint rules created by Tomer Horowitz",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -23,20 +23,20 @@
|
|
|
23
23
|
"eslint-config-xo": "^0.46.0",
|
|
24
24
|
"eslint-config-xo-react": "^0.27.0",
|
|
25
25
|
"eslint-plugin-jsdoc": "^50.2.2",
|
|
26
|
-
"eslint-plugin-react": "^7.35.
|
|
26
|
+
"eslint-plugin-react": "^7.35.2",
|
|
27
27
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
28
28
|
"eslint-plugin-react-native": "^4.1.0",
|
|
29
29
|
"eslint-plugin-security": "^3.0.1",
|
|
30
|
-
"eslint-plugin-sonarjs": "^
|
|
30
|
+
"eslint-plugin-sonarjs": "^2.0.2",
|
|
31
31
|
"requireindex": "^1.2.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@codedependant/semantic-release-docker": "^5.0.3",
|
|
35
|
-
"@eslint/js": "^9.
|
|
35
|
+
"@eslint/js": "^9.10.0",
|
|
36
36
|
"@semantic-release/changelog": "^6.0.3",
|
|
37
37
|
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
38
38
|
"@semantic-release/git": "^10.0.1",
|
|
39
|
-
"@semantic-release/github": "^10.
|
|
39
|
+
"@semantic-release/github": "^10.3.3",
|
|
40
40
|
"@semantic-release/npm": "^12.0.1",
|
|
41
41
|
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
42
42
|
"@types/eslint-plugin-security": "^3.0.0",
|
|
@@ -44,21 +44,21 @@
|
|
|
44
44
|
"@types/requireindex": "^1.2.4",
|
|
45
45
|
"@types/xo": "^0.39.9",
|
|
46
46
|
"bun-types": "latest",
|
|
47
|
-
"eslint": "^9.
|
|
47
|
+
"eslint": "^9.10.0",
|
|
48
48
|
"eslint-doc-generator": "^1.7.1",
|
|
49
49
|
"eslint-plugin-eslint-plugin": "^6.2.0",
|
|
50
50
|
"eslint-plugin-node": "^11.1.0",
|
|
51
|
-
"eslint-plugin-sonarjs": "^
|
|
51
|
+
"eslint-plugin-sonarjs": "^2.0.2",
|
|
52
52
|
"eslint-plugin-unicorn": "^55.0.0",
|
|
53
53
|
"mocha": "^10.7.3",
|
|
54
54
|
"npm-run-all": "^4.1.5",
|
|
55
|
-
"typescript": "^5.
|
|
56
|
-
"typescript-eslint": "^8.
|
|
55
|
+
"typescript": "^5.6.2",
|
|
56
|
+
"typescript-eslint": "^8.5.0",
|
|
57
57
|
"xo": "^0.59.3"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"eslint": ">=9.
|
|
61
|
-
"typescript": "^5.
|
|
60
|
+
"eslint": ">=9.10.0",
|
|
61
|
+
"typescript": "^5.6.2"
|
|
62
62
|
},
|
|
63
63
|
"license": "ISC",
|
|
64
64
|
"packageManager": "yarn@4.4.0"
|
package/src/index.js
CHANGED
|
@@ -4,36 +4,37 @@
|
|
|
4
4
|
'use strict';
|
|
5
5
|
const requireIndex = require('requireindex');
|
|
6
6
|
|
|
7
|
-
const configs = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
7
|
+
const configs = {
|
|
8
|
+
recommended: {
|
|
9
|
+
plugins: [
|
|
10
|
+
'th-rules',
|
|
11
|
+
'sonarjs',
|
|
12
|
+
],
|
|
13
|
+
extends: [
|
|
14
|
+
'plugin:sonarjs/recommended-legacy',
|
|
15
|
+
'plugin:security/recommended-legacy',
|
|
16
|
+
],
|
|
17
|
+
rules: {
|
|
18
|
+
'th-rules/no-destructuring': 'error',
|
|
19
|
+
'th-rules/no-default-export': 'error',
|
|
20
|
+
'th-rules/no-comments': 'error',
|
|
21
|
+
'unicorn/prefer-module': 'warn',
|
|
22
|
+
'unicorn/filename-case': 'off',
|
|
23
|
+
'unicorn/no-array-callback-reference': 'off',
|
|
24
|
+
'import/extensions': 'off',
|
|
25
|
+
'unicorn/no-static-only-class': 'off',
|
|
26
|
+
'unicorn/no-await-expression-member': 'off',
|
|
27
|
+
'new-cap': 'off',
|
|
28
|
+
'no-await-in-loop': 'off',
|
|
29
|
+
'n/file-extension-in-import': 'off',
|
|
30
|
+
'import/no-cycle': 'off',
|
|
31
|
+
camelcase: 'warn',
|
|
32
|
+
},
|
|
33
|
+
env: {
|
|
34
|
+
node: true,
|
|
35
|
+
es2024: true,
|
|
36
|
+
jest: true,
|
|
37
|
+
},
|
|
37
38
|
},
|
|
38
39
|
};
|
|
39
40
|
|
|
@@ -59,6 +60,17 @@ for (const configName of Object.keys(configs)) {
|
|
|
59
60
|
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
60
61
|
},
|
|
61
62
|
};
|
|
63
|
+
configs[`${configName}-react`] = {
|
|
64
|
+
...configs[configName],
|
|
65
|
+
extends: [
|
|
66
|
+
'plugin:react/recommended',
|
|
67
|
+
'plugin:react-hooks/recommended',
|
|
68
|
+
...configs[configName].extends,
|
|
69
|
+
],
|
|
70
|
+
rules: {
|
|
71
|
+
...configs[configName].rules,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
module.exports = {
|
package/src/rules/no-comments.js
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
1
|
/* eslint-disable unicorn/prefer-module */
|
|
2
2
|
|
|
3
3
|
const allowedPatterns = [
|
|
4
|
-
/todo/i, // Allow TODO (case-insensitive)
|
|
5
|
-
/warning/i, // Allow WARNING (case-insensitive)
|
|
6
|
-
/error/i, // Allow ERROR (case-insensitive)
|
|
7
|
-
/info/i, // Allow INFO (case-insensitive)
|
|
8
|
-
/^\s*eslint-(disable|enable|env|globals|ignore|directive)/, // Allow ESLint directives
|
|
4
|
+
/todo/i, // Allow TODO (case-insensitive)
|
|
5
|
+
/warning/i, // Allow WARNING (case-insensitive)
|
|
6
|
+
/error/i, // Allow ERROR (case-insensitive)
|
|
7
|
+
/info/i, // Allow INFO (case-insensitive)
|
|
8
|
+
/^\s*eslint-(disable|enable|env|globals|ignore|directive)/, // Allow ESLint directives
|
|
9
9
|
];
|
|
10
10
|
|
|
11
11
|
const meta = {
|
|
12
|
-
type: 'problem',
|
|
13
|
-
docs: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
fixable: 'code',
|
|
18
|
-
schema: [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
],
|
|
12
|
+
type: 'problem',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Disallow comments except for specified allowed patterns.',
|
|
15
|
+
url: 'https://github.com/tomerh2001/eslint-plugin-th-rules/blob/main/docs/rules/no-comments.md',
|
|
16
|
+
},
|
|
17
|
+
fixable: 'code',
|
|
18
|
+
schema: [
|
|
19
|
+
{
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
allow: {
|
|
23
|
+
type: 'array',
|
|
24
|
+
items: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
},
|
|
27
|
+
description: 'Additional patterns to allow in comments.',
|
|
28
|
+
},
|
|
29
|
+
disallow: {
|
|
30
|
+
type: 'array',
|
|
31
|
+
items: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
},
|
|
34
|
+
description: 'Additional patterns to disallow in comments.',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
function create(context) {
|
|
43
|
-
const options = context.options[0] || {};
|
|
44
|
-
const userAllowedPatterns = (options.allow || []).map(
|
|
45
|
-
const userDisallowedPatterns = (options.disallow || []).map(
|
|
43
|
+
const options = context.options[0] || {};
|
|
44
|
+
const userAllowedPatterns = (options.allow || []).map(pattern => new RegExp(pattern));
|
|
45
|
+
const userDisallowedPatterns = (options.disallow || []).map(pattern => new RegExp(pattern));
|
|
46
46
|
|
|
47
|
-
function isCommentAllowed(comment) {
|
|
48
|
-
|
|
47
|
+
function isCommentAllowed(comment) {
|
|
48
|
+
const text = comment.value.trim();
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
// Check if the comment is a valid JSDoc comment
|
|
51
|
+
if (comment.type === 'Block' && comment.value.startsWith('*')) {
|
|
52
|
+
return true; // Allow any JSDoc-style block comment (/** ... */)
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
// Check if the comment matches any allowed pattern
|
|
56
|
+
for (const pattern of [...allowedPatterns, ...userAllowedPatterns]) {
|
|
57
|
+
if (pattern.test(text)) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
// Check if the comment matches any disallowed pattern
|
|
63
|
+
for (const pattern of userDisallowedPatterns) {
|
|
64
|
+
if (pattern.test(text)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
}
|
|
69
|
+
return false; // Disallow by default if no match
|
|
70
|
+
}
|
|
71
71
|
|
|
72
|
-
return {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
return {
|
|
73
|
+
Program() {
|
|
74
|
+
const sourceCode = context.getSourceCode();
|
|
75
|
+
const comments = sourceCode.getAllComments();
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
77
|
+
for (const comment of comments) {
|
|
78
|
+
if (!isCommentAllowed(comment)) {
|
|
79
|
+
context.report({
|
|
80
|
+
node: comment,
|
|
81
|
+
message: 'Comment not allowed.',
|
|
82
|
+
fix(fixer) {
|
|
83
|
+
return fixer.remove(comment);
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const rule = {
|
|
93
|
-
meta,
|
|
94
|
-
create,
|
|
93
|
+
meta,
|
|
94
|
+
create,
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
module.exports = rule;
|
|
97
|
+
module.exports = rule;
|
|
@@ -6,7 +6,7 @@ const meta = {
|
|
|
6
6
|
type: 'problem',
|
|
7
7
|
docs: {
|
|
8
8
|
description: 'Convert unnamed default exports to named default exports based on the file name.',
|
|
9
|
-
url: 'https://github.com/tomerh2001/eslint-plugin-th-rules/blob/main/docs/rules/no-default-export.md'
|
|
9
|
+
url: 'https://github.com/tomerh2001/eslint-plugin-th-rules/blob/main/docs/rules/no-default-export.md',
|
|
10
10
|
},
|
|
11
11
|
fixable: 'code',
|
|
12
12
|
schema: [],
|
|
@@ -20,7 +20,7 @@ const meta = {
|
|
|
20
20
|
description: 'Disallow destructuring that does not meet certain conditions',
|
|
21
21
|
category: 'Possible Errors',
|
|
22
22
|
recommended: true,
|
|
23
|
-
url: 'https://github.com/tomerh2001/eslint-plugin-th-rules/blob/main/docs/rules/no-destructuring.md'
|
|
23
|
+
url: 'https://github.com/tomerh2001/eslint-plugin-th-rules/blob/main/docs/rules/no-destructuring.md',
|
|
24
24
|
},
|
|
25
25
|
schema: [
|
|
26
26
|
{
|