Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59739666 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Prevent disabling checks via flags property" into main

parents a8a5f642 5d0aaf42
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -370,6 +370,12 @@ func (l *linter) lint(ctx android.ModuleContext) {
		return
	}

	for _, flag := range l.properties.Lint.Flags {
		if strings.Contains(flag, "--disable") || strings.Contains(flag, "--enable") || strings.Contains(flag, "--check") {
			ctx.PropertyErrorf("lint.flags", "Don't use --disable, --enable, or --check in the flags field, instead use the dedicated disabled_checks, warning_checks, error_checks, or fatal_checks fields")
		}
	}

	if l.minSdkVersion.CompareTo(l.compileSdkVersion) == -1 {
		l.extraMainlineLintErrors = append(l.extraMainlineLintErrors, updatabilityChecks...)
		// Skip lint warning checks for NewApi warnings for libcore where they come from source
+19 −0
Original line number Diff line number Diff line
@@ -260,3 +260,22 @@ func TestJavaLintDatabaseSelectionFull(t *testing.T) {
		}
	}
}

func TestCantControlCheckSeverityWithFlags(t *testing.T) {
	bp := `
		java_library {
			name: "foo",
			srcs: [
				"a.java",
			],
			min_sdk_version: "29",
			sdk_version: "current",
			lint: {
				flags: ["--disabled", "NewApi"],
			},
		}
	`
	PrepareForTestWithJavaDefaultModules.
		ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("Don't use --disable, --enable, or --check in the flags field, instead use the dedicated disabled_checks, warning_checks, error_checks, or fatal_checks fields")).
		RunTestWithBp(t, bp)
}