← All tasks
javascripteslint/eslintrc #125Not a task: already works

Bug: `FlatCompat.config` doesn't work with `overrides`

envgap__eslint__eslintrc-125

01 / FAILURE SIGNATURE

As reported upstream

'no-undef': 'error',
Not a benchmark task.
  • The project already builds and runs before the fix, so there is nothing to repair.

02 / ENVIRONMENT RECIPE

Base commit
67454216a9dc4ecb850fd80d67ae39cf5799986d
Manifest
package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

eslint/eslintrc #125 · read the original issue
## Step to reproduce



- `eslint`: `8.46.0`

- `@eslint/eslintrc`: `2.1.1`



You can open & run: https://runkit.com/ayc0/64cac9cf2e21ef0008bee16d



<details><summary>This runkit gets lost / deleted / edited, here is the raw code</summary>



```js

const code = 'console.log(process.pwd())';



const run = async (ESLint, config, filePath) => {

    const eslint = new ESLint(config);

    

    // 2. Lint text.

    const results = await eslint.lintText(code, { filePath });



    // 3. Format the results.

    const formatter = await eslint.loadFormatter("stylish");

    const resultText = formatter.format(results);



    // 4. Output it.

    console.log(resultText);

}



const baseConfig = {

    rules: {

      'no-undef': 'error',

    },

    overrides: [{

        files: ['node.js'],

        env: {

            node: true

        },

    }]

}



const { ESLint } = require("eslint@8.46.0");



const config = { useEslintrc: false, overrideConfig: baseConfig };



await run(ESLint, config, 'classic/node.js'); // should be okay ✅

await run(ESLint, config, 'classic/not-node.js'); // should have an error ✅

// Check output



const { FlatCompat } = require("@eslint/eslintrc@2.1.1");

const { FlatESLint } = require("eslint@8.46.0/use-at-your-own-risk");





const compat = new FlatCompat({

    baseDirectory: __dirname

});

const flatConfig = compat.config(baseConfig);



console.log(flatConfig);



await run(FlatESLint, { overrideConfigFile: true, overrideConfig: flatConfig }, 'flat/node.js'); // should be okay ✅

await run(FlatESLint, { overrideConfigFile: true, overrideConfig: flatConfig }, 'flat/not-node.js'); // should have an error ❌

// Check output

```



</details>



## Explanation of the bug



If we have this config:



```js

const legacyConfig = {

    rules: {

      'no-undef': 'error',

    },

    overrides: [{

        files: ['node.js'],

        env: {

            node: true

        },

    }]

}

```



With the legacy config, using `process.cwd()` shouldn't be allowed in a file like `no-node.js`, but allowed in `node.js`



<img width="989" alt="image" src="https://github.com/eslint/eslintrc/assets/22725671/c159da8d-9de0-491e-aba4-b5ebebb961f4">





And if we use `FlatCompat` to port it to the new structure, we should have the same result.



But when we do:



```js

const compat = new FlatCompat({

    baseDirectory: __dirname

});

const flatConfig = compat.config(legacyConfig);

```



We can see that the `files` and envs' config aren't merged together, instead we have 1 row for the `env`, and another one empty one for the overrides:



<img width="890" alt="image" src="https://github.com/eslint/eslintrc/assets/22725671/1a241180-b5ab-41ed-a536-e6168b720217">



And surely, when we run eslint with this config, no errors are reported (see the `""` x2):



<img width="1032" alt="image" src="https://github.com/eslint/eslintrc/assets/22725671/c58bcc6f-157a-40e6-ba17-3b0c43c9557a">

Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]