fix: avoid requiring eslint package metadata#4010
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4010 +/- ##
==========================================
- Coverage 97.71% 97.69% -0.02%
==========================================
Files 137 137
Lines 10188 10192 +4
Branches 3797 3798 +1
==========================================
+ Hits 9955 9957 +2
- Misses 233 235 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a defensive fallback for environments where eslint isn’t installed (e.g., oxlint), preventing lib/util/message.js from throwing when trying to read ESLint’s package metadata.
Changes:
- Wrap
require('eslint/package.json')in atry/catchto tolerate missing ESLint installations - Switch message selection logic to depend on an optional
eslintVersionvalue
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try { | ||
| eslintVersion = require('eslint/package.json').version; // eslint-disable-line global-require | ||
| } catch (error) { | ||
| if (!error || error.code !== 'MODULE_NOT_FOUND') { |
There was a problem hiding this comment.
this seems unnecessary - the only thing that can throw here is requireing eslint/package.json
ljharb
left a comment
There was a problem hiding this comment.
This is an eslint plugin, and if something wants to support eslint plugins, it shouldn't require any changes in the eslint plugin, no matter what it's doing.
If we can't detect the eslint version, the plugin can't function properly, and its use is not supported. Perhaps oxlint can rewrite specifiers to produce the appropriate eslint package.json?
fixes oxc-project/oxc#17734 (comment)
There are scenarios when
eslintwill not be available - e.g. when using oxlint.This PR adds some safety when requiring
eslintto avoidmessage.jsthrowing an error, and preventing oxlint user from using this plugin.cc @xsjcTony