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(cli): support nested .gitignore and better glob patterns support #1134

Merged
merged 29 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Profile-*.json
# Release artifacts
**/target
# Ignore test files that contributors could create locally
/test.*
**/test.*
# Ignore third-party files
**/node_modules
**/dist
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,29 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
#### New features

- The command `biome migrate` now updates the `$schema` if there's an outdated version.
- The CLI now supports nested `.gitignore` files during the traversal. The users don't need to do anything to avail of this feature. Contributed by @ematipico
- Fix [#709](https://github.com/biomejs/biome/issues/709), by correctly parsing allow list patterns in `.gitignore` files. Contributed by @ematipico
- Fix [#805](https://github.com/biomejs/biome/issues/805), by correctly parsing these kind of patterns. Contributed by @ematipico

- Fix [#1117](https://github.com/biomejs/biome/issues/1117) by correctly respecting the matching. Contributed by @ematipico

### Configuration

#### New features

- Users can specify git ignore patterns inside `ignore` and `include` properties, for example it's possible to **allow list** globs of files using the `!` character:

```json5
{
"files": {
"ignore": [
"node_modules/**",
"!**/dist/**" // this is now accepted and allow list files inside the `dist` folder
]
}
}
```

### Editors

#### New features
Expand Down
59 changes: 41 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ bitflags = "2.3.1"
bpaf = { version = "0.9.5", features = ["derive"] }
countme = "3.0.1"
dashmap = "5.4.0"
ignore = "0.4.20"
indexmap = "1.9.3"
insta = "1.29.0"
lazy_static = "1.4.0"
Expand All @@ -132,9 +133,9 @@ serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
smallvec = { version = "1.10.0", features = ["union", "const_new"] }
tracing = { version = "0.1.37", default-features = false, features = ["std"] }
unicode-bom = "2.0.3"
# pinning to version 1.18 to avoid multiple versions of windows-sys as dependency
tokio = { version = "~1.18.5" }
unicode-bom = "2.0.3"
tokio = { version = "~1.18.5" }
Copy link
Contributor

Choose a reason for hiding this comment

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

The spacing before = seems to be wrong

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry I don't understand what you mean



[profile.dev.package.biome_wasm]
Expand Down
23 changes: 18 additions & 5 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
{
"$schema": "./packages/@biomejs/biome/configuration_schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"enabled": true,
"useIgnoreFile": true
},
"files": {
"ignore": ["types.d.ts", "./editors/intellij"]
},
"formatter": {
"ignore": [
"configuration-schema.json"
"**/dist",
"**/.astro",
"**/assets",
"**/public",
"**/__snapshots__",
"**/editors/intellij/**",
"*.astro",
"*.mdx",
"*.md",
"*.css",
"*.scss",
"*.svg",
"*.png",
"*.yml"
]
},
"formatter": {
"ignore": ["configuration-schema.json"]
},
"linter": {
"enabled": true,
"rules": {
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ bpaf = { workspace = true, features = ["bright-color"] }
crossbeam = "0.8.1"
dashmap = { workspace = true }
hdrhistogram = { version = "7.5.0", default-features = false }
ignore = { workspace = true }
indexmap = { workspace = true }
lazy_static = { workspace = true }
rayon = "1.5.1"
Expand Down
33 changes: 21 additions & 12 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::cli_options::CliOptions;
use crate::configuration::{load_configuration, LoadedConfiguration};
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::commands::validate_configuration_diagnostics;
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_service::configuration::organize_imports::OrganizeImports;
use biome_service::configuration::{FormatterConfiguration, LinterConfiguration};
use biome_service::configuration::{
load_configuration, FormatterConfiguration, LinterConfiguration, LoadedConfiguration,
};
use biome_service::workspace::{FixFileMode, UpdateSettingsParams};
use biome_service::{Configuration, MergeWith};
use biome_service::{Configuration, ConfigurationBasePath, MergeWith};
use std::ffi::OsString;
use std::path::PathBuf;

Expand Down Expand Up @@ -54,9 +55,17 @@ pub(crate) fn check(
Some(FixFileMode::SafeAndUnsafeFixes)
};

let loaded_configuration = load_configuration(&mut session, &cli_options)?.with_file_path();
let base_path = match cli_options.config_path.as_ref() {
None => ConfigurationBasePath::default(),
Some(path) => ConfigurationBasePath::FromUser(PathBuf::from(path)),
};

loaded_configuration.check_for_errors(session.app.console, cli_options.verbose)?;
let loaded_configuration = load_configuration(&session.app.fs, base_path)?;
validate_configuration_diagnostics(
&loaded_configuration,
session.app.console,
cli_options.verbose,
)?;

let LoadedConfiguration {
configuration: mut fs_configuration,
Expand Down Expand Up @@ -92,12 +101,8 @@ pub(crate) fn check(

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
store_path_to_ignore_from_vcs(
&mut session,
&mut fs_configuration,
vcs_base_path,
&cli_options,
)?;
let (vcs_base_path, gitignore_matches) =
fs_configuration.retrieve_gitignore_matches(&session.app.fs, vcs_base_path.as_deref())?;

let stdin = if let Some(stdin_file_path) = stdin_file_path {
let console = &mut session.app.console;
Expand All @@ -112,12 +117,15 @@ pub(crate) fn check(
} else {
None
};
let vcs_enabled = fs_configuration.is_vcs_enabled();

session
.app
.workspace
.update_settings(UpdateSettingsParams {
configuration: fs_configuration,
vcs_base_path,
gitignore_matches,
})?;

execute_mode(
Expand All @@ -128,5 +136,6 @@ pub(crate) fn check(
session,
&cli_options,
paths,
vcs_enabled,
)
}
Loading
Loading