Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Next.js 向けの eslint v8 と prettier の基本設定例 #10

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

strozw
Copy link
Collaborator

@strozw strozw commented Apr 24, 2024

Next.js (v14) で ESLint (v8 & Legacy Config) と Prettier を利用する際の基本的な設定を追加しました。
※ Next.js v1 では、 ESLint v9 と Flat Config に対応していないため

pnpm create next で生成される .eslintrc.json と異なる点

.prettirerc の設定内容

  • .editorconfig と併用する事を前提とし、デフォルトの設定を利用する簡素なスタイル

@strozw strozw changed the title feat: add eslint & prettier config for next.js feat: Next.js 向けの eslint と prettier の基本設定例 Apr 24, 2024
@strozw strozw changed the title feat: Next.js 向けの eslint と prettier の基本設定例 feat: Next.js 向けの eslint v8 と prettier の基本設定例 Apr 24, 2024
@strozw strozw marked this pull request as ready for review April 30, 2024 02:03
Copy link
Member

@hayato-osh hayato-osh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

気になったので見てたらいくつか直せそうなところがあったのでレビューさせていただきました!

bases/eslint-prettier/eslint-v8-nextjs/README.md Outdated Show resolved Hide resolved
bases/eslint-prettier/eslint-v8-nextjs/README.md Outdated Show resolved Hide resolved
@strozw strozw requested a review from hayato-osh May 1, 2024 02:48
@strozw strozw self-assigned this May 7, 2024
Copy link
Collaborator

@totto2727 totto2727 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自分ならこうするかなというのを貼っておきます

warnにしているのはよほど致命的なもの以外はerrorにしたくないという個人的な趣味です

type importを一意に確定させる設定
tsconfigのverbatimModuleSyntaxと合わせるとほぼ一意に確定できるはず

  "@typescript-eslint/consistent-type-imports": [
    "warn",
    {
      fixStyle: "separate-type-imports",
      prefer: "type-imports",
    },
  ],
 'import/consistent-type-specifier-style': ['warn', 'prefer-top-level'],

インポートのソートであれこれ悩みたくなかったので、以下に全て丸投げしていました

https://github.com/lydell/eslint-plugin-simple-import-sort

    {
      files: ["*"],
      plugins: ["simple-import-sort"],
      rules: {
        "simple-import-sort/imports": "warn",
        "simple-import-sort/exports": "warn",
      },
    }

strozw and others added 2 commits May 20, 2024 17:28
Co-authored-by: YAGITA Yugo <14973783+ygkn@users.noreply.github.com>
Co-authored-by: YAGITA Yugo <14973783+ygkn@users.noreply.github.com>
@strozw
Copy link
Collaborator Author

strozw commented May 20, 2024

@totto2727

type importを一意に確定させる設定 tsconfigのverbatimModuleSyntaxと合わせるとほぼ一意に確定できるはず

  "@typescript-eslint/consistent-type-imports": [
    "warn",
    {
      fixStyle: "separate-type-imports",
      prefer: "type-imports",
    },
  ],
 'import/consistent-type-specifier-style': ['warn', 'prefer-top-level'],

上記、ちょっと気になるので、後ほど調べて導入検討します。
ありがとうございます 🙏🏼

インポートのソートであれこれ悩みたくなかったので、以下に全て丸投げしていました

https://github.com/lydell/eslint-plugin-simple-import-sort

    {
      files: ["*"],
      plugins: ["simple-import-sort"],
      rules: {
        "simple-import-sort/imports": "warn",
        "simple-import-sort/exports": "warn",
      },
    }

こちら、ありな感じはするのですが、一旦 eslint-config-nexteslint-plugin-import を採用しているという事もあるので、eslint-plugin-import のまま進めます 🙏🏼

ほかの、react 向けで、 ESLint v9 対応の際には、上記 plugin 検討しようと思います。

@strozw strozw requested a review from ygkn May 24, 2024 08:06
@strozw strozw force-pushed the feat/eslint-prettier/eslint-v8-nextjs branch from 9c8943c to 1abe4bb Compare May 27, 2024 07:42
@strozw
Copy link
Collaborator Author

strozw commented May 27, 2024

@totto2727 @ygkn

eslint-plugin-simple-import-sort の内容を再確認し、import/ordersort-imports よりも、export も含め望ましい形になることがわかったため、eslint-plugin-simple-import-sort を中心にした設定に変更しました。

#10 (comment)

また、併せて推奨されていた import typimport を分割するルールについても、モジュールがタイプか実態のあるものかを判別しやすくなることと、トランスパイル時にパーサーのパフォーマンスに良い影響が期待できることから指定するようにしました。
warnerror については、 verbatimModuleSyntax が指定された場合、TSC にエラーになるため、その点も考慮し error を指定するようにしました。

@strozw strozw requested a review from totto2727 May 27, 2024 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants