vercel / turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
https://turbo.build/repo/docs
MIT License
26k stars 1.79k forks source link

Docs: eslint v9 #7909

Open ramirezj opened 5 months ago

ramirezj commented 5 months ago

What is the improvement or update you wish to see?

Documentation on supporting users who have migrated to the new eslint.config.js config file or who want to continue to use estlintrc but run >= v9 of eslint

Aiming to take a look at this myself, but flagging in case someone has more time to spend on this or a solution already

Is there any context that might help us understand?

With the recent v9 release of eslint, it now uses flat config files by default and support for the deprecated eslintrc config file will be removed entirely in v10

Does the docs page already exist? Please link to it.

https://turbo.build/repo/docs/handbook/linting/eslint

anthonyshew commented 5 months ago

Would definitely appreciate help on this one! I just explored this a little bit and it looks like this will be a net-positive change for Turborepo users, but haven't had time to explore figuring out the new syntax.

ramirezj commented 5 months ago

Digging in between other work, FYI

ch-o-min commented 3 months ago

any change?

MickL commented 3 months ago

Is there any workaround for eslint configs like the one from Turbo that dont have a flat config yet? :)

goosewobbler commented 2 months ago

@MickL ESLint provide some tooling for this:

https://github.com/eslint/eslintrc#usage-esm https://eslint.org/docs/latest/use/configure/migration-guide https://eslint.org/blog/2024/05/eslint-configuration-migrator

ChurroC commented 1 month ago

I recently created my own solution that works pretty well. I just created a new project and just ported over the eslint in this repo: https://github.com/ChurroC/EslintV9-with-TurboPack. This works for me but it is pretty sketch currently.

controversial commented 1 month ago

The following flat config works great for me:

import turboPlugin from 'eslint-plugin-turbo';

export default {
  name: 'eslint-config-turbo (recreated flat)',

  plugins: {
    turbo: { rules: turboPlugin.rules },
  },

  rules: {
    'turbo/no-undeclared-env-vars': 'error',
  },
}
Merieli commented 1 month ago
import turboPlugin from 'eslint-plugin-turbo';

export default {
  name: 'eslint-config-turbo (recreated flat)',

  plugins: {
    turbo: { rules: turboPlugin.rules },
  },

  rules: {
    'turbo/no-undeclared-env-vars': 'error',
  },
}

I'm not sure I understood your configuration @controversial, would this export file have to be in the root of the monorepo?

controversial commented 1 month ago

@Merieli The exported object is one configuration object

A minimal standalone eslint.config.js would live at the root of the monorepo and export an array containing this configuration object:

// eslint.config.js

import turboPlugin from 'eslint-plugin-turbo';

export default [
  // ... more configuration objects ...

  {
    name: 'eslint-config-turbo (recreated flat)',
    plugins: {
      turbo: { rules: turboPlugin.rules },
    },
    rules: {
      'turbo/no-undeclared-env-vars': 'error',
    },
  },
];

You’d usually include multiple such configuration objects in the top-level array

Merieli commented 1 month ago

@controversial Okay, understand... But where you installed the dependencie? Has any repository to reproduce? I am obtain erros with this config, because my linter in files do'nt work and the script to lint throw an error as bellow:

npm error Lifecycle script `lint` failed with error:
│ npm error code 1
│ npm error path /home/..../packages/sdk
│ npm error workspace @hub/sdk@0.0.0
│ npm error location /home/.../packages/sdk
│ npm error command failed
│ npm error command sh -c eslint .

Even though eslint runs and finds errors in the files, there is something wrong with my config.

controversial commented 1 month ago

The configuration example I shared depends on having at least eslint@9 and eslint-plugin-turbo@2 installed.

I think your error is likely unrelated to eslint-plugin-turbo and therefore off topic for this issue.