Ben Konyi 1709c884aa
[ Tool ] Enable omit_obvious_*_types and specify_nonobvious_*_types lints (#172018)
Sources under `packages/flutter_tools/` aren't accessible to the average
Flutter user by navigating through sources from their projects, so it
doesn't need to be as explicitly verbose with types for readability
purposes. The `always_specify_types` lint results in extremely verbose
code within the tool which adds little value.

This change disables `always_specify_types` in favor of a new set of
lints that aim to reduce verbosity by removing obvious types while also
maintaining readability in cases where variable types otherwise wouldn't
be obvious:

  - `omit_obvious_local_variable_types`
  - `omit_obvious_property_types`
  - `specify_nonobvious_local_variable_types`
  - `specify_nonobvious_property_types`
2025-07-11 19:32:57 +00:00

37 lines
1.2 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:path/path.dart' as path;
/// Count the number of libraries that import globals.dart in lib and test.
///
/// This must be run from the flutter_tools project root directory.
void main() {
final sources = Directory(path.join(Directory.current.path, 'lib'));
final tests = Directory(path.join(Directory.current.path, 'test'));
final int sourceGlobals = countGlobalImports(sources);
final int testGlobals = countGlobalImports(tests);
print('lib/ contains $sourceGlobals libraries with global usage');
print('test/ contains $testGlobals libraries with global usage');
}
final globalImport = RegExp("import.*globals.dart' as globals;");
int countGlobalImports(Directory directory) {
var count = 0;
for (final FileSystemEntity file in directory.listSync(recursive: true)) {
if (!file.path.endsWith('.dart') || file is! File) {
continue;
}
final bool hasImport = file.readAsLinesSync().any((String line) {
return globalImport.hasMatch(line);
});
if (hasImport) {
count += 1;
}
}
return count;
}