Skip to content

Commit

Permalink
Merge pull request #35 from donhui/bugfix-0513
Browse files Browse the repository at this point in the history
bugfix: can't create issue
  • Loading branch information
donhui authored May 13, 2022
2 parents c16e7ac + 4b35987 commit ac17c04
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/sonarsource/plugins/mybatis/Constant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sonarsource.plugins.mybatis;

public class Constant {
public static String MYBATIS_MAPPER_CHECK_RULE_01 = "MyBatisMapperCheckRule01";
public static String MYBATIS_MAPPER_CHECK_RULE_02 = "MyBatisMapperCheckRule02";
public static String MYBATIS_MAPPER_CHECK_RULE_03 = "MyBatisMapperCheckRule03";
public static String MYBATIS_MAPPER_CHECK_RULE_04 = "MyBatisMapperCheckRule04";
public static String MYBATIS_MAPPER_CHECK_RULE_05 = "MyBatisMapperCheckRule05";
public static String MYBATIS_MAPPER_CHECK_RULE_06 = "MyBatisMapperCheckRule06";
public static String MYBATIS_MAPPER_CHECK_RULE_07 = "MyBatisMapperCheckRule07";

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.sonar.api.rule.Severity;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
import org.sonar.plugins.xml.Xml;
import org.sonarsource.plugins.mybatis.Constant;

import static org.sonarsource.plugins.mybatis.rules.MyBatisLintRulesDefinition.REPO_KEY;

Expand All @@ -16,26 +17,26 @@ public void define(Context context) {
NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile("MyBatisLint Rules", Xml.KEY);
profile.setDefault(true);

NewBuiltInActiveRule rule1 = profile.activateRule(REPO_KEY, "MyBatisMapperCheckRule01");
rule1.overrideSeverity(Severity.MINOR);
NewBuiltInActiveRule rule01 = profile.activateRule(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_01);
rule01.overrideSeverity(Severity.MINOR);

NewBuiltInActiveRule rule2 = profile.activateRule(REPO_KEY, "MyBatisMapperCheckRule02");
rule2.overrideSeverity(Severity.MAJOR);
NewBuiltInActiveRule rule02 = profile.activateRule(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_02);
rule02.overrideSeverity(Severity.MAJOR);

NewBuiltInActiveRule rule3 = profile.activateRule(REPO_KEY, "MyBatisMapperCheckRule03");
rule3.overrideSeverity(Severity.CRITICAL);
NewBuiltInActiveRule rule03 = profile.activateRule(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_03);
rule03.overrideSeverity(Severity.CRITICAL);

NewBuiltInActiveRule rule4 = profile.activateRule(REPO_KEY, "MyBatisMapperCheckRule04");
rule4.overrideSeverity(Severity.MINOR);
NewBuiltInActiveRule rule04 = profile.activateRule(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_04);
rule04.overrideSeverity(Severity.MINOR);

NewBuiltInActiveRule rule5 = profile.activateRule(REPO_KEY, "MyBatisMapperCheckRule05");
rule5.overrideSeverity(Severity.MAJOR);
NewBuiltInActiveRule rule05 = profile.activateRule(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_05);
rule05.overrideSeverity(Severity.MAJOR);

NewBuiltInActiveRule rule6 = profile.activateRule(REPO_KEY, "MyBatisMapperCheckRule06");
rule6.overrideSeverity(Severity.CRITICAL);
NewBuiltInActiveRule rule06 = profile.activateRule(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_06);
rule06.overrideSeverity(Severity.CRITICAL);

NewBuiltInActiveRule rule7 = profile.activateRule(REPO_KEY, "MyBatisMapperCheckRule07");
rule7.overrideSeverity(Severity.MINOR);
NewBuiltInActiveRule rule07 = profile.activateRule(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_07);
rule07.overrideSeverity(Severity.MINOR);

profile.done();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package org.sonarsource.plugins.mybatis.rules;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.server.rule.RulesDefinitionXmlLoader;
import org.sonar.plugins.xml.Xml;
import org.sonarsource.plugins.mybatis.Constant;

public final class MyBatisLintRulesDefinition implements RulesDefinition {

public static final String REPO_KEY = "MyBatisLint";
protected static final String REPO_NAME = REPO_KEY;

public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_01 = RuleKey.of(REPO_KEY, "MyBatisMapperCheckRule01");
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_02 = RuleKey.of(REPO_KEY, "MyBatisMapperCheckRule02");
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_03 = RuleKey.of(REPO_KEY, "MyBatisMapperCheckRule03");
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_04 = RuleKey.of(REPO_KEY, "MyBatisMapperCheckRule04");
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_05 = RuleKey.of(REPO_KEY, "MyBatisMapperCheckRule05");
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_06 = RuleKey.of(REPO_KEY, "MyBatisMapperCheckRule06");
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_07 = RuleKey.of(REPO_KEY, "MyBatisMapperCheckRule07");
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_01 = RuleKey.of(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_01);
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_02 = RuleKey.of(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_02);
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_03 = RuleKey.of(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_03);
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_04 = RuleKey.of(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_04);
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_05 = RuleKey.of(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_05);
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_06 = RuleKey.of(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_06);
public static final RuleKey MYBATIS_MAPPER_CHECK_RULE_07 = RuleKey.of(REPO_KEY, Constant.MYBATIS_MAPPER_CHECK_RULE_07);


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.plugins.xml.Xml;
import org.sonarsource.plugins.mybatis.Constant;
import org.sonarsource.plugins.mybatis.utils.IOUtils;
import org.sonarsource.plugins.mybatis.xml.MyBatisMapperXmlHandler;
import org.sonarsource.plugins.mybatis.xml.XmlParser;
Expand Down Expand Up @@ -233,37 +234,37 @@ private void matchRuleAndSaveIssue(String sql, String sourceMapperFilePath, Inte
if (sql.startsWith(DELETE)) {
// delete statement contains 1=1
errorMessage = "delete statement should not include 1=1";
ruleId = "MyBatisMapperCheckRule3";
ruleId = Constant.MYBATIS_MAPPER_CHECK_RULE_03;
} else if (sql.startsWith(UPDATE)) {
// update statement contains 1=1
errorMessage = "update statement should not include 1=1";
ruleId = "MyBatisMapperCheckRule2";
ruleId = Constant.MYBATIS_MAPPER_CHECK_RULE_02;
} else if (sql.startsWith(SELECT) && !containsFunctionOrLimit(sql)) {
// select statement contains 1=1
errorMessage = "select statement should not include 1=1";
ruleId = "MyBatisMapperCheckRule1";
ruleId = Constant.MYBATIS_MAPPER_CHECK_RULE_01;
}
} else if (!sql.contains(WHERE)) {
if (sql.startsWith(DELETE)) {
// Where condition not found in delete statement
errorMessage = "where condition not found in delete statement";
ruleId = "MyBatisMapperCheckRule6";
ruleId = Constant.MYBATIS_MAPPER_CHECK_RULE_06;
} else if (sql.startsWith(UPDATE)) {
// Where condition not found in update statement
errorMessage = "where condition not found in update statement";
ruleId = "MyBatisMapperCheckRule5";
ruleId = Constant.MYBATIS_MAPPER_CHECK_RULE_05;
} else if (sql.startsWith(SELECT) && !containsFunctionOrLimit(sql)) {
// Where condition not found in select statement
errorMessage = "where condition not found in select statement";
ruleId = "MyBatisMapperCheckRule4";
ruleId = Constant.MYBATIS_MAPPER_CHECK_RULE_04;
}
}

if (sql.startsWith(SELECT) && sql.contains(STAR)) {
sql = sql.replace(" ", "");
if (!sql.contains(COUNT_STAR)) {
errorMessage = "select statement should not include *";
ruleId = "MyBatisMapperCheckRule7";
ruleId = Constant.MYBATIS_MAPPER_CHECK_RULE_07;
}
}

Expand Down

0 comments on commit ac17c04

Please sign in to comment.