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

Docs: custom rule tutorial doesn't work with v9 #18382

Closed
1 task
Keavon opened this issue Apr 22, 2024 · 1 comment · Fixed by #18383
Closed
1 task

Docs: custom rule tutorial doesn't work with v9 #18382

Keavon opened this issue Apr 22, 2024 · 1 comment · Fixed by #18383
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly documentation Relates to ESLint's documentation

Comments

@Keavon
Copy link

Keavon commented Apr 22, 2024

Docs page(s)

https://eslint.org/docs/latest/extend/custom-rule-tutorial

What documentation issue do you want to solve?

Following the documentation, this error occurs seemingly hinting at the new ESLint v9 flat config format change. Things work when downgrading to ESLint v8 with npm install eslint@8 --save-dev.

$ npm test

> eslint-custom-rule-example@1.0.0 test
> node enforce-foo-bar.test.js

C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\eslint\lib\rule-tester\rule-tester.js:382
        throw err;
        ^

ConfigError: ESLint configuration in rule-tester is invalid: Config (unnamed): Key "parserOptions": This appears to be in eslintrc format rather than flat config format.
    at rethrowConfigError (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\config-array\api.js:230:8)
    at C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\config-array\api.js:1032:5
    at Array.reduce (<anonymous>)
    at FlatConfigArray.getConfig (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\config-array\api.js:1028:39)
    ... 2 lines matching cause stack trace ...
    at RuleTester.<anonymous> (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\eslint\lib\rule-tester\rule-tester.js:1258:33)
    at RuleTester.itDefaultHandler (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\eslint\lib\rule-tester\rule-tester.js:377:23)
    at C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\eslint\lib\rule-tester\rule-tester.js:1255:71
    at Array.forEach (<anonymous>) {
  messageTemplate: 'eslintrc-incompat',
  messageData: { key: 'parserOptions' },
  index: 6,
  [cause]: WrapperError: Key "parserOptions": This appears to be in eslintrc format rather than flat config format.
      at ObjectSchema.validate (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\object-schema\src\object-schema.js:287:23)
      at C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\object-schema\src\object-schema.js:239:18
      ... 6 lines matching cause stack trace ...
      at testValidTemplate (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\eslint\lib\rule-tester\rule-tester.js:908:28)
      at RuleTester.<anonymous> (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\eslint\lib\rule-tester\rule-tester.js:1258:33) {
    messageTemplate: 'eslintrc-incompat',
    messageData: { key: 'parserOptions' },
    [cause]: IncompatibleKeyError: This appears to be in eslintrc format rather than flat config format.
        at Object.validate (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\eslint\lib\config\flat-config-schema.js:536:19)
        at ObjectSchema.validate (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\object-schema\src\object-schema.js:285:35)
        at C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\object-schema\src\object-schema.js:239:18
        at Array.reduce (<anonymous>)
        at ObjectSchema.merge (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\object-schema\src\object-schema.js:237:24)
        at C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\config-array\api.js:1030:43
        at Array.reduce (<anonymous>)
        at FlatConfigArray.getConfig (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\@humanwhocodes\config-array\api.js:1028:39)
        at runRuleForItem (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\eslint\lib\rule-tester\rule-tester.js:793:25)
        at testValidTemplate (C:\Users\Keavon\Projects\Graphite\eslint-custom-rule-example\node_modules\eslint\lib\rule-tester\rule-tester.js:908:28) {
      messageTemplate: 'eslintrc-incompat',
      messageData: { key: 'parserOptions' }
    }
  }
}

Node.js v18.12.1

What do you think is the correct solution?

I'm not familiar with how the flat format change affects custom rules, and I'm stuck here. Someone knowledgeable should probably make the necessary changes to publish the correct way of making custom rules in this tutorial.

Participation

  • I am willing to submit a pull request for this change.

Additional comments

No response

@aladdin-add
Copy link
Member

@Keavon thanks for the report! I've made a fix: #18383

@aladdin-add aladdin-add added bug ESLint is working incorrectly accepted There is consensus among the team that this change meets the criteria for inclusion labels Apr 23, 2024
mdjermanovic pushed a commit that referenced this issue Apr 23, 2024
* docs: update rule tester options in custom-rule-tutorial

Fixes #18382

* chore: update examples

* chore: update more places to eslint v9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly documentation Relates to ESLint's documentation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants