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

fix: don't crash when ESLint is not loaded #267

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Describe the issue precisely: what are you trying to do? what's the expected res
- eslint-plugin-html version:
- NodeJS version:
- Operating System name and version:
- ESLint configuration (.eslintrc):
- ESLint configuration (.eslintrc/eslint.config.js):

<!--
If run from an editor plugin:
Expand Down
36 changes: 2 additions & 34 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,40 +72,8 @@ function iterateESLintModules(fn) {
}

if (!found) {
let eslintPath, eslintVersion
try {
eslintPath = require.resolve("eslint")
} catch {
eslintPath = "(not found)"
}
try {
eslintVersion = require("eslint/package.json").version
} catch {
eslintVersion = "n/a"
}

const parentPaths = (module) =>
module ? [module.filename].concat(parentPaths(module.parent)) : []

throw new 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: ${eslintVersion}
* ESLint path: ${eslintPath}
* Plugin version: ${require("../package.json").version}
* Plugin inclusion paths: ${parentPaths(module).join(", ")}
* NodeJS version: ${process.version}
* CLI arguments: ${JSON.stringify(process.argv)}
* 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:
${new Error().stack.slice(10)}


`
console.warn(
`⚠ eslint-plugin-html warning: ESLint is not loaded, HTML files will fail to lint. If you don't intend to lint HTML files, you can safely ignore this warning. If you think this is a bug, please file a report at https://github.com/BenoitZugmeyer/eslint-plugin-html/issues`
)
}
}
Expand Down