1️⃣ Explain here what's wrong
When configuring ESLint with the Unicorn plugin, using the standard recommended settings introduces an improperly formatted env
key in the configuration. This key appears to follow the traditional .eslintrc
format instead of the expected flat config format. Consequently, ESLint throws an error stating:
Config (unnamed): Key "env": This appears to be in eslintrc format rather than flat config format.
This issue does not occur when using the flat recommended settings, which behave as intended.
2️⃣ Specify which rule is buggy here and in the title
The bug arises when using the standard eslint-plugin-unicorn
recommended configuration. Specifically, the issue is with how the recommended settings handle the env
key in the context of ESLint's flat config.
3️⃣ Add some examples where the issue appears
Example Configuration Causing the Issue:
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { FlatCompat } from "@eslint/eslintrc";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import eslintPluginUnicorn from "eslint-plugin-unicorn";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});
/** @type {import('eslint').Linter.Config[]} */
const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
// eslintPluginUnicorn.configs["flat/recommended"],
eslintPluginUnicorn.configs.recommended,
{
rules: {
"unicorn/better-regex": "warn",
},
},
eslintPluginPrettierRecommended,
];
export default eslintConfig;
Error Message:
Config (unnamed): Key "env": This appears to be in eslintrc format rather than flat config format.
Working Configuration Using Flat Recommended Settings:
Uncommenting the flat recommended settings resolves the issue:
eslintPluginUnicorn.configs["flat/recommended"],
// eslintPluginUnicorn.configs.recommended, // This line causes the issue
and using eslintPluginUnicorn.configs["flat/recommended"]
fixes it.
Additional Information
Steps to Reproduce
eslint-plugin-unicorn
using the standard recommended
settings.env
key format.Expected Behavior
Using the standard eslint-plugin-unicorn
recommended settings should correctly apply configurations in the flat config format without introducing improperly formatted keys.
Actual Behavior
Applying the standard eslint-plugin-unicorn
recommended settings introduces an env
key in the traditional .eslintrc
format, causing ESLint to throw a configuration error.
Possible Solution
Use whatever is exported via eslintPluginUnicorn.configs["flat/recommended"],
because that works.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too