Do not check for '.analysis_options' for default options file in builder.

Change-Id: I9decba4d0db318caedcfd3695f41c127b66f416f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138660
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
This commit is contained in:
Keerti Parthasarathy 2020-03-09 19:31:24 +00:00 committed by commit-bot@chromium.org
parent 4f0fb8f9b0
commit 8329bd7ca8
15 changed files with 21 additions and 198 deletions

View file

@ -147,6 +147,10 @@ The Linter was updated to `0.1.112`, which includes:
* new lint: `unnecessary_string_escapes`
* incompatible rule documentation improvements
#### Analyzer
* Removed support for the deprecated analysis options file name `.analysis_options`.
#### Pub
* `pub get` and `pub upgrade` now fetches version information about hosted

View file

@ -78,7 +78,6 @@ abstract class AbstractAnalysisServer {
'**/*.${AnalysisEngine.SUFFIX_DART}',
'**/*.${AnalysisEngine.SUFFIX_HTML}',
'**/*.${AnalysisEngine.SUFFIX_HTM}',
'**/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}',
'**/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}',
'**/${AnalysisEngine.PUBSPEC_YAML_FILE}',
'**/${AnalysisEngine.ANDROID_MANIFEST_FILE}'

View file

@ -17,13 +17,12 @@ import '../analysis_abstract.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(NewAnalysisOptionsFileNotificationTest);
defineReflectiveTests(OldAnalysisOptionsFileNotificationTest);
defineReflectiveTests(AnalysisOptionsFileNotificationTest);
});
}
abstract class AnalysisOptionsFileNotificationTest
extends AbstractAnalysisTest {
@reflectiveTest
class AnalysisOptionsFileNotificationTest extends AbstractAnalysisTest {
Map<String, List<AnalysisError>> filesErrors = {};
final testSource = '''
@ -37,7 +36,7 @@ main() {
List<AnalysisError> get optionsFileErrors => filesErrors[optionsFilePath];
String get optionsFilePath;
String get optionsFilePath => '$projectPath/analysis_options.yaml';
List<AnalysisError> get testFileErrors => filesErrors[testFile];
@ -260,17 +259,3 @@ linter:
expect(rules, unorderedEquals(lints));
}
}
@reflectiveTest
class NewAnalysisOptionsFileNotificationTest
extends AnalysisOptionsFileNotificationTest {
@override
String get optionsFilePath => '$projectPath/analysis_options.yaml';
}
@reflectiveTest
class OldAnalysisOptionsFileNotificationTest
extends AnalysisOptionsFileNotificationTest {
@override
String get optionsFilePath => '$projectPath/.analysis_options';
}

View file

@ -200,7 +200,7 @@ import 'does_not_exist.dart';
Future<void> test_lintError() async {
var camelCaseTypesLintName = 'camel_case_types';
newFile(join(projectPath, '.analysis_options'), content: '''
newFile(join(projectPath, 'analysis_options.yaml'), content: '''
linter:
rules:
- $camelCaseTypesLintName

View file

@ -43,8 +43,7 @@ import 'src/plugin/plugin_manager_test.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(AbstractContextManagerTest);
defineReflectiveTests(ContextManagerWithNewOptionsTest);
defineReflectiveTests(ContextManagerWithOldOptionsTest);
defineReflectiveTests(ContextManagerWithOptionsTest);
});
}
@ -1657,7 +1656,6 @@ abstract class ContextManagerTest with ResourceProviderMixin {
'**/*.${AnalysisEngine.SUFFIX_DART}',
'**/*.${AnalysisEngine.SUFFIX_HTML}',
'**/*.${AnalysisEngine.SUFFIX_HTM}',
'**/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}',
'**/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'
];
return patterns
@ -1712,27 +1710,9 @@ abstract class ContextManagerTest with ResourceProviderMixin {
}
@reflectiveTest
class ContextManagerWithNewOptionsTest extends ContextManagerWithOptionsTest {
@override
class ContextManagerWithOptionsTest extends ContextManagerTest {
String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE;
@override
@failingTest
Future<void> test_analysis_options_parse_failure() async {
// We have lost the ability to detect errors of this form.
return super.test_analysis_options_parse_failure();
}
}
@reflectiveTest
class ContextManagerWithOldOptionsTest extends ContextManagerWithOptionsTest {
@override
String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_FILE;
}
abstract class ContextManagerWithOptionsTest extends ContextManagerTest {
String get optionsFileName;
void deleteOptionsFile() {
deleteFile('$projPath/$optionsFileName');
}
@ -1879,6 +1859,7 @@ include: package:boo/other_options.yaml
expect(lints[0].name, 'camel_case_types');
}
@failingTest
Future<void> test_analysis_options_parse_failure() async {
// Create files.
String libPath = '$projPath/${ContextManagerTest.LIB_NAME}';

View file

@ -23,7 +23,7 @@ class OptionsIntegrationTest extends AbstractAnalysisServerIntegrationTest {
standardAnalysisSetup();
}
Future<void> test_option_warning_newOptionFile() async {
Future<void> test_option_warning_optionFile() async {
String options = sourcePath(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
writeFile(options, '''
linter:
@ -47,31 +47,4 @@ linter:
expect(error.location.startLine, 3);
expect(error.location.startColumn, 7);
}
Future<void> test_option_warning_oldOptionFile() async {
String options = sourcePath(AnalysisEngine.ANALYSIS_OPTIONS_FILE);
writeFile(options, '''
linter:
rules:
- camel_case_types
''');
optionsAnalysisSetup();
await analysisFinished;
expect(currentAnalysisErrors[options], isList);
List<AnalysisError> errors = currentAnalysisErrors[options];
expect(errors, hasLength(1));
AnalysisError error = errors[0];
expect(error.location.file, options);
expect(error.severity, AnalysisErrorSeverity.INFO);
expect(error.type, AnalysisErrorType.HINT);
expect(error.location.offset, 0);
expect(error.location.length, 1);
expect(error.location.startLine, 1);
expect(error.location.startColumn, 1);
expect(error.message,
'The name of the analysis options file .analysis_options is deprecated; consider renaming it to analysis_options.yaml.');
}
}

View file

@ -31,7 +31,7 @@ class abc { // lint: not CamelCase (should get ignored though)
expect(errors, hasLength(0));
}
Future<void> test_simple_lint_newOptionsFile() async {
Future<void> test_simple_lint_optionsFile() async {
writeFile(sourcePath(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE), '''
linter:
rules:
@ -55,29 +55,4 @@ class a { // lint: not CamelCase
expect(error.severity, AnalysisErrorSeverity.INFO);
expect(error.type, AnalysisErrorType.LINT);
}
Future<void> test_simple_lint_oldOptionsFile() async {
writeFile(sourcePath(AnalysisEngine.ANALYSIS_OPTIONS_FILE), '''
linter:
rules:
- camel_case_types
''');
String source = sourcePath('test.dart');
writeFile(source, '''
class a { // lint: not CamelCase
}''');
standardAnalysisSetup();
await analysisFinished;
expect(currentAnalysisErrors[source], isList);
List<AnalysisError> errors = currentAnalysisErrors[source];
expect(errors, hasLength(1));
AnalysisError error = errors[0];
expect(error.location.file, source);
expect(error.severity, AnalysisErrorSeverity.INFO);
expect(error.type, AnalysisErrorType.LINT);
}
}

View file

@ -21,8 +21,7 @@ class AnalysisOptionsProvider {
AnalysisOptionsProvider([this.sourceFactory]);
/// Provide the options found in either
/// [root]/[AnalysisEngine.ANALYSIS_OPTIONS_FILE] or
/// Provide the options found in
/// [root]/[AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE].
/// Recursively merge options referenced by an include directive
/// and remove the include directive from the resulting options map.
@ -43,10 +42,6 @@ class AnalysisOptionsProvider {
File getOptionsFile(Folder root, {bool crawlUp = false}) {
Resource resource;
for (Folder folder = root; folder != null; folder = folder.parent) {
resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_FILE);
if (resource.exists) {
break;
}
resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
if (resource.exists || !crawlUp) {
break;

View file

@ -378,12 +378,7 @@ class ContextBuilder {
}
Folder root = resourceProvider.getFolder(path);
for (Folder folder = root; folder != null; folder = folder.parent) {
File file =
folder.getChildAssumingFile(AnalysisEngine.ANALYSIS_OPTIONS_FILE);
if (file.exists) {
return file;
}
file = folder
File file = folder
.getChildAssumingFile(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
if (file.exists) {
return file;

View file

@ -111,9 +111,6 @@ class AnalysisEngine {
/// The long suffix used for HTML files.
static const String SUFFIX_HTML = "html";
/// The deprecated file name used for analysis options files.
static const String ANALYSIS_OPTIONS_FILE = '.analysis_options';
/// The file name used for analysis options files.
static const String ANALYSIS_OPTIONS_YAML_FILE = 'analysis_options.yaml';
@ -166,8 +163,7 @@ class AnalysisEngine {
return false;
}
String basename = (context ?? pathos.posix).basename(fileName);
return basename == ANALYSIS_OPTIONS_FILE ||
basename == ANALYSIS_OPTIONS_YAML_FILE;
return basename == ANALYSIS_OPTIONS_YAML_FILE;
}
/// Return `true` if the given [fileName] is assumed to contain Dart source

View file

@ -431,14 +431,6 @@ class OptionsFileValidator {
source,
isNonNullableByDefault: false,
);
if (AnalysisEngine.ANALYSIS_OPTIONS_FILE == source.shortName) {
reporter.reportError(AnalysisError(
source,
0, // offset
1, // length
AnalysisOptionsHintCode.DEPRECATED_ANALYSIS_OPTIONS_FILE_NAME,
[source.shortName]));
}
_validators.forEach((OptionsValidator v) => v.validate(reporter, options));
return recorder.errors;
}

View file

@ -20,8 +20,7 @@ import '../src/util/yaml_test.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AnalysisOptionsProviderOldTest);
defineReflectiveTests(AnalysisOptionsProviderNewTest);
defineReflectiveTests(AnalysisOptionsProviderTest);
});
group('AnalysisOptionsProvider', () {
void expectMergesTo(String defaults, String overrides, String expected) {
@ -101,24 +100,13 @@ analyzer:
}
@reflectiveTest
class AnalysisOptionsProviderNewTest extends AnalysisOptionsProviderTest {
@override
String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE;
}
@reflectiveTest
class AnalysisOptionsProviderOldTest extends AnalysisOptionsProviderTest {
@override
String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_FILE;
}
abstract class AnalysisOptionsProviderTest {
class AnalysisOptionsProviderTest {
TestPathTranslator pathTranslator;
ResourceProvider resourceProvider;
AnalysisOptionsProvider provider;
String get optionsFileName;
String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE;
void setUp() {
var rawProvider = MemoryResourceProvider();

View file

@ -796,17 +796,6 @@ environment:
expect(result.path, filePath);
}
void test_getOptionsFile_inParentOfRoot_old() {
String parentPath = convertPath('/some/directory');
String path = join(parentPath, 'path');
String filePath = join(parentPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE);
newFile(filePath);
File result = builder.getOptionsFile(path);
expect(result, isNotNull);
expect(result.path, filePath);
}
void test_getOptionsFile_inRoot_new() {
String path = convertPath('/some/directory/path');
String filePath = join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
@ -817,16 +806,6 @@ environment:
expect(result.path, filePath);
}
void test_getOptionsFile_inRoot_old() {
String path = convertPath('/some/directory/path');
String filePath = join(path, AnalysisEngine.ANALYSIS_OPTIONS_FILE);
newFile(filePath);
File result = builder.getOptionsFile(path);
expect(result, isNotNull);
expect(result.path, filePath);
}
void _assertPackages(Packages packages, Map<String, String> nameToPath) {
expect(packages, isNotNull);
expect(packages.packages, hasLength(nameToPath.length));

View file

@ -18,7 +18,6 @@ import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/lint/linter.dart';
import 'package:analyzer/src/lint/registry.dart';
import 'package:analyzer/src/task/options.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'package:yaml/yaml.dart';
@ -30,7 +29,6 @@ main() {
defineReflectiveSuite(() {
defineReflectiveTests(ContextConfigurationTest);
defineReflectiveTests(ErrorCodeValuesTest);
defineReflectiveTests(GenerateOldOptionsErrorsTaskTest);
defineReflectiveTests(OptionsFileValidatorTest);
defineReflectiveTests(OptionsProviderTest);
});
@ -208,42 +206,6 @@ class ErrorProcessorMatcher extends Matcher {
}
}
@reflectiveTest
class GenerateOldOptionsErrorsTaskTest with ResourceProviderMixin {
final AnalysisOptionsProvider optionsProvider = AnalysisOptionsProvider();
String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}';
test_does_analyze_old_options_files() {
validate('''
analyzer:
strong-mode: true
''', [
AnalysisOptionsHintCode.DEPRECATED_ANALYSIS_OPTIONS_FILE_NAME,
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED
]);
}
test_finds_issues_in_old_options_files() {
validate('''
analyzer:
strong_mode: true
''', [
AnalysisOptionsHintCode.DEPRECATED_ANALYSIS_OPTIONS_FILE_NAME,
AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES
]);
}
void validate(String content, List<ErrorCode> expected) {
final source = newFile(optionsFilePath, content: content).createSource();
var options = optionsProvider.getOptionsFromSource(source);
final OptionsFileValidator validator = OptionsFileValidator(source);
var errors = validator.validate(options);
expect(errors.map((AnalysisError e) => e.errorCode),
unorderedEquals(expected));
}
}
@reflectiveTest
class OptionsFileValidatorTest {
final OptionsFileValidator validator = OptionsFileValidator(TestSource());

View file

@ -280,8 +280,7 @@ class Driver with HasContextMixin implements CommandLineStarter {
// Analyze the libraries.
for (String path in filesToAnalyze) {
var shortName = resourceProvider.pathContext.basename(path);
if (shortName == AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE ||
shortName == AnalysisEngine.ANALYSIS_OPTIONS_FILE) {
if (shortName == AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE) {
File file = resourceProvider.getFile(path);
String content = file.readAsStringSync();
LineInfo lineInfo = LineInfo.fromContent(content);