跳转至

ESlint

JS/TS 代码格式化工具。

yarn add eslint --dev

yarn add @typescript-eslint/parser --dev
yarn add @typescript-eslint/eslint-plugin --dev

yarn add eslint-plugin-import --dev
# 已包含 TypeScript 支持
eslint --init
eslint src --ext .ts --fix

常用 .eslintrc.yml

env:
  es6: true
  # node: true
  # browser: true
parser: '@typescript-eslint/parser'
parserOptions:
  project: ./tsconfig.json
plugins:
  - '@typescript-eslint'
  - import
extends:
  # react-app
  # plugin:@typescript-eslint/recommended
  - plugin:import/errors
  - plugin:import/warnings
  - plugin:import/typescript
  - "@lightyears1998/lightyears-style"
globals:
  Atomics: readonly
  SharedArrayBuffer: readonly
rules:
  no-console:
    - off

VS Code 设置 settings.json

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "editor.formatOnSaveMode": "modifications",
  "javascript.format.enable": false,
  "typescript.format.enable": false
}

最后更新: December 10, 2020