Skip to content

Commit

Permalink
[dartfix] Bump pedantic dep to v1.8.0 and cleanup lint violations
Browse files Browse the repository at this point in the history
This version added three new lints:
* prefer_iterable_whereType
* unnecessary_const
* unnecessary_new

Change-Id: I99b5f3df86a0243091699cd2f3e1d38b5c5a9216
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108381
Reviewed-by: Dan Rubel <[email protected]>
Commit-Queue: Nicholas Shahan <[email protected]>
  • Loading branch information
nshahan authored and [email protected] committed Jul 9, 2019
1 parent 41330f3 commit d992f55
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion pkg/dartfix/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:pedantic/analysis_options.1.7.0.yaml
include: package:pedantic/analysis_options.1.8.0.yaml

linter:
rules:
Expand Down
2 changes: 1 addition & 1 deletion pkg/dartfix/bin/dartfix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:dartfix/src/driver.dart';

/// The entry point for dartfix.
void main(List<String> args) async {
Driver starter = new Driver();
Driver starter = Driver();

// Wait for the starter to complete.
await starter.start(args);
Expand Down
2 changes: 1 addition & 1 deletion pkg/dartfix/lib/handler/analysis_complete_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mixin AnalysisCompleteHandler on NotificationHandler {
}

Future<void> analysisComplete() {
_analysisComplete ??= new Completer<void>();
_analysisComplete ??= Completer<void>();
return _analysisComplete.future;
}
}
2 changes: 1 addition & 1 deletion pkg/dartfix/lib/listener/bad_message_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mixin BadMessageListener on ServerListener {
_receivedBadDataFromServer = true;
// Give the server 1 second to continue outputting bad data
// such as outputting a stacktrace.
new Future.delayed(new Duration(seconds: 1), () {
Future.delayed(Duration(seconds: 1), () {
throw '$prefix $details';
});
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dartfix/lib/listener/timed_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:analysis_server_client/listener/server_listener.dart';
/// to each logged interaction with the server.
mixin TimedListener on ServerListener {
/// Stopwatch that we use to generate timing information for debug output.
Stopwatch _time = new Stopwatch();
Stopwatch _time = Stopwatch();

/// The [currentElapseTime] at which the last communication was received from
/// the server or `null` if no communication has been received.
Expand Down
26 changes: 13 additions & 13 deletions pkg/dartfix/lib/src/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Driver {
}
if (checkIfChangesShouldBeApplied(result)) {
for (SourceFileEdit fileEdit in result.edits) {
final file = new File(fileEdit.file);
final file = File(fileEdit.file);
String code = file.existsSync() ? file.readAsStringSync() : '';
code = SourceEdit.applySequence(code, fileEdit.edits);
await file.writeAsString(code);
Expand Down Expand Up @@ -80,7 +80,7 @@ class Driver {
/// server being run and return `true` if they are.
/// Display an error message and return `false` if not.
bool checkIfSelectedOptionsAreSupported(Options options) {
if (handler.serverProtocolVersion.compareTo(new Version(1, 22, 2)) >= 0) {
if (handler.serverProtocolVersion.compareTo(Version(1, 22, 2)) >= 0) {
return true;
}
if (options.excludeFixes.isNotEmpty) {
Expand Down Expand Up @@ -108,7 +108,7 @@ class Driver {
logger.trace('Requesting fixes');
Future isAnalysisComplete = handler.analysisComplete();

final params = new EditDartfixParams(options.targets);
final params = EditDartfixParams(options.targets);
if (options.excludeFixes.isNotEmpty) {
params.excludedFixes = options.excludeFixes;
}
Expand All @@ -128,18 +128,18 @@ class Driver {
await isAnalysisComplete;

progress.finish(showTiming: true);
ResponseDecoder decoder = new ResponseDecoder(null);
ResponseDecoder decoder = ResponseDecoder(null);
return EditDartfixResult.fromJson(decoder, 'result', json);
}

void showDescriptions(String title, List<DartFixSuggestion> suggestions) {
if (suggestions.isNotEmpty) {
logger.stdout('');
logger.stdout(ansi.emphasized('$title:'));
List<DartFixSuggestion> sorted = new List.from(suggestions)
List<DartFixSuggestion> sorted = List.from(suggestions)
..sort(compareSuggestions);
for (DartFixSuggestion suggestion in sorted) {
final msg = new StringBuffer();
final msg = StringBuffer();
msg.write(' ${toSentenceFragment(suggestion.description)}');
final loc = suggestion.location;
if (loc != null) {
Expand Down Expand Up @@ -179,12 +179,12 @@ Analysis Details:

Future<EditGetDartfixInfoResult> showFixes({Progress progress}) async {
Map<String, dynamic> json = await server.send(
EDIT_REQUEST_GET_DARTFIX_INFO, new EditGetDartfixInfoParams().toJson());
EDIT_REQUEST_GET_DARTFIX_INFO, EditGetDartfixInfoParams().toJson());
progress?.finish(showTiming: true);
ResponseDecoder decoder = new ResponseDecoder(null);
ResponseDecoder decoder = ResponseDecoder(null);
final result = EditGetDartfixInfoResult.fromJson(decoder, 'result', json);

final fixes = new List<DartFix>.from(result.fixes)
final fixes = List<DartFix>.from(result.fixes)
..sort((f1, f2) => f1.name.compareTo(f2.name));

logger.stdout('''
Expand Down Expand Up @@ -216,8 +216,8 @@ These fixes are NOT automatically applied, but may be enabled using --$includeOp
targets = options.targets;
context = testContext ?? options.context;
logger = testLogger ?? options.logger;
server = new Server(listener: new _Listener(logger));
handler = new _Handler(this);
server = Server(listener: _Listener(logger));
handler = _Handler(this);

// Start showing progress before we start the analysis server.
Progress progress;
Expand Down Expand Up @@ -291,10 +291,10 @@ analysis server
logger.trace('');
logger.trace('Setup analysis');
await server.send(SERVER_REQUEST_SET_SUBSCRIPTIONS,
new ServerSetSubscriptionsParams([ServerService.STATUS]).toJson());
ServerSetSubscriptionsParams([ServerService.STATUS]).toJson());
await server.send(
ANALYSIS_REQUEST_SET_ANALYSIS_ROOTS,
new AnalysisSetAnalysisRootsParams(
AnalysisSetAnalysisRootsParams(
options.targets,
const [],
).toJson());
Expand Down
14 changes: 7 additions & 7 deletions pkg/dartfix/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Options {
}

static Options parse(List<String> args, Context context, Logger logger) {
final parser = new ArgParser(allowTrailingOptions: true)
final parser = ArgParser(allowTrailingOptions: true)
..addSeparator('Choosing fixes to be applied:')
..addMultiOption(includeOption,
abbr: 'i', help: 'Include a specific fix.', valueHelp: 'name-of-fix')
Expand Down Expand Up @@ -106,26 +106,26 @@ class Options {
help: 'Use ansi colors when printing messages.',
defaultsTo: Ansi.terminalSupportsAnsi);

context ??= new Context();
context ??= Context();

ArgResults results;
try {
results = parser.parse(args);
} on FormatException catch (e) {
logger ??= new Logger.standard(ansi: new Ansi(Ansi.terminalSupportsAnsi));
logger ??= Logger.standard(ansi: Ansi(Ansi.terminalSupportsAnsi));
logger.stderr(e.message);
_showUsage(parser, logger);
context.exit(15);
}

Options options = new Options._fromArgs(context, results);
Options options = Options._fromArgs(context, results);

if (logger == null) {
if (options.verbose) {
logger = new Logger.verbose();
logger = Logger.verbose();
} else {
logger = new Logger.standard(
ansi: new Ansi(
logger = Logger.standard(
ansi: Ansi(
options.useColor != null
? options.useColor
: Ansi.terminalSupportsAnsi,
Expand Down
2 changes: 1 addition & 1 deletion pkg/dartfix/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ String findServerPath() {
}
String serverPath =
path.join(parent, 'pkg', 'analysis_server', 'bin', 'server.dart');
if (new File(serverPath).existsSync()) {
if (File(serverPath).existsSync()) {
return serverPath;
}
pathname = parent;
Expand Down
2 changes: 1 addition & 1 deletion pkg/dartfix/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ dependencies:

dev_dependencies:
analyzer: ^0.33.0
pedantic: ^1.7.0
pedantic: ^1.8.0
test: ^1.3.0
6 changes: 3 additions & 3 deletions pkg/dartfix/test/src/driver_exclude_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ main() {
exampleFile = findFile('pkg/dartfix/example/example.dart');
exampleDir = exampleFile.parent;

final driver = new Driver();
final testContext = new TestContext();
final testLogger = new TestLogger(debug: _debug);
final driver = Driver();
final testContext = TestContext();
final testLogger = TestLogger(debug: _debug);
String exampleSource = await exampleFile.readAsString();

var args = ['-xuse-mixin', exampleDir.path];
Expand Down
12 changes: 6 additions & 6 deletions pkg/dartfix/test/src/driver_help_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import 'test_context.dart';

main() {
test('help explicit', () async {
final driver = new Driver();
final testContext = new TestContext();
final testLogger = new TestLogger();
final driver = Driver();
final testContext = TestContext();
final testLogger = TestLogger();
try {
await driver.start(
['--help'], // display help and list fixes
Expand All @@ -32,9 +32,9 @@ main() {
});

test('help implicit', () async {
final driver = new Driver();
final testContext = new TestContext();
final testLogger = new TestLogger();
final driver = Driver();
final testContext = TestContext();
final testLogger = TestLogger();
try {
await driver.start(
[], // no options or arguments should display help and list fixes
Expand Down
6 changes: 3 additions & 3 deletions pkg/dartfix/test/src/driver_include_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ main() {
exampleFile = findFile('pkg/dartfix/example/example.dart');
exampleDir = exampleFile.parent;

final driver = new Driver();
final testContext = new TestContext();
final testLogger = new TestLogger();
final driver = Driver();
final testContext = TestContext();
final testLogger = TestLogger();
String exampleSource = await exampleFile.readAsString();

await driver.start(['-iuse-mixin', exampleDir.path],
Expand Down
6 changes: 3 additions & 3 deletions pkg/dartfix/test/src/driver_required_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ main() {
exampleFile = findFile('pkg/dartfix/example/example.dart');
exampleDir = exampleFile.parent;

final driver = new Driver();
final testContext = new TestContext();
final testLogger = new TestLogger();
final driver = Driver();
final testContext = TestContext();
final testLogger = TestLogger();
String exampleSource = await exampleFile.readAsString();

await driver.start(['-r', exampleDir.path],
Expand Down
8 changes: 4 additions & 4 deletions pkg/dartfix/test/src/driver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ main() {
});

test('fix example', () async {
final driver = new Driver();
final testContext = new TestContext();
final testLogger = new TestLogger(debug: _debug);
final driver = Driver();
final testContext = TestContext();
final testLogger = TestLogger(debug: _debug);
String exampleSource = await exampleFile.readAsString();

await driver.start([
Expand Down Expand Up @@ -92,7 +92,7 @@ main() {
}

String replaceLeadingComment(String source) {
final out = new StringBuffer('''
final out = StringBuffer('''
// This file contains code that has been modified by running dartfix.
// See example.dart for the original unmodified code.
'''
Expand Down
4 changes: 2 additions & 2 deletions pkg/dartfix/test/src/options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ main() {
TestLogger logger;

setUp(() {
context = new TestContext();
logger = new TestLogger();
context = TestContext();
logger = TestLogger();
});

String p(String filePath) => context.convertPath(filePath);
Expand Down
10 changes: 5 additions & 5 deletions pkg/dartfix/test/src/test_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class TestExit {
class TestLogger implements Logger {
final bool debug;
final Ansi ansi;
final stdoutBuffer = new StringBuffer();
final stderrBuffer = new StringBuffer();
final stdoutBuffer = StringBuffer();
final stderrBuffer = StringBuffer();

TestLogger({this.debug = false}) : this.ansi = new Ansi(false);
TestLogger({this.debug = false}) : this.ansi = Ansi(false);

@override
void flush() {}
Expand All @@ -51,7 +51,7 @@ class TestLogger implements Logger {

@override
Progress progress(String message) {
return new SimpleProgress(this, message);
return SimpleProgress(this, message);
}

@override
Expand Down Expand Up @@ -94,7 +94,7 @@ void expectDoesNotHaveSuggestion(
File findFile(String relPath) {
Directory dir = Directory.current;
while (true) {
final file = new File.fromUri(dir.uri.resolve(relPath));
final file = File.fromUri(dir.uri.resolve(relPath));
if (file.existsSync()) {
return file;
}
Expand Down

0 comments on commit d992f55

Please sign in to comment.