2016-09-20 8 views
2

私のチームはAngular 1.5。* + typescriptを使用してプロジェクトに取り組んでいます。Angular 1プロジェクトのTSLint設定

私のようなプロジェクトで最高のTSLint設定についてアドバイスをいただけますか?

TSLintの設定(https://github.com/Microsoft/TypeScript/blob/master/tslint.json)を正式なTSリポジトリとESlintルールを設定して追加します。 https://github.com/Microsoft/TypeScript/blob/master/tslint.json

十分でしょうか?どう思いますか?

ご回答いただきありがとうございます。

答えて

1

十分でしょうか?どう思いますか?

個人的に私は問題になるまで切り替えません。幸いにも、私はチームメートの仲間に尊敬と愛を持たせるために贅沢を持っています。

あなたは1つを選ぶかだけで行くことができます:私は似たような状況にいるよhttps://github.com/palantir/tslint/#configuration

0

:palantirデフォルトを使用するには

{ 
    "extends": "tslint:recommended" 
} 

。私はベースラインとしてtslint-microsoft-contribを使用しました。

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

これは間違いなくあなたが期待するすべての方法で役立ちます。ただし、AngularJs TypeScriptコードでは、一部のルールを再設定または無効にする必要があります。私はno-import-side-effectmember-ordering、関数名をするために以下の構成変更を行い、no-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を使用することです。

関連する問題