Skip to content

Commit

Permalink
[analyzer] Don't crash on certain types of invalid data in analysis_o…
Browse files Browse the repository at this point in the history
…ptions linter config

Fixes #56577
Fixes #55594

Change-Id: I1e69937cd104e8101a7f87b7c9b8ce26b914b3a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382605
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
  • Loading branch information
DanTup authored and Commit Queue committed Aug 28, 2024
1 parent ddab694 commit bbe6f23
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/lint/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class _LintConfig implements LintConfig {
}

String? asString(Object scalar) {
var value = scalar is YamlScalar ? scalar.valueOrThrow : scalar;
var value = scalar is YamlScalar ? scalar.value : scalar;
if (value is String) {
return value;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ class _LintConfig implements LintConfig {
var config = _RuleConfig();
config.group = asString(key);
config.name = asString(rule);
config.args = parseArgs(args)!;
config.args = parseArgs(args) ?? {};
ruleConfigs.add(config);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,74 @@ workspaces
''');
}

/// Verify the type of invalid data in
/// https://github.com/dart-lang/sdk/issues/55594 doesn't result in unhandled
/// exceptions when building contexts.
test_basicWorkspace_invalidAnalysisOption_issue55594() async {
var workspaceRootPath = '/home';
var testPackageRootPath = '$workspaceRootPath/test';
newFile('$testPackageRootPath/lib/a.dart', '');

newAnalysisOptionsYamlFile(testPackageRootPath, '''
linter:
rules:
- camel_case_types
- file_names
- non_constant_identifier_names
- comment_references
-
''');

_assertWorkspaceCollectionText(workspaceRootPath, r'''
contexts
/home
workspace: workspace_0
analyzedFiles
/home/test/lib/a.dart
analysisOptions_0
workspacePackage_0_0
analysisOptions
analysisOptions_0: /home/test/analysis_options.yaml
workspaces
workspace_0: BasicWorkspace
root: /home
workspacePackage_0_0
''');
}

/// Verify the type of invalid data in
/// https://github.com/dart-lang/sdk/issues/56577 doesn't result in unhandled
/// exceptions when building contexts.
test_basicWorkspace_invalidAnalysisOption_issue56577() async {
var workspaceRootPath = '/home';
var testPackageRootPath = '$workspaceRootPath/test';
newFile('$testPackageRootPath/lib/a.dart', '');

newAnalysisOptionsYamlFile(testPackageRootPath, '''
linter:
rules:
analyzer:
errors:
todo: ignore
''');

_assertWorkspaceCollectionText(workspaceRootPath, r'''
contexts
/home
workspace: workspace_0
analyzedFiles
/home/test/lib/a.dart
analysisOptions_0
workspacePackage_0_0
analysisOptions
analysisOptions_0: /home/test/analysis_options.yaml
workspaces
workspace_0: BasicWorkspace
root: /home
workspacePackage_0_0
''');
}

test_packageConfigWorkspace_enabledExperiment() async {
configuration.withEnabledFeatures = true;

Expand Down

0 comments on commit bbe6f23

Please sign in to comment.