diff --git a/pkg/analyzer_cli/lib/src/build_mode.dart b/pkg/analyzer_cli/lib/src/build_mode.dart index a8e97572ddf..5beef119944 100644 --- a/pkg/analyzer_cli/lib/src/build_mode.dart +++ b/pkg/analyzer_cli/lib/src/build_mode.dart @@ -270,7 +270,8 @@ class BuildMode { ]); // Set context options. - Driver.setAnalysisContextOptions(resourceProvider, context, options, + Driver.setAnalysisContextOptions( + resourceProvider, context.sourceFactory, context, options, (AnalysisOptionsImpl contextOptions) { if (options.buildSummaryOnlyDiet) { contextOptions.analyzeFunctionBodies = false; diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart index 16ec22d2fa3..35caf046d23 100644 --- a/pkg/analyzer_cli/lib/src/driver.dart +++ b/pkg/analyzer_cli/lib/src/driver.dart @@ -491,13 +491,6 @@ class Driver implements CommandLineStarter { // Create a context. _context = AnalysisEngine.instance.createAnalysisContext(); - AnalyzeFunctionBodiesPredicate dietParsingPolicy = - _chooseDietParsingPolicy(options); - setAnalysisContextOptions(resourceProvider, _context, options, - (AnalysisOptionsImpl contextOptions) { - contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy; - }); - // Find package info. _PackageInfo packageInfo = _findPackages(options); @@ -528,6 +521,14 @@ class Driver implements CommandLineStarter { SourceFactory sourceFactory = _chooseUriResolutionPolicy( options, embedderMap, packageInfo, summaryDataStore); + AnalyzeFunctionBodiesPredicate dietParsingPolicy = + _chooseDietParsingPolicy(options); + setAnalysisContextOptions( + resourceProvider, sourceFactory, _context, options, + (AnalysisOptionsImpl contextOptions) { + contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy; + }); + _context.sourceFactory = sourceFactory; _context.resultProvider = new InputPackagesResultProvider(_context, summaryDataStore); @@ -680,6 +681,7 @@ class Driver implements CommandLineStarter { static void setAnalysisContextOptions( file_system.ResourceProvider resourceProvider, + SourceFactory sourceFactory, AnalysisContext context, CommandLineOptions options, void configureContextOptions(AnalysisOptionsImpl contextOptions)) { @@ -704,7 +706,7 @@ class Driver implements CommandLineStarter { context.analysisOptions = contextOptions; // Process analysis options file (and notify all interested parties). - _processAnalysisOptions(resourceProvider, context, options); + _processAnalysisOptions(resourceProvider, sourceFactory, context, options); } /// Perform a deep comparison of two string lists. @@ -761,14 +763,16 @@ class Driver implements CommandLineStarter { static void _processAnalysisOptions( file_system.ResourceProvider resourceProvider, + SourceFactory sourceFactory, AnalysisContext context, CommandLineOptions options) { file_system.File file = _getOptionsFile(resourceProvider, options); List optionsProcessors = AnalysisEngine.instance.optionsPlugin.optionsProcessors; + try { AnalysisOptionsProvider analysisOptionsProvider = - new AnalysisOptionsProvider(); + new AnalysisOptionsProvider(sourceFactory); Map optionMap = analysisOptionsProvider.getOptionsFromFile(file); optionsProcessors.forEach( diff --git a/pkg/analyzer_cli/test/data/options_include_directive_tests_project/.analysis_options b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/.analysis_options new file mode 100644 index 00000000000..7d954249ead --- /dev/null +++ b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/.analysis_options @@ -0,0 +1 @@ +include: other_options.yaml diff --git a/pkg/analyzer_cli/test/data/options_include_directive_tests_project/_packages b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/_packages new file mode 100644 index 00000000000..574bcbd9ff6 --- /dev/null +++ b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/_packages @@ -0,0 +1,3 @@ +# Generated by pub on 2016-11-30 13:02:00.280796. +foo:pkg/foo/lib/ +options_include_directive_tests_project:lib/ diff --git a/pkg/analyzer_cli/test/data/options_include_directive_tests_project/lib/test_file.dart b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/lib/test_file.dart new file mode 100644 index 00000000000..c53a7e080f7 --- /dev/null +++ b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/lib/test_file.dart @@ -0,0 +1,16 @@ +// 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. + +library analyzer_cli.test.data.options_include_directive_test_project.test_file; + + +int foo() { + + int x = baz(); // Undefined function. + if (x == 0) { + print('x is zero'); + } else ; // Empty else statement + + // Missing return +} diff --git a/pkg/analyzer_cli/test/data/options_include_directive_tests_project/other_options.yaml b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/other_options.yaml new file mode 100644 index 00000000000..c27dd4a63e4 --- /dev/null +++ b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/other_options.yaml @@ -0,0 +1 @@ +include: package:foo/foo_package_options.yaml diff --git a/pkg/analyzer_cli/test/data/options_include_directive_tests_project/pkg/foo/lib/foo_package_options.yaml b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/pkg/foo/lib/foo_package_options.yaml new file mode 100644 index 00000000000..89c0bf6a4f6 --- /dev/null +++ b/pkg/analyzer_cli/test/data/options_include_directive_tests_project/pkg/foo/lib/foo_package_options.yaml @@ -0,0 +1,13 @@ +analyzer: + strong-mode: true + errors: + unused_local_variable: ignore + missing_return: error + undefined_function: warning + language: + enableSuperMixins: true + +linter: + rules: + # see catalog here: http://dart-lang.github.io/linter/lints/ + - avoid_empty_else diff --git a/pkg/analyzer_cli/test/driver_test.dart b/pkg/analyzer_cli/test/driver_test.dart index 222d96d63be..f582e59cdb4 100644 --- a/pkg/analyzer_cli/test/driver_test.dart +++ b/pkg/analyzer_cli/test/driver_test.dart @@ -306,6 +306,25 @@ linter: createTests('old', AnalysisEngine.ANALYSIS_OPTIONS_FILE); createTests('new', AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); + + test('include directive', () { + String testDir = path.join( + testDirectory, 'data', 'options_include_directive_tests_project'); + drive( + path.join(testDir, 'lib', 'test_file.dart'), + args: [ + '--fatal-warnings', + '--packages', + path.join(testDir, '_packages'), + ], + options: path.join(testDir, '.analysis_options'), + ); + expect(exitCode, 3); + expect(outSink.toString(), + contains('but doesn\'t end with a return statement.')); + expect(outSink.toString(), contains('isn\'t defined')); + expect(outSink.toString(), contains('Avoid empty else statements.')); + }); }); void createTests(String designator, String optionsFileName) {