2016-09-20 79 views

回答

1

這樣就夠了嗎?你怎麼看?

就我個人而言,我不打開它,直到它成爲一個問題。幸運的是,我有我的隊友尊重和愛的豪華,所以他們知道我的意思是好的。

你可以選擇一個或只是去:

{ 
    "extends": "tslint:recommended" 
} 

要使用默認真知晶球:https://github.com/palantir/tslint/#configuration

0

我在一個類似的情況我。我用tslint-microsoft-contrib作爲基準。

"extends": "tslint-microsoft-contrib", 

這絕對有助於您所期望的各種方式。但是,對於AngularJs TypeScript代碼,一些規則需要重新配置或關閉。我做了以下配置更改函數名,member-orderingno-import-side-effectno-unsafe-any

"function-name": [ 
    true, 
    { 
    // allow public methods to start with $ for $onChanges 
    // and other Angular lifecycle hooks 
    "method-regex": "^[a-z$][\\w\\d]+$", 

    // otherwise unchanged 
    "private-method-regex": "^[a-z][\\w\\d]+$", 
    "protected-method-regex": "^[a-z][\\w\\d]+$", 
    "static-method-regex": "^[A-Z_\\d]+$", 
    "function-regex": "^[a-z][\\w\\d]+$" 
    } 
], 

// Variant ordering that places public statics before constructor 
// So we can place AngularJs $inject just before the constructor 
"member-ordering": [ 
    true, 
    { 
    "order": [ 
     "public-instance-field", 
     "protected-instance-field", 
     "private-instance-field", 
     "public-static-field", 
     "protected-static-field", 
     "private-static-field", 
     "constructor", 
     "public-static-method", 
     "protected-static-method", 
     "private-static-method", 
     "public-instance-method", 
     "protected-instance-method", 
     "private-instance-method" 
    ] 
    } 
], 

// angular.module(...).component(...) is a side-effect 
"no-import-side-effect": false, 

// ng.IController, among others in @types/angular, uses "any" 
// and is flagged by this rule 
"no-unsafe-any": false, 

取決於你如何定義AngularJs組件,您可能不需要設置無進口副作用爲false。對於在TypeScript中定義AngularJs組件的最佳方式,我還沒有看到任何共識,如果將它列爲從AngularJs遷移到Angular 2+的步驟1,這是令人遺憾的。

不幸的是,對於AngularJs自定義tslint規則匹配最佳實踐的可能性,這是錯過了。我正在運行生成的代碼上運行eslint-plugin-angular的想法,或將這些規則轉換爲TypeScript。但更好的解決方案可能是遷移到Angular 2+並使用 codelyzer