nuxt / eslint

Collection of ESLint-related packages for Nuxt
https://eslint.nuxt.com
MIT License
514 stars 65 forks source link

Several built-in Nuxt globals are not defined in ESLint config, causing linter to error in JS files #461

Open adamreisnz opened 2 days ago

adamreisnz commented 2 days ago

Environment

Package

None

Reproduction

https://github.com/adamreisnz/nuxt-eslint-reproduction/tree/issue-461

Describe the bug

Several built-in Nuxt globals are showing up as undefined, despite using the Nuxt ESLint module. For example, check the files:

nuxt.config.ts --> defineNuxtConfig is marked by ESLint as not defined server/test.js --> defineEventHandler and readBody are marked by ESLint as not defined

This list is probably non-exhaustive, it's just the methods I've used so far.

Additional context

This is with a brand new Nuxt app with module enabled, and some additional globals

Logs

No response

antfu commented 2 days ago

@adamreisnz Why would you add your own @eslint/js and eslint-plugin-vue configs to override Nuxt's configs?

https://github.com/adamreisnz/nuxt-eslint-reproduction/blob/a32edf5fd06da40dc9cc3b0f8b7fc3b050578cbc/eslint.config.mjs#L6-L7

adamreisnz commented 2 days ago

Why does that matter for this problem?

I don't know what base settings Nuxt uses, and I want to make sure that the base Vue settings that I need are included.

This shouldn't affect global as they don't get overwritten.

On Sat, 29 Jun 2024, 13:03 Anthony Fu, @.***> wrote:

@adamreisnz https://github.com/adamreisnz Why would you add your own @eslint/js and eslint-plugin-vue configs to override Nuxt's configs?

https://github.com/adamreisnz/nuxt-eslint-reproduction/blob/a32edf5fd06da40dc9cc3b0f8b7fc3b050578cbc/eslint.config.mjs#L6-L7

— Reply to this email directly, view it on GitHub https://github.com/nuxt/eslint/issues/461#issuecomment-2197807277, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADXYQXZTLQQISOX3APSW2DZJYBXJAVCNFSM6AAAAABKCSJCCGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJXHAYDOMRXG4 . You are receiving this because you were mentioned.Message ID: @.***>

dsvgl commented 2 days ago

I don't know what base settings Nuxt uses, and I want to make sure that the base Vue settings that I need are included.

Use the config inspector to see what is being loaded. Or check the source-code.

adamreisnz commented 16 hours ago

I have removed the extra configuration from the eslint.config.mjs file to avoid discussions about it detracting from the problem at hand.

Methods calls like defineEventHandler and readBody are still flagged as not defined in .js files.

The error goes away in the .ts file, because in your config, no-undef has been disabled fully for TS files (see https://github.com/nuxt/eslint/issues/452)