我使用 Visual Studio 2013 开发 Typescript,并且总是在底部打开错误列表。TSLint可以在编写代码时告诉我代码是否凌乱/不正确。我认为我除了安装Web Essentials插件之外没有做任何其他事情。
我最近安装了Visual Studio 2015,但是无论如何都无法像在Visual Studio 2013中那样使用TSLint。我是否遗漏了一些显而易见的东西?
我使用 Visual Studio 2013 开发 Typescript,并且总是在底部打开错误列表。TSLint可以在编写代码时告诉我代码是否凌乱/不正确。我认为我除了安装Web Essentials插件之外没有做任何其他事情。
我最近安装了Visual Studio 2015,但是无论如何都无法像在Visual Studio 2013中那样使用TSLint。我是否遗漏了一些显而易见的东西?
现在最简单的方法似乎是从Visual Studio Gallery下载Mads Kristensen的Web Analyzer插件,它包括TSLint支持。
https://visualstudiogallery.msdn.microsoft.com/6edc26d4-47d8-4987-82ee-7c820d79be1d
(它是免费的)
现在您需要使用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));
});
好的,现在所有准备工作都已经完成了!现在在 Visual Studio 中打开 任务运行器资源管理器(Task Runner Explorer)。任务应该会出现在这里。
请注意,您可以告诉每个任务何时运行。您可以通过右键单击每个任务设置此选项,它将添加到 gulpfile.js
文件的第一行。
TSLint:All
任务将对所有指定文件运行 TSLint。TSLint:Newer
任务将对自上次检查后更改过的所有文件运行 TSLint。TSLint:Watch
任务将保持运行状态,并在保存文件时自动检查文件!https://github.com/mbraude/NCapsulateExtensions.TsLint
希望您或其他人知道System.Web.Helpers在哪里,这样您就可以安装它并尝试使用,或者作者接受拉取请求并发布新版本。