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

Importing the plugin in a flat config breaks @eslint/config-inspector #264

Closed
bryan-hoang opened this issue Apr 18, 2024 · 1 comment · Fixed by #267
Closed

Importing the plugin in a flat config breaks @eslint/config-inspector #264

bryan-hoang opened this issue Apr 18, 2024 · 1 comment · Fixed by #267

Comments

@bryan-hoang
Copy link

Description

While trying to upgrade a project's ESLint setup to v9 with flat configs, I noticed that loading eslint-plugin-html in a flat config prevents the usage of https://github.com/eslint/config-inspector when I tried debugging configuration issues during the migration. Specifically, the inspector always crashes on startup due to Error: eslint-plugin-html error: It seems that eslint is not loaded.

So I'm forced to either comment out the plugin whenever I want to use the inspector, or remove the plugin from the flat config to avoid the issue entirely.

Setup configuration

  • ESLint version: 9.0.0
  • eslint-plugin-html version: 8.1.0
  • NodeJS version: 21.7.3
  • Operating System name and version: Ubuntu 22.04.4 LTS
  • ESLint configuration (eslint.config.js):
import html from "eslint-plugin-html";

export default [];
  • Editor name and version: N/A
  • Plugin name and version: N/A

Additional context

Here's a repository that provides a minimal reproduction of the issue: https://github.com/bryan-hoang/repro-eslint-html-config-inspector

An example of the error & full stack trace
$ npx @eslint/config-inspector
ℹ Starting ESLint config inspector at http://127.0.0.1:7777

ℹ Reading ESLint config from /home/bryan/src/localhost/eslint-html-bug-repro/eslint.config.mjs
/home/bryan/src/localhost/eslint-html-bug-repro/node_modules/eslint-plugin-html/src/index.js:90
    throw new Error(
          ^

Error: eslint-plugin-html error: It seems that eslint is not loaded.
If you think this is a bug, please file a report at https://github.com/BenoitZugmeyer/eslint-plugin-html/issues

In the report, please include *all* those informations:

* ESLint version: 9.0.0
* ESLint path: /home/bryan/src/localhost/eslint-html-bug-repro/node_modules/eslint/lib/api.js
* Plugin version: 8.1.0
* Plugin inclusion paths: /home/bryan/src/localhost/eslint-html-bug-repro/node_modules/eslint-plugin-html/src/index.js
* NodeJS version: v21.7.3
* CLI arguments: ["/home/bryan/.local/share/mise/installs/node/21.7.3/bin/node","/home/bryan/.cache/npm/_npx/37ca41379bd26461/node_modules/.bin/config-inspector"]
* Content of your lock file (package-lock.json or yarn.lock) or the output of `npm list`
* How did you run ESLint (via the command line? an editor plugin?)
* The following stack trace:
    at iterateESLintModules (/home/bryan/src/localhost/eslint-html-bug-repro/node_modules/eslint-plugin-html/src/index.js:105:7)
    at Object.<anonymous> (/home/bryan/src/localhost/eslint-html-bug-repro/node_modules/eslint-plugin-html/src/index.js:30:1)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at cjsLoader (node:internal/modules/esm/translators:366:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:315:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)



    at iterateESLintModules (/home/bryan/src/localhost/eslint-html-bug-repro/node_modules/eslint-plugin-html/src/index.js:90:11)
    at Object.<anonymous> (/home/bryan/src/localhost/eslint-html-bug-repro/node_modules/eslint-plugin-html/src/index.js:30:1)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at cjsLoader (node:internal/modules/esm/translators:366:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:315:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)

Node.js v21.7.3
BenoitZugmeyer added a commit that referenced this issue Apr 22, 2024
Before ESLint 9, the plugin needed to be imported only when actually
linting files. Tools inspecting the configuration didn't need to
import the plugin, as it declared as a plain JSON.

With ESLint 9, tools inspecting the configuration actually need to
import evaluate the configuration file wich imports the plugin. So it
has a higher chance to be evaluated outside of ESLint.

To allow such use case, don't throw an exception when the plugin is not
loaded through ESLint, but rather display a warning. The bug report
template should be enough to gather the needed information.

Fixes #264
BenoitZugmeyer added a commit that referenced this issue Apr 22, 2024
Before ESLint 9, the plugin needed to be imported only when actually
linting files. Tools inspecting the configuration didn't need to
import the plugin, as it declared as a plain JSON.

With ESLint 9, tools inspecting the configuration actually need to
import evaluate the configuration file wich imports the plugin. So it
has a higher chance to be evaluated outside of ESLint.

To allow such use case, don't throw an exception when the plugin is not
loaded through ESLint, but rather display a warning. The bug report
template should be enough to gather the needed information.

Fixes #264
BenoitZugmeyer added a commit that referenced this issue Apr 22, 2024
Before ESLint 9, the plugin needed to be imported only when actually
linting files. Tools inspecting the configuration didn't need to
import the plugin, as the configuration was declared as a plain JSON.

With ESLint 9, tools inspecting the configuration actually need to
evaluate the configuration file wich imports the plugin. So it has a
higher chance to be evaluated outside of ESLint.

To allow such use case, don't throw an exception when the plugin is not
loaded through ESLint, but rather display a warning. The bug report
template should be enough to gather the needed information.

Fixes #264
BenoitZugmeyer added a commit that referenced this issue Apr 22, 2024
Before ESLint 9, the plugin needed to be imported only when actually
linting files. Tools inspecting the configuration didn't need to
import the plugin, as the configuration was declared as a plain JSON.

With ESLint 9, tools inspecting the configuration actually need to
evaluate the configuration file wich imports the plugin. So it has a
higher chance to be evaluated outside of ESLint.

To allow such use case, don't throw an exception when the plugin is not
loaded through ESLint, but rather display a warning. The bug report
template should be enough to gather the needed information.

Fixes #264
@BenoitZugmeyer
Copy link
Owner

Thank you for the report, I'm releasing a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants