Skip to content

Commit

Permalink
fix(project): correctly ignore folders
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Mar 21, 2024
1 parent 9e0a308 commit 21f01af
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### CLI

#### Bug fixes

- Fixes [#2131](https://github.com/biomejs/biome/issues/2131), where folders were incorrectly ignored when running the command `check`. Now folders are correctly ignored based on their command. Contributed by @ematipico

### Configuration

#### Bug fixes
Expand Down
11 changes: 3 additions & 8 deletions crates/biome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@ pub(crate) struct Execution {
impl Execution {
pub(crate) fn to_features(&self) -> Vec<FeatureName> {
match self.traversal_mode {
TraversalMode::Format { .. } => FeaturesBuilder::new()
.with_formatter()
.build(),
TraversalMode::Lint { ..} => FeaturesBuilder::new()
.with_linter()
.build(),
TraversalMode::Format { .. } => FeaturesBuilder::new().with_formatter().build(),
TraversalMode::Lint { .. } => FeaturesBuilder::new().with_linter().build(),
TraversalMode::Check { .. } | TraversalMode::CI { .. } => FeaturesBuilder::new()
.with_organize_imports()
.with_formatter()
.with_linter()
.build(),
TraversalMode::Migrate { .. } => vec![]

TraversalMode::Migrate { .. } => vec![],
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions crates/biome_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ pub(crate) fn process_file(ctx: &TraversalOptions, path: &Path) -> FileResult {
.workspace
.file_features(SupportsFeatureParams {
path: biome_path,
feature: FeaturesBuilder::new()
.with_formatter()
.with_linter()
.with_organize_imports()
.build(),
feature: ctx.execution.to_features(),
})
.with_file_path_and_code_and_tags(
path.display().to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/execute/process_file/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) fn check_file<'ctx>(
let mut changed = false;
tracing::info_span!("Process check", path =? workspace_file.path.display()).in_scope(
move || {
dbg!(&path);
if file_features.supports_lint() {
let lint_result = lint_with_guard(ctx, &mut workspace_file);
match lint_result {
Expand Down
8 changes: 2 additions & 6 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use biome_diagnostics::PrintGitHubDiagnostic;
use biome_diagnostics::{category, DiagnosticExt, Error, PrintDiagnostic, Resource, Severity};
use biome_fs::{BiomePath, FileSystem, PathInterner};
use biome_fs::{TraversalContext, TraversalScope};
use biome_service::workspace::{FeaturesBuilder, IsPathIgnoredParams};
use biome_service::workspace::IsPathIgnoredParams;
use biome_service::{extension_error, workspace::SupportsFeatureParams, Workspace, WorkspaceError};
use crossbeam::channel::{unbounded, Receiver, Sender};
use rustc_hash::FxHashSet;
Expand Down Expand Up @@ -713,11 +713,7 @@ impl<'ctx, 'app> TraversalContext for TraversalOptions<'ctx, 'app> {

let file_features = self.workspace.file_features(SupportsFeatureParams {
path: biome_path.clone(),
feature: FeaturesBuilder::new()
.with_linter()
.with_formatter()
.with_organize_imports()
.build(),
feature: self.execution.to_features(),
});

let file_features = match file_features {
Expand Down
49 changes: 49 additions & 0 deletions crates/biome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2797,3 +2797,52 @@ fn use_literal_keys_should_emit_correct_ast_issue_266() {
result,
));
}

#[test]
fn should_show_diagnostics_for_formatter_when_linter_ignores_folder() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let file_path = Path::new("build/file.js");
fs.insert(
file_path.into(),
r#"
value['optimizelyService'] = optimizelyService;
"#,
);

let biome_json = Path::new("biome.json");
fs.insert(
biome_json.into(),
r#"{
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"ignore": ["build/**"],
"enabled": true,
"rules": {
"recommended": true
}
}
}
"#,
);

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("check"), file_path.as_os_str().to_str().unwrap()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_show_diagnostics_for_formatter_when_linter_ignores_folder",
fs,
console,
result,
));
}
56 changes: 56 additions & 0 deletions crates/biome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3461,3 +3461,59 @@ fn format_empty_svelte_ts_files_write() {
result,
));
}

#[test]
fn should_fix_file_ignored_by_linter_inside_folder() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let file_path = Path::new("build/file.js");
fs.insert(
file_path.into(),
r#"
value['optimizelyService'] = optimizelyService;
"#,
);

let biome_json = Path::new("biome.json");
fs.insert(
biome_json.into(),
r#"{
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"ignore": ["**/build"],
"enabled": true,
"rules": {
"recommended": true
}
}
}
"#,
);

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(
[
("format"),
"--write",
file_path.as_os_str().to_str().unwrap(),
]
.as_slice(),
),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_fix_file_ignored_by_linter_inside_folder",
fs,
console,
result,
));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `biome.json`

```json
{
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"ignore": ["build/**"],
"enabled": true,
"rules": {
"recommended": true
}
}
}
```

## `build/file.js`

```js

value['optimizelyService'] = optimizelyService;

```

# Termination Message

```block
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Some errors were emitted while running checks.
```

# Emitted Messages

```block
build/file.js format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
i Formatter would have printed the following content:
1 │ -
2 │ - → value['optimizelyService']·=·optimizelyService;
3 │ - → →
1 │ + value["optimizelyService"]·=·optimizelyService;
2 │ +
```

```block
Checked 1 file in <TIME>. No fixes needed.
Found 2 errors.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `biome.json`

```json
{
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"ignore": ["**/build"],
"enabled": true,
"rules": {
"recommended": true
}
}
}
```

## `build/file.js`

```js
value["optimizelyService"] = optimizelyService;

```

# Emitted Messages

```block
Formatted 1 file in <TIME>. Fixed 1 file.
```
1 change: 1 addition & 0 deletions crates/biome_service/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl FileFeaturesResult {

/// Checks whether the file support the given `feature`
fn supports_for(&self, feature: &FeatureName) -> bool {
dbg!(&self.features_supported);
self.features_supported
.get(feature)
.map(|support_kind| matches!(support_kind, SupportKind::Supported))
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_service/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ impl WorkspaceServer {
fn is_ignored(&self, path: &Path, features: Vec<FeatureName>) -> bool {
let file_name = path.file_name().and_then(|s| s.to_str());
let ignored_by_features = {
let mut ignored = false;
let mut ignored = false;
for feature in features {
// a path is ignored if it's ignored by all features
ignored &= self.is_ignored_by_feature_config(path, feature)
ignored &= self.is_ignored_by_feature_config(path, feature)
}
ignored
};
Expand Down
4 changes: 4 additions & 0 deletions website/src/content/docs/internals/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### CLI

#### Bug fixes

- Fixes [#2131](https://github.com/biomejs/biome/issues/2131), where folders were incorrectly ignored when running the command `check`. Now folders are correctly ignored based on their command. Contributed by @ematipico

### Configuration

#### Bug fixes
Expand Down

0 comments on commit 21f01af

Please sign in to comment.