ES-Lint Rule or Plugin to identify the commented code
Asked Answered
V

4

8

I'm trying to find the rules or plugins of ES-Lint to identify the commented code so that I can remove that unnecessary code and clean my repository.

I would like to identify the multiline as well as single line code:

/* import CreateIncentive from './containers/create-incentive';
import AffiliateFilters from './containers/affiliate-filters'; */

//import NotificationsSettings from './containers/notifications-settings';

I have tried with below rules Bt it is not identifying the above kind of code :

"rules": {
        "no-warning-comments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "anywhere" }],
        "spaced-comment": ["error", "always", { "exceptions": ["-", "+"] }]
    }
Vanna answered 20/8, 2020 at 11:36 Comment(0)
V
0

So I found the way to consider the code commented rule for Sonar. It is just a matter of Quality Profile.I had set the DEFAULT profile to sonar-way but it has only 100 rules specified.

While the other profile available for JAVASCRIPT is Sonar way Recommended which has 148 rules and it also includes the rule to identify the code commented.

So switching the default profile to Sonar Way Recommended had the default rule to identify the commented code for multi-line or single line code.

enter image description here

Vanna answered 26/8, 2020 at 13:1 Comment(0)
S
3

eslint-plugin-etc Is a great suite of extra ESLint rules (often TS-related) and they offer one for commented out code:

https://github.com/cartant/eslint-plugin-etc/blob/main/docs/rules/no-commented-out-code.md

Add it to your ESLint config

rules: {
  "etc/no-commented-out-code": "error"
}
Sussman answered 11/4, 2023 at 10:47 Comment(0)
T
1

I have created a plugin for that purpose:

Install

npm install eslint-plugin-no-comments --save-dev

Configuration

// eslintrc.js
{
    "plugins": ["eslint-plugin-no-comments"],
    "rules": {
        "eslint-plugin-no-comments/disallowComments": "error"
    }
}

Full Documentation

Tierell answered 27/8, 2021 at 0:47 Comment(1)
Looks like package was updated // eslintrc.js { "plugins": ["no-comments"], "rules": { "no-comments/disallowComments": "error" } } worked for meBrightman
V
0

So I found the way to consider the code commented rule for Sonar. It is just a matter of Quality Profile.I had set the DEFAULT profile to sonar-way but it has only 100 rules specified.

While the other profile available for JAVASCRIPT is Sonar way Recommended which has 148 rules and it also includes the rule to identify the code commented.

So switching the default profile to Sonar Way Recommended had the default rule to identify the commented code for multi-line or single line code.

enter image description here

Vanna answered 26/8, 2020 at 13:1 Comment(0)
S
-1

Maybe you can try no-inline-comments ESLint rule

https://eslint.org/docs/rules/no-inline-comments

Slur answered 20/8, 2020 at 11:40 Comment(1)
It will only give me the warning in case of disallowing comments on the same line as code.Vanna

© 2022 - 2024 — McMap. All rights reserved.