Open benjaminrindaroy opened 9 months ago
Hi @benjaminrindaroy
There is a FlatCompat
class provided by Eslint, which can help with issues like the one you describe. With the FlatCompat
, using "old style" Eslint configs inside a flat config is possible. It's not ideal, but for now, until all your plugins officially support flat config, it's a good workaround.
import { FlatCompat } from '@eslint/eslintrc'
const compat = new FlatCompat()
export default [
// other flat configs
...compat.config({
extends: [
'plugin:storybook/recommended',
// other extends
],
// .eslintignore is not supported with flat config, make sure to ignore also other build and test folders
ignorePatterns: ['!.storybook', 'storybook-static'],
})
]
I did not test this in your demo repo, but used this approach in a project at work, and had no issues so far.
Describe the bug
Storybook fails to read new eslint configuration.
Eslint is planning to remove the old
.eslintrc.json
config setup and going to useeslint.config.js
from version 9 on. As of version 8 it still supports current supported.eslintrc.json
in storybook. More reading on eslint page hereFor projects using storybook that would like to future-proof eslint and change over to the new config system, I wish to report issue to work on this.
Further reading on the new config setup:
Terminal error On this terminal print you can se that the disable comment to supress eslint rules gets an error because the eslint confiugration is not read from
eslint.config.js
with all its plugins (in this case@typescript-eslint
)To Reproduce
You can test this code using storybook with the new flat config system.
Also you can test this using this simple code: https://github.com/benjaminrindaroy/storybook-eslint-flat-config
Be sure to run
yarn install
after you fetch the repo. This project is a fresh install of storybook.System
Additional context
If anyone counters this, there is a workaround in order to make storybook run. But you have create a
.eslintrc.json
. Still it defeats the purpose using the new flat config.Put any plugins that the disable-comments are using. For example:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
- needs the@typescript-eslint
eslint plugin.// eslint-disable-next-line import/no-extraneous-dependencies
- needs theimport
eslint plugin// eslint-disable-next-line react-hooks/exhaustive-deps
- needs thereact
eslint plugin ...etcSo in order for my reproduce code to work for the workaround I need to create a
.eslintrc.json
with these settings:The caveat of config above is that it ignores all files. But as long as you use the flat config in vscode linter, and eslint CLI. (you can set the
.env
rule on/off by using theESLINT_USE_FLAT_CONFIG
enviroment flag). Of course you can put your rules back in the.eslintrc.json
that you use in the neweslint.config.js
.