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

javascript - ESLint rule to block users from disabling ESLint rules - Stack Overflow

programmeradmin1浏览0评论

I have a project with very few ESLint rules that are mandatory for all the collaborators, unfortunately, I've found some developers have disabled some rules with no justification and the Code Review failed to stop this. Is there a way to configure ESLint to ignore ments disabling rules or for it to throw warnings whenever this happens?

I've been looking for a while and haven't found anything of the sort. Is there maybe another way to do this?

I have a project with very few ESLint rules that are mandatory for all the collaborators, unfortunately, I've found some developers have disabled some rules with no justification and the Code Review failed to stop this. Is there a way to configure ESLint to ignore ments disabling rules or for it to throw warnings whenever this happens?

I've been looking for a while and haven't found anything of the sort. Is there maybe another way to do this?

Share Improve this question asked Sep 22, 2020 at 1:36 RichySTRichyST 2731 gold badge3 silver badges12 bronze badges 3
  • gitlab enterprise and github team has the feature to lock the .eslintrc file so no one has permission to change it – arslan2012 Commented Sep 22, 2020 at 2:16
  • 1 @arslan2012 I'm specifically referring to the ments /* eslint-disable */ put in files by other programmers – RichyST Commented Sep 22, 2020 at 2:35
  • You can probably add a checklist in the PR template and have an item stating that you should do you best to lint your code or at least leave ments for code where an eslint-disable is used. – Joshua Commented Sep 22, 2020 at 3:57
Add a ment  | 

2 Answers 2

Reset to default 17

Wow, very cool scenario. But I feel sorry for the developers who might want to kick me for answering this. Follow the below steps

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

in your .eslintrc.* file add

{
    "extends": [
        "eslint:remended",
        "plugin:eslint-ments/remended"
    ],
    "rules": {
        "eslint-ments/no-use": ["error", {"allow": []}]
    }
}

For more info check this link https://mysticatea.github.io/eslint-plugin-eslint-ments/rules/no-use.html

If you don't want to add an additional plugin, you can use eslint's no-warning-ments rule to achieve this. Add the following line under rules in your eslint config file to disable eslint-disable term in ments which has the same effect.

"no-warning-ments": ["warn", { "terms": ["eslint-disable"], "location": "anywhere" }]
发布评论

评论列表(0)

  1. 暂无评论