3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ESLintで禁止構文を設定する

Last updated at Posted at 2020-04-01

はじめに

eslintで禁止構文を設定することで、CIでeslintを実行することで自動的に禁止構文を検出できるようにする

設定例

なにを禁止するかは個人や開発チームの方針などによっても変わってくることもあるはずなので、これは例です

.eslintrc.json
{
  "rules": {
    "no-restricted-syntax": [
      "error",
      "TSEnumDeclaration",
      "TSInterfaceDeclaration",
      "ForInStatement",
      "ForOfStatement",
      "LabeledStatement",
      "WithStatement",
      "VariableDeclaration[kind='let']"
    ]
  }
}

TSEnumDeclaration

enum使わなくてもとunion typeで足りるため
https://www.kabuku.co.jp/developers/good-bye-typescript-enum

TSInterfaceDeclaration

typescriptの型定義を基本的にType aliasで統一する方針にしてるため

ForInStatement, ForOfStatement, LabeledStatement, WithStatement

を参考にした

VariableDeclaration[kind='let']

ES2015から変数定義は基本的にはconstが推奨されて、letを使う機会はほぼないため

禁止したい構文がある場合の構文の名前の調べ方

でbabelの型定義がみれる

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?