在Visual Studio 2015中设置TSLint

Tre*_*tVB 16 tslint visual-studio-2015

我在Visual Studio 2013中使用Typescript开发,并始终在底部打开我的错误列表.TSLint告诉我,当我编写代码时,我的代码很乱/不正确.除了安装Web Essentials插件之外,我认为我不必做任何其他事情.

我最近安装了Visual Studio 2015,但在我的生活中,不能像在Visual Studio 2013中那样使用TSLint.我是否遗漏了一些明显的东西?

小智 15

看起来现在最简单的方法是从Visual Studio Gallery下载Mads Kristensen的Web Analyzer,它包括TSLint支持

https://visualstudiogallery.msdn.microsoft.com/6edc26d4-47d8-4987-82ee-7c820d79be1d

(免费)


CBa*_*arr 10

你现在必须使用gulp任务才能实现这一目标.如果你问我这有点痛苦,但确实有效!这是我们的做法:

  1. 安装节点:https://nodejs.org
  2. 安装Gulp:http://gulpjs.com
  3. 将gulp包安装到项目根目录:
    • 在命令行中 cd C:\\path\to\project
    • npm install gulp-tslint --save-dev
    • npm install gulp-plumber --save-dev

可选的:

  • npm install gulp-newer --save-dev
  • npm install gulp-watch --save-dev

现在一切都安装好了!打开Visual Studio并gulpfile.js使用以下内容向项目根目录添加新内容:

/// <binding AfterBuild='TSLint:All' ProjectOpened='TSLint:Watch' />
//Node packages
var gulp    = require("gulp");
var plumber = require("gulp-plumber");
var tslint  = require("gulp-tslint");

//Only include these 2 packages if you've installed them
var newer   = require("gulp-newer");
var watch   = require("gulp-watch");


//Paths to include/exclude
var TYPE_SCRIPT_FILES = ["app/**/*.ts", "!app/core/Events.ts"];

//Our TSLint settings
var TYPE_SCRIPT_REPORT = tslint.report("prose", {
    emitError: false,
    reportLimit: 50
});

//The actual task to run
gulp.task("TSLint:All", function () {
    return gulp.src(TYPE_SCRIPT_FILES)
        .pipe(plumber())
        .pipe(tslint())
        .pipe(TYPE_SCRIPT_REPORT);
});


//===== ONly include the below code if needed
// File locations
var BIN = "bin";

// Listens for new (updated) typescript files and runs through TSlint
gulp.task("TSLint:Newer", [], function (done) {
    return gulp.src(TYPE_SCRIPT_FILES)
        .pipe(plumber())
        .pipe(newer(BIN))
        .pipe(tslint())
        .pipe(TYPE_SCRIPT_REPORT)
        .pipe(gulp.dest(BIN));
});

//This task runs when the project opens. When any file changes, it will be run through TSLint
gulp.task('TSLint:Watch', function () {
    return gulp.src(TYPE_SCRIPT_FILES)
        .pipe(watch(TYPE_SCRIPT_FILES))
        .pipe(plumber())
        .pipe(tslint())
        .pipe(TYPE_SCRIPT_REPORT)
        .pipe(gulp.dest(BIN));
});
Run Code Online (Sandbox Code Playgroud)

好的,现在一切都准备好了!现在在Visual Studio中打开Task Runner Explorer.任务应该出现在这里.

Visual Studio 2015任务运行器资源管理器

不是说您可以告诉每个任务何时运行.您可以通过右键单击每个任务来设置它,它只是添加到第一行gulpfile.js

Visual Studio 2015任务运行器资源管理器绑定


  • TSLint:All任务将在所有指定的文件上运行TSLint.
  • TSLint:Newer任务将对自上次检查以来已更改的所有文件运行TSLint.
  • TSLint:Watch任务将继续运行,并自动检查文件,因为它们得到保存!

  • 如果您希望在构建后在Visual Studio错误列表中显示警告,请使用"msbuild"而不是"散文",并将其称为MSBuild前/后构建任务. (4认同)