newSquid1.setDescription("Detect potential bug"); newSquid1.setInternalKey("foo=bar"); newSquid1.setSeverity(Severity.CRITICAL); newSquid1.setStatus(RuleStatus.BETA); newSquid1.addParam("min");
public Rules provide(Sonarlint.Rules storageRules) { if (rules == null) { RulesBuilder builder = new RulesBuilder(); for (Map.Entry<String, Sonarlint.Rules.Rule> entry : storageRules.getRulesByKeyMap().entrySet()) { Sonarlint.Rules.Rule r = entry.getValue(); NewRule newRule = builder.add(RuleKey.of(r.getRepo(), r.getKey())) .setName(r.getName()) .setInternalKey(r.getInternalKey()) .setSeverity(r.getSeverity()) .setDescription(r.getHtmlDesc()); if (StringUtils.isNotEmpty(r.getType())) { newRule.setType(r.getType()); } } rules = builder.build(); } return rules; }
private Rules load(RuleDao ruleDao, DefaultDebtModel debtModel, Durations durations) { RulesBuilder rulesBuilder = new RulesBuilder(); List<RuleParamDto> ruleParamDtos = ruleDao.selectParameters(); ListMultimap<Integer, RuleParamDto> paramDtosByRuleId = ArrayListMultimap.create(); for (RuleParamDto dto : ruleParamDtos) { paramDtosByRuleId.put(dto.getRuleId(), dto); } for (RuleDto ruleDto : ruleDao.selectEnablesAndNonManual()) { RuleKey ruleKey = RuleKey.of(ruleDto.getRepositoryKey(), ruleDto.getRuleKey()); NewRule newRule = rulesBuilder.add(ruleKey) .setId(ruleDto.getId()) .setName(ruleDto.getName()) .setSeverity(ruleDto.getSeverityString()) .setDescription(ruleDto.getDescription()) .setStatus(ruleDto.getStatus()) .setInternalKey(ruleDto.getConfigKey()); if (hasCharacteristic(ruleDto)) { newRule.setDebtSubCharacteristic(effectiveCharacteristic(ruleDto, ruleKey, debtModel).key()); newRule.setDebtRemediationFunction(effectiveFunction(ruleDto, ruleKey, durations)); } for (RuleParamDto ruleParamDto : paramDtosByRuleId.get(ruleDto.getId())) { newRule.addParam(ruleParamDto.getName()) .setDescription(ruleParamDto.getDescription()); } } return rulesBuilder.build(); }
private static Rules createRules(StandaloneRuleDefinitionsLoader pluginRulesLoader) { RulesBuilder builder = new RulesBuilder(); for (RulesDefinition.Repository repoDef : pluginRulesLoader.getContext().repositories()) { for (RulesDefinition.Rule ruleDef : repoDef.rules()) { if (ruleDef.type() == RuleType.SECURITY_HOTSPOT) { continue; } NewRule newRule = builder.add(RuleKey.of(ruleDef.repository().key(), ruleDef.key())) .setInternalKey(ruleDef.internalKey()) .setDescription(ruleDef.htmlDescription() != null ? ruleDef.htmlDescription() : Markdown.convertToHtml(ruleDef.markdownDescription())) .setSeverity(ruleDef.severity()) .setType(ruleDef.type() != null ? ruleDef.type().toString() : null) .setName(ruleDef.name()); for (Param p : ruleDef.params()) { newRule.addParam(p.key()) .setDescription(p.description()); } } } return builder.build(); } }