mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:01:42 +00:00
[analysis_server] Add a test for analysis_options nested in the workspace not handling includes
See https://github.com/dart-lang/sdk/issues/56047 Change-Id: Ic61234cb9cdf30ac7d28989c77eff8048730e891 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372340 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
parent
39497e46fc
commit
2f5dff3586
|
@ -5,6 +5,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:analysis_server/lsp_protocol/protocol.dart';
|
||||
import 'package:analyzer/src/lint/registry.dart';
|
||||
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin;
|
||||
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
|
||||
|
@ -76,6 +77,10 @@ String b = "Test";
|
|||
void setUp() {
|
||||
super.setUp();
|
||||
|
||||
if (Registry.ruleRegistry.isEmpty) {
|
||||
registerLintRules();
|
||||
}
|
||||
|
||||
// These tests deliberately generate diagnostics.
|
||||
failTestOnErrorDiagnostic = false;
|
||||
}
|
||||
|
@ -498,6 +503,56 @@ version: latest
|
|||
expect(diagnostic.range.end.character, equals(12));
|
||||
}
|
||||
|
||||
/// Ensure lints included from another package work when there are multiple
|
||||
/// workspace folders.
|
||||
///
|
||||
/// https://github.com/dart-lang/sdk/issues/56047
|
||||
@skippedTest
|
||||
Future<void> test_lints_includedFromPackage() async {
|
||||
// FailingTest() doesn't handle timeouts so this is marked as skipped.
|
||||
// Needs to be manually updated when
|
||||
// https://github.com/dart-lang/sdk/issues/56047 is fixed.
|
||||
|
||||
var rootWorkspacePath = '$packagesRootPath/root';
|
||||
|
||||
// Set up a project with an analysis_options that enables a lint.
|
||||
var lintsPackagePath = '$rootWorkspacePath/my_lints';
|
||||
newFile('$lintsPackagePath/lib/pubspec.yaml', '''
|
||||
name: my_lints
|
||||
''');
|
||||
newFile('$lintsPackagePath/lib/analysis_options.yaml', '''
|
||||
linter:
|
||||
rules:
|
||||
- avoid_dynamic_calls
|
||||
''');
|
||||
writePackageConfig(convertPath(lintsPackagePath));
|
||||
|
||||
// Set up a project that imports the analysis_options and violates the lint.
|
||||
var projectPackagePath = '$rootWorkspacePath/my_project';
|
||||
writePackageConfig(
|
||||
projectPackagePath,
|
||||
config: (PackageConfigFileBuilder()
|
||||
..add(name: 'my_lints', rootPath: lintsPackagePath)),
|
||||
);
|
||||
newFile('$projectPackagePath/analysis_options.yaml', '''
|
||||
include: package:my_lints/analysis_options.yaml
|
||||
|
||||
linter:
|
||||
rules:
|
||||
- prefer_single_quotes
|
||||
''');
|
||||
newFile('$projectPackagePath/main.dart', '''
|
||||
void f(dynamic a) => a.foo();
|
||||
''');
|
||||
|
||||
// Verify there's an error for the import.
|
||||
var diagnosticsUpdate =
|
||||
waitForDiagnostics(toUri('$projectPackagePath/main.dart'));
|
||||
await initialize(workspaceFolders: [toUri(rootWorkspacePath)]);
|
||||
var diagnostics = await diagnosticsUpdate;
|
||||
expect(diagnostics!.single.code, contains('avoid_dynamic_calls'));
|
||||
}
|
||||
|
||||
Future<void> test_looseFile_withoutPubpsec() async {
|
||||
await initialize(allowEmptyRootUri: true);
|
||||
|
||||
|
@ -539,7 +594,6 @@ void f() {
|
|||
}
|
||||
''';
|
||||
|
||||
registerLintRules();
|
||||
newFile(analysisOptionsPath, '''
|
||||
linter:
|
||||
rules:
|
||||
|
|
Loading…
Reference in a new issue