最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ES-Lint Rule or Plugin to identify the commented code - Stack Overflow

programmeradmin1浏览0评论

I'm trying to find the rules or plugins of ES-Lint to identify the mented 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-ments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "anywhere" }],
        "spaced-ment": ["error", "always", { "exceptions": ["-", "+"] }]
    }

I'm trying to find the rules or plugins of ES-Lint to identify the mented 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-ments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "anywhere" }],
        "spaced-ment": ["error", "always", { "exceptions": ["-", "+"] }]
    }
Share Improve this question asked Aug 20, 2020 at 11:36 HarshalHarshal 3,6229 gold badges39 silver badges67 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

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

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

Add it to your ESLint config

rules: {
  "etc/no-mented-out-code": "error"
}

I have created a plugin for that purpose:

Install

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

Configuration

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

Full Documentation

So I found the way to consider the code mented 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 Remended which has 148 rules and it also includes the rule to identify the code mented.

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

Maybe you can try no-inline-ments ESLint rule

https://eslint/docs/rules/no-inline-ments

发布评论

评论列表(0)

  1. 暂无评论