Skip to content

Use ESLint's existing config lookup system to look up ESLint config #58

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

Closed
JoshuaKGoldberg opened this issue Jul 1, 2019 · 3 comments
Closed
Labels
status: aged away Not enough activity occurred on this issue in a reasonable amount of time to justify taking action. type: enhancement New feature or request

Comments

@JoshuaKGoldberg
Copy link
Member

🚀 Feature Request

Right now, if you don't specify an --eslint to an ESLint configuration file, only .eslintrc.js will be looked at. ESLint allows other formats such as JSON and YAML.

Existing Behavior

The path to look up an existing ESLint configuration file is hardcoded to .eslintrc.js.

Change Proposal

Use whatever ESLint does (or, if that's not easily doable, some similar semblance) to look up that file path.

Related: #10

@JoshuaKGoldberg JoshuaKGoldberg added type: enhancement New feature or request status: accepting prs Please, send in a PR to resolve this! ✨ labels Jul 1, 2019
@JoshuaKGoldberg JoshuaKGoldberg added this to the 1.0 Ready 🚀 milestone Jul 1, 2019
@JoshuaKGoldberg
Copy link
Member Author

In retrospect, this seems lower priority. Folks can manually pass their ESLint file path.

The investigation in #232 is a cool one but let's hold off on accepting PRs till a solution that doesn't involve rewire or __get__ is known. 😄

@JoshuaKGoldberg JoshuaKGoldberg removed this from the 1.0 Ready 🚀 milestone Oct 20, 2019
@JoshuaKGoldberg JoshuaKGoldberg added status: needs investigation Let's dig deeper into this before drawing conclusions. and removed status: accepting prs Please, send in a PR to resolve this! ✨ labels Oct 20, 2019
@jeremyyap
Copy link
Contributor

jeremyyap commented Oct 21, 2019

@JoshuaKGoldberg here's what I found while looking into #232.

It turns out the argument passed to --print-config is not the ESLint config file path, but instead the code file you want to print the effective configuration for. This is necessary due to ESLint's configuration cascading whereby different files may have different rulesets.

Since we only care about the root ESLint config file, we can pass in a file that should exist in the root folder of every project and ESLint will resolve the config file path by itself:

eslint --print-config package-lock.json

And if we want to specify a custom config file:

eslint --print-config package-lock.json --config <eslintrc file>

Finally, here is a possible method to get the reported configuration using ESLint's API

import { CLIEngine } from "eslint";
...
return new CLIEngine({}).getConfigForFile("package-lock.json");

Edit: unfortunately this won't work when generating the raw configuration

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Please, send in a PR to resolve this! ✨ and removed status: needs investigation Let's dig deeper into this before drawing conclusions. labels Oct 21, 2019
@JoshuaKGoldberg
Copy link
Member Author

Yeah, I poked around here and couldn't find a good way to extract the internal ESLint logic within the config factory. The point of this issue was that it would be good to detect any of the support ESLint configuration names; I'll file a separate issue to do specifically that manually.

@JoshuaKGoldberg JoshuaKGoldberg added status: aged away Not enough activity occurred on this issue in a reasonable amount of time to justify taking action. and removed status: accepting prs Please, send in a PR to resolve this! ✨ labels Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: aged away Not enough activity occurred on this issue in a reasonable amount of time to justify taking action. type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants