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

feat(linter): search for .oxlintrc.json when no --config is provided #4924

Conversation

DonIsaac
Copy link
Contributor

@DonIsaac DonIsaac commented Aug 15, 2024

Closes #4600

@github-actions github-actions bot added the A-cli Area - CLI label Aug 15, 2024
Copy link
Contributor Author

DonIsaac commented Aug 15, 2024

@DonIsaac DonIsaac marked this pull request as ready for review August 15, 2024 21:35
@DonIsaac DonIsaac added C-enhancement Category - New feature or request A-linter Area - Linter labels Aug 15, 2024
Copy link

codspeed-hq bot commented Aug 15, 2024

CodSpeed Performance Report

Merging #4924 will not alter performance

Comparing don/08-15-feat_linter_search_for_.oxlintrc.json_when_no_--config_is_provided (7b5eb51) with main (4081293)

Summary

✅ 29 untouched benchmarks

@rzvxa
Copy link
Contributor

rzvxa commented Aug 15, 2024

Both of our editor extensions are providing a default .eslintrc so this wouldn't work as intended in IDEs.

"oxc_language_server.configPath": {
"type": "string",
"scope": "window",
"default": ".eslintrc",
"description": "Path to ESlint configuration."
}

https://github.com/oxc-project/coc-oxc/blob/63f2682fa39c7afb39cc2d248dacb23e04545a74/package.json#L54-L59

We should follow this PR with 2 more to address this change. The coc-oxc release pipeline is a bit finicky - since I just bootstrapped it using one of my old CI actions - But anything that bumps the version and goes into the main would trigger a release.

I know you are OK with changing the VSCode one but in case you don't want to bother with the Vim(or even VSCode if you have other tasks in mind) Just let me know so I can take over this small change.

@DonIsaac
Copy link
Contributor Author

DonIsaac commented Aug 15, 2024

I'll add a PR to this stack updating the VSCode defaults, but we'll need a separate PR for the CoC plugin. If you're happy to update that repo, I'd appreciate the help :)

@DonIsaac DonIsaac force-pushed the don/08-15-feat_linter_search_for_.oxlintrc.json_when_no_--config_is_provided branch from b27f6fe to 7b5eb51 Compare August 15, 2024 22:07
@DonIsaac DonIsaac requested a review from rzvxa August 16, 2024 01:06
/// directory (in order):
///
/// - `.oxlintrc.json`
/// - `oxlintrc.json`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't understand how we can guarantee the order here, What am I missing?
If we don't search with the order in mind we can drop the (in order) part.

@@ -92,7 +92,7 @@ impl Runner for LintRunner {
let cwd = std::env::current_dir().unwrap().into_boxed_path();
let lint_options = LintOptions::default()
.with_filter(filter)
.with_config_path(basic_options.config)
.with_config_path(basic_options.config().map(Into::into))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked into the LSP, I'm working on a PR updating our LSP to take advantage of this feature. Is it possible to provide a way to resolve the path in the with_config_path instead of doing it in the basic_options?

It allows me to pass in a None value here and let this logic resolve it.

.with_config_path(Some(config_path)),

Copy link
Contributor

@rzvxa rzvxa Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe adding a dedicated setter would be better, Or even providing a function that is both public and is used in the basic_options implementation so we can share that code. Something like resolve_config_path or find_oxlint_config? What are your thoughts on it?

Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior differs from eslint, will this give a surprise? Is implicit better than explicit here?

}

let pwd = std::env::current_dir().ok()?;
for entry in std::fs::read_dir(&pwd).ok()? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the performance overhead of this :-/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change this to concat our paths and only check the fs stat of those few paths.

I'm more interested in this comment of yours:

This behavior differs from eslint, will this give a surprise? Is implicit better than explicit here?

I feel it's useful for LSP, How does it differ from eslint? Doesn't eslint use the cwd to find the config if none is provided? In your opinion doing this for the CLI is a bad diversion?

Can't we make this work with something like this: https://eslint.org/docs/latest/use/command-line-interface#--no-eslintrc

I can think of situations where people would want to omit the config flag to run the linter with the default configuration, But most of the time that's not the case. I'm not sure about the implications of this change so please share your thoughts on it.

@DonIsaac
Copy link
Contributor Author

ESLint will default to one of the various .eslintrc file names. This is equivalent behavior, but for our config file. We could also look for an .eslintrc (or other file name) if no oxlint config is found.

@Boshen
Copy link
Member

Boshen commented Aug 20, 2024

I still think we should conform to what eslint does, because all our users come from eslint.

We can merge this if we can reference this feature back to eslint.

@Boshen
Copy link
Member

Boshen commented Aug 23, 2024

Let's revisit this after we improve our config logic.

@Boshen Boshen closed this Aug 23, 2024
@Boshen Boshen deleted the don/08-15-feat_linter_search_for_.oxlintrc.json_when_no_--config_is_provided branch November 21, 2024 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area - CLI A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto load config
3 participants