Skip to content

Commit d9ca99d

Browse files
committed
Merge pull request #3637 from RyanCavanaugh/errorCheck
Remove unused errors
2 parents c20ea3e + aa59753 commit d9ca99d

File tree

3 files changed

+87
-70
lines changed

3 files changed

+87
-70
lines changed

scripts/errorCheck.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
declare var require: any;
2+
let fs = require('fs');
3+
let async = require('async');
4+
let glob = require('glob');
5+
6+
fs.readFile('src/compiler/diagnosticMessages.json', 'utf-8', (err, data) => {
7+
if (err) {
8+
throw err;
9+
}
10+
11+
let messages = JSON.parse(data);
12+
let keys = Object.keys(messages);
13+
console.log('Loaded ' + keys.length + ' errors');
14+
15+
for (let k of keys) {
16+
messages[k]['seen'] = false;
17+
}
18+
19+
let errRegex = /\(\d+,\d+\): error TS([^:]+):/g;
20+
21+
let baseDir = 'tests/baselines/reference/';
22+
fs.readdir(baseDir, (err, files) => {
23+
files = files.filter(f => f.indexOf('.errors.txt') > 0);
24+
let tasks: Array<(callback: () => void) => void> = [];
25+
files.forEach(f => tasks.push(done => {
26+
fs.readFile(baseDir + f, 'utf-8', (err, baseline) => {
27+
if (err) throw err;
28+
29+
let g: string[];
30+
while (g = errRegex.exec(baseline)) {
31+
var errCode = +g[1];
32+
let msg = keys.filter(k => messages[k].code === errCode)[0];
33+
messages[msg]['seen'] = true;
34+
}
35+
36+
done();
37+
});
38+
}));
39+
40+
async.parallelLimit(tasks, 25, done => {
41+
console.log('== List of errors not present in baselines ==');
42+
let count = 0;
43+
for (let k of keys) {
44+
if (messages[k]['seen'] !== true) {
45+
console.log(k);
46+
count++;
47+
}
48+
}
49+
console.log(count + ' of ' + keys.length + ' errors are not in baselines');
50+
});
51+
});
52+
});
53+
54+
fs.readFile('src/compiler/diagnosticInformationMap.generated.ts', 'utf-8', (err, data) => {
55+
let errorRegexp = /\s(\w+): \{ code/g;
56+
let errorNames: string[] = [];
57+
let errMatch: string[];
58+
while (errMatch = errorRegexp.exec(data)) {
59+
errorNames.push(errMatch[1]);
60+
}
61+
62+
let allSrc: string = '';
63+
glob('./src/**/*.ts', {}, (err, files) => {
64+
console.log('Reading ' + files.length + ' source files');
65+
for(let file of files) {
66+
if (file.indexOf('diagnosticInformationMap.generated.ts') > 0) {
67+
continue;
68+
}
69+
70+
let src = fs.readFileSync(file, 'utf-8');
71+
allSrc = allSrc + src;
72+
}
73+
74+
console.log('Consumed ' + allSrc.length + ' characters of source');
75+
76+
let count = 0;
77+
console.log('== List of errors not used in source ==')
78+
for(let errName of errorNames) {
79+
if (allSrc.indexOf(errName) < 0) {
80+
console.log(errName);
81+
count++;
82+
}
83+
}
84+
console.log(count + ' of ' + errorNames.length + ' errors are not used in source');
85+
});
86+
});
87+

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,16 @@ namespace ts {
2020
An_index_signature_must_have_a_type_annotation: { code: 1021, category: DiagnosticCategory.Error, key: "An index signature must have a type annotation." },
2121
An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: DiagnosticCategory.Error, key: "An index signature parameter must have a type annotation." },
2222
An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: DiagnosticCategory.Error, key: "An index signature parameter type must be 'string' or 'number'." },
23-
A_class_or_interface_declaration_can_only_have_one_extends_clause: { code: 1024, category: DiagnosticCategory.Error, key: "A class or interface declaration can only have one 'extends' clause." },
24-
An_extends_clause_must_precede_an_implements_clause: { code: 1025, category: DiagnosticCategory.Error, key: "An 'extends' clause must precede an 'implements' clause." },
25-
A_class_can_only_extend_a_single_class: { code: 1026, category: DiagnosticCategory.Error, key: "A class can only extend a single class." },
26-
A_class_declaration_can_only_have_one_implements_clause: { code: 1027, category: DiagnosticCategory.Error, key: "A class declaration can only have one 'implements' clause." },
2723
Accessibility_modifier_already_seen: { code: 1028, category: DiagnosticCategory.Error, key: "Accessibility modifier already seen." },
2824
_0_modifier_must_precede_1_modifier: { code: 1029, category: DiagnosticCategory.Error, key: "'{0}' modifier must precede '{1}' modifier." },
2925
_0_modifier_already_seen: { code: 1030, category: DiagnosticCategory.Error, key: "'{0}' modifier already seen." },
3026
_0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a class element." },
31-
An_interface_declaration_cannot_have_an_implements_clause: { code: 1032, category: DiagnosticCategory.Error, key: "An interface declaration cannot have an 'implements' clause." },
3227
super_must_be_followed_by_an_argument_list_or_member_access: { code: 1034, category: DiagnosticCategory.Error, key: "'super' must be followed by an argument list or member access." },
3328
Only_ambient_modules_can_use_quoted_names: { code: 1035, category: DiagnosticCategory.Error, key: "Only ambient modules can use quoted names." },
3429
Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: DiagnosticCategory.Error, key: "Statements are not allowed in ambient contexts." },
3530
A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used in an already ambient context." },
3631
Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: DiagnosticCategory.Error, key: "Initializers are not allowed in ambient contexts." },
3732
_0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a module element." },
38-
A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used with an interface declaration." },
3933
A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: DiagnosticCategory.Error, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." },
4034
A_rest_parameter_cannot_be_optional: { code: 1047, category: DiagnosticCategory.Error, key: "A rest parameter cannot be optional." },
4135
A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: DiagnosticCategory.Error, key: "A rest parameter cannot have an initializer." },
@@ -94,7 +88,6 @@ namespace ts {
9488
case_or_default_expected: { code: 1130, category: DiagnosticCategory.Error, key: "'case' or 'default' expected." },
9589
Property_or_signature_expected: { code: 1131, category: DiagnosticCategory.Error, key: "Property or signature expected." },
9690
Enum_member_expected: { code: 1132, category: DiagnosticCategory.Error, key: "Enum member expected." },
97-
Type_reference_expected: { code: 1133, category: DiagnosticCategory.Error, key: "Type reference expected." },
9891
Variable_declaration_expected: { code: 1134, category: DiagnosticCategory.Error, key: "Variable declaration expected." },
9992
Argument_expression_expected: { code: 1135, category: DiagnosticCategory.Error, key: "Argument expression expected." },
10093
Property_assignment_expected: { code: 1136, category: DiagnosticCategory.Error, key: "Property assignment expected." },
@@ -111,9 +104,6 @@ namespace ts {
111104
Cannot_compile_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile modules unless the '--module' flag is provided." },
112105
File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "File name '{0}' differs from already included file name '{1}' only in casing" },
113106
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
114-
var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." },
115-
let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." },
116-
const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." },
117107
const_declarations_must_be_initialized: { code: 1155, category: DiagnosticCategory.Error, key: "'const' declarations must be initialized" },
118108
const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." },
119109
let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." },
@@ -124,7 +114,6 @@ namespace ts {
124114
Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." },
125115
A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." },
126116
A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." },
127-
Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: DiagnosticCategory.Error, key: "Computed property names are only available when targeting ECMAScript 6 and higher." },
128117
A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol: { code: 1168, category: DiagnosticCategory.Error, key: "A computed property name in a method overload must directly refer to a built-in symbol." },
129118
A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol: { code: 1169, category: DiagnosticCategory.Error, key: "A computed property name in an interface must directly refer to a built-in symbol." },
130119
A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol: { code: 1170, category: DiagnosticCategory.Error, key: "A computed property name in a type literal must directly refer to a built-in symbol." },
@@ -140,7 +129,6 @@ namespace ts {
140129
Property_destructuring_pattern_expected: { code: 1180, category: DiagnosticCategory.Error, key: "Property destructuring pattern expected." },
141130
Array_element_destructuring_pattern_expected: { code: 1181, category: DiagnosticCategory.Error, key: "Array element destructuring pattern expected." },
142131
A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." },
143-
Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: DiagnosticCategory.Error, key: "Destructuring declarations are not allowed in ambient contexts." },
144132
An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." },
145133
Modifiers_cannot_appear_here: { code: 1184, category: DiagnosticCategory.Error, key: "Modifiers cannot appear here." },
146134
Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." },
@@ -205,7 +193,6 @@ namespace ts {
205193
Module_0_has_no_exported_member_1: { code: 2305, category: DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." },
206194
File_0_is_not_a_module: { code: 2306, category: DiagnosticCategory.Error, key: "File '{0}' is not a module." },
207195
Cannot_find_module_0: { code: 2307, category: DiagnosticCategory.Error, key: "Cannot find module '{0}'." },
208-
A_module_cannot_have_more_than_one_export_assignment: { code: 2308, category: DiagnosticCategory.Error, key: "A module cannot have more than one export assignment." },
209196
An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2309, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." },
210197
Type_0_recursively_references_itself_as_a_base_type: { code: 2310, category: DiagnosticCategory.Error, key: "Type '{0}' recursively references itself as a base type." },
211198
A_class_may_only_extend_another_class: { code: 2311, category: DiagnosticCategory.Error, key: "A class may only extend another class." },
@@ -531,7 +518,6 @@ namespace ts {
531518
File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
532519
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
533520
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
534-
Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
535521
Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." },
536522
File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." },
537523
Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." },

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,6 @@
6767
"category": "Error",
6868
"code": 1023
6969
},
70-
"A class or interface declaration can only have one 'extends' clause.": {
71-
"category": "Error",
72-
"code": 1024
73-
},
74-
"An 'extends' clause must precede an 'implements' clause.": {
75-
"category": "Error",
76-
"code": 1025
77-
},
78-
"A class can only extend a single class.": {
79-
"category": "Error",
80-
"code": 1026
81-
},
82-
"A class declaration can only have one 'implements' clause.": {
83-
"category": "Error",
84-
"code": 1027
85-
},
8670
"Accessibility modifier already seen.": {
8771
"category": "Error",
8872
"code": 1028
@@ -99,10 +83,6 @@
9983
"category": "Error",
10084
"code": 1031
10185
},
102-
"An interface declaration cannot have an 'implements' clause.": {
103-
"category": "Error",
104-
"code": 1032
105-
},
10686
"'super' must be followed by an argument list or member access.": {
10787
"category": "Error",
10888
"code": 1034
@@ -127,10 +107,6 @@
127107
"category": "Error",
128108
"code": 1044
129109
},
130-
"A 'declare' modifier cannot be used with an interface declaration.": {
131-
"category": "Error",
132-
"code": 1045
133-
},
134110
"A 'declare' modifier is required for a top level declaration in a .d.ts file.": {
135111
"category": "Error",
136112
"code": 1046
@@ -363,10 +339,6 @@
363339
"category": "Error",
364340
"code": 1132
365341
},
366-
"Type reference expected.": {
367-
"category": "Error",
368-
"code": 1133
369-
},
370342
"Variable declaration expected.": {
371343
"category": "Error",
372344
"code": 1134
@@ -431,18 +403,6 @@
431403
"category": "Error",
432404
"code": 1150
433405
},
434-
"'var', 'let' or 'const' expected.": {
435-
"category": "Error",
436-
"code": 1152
437-
},
438-
"'let' declarations are only available when targeting ECMAScript 6 and higher.": {
439-
"category": "Error",
440-
"code": 1153
441-
},
442-
"'const' declarations are only available when targeting ECMAScript 6 and higher.": {
443-
"category": "Error",
444-
"code": 1154
445-
},
446406
"'const' declarations must be initialized": {
447407
"category": "Error",
448408
"code": 1155
@@ -483,10 +443,6 @@
483443
"category": "Error",
484444
"code": 1166
485445
},
486-
"Computed property names are only available when targeting ECMAScript 6 and higher.": {
487-
"category": "Error",
488-
"code": 1167
489-
},
490446
"A computed property name in a method overload must directly refer to a built-in symbol.": {
491447
"category": "Error",
492448
"code": 1168
@@ -547,10 +503,6 @@
547503
"category": "Error",
548504
"code": 1182
549505
},
550-
"Destructuring declarations are not allowed in ambient contexts.": {
551-
"category": "Error",
552-
"code": 1183
553-
},
554506
"An implementation cannot be declared in ambient contexts.": {
555507
"category": "Error",
556508
"code": 1184
@@ -810,10 +762,6 @@
810762
"category": "Error",
811763
"code": 2307
812764
},
813-
"A module cannot have more than one export assignment.": {
814-
"category": "Error",
815-
"code": 2308
816-
},
817765
"An export assignment cannot be used in a module with other exported elements.": {
818766
"category": "Error",
819767
"code": 2309
@@ -2116,10 +2064,6 @@
21162064
"category": "Message",
21172065
"code": 6056
21182066
},
2119-
"Preserve new-lines when emitting code.": {
2120-
"category": "Message",
2121-
"code": 6057
2122-
},
21232067
"Specifies the root directory of input files. Use to control the output directory structure with --outDir.": {
21242068
"category": "Message",
21252069
"code": 6058

0 commit comments

Comments
 (0)