Search in sources :

Example 1 with RuleGroup

use of com.cflint.config.CFLintPluginInfo.RuleGroup in project CFLint by cflint.

the class CFLintMain method listRuleGroups.

/**
     * List the rule groups
     * 
     * @param pluginInfo
     */
private static void listRuleGroups(CFLintPluginInfo pluginInfo) {
    Map<String, PluginMessage> allCodes = new LinkedHashMap<String, PluginMessage>();
    for (PluginInfoRule rule : pluginInfo.getRules()) {
        for (PluginMessage msg : rule.getMessages()) {
            allCodes.put(msg.getCode(), msg);
        }
    }
    for (RuleGroup ruleGroup : pluginInfo.getRuleGroups()) {
        System.out.println("Rule Group : " + ruleGroup.getName());
        for (PluginMessage msg : ruleGroup.getMessages()) {
            System.out.println("\t" + msg.getCode() + " : " + msg.getSeverity());
            allCodes.remove(msg.getCode());
        }
    }
    if (!allCodes.isEmpty()) {
        System.out.println("Rule Group : UNASSIGNED");
        for (PluginMessage msg : allCodes.values()) {
            System.out.println("\t" + msg.getCode() + " : " + msg.getSeverity());
        }
    }
}
Also used : PluginMessage(com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage) PluginInfoRule(com.cflint.config.CFLintPluginInfo.PluginInfoRule) RuleGroup(com.cflint.config.CFLintPluginInfo.RuleGroup) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with RuleGroup

use of com.cflint.config.CFLintPluginInfo.RuleGroup in project CFLint by cflint.

the class CFLintDoc method generateRuleMarkDown.

public static void generateRuleMarkDown(final CFLintPluginInfo pluginInfo, final PrintWriter print) {
    final Map<String, String> descriptions = ConfigUtils.loadDescriptions();
    final List<String> diminishParms = Arrays.asList("UnusedLocalVarChecker", "CFXTagChecker", "FunctionXChecker");
    print.println("List of built-in rules and rule groups");
    print.println("======================================");
    print.println("## Rule Parameters ");
    for (PluginInfoRule ruleInfo : pluginInfo.getRules()) {
        // Do not highlight specific parameters.
        if (!diminishParms.contains(ruleInfo.getClassName())) {
            for (PluginParameter p : ruleInfo.getParameters()) {
                print.println("<br>" + ruleInfo.getName() + "." + p.getName() + " = *" + p.getValue() + "*");
            }
        }
    }
    print.println("## Built-in rules");
    for (PluginInfoRule ruleInfo : pluginInfo.getRules()) {
        print.println("* " + ruleInfo.getName());
        final String className = ruleInfo.getClassName() == null ? ruleInfo.getName() : ruleInfo.getClassName();
        final String fullClassName = className.contains(".") ? className : "com.cflint.plugins.core." + className;
        // print.println("**Class:** "+fullClassName);
        if (!ruleInfo.getParameters().isEmpty()) {
            print.println("    * Parameters");
            for (PluginParameter p : ruleInfo.getParameters()) {
                print.println("        * " + p.getName() + " = *" + p.getValue() + "*");
            }
        }
        int counter = 1;
        for (PluginMessage msg : ruleInfo.getMessages()) {
            final String desc = descriptions.get(msg.getCode()) != null ? descriptions.get(msg.getCode()).replace(">", "&gt;").replace("<", "&lt;") : "";
            print.println("    * " + msg.getCode() + " - " + desc + "  *" + msg.getSeverity() + "*");
            print.println("        * " + cleanUpMessage(msg, ruleInfo));
        }
    }
    print.println("## Rule Groups");
    for (final RuleGroup ruleGroup : pluginInfo.getRuleGroups()) {
        print.println("### " + ruleGroup.getName());
        for (final PluginMessage msg : ruleGroup.getMessages()) {
            print.println(" * " + msg.getCode() + "   *" + msg.getSeverity() + "*");
        }
    }
}
Also used : PluginMessage(com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage) PluginInfoRule(com.cflint.config.CFLintPluginInfo.PluginInfoRule) PluginParameter(com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginParameter) RuleGroup(com.cflint.config.CFLintPluginInfo.RuleGroup)

