Skip to content

Commit 2238f59

Browse files
committed
feat: Added recommended-react config
1 parent 4cb2915 commit 2238f59

11 files changed

+2528
-289
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ This repository contains custom ESLint rules to enhance code quality and consist
1818
✅ Set in the `recommended` configuration.\
1919
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
2020

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][] | |
2626

2727
<!-- end auto-generated rules list -->
2828

bun.lockb

34 KB
Binary file not shown.

docs/rules/no-comments.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow comments except for specified allowed patterns (`th-rules/no-comments`)
22

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`.
44

55
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
66

docs/rules/no-default-export.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Convert unnamed default exports to named default exports based on the file name (`th-rules/no-default-export`)
22

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`.
44

55
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
66

docs/rules/no-destructuring.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow destructuring that does not meet certain conditions (`th-rules/no-destructuring`)
22

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`.
44

55
<!-- end auto-generated rule header -->
66

package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,42 @@
2323
"eslint-config-xo": "^0.46.0",
2424
"eslint-config-xo-react": "^0.27.0",
2525
"eslint-plugin-jsdoc": "^50.2.2",
26-
"eslint-plugin-react": "^7.35.0",
26+
"eslint-plugin-react": "^7.35.2",
2727
"eslint-plugin-react-hooks": "^4.6.2",
2828
"eslint-plugin-react-native": "^4.1.0",
2929
"eslint-plugin-security": "^3.0.1",
30-
"eslint-plugin-sonarjs": "^1.0.4",
30+
"eslint-plugin-sonarjs": "^2.0.2",
3131
"requireindex": "^1.2.0"
3232
},
3333
"devDependencies": {
3434
"@codedependant/semantic-release-docker": "^5.0.3",
35-
"@eslint/js": "^9.9.0",
35+
"@eslint/js": "^9.10.0",
3636
"@semantic-release/changelog": "^6.0.3",
3737
"@semantic-release/commit-analyzer": "^13.0.0",
3838
"@semantic-release/git": "^10.0.1",
39-
"@semantic-release/github": "^10.1.7",
39+
"@semantic-release/github": "^10.3.3",
4040
"@semantic-release/npm": "^12.0.1",
4141
"@semantic-release/release-notes-generator": "^14.0.1",
4242
"@types/eslint-plugin-security": "^3.0.0",
4343
"@types/eslint__js": "^8.42.3",
4444
"@types/requireindex": "^1.2.4",
4545
"@types/xo": "^0.39.9",
4646
"bun-types": "latest",
47-
"eslint": "^9.9.0",
47+
"eslint": "^9.10.0",
4848
"eslint-doc-generator": "^1.7.1",
4949
"eslint-plugin-eslint-plugin": "^6.2.0",
5050
"eslint-plugin-node": "^11.1.0",
51-
"eslint-plugin-sonarjs": "^1.0.4",
51+
"eslint-plugin-sonarjs": "^2.0.2",
5252
"eslint-plugin-unicorn": "^55.0.0",
5353
"mocha": "^10.7.3",
5454
"npm-run-all": "^4.1.5",
55-
"typescript": "^5.5.4",
56-
"typescript-eslint": "^8.2.0",
55+
"typescript": "^5.6.2",
56+
"typescript-eslint": "^8.5.0",
5757
"xo": "^0.59.3"
5858
},
5959
"peerDependencies": {
60-
"eslint": ">=9.9.0",
61-
"typescript": "^5.5.4"
60+
"eslint": ">=9.10.0",
61+
"typescript": "^5.6.2"
6262
},
6363
"license": "ISC",
6464
"packageManager": "yarn@4.4.0"

src/index.js

+42-30
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,37 @@
44
'use strict';
55
const requireIndex = require('requireindex');
66

7-
const configs = {};
8-
configs.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,
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+
},
3738
},
3839
};
3940

@@ -59,6 +60,17 @@ for (const configName of Object.keys(configs)) {
5960
'@typescript-eslint/no-unsafe-argument': 'off',
6061
},
6162
};
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+
};
6274
}
6375

6476
module.exports = {

src/rules/no-comments.js

+76-76
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,97 @@
11
/* eslint-disable unicorn/prefer-module */
22

33
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
99
];
1010

1111
const meta = {
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-
],
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+
],
4040
};
4141

4242
function create(context) {
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));
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));
4646

47-
function isCommentAllowed(comment) {
48-
const text = comment.value.trim();
47+
function isCommentAllowed(comment) {
48+
const text = comment.value.trim();
4949

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-
}
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+
}
5454

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-
}
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+
}
6161

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-
}
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+
}
6868

69-
return false; // Disallow by default if no match
70-
}
69+
return false; // Disallow by default if no match
70+
}
7171

72-
return {
73-
Program() {
74-
const sourceCode = context.getSourceCode();
75-
const comments = sourceCode.getAllComments();
72+
return {
73+
Program() {
74+
const sourceCode = context.getSourceCode();
75+
const comments = sourceCode.getAllComments();
7676

77-
comments.forEach((comment) => {
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-
};
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+
};
9090
}
9191

9292
const rule = {
93-
meta,
94-
create,
93+
meta,
94+
create,
9595
};
9696

97-
module.exports = rule;
97+
module.exports = rule;

src/rules/no-default-export.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const meta = {
66
type: 'problem',
77
docs: {
88
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',
1010
},
1111
fixable: 'code',
1212
schema: [],

src/rules/no-destructuring.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const meta = {
2020
description: 'Disallow destructuring that does not meet certain conditions',
2121
category: 'Possible Errors',
2222
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',
2424
},
2525
schema: [
2626
{

0 commit comments

Comments
 (0)