mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
enable more lints for dartdev
Change-Id: Id3a0145076a671c830785b6344035726593e1492 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151940 Auto-Submit: Kevin Moore <kevmoo@google.com> Commit-Queue: Jaime Wren <jwren@google.com> Reviewed-by: Jaime Wren <jwren@google.com>
This commit is contained in:
parent
cb1105af48
commit
fcb6ba0d96
|
@ -12,6 +12,53 @@ analyzer:
|
|||
|
||||
linter:
|
||||
rules:
|
||||
- avoid_function_literals_in_foreach_calls
|
||||
- avoid_private_typedef_functions
|
||||
- avoid_redundant_argument_values
|
||||
- avoid_renaming_method_parameters
|
||||
- avoid_returning_null_for_void
|
||||
- avoid_void_async
|
||||
- await_only_futures
|
||||
- camel_case_types
|
||||
- constant_identifier_names
|
||||
- directives_ordering
|
||||
- empty_statements
|
||||
- file_names
|
||||
- iterable_contains_unrelated_type
|
||||
- lines_longer_than_80_chars
|
||||
- list_remove_unrelated_type
|
||||
- missing_whitespace_between_adjacent_strings
|
||||
- no_runtimeType_toString
|
||||
- non_constant_identifier_names
|
||||
- only_throw_errors
|
||||
- overridden_fields
|
||||
- package_names
|
||||
- package_prefixed_library_names
|
||||
- prefer_asserts_in_initializer_lists
|
||||
- prefer_const_constructors
|
||||
- prefer_const_declarations
|
||||
- prefer_expression_function_bodies
|
||||
- prefer_function_declarations_over_variables
|
||||
- prefer_initializing_formals
|
||||
- prefer_inlined_adds
|
||||
- prefer_interpolation_to_compose_strings
|
||||
- prefer_is_not_operator
|
||||
- prefer_null_aware_operators
|
||||
- prefer_relative_imports
|
||||
- prefer_typing_uninitialized_variables
|
||||
- prefer_void_to_null
|
||||
- provide_deprecation_message
|
||||
- sort_pub_dependencies
|
||||
- test_types_in_equals
|
||||
- throw_in_finally
|
||||
- type_annotate_public_apis
|
||||
- unnecessary_brace_in_string_interps
|
||||
- unnecessary_lambdas
|
||||
- unnecessary_null_aware_assignments
|
||||
- unnecessary_overrides
|
||||
- unnecessary_parenthesis
|
||||
- unnecessary_statements
|
||||
- unnecessary_string_interpolations
|
||||
- use_is_even_rather_than_modulo
|
||||
- use_string_buffers
|
||||
- void_checks
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
import 'package:dartdev/dartdev.dart';
|
||||
|
||||
/// The entry point for dartdev.
|
||||
void main(List<String> args) async {
|
||||
Future<void> main(List<String> args) async {
|
||||
await runDartdev(args);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import 'src/core.dart';
|
|||
/// This is typically called from bin/, but given the length of the method and
|
||||
/// analytics logic, it has been moved here. Also note that this method calls
|
||||
/// [io.exit(code)] directly.
|
||||
void runDartdev(List<String> args) async {
|
||||
Future<void> runDartdev(List<String> args) async {
|
||||
final stopwatch = Stopwatch();
|
||||
dynamic result;
|
||||
|
||||
|
@ -38,8 +38,6 @@ void runDartdev(List<String> args) async {
|
|||
Exception exception;
|
||||
StackTrace stackTrace;
|
||||
|
||||
var runner;
|
||||
|
||||
analytics =
|
||||
createAnalyticsInstance(args.contains('--disable-dartdev-analytics'));
|
||||
|
||||
|
@ -67,11 +65,11 @@ void runDartdev(List<String> args) async {
|
|||
io.exit(0);
|
||||
}
|
||||
|
||||
var commandName;
|
||||
String commandName;
|
||||
|
||||
try {
|
||||
stopwatch.start();
|
||||
runner = DartdevRunner(args);
|
||||
final runner = DartdevRunner(args);
|
||||
// Run can't be called with the '--disable-dartdev-analytics' flag, remove
|
||||
// it if it is contained in args.
|
||||
if (args.contains('--disable-dartdev-analytics')) {
|
||||
|
@ -122,7 +120,8 @@ void runDartdev(List<String> args) async {
|
|||
fatal: true);
|
||||
}
|
||||
|
||||
await analytics.waitForLastPing(timeout: Duration(milliseconds: 200));
|
||||
await analytics.waitForLastPing(
|
||||
timeout: const Duration(milliseconds: 200));
|
||||
}
|
||||
|
||||
// As the notification to the user read on the first run, analytics are
|
||||
|
@ -173,10 +172,11 @@ class DartdevRunner<int> extends CommandRunner {
|
|||
'dart [<vm-flags>] <command|dart-file> [<arguments>]';
|
||||
|
||||
@override
|
||||
Future<int> runCommand(ArgResults results) async {
|
||||
assert(!results.arguments.contains('--disable-dartdev-analytics'));
|
||||
if (results.command == null && results.arguments.isNotEmpty) {
|
||||
final firstArg = results.arguments.first;
|
||||
Future<int> runCommand(ArgResults topLevelResults) async {
|
||||
assert(!topLevelResults.arguments.contains('--disable-dartdev-analytics'));
|
||||
if (topLevelResults.command == null &&
|
||||
topLevelResults.arguments.isNotEmpty) {
|
||||
final firstArg = topLevelResults.arguments.first;
|
||||
// If we make it this far, it means the VM couldn't find the file on disk.
|
||||
if (firstArg.endsWith('.dart')) {
|
||||
io.stderr.writeln(
|
||||
|
@ -185,11 +185,11 @@ class DartdevRunner<int> extends CommandRunner {
|
|||
io.exit(254);
|
||||
}
|
||||
}
|
||||
isVerbose = results['verbose'];
|
||||
isVerbose = topLevelResults['verbose'];
|
||||
|
||||
final Ansi ansi = Ansi(Ansi.terminalSupportsAnsi);
|
||||
log = isVerbose ? Logger.verbose(ansi: ansi) : Logger.standard(ansi: ansi);
|
||||
|
||||
return await super.runCommand(results);
|
||||
return await super.runCommand(topLevelResults);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ const String analyticsDisabledNoticeMessage = '''
|
|||
║ `dart --enable-analytics` ║
|
||||
╚════════════════════════════════════════════════════════════════════════════╝
|
||||
''';
|
||||
const String _unknown_command = '<unknown>';
|
||||
const String _unknownCommand = '<unknown>';
|
||||
const String _appName = 'dartdev';
|
||||
const String _dartDirectoryName = '.dart';
|
||||
const String _settingsFileName = 'dartdev.json';
|
||||
|
@ -87,7 +87,7 @@ String getCommandStr(List<String> args, List<String> allCommands) {
|
|||
return 'help';
|
||||
}
|
||||
return args.firstWhere((arg) => allCommands.contains(arg),
|
||||
orElse: () => _unknown_command);
|
||||
orElse: () => _unknownCommand);
|
||||
}
|
||||
|
||||
/// Given some set of arguments and parameters, this returns a proper subset
|
||||
|
|
|
@ -17,13 +17,9 @@ class AnalyzeCommand extends DartdevCommand<int> {
|
|||
: super('analyze', "Analyze the project's Dart code.") {
|
||||
argParser
|
||||
..addFlag('fatal-infos',
|
||||
help: 'Treat info level issues as fatal.',
|
||||
defaultsTo: false,
|
||||
negatable: false)
|
||||
help: 'Treat info level issues as fatal.', negatable: false)
|
||||
..addFlag('fatal-warnings',
|
||||
help: 'Treat warning level issues as fatal.',
|
||||
defaultsTo: true,
|
||||
negatable: true);
|
||||
help: 'Treat warning level issues as fatal.', defaultsTo: true);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -38,7 +38,7 @@ class AnalysisServer {
|
|||
|
||||
Future<void> start() async {
|
||||
final List<String> command = <String>[
|
||||
sdk.analysis_server_snapshot,
|
||||
sdk.analysisServerSnapshot,
|
||||
'--disable-server-feature-completion',
|
||||
'--disable-server-feature-search',
|
||||
'--sdk',
|
||||
|
@ -116,7 +116,9 @@ class AnalysisServer {
|
|||
final Map<String, dynamic> error =
|
||||
castStringKeyedMap(response['error']);
|
||||
log.stderr(
|
||||
'Error response from the server: ${error['code']} ${error['message']}');
|
||||
'Error response from the server: '
|
||||
'${error['code']} ${error['message']}',
|
||||
);
|
||||
if (error['stackTrace'] != null) {
|
||||
log.stderr(error['stackTrace'] as String);
|
||||
}
|
||||
|
@ -235,11 +237,9 @@ class AnalysisError implements Comparable<AnalysisError> {
|
|||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '${severity.toLowerCase()} • '
|
||||
'$messageSentenceFragment at $file:$startLine:$startColumn • '
|
||||
'($code)';
|
||||
}
|
||||
String toString() => '${severity.toLowerCase()} • '
|
||||
'$messageSentenceFragment at $file:$startLine:$startColumn • '
|
||||
'($code)';
|
||||
}
|
||||
|
||||
class FileAnalysisErrors {
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'dart:convert';
|
|||
import 'dart:io' as io;
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:stagehand/stagehand.dart' as stagehand;
|
||||
|
||||
import '../core.dart';
|
||||
|
@ -24,13 +24,11 @@ class CreateCommand extends DartdevCommand {
|
|||
'web-simple'
|
||||
];
|
||||
|
||||
static Iterable<stagehand.Generator> get generators {
|
||||
return legalTemplateIds.map(retrieveTemplateGenerator);
|
||||
}
|
||||
static Iterable<stagehand.Generator> get generators =>
|
||||
legalTemplateIds.map(retrieveTemplateGenerator);
|
||||
|
||||
static stagehand.Generator retrieveTemplateGenerator(String templateId) {
|
||||
return stagehand.getGenerator(templateId);
|
||||
}
|
||||
static stagehand.Generator retrieveTemplateGenerator(String templateId) =>
|
||||
stagehand.getGenerator(templateId);
|
||||
|
||||
CreateCommand({bool verbose = false})
|
||||
: super('create', 'Create a new project.') {
|
||||
|
@ -53,8 +51,8 @@ class CreateCommand extends DartdevCommand {
|
|||
argParser.addFlag(
|
||||
'force',
|
||||
negatable: false,
|
||||
help:
|
||||
'Force project generation, even if the target directory already exists.',
|
||||
help: 'Force project generation, even if the target directory already '
|
||||
'exists.',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -77,19 +75,23 @@ class CreateCommand extends DartdevCommand {
|
|||
|
||||
String dir = argResults.rest.first;
|
||||
var targetDir = io.Directory(dir);
|
||||
if (targetDir.existsSync() && !(argResults['force'])) {
|
||||
if (targetDir.existsSync() && !argResults['force']) {
|
||||
log.stderr(
|
||||
"Directory '$dir' already exists (use '--force' to force project generation).");
|
||||
"Directory '$dir' already exists "
|
||||
"(use '--force' to force project generation).",
|
||||
);
|
||||
return 73;
|
||||
}
|
||||
|
||||
log.stdout(
|
||||
'Creating ${log.ansi.emphasized(path.absolute(dir))} using template $templateId...');
|
||||
'Creating ${log.ansi.emphasized(p.absolute(dir))} '
|
||||
'using template $templateId...',
|
||||
);
|
||||
log.stdout('');
|
||||
|
||||
var generator = retrieveTemplateGenerator(templateId);
|
||||
await generator.generate(
|
||||
path.basename(dir),
|
||||
p.basename(dir),
|
||||
DirectoryGeneratorTarget(generator, io.Directory(dir)),
|
||||
);
|
||||
|
||||
|
@ -125,7 +127,7 @@ class CreateCommand extends DartdevCommand {
|
|||
log.stdout('');
|
||||
log.stdout('Created project $dir! In order to get started, type:');
|
||||
log.stdout('');
|
||||
log.stdout(log.ansi.emphasized(' cd ${path.relative(dir)}'));
|
||||
log.stdout(log.ansi.emphasized(' cd ${p.relative(dir)}'));
|
||||
// TODO(devoncarew): Once we have a 'run' command, print out here how to run
|
||||
// the app.
|
||||
log.stdout('');
|
||||
|
@ -159,7 +161,7 @@ class CreateCommand extends DartdevCommand {
|
|||
return m;
|
||||
});
|
||||
|
||||
JsonEncoder encoder = JsonEncoder.withIndent(' ');
|
||||
JsonEncoder encoder = const JsonEncoder.withIndent(' ');
|
||||
return encoder.convert(items.toList());
|
||||
}
|
||||
}
|
||||
|
@ -173,10 +175,10 @@ class DirectoryGeneratorTarget extends stagehand.GeneratorTarget {
|
|||
}
|
||||
|
||||
@override
|
||||
Future createFile(String filePath, List<int> contents) async {
|
||||
io.File file = io.File(path.join(dir.path, filePath));
|
||||
Future createFile(String path, List<int> contents) async {
|
||||
io.File file = io.File(p.join(dir.path, path));
|
||||
|
||||
String name = path.relative(file.path, from: dir.path);
|
||||
String name = p.relative(file.path, from: dir.path);
|
||||
log.stdout(' $name');
|
||||
|
||||
await file.create(recursive: true);
|
||||
|
|
|
@ -18,6 +18,7 @@ class RunCommand extends DartdevCommand<int> {
|
|||
@override
|
||||
final ArgParser argParser = ArgParser.allowAnything();
|
||||
final bool verbose;
|
||||
|
||||
RunCommand({this.verbose = false}) : super('run', '''
|
||||
Run a Dart file.''');
|
||||
|
||||
|
@ -91,7 +92,9 @@ Run a Dart file.''');
|
|||
}
|
||||
if (!foundImplicitFileToRun) {
|
||||
log.stderr(
|
||||
'Could not find the implicit file to run: bin$separator$cwdName.dart.');
|
||||
'Could not find the implicit file to run: '
|
||||
'bin$separator$cwdName.dart.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,8 +103,9 @@ Run a Dart file.''');
|
|||
// service intermediary which implements the VM service protocol and
|
||||
// provides non-VM specific extensions (e.g., log caching, client
|
||||
// synchronization).
|
||||
if (args.any((element) => (element.startsWith('--observe') ||
|
||||
element.startsWith('--enable-vm-service')))) {
|
||||
if (args.any((element) =>
|
||||
element.startsWith('--observe') ||
|
||||
element.startsWith('--enable-vm-service'))) {
|
||||
return await _DebuggingSession(this, args).start();
|
||||
}
|
||||
|
||||
|
@ -138,8 +142,8 @@ class _DebuggingSession {
|
|||
try {
|
||||
_bindAddress = Uri.http(observatoryBindInfo[1], '');
|
||||
} on FormatException {
|
||||
// TODO(bkonyi): log invalid parse? The VM service just ignores bad
|
||||
// input flags.
|
||||
// TODO(bkonyi): log invalid parse? The VM service just ignores
|
||||
// bad input flags.
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
|
@ -166,9 +170,10 @@ class _DebuggingSession {
|
|||
// Strip --observe and --write-service-info from the arguments as we'll be
|
||||
// providing our own.
|
||||
_args.removeWhere(
|
||||
(arg) => (arg.startsWith('--observe') ||
|
||||
(arg) =>
|
||||
arg.startsWith('--observe') ||
|
||||
arg.startsWith('--enable-vm-service') ||
|
||||
arg.startsWith('--write-service-info')),
|
||||
arg.startsWith('--write-service-info'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -196,8 +201,7 @@ class _DebuggingSession {
|
|||
|
||||
// Start DDS once the VM service has finished starting up.
|
||||
await Future.any([
|
||||
_waitForRemoteServiceUri(serviceInfoFile)
|
||||
.then((serviceUri) => _startDDS(serviceUri)),
|
||||
_waitForRemoteServiceUri(serviceInfoFile).then(_startDDS),
|
||||
_process.exitCode,
|
||||
]);
|
||||
|
||||
|
@ -215,7 +219,7 @@ class _DebuggingSession {
|
|||
|
||||
Future<Uri> _waitForRemoteServiceUri(File serviceInfoFile) async {
|
||||
// Wait for VM service to write its connection info to disk.
|
||||
while ((await serviceInfoFile.length() <= 5)) {
|
||||
while (await serviceInfoFile.length() <= 5) {
|
||||
await Future.delayed(const Duration(milliseconds: 50));
|
||||
}
|
||||
final serviceInfoStr = await serviceInfoFile.readAsString();
|
||||
|
@ -264,14 +268,14 @@ class _DebuggingSession {
|
|||
// to ensure we don't let any unfiltered messages slip through.
|
||||
// TODO(bkonyi): consider filtering on bytes rather than decoding the UTF8.
|
||||
_stderrDone = process.stderr
|
||||
.transform(Utf8Decoder(allowMalformed: true))
|
||||
.transform(const Utf8Decoder(allowMalformed: true))
|
||||
.listen((event) async {
|
||||
await _waitForDDS();
|
||||
stderr.write(filterObservatoryUri(event));
|
||||
}).asFuture();
|
||||
|
||||
_stdoutDone = process.stdout
|
||||
.transform(Utf8Decoder(allowMalformed: true))
|
||||
.transform(const Utf8Decoder(allowMalformed: true))
|
||||
.listen((event) async {
|
||||
await _waitForDDS();
|
||||
stdout.write(filterObservatoryUri(event));
|
||||
|
|
|
@ -31,7 +31,7 @@ abstract class DartdevCommand<int> extends Command {
|
|||
@override
|
||||
String get description => _description;
|
||||
|
||||
Project get project => (_project ??= Project());
|
||||
Project get project => _project ??= Project();
|
||||
}
|
||||
|
||||
/// A utility method to start the given executable as a process, optionally
|
||||
|
@ -122,7 +122,6 @@ class PackageConfig {
|
|||
return _packages.map<Map<String, dynamic>>(castStringKeyedMap).toList();
|
||||
}
|
||||
|
||||
bool hasDependency(String packageName) {
|
||||
return packages.any((element) => element['name'] == packageName);
|
||||
}
|
||||
bool hasDependency(String packageName) =>
|
||||
packages.any((element) => element['name'] == packageName);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class Sdk {
|
|||
// if the SDK isn't completely built.
|
||||
String get dart => Platform.resolvedExecutable;
|
||||
|
||||
String get analysis_server_snapshot => path.absolute(
|
||||
String get analysisServerSnapshot => path.absolute(
|
||||
sdkPath, 'bin', 'snapshots', 'analysis_server.dart.snapshot');
|
||||
|
||||
String get dartfmt => path.absolute(sdkPath, 'bin', _binName('dartfmt'));
|
||||
|
|
|
@ -6,11 +6,11 @@ import 'package:dartdev/src/analytics.dart';
|
|||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('DisabledAnalytics', disabledAnalytics_object);
|
||||
group('DisabledAnalytics', disabledAnalyticsObject);
|
||||
group('utils', utils);
|
||||
}
|
||||
|
||||
void disabledAnalytics_object() {
|
||||
void disabledAnalyticsObject() {
|
||||
test('object', () {
|
||||
var diabledAnalytics = DisabledAnalytics('trackingId', 'appName');
|
||||
expect(diabledAnalytics.trackingId, 'trackingId');
|
||||
|
|
|
@ -71,7 +71,7 @@ void format() {
|
|||
|
||||
test('unknown file', () {
|
||||
p = project(mainSrc: 'int get foo => 1;\n');
|
||||
var unknownFilePath = p.relativeFilePath + '-unknown-file.dart';
|
||||
var unknownFilePath = '${p.relativeFilePath}-unknown-file.dart';
|
||||
ProcessResult result = p.runSync('format', [unknownFilePath]);
|
||||
expect(result.exitCode, 0);
|
||||
expect(result.stderr,
|
||||
|
|
|
@ -39,7 +39,7 @@ void run() {
|
|||
test('no such file', () {
|
||||
p = project(mainSrc: "void main() { print('Hello World'); }");
|
||||
ProcessResult result =
|
||||
p.runSync('run', ['no/such/file/' + p.relativeFilePath]);
|
||||
p.runSync('run', ['no/such/file/${p.relativeFilePath}']);
|
||||
|
||||
expect(result.stderr, isNotEmpty);
|
||||
expect(result.exitCode, isNot(0));
|
||||
|
|
|
@ -48,7 +48,7 @@ void _project() {
|
|||
});
|
||||
}
|
||||
|
||||
final String _packageData = '''{
|
||||
const String _packageData = '''{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@ void _sdk() {
|
|||
});
|
||||
|
||||
test('analysis_server_snapshot', () {
|
||||
expectFileExists(Sdk().analysis_server_snapshot);
|
||||
expectFileExists(Sdk().analysisServerSnapshot);
|
||||
});
|
||||
|
||||
test('dartfmt', () {
|
||||
|
|
|
@ -12,9 +12,8 @@ import 'package:test/test.dart';
|
|||
/// invocation requires the VM to compile the entire dependency graph.
|
||||
const Timeout longTimeout = Timeout(Duration(minutes: 5));
|
||||
|
||||
TestProject project({String mainSrc, String analysisOptions}) {
|
||||
return TestProject(mainSrc: mainSrc, analysisOptions: analysisOptions);
|
||||
}
|
||||
TestProject project({String mainSrc, String analysisOptions}) =>
|
||||
TestProject(mainSrc: mainSrc, analysisOptions: analysisOptions);
|
||||
|
||||
class TestProject {
|
||||
static String get defaultProjectName => 'dartdev_temp';
|
||||
|
@ -94,9 +93,8 @@ class TestProject {
|
|||
return _sdkRootPath;
|
||||
}
|
||||
|
||||
String get absolutePathToDartdevFile {
|
||||
return path.join(sdkRootPath, 'pkg', 'dartdev', 'bin', 'dartdev.dart');
|
||||
}
|
||||
String get absolutePathToDartdevFile =>
|
||||
path.join(sdkRootPath, 'pkg', 'dartdev', 'bin', 'dartdev.dart');
|
||||
|
||||
File findFile(String name) {
|
||||
var file = File(path.join(dir.path, name));
|
||||
|
|
|
@ -90,7 +90,7 @@ void main() {
|
|||
});
|
||||
}
|
||||
|
||||
final String _packageData = '''{
|
||||
const String _packageData = '''{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue