Skip to content

Commit

Permalink
update to tslint5
Browse files Browse the repository at this point in the history
  • Loading branch information
egamma committed Nov 7, 2017
1 parent 968934c commit 56111c9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -50,7 +50,7 @@
}
},
{
"taskName": "Run Dev",
"label": "Run Dev",
"type": "shell",
"command": "./scripts/code.sh",
"windows": {
Expand Down
29 changes: 15 additions & 14 deletions build/gulpfile.hygiene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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))
Expand All @@ -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) => {
Expand Down Expand Up @@ -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, '.');
Expand Down
14 changes: 8 additions & 6 deletions build/lib/tslint/noUnexternalizedStringsRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
14 changes: 8 additions & 6 deletions build/lib/tslint/noUnexternalizedStringsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -430,5 +430,6 @@
],
"duplicate-imports": true,
"translation-remind": true
}
}
},
"defaultSeverity": "warning"
}

0 comments on commit 56111c9

Please sign in to comment.