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(config): add the includes field #4899

Merged
merged 7 commits into from
Jan 25, 2025
Merged

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented Jan 15, 2025

Summary

Part of #4611
This PR adds the includes field.
This PR is not a breaking change because I didn't remove include and ignore.

I leave the removal of include and ignore to another PR.
I also started a migration rule and decided to leave it for another PR.

I noted a minor "caveat": when we replace ignore with includes we have to add an include pattern to ensure that some files got processed.
For example, the following config:

{
  "files": {
    "ignore": ["src"]
  }
}

Have to be rewritten as:

{
  "files": {
    "includes": ["**", "!src"]
  }
}

I think it is fine.

Test Plan

I replaced all occurrences of include and ignore by includes in the tests.

@github-actions github-actions bot added A-CLI Area: CLI A-Core Area: core A-Project Area: project A-Linter Area: linter A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools A-LSP Area: language server protocol L-JavaScript Language: JavaScript and super languages L-CSS Language: CSS L-JSON Language: JSON and super languages A-Diagnostic Area: diagnostocis A-Changelog Area: changelog L-HTML Language: HTML L-Grit Language: GritQL labels Jan 15, 2025
@Conaclos Conaclos changed the base branch from main to next January 15, 2025 20:51
@Conaclos Conaclos changed the title Conaclos/config includes next feat(config): add the includes field Jan 15, 2025
@Conaclos Conaclos force-pushed the conaclos/config-includes-next branch from 8848003 to 6b34864 Compare January 15, 2025 20:59
@github-actions github-actions bot removed A-Core Area: core A-Linter Area: linter A-Formatter Area: formatter A-Tooling Area: internal tools A-LSP Area: language server protocol L-CSS Language: CSS A-Diagnostic Area: diagnostocis A-Changelog Area: changelog L-HTML Language: HTML L-Grit Language: GritQL labels Jan 15, 2025
@Conaclos Conaclos force-pushed the conaclos/config-includes-next branch from 6b34864 to 53f9da6 Compare January 15, 2025 21:17
@Conaclos Conaclos force-pushed the conaclos/config-includes-next branch from 53f9da6 to d4f8b93 Compare January 16, 2025 20:14
@github-actions github-actions bot added A-Linter Area: linter A-LSP Area: language server protocol labels Jan 16, 2025
@Conaclos Conaclos marked this pull request as ready for review January 18, 2025 14:30
@Conaclos
Copy link
Member Author

Conaclos commented Jan 18, 2025

While I am testing the change, I noted some issues with our way of handling paths.

Given the following hierarchy:

.
└── src
    └── file.js

Biome will provide different paths to the glob matcher according to the command:

  • biome check . provides ., ./src, and ./src/file.js
  • biome check provides /absolute/path/, /absolute/path/src, and /absolute/path/src/file.js
  • biome check src provides src, and src/file.js
  • biome check ../../absolute/path provides ../../absolute/path, ../../absolute/path/src, and ../../absolute/path/src/file.js

This was not causing any issue with include/ignore because our glob library implicitly added ** in front of any glob.

We have to normalize the path provided on the CLI in order to solve the issue.
We should certainly normalize it against the path of the active configuration file biome.json.

I don't know how this affects our LSP.

Maybe related to the PR #4823 and the issue #4868?

@ematipico
Copy link
Member

ematipico commented Jan 21, 2025

@Conaclos

While I am testing the change, I noted some issues with our way of handling paths.

I was actually working on this PR before you mentioned that you were working on it, and I realised this, and I had already fixed the bug.

When converting the Glob from biome_configuration::Configuration to Settings, we must strip the working directory from the input path (the path that we are handling). Hence, I had created a small newtype that could hold the working directory (which is the biome.json directory, as you mentioned), and a new method that strips the working directory from input path, and then use the result against the Glob type.

We must apply this change in this PR, and once you'll do so we will have two tests that will break. You will realise that those regressions make sense because we don't apply ** before the glob, so we will need to update the test cases.

@Conaclos
Copy link
Member Author

@ematipico Thanks for the hint. Do you want to port your solution to this PR?

We must apply this change in this PR, and once you'll do so we will have two tests that will break. You will realise that those regressions make sense because we don't apply ** before the glob, so we will need to update the test cases.

