声纳 C# 的禁用规则
Disable rule for Sonar C#
我想为我的 Codacy 项目禁用 Sonar C# 的某些规则。根据 SonarQube 文档,我必须创建一个 .editorconfig
文件,所以我做了:
[*.cs]
dotnet_diagnostic.S121.severity = none
dotnet_diagnostic.S3216.severity = none
但是,Codacy 似乎没有提取 .editorconfig
文件 - 至少应该禁用的警告仍然存在。
我需要做什么才能禁用 Sonar C# 的某些规则?
谢谢!
我也在 Codacy 的论坛 (see here) 上问过这个问题。这是我得到的答案:
Basically, the SonarLint.xml file should contain all and only the rules that you want to use in your repository.
One of our engineers developed a script that’s going to the public repository codacy-sonar-csharp, fetches all the patterns used by default in Codacy’s Sonar tool, and creates a SonarLint.xml file with them.
这里是提到的脚本:
#!/bin/env bash
container_id=$(docker create codacy-csharp:latest)
codacy_rules_file=/tmp/codacy-rules.json
# get all the rules defined for the tool from inside the docker container
docker cp $container_id:/docs/patterns.json $codacy_rules_file
docker rm $container_id
# obtain all ids of the rules we have enabled by default
rules_ids=$(cat $codacy_rules_file | jq -r '.patterns[] | select (.enabled == true) | .patternId')
cat << EOF > SonarLint.xml
<?xml version="1.0" encoding="UTF-8"?>
<AnalysisInput>
<Rules>
EOF
for rule_id in $rules_ids
do
echo -e "\t<Rule>\n\t\t<Key>$rule_id</Key>\n\t</Rule>\n" >> SonarLint.xml
done
cat << EOF >> SonarLint.xml
</Rules>
</AnalysisInput>
EOF
我想为我的 Codacy 项目禁用 Sonar C# 的某些规则。根据 SonarQube 文档,我必须创建一个 .editorconfig
文件,所以我做了:
[*.cs]
dotnet_diagnostic.S121.severity = none
dotnet_diagnostic.S3216.severity = none
但是,Codacy 似乎没有提取 .editorconfig
文件 - 至少应该禁用的警告仍然存在。
我需要做什么才能禁用 Sonar C# 的某些规则?
谢谢!
我也在 Codacy 的论坛 (see here) 上问过这个问题。这是我得到的答案:
Basically, the SonarLint.xml file should contain all and only the rules that you want to use in your repository. One of our engineers developed a script that’s going to the public repository codacy-sonar-csharp, fetches all the patterns used by default in Codacy’s Sonar tool, and creates a SonarLint.xml file with them.
这里是提到的脚本:
#!/bin/env bash
container_id=$(docker create codacy-csharp:latest)
codacy_rules_file=/tmp/codacy-rules.json
# get all the rules defined for the tool from inside the docker container
docker cp $container_id:/docs/patterns.json $codacy_rules_file
docker rm $container_id
# obtain all ids of the rules we have enabled by default
rules_ids=$(cat $codacy_rules_file | jq -r '.patterns[] | select (.enabled == true) | .patternId')
cat << EOF > SonarLint.xml
<?xml version="1.0" encoding="UTF-8"?>
<AnalysisInput>
<Rules>
EOF
for rule_id in $rules_ids
do
echo -e "\t<Rule>\n\t\t<Key>$rule_id</Key>\n\t</Rule>\n" >> SonarLint.xml
done
cat << EOF >> SonarLint.xml
</Rules>
</AnalysisInput>
EOF