Skip to content

Commit 82dda49

Browse files
committed
feat: created no-comments rule
1 parent c766606 commit 82dda49

File tree

7 files changed

+49
-4
lines changed

7 files changed

+49
-4
lines changed

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"cSpell.words": [
3+
"sonarjs"
4+
]
5+
}

.xo-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"plugin:th-rules/recommended-typescript"
4+
]
5+
}

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,35 @@ This rule targets unnamed default exports and automatically generates a named ex
5959
}
6060
}
6161
```
62+
### 3. No-Disallowed-Comments Rule
63+
64+
**Rule ID:** `th-rules/no-disallowed-comments`
65+
66+
#### Description
67+
68+
This rule disallows comments unless they match specified allowed patterns. It ensures that only relevant and permitted comments are present in the codebase, such as TODOs, warnings, JSDoc comments, ESLint directives, etc.
69+
70+
#### Rule Details
71+
72+
By default, the following comments are allowed:
73+
74+
- TODO, WARNING, ERROR, INFO (case-insensitive).
75+
- ESLint directives like `/* eslint-disable */`.
76+
- JSDoc comments (any comment starting with `/**`).
77+
78+
You can also configure additional patterns to allow or disallow specific types of comments.
79+
80+
#### Configuration
81+
82+
```json
83+
{
84+
"rules": {
85+
"th-rules/no-disallowed-comments": [
86+
"error",
87+
{
88+
"allow": ["keep", "important"],
89+
"disallow": ["deprecated", "hack"]
90+
}
91+
]
92+
}
93+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"eslint-plugin-react-native": "^4.1.0",
2929
"eslint-plugin-security": "^3.0.1",
3030
"eslint-plugin-sonarjs": "^1.0.4",
31+
"eslint-plugin-th-rules": "^1.11.4",
3132
"requireindex": "^1.2.0"
3233
},
3334
"devDependencies": {

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ configs.recommended = {
2727
'unicorn/no-await-expression-member': 'off',
2828
'new-cap': 'off',
2929
'no-await-in-loop': 'off',
30+
'n/file-extension-in-import': 'off',
31+
'import/no-cycle': 'off',
3032
camelcase: 'warn',
3133
},
3234
env: {
@@ -37,7 +39,7 @@ configs.recommended = {
3739
};
3840

3941
for (const configName of Object.keys(configs)) {
40-
configs[configName + '-typescript'] = {
42+
configs[`${configName}-typescript`] = {
4143
...configs[configName],
4244
extends: [
4345
'plugin:@typescript-eslint/strict-type-checked',

src/tests/no-comments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const ruleTester = new RuleTester({
88
parser: require.resolve('@babel/eslint-parser'),
99
});
1010

11-
ruleTester.run('no-disallowed-comments', rule, {
11+
ruleTester.run('no-comments', rule, {
1212
valid: [
1313
{
1414
code: `

yarn.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3301,7 +3301,7 @@ __metadata:
33013301
languageName: node
33023302
linkType: hard
33033303

3304-
"eslint-plugin-th-rules@workspace:.":
3304+
"eslint-plugin-th-rules@npm:^1.11.4, eslint-plugin-th-rules@workspace:.":
33053305
version: 0.0.0-use.local
33063306
resolution: "eslint-plugin-th-rules@workspace:."
33073307
dependencies:
@@ -3332,6 +3332,7 @@ __metadata:
33323332
eslint-plugin-react-native: "npm:^4.1.0"
33333333
eslint-plugin-security: "npm:^3.0.1"
33343334
eslint-plugin-sonarjs: "npm:^1.0.4"
3335+
eslint-plugin-th-rules: "npm:^1.11.4"
33353336
eslint-plugin-unicorn: "npm:^55.0.0"
33363337
mocha: "npm:^10.7.3"
33373338
npm-run-all: "npm:^4.1.5"

0 commit comments

Comments
 (0)