I already updated the failing tests.

@ematipico
Copy link
Member

I will, thank you!

@ematipico
Copy link
Member

ematipico commented Jan 22, 2025

@Conaclos

I pushed my changes in bc3bdb7 (#4899)

Highlight of the changes:

  • I had to change the signature of CandidatePath::new to exactly match the one of globset::Candidate because it the compiler was complaining about &UtfPath8 not knowing its size at compile time.
  • I created a new type called IncludesFiles which contains two high-order functions that call the underneath CandidatePath functions, that's because we need to strip the working directory from the paths, since we don't prepend ** to our globs
  • I also left a note about the default values coming from the CLI. I believe the issue is caused by pure(Default::default()). I tried to use different approaches, but they didn't workout. Maybe it's a bug in bpaf but I didn't spend time creating a minimal reproduction

@ematipico ematipico force-pushed the conaclos/config-includes-next branch from f39271a to bc3bdb7 Compare January 22, 2025 11:38
@Conaclos
Copy link
Member Author

Conaclos commented Jan 22, 2025

@ematipico

I pushed my changes in bc3bdb7 (#4899)

Is it normal that you didn't replace all occurrences of Box<[biome_glob::Glob]> with IncludesFiles? Notably in FormatSettings, LinterSettings and AssistSettings.

I created a new type called IncludesFiles which contains two high-order functions that call the underneath CandidatePath functions, that's because we need to strip the working directory from the paths, since we don't prepend ** to our globs

Do you think we could eventually move the normalization in a higher level?
For now, it is fine. However, I wonder if we could avoid repeated normalization of a same path. Moreover, I would like eventually to pass CandidatePath instead of Utf8Path to avoid repeated conversion of Utf8Path to CandidatePath. Of course these changes should be left for a future PR (they are improvements not critical to the feature).

@ematipico
Copy link
Member

Is it normal that you didn't replace all occurrences of Box<[biome_glob::Glob]> with IncludesFiles?

I definitely missed them! Ooops

Do you think we could eventually move the normalization in a higher level?

I think so, but that's not part of this PR but the traversal/workspace.

Maybe we could strip the workspace directory from the file path inside the open_file method

@Conaclos Conaclos requested review from a team January 23, 2025 20:10
@Conaclos
Copy link
Member Author

I definitely missed them! Ooops

Fixed :)

@pacak
Copy link

pacak commented Jan 24, 2025

I tried to use different approaches, but they didn't workout. Maybe it's a bug in bpaf but I didn't spend time creating a minimal reproduction

Released 0.9.16 :)

@@ -1281,7 +1280,10 @@ fn does_not_format_ignored_files() {
let mut console = BufferConsole::default();
let mut fs = MemoryFileSystem::default();
let file_path = Utf8Path::new("biome.json");
fs.insert(file_path.into(), CONFIG_FORMATTER_IGNORED_FILES.as_bytes());
fs.insert(
Copy link
Member

Choose a reason for hiding this comment

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

q: are we no longer using the constant here to improve maintainability (switching from an ignore-based configuration to an includes-based one with a negation)?

Copy link
Member Author

@Conaclos Conaclos Jan 25, 2025

Choose a reason for hiding this comment

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

I am not sure to understand what you mean.

This function is a test, I chose to use an inline configuration because this makes it easier to understand and edit the test.
This makes the test self-contained.
I don't know why we use constants in the first place: maybe to factorize some tests?
Most of them are only used by a single test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am going to merge the PR. Please let me know if I missed something. I will fix it in a future PR if needed.

@Conaclos Conaclos force-pushed the conaclos/config-includes-next branch 2 times, most recently from fd3cd48 to 5d93da1 Compare January 25, 2025 10:29
@Conaclos
Copy link
Member Author

I updated bpaf, removed the workaround, added some documentation and did some refactoring. The PR is ready to merge.

@Conaclos Conaclos merged commit c047886 into next Jan 25, 2025
11 checks passed
@Conaclos Conaclos deleted the conaclos/config-includes-next branch January 25, 2025 10:54
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 A-LSP Area: language server protocol A-Parser Area: parser A-Project Area: project L-JavaScript Language: JavaScript and super languages L-JSON Language: JSON and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants