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

Bug: env Key Misformatted in Flat Config When Using Standard Recommended Settings #2546

Open
janhesters opened this issue Jan 25, 2025 · 0 comments
Labels

Comments

@janhesters
Copy link

janhesters commented Jan 25, 2025

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

  • Environment: Node.js, ESLint with Flat Config
  • ESLint Version: ^9
  • Unicorn Plugin Version: ^56.0.

Steps to Reproduce

  1. Set up an ESLint configuration using Flat Config.
  2. Extend the configuration with eslint-plugin-unicorn using the standard recommended settings.
  3. Add any additional rules or plugins as needed.
  4. Run ESLint and observe the error regarding the 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.

@janhesters janhesters added the bug label Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant