mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:07:49 +00:00
remove support for analyzer configuration in pubspec
This removes support for having directives like this in your pubspec: analyzer: configuration: test_pack/config R=brianwilkerson@google.com Review URL: https://codereview.chromium.org/2511963002 .
This commit is contained in:
parent
5399d8acf6
commit
74d713ece9
|
@ -16,7 +16,6 @@ import 'package:analyzer/instrumentation/instrumentation.dart';
|
|||
import 'package:analyzer/plugin/options.dart';
|
||||
import 'package:analyzer/plugin/resolver_provider.dart';
|
||||
import 'package:analyzer/source/analysis_options_provider.dart';
|
||||
import 'package:analyzer/source/config.dart';
|
||||
import 'package:analyzer/source/package_map_provider.dart';
|
||||
import 'package:analyzer/source/package_map_resolver.dart';
|
||||
import 'package:analyzer/source/path_filter.dart';
|
||||
|
@ -1104,17 +1103,6 @@ class ContextManagerImpl implements ContextManager {
|
|||
pubspec = child;
|
||||
}
|
||||
}
|
||||
if (pubspec != null) {
|
||||
File pubSource = resourceProvider.getFile(pubspec.path);
|
||||
if (enableNewAnalysisDriver) {
|
||||
// TODO(scheglov) implement for the new analysis driver
|
||||
} else {
|
||||
setConfiguration(
|
||||
info.context,
|
||||
new AnalysisConfiguration.fromPubspec(
|
||||
pubSource, resourceProvider, disposition.packages));
|
||||
}
|
||||
}
|
||||
|
||||
if (enableNewAnalysisDriver) {
|
||||
// TODO(scheglov) implement for the new analysis driver
|
||||
|
@ -1272,18 +1260,6 @@ class ContextManagerImpl implements ContextManager {
|
|||
if (maps.length == 1) {
|
||||
embeddedOptions = maps.first;
|
||||
}
|
||||
|
||||
AnalysisConfiguration configuration = getConfiguration(info.context);
|
||||
if (configuration != null) {
|
||||
Map configMap = configuration.options;
|
||||
if (configMap != null) {
|
||||
if (embeddedOptions != null) {
|
||||
embeddedOptions = new Merger().merge(embeddedOptions, configMap);
|
||||
} else {
|
||||
embeddedOptions = configMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
return embeddedOptions;
|
||||
}
|
||||
|
||||
|
|
|
@ -1992,217 +1992,6 @@ linter:
|
|||
// No error means success.
|
||||
}
|
||||
|
||||
test_configed_options() async {
|
||||
// Create files.
|
||||
String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
|
||||
newFile([projPath, 'test', 'test.dart']);
|
||||
newFile(
|
||||
[projPath, 'pubspec.yaml'],
|
||||
r'''
|
||||
dependencies:
|
||||
test_pack: any
|
||||
analyzer:
|
||||
configuration: test_pack/config
|
||||
''');
|
||||
|
||||
// Setup .packages file
|
||||
newFile(
|
||||
[projPath, '.packages'],
|
||||
r'''
|
||||
test_pack:lib/''');
|
||||
|
||||
// Setup config.yaml.
|
||||
newFile(
|
||||
[libPath, 'config', 'config.yaml'],
|
||||
r'''
|
||||
analyzer:
|
||||
strong-mode: true
|
||||
language:
|
||||
enableSuperMixins: true
|
||||
errors:
|
||||
missing_return: false
|
||||
linter:
|
||||
rules:
|
||||
- avoid_as
|
||||
''');
|
||||
|
||||
// Setup analysis options
|
||||
newFile(
|
||||
[projPath, optionsFileName],
|
||||
r'''
|
||||
analyzer:
|
||||
exclude:
|
||||
- 'test/**'
|
||||
language:
|
||||
enableGenericMethods: true
|
||||
errors:
|
||||
unused_local_variable: false
|
||||
linter:
|
||||
rules:
|
||||
- camel_case_types
|
||||
''');
|
||||
|
||||
// Setup context.
|
||||
manager.setRoots(<String>[projPath], <String>[], <String, String>{});
|
||||
await pumpEventQueue();
|
||||
|
||||
// Confirm that one context was created.
|
||||
var contexts =
|
||||
manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
|
||||
expect(contexts, isNotNull);
|
||||
expect(contexts, hasLength(1));
|
||||
|
||||
var context = contexts.first;
|
||||
|
||||
// Verify options.
|
||||
// * from `config.yaml`:
|
||||
expect(context.analysisOptions.strongMode, isTrue);
|
||||
expect(context.analysisOptions.enableSuperMixins, isTrue);
|
||||
// * from analysis options:
|
||||
expect(context.analysisOptions.enableGenericMethods, isTrue);
|
||||
|
||||
// * verify tests are excluded
|
||||
expect(callbacks.currentContextFilePaths[projPath].keys,
|
||||
unorderedEquals(['/my/proj/$optionsFileName']));
|
||||
|
||||
// Verify filter setup.
|
||||
expect(errorProcessors, hasLength(2));
|
||||
|
||||
// * (config.)
|
||||
expect(getProcessor(missing_return).severity, isNull);
|
||||
|
||||
// * (options.)
|
||||
expect(getProcessor(unused_local_variable).severity, isNull);
|
||||
|
||||
// Verify lints.
|
||||
var lintNames = lints.map((lint) => lint.name);
|
||||
expect(
|
||||
lintNames,
|
||||
unorderedEquals(
|
||||
['avoid_as' /* config */, 'camel_case_types' /* options */]));
|
||||
}
|
||||
|
||||
test_embedder_and_configed_options() async {
|
||||
// Create files.
|
||||
String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
|
||||
String sdkExtPath = newFolder([projPath, 'sdk_ext']);
|
||||
newFile([projPath, 'test', 'test.dart']);
|
||||
newFile([sdkExtPath, 'entry.dart']);
|
||||
|
||||
// Setup pubspec with configuration.
|
||||
newFile(
|
||||
[projPath, 'pubspec.yaml'],
|
||||
r'''
|
||||
dependencies:
|
||||
test_pack: any
|
||||
analyzer:
|
||||
configuration: test_pack/config
|
||||
''');
|
||||
|
||||
// Setup _embedder.yaml.
|
||||
newFile(
|
||||
[libPath, '_embedder.yaml'],
|
||||
r'''
|
||||
embedded_libs:
|
||||
"dart:foobar": "../sdk_ext/entry.dart"
|
||||
analyzer:
|
||||
strong-mode: true
|
||||
language:
|
||||
enableSuperMixins: true
|
||||
errors:
|
||||
missing_return: false
|
||||
linter:
|
||||
rules:
|
||||
- avoid_as
|
||||
''');
|
||||
|
||||
// Setup .packages file
|
||||
newFile(
|
||||
[projPath, '.packages'],
|
||||
r'''
|
||||
test_pack:lib/''');
|
||||
|
||||
// Setup analysis options
|
||||
newFile(
|
||||
[projPath, optionsFileName],
|
||||
r'''
|
||||
analyzer:
|
||||
exclude:
|
||||
- 'test/**'
|
||||
language:
|
||||
enableGenericMethods: true
|
||||
errors:
|
||||
unused_local_variable: false
|
||||
linter:
|
||||
rules:
|
||||
- camel_case_types
|
||||
''');
|
||||
|
||||
// Setup config.yaml.
|
||||
newFile(
|
||||
[libPath, 'config', 'config.yaml'],
|
||||
r'''
|
||||
analyzer:
|
||||
errors:
|
||||
missing_required_param: error
|
||||
linter:
|
||||
rules:
|
||||
- always_specify_types
|
||||
''');
|
||||
|
||||
// Setup context.
|
||||
manager.setRoots(<String>[projPath], <String>[], <String, String>{});
|
||||
await pumpEventQueue();
|
||||
|
||||
// Confirm that one context was created.
|
||||
var contexts =
|
||||
manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
|
||||
expect(contexts, isNotNull);
|
||||
expect(contexts, hasLength(1));
|
||||
var context = contexts[0];
|
||||
|
||||
// Verify options.
|
||||
// * from `_embedder.yaml`:
|
||||
expect(context.analysisOptions.strongMode, isTrue);
|
||||
expect(context.analysisOptions.enableSuperMixins, isTrue);
|
||||
// * from analysis options:
|
||||
expect(context.analysisOptions.enableGenericMethods, isTrue);
|
||||
|
||||
// * verify tests are excluded
|
||||
expect(
|
||||
callbacks.currentContextFilePaths[projPath].keys,
|
||||
unorderedEquals(
|
||||
['/my/proj/sdk_ext/entry.dart', '/my/proj/$optionsFileName']));
|
||||
|
||||
// Verify filter setup.
|
||||
expect(errorProcessors, hasLength(3));
|
||||
|
||||
// * (embedder.)
|
||||
expect(getProcessor(missing_return).severity, isNull);
|
||||
|
||||
// * (config.)
|
||||
expect(getProcessor(missing_required_param).severity, ErrorSeverity.ERROR);
|
||||
|
||||
// * (options.)
|
||||
expect(getProcessor(unused_local_variable).severity, isNull);
|
||||
|
||||
// Verify lints.
|
||||
var lintNames = lints.map((lint) => lint.name);
|
||||
|
||||
expect(
|
||||
lintNames,
|
||||
unorderedEquals([
|
||||
'avoid_as' /* embedder */,
|
||||
'always_specify_types' /* config*/,
|
||||
'camel_case_types' /* options */
|
||||
]));
|
||||
|
||||
// Sanity check embedder libs.
|
||||
var source = context.sourceFactory.forUri('dart:foobar');
|
||||
expect(source, isNotNull);
|
||||
expect(source.fullName, '/my/proj/sdk_ext/entry.dart');
|
||||
}
|
||||
|
||||
test_embedder_options() async {
|
||||
// Create files.
|
||||
String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/source/analysis_options_provider.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/task/model.dart';
|
||||
import 'package:analyzer/task/model.dart';
|
||||
import 'package:package_config/packages.dart';
|
||||
import 'package:yaml/src/yaml_node.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
/// The descriptor used to associate analysis configuration with analysis
|
||||
/// contexts in configuration data.
|
||||
final ResultDescriptor<AnalysisConfiguration> ANALYSIS_CONFIGURATION =
|
||||
new ResultDescriptorImpl('analysis.config', null);
|
||||
|
||||
/// Return configuration associated with this [context], or `null` if there is
|
||||
/// none.
|
||||
AnalysisConfiguration getConfiguration(AnalysisContext context) =>
|
||||
context.getConfigurationData(ANALYSIS_CONFIGURATION);
|
||||
|
||||
/// Associate this [config] with the given [context].
|
||||
void setConfiguration(AnalysisContext context, AnalysisConfiguration config) {
|
||||
context.setConfigurationData(ANALYSIS_CONFIGURATION, config);
|
||||
}
|
||||
|
||||
/// Analysis configuration.
|
||||
abstract class AnalysisConfiguration {
|
||||
final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider();
|
||||
final Packages packages;
|
||||
final ResourceProvider resourceProvider;
|
||||
AnalysisConfiguration(this.resourceProvider, this.packages);
|
||||
|
||||
factory AnalysisConfiguration.fromPubspec(
|
||||
File pubspec, ResourceProvider resourceProvider, Packages packages) =>
|
||||
new PubspecConfiguration(pubspec, resourceProvider, packages);
|
||||
|
||||
/// Get a map of options defined by this configuration (or `null` if none
|
||||
/// are specified).
|
||||
Map get options;
|
||||
}
|
||||
|
||||
/// Describes an analysis configuration.
|
||||
class AnalysisConfigurationDescriptor {
|
||||
/// The name of the package hosting the configuration.
|
||||
String package;
|
||||
|
||||
/// The name of the configuration "pragma".
|
||||
String pragma;
|
||||
|
||||
AnalysisConfigurationDescriptor.fromAnalyzerOptions(Map analyzerOptions) {
|
||||
Object config = analyzerOptions['configuration'];
|
||||
if (config is String) {
|
||||
List<String> items = config.split('/');
|
||||
if (items.length == 2) {
|
||||
package = items[0].trim();
|
||||
pragma = items[1].trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Return true if this descriptor is valid.
|
||||
bool get isValid => package != null && pragma != null;
|
||||
}
|
||||
|
||||
/// Pubspec-specified analysis configuration.
|
||||
class PubspecConfiguration extends AnalysisConfiguration {
|
||||
final File pubspec;
|
||||
PubspecConfiguration(
|
||||
this.pubspec, ResourceProvider resourceProvider, Packages packages)
|
||||
: super(resourceProvider, packages);
|
||||
|
||||
@override
|
||||
Map get options {
|
||||
//Safest not to cache (requested infrequently).
|
||||
if (pubspec.exists) {
|
||||
try {
|
||||
String contents = pubspec.readAsStringSync();
|
||||
YamlNode map = loadYamlNode(contents);
|
||||
if (map is YamlMap) {
|
||||
YamlNode config = map['analyzer'];
|
||||
if (config is YamlMap) {
|
||||
AnalysisConfigurationDescriptor descriptor =
|
||||
new AnalysisConfigurationDescriptor.fromAnalyzerOptions(config);
|
||||
|
||||
if (descriptor.isValid) {
|
||||
//Create a path, given descriptor and packagemap
|
||||
Uri uri = packages.asMap()[descriptor.package];
|
||||
Uri pragma = new Uri.file('config/${descriptor.pragma}.yaml',
|
||||
windows: false);
|
||||
Uri optionsUri = uri.resolveUri(pragma);
|
||||
String path = resourceProvider.pathContext.fromUri(optionsUri);
|
||||
File file = resourceProvider.getFile(path);
|
||||
if (file.exists) {
|
||||
return optionsProvider.getOptionsFromFile(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_) {
|
||||
// Skip exceptional configurations.
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/source/config.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
main() {
|
||||
group('Analysis Config', () {
|
||||
test('parseConfigSource', () {
|
||||
String source = r'''
|
||||
analyzer:
|
||||
configuration: google/strict
|
||||
''';
|
||||
YamlMap options = loadYamlNode(source);
|
||||
AnalysisConfigurationDescriptor descriptor =
|
||||
new AnalysisConfigurationDescriptor.fromAnalyzerOptions(
|
||||
options['analyzer']);
|
||||
expect(descriptor.package, 'google');
|
||||
expect(descriptor.pragma, 'strict');
|
||||
});
|
||||
});
|
||||
}
|
|
@ -7,7 +7,6 @@ library analyzer.test.source.test_all;
|
|||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'analysis_options_provider_test.dart' as analysis_options_provider_test;
|
||||
import 'config_test.dart' as config_test;
|
||||
import 'embedder_test.dart' as embedder_test;
|
||||
import 'error_processor_test.dart' as error_processor_test;
|
||||
import 'package_map_provider_test.dart' as package_map_provider_test;
|
||||
|
@ -19,7 +18,6 @@ import 'sdk_ext_test.dart' as sdk_ext_test;
|
|||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
analysis_options_provider_test.main();
|
||||
config_test.main();
|
||||
embedder_test.main();
|
||||
error_processor_test.main();
|
||||
package_map_provider_test.main();
|
||||
|
|
Loading…
Reference in a new issue