I want to do some minor edits to core eslint rules, e.g. array-bracket-newline
, or indent
. These rules often depend on utilities inside eslint
, most commonly ast-utils
. So far, i've used a plugin, added the modified rules there, and did a require('eslint/lib/rules/utils/ast-utils')
, as eslint
is a peer-dependency anyways.
Since https://github.com/eslint/eslint/commit/24c9f2ac57efcd699ca69695c82e51ce5742df7b this is no longer possible, as an exports
directive was added to the package.json
. What is the usual method for changing behavior of core eslint rules nowadays?
eslint
as a whole seems unclean, as there are a lot of other parts, which depend on it (starting from eslint-plugins, over to vscode extensions, yarn sdks, ...). Each one would need to be changed, or some very dirty rename used, in which the fork pretends to be the original (accident waiting to happen).exports
away seems really dirty.Is there some clean way?
Edit: my current best idea is forking eslint
, removing the exports
, and then using require('eslint-fork/lib/rules/utils/ast-utils')
on the fork. This means i need an extra eslint
copy for no real reason, but it's for linting, and a bit of disk space isn't important.
It is possible to require unexported files by their full path, i.e.:
const { dirname, join } = require('path');
const astUtilsPath = join(dirname(require.resolve('eslint')), 'rules/utils/ast-utils.js');
const astUtils = require(astUtilsPath);
Note that this method relies on the main export being located in a particular package folder ('lib' in the case of eslint).