Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 3007783002: Add fixes for two additional lints (Closed)
Patch Set: Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/util.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; 8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
9 import 'package:analysis_server/src/services/correction/fix.dart'; 9 import 'package:analysis_server/src/services/correction/fix.dart';
10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; 10 import 'package:analysis_server/src/services/correction/fix_internal.dart';
(...skipping 5543 matching lines...) Expand 10 before | Expand all | Expand 10 after
5554 Future<Null> findLint(String src, String lintCode, {int length: 1}) async { 5554 Future<Null> findLint(String src, String lintCode, {int length: 1}) async {
5555 int errorOffset = src.indexOf('/*LINT*/'); 5555 int errorOffset = src.indexOf('/*LINT*/');
5556 await resolveTestUnit(src.replaceAll('/*LINT*/', '')); 5556 await resolveTestUnit(src.replaceAll('/*LINT*/', ''));
5557 error = new AnalysisError( 5557 error = new AnalysisError(
5558 resolutionMap.elementDeclaredByCompilationUnit(testUnit).source, 5558 resolutionMap.elementDeclaredByCompilationUnit(testUnit).source,
5559 errorOffset, 5559 errorOffset,
5560 length, 5560 length,
5561 new LintCode(lintCode, '<ignored>')); 5561 new LintCode(lintCode, '<ignored>'));
5562 } 5562 }
5563 5563
5564 test_addRequiredAnnotation() async {
5565 String src = '''
5566 void function({String /*LINT*/param}) {
5567 assert(param != null);
5568 }
5569 ''';
5570 await findLint(src, LintNames.always_require_non_null_named_parameters);
5571 await applyFix(DartFixKind.LINT_ADD_REQUIRED);
5572 verifyResult('''
5573 void function({@required String param}) {
5574 assert(param != null);
5575 }
5576 ''');
5577 }
5578
5564 test_lint_addMissingOverride_field() async { 5579 test_lint_addMissingOverride_field() async {
5565 String src = ''' 5580 String src = '''
5566 class abstract Test { 5581 class abstract Test {
5567 int get t; 5582 int get t;
5568 } 5583 }
5569 class Sub extends Test { 5584 class Sub extends Test {
5570 int /*LINT*/t = 42; 5585 int /*LINT*/t = 42;
5571 } 5586 }
5572 '''; 5587 ''';
5573 await findLint(src, LintNames.annotate_overrides); 5588 await findLint(src, LintNames.annotate_overrides);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
5788 5803
5789 await applyFix(DartFixKind.REMOVE_AWAIT); 5804 await applyFix(DartFixKind.REMOVE_AWAIT);
5790 5805
5791 verifyResult(''' 5806 verifyResult('''
5792 bad() async { 5807 bad() async {
5793 print('hola'); 5808 print('hola');
5794 } 5809 }
5795 '''); 5810 ''');
5796 } 5811 }
5797 5812
5813 test_removeEmptyElse_newLine() async {
5814 String src = '''
5815 void foo(bool cond) {
5816 if (cond) {
5817 //
5818 }
5819 else /*LINT*/;
5820 }
5821 ''';
5822 await findLint(src, LintNames.avoid_empty_else);
5823
5824 await applyFix(DartFixKind.REMOVE_EMPTY_ELSE);
5825
5826 verifyResult('''
5827 void foo(bool cond) {
5828 if (cond) {
5829 //
5830 }
5831 }
5832 ''');
5833 }
5834
5835 test_removeEmptyElse_sameLine() async {
5836 String src = '''
5837 void foo(bool cond) {
5838 if (cond) {
5839 //
5840 } else /*LINT*/;
scheglov 2017/08/29 17:05:22 Is the lint reported for empty else blocks?
Brian Wilkerson 2017/08/29 17:16:46 It isn't currently, but I think it should be.
5841 }
5842 ''';
5843 await findLint(src, LintNames.avoid_empty_else);
5844
5845 await applyFix(DartFixKind.REMOVE_EMPTY_ELSE);
5846
5847 verifyResult('''
5848 void foo(bool cond) {
5849 if (cond) {
5850 //
5851 }
5852 }
5853 ''');
5854 }
5855
5798 test_removeEmptyStatement_insideBlock() async { 5856 test_removeEmptyStatement_insideBlock() async {
5799 String src = ''' 5857 String src = '''
5800 void foo() { 5858 void foo() {
5801 while(true) { 5859 while(true) {
5802 /*LINT*/; 5860 /*LINT*/;
5803 } 5861 }
5804 } 5862 }
5805 '''; 5863 ''';
5806 await findLint(src, LintNames.empty_statements); 5864 await findLint(src, LintNames.empty_statements);
5807 5865
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
6531 @override 6589 @override
6532 final AnalysisError error; 6590 final AnalysisError error;
6533 6591
6534 _DartFixContextImpl(this.resourceProvider, this.analysisDriver, 6592 _DartFixContextImpl(this.resourceProvider, this.analysisDriver,
6535 this.astProvider, this.unit, this.error); 6593 this.astProvider, this.unit, this.error);
6536 6594
6537 @override 6595 @override
6538 GetTopLevelDeclarations get getTopLevelDeclarations => 6596 GetTopLevelDeclarations get getTopLevelDeclarations =>
6539 analysisDriver.getTopLevelNameDeclarations; 6597 analysisDriver.getTopLevelNameDeclarations;
6540 } 6598 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/util.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698