Updated doc section using the extension with a task runner

This commit is contained in:
Erich Gamma 2016-09-16 12:08:54 +02:00
Родитель 60b1b8af3b
Коммит 7725a60755
1 изменённых файлов: 29 добавлений и 38 удалений

Просмотреть файл

@ -49,55 +49,46 @@ Here is an example. Create a gulp task using `gulp-tslint` that generates a repo
with a problem matcher. In your `gulpfile.js` define a task like the one below, with a custom problem reporter: with a problem matcher. In your `gulpfile.js` define a task like the one below, with a custom problem reporter:
```js ```js
function reportFailures(failures) { 'use strict';
failures.forEach(failure => { const gulp = require('gulp');
const name = failure.name || failure.fileName; const gulp_tslint = require('gulp-tslint');
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('tslint', () => { gulp.task('tslint', () => {
const options = { summarizeFailureOutput: true }; return gulp.src(['**/*.ts', '!**/*.d.ts', '!node_modules/**'])
.pipe(gulp_tslint())
return gulp.src(all, { base: '.' }) .pipe(gulp_tslint.report());
.pipe(filter(tslintFilter))
.pipe(gulptslint.report(reportFailures, options));
}); });
``` ```
Next define a Task which runs the gulp task with a problem matcher that extracts the tslint errors into warnings. Next define a Task which runs the gulp task with a problem matcher that extracts the tslint errors into warnings.
```json ```json
{ "tasks": [
"taskName": "tslint", {
"args": [], "taskName": "tslint",
"problemMatcher": { "args": [],
"owner": "tslint", "problemMatcher": {
"fileLocation": [ "owner": "tslint",
"relative", "fileLocation": [
"${workspaceRoot}" "relative",
], "${workspaceRoot}"
"severity": "warning", ],
"pattern": { "severity": "warning",
"regexp": "(.*):(\\d+):(\\d+):(.*)$", "pattern": {
"file": 1, "regexp": "^(\\S.*)\\[(\\d+), (\\d+)\\]:\\s+(.*)$",
"line": 2, "file": 1,
"column": 3, "line": 2,
"message": 4 "column": 3,
"message": 4
}
} }
} }
} ]
``` ```
What is important is that you set the `owner` attribute to `tslint`. Then the warnings extracted by the >Notice: you must set the `owner` attribute to `tslint`. Then the warnings extracted by the problem matcher go into the same collection
problem matcher go into the same collection as the warnings produced by this extension. In this way you will not see as the warnings produced by this extension. In this way you will not see duplicates.
duplicates.
Finally, when you then run the `tslint` tasks you will see the warning Finally, when you then run the `tslint` task you will see the warning produced by the gulp task in the `Problems` panel.
produced by the gulp task in the `Problems` panel.
# Release Notes # Release Notes