diff --git a/core/quality/family_hooks.bzl b/core/quality/family_hooks.bzl index b314325b9a..ff7f5f2cf8 100644 --- a/core/quality/family_hooks.bzl +++ b/core/quality/family_hooks.bzl @@ -1,7 +1,9 @@ """Hook helpers shared by the quality family files.""" load("//core/quality:pipeline.bzl", "drop_pipeline_tool") -load("//core/quality:real_core.bzl", "real_context", "real_resolve_list") +load("//core/quality:policy.bzl", "QualityPolicyInfo") +load("//core/quality:real_core.bzl", "real_context", "real_family_tier", "real_resolve_list") +load("//core/quality/private:native_config_impl.bzl", "bound_config_targets") visibility(["//bicep/...", "//cc/...", "//core/...", "//dart/...", "//dotnet/...", "//erlang/...", "//go/...", "//haskell/...", "//java/...", "//javascript/...", "//julia/...", "//kubernetes/...", "//lua/...", "//ocaml/...", "//ruby/...", "//rust/...", "//scala/...", "//terraform/..."]) @@ -14,6 +16,14 @@ def without(resolved, tool): """Context that drops a tool from the pipeline.""" return real_context(resolved = drop_pipeline_tool(resolved, tool)) +def without_in_standard_unless_bound(ctx, resolved, tool, family_id): + """Context that drops a tool with no default rules at the standard tier, unless the user bound a config for it; None otherwise.""" + if real_family_tier(ctx, family_id) != "standard": + return None + if tool in bound_config_targets(ctx.rule.attr, ctx.attr._policy[QualityPolicyInfo].declared, ""): + return None + return without(resolved, tool) + def default_files_hook(extensions, only_capability = None, except_capability = None): def _hook(target, _ctx, _resolved, capability, _what, _shared): if only_capability != None and capability != only_capability: diff --git a/core/quality/runner/BUILD.bazel b/core/quality/runner/BUILD.bazel index 962a8e1168..e50633f2ac 100644 --- a/core/quality/runner/BUILD.bazel +++ b/core/quality/runner/BUILD.bazel @@ -53,7 +53,6 @@ rust_library( "//core/quality/tiers/zizmor:standard.txt", "//core/quality/tiers/zanuda:standard.txt", "//core/quality/tiers/zanuda:strict.txt", - "//core/quality/tiers/pmd:standard.xml", "//lua/private/quality:lua54.yml", ], crate_name = "quality_runner", @@ -189,7 +188,6 @@ rust_test( "//core/quality/tiers/zizmor:standard.txt", "//core/quality/tiers/zanuda:standard.txt", "//core/quality/tiers/zanuda:strict.txt", - "//core/quality/tiers/pmd:standard.xml", "//lua/private/quality:lua54.yml", ], coverage_lib = ":quality_runner_lib", diff --git a/core/quality/runner/src/real_tools.rs b/core/quality/runner/src/real_tools.rs index b73a69a67c..52f1a9d198 100644 --- a/core/quality/runner/src/real_tools.rs +++ b/core/quality/runner/src/real_tools.rs @@ -452,23 +452,6 @@ fn selene_embedded_std_is_the_merged_file() { assert!(std.contains("lua54")); } -#[test] -fn pmd_standard_tier_covers_unused_code() { - let text = std::str::from_utf8(include_bytes!("../../tiers/pmd/standard.xml")).expect("utf8"); - for rule in [ - "UnusedPrivateMethod", - "UnusedPrivateField", - "UnusedLocalVariable", - "UnusedFormalParameter", - "UnusedAssignment", - ] { - assert!( - text.contains(&format!("bestpractices.xml/{rule}\"")), - "{rule}" - ); - } -} - #[test] fn gplint_crashes_are_never_clean() { let backend = backend_for("gplint", gplint_tool(), roundtrip_gplint); diff --git a/core/quality/testdata/matrix/matrix_scala_scalafix_profile_standard.expected.txt b/core/quality/testdata/matrix/matrix_scala_scalafix_profile_standard.expected.txt deleted file mode 100644 index bd89cf20f5..0000000000 --- a/core/quality/testdata/matrix/matrix_scala_scalafix_profile_standard.expected.txt +++ /dev/null @@ -1,11 +0,0 @@ -producer //core/quality/testdata:matrix_scala_scalafix_profile_standard -capability LINT -stages 1 -stage scalafix classes=scala sources=core/quality/testdata/profiles/scala/Strict.scala -completed_rounds 2 -convergence STABLE -initial 1 -initial ERROR scalafix Patch core/quality/testdata/profiles/scala/Strict.scala 43 67 fixable=true "scalafix would rewrite this code" -terminal 0 -replacements 1 -replacement core/quality/testdata/profiles/scala/Strict.scala 45 67 "" diff --git a/core/quality/testdata/runner_matrix_scala_dotnet.bzl b/core/quality/testdata/runner_matrix_scala_dotnet.bzl index 8b4d643e27..0fb1eb0710 100644 --- a/core/quality/testdata/runner_matrix_scala_dotnet.bzl +++ b/core/quality/testdata/runner_matrix_scala_dotnet.bzl @@ -1,20 +1,6 @@ """Scala plus .NET cohort matrix cells.""" SCALA_DOTNET_CASES = [ - { - "name": "matrix_scala_scalafix_profile_standard", - "srcs": ["//core/quality/testdata/profiles/scala:Strict.scala"], - "capability": "lint", - "stages": ["scalafix;scala;core/quality/testdata/profiles/scala/Strict.scala"], - "tool_names": ["scalafix"], - "tool_binaries": ["//java/private/quality/tools:scalafix"], - "toolfile_tools": ["scalafix", "scalafix", "scalafix"], - "toolfile_srcs": ["//core/quality/testdata/profiles/scala:strict", "@maven//:org_scala_lang_scala_library_2_13_10", "//core/quality/tiers/scalafix:standard.conf"], - "toolfile_rels": ["dx-scalafix/owned/core/quality/testdata/profiles/scala/libstrict.jar", "dx-scalafix/aux/0-scala-library.jar", ""], - "config_tools": ["scalafix"], - "config_files": ["//core/quality/tiers/scalafix:standard.conf"], - "expected_file": ":matrix/matrix_scala_scalafix_profile_standard.expected.txt", - }, { "name": "matrix_scala_scalafix_profile_strict", "srcs": ["//core/quality/testdata/profiles/scala:Strict.scala"], diff --git a/core/quality/tiers/detekt/standard.yml b/core/quality/tiers/detekt/standard.yml index 70bb386838..40c88230cc 100644 --- a/core/quality/tiers/detekt/standard.yml +++ b/core/quality/tiers/detekt/standard.yml @@ -91,7 +91,7 @@ complexity: active: false threshold: 15 ComplexCondition: - active: false + active: true threshold: 4 ComplexInterface: active: false @@ -100,7 +100,7 @@ complexity: includePrivateDeclarations: false ignoreOverloaded: false CyclomaticComplexMethod: - active: false + active: true threshold: 15 ignoreSingleWhenExpression: false ignoreSimpleWhenEntries: false @@ -119,13 +119,13 @@ complexity: active: false ignoredLabels: [] LargeClass: - active: false + active: true threshold: 600 LongMethod: - active: false + active: true threshold: 60 LongParameterList: - active: false + active: true functionThreshold: 6 constructorThreshold: 7 ignoreDefaultParameters: false @@ -139,7 +139,7 @@ complexity: threshold: 3 ignoreArgumentsMatchingNames: false NestedBlockDepth: - active: false + active: true threshold: 4 NestedScopeFunctions: active: false @@ -160,7 +160,7 @@ complexity: excludeStringsWithLessThan5Characters: true ignoreStringsRegex: '$^' TooManyFunctions: - active: false + active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] thresholdInFiles: 11 thresholdInClasses: 11 @@ -174,21 +174,21 @@ complexity: coroutines: active: true GlobalCoroutineUsage: - active: true - InjectDispatcher: active: false + InjectDispatcher: + active: true dispatcherNames: - 'IO' - 'Default' - 'Unconfined' RedundantSuspendModifier: - active: false + active: true SleepInsteadOfDelay: active: true SuspendFunSwallowedCancellation: - active: true + active: false SuspendFunWithCoroutineScopeReceiver: - active: true + active: false SuspendFunWithFlowReturnType: active: true empty-blocks: @@ -197,9 +197,9 @@ empty-blocks: active: true allowedExceptionNameRegex: '_|(ignore|expected).*' EmptyClassBlock: - active: false + active: true EmptyDefaultConstructor: - active: false + active: true EmptyDoWhileBlock: active: true EmptyElseBlock: @@ -209,16 +209,16 @@ empty-blocks: EmptyForBlock: active: true EmptyFunctionBlock: - active: false + active: true ignoreOverridden: false EmptyIfBlock: active: true EmptyInitBlock: - active: false + active: true EmptyKtFile: - active: false + active: true EmptySecondaryConstructor: - active: false + active: true EmptyTryBlock: active: true EmptyWhenBlock: @@ -238,13 +238,13 @@ exceptions: active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] NotImplementedDeclaration: - active: true + active: false ObjectExtendsThrowable: - active: true + active: false PrintStackTrace: active: true RethrowCaughtException: - active: false + active: true ReturnFromFinally: active: true ignoreLabeled: false @@ -259,9 +259,9 @@ exceptions: ThrowingExceptionFromFinally: active: true ThrowingExceptionInMain: - active: true - ThrowingExceptionsWithoutMessageOrCause: active: false + ThrowingExceptionsWithoutMessageOrCause: + active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] exceptions: - 'ArrayIndexOutOfBoundsException' @@ -274,9 +274,9 @@ exceptions: - 'RuntimeException' - 'Throwable' ThrowingNewInstanceOfSameException: - active: false + active: true TooGenericExceptionCaught: - active: false + active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] exceptionNames: - 'ArrayIndexOutOfBoundsException' @@ -289,7 +289,7 @@ exceptions: - 'Throwable' allowedExceptionNameRegex: '_|(ignore|expected).*' TooGenericExceptionThrown: - active: false + active: true exceptionNames: - 'Error' - 'Exception' @@ -301,15 +301,15 @@ naming: active: false allowedPattern: '^(is|has|are)' ClassNaming: - active: false + active: true classPattern: '[A-Z][a-zA-Z0-9]*' ConstructorParameterNaming: - active: false + active: true parameterPattern: '[a-z][A-Za-z0-9]*' privateParameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' EnumNaming: - active: false + active: true enumEntryPattern: '[A-Z][_a-zA-Z0-9]*' ForbiddenClassName: active: false @@ -321,23 +321,23 @@ naming: active: false minimumFunctionNameLength: 3 FunctionNaming: - active: false + active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] functionPattern: '[a-z][a-zA-Z0-9]*' excludeClassPattern: '$^' FunctionParameterNaming: - active: false + active: true parameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' InvalidPackageDeclaration: - active: false + active: true rootPackage: '' requireRootInDeclaration: false LambdaParameterNaming: active: false parameterPattern: '[a-z][A-Za-z0-9]*|_' MatchingDeclarationName: - active: false + active: true mustBeFirst: true multiplatformTargets: - 'ios' @@ -351,22 +351,22 @@ naming: - 'mingwX64' - 'linuxX64' MemberNameEqualsClassName: - active: false + active: true ignoreOverridden: true NoNameShadowing: - active: false + active: true NonBooleanPropertyPrefixedWithIs: active: false ObjectPropertyNaming: - active: false + active: true constantPattern: '[A-Za-z][_A-Za-z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '(_)?[A-Za-z][_A-Za-z0-9]*' PackageNaming: - active: false + active: true packagePattern: '[a-z]+(\.[a-z][A-Za-z0-9]*)*' TopLevelPropertyNaming: - active: false + active: true constantPattern: '[A-Z][_A-Z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*' @@ -377,27 +377,27 @@ naming: active: false minimumVariableNameLength: 1 VariableNaming: - active: false + active: true variablePattern: '[a-z][A-Za-z0-9]*' privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' performance: active: true ArrayPrimitive: - active: false + active: true CouldBeSequence: active: false threshold: 3 ForEachOnRange: - active: false + active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] SpreadOperator: - active: false + active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] UnnecessaryPartOfBinaryExpression: active: false UnnecessaryTemporaryInstantiation: - active: false + active: true potential-bugs: active: true AvoidReferentialEquality: @@ -405,15 +405,15 @@ potential-bugs: forbiddenTypePatterns: - 'kotlin.String' CastNullableToNonNullableType: - active: true + active: false CastToNullableType: - active: true + active: false Deprecation: - active: true + active: false DontDowncastCollectionTypes: - active: true - DoubleMutabilityForCollection: active: false + DoubleMutabilityForCollection: + active: true mutableTypes: - 'kotlin.collections.MutableList' - 'kotlin.collections.MutableMap' @@ -424,14 +424,14 @@ potential-bugs: - 'java.util.LinkedHashMap' - 'java.util.HashMap' ElseCaseInsteadOfExhaustiveWhen: - active: true + active: false ignoredSubjectTypes: [] EqualsAlwaysReturnsTrueOrFalse: active: true EqualsWithHashCodeExist: active: true ExitOutsideMain: - active: true + active: false ExplicitGarbageCollectionCall: active: true HasPlatformType: @@ -473,19 +473,19 @@ potential-bugs: active: false excludes: ['**/*.kts'] NullCheckOnMutableProperty: - active: true + active: false NullableToStringCall: - active: true + active: false PropertyUsedBeforeDeclaration: - active: true + active: false UnconditionalJumpStatementInLoop: - active: true + active: false UnnecessaryNotNullCheck: active: false UnnecessaryNotNullOperator: - active: false + active: true UnnecessarySafeCall: - active: false + active: true UnreachableCatchBlock: active: true UnreachableCode: @@ -530,7 +530,7 @@ style: DataClassShouldBeImmutable: active: false DestructuringDeclarationWithTooManyEntries: - active: false + active: true maxDestructuringEntries: 3 DoubleNegativeLambda: active: false @@ -549,7 +549,7 @@ style: ExplicitCollectionElementAccessMethod: active: false ExplicitItLambdaParameter: - active: false + active: true ExpressionBodySyntax: active: false includeLineWrapping: false @@ -571,7 +571,7 @@ style: - reason: 'Kotlin does not support @Inherited annotation, see https://youtrack.jetbrains.com/issue/KT-22265' value: 'java.lang.annotation.Inherited' ForbiddenComment: - active: false + active: true comments: - reason: 'Forbidden FIXME todo marker in comment, please fix the problem.' value: 'FIXME:' @@ -595,19 +595,19 @@ style: active: false rules: [] ForbiddenVoid: - active: false + active: true ignoreOverridden: false ignoreUsageInGenerics: false FunctionOnlyReturningConstant: - active: false + active: true ignoreOverridableFunction: true ignoreActualFunction: true excludedFunctions: [] LoopWithTooManyJumpStatements: - active: false + active: true maxJumpCount: 1 MagicNumber: - active: false + active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**', '**/*.kts'] ignoreNumbers: - '-1' @@ -630,16 +630,16 @@ style: active: false maxChainedCalls: 5 MaxLineLength: - active: false + active: true maxLineLength: 120 excludePackageStatements: true excludeImportStatements: true excludeCommentStatements: false excludeRawStrings: true MayBeConst: - active: false + active: true ModifierOrder: - active: false + active: true MultilineLambdaItParameter: active: false MultilineRawStringIndentation: @@ -649,31 +649,31 @@ style: - 'trimIndent' - 'trimMargin' NestedClassesVisibility: - active: false + active: true NewLineAtEndOfFile: - active: false + active: true NoTabs: active: false NullableBooleanCheck: active: false ObjectLiteralToLambda: - active: false + active: true OptionalAbstractKeyword: - active: false + active: true OptionalUnit: active: false PreferToOverPairSyntax: active: false ProtectedMemberInFinalClass: - active: false + active: true RedundantExplicitType: active: false RedundantHigherOrderMapUsage: - active: false + active: true RedundantVisibilityModifierRule: active: false ReturnCount: - active: false + active: true max: 2 excludedFunctions: - 'equals' @@ -681,7 +681,7 @@ style: excludeReturnFromLambda: true excludeGuardClauses: false SafeCast: - active: false + active: true SerialVersionUIDInSerializableClass: active: true SpacingBetweenPackageAndImports: @@ -691,7 +691,7 @@ style: maxEscapedCharacterCount: 2 ignoredCharacters: [] ThrowsCount: - active: false + active: true max: 2 excludeGuardClauses: false TrailingWhitespace: @@ -706,19 +706,19 @@ style: acceptableLength: 4 allowNonStandardGrouping: false UnnecessaryAbstractClass: - active: false + active: true UnnecessaryAnnotationUseSiteTarget: active: false UnnecessaryApply: - active: false + active: true UnnecessaryBackticks: active: false UnnecessaryBracesAroundTrailingLambda: active: false UnnecessaryFilter: - active: false + active: true UnnecessaryInheritance: - active: false + active: true UnnecessaryInnerClass: active: false UnnecessaryLet: @@ -731,7 +731,7 @@ style: UnusedImports: active: false UnusedParameter: - active: false + active: true allowedNames: 'ignored|expected' UnusedPrivateClass: active: true @@ -742,13 +742,13 @@ style: active: true allowedNames: '_|ignored|expected|serialVersionUID' UseAnyOrNoneInsteadOfFind: - active: false + active: true UseArrayLiteralsInAnnotations: - active: false + active: true UseCheckNotNull: - active: false + active: true UseCheckOrError: - active: false + active: true UseDataClass: active: false allowVars: false @@ -760,25 +760,25 @@ style: active: false ignoreWhenContainingVariableDeclaration: false UseIsNullOrEmpty: - active: false + active: true UseLet: active: false UseOrEmpty: - active: false + active: true UseRequire: - active: false + active: true UseRequireNotNull: - active: false + active: true UseSumOfInsteadOfFlatMapSize: active: false UselessCallOnNotNull: - active: false + active: true UtilityClassWithPublicConstructor: - active: false + active: true VarCouldBeVal: - active: false + active: true ignoreLateinitVar: false WildcardImport: - active: false + active: true excludeImports: - 'java.util.*' diff --git a/core/quality/tiers/errorprone/standard.flags b/core/quality/tiers/errorprone/standard.flags index 3c9eb90790..e69de29bb2 100644 --- a/core/quality/tiers/errorprone/standard.flags +++ b/core/quality/tiers/errorprone/standard.flags @@ -1 +0,0 @@ --XepDisableAllWarnings diff --git a/core/quality/tiers/pmd/standard.xml b/core/quality/tiers/pmd/standard.xml index 7dbc3e4109..bc6a9edb0b 100644 --- a/core/quality/tiers/pmd/standard.xml +++ b/core/quality/tiers/pmd/standard.xml @@ -3,96 +3,6 @@ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"> - PMD rules that catch bugs: unused code, broken equality and cloning, resource and exception handling mistakes, unsafe concurrency and weak crypto. No style rules. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + PMD's own recommended starting ruleset for Java. + diff --git a/core/quality/tiers/roslyn/standard.globalconfig b/core/quality/tiers/roslyn/standard.globalconfig index cd62c99a23..7874532f38 100644 --- a/core/quality/tiers/roslyn/standard.globalconfig +++ b/core/quality/tiers/roslyn/standard.globalconfig @@ -1,155 +1 @@ is_global = true -global_level = 100 -build_property.EnforceCodeStyleInBuild = true - -dotnet_diagnostic.IDE0005.severity = warning -dotnet_diagnostic.IDE0051.severity = warning -dotnet_diagnostic.IDE0052.severity = warning -dotnet_diagnostic.IDE0060.severity = warning - -dotnet_diagnostic.CA1000.severity = warning -dotnet_diagnostic.CA1001.severity = warning -dotnet_diagnostic.CA1010.severity = warning -dotnet_diagnostic.CA1016.severity = warning -dotnet_diagnostic.CA1018.severity = warning -dotnet_diagnostic.CA1036.severity = warning -dotnet_diagnostic.CA1041.severity = warning -dotnet_diagnostic.CA1047.severity = warning -dotnet_diagnostic.CA1050.severity = warning -dotnet_diagnostic.CA1051.severity = warning -dotnet_diagnostic.CA1061.severity = warning -dotnet_diagnostic.CA1067.severity = warning -dotnet_diagnostic.CA1068.severity = warning -dotnet_diagnostic.CA1069.severity = warning -dotnet_diagnostic.CA1070.severity = warning -dotnet_diagnostic.CA1200.severity = warning -dotnet_diagnostic.CA1304.severity = warning -dotnet_diagnostic.CA1305.severity = warning -dotnet_diagnostic.CA1309.severity = warning -dotnet_diagnostic.CA1310.severity = warning -dotnet_diagnostic.CA1311.severity = warning -dotnet_diagnostic.CA1401.severity = warning -dotnet_diagnostic.CA1419.severity = warning -dotnet_diagnostic.CA1421.severity = warning -dotnet_diagnostic.CA1507.severity = warning -dotnet_diagnostic.CA1510.severity = warning -dotnet_diagnostic.CA1511.severity = warning -dotnet_diagnostic.CA1512.severity = warning -dotnet_diagnostic.CA1513.severity = warning -dotnet_diagnostic.CA1514.severity = warning -dotnet_diagnostic.CA1516.severity = none -dotnet_diagnostic.CA1707.severity = warning -dotnet_diagnostic.CA1708.severity = warning -dotnet_diagnostic.CA1710.severity = warning -dotnet_diagnostic.CA1711.severity = warning -dotnet_diagnostic.CA1712.severity = warning -dotnet_diagnostic.CA1715.severity = warning -dotnet_diagnostic.CA1716.severity = warning -dotnet_diagnostic.CA1720.severity = warning -dotnet_diagnostic.CA1725.severity = warning -dotnet_diagnostic.CA1727.severity = warning -dotnet_diagnostic.CA1805.severity = warning -dotnet_diagnostic.CA1806.severity = warning -dotnet_diagnostic.CA1816.severity = warning -dotnet_diagnostic.CA1821.severity = warning -dotnet_diagnostic.CA1822.severity = warning -dotnet_diagnostic.CA1824.severity = warning -dotnet_diagnostic.CA1825.severity = warning -dotnet_diagnostic.CA1826.severity = warning -dotnet_diagnostic.CA1827.severity = warning -dotnet_diagnostic.CA1828.severity = warning -dotnet_diagnostic.CA1829.severity = warning -dotnet_diagnostic.CA1830.severity = warning -dotnet_diagnostic.CA1832.severity = warning -dotnet_diagnostic.CA1833.severity = warning -dotnet_diagnostic.CA1834.severity = warning -dotnet_diagnostic.CA1835.severity = warning -dotnet_diagnostic.CA1836.severity = warning -dotnet_diagnostic.CA1837.severity = warning -dotnet_diagnostic.CA1838.severity = warning -dotnet_diagnostic.CA1839.severity = warning -dotnet_diagnostic.CA1840.severity = warning -dotnet_diagnostic.CA1841.severity = warning -dotnet_diagnostic.CA1842.severity = warning -dotnet_diagnostic.CA1843.severity = warning -dotnet_diagnostic.CA1844.severity = warning -dotnet_diagnostic.CA1845.severity = warning -dotnet_diagnostic.CA1846.severity = warning -dotnet_diagnostic.CA1847.severity = warning -dotnet_diagnostic.CA1848.severity = warning -dotnet_diagnostic.CA1850.severity = warning -dotnet_diagnostic.CA1852.severity = warning -dotnet_diagnostic.CA1853.severity = warning -dotnet_diagnostic.CA1854.severity = warning -dotnet_diagnostic.CA1855.severity = warning -dotnet_diagnostic.CA1856.severity = warning -dotnet_diagnostic.CA1858.severity = warning -dotnet_diagnostic.CA1859.severity = warning -dotnet_diagnostic.CA1860.severity = warning -dotnet_diagnostic.CA1861.severity = warning -dotnet_diagnostic.CA1862.severity = warning -dotnet_diagnostic.CA1863.severity = warning -dotnet_diagnostic.CA1864.severity = warning -dotnet_diagnostic.CA1865.severity = warning -dotnet_diagnostic.CA1866.severity = warning -dotnet_diagnostic.CA1868.severity = warning -dotnet_diagnostic.CA1869.severity = warning -dotnet_diagnostic.CA1870.severity = warning -dotnet_diagnostic.CA1871.severity = warning -dotnet_diagnostic.CA1872.severity = warning -dotnet_diagnostic.CA1873.severity = warning -dotnet_diagnostic.CA1874.severity = warning -dotnet_diagnostic.CA1875.severity = warning -dotnet_diagnostic.CA2009.severity = warning -dotnet_diagnostic.CA2011.severity = warning -dotnet_diagnostic.CA2012.severity = warning -dotnet_diagnostic.CA2016.severity = warning -dotnet_diagnostic.CA2019.severity = warning -dotnet_diagnostic.CA2020.severity = warning -dotnet_diagnostic.CA2101.severity = warning -dotnet_diagnostic.CA2201.severity = warning -dotnet_diagnostic.CA2208.severity = warning -dotnet_diagnostic.CA2211.severity = warning -dotnet_diagnostic.CA2215.severity = warning -dotnet_diagnostic.CA2218.severity = warning -dotnet_diagnostic.CA2219.severity = warning -dotnet_diagnostic.CA2224.severity = warning -dotnet_diagnostic.CA2231.severity = warning -dotnet_diagnostic.CA2241.severity = warning -dotnet_diagnostic.CA2242.severity = warning -dotnet_diagnostic.CA2244.severity = warning -dotnet_diagnostic.CA2245.severity = warning -dotnet_diagnostic.CA2246.severity = warning -dotnet_diagnostic.CA2248.severity = warning -dotnet_diagnostic.CA2249.severity = warning -dotnet_diagnostic.CA2250.severity = warning -dotnet_diagnostic.CA2251.severity = warning -dotnet_diagnostic.CA2252.severity = warning -dotnet_diagnostic.CA2253.severity = warning -dotnet_diagnostic.CA2254.severity = warning -dotnet_diagnostic.CA2262.severity = warning -dotnet_diagnostic.CA2263.severity = warning -dotnet_diagnostic.CA3061.severity = warning -dotnet_diagnostic.CA3075.severity = warning -dotnet_diagnostic.CA3076.severity = warning -dotnet_diagnostic.CA3077.severity = warning -dotnet_diagnostic.CA3147.severity = warning -dotnet_diagnostic.CA5350.severity = warning -dotnet_diagnostic.CA5351.severity = warning -dotnet_diagnostic.CA5359.severity = warning -dotnet_diagnostic.CA5360.severity = warning -dotnet_diagnostic.CA5363.severity = warning -dotnet_diagnostic.CA5364.severity = warning -dotnet_diagnostic.CA5365.severity = warning -dotnet_diagnostic.CA5366.severity = warning -dotnet_diagnostic.CA5368.severity = warning -dotnet_diagnostic.CA5369.severity = warning -dotnet_diagnostic.CA5370.severity = warning -dotnet_diagnostic.CA5371.severity = warning -dotnet_diagnostic.CA5372.severity = warning -dotnet_diagnostic.CA5373.severity = warning -dotnet_diagnostic.CA5374.severity = warning -dotnet_diagnostic.CA5379.severity = warning -dotnet_diagnostic.CA5384.severity = warning -dotnet_diagnostic.CA5385.severity = warning -dotnet_diagnostic.CA5397.severity = warning diff --git a/core/quality/tiers/scalafix/standard.conf b/core/quality/tiers/scalafix/standard.conf index cbaf209813..e69de29bb2 100644 --- a/core/quality/tiers/scalafix/standard.conf +++ b/core/quality/tiers/scalafix/standard.conf @@ -1,11 +0,0 @@ -rules = [ - RemoveUnused - DisableSyntax - LeakingImplicitClassVal - NoValInForComprehension - NoAutoTupling -] - -DisableSyntax.noFinalize = true -DisableSyntax.noReturns = true -DisableSyntax.noValInAbstract = true diff --git a/core/quality/tiers/spotbugs/standard.xml b/core/quality/tiers/spotbugs/standard.xml index 4ed2d63fed..7192c83c12 100644 --- a/core/quality/tiers/spotbugs/standard.xml +++ b/core/quality/tiers/spotbugs/standard.xml @@ -1,23 +1,5 @@ - - - - - - - - - - - - - - - - - - diff --git a/core/quality/tiers/wartremover/standard.txt b/core/quality/tiers/wartremover/standard.txt index e232cf31f4..e69de29bb2 100644 --- a/core/quality/tiers/wartremover/standard.txt +++ b/core/quality/tiers/wartremover/standard.txt @@ -1,8 +0,0 @@ -ArrayEquals -ArrayToString -EitherProjectionPartial -IterableOps -Null -OptionPartial -Return -TryPartial diff --git a/csharp/tests/fixtures/profiles/BUILD.bazel b/csharp/tests/fixtures/profiles/BUILD.bazel index 685e6fcd92..9a5d196c3f 100644 --- a/csharp/tests/fixtures/profiles/BUILD.bazel +++ b/csharp/tests/fixtures/profiles/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_dx//core:defs.bzl", "roslyn_config") load("@rules_dx//core/quality:fixtures.bzl", "real_source_target") load("@rules_dx//rust:defs.bzl", "rust_test") load("//csharp:defs.bzl", "csharp_library") -load(":sarif.bzl", "roslyn_sarif", "sdk_recommended") +load(":sarif.bzl", "roslyn_sarif") package( default_testonly = True, @@ -57,21 +57,15 @@ roslyn_sarif( dep = ":strict", ) -sdk_recommended( - name = "sdk_recommended", -) - rust_test( name = "profiles_test", srcs = ["profiles_test.rs"], data = [ - ":sdk_recommended", ":standard_sarif", ":strict_sarif", "@rules_dx//core/quality/tiers/roslyn:standard.globalconfig", ], env = { - "DX_SDK_RECOMMENDED": "$(rootpath :sdk_recommended)", "DX_STANDARD_TEMPLATE": "$(rootpath @rules_dx//core/quality/tiers/roslyn:standard.globalconfig)", "DX_STANDARD_SARIF": "$(rootpath :standard_sarif)", "DX_STRICT_SARIF": "$(rootpath :strict_sarif)", diff --git a/csharp/tests/fixtures/profiles/profiles_test.rs b/csharp/tests/fixtures/profiles/profiles_test.rs index 0d64af5e3d..1fd9a83284 100644 --- a/csharp/tests/fixtures/profiles/profiles_test.rs +++ b/csharp/tests/fixtures/profiles/profiles_test.rs @@ -12,37 +12,25 @@ fn rule_ids(env: &str) -> BTreeSet { } #[test] -fn strict_adds_one_design_rule() { +fn strict_adds_a_design_rule_and_keeps_every_standard_finding() { let standard = rule_ids("DX_STANDARD_SARIF"); let strict = rule_ids("DX_STRICT_SARIF"); - let added: Vec<&String> = strict.difference(&standard).collect(); - assert_eq!( - added, - vec!["CA1008"], - "standard {standard:?} strict {strict:?}" - ); + assert!(!standard.contains("CA1008"), "standard {standard:?}"); + assert!(strict.contains("CA1008"), "strict {strict:?}"); assert!( standard.is_subset(&strict), "strict dropped a standard finding" ); } -fn ca_lines(env: &str) -> Vec { - let rel = std::env::var(env).unwrap_or_else(|_| panic!("{env} must name a globalconfig")); - let text = std::fs::read_to_string(dx_testing::resolve_runfiles(&rel)).expect("read config"); - text.lines() - .filter(|line| line.starts_with("dotnet_diagnostic.CA")) - .map(str::to_owned) - .collect() -} - #[test] -fn standard_is_the_sdk_recommended_tier() { - assert_eq!( - ca_lines("DX_STANDARD_TEMPLATE"), - ca_lines("DX_SDK_RECOMMENDED"), - "the SDK changed its Recommended tier; copy the dotnet_diagnostic.CA lines of \ - Sdks/Microsoft.NET.Sdk/analyzers/build/config/analysislevel__recommended.globalconfig \ - into core/quality/tiers/roslyn/standard.globalconfig" - ); +fn standard_sets_no_severities_so_the_sdk_default_applies() { + let rel = std::env::var("DX_STANDARD_TEMPLATE").expect("DX_STANDARD_TEMPLATE names a config"); + let text = std::fs::read_to_string(dx_testing::resolve_runfiles(&rel)).expect("read config"); + let settings: Vec<&str> = text + .lines() + .map(str::trim) + .filter(|line| !line.is_empty() && !line.starts_with('#') && *line != "is_global = true") + .collect(); + assert!(settings.is_empty(), "standard configures {settings:?}"); } diff --git a/csharp/tests/fixtures/profiles/sarif.bzl b/csharp/tests/fixtures/profiles/sarif.bzl index bbbe5a7703..d76520e77c 100644 --- a/csharp/tests/fixtures/profiles/sarif.bzl +++ b/csharp/tests/fixtures/profiles/sarif.bzl @@ -9,22 +9,3 @@ roslyn_sarif = rule( implementation = _roslyn_sarif_impl, attrs = {"dep": attr.label(aspects = [roslyn_aspect], mandatory = True)}, ) - -_TOOLCHAIN = "@rules_dotnet//dotnet/toolchain:toolchain_type" - -def _sdk_recommended_impl(ctx): - toolchain = ctx.toolchains[_TOOLCHAIN] - csc = toolchain.csharp_compiler.files_to_run.executable - major = csc.path.partition("/sdk/")[2].partition("/")[0].partition(".")[0] - suffix = "/analyzers/build/config/analysislevel_%s_recommended.globalconfig" % major - found = [f for f in toolchain.runtime.default_runfiles.files.to_list() + toolchain.csharp_compiler.default_runfiles.files.to_list() if f.path.endswith(suffix)] - found = {f.path: f for f in found}.values() - if len(found) != 1: - fail("want one analysislevel_%s_recommended.globalconfig in the SDK, got %d" % (major, len(found))) - return [DefaultInfo(files = depset(list(found)))] - -sdk_recommended = rule( - implementation = _sdk_recommended_impl, - toolchains = [config_common.toolchain_type(_TOOLCHAIN)], - doc = "The Recommended analysis level globalconfig of the pinned .NET SDK.", -) diff --git a/docs/languages/java.md b/docs/languages/java.md index 712a62f6c0..cb339736e4 100644 --- a/docs/languages/java.md +++ b/docs/languages/java.md @@ -87,7 +87,7 @@ private methods, fields, locals, parameters and assignments as info. See the | Tier | `javac` | `pmd` | `spotbugs` | | --- | --- | --- | --- | -| `standard` | Compile flags above, plus Error Prone's default error checks | Error-prone and best-practice rules that find bugs | Ranks 1 to 14 at medium and high confidence, default analysis effort | +| `standard` | Compile flags above, plus Error Prone's default checks | PMD's quickstart ruleset | Every rank at medium and high confidence, default analysis effort | | `strict` | Compile flags above plus `-Xlint:all,-processing` and `-Werror`. Error Prone reports its warnings and a chosen list of off-by-default checks as warnings, and `-Werror` makes them fail the build | Every rule in every PMD category except `AtLeastOneConstructor`, `OnlyOneReturn` (forbids early returns), `LocalVariableDeclarationShouldBeAtStartOfBlock` (contradicts `PrematureDeclaration`), `LoosePackageCoupling` (needs a package list) and `WrongTestAnnotation` (by default it accepts only JUnit Jupiter) | Every rank and confidence, with maximum analysis effort | Strict Error Prone leaves out checks for libraries you may not use (nullness diff --git a/docs/languages/kotlin.md b/docs/languages/kotlin.md index 827a80c37f..0a18b3d9f9 100644 --- a/docs/languages/kotlin.md +++ b/docs/languages/kotlin.md @@ -98,7 +98,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/docs/languages/scala.md b/docs/languages/scala.md index f08f8ec713..0f3b35ba82 100644 --- a/docs/languages/scala.md +++ b/docs/languages/scala.md @@ -80,8 +80,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/java/README.md b/java/README.md index 9e86c1d926..d291ccac96 100644 --- a/java/README.md +++ b/java/README.md @@ -49,7 +49,7 @@ private methods, fields, locals, parameters and assignments as info. See the | Tier | `javac` | `pmd` | `spotbugs` | | --- | --- | --- | --- | -| `standard` | Compile flags above, plus Error Prone's default error checks | Error-prone and best-practice rules that find bugs | Ranks 1 to 14 at medium and high confidence, default analysis effort | +| `standard` | Compile flags above, plus Error Prone's default checks | PMD's quickstart ruleset | Every rank at medium and high confidence, default analysis effort | | `strict` | Compile flags above plus `-Xlint:all,-processing` and `-Werror`. Error Prone reports its warnings and a chosen list of off-by-default checks as warnings, and `-Werror` makes them fail the build | Every rule in every PMD category except `AtLeastOneConstructor`, `OnlyOneReturn` (forbids early returns), `LocalVariableDeclarationShouldBeAtStartOfBlock` (contradicts `PrematureDeclaration`), `LoosePackageCoupling` (needs a package list) and `WrongTestAnnotation` (by default it accepts only JUnit Jupiter) | Every rank and confidence, with maximum analysis effort | Strict Error Prone leaves out checks for libraries you may not use (nullness diff --git a/java/private/quality/tools/javac_check/src/dx/quality/javac/JavacCheck.java b/java/private/quality/tools/javac_check/src/dx/quality/javac/JavacCheck.java index 916a38172b..be367c0073 100644 --- a/java/private/quality/tools/javac_check/src/dx/quality/javac/JavacCheck.java +++ b/java/private/quality/tools/javac_check/src/dx/quality/javac/JavacCheck.java @@ -57,6 +57,7 @@ public static String check(List request) throws IOException { List processors = new ArrayList<>(); List options = new ArrayList<>(); List errorProne = new ArrayList<>(); + boolean errorProneRequested = false; for (String line : request) { if (line.isEmpty()) { continue; @@ -89,6 +90,7 @@ public static String check(List request) throws IOException { options.add(value); break; case "errorprone": + errorProneRequested = true; errorProne.addAll(flagLines(Path.of(value))); break; default: @@ -138,11 +140,11 @@ public static String check(List request) throws IOException { if (!processorpath.isEmpty()) { args.addAll(List.of("-processorpath", String.join(File.pathSeparator, processorpath))); } - if (!errorProne.isEmpty()) { + if (errorProneRequested) { args.add("-XDcompilePolicy=simple"); List flags = new ArrayList<>(errorProne); flags.addAll(consumerFlags); - args.add("-Xplugin:ErrorProne " + String.join(" ", flags)); + args.add(("-Xplugin:ErrorProne " + String.join(" ", flags)).strip()); } DiagnosticCollector 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 = []