Example 3 with RuleGroup

use of com.cflint.config.CFLintPluginInfo.RuleGroup in project CFLint by cflint.

the class CFLintDoc method generateRuleGroup.

public static void generateRuleGroup(final CFLintPluginInfo pluginInfo, final PrintWriter print) {
    final Map<String, PluginMessage> allCodes = new LinkedHashMap<>();
    for (final PluginInfoRule rule : pluginInfo.getRules()) {
        for (final PluginMessage msg : rule.getMessages()) {
            allCodes.put(msg.getCode(), msg);
        }
    }
    for (final RuleGroup ruleGroup : pluginInfo.getRuleGroups()) {
        print.println("Rule Group : " + ruleGroup.getName());
        for (final PluginMessage msg : ruleGroup.getMessages()) {
            print.println("\t" + msg.getCode() + " : " + msg.getSeverity());
            allCodes.remove(msg.getCode());
        }
    }
    if (!allCodes.isEmpty()) {
        print.println("Rule Group : UNASSIGNED");
        for (final PluginMessage msg : allCodes.values()) {
            print.println("\t" + msg.getCode() + " : " + msg.getSeverity());
        }
    }
}
Also used : PluginMessage(com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage) PluginInfoRule(com.cflint.config.CFLintPluginInfo.PluginInfoRule) RuleGroup(com.cflint.config.CFLintPluginInfo.RuleGroup) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with RuleGroup

use of com.cflint.config.CFLintPluginInfo.RuleGroup in project CFLint by cflint.

the class TestCFLintConfig method testRuleGroups.

@Test
public /**
 * Test the round trip of the config json file including rule groups.
 *
 * @throws JsonGenerationException
 * @throws JsonMappingException
 * @throws IOException
 */
void testRuleGroups() throws JsonGenerationException, JsonMappingException, IOException {
    CFLintPluginInfo config = new CFLintPluginInfo();
    PluginInfoRule rule = new CFLintPluginInfo.PluginInfoRule();
    config.getRules().add(rule);
    rule.setName("OPM");
    PluginMessage message = new PluginMessage();
    rule.getMessages().add(message);
    message.setCode("MyCode");
    message.setMessageText("messageText");
    message.setSeverity(Levels.WARNING);
    RuleGroup ruleGroup = new RuleGroup("r1");
    ruleGroup.setDefaultSeverity(Levels.INFO);
    ruleGroup.getMessages().add(message);
    config.getRuleGroups().add(ruleGroup);
    RuleGroup ruleGroup2 = new RuleGroup("r2");
    config.getRuleGroups().add(ruleGroup2);
    String jsonText = ConfigUtils.marshalJson(config);
    CFLintPluginInfo backConfig = ConfigUtils.unmarshalJson(jsonText, CFLintPluginInfo.class);
    assertEquals("MyCode", backConfig.getRules().get(0).getMessages().get(0).getCode());
    assertEquals("messageText", backConfig.getRules().get(0).getMessages().get(0).getMessageText());
    assertEquals("MyCode", backConfig.getRuleGroups().get(0).getMessages().get(0).getCode());
    assertEquals("messageText", backConfig.getRuleGroups().get(0).getMessages().get(0).getMessageText());
    assertEquals(Levels.INFO, backConfig.getRuleGroups().get(0).getDefaultSeverity());
}
Also used : PluginMessage(com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage) PluginInfoRule(com.cflint.config.CFLintPluginInfo.PluginInfoRule) RuleGroup(com.cflint.config.CFLintPluginInfo.RuleGroup) Test(org.junit.Test)

Aggregations

PluginInfoRule (com.cflint.config.CFLintPluginInfo.PluginInfoRule)4 PluginMessage (com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage)4 RuleGroup (com.cflint.config.CFLintPluginInfo.RuleGroup)4 LinkedHashMap (java.util.LinkedHashMap)2 PluginParameter (com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginParameter)1 Test (org.junit.Test)1