Version 2.13.0-107.0.dev
Merge commit '10a0c238ce55fcd74dd107e763424b3dd90d0cce' into 'dev'
diff --git a/pkg/analyzer/lib/src/context/builder.dart b/pkg/analyzer/lib/src/context/builder.dart
index f8ac509..a388bb3 100644
--- a/pkg/analyzer/lib/src/context/builder.dart
+++ b/pkg/analyzer/lib/src/context/builder.dart
@@ -9,7 +9,7 @@
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/analysis_options/analysis_options_provider.dart';
import 'package:analyzer/src/command_line/arguments.dart'
- show applyAnalysisOptionFlags, flutterAnalysisOptionsPath;
+ show applyAnalysisOptionFlags;
import 'package:analyzer/src/context/context_root.dart';
import 'package:analyzer/src/context/packages.dart';
import 'package:analyzer/src/dart/analysis/byte_store.dart';
@@ -281,27 +281,6 @@
// Ignore exceptions thrown while trying to load the options file.
verbose('Exception: $e\n when loading ${optionsFile.path}');
}
- } else {
- // Search for the default analysis options.
- Source? source;
- if (workspace is WorkspaceWithDefaultAnalysisOptions) {
- source = sourceFactory.forUri(WorkspaceWithDefaultAnalysisOptions.uri);
- } else {
- source = sourceFactory.forUri(flutterAnalysisOptionsPath);
- }
-
- if (source != null && source.exists()) {
- try {
- optionMap = optionsProvider.getOptionsFromSource(source);
- if (contextRoot != null) {
- contextRoot.optionsFilePath = source.fullName;
- }
- verbose('Loaded analysis options from ${source.fullName}');
- } catch (e) {
- // Ignore exceptions thrown while trying to load the options file.
- verbose('Exception: $e\n when loading ${source.fullName}');
- }
- }
}
if (optionMap != null) {
diff --git a/pkg/analyzer/lib/src/dart/analysis/context_locator.dart b/pkg/analyzer/lib/src/dart/analysis/context_locator.dart
index 6612823..6b341e8 100644
--- a/pkg/analyzer/lib/src/dart/analysis/context_locator.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/context_locator.dart
@@ -232,6 +232,8 @@
required File? optionsFile,
required File? packagesFile,
}) {
+ optionsFile ??= _findDefaultOptionsFile(workspace);
+
var root = ContextRootImpl(resourceProvider, rootFolder, workspace);
root.packagesFile = packagesFile;
root.optionsFile = optionsFile;
@@ -372,6 +374,26 @@
);
}
+ File? _findDefaultOptionsFile(Workspace workspace) {
+ // TODO(scheglov) Create SourceFactory once.
+ var sourceFactory = workspace.createSourceFactory(null, null);
+
+ String? uriStr;
+ if (workspace is WorkspaceWithDefaultAnalysisOptions) {
+ uriStr = WorkspaceWithDefaultAnalysisOptions.uri;
+ } else {
+ uriStr = 'package:flutter/analysis_options_user.yaml';
+ }
+
+ var path = sourceFactory.forUri(uriStr)?.fullName;
+ if (path != null) {
+ var file = resourceProvider.getFile(path);
+ if (file.exists) {
+ return file;
+ }
+ }
+ }
+
/// Return the analysis options file to be used to analyze files in the given
/// [folder], or `null` if there is no analysis options file in the given
/// folder or any parent folder.
diff --git a/pkg/analyzer/test/src/context/builder_test.dart b/pkg/analyzer/test/src/context/builder_test.dart
index 00d5959..55fb085 100644
--- a/pkg/analyzer/test/src/context/builder_test.dart
+++ b/pkg/analyzer/test/src/context/builder_test.dart
@@ -484,49 +484,6 @@
expect(htmlSource.exists(), isTrue);
}
- void test_getAnalysisOptions_default_bazel() {
- _defineMockLintRules();
- AnalysisOptionsImpl defaultOptions = AnalysisOptionsImpl();
- builderOptions.defaultOptions = defaultOptions;
- AnalysisOptionsImpl expected = AnalysisOptionsImpl();
- expected.lint = true;
- expected.lintRules = <Linter>[_mockLintRule];
- newFile('/root/WORKSPACE');
- newFile('/root/dart/analysis_options/lib/default.yaml', content: '''
-linter:
- rules:
- - mock_lint_rule
-''');
- newFile('/root/dart/analysis_options/lib/flutter.yaml', content: '''
-linter:
- rules:
- - mock_lint_rule2
-''');
- var options = _getAnalysisOptions(builder, convertPath('/root/some/path'));
- _expectEqualOptions(options, expected);
- }
-
- void test_getAnalysisOptions_default_flutter() {
- _defineMockLintRules();
- AnalysisOptionsImpl defaultOptions = AnalysisOptionsImpl();
- builderOptions.defaultOptions = defaultOptions;
- AnalysisOptionsImpl expected = AnalysisOptionsImpl();
- expected.lint = true;
- expected.lintRules = <Linter>[_mockLintRule];
- String packagesFilePath = convertPath('/some/directory/path/.packages');
- newFile(packagesFilePath, content: '''
-flutter:${toUriStr('/pkg/flutter/lib/')}
-''');
- newFile('/pkg/flutter/lib/analysis_options_user.yaml', content: '''
-linter:
- rules:
- - mock_lint_rule
-''');
- String projectPath = convertPath('/some/directory/path');
- var options = _getAnalysisOptions(builder, projectPath);
- _expectEqualOptions(options, expected);
- }
-
void test_getAnalysisOptions_default_noOverrides() {
AnalysisOptionsImpl defaultOptions = AnalysisOptionsImpl();
builderOptions.defaultOptions = defaultOptions;
diff --git a/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart b/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart
index 709a567..1166f42 100644
--- a/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart
@@ -5,8 +5,8 @@
import 'package:analyzer/dart/analysis/context_root.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/context_locator.dart';
+import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
-import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:analyzer/src/workspace/basic.dart';
import 'package:analyzer/src/workspace/bazel.dart';
import 'package:analyzer/src/workspace/pub.dart';
@@ -819,9 +819,10 @@
void test_locateRoots_nested_packageConfigJson() {
var outerRootFolder = newFolder('/test/outer');
var outerOptionsFile = newAnalysisOptionsYamlFile('/test/outer');
- var outerPackagesFile = _newPackageConfigFile('/test/outer');
+ var outerPackagesFile = newPackageConfigJsonFile('/test/outer');
var innerRootFolder = newFolder('/test/outer/examples/inner');
- var innerPackagesFile = _newPackageConfigFile('/test/outer/examples/inner');
+ var innerPackagesFile =
+ newPackageConfigJsonFile('/test/outer/examples/inner');
var roots = contextLocator.locateRoots(
includedPaths: [outerRootFolder.path],
@@ -930,6 +931,55 @@
expect(outerRoot.packagesFile, outerPackagesFile);
}
+ void test_locateRoots_options_default_bazel() {
+ var workspacePath = '/home/workspace';
+ var workspaceFolder = getFolder(workspacePath);
+ newFile('$workspacePath/WORKSPACE');
+ var bazelOptionsFile = newFile(
+ '$workspacePath/dart/analysis_options/lib/default.yaml',
+ );
+
+ var rootFolder = getFolder('$workspacePath/test');
+
+ var roots = contextLocator.locateRoots(
+ includedPaths: [rootFolder.path],
+ );
+ expect(roots, hasLength(1));
+
+ var root = findRoot(roots, workspaceFolder);
+ expect(root.includedPaths, unorderedEquals([rootFolder.path]));
+ expect(root.excludedPaths, isEmpty);
+ expect(root.optionsFile, bazelOptionsFile);
+ expect(root.packagesFile, isNull);
+ }
+
+ void test_locateRoots_options_default_flutter() {
+ var rootFolder = newFolder('/home/test');
+
+ var flutterPath = '/home/packages/flutter';
+ var flutterAnalysisOptionsFile = newFile(
+ '$flutterPath/lib/analysis_options_user.yaml',
+ );
+
+ var packageConfigFileBuilder = PackageConfigFileBuilder()
+ ..add(name: 'flutter', rootPath: flutterPath);
+ var packagesFile = newPackageConfigJsonFile(
+ rootFolder.path,
+ content: packageConfigFileBuilder.toContent(toUriStr: toUriStr),
+ );
+
+ var roots = contextLocator.locateRoots(
+ includedPaths: [rootFolder.path],
+ );
+ expect(roots, hasLength(1));
+
+ var root = findRoot(roots, rootFolder);
+ expect(root.includedPaths, unorderedEquals([rootFolder.path]));
+ expect(root.excludedPaths, isEmpty);
+ expect(root.optionsFile, flutterAnalysisOptionsFile);
+ expect(root.packagesFile, packagesFile);
+ }
+
void test_locateRoots_options_hasError() {
Folder rootFolder = newFolder('/test/root');
File optionsFile = newAnalysisOptionsYamlFile('/test/root', content: '''
@@ -1226,7 +1276,7 @@
var rootFolder = newFolder('/test');
var optionsFile = newAnalysisOptionsYamlFile('/test');
newDotPackagesFile('/test'); // the file is not used
- var packageConfigJsonFile = _newPackageConfigFile('/test');
+ var packageConfigJsonFile = newPackageConfigJsonFile('/test');
var roots = contextLocator.locateRoots(includedPaths: [rootFolder.path]);
expect(roots, hasLength(1));
@@ -1317,13 +1367,4 @@
var root = convertPath(posixRoot);
expect(workspace.root, root);
}
-
- File _newPackageConfigFile(String directoryPath) {
- String path = join(
- directoryPath,
- file_paths.dotDartTool,
- file_paths.packageConfigJson,
- );
- return newFile(path);
- }
}
diff --git a/tools/VERSION b/tools/VERSION
index 2d94919..0af9dd2 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 13
PATCH 0
-PRERELEASE 106
+PRERELEASE 107
PRERELEASE_PATCH 0
\ No newline at end of file