我不知道应该包含哪条规则tslint.json.谁能告诉我常见或标准用途tslint.json?
如何写tslint.json文件?
我知道重新加载Angular单页应用程序并不理想,但是有一个地方需要重新加载整个应用程序。TSLint说不建议使用重装。还有其他选择吗?
我有一些以前导下划线开头的变量名称,在更新我的tslint.json后仍然会收到此警告
tslint.json
{
"extends": "tslint:recommended",
"rules": {
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-leading-underscore"
]
},
"exclude": [
"build/**/*",
"node_modules/**/*",
"tmp/**/*"
]
}
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
谢谢你的反馈
UPDATE
我使用的是TSLint的4.5.1版本
我正在 VS Code 中开发一个 Angular 项目,使用“Prettier”插件进行代码格式化,使用 ESLint/TSLint 插件进行标准执行。
我知道这不是“错误”,但我非常喜欢干净的构建,并希望尽可能删除警告。
groupMouseDown = d => {
...
}; <--- This semicolon is the issue
Run Code Online (Sandbox Code Playgroud)
上面是 Typescript 中的一个函数,使用“胖箭头”语法,使函数内联。请注意,在该行的末尾,是一个分号。
我不是在这里开始争论分号是否应该在这里,网上有很多这样的。相反,我只需要处理它。
Prettier 被认为是一个“固执己见”的格式化者,他们在这个问题上的立场是他们认为它应该存在。这很好,但他们也拒绝添加一个不把它放在那里的选项,因此是“有意见的”部分。
另一方面,linters 认为分号不应该存在,因此他们将其标记为不必要的分号。到目前为止,我还没有找到不将此报告为警告的选项,除非我为每个案例删除它。
所以,在一天结束时,我必须解决不同意的问题,让我别无选择地忽略这一点并做我想让他们做的事情,这就是一起玩得很好。
有没有其他人反对这个?有没有办法:1)仅在这种特定情况下停止添加分号,或者... 2)停止短绒仅在这种特定情况下将其报告为警告?
我不想做的是告诉 Prettier 不要在需要的地方放置任何分号,也不想告诉 linters 忽略所有不必要的分号。
我有下面的打字稿代码:
import * as express from 'express';
import * as bodyParser from 'body-parser';
...
const app: express.Application = express();
app.use(bodyParser.json());
Run Code Online (Sandbox Code Playgroud)
在 VSCode 中,最后一行的 bodyParser 用黄色波浪线标记,表示不推荐使用 body-parser。
在 .d.ts 文件中,我看到以下内容:
/** @deprecated */
declare function bodyParser(
options?: bodyParser.OptionsJson & bodyParser.OptionsText & bodyParser.OptionsUrlencoded,
): NextHandleFunction;
declare namespace bodyParser {
...
function json(options?: OptionsJson): NextHandleFunction;
Run Code Online (Sandbox Code Playgroud)
为什么 linter 会抱怨 body-parser 函数,而我没有在我的代码中将它用作函数?我是否在 tsconfig.json 文件中遗漏了一些东西来防止这种情况发生?编译似乎没有问题。
我一直试图搜索互联网来解决这个问题但无济于事.也许你可以帮助我.我正在获得tslint'缺少空白'的警告,例如:
警告在./src/app/content/content.controller.ts [4,13]:缺少空格[5,21]:缺少空格
我想摆脱警告
这是代码的一个例子....基本上我有一个用于声明类型冒号的地方就是发生错误的地方.我不想在它之间留一个空间,所以我想让它不会让我烦恼...
export class ContentCtrl {
filters:IFilter[];
selectedFilters:IFilter[];
filterToAdd:IFilter;
/** @ngInject */
constructor(private $log:angular.ILogService,
private $timeout:any,
private toastr:any,
private filterService:FilterService) {
const self = this;
Run Code Online (Sandbox Code Playgroud)
我查看了tslint.json文件,无法弄清楚如何摆脱它.
我看到一个有前途的财产说:"typedef-whitespace"
我把它改成了以下但是,唉,无济于事:
"typedef-whitespace": [true,
{
"callSignature": "noSpace",
"catchClause": "noSpace",
"indexSignature": "noSpace",
"parameter": "noSpace"
}
],
Run Code Online (Sandbox Code Playgroud)
如何摆脱"遗漏的空白"错误?
我正在使用来自cordova的设备插件,所以我有这样的一行let model = device.model || "";会导致Cannot find name 'device'.错误.我认为使用ESLint我需要做
"eslintConfig": {
"globals": {
"device": true
}
}
但是TSLint对应的是什么?
当我尝试运行命令ng lint --fixcli 时抛出此错误:
An unhandled exception occurred: Cannot find builder "@angular-devkit/build-angular:tslint".
See "C:\Users\MOE89A~1.ZAR\AppData\Local\Temp\ng-Ijc3an\angular-errors.log" for further details.
Run Code Online (Sandbox Code Playgroud)
我的 lint 确认angular.json:
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/wepod-app/tsconfig.app.json",
"projects/wepod-app/tsconfig.spec.json",
"projects/wepod-app/e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
Run Code Online (Sandbox Code Playgroud)
我的package.json:
{
"name": "wepod-clients",
"version": "3.2.3",
"scripts": {
"ng": "ng",
"start": "node patch.js && ng serve",
"build": "node patch.js && node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng run wepod-app:app-shell:production && ng run wepod-app:auth-standalone:production",
"server": "npm run build && http-server -p …Run Code Online (Sandbox Code Playgroud) 我在Visual Studio 2013中使用Typescript开发,并始终在底部打开我的错误列表.TSLint告诉我,当我编写代码时,我的代码很乱/不正确.除了安装Web Essentials插件之外,我认为我不必做任何其他事情.
我最近安装了Visual Studio 2015,但在我的生活中,不能像在Visual Studio 2013中那样使用TSLint.我是否遗漏了一些明显的东西?
tslint ×10
typescript ×6
angular ×3
eslint ×2
javascript ×2
angular-cli ×1
body-parser ×1
prettier ×1