增加注释

wuhaoyang
Guo XIn 11 months ago
parent 102558ec39
commit 0dabc96154
  1. 9
      sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/SecurityDesignRuleRepository.java
  2. 17
      sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/ABCVarNameChecker.java
  3. 2
      sonar-keyware-plugins-java/src/main/java/com/keyware/sonar/java/rules/JavaSecurityDesignRulesRepository.java

@ -15,19 +15,22 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
* TODO SecurityDesignRuleRepository * 信息安全性设计准则规则仓库定义实现类
* *
* @author GuoXin * @author GuoXin
* @date 2024/1/9 * @date 2024/1/9
*/ */
public class SecurityDesignRuleRepository implements RulesDefinition { public class SecurityDesignRuleRepository implements RulesDefinition {
private final String REPOSITORY_NAME = "C++信息安全性设计准则"; private final String REPOSITORY_NAME = "C++信息安全性设计准则";
private final List<Class> RULES_DEFINITIONS = Arrays.asList(ABCVarNameChecker.class);
// 规则检查器的集合,当有新的规则开发完毕后,需要添加到下面的集合中
private final List<Class> RULE_CHECKERS = Arrays.asList(ABCVarNameChecker.class);
@Override @Override
public void define(Context context) { public void define(Context context) {
var repository = context.createRepository("cxx-security-design-rules", CxxLanguage.KEY). var repository = context.createRepository("cxx-security-design-rules", CxxLanguage.KEY).
setName(REPOSITORY_NAME); setName(REPOSITORY_NAME);
new AnnotationBasedRulesDefinition(repository, CxxLanguage.KEY).addRuleClasses(false, RULES_DEFINITIONS); new AnnotationBasedRulesDefinition(repository, CxxLanguage.KEY).addRuleClasses(false, RULE_CHECKERS);
repository.done(); repository.done();
} }
} }

@ -10,17 +10,15 @@ import com.sonar.cxx.sslr.api.AstNode;
import com.sonar.cxx.sslr.api.Grammar; import com.sonar.cxx.sslr.api.Grammar;
import org.sonar.check.Priority; import org.sonar.check.Priority;
import org.sonar.check.Rule; import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.cxx.parser.CxxGrammarImpl; import org.sonar.cxx.parser.CxxGrammarImpl;
import org.sonar.cxx.squidbridge.annotations.ActivatedByDefault; import org.sonar.cxx.squidbridge.annotations.ActivatedByDefault;
import org.sonar.cxx.squidbridge.annotations.SqaleConstantRemediation; import org.sonar.cxx.squidbridge.annotations.SqaleConstantRemediation;
import org.sonar.cxx.squidbridge.checks.SquidCheck; import org.sonar.cxx.squidbridge.checks.SquidCheck;
import static com.sonar.cxx.sslr.api.GenericTokenType.IDENTIFIER; import static com.sonar.cxx.sslr.api.GenericTokenType.IDENTIFIER;
import static javax.swing.Action.DEFAULT;
/** /**
* TODO ABCVarNameChecker * C++规则检查器的实现示例
* *
* @author GuoXin * @author GuoXin
* @date 2024/1/6 * @date 2024/1/6
@ -29,20 +27,23 @@ import static javax.swing.Action.DEFAULT;
@ActivatedByDefault @ActivatedByDefault
@SqaleConstantRemediation("5min") @SqaleConstantRemediation("5min")
public class ABCVarNameChecker extends SquidCheck<Grammar> { public class ABCVarNameChecker extends SquidCheck<Grammar> {
/** /**
* format * 初始化规则检查器
*/ */
@RuleProperty(
key = "format",
defaultValue = "" + DEFAULT)
public String format = DEFAULT;
@Override @Override
public void init() { public void init() {
// 订阅要检查AST节点类型,用于在visitNode方法中检查该类型节点
this.subscribeTo( this.subscribeTo(
CxxGrammarImpl.declaratorId CxxGrammarImpl.declaratorId
); );
} }
/**
* 检查AST节点
*
* @param astNode 要处理的AST节点该节点类型为通过subscribeTo方法订阅的类型
*/
@Override @Override
public void visitNode(AstNode astNode) { public void visitNode(AstNode astNode) {
var idNode = astNode.getLastChild(IDENTIFIER); var idNode = astNode.getLastChild(IDENTIFIER);

@ -30,7 +30,7 @@ public class JavaSecurityDesignRulesRepository implements RulesDefinition {
private static final String RESOURCE_BASE_PATH = "org/sonar/l10n/java/rules/java"; private static final String RESOURCE_BASE_PATH = "org/sonar/l10n/java/rules/java";
public static final String REPOSITORY_KEY = "keyware-java-security-design"; public static final String REPOSITORY_KEY = "keyware-java-security-design";
public static final String REPOSITORY_NAME = "Java安全性设计准则"; public static final String REPOSITORY_NAME = "Java信息安全性设计准则";
// 添加需要视为模板规则的规则的规则键 // 添加需要视为模板规则的规则的规则键
private static final Set<String> RULE_TEMPLATES_KEY = Collections.emptySet(); private static final Set<String> RULE_TEMPLATES_KEY = Collections.emptySet();

Loading…
Cancel
Save