@Test public void can_disable_rules() { NoSonarCollector collector = new NoSonarCollector(); TestOpenApiVisitorRunner.scanFile(new File(NoSonarCollectorTest.class.getResource("/nosonar-test.yaml").getFile()), collector); assertThat(collector.isEnabled("/info/license", "RuleId1")).isFalse(); assertThat(collector.isEnabled("/info/license", "RuleId3")).isTrue(); assertThat(collector.isEnabled("/paths/~1pets/get", "RuleId1")).isTrue(); assertThat(collector.isEnabled("/paths/~1pets/get", "RuleId3")).isTrue(); assertThat(collector.isEnabled("/paths/~1pets/get/parameters/1", "RuleId3")).isFalse(); }
public boolean isEnabled(String pointer, String ruleId) { Set<String> enabled = enabledByPointer.getOrDefault(pointer, Collections.emptySet()); Set<String> disabled = disabledByPointer.getOrDefault(pointer, Collections.emptySet()); if (globallyDisabled.contains(ruleId)) { return enabled.contains(ruleId); } return !disabled.contains(ruleId) || enabled.contains(ruleId); }
NoSonarCollector extends OpenApiVisitor { public boolean isEnabled(String pointer, String ruleId) { Set<String> enabled = enabledByPointer.getOrDefault(pointer, Collections.emptySet()); Set<String> disabled = disabledByPointer.getOrDefault(pointer, Collections.emptySet()); if (globallyDisabled.contains(ruleId)) { return enabled.contains(ruleId); } return !disabled.contains(ruleId) || enabled.contains(ruleId); } }
NoSonarCollector extends OpenApiVisitor { public boolean isEnabled(String pointer, String ruleId) { Set<String> enabled = enabledByPointer.getOrDefault(pointer, Collections.emptySet()); Set<String> disabled = disabledByPointer.getOrDefault(pointer, Collections.emptySet()); if (globallyDisabled.contains(ruleId)) { return enabled.contains(ruleId); } return !disabled.contains(ruleId) || enabled.contains(ruleId); }  }
NoSonarCollector extends OpenApiVisitor { public boolean isEnabled(String pointer, String ruleId) { Set<String> enabled = enabledByPointer.getOrDefault(pointer, Collections.emptySet()); Set<String> disabled = disabledByPointer.getOrDefault(pointer, Collections.emptySet()); if (globallyDisabled.contains(ruleId)) { return enabled.contains(ruleId); } return !disabled.contains(ruleId) || enabled.contains(ruleId); }  boolean isEnabled(String pointer, String ruleId); }
NoSonarCollector extends OpenApiVisitor { public boolean isEnabled(String pointer, String ruleId) { Set<String> enabled = enabledByPointer.getOrDefault(pointer, Collections.emptySet()); Set<String> disabled = disabledByPointer.getOrDefault(pointer, Collections.emptySet()); if (globallyDisabled.contains(ruleId)) { return enabled.contains(ruleId); } return !disabled.contains(ruleId) || enabled.contains(ruleId); }  boolean isEnabled(String pointer, String ruleId);  }