Typescript 에 tslint 적용하기

Dev Cho·2020년 6월 6일
0

[Typescript]

목록 보기
1/2

$ npm i -g typescript

typescript 글로벌 설치 후

$ npm i -D tslint-config-prettier

devDependencies 모드로 tslint-config-prettier 설치

tslint.json

{
  "extends": ["tslint:recommend", "tslint-config-prettier"],
  "linterOptions": {
    "exclude": ["config/**/*.js", "node_modules/**/*."]
  },
  "rules": {
    "no-console": false,
    "member-access": false,
    "object-literal-sort-keys": false,
    "ordered-imports": true, // import 순서 정렬
    "interface-name": false, // interface 이름에 대해
    "strict-null-checks": false, // 엄격한 null check
    "semicolon": true, // semiclon 사용
    "trailing-comma": [true, {
      "singleline": "never",
      "multiline": {
        "objects": "always",
        "arrays": "always",
        "functions": "never",
        "typeLiterals": "ignore"
      }
    }],
    "quotemark": [true, "single"], // single quoter만 허용
    "no-trailing-whitespace": [true, "ignore-comments"] // 공백 처리
  },
  "rulesDirectory": []
}

tslint.json 을 위와 같이 작성 후 VS CODEsetting.json 에서 아래와 같이

"tslint.autoFixOnSave": true

추가 해주면 tslint.json 에서 지정한 포맷에 맞게 자동 저장 해주는 기능이 활성화 됨

예를 들어 아래와 같은 코드를 작성 후

const a: number = 3;;;;;

코드를 저장한다면 ? 아래와 같이 포맷에 맞게 알아서 변경 해주는 편리함을 느낄 수 있다.

const a: number = 3;

0개의 댓글