AndreaPontrandolfo / sheriff

A comprehensive and opinionated Typescript-first ESLint configuration.
https://www.eslint-config-sheriff.dev
MIT License
106 stars 7 forks source link

ConfigError: Config (unnamed): Unexpected key "default" found. #146

Closed nahtnam closed 3 months ago

nahtnam commented 3 months ago

Hey!

I was checking out sheriff for my project. I used the CLI and selected the ts-patch option. When running eslint . after, I get the following error:

Oops! Something went wrong! :(

ESLint: 9.5.0

ConfigError: Config (unnamed): Unexpected key "default" found.
    at rethrowConfigError (~/code/my-app/node_modules/@eslint/config-array/dist/cjs/index.cjs:302:8)
    at ~/code/my-app/node_modules/@eslint/config-array/dist/cjs/index.cjs:1097:5
    at Array.reduce (<anonymous>)
    at FlatConfigArray.getConfigWithStatus (~/code/my-app/node_modules/@eslint/config-array/dist/cjs/index.cjs:1090:43)
    at FlatConfigArray.getConfig (~/code/my-app/node_modules/@eslint/config-array/dist/cjs/index.cjs:1119:15)
    at ~/code/my-app/node_modules/eslint-ts-patch/node_modules/eslint/lib/eslint/eslint-helpers.js:346:56
    at Array.reduce (<anonymous>)
    at ~/code/my-app/node_modules/eslint-ts-patch/node_modules/eslint/lib/eslint/eslint-helpers.js:333:36
    at ~/code/my-app/node_modules/eslint-ts-patch/node_modules/eslint/lib/eslint/eslint-helpers.js:296:32
    at Object.isAppliedFilter (~/code/my-app/node_modules/@nodelib/fs.walk/out/readers/common.js:12:31)

The generated eslint config was:

import sheriff from 'eslint-config-sheriff';
import { defineFlatConfig } from 'eslint-define-config';
import type { SheriffSettings } from '@sherifforg/types';

const sheriffOptions: SheriffSettings = {
  "react": true,
  "lodash": false,
  "next": true,
  "playwright": false,
  "jest": false,
  "vitest": false
};

export default defineFlatConfig([...sheriff(sheriffOptions)]);

Any ideas on what might be going on? I've never used a flat config before

AndreaPontrandolfo commented 3 months ago

Hey @nahtnam , thanks for the report!

So, here is what is going on: i didn't lock the version of eslint-ts-patch. So when create-sheriff-config install it, it install the latest version, which is the 9.5.0. The problem is that Sheriff is currently incompatible with ESLint version 9.X.X, which is why you are seeing the error that you posted. There are 2 guardrails in place for the normal eslint.config.js to avoid this error:

  1. create-sheriff-config install a locked version, the 8.57.0
  2. Sheriff define ESlint version 8.57.0 as a peer dependency, so it should have errored out while installing 9.5.0, like in your case. Not sure if you happened to see the npm warning or not.

Anyway, for the meantime i'm gonna upload a PR that fixes this. But this is not really important anyway for 2 reasons:

  1. i'm (hopefully) gonna update Sheriff to be compatible with the latest version of ESLint.
  2. ESLint it self is soon going to support Typescript config natively. Actually there are currently 2 competing open PRs for this: https://github.com/eslint/eslint/pull/18134 and https://github.com/eslint/eslint/pull/18440. After this happens, i will remove my custom implementation.