该存储库包含eslint-plugin-sonarjs到版本^1.0.0 。对于版本>=2.0.0请转到Sonarjs分析仪的存储库。 eslint-plugin-sonarjs的新版本使所有Sonarjs规则都可用于Eslint用户,而不是^1.0.0居住在这里的子集。
预计不会在这里降落新的变化。
Sonarjs的ESLINT规则,可以通过检测错误和可疑模式来帮助开发人员生成干净的代码。
此类别中的规则旨在找到有很大机会成为错误的代码中的位置,即不按预期工作。
no-all-duplicated-branches )no-element-overwrite )no-empty-collection )no-extra-arguments )no-identical-conditions )no-identical-expressions )no-ignored-return )(使用类型)no-one-iteration-loop )no-use-of-empty-return-value )non-existent-operator )(:扳手:固定)代码气味或可维护性问题是针对代码景点提出的,这可能会在将来变化昂贵。这些规则还有助于保持高码质量和可读性。最后,一些规则报告了有关不同可疑代码模式的问题。
cognitive-complexity )elseif-without-else )(禁用)max-switch-cases )no-collapsible-if )no-collection-size-mischeck )(:扳手:可固定,用途类型)no-duplicate-string )no-duplicated-branches )no-gratuitous-expressions )no-identical-functions )no-inverted-boolean-check )(:扳手:可固定,禁用)no-nested-switch )no-nested-template-literals )no-redundant-boolean )no-redundant-jump )(:扳手:固定)no-same-line-conditional )开始(:扳手:固定)no-small-switch )no-unused-collection )no-useless-catch )prefer-immediate-return )(:扳手:可固定)prefer-object-literal )prefer-single-boolean-return )(:wrench: fixable )prefer-while )(:扳手:可固定) npm (或yarn )为您的项目或全球安装eslint-plugin-sonarjs : npm install eslint-plugin-sonarjs --save-dev # install for your project
npm install eslint-plugin-sonarjs -g # or install globallyeslint-plugin-sonarjs添加到Eslint配置的插件中。对于ESLINT 9:将plugins选项添加到您的eslint.config.js ,并包含推荐的配置以启用所有规则:
import sonarjs from "eslint-plugin-sonarjs";
[
sonarjs.configs.recommended,
{
"plugins": {
sonarjs,
}
}
]
对于ESLINT 8:将plugins选项添加到您的.eslintrc和plugin:sonarjs/recommended-legacy到extends选项,以启用所有建议的规则:
{
"plugins" : [ " sonarjs " ],
"extends" : [ " plugin:sonarjs/recommended-legacy " ]
}{
"rules" : {
"sonarjs/cognitive-complexity" : " error " ,
"sonarjs/no-identical-expressions" : " error "
// etc.
}
}@typescript-eslint/parser作为ESLINT的解析器(像我们一样),并设置ParseRoptions.Project选项。因此,可以使用类型信息,这对于某些规则是有益的,甚至是必不可少的。 该插件仅提供recommended配置。几乎所有规则都在此配置文件中激活,但有一些例外(检查规则列表中的disabled标签)。 recommended配置会激活具有error严重性的规则。我们包括recommended-legacy配置,该配置与ESLINT V8兼容,并具有相同的规则配置。
该插件向Eslint用户展示了Sonar-*产品(又称Sonarjs)的JS/TS规则的子集。我们提取了Eslint Core或其他ESLINT插件中无法使用的规则,以对ESLINT社区有益。
如果您是Sonarqube或Sonarcloud用户,请在本地填写代码,我们建议使用Sonarlint IDE扩展名(可用于VSCODE,JETBRAINS IDES和ECLIPSE)。您可以将声音连接到Sonarqube/Sonarcloud项目以同步规则配置,发行状态等。
您想参加该项目的开发吗?看看我们的贡献指南!