プログラミングマガジン

プログラミングを中心にIT技術をできるだけわかりやすくまとめます。

  • ホーム
  • TypeScript
  • 【TypeScript】「ESlint」の初期設定コマンド
 
 
     
  • サーバー言語  
    • Python
    • Ruby
    • PHP
    • SQL
  •  
  • インフラ  
       
    • AWS
    •  
    • 基本
    • Git
  • Web
       
    • Web開発
    • JavaScript
    • Vue.js
    • React
  •  
  • 設計  
       
    • 実装設計
    • DB設計
  • 問い合わせ
  

【TypeScript】「ESlint」の初期設定コマンド

12.26

  • miyabisan2
  • コメントを書く

この記事は2分で読めます

コマンド

1
npx eslint --init

ESlintをどのように使いますか?(How would you like to use ESLint?)

1
2
3
  To check syntax only(構文チェックのみ)
  To check syntax and find problems(構文チェックと問題の探索)
  To check syntax, find problems, and enforce code style(構文チェックと問題の探索と、コードスタイルの適用)

特に、なければ「To check syntax, find problems, and enforce code style」を選んでおけば良いでしょう。

プロジェクトで使っているモジュールの管理方法は?(What type of modules does your project use?)

1
2
3
JavaScript modules (import/export)
CommonJS (require/exports)
None of these

Reactを使う場合は「JavaScript modules (import/export)」を選んでおけば良いでしょう。Node.js環境とかであれば、「CommonJS (require/exports)」になるでしょう。

どのフレームワークを使ってるか(Which framework does your project use?)

1
2
3
React
Vue.js
None of these

普通に選びましょう。

TypeScriptを使ってるか?(Does your project use TypeScript? › No / Yes)

使っている場合は「Yes」で問題ないです。

コードの実行環境は?(Where does your code run?)

1
2
Browser
Node

Reactであれば、ブラウザなのでBrowserを選んでおけば良いでしょう。

プロジェクトで使うスタイルはどのように定義しますか?(How would you like to define a style for your project?)

1
2
3
Use a popular style guide(人気のスタイルガイド)
Answer questions about your style(自分で決める)
Inspect your JavaScript file(s)

無難に「Use a popular style guide」を選んでおけば良いでしょう。

どのスタイルガイドを使いますか?(Which style guide do you want to follow?)

1
2
3
4
Airbnb: https://github.com/airbnb/javascript
Standard: https://github.com/standard/standard
Google: https://github.com/google/eslint-config-google
XO: https://github.com/xojs/eslint-config-xo

現状、一番人気なのは「Airbnb」でしょう。

設定ファイルをどの形式で作成するか?(What format do you want your config file to be in?)

1
2
3
JavaScript
YAML
JSON

無難にJSONなどを選んでおけば良いでしょう。

すぐパッケージをインストールしますか?(Would you like to install them now with npm?)

はいを選ぶと以下のパッケージとeslintの設定ファイル(.eslintrc.json)が生成されます。

パッケージ

1
2
3
4
5
6
7
8
eslint-plugin-react
@typescript-eslint/eslint-plugin
eslint-config-airbnb
eslint
eslint-plugin-import
eslint-plugin-jsx-a11y
eslint-plugin-react-hooks
@typescript-eslint/parser

設定後

Strings must use singlequote.(quotes)

シングルコーテーションでないとエラーになる。pretterの整形の邪魔になるので解除しておきましょう。

1
"quotes": "off"

JSX not allowed in files with extension

拡張子系エラーが出た。ので以下のルールを追加する。

1
"react/jsx-filename-extension": [1, { "extensions": [".ts", ".tsx"] }]

その他

普通に実装するとこの辺のエラーに引っかかったので以下のような設定にしておいた方が良さそう。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  "rules": {
    "quotes": "off",
    "react/jsx-filename-extension": [1, { "extensions": [".ts", ".tsx"] }],
    "react/function-component-definition": [
      2,
      {
        "namedComponents": "arrow-function",
        "unnamedComponents": "arrow-function"
      }
    ],
    "import/no-unresolved": "off",
    "import/extensions": [".js", ".jsx", ".json", ".ts", ".tsx"],
    "trailing-comma": [
      true,
      {
        "singleline": "never",
        "multiline": {
          "objects": "always",
          "arrays": "always",
          "functions": "never",
          "typeLiterals": "ignore"
        }
      }
    ]
  }

スポンサーリンク
  • 2021 12.26
  • miyabisan2
  • コメントを書く
  • TypeScript
  • Tweets Twitter
  • このエントリーをはてなブックマークに追加
  • LINEで送る

関連記事

  1. 2020 04.19

    【TypeScript】「never型」や「void型」、「Object型」、「インデックスシグネチャ」

  2. 2022 09.24

    【TypeScript】「シングルトンクラス」を作るには

  3. 2020 04.19

    【TypeScript】「関数」、「クラス」に関する知識

  4. 2020 04.19

    【TypeScript】「エイリアス型(type)」、「interface」について

  5. 2021 05.22

    【TypeScript】「as」、「any」、「?」、「!」、「型の互換性」、「アサーション」について

  6. 2020 04.13

    【TypeScript】「変数」、「定数」、「データ型」、「型推論」、「配列」

  • コメント ( 0 )
  • トラックバック ( 0 )
  1. この記事へのコメントはありません。

  1. この記事へのトラックバックはありません。

返信をキャンセルする。

【Web開発】「Socket.IO」の基本、実装方法、…

【Node.js】「cluster」モジュールについて

RETURN TOP

著者プロフィール

エンジニア歴10年で過去に業務系、Webデザイン、インフラ系なども経験あります。現在はWeb系でフロントエンド開発中心です。

詳細なプロフィールはこちら

スポンサーリンク

カテゴリー

  • Android
  • AngularJS
  • API
  • AWS
  • C++
  • CSS
  • cursor
  • C言語
  • DDD
  • DevOps
  • Django
  • Docker
  • Figma
  • Git
  • GitLab
  • GraphQL
  • gRPC
  • Hasura
  • Java
  • JavaScript
  • Kubernetes
  • Laravel
  • linux
  • MySQL
  • Next.js
  • nginx
  • Node.js
  • NoSQL
  • Nuxt.js
  • Oracle
  • PHP
  • Python
  • React
  • Redux
  • Rspec
  • Ruby
  • Ruby on Rails
  • Sass
  • Spring Framework
  • SQL
  • TypeScript
  • Unity
  • Vue.js
  • Webサービス開発
  • Webデザイン
  • Web技術
  • インフラ
  • オブジェクト指向
  • システム開発
  • セキュリティ
  • その他
  • データベース
  • デザインパターン
  • テスト
  • ネットワーク
  • プログラミング全般
  • マイクロサービス
  • マイクロソフト系技術
  • マルチメディア
  • リファクタリング
  • 副業
  • 未分類
  • 業務知識
  • 生成AI
  • 設計
  • 関数型言語
RETURN TOP

Copyright ©  プログラミングマガジン | プライバシーポリシー