diff --git a/.vscode/settings.json b/.vscode/settings.json index 7acd2c0fbe4c7a2b24ddfb81f2a50b1099704ca2..1565c3d6fd5e807cc02dfcb6395accb001e97db5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,5 +12,6 @@ ".build/**": true, "out*/**": true, "extensions/**/out/**": true - } + }, + "tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib" } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bdfc0cff0c62070356d063da1744d32200d81f76..78d287a1677ea632eb7be90271c13c0ac92cc39d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -25,6 +25,25 @@ } } }, + { + "taskName": "tslint", + "args": [], + "problemMatcher": { + "owner": "tslint", + "fileLocation": [ + "relative", + "${workspaceRoot}" + ], + "severity": "warning", + "pattern": { + "regexp": "^\\[tslint\\] (.*):(\\d+):(\\d+):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "message": 4 + } + } + }, { "taskName": "test", "args": [ diff --git a/build/gulpfile.hygiene.js b/build/gulpfile.hygiene.js index 2d12721673f2acbf586459acebf1b514c5cdf678..8fad6d47dbb9bcd7c0edd12085910aa1e23de944 100644 --- a/build/gulpfile.hygiene.js +++ b/build/gulpfile.hygiene.js @@ -7,6 +7,7 @@ var gulp = require('gulp'); var filter = require('gulp-filter'); var es = require('event-stream'); var path = require('path'); +var tslint = require('gulp-tslint'); var all = [ '*', @@ -55,7 +56,7 @@ var indentationFilter = [ '!extensions/**/themes/**', ]; -var copyrightFilterList = [ +var copyrightFilter = [ '**', '!**/*.json', '!**/*.html', @@ -69,6 +70,15 @@ var copyrightFilterList = [ '!src/vs/editor/standalone-languages/swift.ts', ]; +var tslintFilter = [ + 'src/**/*.ts', + 'extensions/**/*.ts', + '!**/*.d.ts', + '!**/typings/**', + '!**/*.test.ts', + '!src/vs/editor/standalone-languages/test/**' +]; + var copyrightHeader = [ '/*---------------------------------------------------------------------------------------------', ' * Copyright (c) Microsoft Corporation. All rights reserved.', @@ -76,6 +86,28 @@ var copyrightHeader = [ ' *--------------------------------------------------------------------------------------------*/' ].join('\n'); +/** + * Reports tslint erros in the format: + * src/helloWorld.c:5:3: warning: implicit declaration of function ‘prinft’ + */ +var lintReporter = function (output, file, options) { + var relativeBase = file.base.substring(file.cwd.length + 1).replace('\\', '/'); + output.forEach(function (e) { + var message = relativeBase + e.name + ':' + (e.startPosition.line + 1) + ':' + (e.startPosition.character + 1) + ': ' + e.failure; + console.log('[tslint] ' + message); + }); +}; + +gulp.task('tslint', function () { + return gulp.src(all, { base: '.' }) + .pipe(filter(tslintFilter)) + .pipe(tslint({ rulesDirectory: 'node_modules/tslint-microsoft-contrib' })) + .pipe(tslint.report(lintReporter, { + summarizeFailureOutput: false, + emitError: false + })); +}); + var hygiene = exports.hygiene = function (some) { var errorCount = 0; @@ -92,7 +124,7 @@ var hygiene = exports.hygiene = function (some) { file.contents .toString('utf8') .split(/\r\n|\r|\n/) - .forEach(function(line, i) { + .forEach(function (line, i) { if (/^\s*$/.test(line)) { // empty or whitespace lines are OK } else if (/^[\t]*[^\s]/.test(line)) { @@ -123,7 +155,7 @@ var hygiene = exports.hygiene = function (some) { .pipe(eol) .pipe(filter(indentationFilter)) .pipe(indentation) - .pipe(filter(copyrightFilterList)) + .pipe(filter(copyrightFilter)) .pipe(copyrights) .pipe(es.through(null, function () { if (errorCount > 0) { diff --git a/package.json b/package.json index 21cdb0b4c57533e883e2bfdbf10c5a8d576e8c70..bf099ec4f9f51e0b8587d38c47753a4f4e3563d6 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,8 @@ "gulp-util": "^3.0.6", "gulp-vinyl-zip": "^1.1.0", "gulp-watch": "^4.2.4", + "gulp-tslint": "^4.3.0", + "tslint-microsoft-contrib": "^2.0.0", "innosetup-compiler": "^5.5.60", "istanbul": "^0.3.17", "jsdom-no-contextify": "^3.1.0", diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000000000000000000000000000000000000..7aad3601098a3b6e3e4f08fdc36e80e73c111bdf --- /dev/null +++ b/tslint.json @@ -0,0 +1,7 @@ +{ + "rules": { + "no-unused-expression": true, + "no-unreachable": true, + "no-duplicate-variable": true + } +} \ No newline at end of file