The dart fix command should not modify generated files

Change-Id: I485b0b0d1b99e5105402f12ad19d707f169df71a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205900
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2021-07-03 05:25:35 +00:00 committed by commit-bot@chromium.org
parent 0f2e58367d
commit adcef136a6
3 changed files with 25 additions and 18 deletions

View file

@ -168,7 +168,8 @@ class BulkFixProcessor {
for (var context in contexts) {
var pathContext = context.contextRoot.resourceProvider.pathContext;
for (var path in context.contextRoot.analyzedFiles()) {
if (!file_paths.isDart(pathContext, path)) {
if (!file_paths.isDart(pathContext, path) ||
file_paths.isGenerated(path)) {
continue;
}
var library = await context.currentSession.getResolvedLibrary2(path);

View file

@ -11,6 +11,7 @@ import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/utilities_dart.dart' as utils;
import 'package:analyzer/src/source/package_map_resolver.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:analyzer/src/workspace/package_build.dart';
/// Return `true` if the given [source] refers to a file that is assumed to be
@ -19,22 +20,7 @@ bool isGeneratedSource(Source? source) {
if (source == null) {
return false;
}
// TODO(brianwilkerson) Generalize this mechanism.
const List<String> suffixes = <String>[
'.g.dart',
'.pb.dart',
'.pbenum.dart',
'.pbserver.dart',
'.pbjson.dart',
'.template.dart'
];
String fullName = source.fullName;
for (String suffix in suffixes) {
if (fullName.endsWith(suffix)) {
return true;
}
}
return false;
return file_paths.isGenerated(source.fullName);
}
/// Instances of the class `SourceFactory` resolve possibly relative URI's

View file

@ -4,7 +4,7 @@
/// The set of constants and utilities to check file paths.
///
/// The recommended import prefix in `file_paths`.
/// The recommended import prefix is `file_paths`.
import 'package:path/path.dart' as p;
/// The file name used for analysis options files.
@ -70,6 +70,26 @@ bool isFixDataYaml(p.Context pathContext, String path) {
return pathContext.basename(path) == fixDataYaml;
}
/// Return `true` if the given [path] refers to a file that is assumed to be
/// generated.
bool isGenerated(String path) {
// TODO(brianwilkerson) Generalize this mechanism.
const List<String> suffixes = <String>[
'.g.dart',
'.pb.dart',
'.pbenum.dart',
'.pbserver.dart',
'.pbjson.dart',
'.template.dart'
];
for (var suffix in suffixes) {
if (path.endsWith(suffix)) {
return true;
}
}
return false;
}
/// Return `true` if [path] is a `.dart_tool/package_config.json` file.
bool isPackageConfigJson(p.Context pathContext, String path) {
var components = pathContext.split(path);