[analyzer_testing] Propagate linter exceptions by default.

Changes the behavior of the `analysisOptionsContent` function so that
unless `propagateLinterExceptions: false` is passed to it, it creates
an analysis options file that specifies a `true` value for
`propagate-linter-exceptions`.

This ensures that when tests that use `package:analyzer_testing` are
run, exceptions that occur while processing lint rules will cause the
test to fail. Previously, such exceptions would be silently swallowed
by the analyzer, and the test would pass.

Change-Id: I6a6a69643d76cf15d801eab5c4ce6a77c7dbac96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460220
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry
2025-11-06 14:39:20 -08:00
committed by Commit Queue
parent 7e4cc3dabd
commit 3f29cf4b7d
7 changed files with 34 additions and 6 deletions
@@ -125,6 +125,7 @@ class AbstractContextTest
List<String> cannotIgnore = const [],
List<String> lints = const [],
Map<String, Object?> errors = const {},
bool propagateLinterExceptions = true,
bool strictCasts = false,
bool strictInference = false,
bool strictRawTypes = false,
@@ -134,6 +135,7 @@ class AbstractContextTest
includes: includes,
experiments: experiments,
legacyPlugins: legacyPlugins,
propagateLinterExceptions: propagateLinterExceptions,
rules: lints,
errors: errors,
unignorableNames: cannotIgnore,
@@ -23,7 +23,10 @@ class IgnoreDiagnosticAnalysisOptionFileTest extends FixProcessorTest {
FixKind get kind => ignoreErrorAnalysisFileKind;
Future<void> test_addFixToExistingErrorMap() async {
createAnalysisOptionsFile(errors: {'unused_label': 'ignore'});
createAnalysisOptionsFile(
errors: {'unused_label': 'ignore'},
propagateLinterExceptions: false,
);
await resolveTestCode('''
void f() {
@@ -107,6 +110,7 @@ analyzer:
// To create a valid `analyzer` label, we add a `cannot-ignore` label.
// This also implicitly tests when unrelated label is in `cannot-ignore`
cannotIgnore: ['unused_label'],
propagateLinterExceptions: false,
);
await resolveTestCode('''
@@ -139,7 +143,10 @@ void f() {
// Having a newline is important because yaml_edit copies existing
// newlines and we want to test the current platforms EOLs.
// The content is normalized in newFile().
createAnalysisOptionsFile(includes: ['package:lints/recommended.yaml']);
createAnalysisOptionsFile(
includes: ['package:lints/recommended.yaml'],
propagateLinterExceptions: false,
);
await resolveTestCode('''
void f() {
@@ -75,7 +75,10 @@ class ContextBuilderImplTest with ResourceProviderMixin {
var projectPath = convertPath('/home/test');
var optionsFile = newAnalysisOptionsYamlFile(
projectPath,
analysisOptionsContent(strictRawTypes: true),
analysisOptionsContent(
strictRawTypes: true,
propagateLinterExceptions: false,
),
);
var analysisContext = _createSingleAnalysisContext(projectPath);
+7
View File
@@ -1,3 +1,10 @@
## 0.1.8-dev
- Change the behavior of `analysisOptionsContent` so that by default, the
analysis options file used in testing specifies a `true` value for
`propagate-linter-exceptions`. This ensures that when tests are run,
exceptions that occur while processing lint rules will cause the test to fail.
## 0.1.7
- Deprecate `AnalysisRuleTest.analysisRule`; instead of implementing this
+1 -1
View File
@@ -70,7 +70,7 @@ package:analyzer_testing/utilities/extensions/resource_provider.dart:
ResourceProviderExtension (extension on ResourceProvider):
convertPath (method: String Function(String))
package:analyzer_testing/utilities/utilities.dart:
analysisOptionsContent (function: String Function({Map<String, Object?> errors, List<String> experiments, List<String> includes, List<String> legacyPlugins, List<String> rules, bool strictCasts, bool strictInference, bool strictRawTypes, List<String> unignorableNames}))
analysisOptionsContent (function: String Function({Map<String, Object?> errors, List<String> experiments, List<String> includes, List<String> legacyPlugins, bool propagateLinterExceptions, List<String> rules, bool strictCasts, bool strictInference, bool strictRawTypes, List<String> unignorableNames}))
pubspecYamlContent (function: String Function({List<String> dependencies, String? name, String? sdkVersion}))
dart:async:
Future (referenced)
@@ -8,6 +8,7 @@ String analysisOptionsContent({
List<String> includes = const [],
List<String> experiments = const [],
List<String> legacyPlugins = const [],
bool propagateLinterExceptions = true,
List<String> rules = const [],
Map<String, Object?> errors = const {},
bool strictCasts = false,
@@ -30,7 +31,8 @@ String analysisOptionsContent({
errors.isNotEmpty ||
unignorableNames.isNotEmpty ||
legacyPlugins.isNotEmpty ||
experiments.isNotEmpty) {
experiments.isNotEmpty ||
propagateLinterExceptions) {
buffer.writeln('analyzer:');
}
if (experiments.isNotEmpty) {
@@ -74,6 +76,13 @@ String analysisOptionsContent({
}
}
if (propagateLinterExceptions) {
buffer.writeln(' optional-checks:');
buffer.writeln(
' propagate-linter-exceptions: $propagateLinterExceptions',
);
}
if (rules.isNotEmpty) {
buffer.writeln('linter:');
buffer.writeln(' rules:');
+1 -1
View File
@@ -1,6 +1,6 @@
name: analyzer_testing
description: Testing utilities related to the analyzer and analysis_server_plugin packages.
version: 0.1.7
version: 0.1.8-dev
repository: https://github.com/dart-lang/sdk/tree/main/pkg/analyzer_testing
environment: