turbo icon indicating copy to clipboard operation
turbo copied to clipboard

Docs: eslint v9

Open ramirezj opened this issue 2 years ago • 11 comments

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

ramirezj avatar Apr 06 '24 08:04 ramirezj

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.

anthonyshew avatar Apr 10 '24 20:04 anthonyshew

Digging in between other work, FYI

ramirezj avatar Apr 12 '24 18:04 ramirezj

any change?

ch-o-min avatar Jun 11 '24 13:06 ch-o-min

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

MickL avatar Jun 11 '24 15:06 MickL

@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

goosewobbler avatar Jun 22 '24 00:06 goosewobbler

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.

ChurroC avatar Jul 29 '24 01:07 ChurroC

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',
  },
}

controversial avatar Aug 08 '24 19:08 controversial

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?

Merieli avatar Aug 08 '24 20:08 Merieli

@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

controversial avatar Aug 08 '24 20:08 controversial

@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/[email protected]
│ 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.

Merieli avatar Aug 08 '24 20:08 Merieli

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.

controversial avatar Aug 08 '24 20:08 controversial

I'm new to turborepo, should I have a single flat config file in the root dir, or a shared config that would be extended in every package like examples for the old config?

SPAHI4 avatar Oct 29 '24 14:10 SPAHI4

We still recommend having a configuration file in each package for better cache hit ratios.

anthonyshew avatar Oct 29 '24 19:10 anthonyshew

https://github.com/vercel/turborepo/blob/3d7509284256f2f12233716dede9a964a03c7c28/packages/eslint-plugin-turbo/lib/configs/recommended.ts#L13-L19

Because of the config.settings above, I did this. It works pretty well.

import turbo from 'eslint-plugin-turbo';
/** @type {import('eslint').Linter.Config} */
export default {
  plugins: {
    turbo,
  },
  rules: {
    ...turbo.configs.recommended.rules,
  },
  settings: {
    ...turbo.configs.recommended.settings,
  },
};

appano1 avatar Nov 06 '24 07:11 appano1

So.. in the end is there a working Turborepo starter with flat ESLint config that uses multiple files (as recommended by Turborepo team) instead of root global config? Or it's just not possible? I'd like to do everything properly if possible.

rinart73 avatar Nov 21 '24 15:11 rinart73

So.. in the end is there a working Turborepo starter with flat ESLint config that uses multiple files (as recommended by Turborepo team) instead of root global config? Or it's just not possible? I'd like to do everything properly if possible.

Above I had a template for flat eslint setup that uses multiple files. This was my eslint package folder: https://github.com/ChurroC/EslintV9-with-TurboPack/tree/main/packages/eslint-config.

ChurroC avatar Nov 21 '24 16:11 ChurroC

Just want to update quick:

  • I'm updating create-turbo in https://github.com/vercel/turborepo/pull/9501
  • eslint-plugin-turbo supports Flat Config in https://github.com/vercel/turborepo/pull/9426 and eslint-config-turbo supports Flat Config in https://github.com/vercel/turborepo/pull/9502
  • I'll make sure supporting READMEs and docs are updated once these are all landed.

Thanks for the patience everyone!

anthonyshew avatar Nov 22 '24 22:11 anthonyshew

https://github.com/vercel/turborepo/pull/9515 updates READMEs and docs!

Thanks, everyone!

anthonyshew avatar Nov 25 '24 20:11 anthonyshew