collector = new DiagnosticCollector<>();
int exit;
diff --git a/java/tests/CheckTestSupport.java b/java/tests/CheckTestSupport.java
index d07596e195..96e320c611 100644
--- a/java/tests/CheckTestSupport.java
+++ b/java/tests/CheckTestSupport.java
@@ -118,9 +118,9 @@ public static String runfile(String variable) {
/**
* Runs the wartremover tiers over a clean fixture, a bug fixture and a style fixture.
*
- * The bug fixture must fail both tiers, the style fixture only the strict tier. The
- * environment names the plugin jar ({@code WARTREMOVER_JAR}) and the tier files; {@code extras}
- * is the strict file of this Scala major.
+ *
Standard is WartRemover's default, which enables no warts, so only the strict tier fails the
+ * bug and style fixtures. The environment names the plugin jar ({@code WARTREMOVER_JAR}) and the
+ * tier files; {@code extras} is the strict file of this Scala major.
*/
public static void wartremoverCheck(
Function, String> check,
@@ -144,8 +144,11 @@ public static void wartremoverCheck(
expect(log.contains("\"diagnostics\":[]"), tier + " warts are silent on clean code", log);
Path bad = write(dir, "wart_" + tier + "/bug/Bug.scala", bug);
log = check.apply(with(List.of("source=" + bad), request));
- expect(log.contains("\"exit\":1"), tier + " warts fail a bug", log);
- expect(log.contains("Null"), tier + " warts name the Null wart", log);
+ expect(
+ log.contains(strict ? "\"exit\":1" : "\"exit\":0"),
+ tier + " warts " + (strict ? "fail" : "accept") + " a bug wart",
+ log);
+ expect(log.contains("Null") == strict, tier + " names the Null wart only when strict", log);
Path odd = write(dir, "wart_" + tier + "/style/Style.scala", style);
log = check.apply(with(List.of("source=" + odd), request));
expect(
diff --git a/java/tests/JavacCheckTest.java b/java/tests/JavacCheckTest.java
index c392801660..640d093fea 100644
--- a/java/tests/JavacCheckTest.java
+++ b/java/tests/JavacCheckTest.java
@@ -84,7 +84,7 @@ private static String runfile(String variable) {
return Path.of(System.getenv("TEST_SRCDIR"), System.getenv(variable)).toString();
}
- /** Error Prone: the standard tier fails real bugs only, the strict tier fails warnings too. */
+ /** Error Prone: standard is the tool default, strict fails warnings too. */
private static void errorProne(Path dir) throws Exception {
Path clean =
write(
@@ -101,8 +101,18 @@ private static void errorProne(Path dir) throws Exception {
dir,
"ep_style/p/Style.java",
"package p;\nfinal class Style {\n void f(boolean b) {\n if (b) return;\n }\n}\n");
+ Path defaultWarning =
+ write(
+ dir,
+ "ep_default_warning/p/Same.java",
+ "package p;\nfinal class Same {\n boolean f(String a, String b) {\n return a == b;\n }\n}\n");
for (String tier : List.of("STANDARD", "STRICT")) {
boolean strict = tier.equals("STRICT");
+ String warned = errorProneCheck(defaultWarning, tier, false);
+ expect(
+ warned.contains("StringEquality"),
+ tier + " reports a check that is a warning by default",
+ warned);
String log = errorProneCheck(clean, tier, strict);
expect(log.contains("\"exit\":0"), tier + " Error Prone accepts clean code", log);
expect(
diff --git a/java/tests/jvm_tiers_test.rs b/java/tests/jvm_tiers_test.rs
index f6a84b029e..b101b20e6e 100644
--- a/java/tests/jvm_tiers_test.rs
+++ b/java/tests/jvm_tiers_test.rs
@@ -51,17 +51,6 @@ const WART_EXCLUDED: &[(&str, &[&str])] = &[
),
];
-const WART_STANDARD: &[&str] = &[
- "ArrayEquals",
- "ArrayToString",
- "EitherProjectionPartial",
- "IterableOps",
- "Null",
- "OptionPartial",
- "Return",
- "TryPartial",
-];
-
fn tier(path: &str) -> String {
let file = resolve_runfiles(&format!("_main/core/quality/tiers/{path}"));
std::fs::read_to_string(&file).unwrap_or_else(|error| panic!("{path}: {error}"))
@@ -139,19 +128,23 @@ fn pmd_jar() -> std::path::PathBuf {
.expect("the PMD distribution has pmd-java")
}
-fn pmd_tier(file: &str) -> Vec {
- ruleset_rules(&tier(file), "ref")
+fn pmd_rule_names(xml: &str, what: &str) -> Vec {
+ ruleset_rules(xml, "ref")
.into_iter()
.map(|(reference, _)| {
reference
.strip_prefix("category/java/")
.and_then(|rest| rest.split_once(".xml/"))
.map(|(category, rule)| format!("{category}/{rule}"))
- .unwrap_or_else(|| panic!("{file}: unexpected rule reference {reference}"))
+ .unwrap_or_else(|| panic!("{what}: unexpected rule reference {reference}"))
})
.collect()
}
+fn pmd_tier(file: &str) -> Vec {
+ pmd_rule_names(&tier(file), file)
+}
+
fn unique(rules: Vec, what: &str) -> Set {
let count = rules.len();
let set: Set = rules.into_iter().collect();
@@ -159,10 +152,6 @@ fn unique(rules: Vec, what: &str) -> Set {
set
}
-fn strings(list: &[&str]) -> Set {
- list.iter().map(|rule| (*rule).to_owned()).collect()
-}
-
fn diff(left: &Set, right: &Set) -> Vec {
left.difference(right).cloned().collect()
}
@@ -217,21 +206,31 @@ fn pmd_strict_is_every_rule_of_the_pinned_pmd_minus_the_documented_exclusions()
}
#[test]
-fn pmd_standard_is_a_bug_only_subset_of_strict() {
- let standard = unique(pmd_tier("pmd/standard.xml"), "standard PMD");
+fn pmd_standard_is_the_pinned_pmds_own_quickstart_ruleset() {
+ let references = ruleset_rules(&tier("pmd/standard.xml"), "ref");
+ assert_eq!(
+ references,
+ [("rulesets/java/quickstart.xml".to_owned(), false)],
+ "standard adds or drops nothing next to the quickstart ruleset"
+ );
+}
+
+#[test]
+fn pmd_strict_keeps_every_rule_of_the_pinned_pmds_quickstart_ruleset() {
+ let quickstart = unique(
+ pmd_rule_names(
+ &jar_entry(&pmd_jar(), "rulesets/java/quickstart.xml"),
+ "quickstart",
+ ),
+ "quickstart PMD",
+ );
+ assert!(!quickstart.is_empty(), "read no quickstart rules");
let strict = unique(pmd_tier("pmd/strict.xml"), "strict PMD");
assert_eq!(
- diff(&standard, &strict),
+ diff(&quickstart, &strict),
Vec::::new(),
- "standard is not inside strict"
+ "strict drops a quickstart rule"
);
- assert!(standard.len() < strict.len());
- for style in ["codestyle/", "documentation/"] {
- assert!(
- !standard.iter().any(|rule| rule.starts_with(style)),
- "standard has {style}"
- );
- }
}
/// `ruleset/Rule` for every rule that a detekt config maps, with whether it is active.
@@ -301,17 +300,26 @@ fn detekt_strict_is_every_rule_of_the_pinned_detekt_minus_the_documented_exclusi
}
#[test]
-fn detekt_standard_is_a_smaller_set_of_the_strict_rules() {
+fn detekt_standard_activates_exactly_the_rules_detekt_activates_by_default() {
+ let default = detekt_rules(
+ &jar_entry(&env_file("DETEKT_JAR"), "default-detekt-config.yml"),
+ "default detekt config",
+ );
+ let standard = detekt_tier("detekt/standard.yml");
+ assert_eq!(active(&standard), active(&default));
+ let names =
+ |rules: &[(String, bool)]| -> Set { rules.iter().map(|(rule, _)| rule.clone()).collect() };
+ assert_eq!(names(&standard), names(&default));
+}
+
+#[test]
+fn detekt_strict_keeps_every_rule_detekt_activates_by_default() {
let standard = detekt_tier("detekt/standard.yml");
let strict = detekt_tier("detekt/strict.yml");
assert_eq!(
diff(&active(&standard), &active(&strict)),
Vec::::new()
);
- assert!(active(&standard).len() < active(&strict).len());
- let names =
- |rules: &[(String, bool)]| -> Set { rules.iter().map(|(rule, _)| rule.clone()).collect() };
- assert_eq!(names(&standard), names(&strict));
}
/// The rules and `Key.option = value` settings of a scalafix `.conf`, read line by line.
@@ -337,68 +345,15 @@ fn scalafix(file: &str) -> (Set, Set) {
}
#[test]
-fn scalafix_strict_adds_syntax_bans_standard_leaves_out() {
+fn scalafix_standard_runs_no_rules_and_strict_keeps_the_syntax_bans() {
let ((standard_rules, standard), (strict_rules, strict)) = (
scalafix("scalafix/standard.conf"),
scalafix("scalafix/strict.conf"),
);
- assert_eq!(
- standard_rules,
- strings(&[
- "RemoveUnused",
- "DisableSyntax",
- "LeakingImplicitClassVal",
- "NoValInForComprehension",
- "NoAutoTupling",
- ])
- );
- assert_eq!(
- diff(&strict_rules, &standard_rules),
- [
- "ExplicitResultTypes",
- "OrganizeImports",
- "ProcedureSyntax",
- "RedundantSyntax"
- ]
- );
- assert_eq!(diff(&standard_rules, &strict_rules), Vec::::new());
- assert_eq!(
- standard,
- strings(&[
- "DisableSyntax.noFinalize = true",
- "DisableSyntax.noReturns = true",
- "DisableSyntax.noValInAbstract = true",
- ])
- );
- let options = [
- "noAsInstanceOf",
- "noContravariantTypes",
- "noCovariantTypes",
- "noDefaultArgs",
- "noFinalVal",
- "noImplicitConversion",
- "noImplicitObject",
- "noIsInstanceOf",
- "noNulls",
- "noSemicolons",
- "noTabs",
- "noThrows",
- "noUniversalEquality",
- "noValPatterns",
- "noVars",
- "noWhileLoops",
- "noXml",
- ];
- let mut added: Set = options
- .iter()
- .map(|option| format!("DisableSyntax.{option} = true"))
- .collect();
- added.insert("OrganizeImports.removeUnused = false".to_owned());
- assert_eq!(
- diff(&strict, &standard),
- added.into_iter().collect::>()
- );
- assert_eq!(diff(&standard, &strict), Vec::::new());
+ assert_eq!(standard_rules, Set::new());
+ assert_eq!(standard, Set::new());
+ assert!(strict_rules.contains("DisableSyntax"));
+ assert!(strict.contains("DisableSyntax.noReturns = true"));
}
fn lines(file: &str) -> Vec {
@@ -433,11 +388,8 @@ fn grouped(groups: &[(&str, &[&str])]) -> Set {
}
#[test]
-fn error_prone_standard_turns_every_warning_off() {
- assert_eq!(
- lines("errorprone/standard.flags"),
- ["-XepDisableAllWarnings"]
- );
+fn error_prone_standard_passes_no_flags_so_the_tool_default_applies() {
+ assert_eq!(lines("errorprone/standard.flags"), Vec::::new());
}
/// The super class and interfaces a class file names.
@@ -568,9 +520,6 @@ fn wartremover_strict_is_the_curated_set_of_each_pinned_plugin() {
}
#[test]
-fn wartremover_standard_is_the_exact_bug_only_list_inside_strict() {
- let standard = unique(lines("wartremover/standard.txt"), "standard warts");
- assert_eq!(standard, strings(WART_STANDARD));
- let strict = unique(lines("wartremover/strict.txt"), "common warts");
- assert_eq!(diff(&standard, &strict), Vec::::new());
+fn wartremover_standard_enables_no_warts_like_the_plugin_default() {
+ assert_eq!(lines("wartremover/standard.txt"), Vec::::new());
}
diff --git a/kotlin/README.md b/kotlin/README.md
index fd4034a026..72005b0ee8 100644
--- a/kotlin/README.md
+++ b/kotlin/README.md
@@ -58,7 +58,7 @@ None of them needs a config file.
| Tier | `detekt` | `kotlinc` |
| --- | --- | --- |
-| `standard` | 56 rules that find bugs; findings are warnings | Compiler warnings |
+| `standard` | detekt's default rules and settings; findings are warnings | Compiler warnings |
| `strict` | Every rule except `AbsentOrWrongFileLicense`; findings fail the check | Compiler warnings plus `-Wextra`, `-Xreport-all-warnings` and `-Werror` |
## Bench and fuzz
diff --git a/scala/README.md b/scala/README.md
index 1b946aa416..c971a8942d 100644
--- a/scala/README.md
+++ b/scala/README.md
@@ -43,8 +43,8 @@ through to `rules_scala`.
| Tier | `scalac` | `scalafix` | `wartremover` |
| --- | --- | --- | --- |
-| `standard` | Compiler warnings, fatal | `RemoveUnused`, `LeakingImplicitClassVal`, `NoValInForComprehension`, `NoAutoTupling`, `DisableSyntax` with `noFinalize`, `noReturns` and `noValInAbstract` | `ArrayEquals`, `ArrayToString`, `EitherProjectionPartial`, `IterableOps`, `Null`, `OptionPartial`, `Return` and `TryPartial` |
-| `strict` | Scala 2: `-Wdead-code`, `-Wextra-implicit`, `-Wnumeric-widen`, `-Woctal-literal`, `-Wperformance`, `-Wunnamed-boolean-literal-strict`, `-Wtostring-interpolated`, `-Wmultiarg-infix` and `-Xlint:_`. Scala 3: `-Ysafe-init` and `-Wall`. Warnings are fatal | Standard rules plus `ProcedureSyntax`, `RedundantSyntax`, `ExplicitResultTypes`, `OrganizeImports` and every `DisableSyntax` option | Every wart of the pinned plugin for your Scala version except `Unsafe` (its members are listed one by one), `Equals` (bans every `==`) and `Recursion` (bans every non-tail recursion) |
+| `standard` | Compiler warnings, fatal | None: Scalafix has no default rules, so it is skipped unless you bind a `scalafix_config` | No warts, the plugin's default |
+| `strict` | Scala 2: `-Wdead-code`, `-Wextra-implicit`, `-Wnumeric-widen`, `-Woctal-literal`, `-Wperformance`, `-Wunnamed-boolean-literal-strict`, `-Wtostring-interpolated`, `-Wmultiarg-infix` and `-Xlint:_`. Scala 3: `-Ysafe-init` and `-Wall`. Warnings are fatal | `RemoveUnused`, `LeakingImplicitClassVal`, `NoValInForComprehension`, `NoAutoTupling`, `DisableSyntax` with `noFinalize`, `noReturns` and `noValInAbstract`, plus `ProcedureSyntax`, `RedundantSyntax`, `ExplicitResultTypes`, `OrganizeImports` and every `DisableSyntax` option | Every wart of the pinned plugin for your Scala version except `Unsafe` (its members are listed one by one), `Equals` (bans every `==`) and `Recursion` (bans every non-tail recursion) |
## Bench and fuzz
diff --git a/scala/private/quality/scala.bzl b/scala/private/quality/scala.bzl
index 2423a8c958..24407102e4 100644
--- a/scala/private/quality/scala.bzl
+++ b/scala/private/quality/scala.bzl
@@ -2,7 +2,7 @@
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
load("@rules_scala//scala:semanticdb_provider.bzl", "SemanticdbInfo")
-load("//core/quality:family_hooks.bzl", "stage")
+load("//core/quality:family_hooks.bzl", "stage", "without_in_standard_unless_bound")
load("//core/quality:real_core.bzl", "real_config", "real_context", "real_make_aspect", "real_member")
load("//java/private/quality:jvm.bzl", "jvm_aux_jars", "jvm_check_hook")
load(":scalac_check.bzl", "scalac_check_aspect")
@@ -39,6 +39,7 @@ SHARD_SPECS = {
"real_scala_lint": {
"capability": "lint",
"doc": "Additive Scala lint family aspect (Scalafix; target-coupled via SemanticdbInfo and JavaInfo).",
+ "extra_attrs": {"_config_tier": attr.label(default = "//config:config_tier")},
"shard": "scala",
},
"real_scala_typecheck": {
@@ -67,7 +68,10 @@ def _scalafix_context(target, what):
sorted(auxiliary.values(), key = lambda f: f.path),
)
-def _scalafix_hook(target, _ctx, _resolved, _capability, what, _shared):
+def _scalafix_hook(target, ctx, resolved, _capability, what, _shared):
+ skipped = without_in_standard_unless_bound(ctx, resolved, "scalafix", "scala")
+ if skipped != None:
+ return skipped
(owned, aux) = _scalafix_context(target, what)
tool_files = []
inputs = []