update to tslint5

This commit is contained in:
Erich Gamma 2017-11-07 11:53:59 +01:00
parent 968934c141
commit 56111c9cc6
6 changed files with 40 additions and 34 deletions

6
.vscode/tasks.json vendored
View file

@ -33,11 +33,11 @@
"task": "tslint",
"label": "Run tslint",
"problemMatcher": [
"$tslint4"
"$tslint5"
]
},
{
"taskName": "Run tests",
"label": "Run tests",
"type": "shell",
"command": "./scripts/test.sh",
"windows": {
@ -50,7 +50,7 @@
}
},
{
"taskName": "Run Dev",
"label": "Run Dev",
"type": "shell",
"command": "./scripts/code.sh",
"windows": {

View file

@ -123,7 +123,8 @@ const tslintFilter = [
'!**/node_modules/**',
'!extensions/typescript/test/colorize-fixtures/**',
'!extensions/vscode-api-tests/testWorkspace/**',
'!extensions/**/*.test.ts'
'!extensions/**/*.test.ts',
'!extensions/html/server/lib/jquery.d.ts'
];
const copyrightHeader = [
@ -133,17 +134,6 @@ const copyrightHeader = [
' *--------------------------------------------------------------------------------------------*/'
].join('\n');
function reportFailures(failures) {
failures.forEach(failure => {
const name = failure.name || failure.fileName;
const position = failure.startPosition;
const line = position.lineAndCharacter ? position.lineAndCharacter.line : position.line;
const character = position.lineAndCharacter ? position.lineAndCharacter.character : position.character;
console.error(`${name}:${line + 1}:${character + 1}:${failure.failure}`);
});
}
gulp.task('eslint', () => {
return vfs.src(all, { base: '.', follow: true, allowEmpty: true })
.pipe(filter(eslintFilter))
@ -153,12 +143,12 @@ gulp.task('eslint', () => {
});
gulp.task('tslint', () => {
const options = { summarizeFailureOutput: true };
const options = { emitError: false };
return vfs.src(all, { base: '.', follow: true, allowEmpty: true })
.pipe(filter(tslintFilter))
.pipe(gulptslint({ rulesDirectory: 'build/lib/tslint' }))
.pipe(gulptslint.report(reportFailures, options));
.pipe(gulptslint.report(options));
});
const hygiene = exports.hygiene = (some, options) => {
@ -219,6 +209,17 @@ const hygiene = exports.hygiene = (some, options) => {
cb(err);
});
});
function reportFailures(failures) {
failures.forEach(failure => {
const name = failure.name || failure.fileName;
const position = failure.startPosition;
const line = position.lineAndCharacter ? position.lineAndCharacter.line : position.line;
const character = position.lineAndCharacter ? position.lineAndCharacter.character : position.character;
console.error(`${name}:${line + 1}:${character + 1}:${failure.failure}`);
});
}
const tsl = es.through(function (file) {
const configuration = tslint.Configuration.findConfiguration(null, '.');

View file

@ -88,10 +88,11 @@ var NoUnexternalizedStringsRuleWalker = /** @class */ (function (_super) {
var info = this.findDescribingParent(node);
// Ignore strings in import and export nodes.
if (info && info.isImport && doubleQuoted) {
this.addFailureAtNode(node, NoUnexternalizedStringsRuleWalker.ImportFailureMessage, new Lint.Fix(NoUnexternalizedStringsRuleWalker.ImportFailureMessage, [
this.createReplacement(node.getStart(), 1, '\''),
this.createReplacement(node.getStart() + text.length - 1, 1, '\''),
]));
var fix = [
Lint.Replacement.replaceFromTo(node.getStart(), 1, '\''),
Lint.Replacement.replaceFromTo(node.getStart() + text.length - 1, 1, '\''),
];
this.addFailureAtNode(node, NoUnexternalizedStringsRuleWalker.ImportFailureMessage, fix);
return;
}
var callInfo = info ? info.callInfo : null;
@ -101,8 +102,9 @@ var NoUnexternalizedStringsRuleWalker = /** @class */ (function (_super) {
}
if (doubleQuoted && (!callInfo || callInfo.argIndex === -1 || !this.signatures[functionName])) {
var s = node.getText();
var replacement = new Lint.Replacement(node.getStart(), node.getWidth(), "nls.localize('KEY-" + s.substring(1, s.length - 1) + "', " + s + ")");
var fix = new Lint.Fix('Unexternalitzed string', [replacement]);
var fix = [
Lint.Replacement.replaceFromTo(node.getStart(), node.getWidth(), "nls.localize('KEY-" + s.substring(1, s.length - 1) + "', " + s + ")"),
];
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Unexternalized string found: " + node.getText(), fix));
return;
}

View file

@ -104,13 +104,14 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker {
let info = this.findDescribingParent(node);
// Ignore strings in import and export nodes.
if (info && info.isImport && doubleQuoted) {
const fix = [
Lint.Replacement.replaceFromTo(node.getStart(), 1, '\''),
Lint.Replacement.replaceFromTo(node.getStart() + text.length - 1, 1, '\''),
];
this.addFailureAtNode(
node,
NoUnexternalizedStringsRuleWalker.ImportFailureMessage,
new Lint.Fix(NoUnexternalizedStringsRuleWalker.ImportFailureMessage, [
this.createReplacement(node.getStart(), 1, '\''),
this.createReplacement(node.getStart() + text.length - 1, 1, '\''),
])
fix
);
return;
}
@ -122,8 +123,9 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker {
if (doubleQuoted && (!callInfo || callInfo.argIndex === -1 || !this.signatures[functionName])) {
const s = node.getText();
const replacement = new Lint.Replacement(node.getStart(), node.getWidth(), `nls.localize('KEY-${s.substring(1, s.length - 1)}', ${s})`);
const fix = new Lint.Fix('Unexternalitzed string', [replacement]);
const fix = [
Lint.Replacement.replaceFromTo(node.getStart(), node.getWidth(), `nls.localize('KEY-${s.substring(1, s.length - 1)}', ${s})`),
];
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), `Unexternalized string found: ${node.getText()}`, fix));
return;
}

View file

@ -85,7 +85,7 @@
"gulp-shell": "^0.5.2",
"gulp-sourcemaps": "^1.11.0",
"gulp-tsb": "2.0.4",
"gulp-tslint": "^7.0.1",
"gulp-tslint": "^8.1.2",
"gulp-uglify": "^3.0.0",
"gulp-util": "^3.0.6",
"gulp-vinyl-zip": "^1.2.2",
@ -107,7 +107,7 @@
"rimraf": "^2.2.8",
"sinon": "^1.17.2",
"source-map": "^0.4.4",
"tslint": "^4.3.1",
"tslint": "^5.8.0",
"typescript": "2.6.1",
"typescript-formatter": "4.0.1",
"uglify-es": "^3.0.18",

View file

@ -6,7 +6,7 @@
"no-string-throw": true,
"no-unused-expression": true,
"no-duplicate-variable": true,
"no-unused-variable": true,
// "no-unused-variable": true, // requires type information in tslint > v4
"curly": true,
"class-name": true,
"semicolon": [
@ -430,5 +430,6 @@
],
"duplicate-imports": true,
"translation-remind": true
}
}
},
"defaultSeverity": "warning"
}