@ServerSide @ComputeEngineSide @SonarLintSide @ExtensionPoint public interface RulesDefinition
public class MyJsRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context.createRepository("my_js", "js").setName("My Javascript Analyzer"); // define a rule programmatically. Note that rules // could be loaded from files (JSON, XML, ...) NewRule x1Rule = repository.createRule("x1") .setName("No empty line") .setHtmlDescription("Generate an issue on empty lines") // optional tags .setTags("style", "stupid") // optional status. Default value is READY. .setStatus(RuleStatus.BETA) // default severity when the rule is activated on a Quality profile. Default value is MAJOR. .setSeverity(Severity.MINOR); // optional type for SonarQube Quality Model. Default is RulesDefinition.Type.CODE_SMELL. .setType(RulesDefinition.Type.BUG) x1Rule .setDebtRemediationFunction(x1Rule.debtRemediationFunctions().linearWithOffset("1h", "30min")); x1Rule.createParam("acceptWhitespace") .setDefaultValue("false") .setType(RuleParamType.BOOLEAN) .setDescription("Accept whitespaces on the line"); // don't forget to call done() to finalize the definition repository.done(); } }
RulesDefinitionXmlLoader
), then it can be loaded by using :
public class MyJsRulesDefinition implements RulesDefinition { private final RulesDefinitionXmlLoader xmlLoader; public MyJsRulesDefinition(RulesDefinitionXmlLoader xmlLoader) { this.xmlLoader = xmlLoader; } @Override public void define(Context context) { NewRepository repository = context.createRepository("my_js", "js").setName("My Javascript Analyzer"); // see javadoc of RulesDefinitionXmlLoader for the format xmlLoader.load(repository, getClass().getResourceAsStream("/path/to/rules.xml")); repository.done(); } }
public class MyJsRulesDefinition implements RulesDefinition { private final RulesDefinitionXmlLoader xmlLoader; private final RulesDefinitionI18nLoader i18nLoader; public MyJsRulesDefinition(RulesDefinitionXmlLoader xmlLoader, RulesDefinitionI18nLoader i18nLoader) { this.xmlLoader = xmlLoader; this.i18nLoader = i18nLoader; } @Override public void define(Context context) { NewRepository repository = context.createRepository("my_js", "js").setName("My Javascript Analyzer"); xmlLoader.load(repository, getClass().getResourceAsStream("/path/to/rules.xml"), "UTF-8"); i18nLoader.load(repository); repository.done(); } }
Modifier and Type | Interface and Description |
---|---|
static class |
RulesDefinition.Context
Instantiated by core but not by plugins, except for their tests.
|
static interface |
RulesDefinition.DebtRemediationFunctions
Factory of
DebtRemediationFunction . |
static interface |
RulesDefinition.ExtendedRepository |
static interface |
RulesDefinition.NewExtendedRepository |
static class |
RulesDefinition.NewParam |
static interface |
RulesDefinition.NewRepository |
static class |
RulesDefinition.NewRepositoryImpl |
static class |
RulesDefinition.NewRule |
static class |
RulesDefinition.Param |
static interface |
RulesDefinition.Repository |
static class |
RulesDefinition.RepositoryImpl |
static class |
RulesDefinition.Rule |
static class |
RulesDefinition.SubCharacteristics
Deprecated.
in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
See https://jira.sonarsource.com/browse/MMF-184
|
Modifier and Type | Method and Description |
---|---|
void |
define(RulesDefinition.Context context)
This method is executed when server is started.
|
void define(RulesDefinition.Context context)