-
Notifications
You must be signed in to change notification settings - Fork 13k
Remove unused errors #3637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unused errors #3637
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
declare var require: any; | ||
let fs = require('fs'); | ||
let async = require('async'); | ||
let glob = require('glob'); | ||
|
||
fs.readFile('src/compiler/diagnosticMessages.json', 'utf-8', (err, data) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
let messages = JSON.parse(data); | ||
let keys = Object.keys(messages); | ||
console.log('Loaded ' + keys.length + ' errors'); | ||
|
||
for (let k of keys) { | ||
messages[k]['seen'] = false; | ||
} | ||
|
||
let errRegex = /\(\d+,\d+\): error TS([^:]+):/g; | ||
|
||
let baseDir = 'tests/baselines/reference/'; | ||
fs.readdir(baseDir, (err, files) => { | ||
files = files.filter(f => f.indexOf('.errors.txt') > 0); | ||
let tasks: Array<(callback: () => void) => void> = []; | ||
files.forEach(f => tasks.push(done => { | ||
fs.readFile(baseDir + f, 'utf-8', (err, baseline) => { | ||
if (err) throw err; | ||
|
||
let g: string[]; | ||
while (g = errRegex.exec(baseline)) { | ||
var errCode = +g[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
let msg = keys.filter(k => messages[k].code === errCode)[0]; | ||
messages[msg]['seen'] = true; | ||
} | ||
|
||
done(); | ||
}); | ||
})); | ||
|
||
async.parallelLimit(tasks, 25, done => { | ||
console.log('== List of errors not present in baselines =='); | ||
let count = 0; | ||
for (let k of keys) { | ||
if (messages[k]['seen'] !== true) { | ||
console.log(k); | ||
count++; | ||
} | ||
} | ||
console.log(count + ' of ' + keys.length + ' errors are not in baselines'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are the numbers your found? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 138 of 535 errors are not in baselines There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that a decent number of those are e.g. commandline option descriptions, which aren't actually errors |
||
}); | ||
}); | ||
}); | ||
|
||
fs.readFile('src/compiler/diagnosticInformationMap.generated.ts', 'utf-8', (err, data) => { | ||
let errorRegexp = /\s(\w+): \{ code/g; | ||
let errorNames: string[] = []; | ||
let errMatch: string[]; | ||
while (errMatch = errorRegexp.exec(data)) { | ||
errorNames.push(errMatch[1]); | ||
} | ||
|
||
let allSrc: string = ''; | ||
glob('./src/**/*.ts', {}, (err, files) => { | ||
console.log('Reading ' + files.length + ' source files'); | ||
for(let file of files) { | ||
if (file.indexOf('diagnosticInformationMap.generated.ts') > 0) { | ||
continue; | ||
} | ||
|
||
let src = fs.readFileSync(file, 'utf-8'); | ||
allSrc = allSrc + src; | ||
} | ||
|
||
console.log('Consumed ' + allSrc.length + ' characters of source'); | ||
|
||
let count = 0; | ||
console.log('== List of errors not used in source ==') | ||
for(let errName of errorNames) { | ||
if (allSrc.indexOf(errName) < 0) { | ||
console.log(errName); | ||
count++; | ||
} | ||
} | ||
console.log(count + ' of ' + errorNames.length + ' errors are not used in source'); | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,22 +67,6 @@ | |
"category": "Error", | ||
"code": 1023 | ||
}, | ||
"A class or interface declaration can only have one 'extends' clause.": { | ||
"category": "Error", | ||
"code": 1024 | ||
}, | ||
"An 'extends' clause must precede an 'implements' clause.": { | ||
"category": "Error", | ||
"code": 1025 | ||
}, | ||
"A class can only extend a single class.": { | ||
"category": "Error", | ||
"code": 1026 | ||
}, | ||
"A class declaration can only have one 'implements' clause.": { | ||
"category": "Error", | ||
"code": 1027 | ||
}, | ||
"Accessibility modifier already seen.": { | ||
"category": "Error", | ||
"code": 1028 | ||
|
@@ -99,10 +83,6 @@ | |
"category": "Error", | ||
"code": 1031 | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These seem like legitimate errors. What do we report in place of them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extends_clause_already_seen
extends_clause_must_precede_implements_clause
Classes_can_only_extend_a_single_class
implements_clause_already_seen There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those seem like potentially better messages given the direction of singular indefinite articles @JsonFreeman pushed for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are in line with our other parser-like error messages, e.g. we say |
||
"An interface declaration cannot have an 'implements' clause.": { | ||
"category": "Error", | ||
"code": 1032 | ||
}, | ||
"'super' must be followed by an argument list or member access.": { | ||
"category": "Error", | ||
"code": 1034 | ||
|
@@ -127,10 +107,6 @@ | |
"category": "Error", | ||
"code": 1044 | ||
}, | ||
"A 'declare' modifier cannot be used with an interface declaration.": { | ||
"category": "Error", | ||
"code": 1045 | ||
}, | ||
"A 'declare' modifier is required for a top level declaration in a .d.ts file.": { | ||
"category": "Error", | ||
"code": 1046 | ||
|
@@ -363,10 +339,6 @@ | |
"category": "Error", | ||
"code": 1132 | ||
}, | ||
"Type reference expected.": { | ||
"category": "Error", | ||
"code": 1133 | ||
}, | ||
"Variable declaration expected.": { | ||
"category": "Error", | ||
"code": 1134 | ||
|
@@ -431,18 +403,6 @@ | |
"category": "Error", | ||
"code": 1150 | ||
}, | ||
"'var', 'let' or 'const' expected.": { | ||
"category": "Error", | ||
"code": 1152 | ||
}, | ||
"'let' declarations are only available when targeting ECMAScript 6 and higher.": { | ||
"category": "Error", | ||
"code": 1153 | ||
}, | ||
"'const' declarations are only available when targeting ECMAScript 6 and higher.": { | ||
"category": "Error", | ||
"code": 1154 | ||
}, | ||
"'const' declarations must be initialized": { | ||
"category": "Error", | ||
"code": 1155 | ||
|
@@ -483,10 +443,6 @@ | |
"category": "Error", | ||
"code": 1166 | ||
}, | ||
"Computed property names are only available when targeting ECMAScript 6 and higher.": { | ||
"category": "Error", | ||
"code": 1167 | ||
}, | ||
"A computed property name in a method overload must directly refer to a built-in symbol.": { | ||
"category": "Error", | ||
"code": 1168 | ||
|
@@ -547,10 +503,6 @@ | |
"category": "Error", | ||
"code": 1182 | ||
}, | ||
"Destructuring declarations are not allowed in ambient contexts.": { | ||
"category": "Error", | ||
"code": 1183 | ||
}, | ||
"An implementation cannot be declared in ambient contexts.": { | ||
"category": "Error", | ||
"code": 1184 | ||
|
@@ -736,10 +688,6 @@ | |
"category": "Error", | ||
"code": 2307 | ||
}, | ||
"A module cannot have more than one export assignment.": { | ||
"category": "Error", | ||
"code": 2308 | ||
}, | ||
"An export assignment cannot be used in a module with other exported elements.": { | ||
"category": "Error", | ||
"code": 2309 | ||
|
@@ -2022,10 +1970,6 @@ | |
"category": "Message", | ||
"code": 6056 | ||
}, | ||
"Preserve new-lines when emitting code.": { | ||
"category": "Message", | ||
"code": 6057 | ||
}, | ||
"Specifies the root directory of input files. Use to control the output directory structure with --outDir.": { | ||
"category": "Message", | ||
"code": 6058 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curlies