mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Remove unnecessary 'use strict' lines and add hygiene check (#5363)
* Remove unnecessary 'use strict' lines and add hygiene check for them * Move check to under tslint filters to reduce number of filters needed * Only take first 10 lines of file
This commit is contained in:
@@ -92,11 +92,10 @@ const indentationFilter = [
|
||||
'!**/*.dockerfile',
|
||||
'!extensions/markdown-language-features/media/*.js',
|
||||
// {{SQL CARBON EDIT}}
|
||||
'!**/*.xlf',
|
||||
'!**/*.docx',
|
||||
'!**/*.sql',
|
||||
'!**/*.{xlf,docx,sql,vsix}',
|
||||
'!extensions/mssql/sqltoolsservice/**',
|
||||
'!extensions/import/flatfileimportservice/**',
|
||||
'!extensions/admin-tool-ext-win/ssmsmin/**'
|
||||
];
|
||||
|
||||
const copyrightFilter = [
|
||||
@@ -184,6 +183,11 @@ const tslintFilter = [
|
||||
'!extensions/html-language-features/server/lib/jquery.d.ts'
|
||||
];
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
const useStrictFilter = [
|
||||
'src/**'
|
||||
];
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
const copyrightHeaderLines = [
|
||||
'/*---------------------------------------------------------------------------------------------',
|
||||
@@ -234,8 +238,8 @@ function hygiene(some) {
|
||||
});
|
||||
|
||||
const copyrights = es.through(function (file) {
|
||||
const lines = file.__lines;
|
||||
|
||||
const lines = file.__lines;
|
||||
for (let i = 0; i < copyrightHeaderLines.length; i++) {
|
||||
if (lines[i] !== copyrightHeaderLines[i]) {
|
||||
console.error(file.relative + ': Missing or bad copyright statement');
|
||||
@@ -247,6 +251,23 @@ function hygiene(some) {
|
||||
this.emit('data', file);
|
||||
});
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
// Check for unnecessary 'use strict' lines. These are automatically added by the alwaysStrict compiler option so don't need to be added manually
|
||||
const useStrict = es.through(function (file) {
|
||||
const lines = file.__lines;
|
||||
// Only take the first 10 lines to reduce false positives- the compiler will throw an error if it's not the first non-comment line in a file
|
||||
// (10 is used to account for copyright and extraneous newlines)
|
||||
lines.slice(0,10).forEach((line, i) => {
|
||||
if (/\s*'use\s*strict\s*'/.test(line)) {
|
||||
console.error(file.relative + '(' + (i + 1) + ',1): Unnecessary \'use strict\' - this is already added by the compiler');
|
||||
errorCount++;
|
||||
}
|
||||
});
|
||||
|
||||
this.emit('data', file);
|
||||
});
|
||||
// {{SQL CARBON EDIT}} END
|
||||
|
||||
const formatting = es.map(function (file, cb) {
|
||||
tsfmt.processString(file.path, file.contents.toString('utf8'), {
|
||||
verify: false,
|
||||
@@ -305,7 +326,10 @@ function hygiene(some) {
|
||||
const typescript = result
|
||||
.pipe(filter(tslintFilter))
|
||||
.pipe(formatting)
|
||||
.pipe(tsl);
|
||||
.pipe(tsl)
|
||||
// {{SQL CARBON EDIT}}
|
||||
.pipe(filter(useStrictFilter))
|
||||
.pipe(useStrict);
|
||||
|
||||
const javascript = result
|
||||
.pipe(filter(eslintFilter))
|
||||
|
||||
Reference in New Issue
Block a user