2016-09-20 2 views
2

우리 팀은 Angular 1.5. * + typescript를 사용하는 프로젝트 작업을하고 있습니다.Angular 1 프로젝트의 TSLint 구성

내 프로젝트와 같은 최상의 TSLint 구성에 대한 조언을 누군가에게 줄 수 있습니까?

공식 TS repo에서 ESLint 규칙이 설정된 TSLint config (https://github.com/Microsoft/TypeScript/blob/master/tslint.json)를 추가하고 싶습니다. https://github.com/Microsoft/TypeScript/blob/master/tslint.json

충분할까요? 어떻게 생각해?

미리 답변 해 주셔서 감사합니다.

답변

1

충분합니까? 어떻게 생각해?

개인적으로 문제가 될 때까지 스위치를 켜지 않습니다. 다행히도 나는 팀 메이트를 존중하고 사랑하게하여 사치스럽게 생각합니다.

당신은 한 장 또는 함께 갈 것을 선택할 수 있습니다 : 나는 비슷한 상황에있어 https://github.com/palantir/tslint/#configuration

0

:

{ 
    "extends": "tslint:recommended" 
} 

는 팔란 기본값을 사용합니다. 나는베이스 라인으로 tslint-microsoft-contrib을 사용했다.

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

확실히 모든 방식으로 도움이됩니다. 그러나 AngularJs TypeScript 코드의 경우 일부 규칙을 재구성하거나 해제해야합니다. 내가 함수 이름, member-ordering, no-import-side-effectno-unsafe-any의 구성을 다음과 같이 변경했다 : 당신이 AngularJS와 구성 요소를 정의하는 방법에 따라

"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, 

을 false로 노 수입 부작용을 설정하지하지 않아도됩니다. TypeScript에서 AngularJs 구성 요소를 정의하는 최선의 방법에 대한 합의를 보지 못했습니다. AngularJs에서 Angular 2+로 마이그레이션하기위한 1 단계로 나열된 것이 유감입니다.

슬프게도, AngularJs가 모범 사례와 일치하도록 사용자 지정 tslint 규칙이 누락 될 수 있습니다. 생성 된 코드에서 eslint-plugin-angular을 실행하거나 이러한 규칙을 TypeScript로 변환하는 아이디어를 가지고 놀고 있습니다. 그러나 더 좋은 해결책은 Angular 2+로 이전하고 codelyzer을 사용하는 것입니다.

관련 문제