2017-08-15 40 views
0

我使用的角度入門套件: https://github.com/AngularClass/angular-starterTslint --fix不會自動修復,但isntead輸出的皮棉問題控制檯錯誤

,我試圖讓tslint到AUTOFIX用我所有的皮棉問題 - -fix標誌。

我運行腳本: npm run tslint --fix src/**/*.ts

它只是輸出是說我已經在tslint告知,而不是autofixing它同樣的錯誤:

控制檯輸出:

ERROR: src/app/app-routing.module.ts[10, 5]: comment must start with a space 
ERROR: src/app/app-routing.module.ts[2, 20]: Too many spaces before 'from' 

我是否缺少允許其實施更改的內容?

我的版本是:

"tslint": "^5.6.0" 
"codelyzer": "^3.1.2" 

問:我怎樣才能tslint實現自動修復到我的皮棉錯誤?

回答

0

不幸的是,並非所有的linting違規都是可自動修復的。您可以通過查找Has Fixer標籤來查看which rules are auto-fixable here

我的猜測是由comment-format rule管轄,這是不是自動可以解決的「發表評論必須以空格開始」。

我不知道哪個規則導致你的第二個錯誤,但它是最有可能也不會自動解決的。

這裏是你可以運行tslint --fix對來驗證一些違規行爲是固定的一個片段,而有些則沒有。

//no var keyword (comment does not start with space) 
var x: string = 'x'; 
console.log(x); 

// array-type 
let y: String[] = []; 
console.log(y); 

// ban-single-arg-parens 
['1', '2'].filter((arg) => { 
    console.log(arg); 
}); 

// semicolon 
let z: string = '' 
console.log(z); 

// no unused variable 
let a: string = ''; 

// trailing comma 
let list = ['1', '2', ]; 

// missing trailing comma 
let obj = [ 
    1, 
    2 
]; 

規則掉毛上述文件時包括:

"semicolon": [true, "always"], 
"trailing-comma": [true, {"multiline": "always", "singleline": "never"}], 
"array-type": [true, "array-generic"], 
"arrow-parens": [true, "ban-single-arg-parens"], 

人們很容易認爲所有空白的錯誤都會被自動可以解決的,也許他們應該。可悲的是,他們不是。

0

更新庫tslintcodelyzer到最新。

,然後使用這個命令:

tslint --fix src/**/*.ts -t verbose不使用npm run

完成後,它會顯示你的無法修復的問題,所以你必須手動修復它。

您也可以在它添加package.jsonscripts這樣的:

"lint-fix": "tslint --fix src/**/*.ts -t verbose"