Resolve the configuration file path in the commonjs style
See original GitHub issueThe version of ESLint you are using.
4.19.1
The problem you want to solve.
Assume that I have an eslint configuration file whose path is <ProjectRoot>/path/to/eslint-configuration/index.js
, and I want to use it as the following way:
In package.json
:
"eslintConfig": {
"extends": "./path/to/eslint-configuration"
}
Eslint can’t read the configuration file path and throws an error (I have simplified the paths in the error message):
Cannot read config file: /absolute/xx/<ProjectRoot>/path/to/eslint-configuration Error: EISDIR: illegal operation on a directory, read Referenced from: /absolute/xx/<ProjectRoot>/package.json
When I first want to target the eslint configuration to a file is relative to my project, my initial intuition was writing it in the commonjs
way. I hope that eslint would resolve ./path/to/eslint-configuration
to /absolute/xx/<ProjectRoot>/path/to/eslint-configuration/index.js
. But it will not actually.
It’s counterintuitive that the path needed by node application could not be resolved in the “node” way. I know I can write down the full path of which file I want to target, but there is a better way to solve it.
Your take on the correct solution to problem.
As the current strategy of how eslint resolves the configuration file is the following: https://github.com/eslint/eslint/blob/master/lib/config/config-file.js#L453-L484
So I read the source codes about how eslint resolves configuration file path. I found that the strategy is complicated due to prefixes like eslint-config-
and eslint-plugin-
. But what I want is still feasible, because abbreviated config / plugin package name is different with absolute path. Resolve the absolute path by require.resolve()
is feasible and has no impact on other places.
All I need to do is wrapping the fullPath
with require.resolve()
:
https://github.com/eslint/eslint/blob/master/lib/config/config-file.js#L457
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top GitHub Comments
Thanks for creating an issue, I think I understand the motivation now.
I have a few concerns about making this change:
./path/to/eslint-configuration
works when the config is located at./path/to/eslint-configuration/index.js
, but fails when the config is located at./path/to/eslint-configuration/index.yml
.Overall, since the benefit of this change seems fairly minor (it just saves a few keystrokes for the one-time use case of creating a config file), I’m leaning against wanting to add it. However, I’m not strongly opposed, if there are other team members who think this would be a worthwhile change.
Closing as there doesn’t seem to be interest in pursuing this at this time. Thanks!