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

Side by Side Diff: pkg/analyzer/test/generated/hint_code_test.dart

Issue 1863103002: Add an UNUSED_SHOWN_NAMES hint to the analyzer (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix top-level variables Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library analyzer.test.generated.hint_code_test; 5 library analyzer.test.generated.hint_code_test;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/source_io.dart'; 9 import 'package:analyzer/src/generated/source_io.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 2820 matching lines...) Expand 10 before | Expand all | Expand 10 after
2831 r''' 2831 r'''
2832 library lib1; 2832 library lib1;
2833 class A {} 2833 class A {}
2834 class B {}'''); 2834 class B {}''');
2835 computeLibrarySourceErrors(source); 2835 computeLibrarySourceErrors(source);
2836 assertErrors(source, [HintCode.UNUSED_IMPORT]); 2836 assertErrors(source, [HintCode.UNUSED_IMPORT]);
2837 assertNoErrors(source2); 2837 assertNoErrors(source2);
2838 verify([source, source2]); 2838 verify([source, source2]);
2839 } 2839 }
2840 2840
2841 void test_unusedShownName() {
2842 Source source = addSource(r'''
2843 library L;
2844 import 'lib1.dart' show A, B;
2845 A a;''');
2846 Source source2 = addNamedSource(
2847 "/lib1.dart", r'''
2848 library lib1;
2849 class A {}
2850 class B {}''');
2851 computeLibrarySourceErrors(source);
2852 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
2853 assertNoErrors(source2);
2854 verify([source, source2]);
2855 }
2856
2857 void test_unusedShownName_topLevelVariable() {
2858 Source source = addSource(r'''
2859 library L;
2860 import 'lib1.dart' show var1, var2;
2861 import 'lib1.dart' show var3, var4;
2862 int a = var1;
2863 int b = var2;
2864 int c = var3;''');
2865 Source source2 = addNamedSource(
2866 "/lib1.dart",
2867 r'''
2868 library lib1;
2869 const int var1 = 1;
2870 const int var2 = 2;
2871 const int var3 = 3;
2872 const int var4 = 4;''');
2873 computeLibrarySourceErrors(source);
2874 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
2875 assertNoErrors(source2);
2876 verify([source, source2]);
2877 }
2878
2879 void test_unusedShownName_as() {
2880 Source source = addSource(r'''
2881 library L;
2882 import 'lib1.dart' as p show A, B;
2883 p.A a;''');
2884 Source source2 = addNamedSource(
2885 "/lib1.dart", r'''
2886 library lib1;
2887 class A {}
2888 class B {}''');
2889 computeLibrarySourceErrors(source);
2890 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
2891 assertNoErrors(source2);
2892 verify([source, source2]);
2893 }
2894
2895 void test_unusedShownName_duplicates() {
2896 Source source = addSource(r'''
2897 library L;
2898 import 'lib1.dart' show A, B;
2899 import 'lib1.dart' show C, D;
2900 A a;
2901 C c;''');
2902 Source source2 = addNamedSource(
2903 "/lib1.dart", r'''
2904 library lib1;
2905 class A {}
2906 class B {}
2907 class C {}
2908 class D {}''');
2909 computeLibrarySourceErrors(source);
2910 assertErrors(source, [
2911 HintCode.UNUSED_SHOWN_NAME,
2912 HintCode.UNUSED_SHOWN_NAME]);
2913 assertNoErrors(source2);
2914 verify([source, source2]);
2915 }
2916
2841 void test_unusedLocalVariable_inCatch_exception() { 2917 void test_unusedLocalVariable_inCatch_exception() {
2842 enableUnusedLocalVariable = true; 2918 enableUnusedLocalVariable = true;
2843 Source source = addSource(r''' 2919 Source source = addSource(r'''
2844 main() { 2920 main() {
2845 try { 2921 try {
2846 } on String catch (exception) { 2922 } on String catch (exception) {
2847 } 2923 }
2848 }'''); 2924 }''');
2849 computeLibrarySourceErrors(source); 2925 computeLibrarySourceErrors(source);
2850 assertErrors(source, [HintCode.UNUSED_CATCH_CLAUSE]); 2926 assertErrors(source, [HintCode.UNUSED_CATCH_CLAUSE]);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
3099 n() { 3175 n() {
3100 var a = m(), b = m(); 3176 var a = m(), b = m();
3101 } 3177 }
3102 }'''); 3178 }''');
3103 computeLibrarySourceErrors(source); 3179 computeLibrarySourceErrors(source);
3104 assertErrors( 3180 assertErrors(
3105 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); 3181 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]);
3106 verify([source]); 3182 verify([source]);
3107 } 3183 }
3108 } 3184 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/test/generated/non_error_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698