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(restricted_glob): negated globs #4377

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

Conaclos
Copy link
Member

Summary

In the import revamping RFC, I proposed that each group be represented by a special identifier or a glob.
For example in the following list we have two groups:

{
  groups: [
    "@myCompany/**"
    "@*/**"
  ]
}

This will place all imports starting with @myCompany/ before all other scoped imports.
Unfortunately, as noted by a comment in the RFC, this doesn't allow doing the reverse, i.e. placing first all coped imports (except the ones starting with @myCompany/).
At the time, I thought about a recursive approach to solve this limitation.
However, this looks complicated and might even produce unwanted or confusing results for users.
I think we should keep a simple approach where we stop as soon as a group matches.
So to solve the previous limitation, I think we could allow a group to be defined by a list of globs.
We could allow the inclusion of negated globs in this list, which would act as an exception (similar to what .gitignore does).
Then we could write:

{
  groups: [
    ["@*/**", "!@myCompany/**"],
    "@myCompany/**"
  ]
}

This PR adds negated globs to restricted globs and a method matches_with_exceptions to match against a list of globs where negated globs are treated as exceptions (.gitignore-like negated globs).

Test Plan

I added some unit tests.

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Oct 24, 2024
@Conaclos Conaclos force-pushed the conaclos/restricted-glob-negation branch 3 times, most recently from b570950 to b82307f Compare October 24, 2024 21:39
Copy link

codspeed-hq bot commented Oct 24, 2024

CodSpeed Performance Report

Merging #4377 will not alter performance

Comparing conaclos/restricted-glob-negation (c2dace0) with main (92879ae)

Summary

✅ 101 untouched benchmarks

crates/biome_js_analyze/src/utils/restricted_glob.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/utils/restricted_glob.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/utils/restricted_glob.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/utils/restricted_glob.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/utils/restricted_glob.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/utils/restricted_glob.rs Outdated Show resolved Hide resolved
crates/biome_js_analyze/src/utils/restricted_glob.rs Outdated Show resolved Hide resolved
@Conaclos Conaclos force-pushed the conaclos/restricted-glob-negation branch from fbef9fd to c2dace0 Compare October 25, 2024 11:04
@Conaclos Conaclos merged commit 28a2a6c into main Oct 25, 2024
12 checks passed
@Conaclos Conaclos deleted the conaclos/restricted-glob-negation branch October 25, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants