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

Upgrade to ESLint 9 #1

Open
DylanSp opened this issue Apr 27, 2024 · 0 comments
Open

Upgrade to ESLint 9 #1

DylanSp opened this issue Apr 27, 2024 · 0 comments

Comments

@DylanSp
Copy link
Owner

DylanSp commented Apr 27, 2024

Upgrade to ESLint 9, with its new flat config system. ESLint has a migration guide.

.eslintrc.cjs can be moved to eslint.config.js - a lot of the Typescript setup can be deleted, it's now handled automatically by typescript-eslint; see their migration instructions.

  • Install @eslint/js, @types/eslint, and typescript-eslint as dev dependencies.
  • Remove @typescript-eslint/parser and @typescript-eslint/eslint-plugin from package.json.

All of the plugins (react/recommended, react-hooks/recommended, react/jsx-runtime, prettier/recommended, and react-refresh) need to be upgraded to work with ESLint 9 before I can update. As of 4/27/2024, eslint-plugin-react definitely isn't - see jsx-eslint/eslint-plugin-react#3699. I haven't checked the other plugins.

The new file will probably look something like:

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintReact from "eslint-plugin-react";

export default tseslint.config(
  // replaces the ignorePatterns key
  {
    ignores: ["dist"],
  },

  eslint.configs.recommended, // sets up ESLint's recommended config,
  ...tseslint.configs.recommendedTypeChecked, // sets up typescript-eslint's requirements and it's "recommended-type-checked" config

  // config object with customizations
  {
    // new way of importing plugins
    plugins: {
      "react": eslintReact,
      // other plugins...
    },
   
    // rule customizations stay the same
    rules: {
      "react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
      "prettier/prettier": "warn",
    },
  }
);

I'm not sure if the env config, env: { browser: true, es2020: true }, is still needed; the ESLint migration guide suggests something with languageOptions.globals. This might be handled automatically by typescript-eslint - their guides don't mention setting this.

I'm also not sure what to do with the settings config:

    settings: {
      react: {
        version: "detect",
      },
    },

This ESLint blog post on the new config system suggests that putting it first in the array of config objects should work.

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

No branches or pull requests

1 participant