【问题标题】:ES-Lint Rule or Plugin to identify the commented codeESLint Rule 或 Plugin 来识别被注释的代码
【发布时间】:2020-12-09 17:44:24
【问题描述】:

我正在尝试查找 ES-Lint 的规则或插件来识别注释代码,以便我可以删除那些不必要的代码并清理我的存储库。

我想识别多行代码和单行代码:

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

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

我尝试了以下规则 Bt 它没有识别上述类型的代码:

"rules": {
        "no-warning-comments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "anywhere" }],
        "spaced-comment": ["error", "always", { "exceptions": ["-", "+"] }]
    }

【问题讨论】:

    标签: javascript reactjs eslint eslint-config-airbnb


    【解决方案1】:

    也许你可以试试no-inline-comments ESLint 规则

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

    【讨论】:

    • 它只会在不允许 cmets 与代码位于同一行的情况下给我警告。
    【解决方案2】:

    所以我找到了考虑 Sonar 的代码注释规则的方法。这只是质量配置文件的问题。我已将 DEFAULT 配置文件设置为 sonar-way,但它只指定了 100 条规则。

    而其他可用于 JAVASCRIPT 的配置文件是 Sonar way Recommended,它有 148 条规则,它还包括识别注释代码的规则。

    因此,将默认配置文件切换为Sonar Way Recommended具有识别多行代码或单行代码的注释代码的默认规则。

    【讨论】:

      【解决方案3】:

      我为此创建了一个插件:

      安装

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

      配置

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

      Full Documentation

      【讨论】:

        猜你喜欢
        • 2023-03-14
        • 2011-08-25
        • 1970-01-01
        • 2021-01-26
        • 1970-01-01
        • 2021-11-22
        • 1970-01-01
        • 2013-09-13
        • 2016-10-08
        相关资源
        最近更新 更多