WebEssentials tslint 自定义规则 [英] WebEssentials tslint custom rules

查看:46
本文介绍了WebEssentials tslint 自定义规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的解决方案目录中有一个 tslint.json 文件,我正在尝试按照 https://www.npmjs.com/package/tslint

I have a tslint.json file in my solution directory and I'm trying to create a custom rule following the guidelines on https://www.npmjs.com/package/tslint

我创建了一个nonImportsRule.ts",从链接中复制了代码,并在我的 tslint.json 文件中添加了no-imports":true,但是没有采用该规则.

I have created a "nonImportsRule.ts", have copied the code from the link and have added "no-imports": true to my tslint.json file however the rule is not being picked up.

指南说需要指定一个 rulesDirectory,但我不知道应该在哪里配置?

The guide says that a rulesDirectory needs to be specified, but I have no idea where this should be configured?

此外 - 如果违反 tslint 规则,是否可以设置 Web Essentials 以破坏构建?

Also - is it possible to setup Web Essentials to break the build if tslint rules are violated?

推荐答案

我遇到了同样的问题.我想将 TSLint 扩展、tslint-microsoft-contrib 和 codelyzer 与 Web Analyzer 一起使用.这没有用.找出原因的第一步是在 server.js 中进行改编,它可以在 C:\Users\[User]\AppData\Local\Temp\WebAnalyzer1.7.75 中找到.我把TSLint函数改成了:

I had a same kind of a problem. I wanted to use the TSLint extensions, tslint-microsoft-contrib and codelyzer, together with Web Analyzer. This did not work. The first step to figure out why was to make an adaptation in server.js which can be found in C:\Users\[User]\AppData\Local\Temp\WebAnalyzer1.7.75. I changed the TSLint function into:

tslint: function (configFile, files) {
    // Try catch tslint errors 
    try {

        var tslint = require("tslint");
        var options = {
            formatter: "json",
            configuration: JSON.parse(fs.readFileSync(configFile, "utf8").trim())
        };

        var results = [];

        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            var ll = new tslint(file, fs.readFileSync(file, "utf8"), options);
            results = results.concat(JSON.parse(ll.lint().output));
        }

    } catch(error) {
        // Return tslint error to visual studio so we can get some ideas for counter measures.
        var result = JSON.parse('[{"endPosition": {"character": 0,"line": 0,"position": 0},"failure": "INSTALL ERROR","name": "/","ruleName": "INSTALL ERROR","startPosition": {"character": 0,"line": 0,"position": 0}}]');
        result[0].failure = error.message;
        return result;
    }

    return results;
},

当我运行 Web Analyzer 时,这种交替导致了 Visual Studio 错误列表中的错误反馈.应用更改后,不要忘记使用任务管理器强制创建 node.exe 的新实例.对于我的特殊情况,反馈导致在以下目录中安装以下 npm 包:

The alternation resulted in error feedback in the visual studio error list when I run the Web Analyzer. Do not forget to force a new instance of node.exe with the task manager after you have applied the alternation. The feedback leaded, for my particular situation, to the following installation of npm packages in the following directories:

包:

  • "codelyzer": "0.0.12"
  • "tslint": "^3.7.3"
  • "tslint-microsoft-contrib": "^2.0.2"
  • "打字稿":"^1.8.9"

目录:

  • C:\Users\[用户]\AppData\Local\Temp\WebAnalyzer1.7.75
  • C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE

此后,Web Analyzer 能够使用与我的 grunt 任务相同的 tslint 规则.希望更新版本的 Web Analyzer 能够更优雅地解决我的问题.

After this, Web Analyzer was able to use the same tslint rules as my grunt task. Hopefully a newer version of Web Analyzer will solve my problems more elegantly.

这篇关于WebEssentials tslint 自定义规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