Skip to content

Commit

Permalink
Use overrides for denylist some folders
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Dec 13, 2023
1 parent 55d7e40 commit 236d9f5
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 32 deletions.
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: 0 additions & 20 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,5 @@
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignore": ["types.d.ts", "./editors/intellij"]
},
"formatter": {
"ignore": [
"configuration-schema.json"
]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noNonNullAssertion": "off"
}
}
},
"organizeImports": {
"enabled": true
}
}
7 changes: 6 additions & 1 deletion crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,12 @@ impl<'ctx, 'app> TraversalContext for TraversalOptions<'ctx, 'app> {
});

let file_features = match file_features {
Ok(file_features) => file_features,
Ok(file_features) => {
if !file_features.is_supported() {
return false;
}
file_features
}
Err(err) => {
self.miss_handler_err(err, rome_path);

Expand Down
43 changes: 38 additions & 5 deletions crates/biome_fs/src/fs/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::{
};
use biome_diagnostics::adapters::IgnoreError;
use biome_diagnostics::{adapters::IoError, DiagnosticExt, Error, Severity};
use ignore::overrides::OverrideBuilder;
use ignore::WalkBuilder;
use rayon::{scope, Scope};
use std::ffi::OsStr;
use std::fs::{DirEntry, FileType};
use std::{
env,
ffi::OsStr,
fs,
env, fs,
io::{self, ErrorKind as IoErrorKind, Read, Seek, Write},
mem,
path::{Path, PathBuf},
Expand Down Expand Up @@ -119,10 +119,31 @@ fn can_track_error(error: &ignore::Error) -> bool {
}
}

fn add_overrides<'a>(inputs_iter: impl Iterator<Item = &'a PathBuf>, walker: &mut WalkBuilder) {
for item in inputs_iter {
let mut override_builder = OverrideBuilder::new(item);
for default_ignore in DEFAULT_IGNORE_GLOBS {
// SAFETY: these are internal globs, so we have control over them
override_builder.add(default_ignore).unwrap();
}
let overrides = override_builder.build().unwrap();

// SAFETY: these are internal globs, so we have control over them
walker.overrides(overrides);
}
}

impl<'scope> TraversalScope<'scope> for OsTraversalScope<'scope> {
fn traverse_paths(&self, context: &'scope dyn TraversalContext, paths: Vec<PathBuf>) {
let mut inputs = paths.iter();
let mut walker = WalkBuilder::new(inputs.next().unwrap());
// SAFETY: absence of positional arguments should in a CLI error and should not arrive here
let first_input = inputs.next().unwrap();
let mut walker = WalkBuilder::new(first_input);
for input in inputs {
walker.add(input);
}

add_overrides(paths.iter(), &mut walker);
walker
.follow_links(true)
.git_ignore(true)
Expand Down Expand Up @@ -172,7 +193,8 @@ impl<'scope> TraversalScope<'scope> for OsTraversalScope<'scope> {

let _ = ctx.interner().intern_path(path.clone());

if file_type.is_file() {
let rome_path = RomePath::new(&path);
if file_type.is_file() && ctx.can_handle(&rome_path) {
self.scope.spawn(move |_| {
ctx.handle_file(&path);
});
Expand All @@ -198,6 +220,14 @@ impl<'scope> TraversalScope<'scope> for OsTraversalScope<'scope> {
/// detecting and parsing .ignore files
const DEFAULT_IGNORE: &[&str; 5] = &[".git", ".svn", ".hg", ".yarn", "node_modules"];

const DEFAULT_IGNORE_GLOBS: &[&str; 5] = &[
".git/**",
".svn/**",
".hg/**",
".yarn/**",
"**/node_modules/**",
];

/// Traverse a single directory
fn handle_dir<'scope>(
scope: &Scope<'scope>,
Expand All @@ -206,6 +236,9 @@ fn handle_dir<'scope>(
// The unresolved origin path in case the directory is behind a symbolic link
origin_path: Option<PathBuf>,
) {
// Paths like . or ./ should be normalized and converted to the current working directory.
// This would allow us to have always absolute paths, and make the overrides working as expected.
// TODO: remove this once . or ./ paths are normalized
if let Some(file_name) = path.file_name().and_then(OsStr::to_str) {
if DEFAULT_IGNORE.contains(&file_name) {
return;
Expand Down
13 changes: 13 additions & 0 deletions crates/biome_service/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ impl FileFeaturesResult {
pub fn support_kind_for(&self, feature: &FeatureName) -> Option<&SupportKind> {
self.features_supported.get(feature)
}

/// Check whether is file has some kind of support
pub fn is_supported(&self) -> bool {
self.features_supported
.values()
.any(|support_kind| support_kind.is_supported())
}
}

impl SupportsFeatureResult {
Expand Down Expand Up @@ -266,6 +273,10 @@ impl SupportKind {
pub const fn is_not_enabled(&self) -> bool {
matches!(self, SupportKind::FeatureNotEnabled)
}

pub const fn is_not_supported(&self) -> bool {
matches!(self, SupportKind::FileNotSupported)
}
}

#[derive(Debug, Clone, Hash, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
Expand Down Expand Up @@ -306,7 +317,9 @@ impl FeaturesBuilder {
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UpdateSettingsParams {
pub configuration: Configuration,
// @ematipico TODO: have a better data structure for this
pub vcs_base_path: Option<PathBuf>,
// @ematipico TODO: have a better data structure for this
pub gitignore_matches: Vec<String>,
}

Expand Down
4 changes: 1 addition & 3 deletions editors/intellij/src/test/testData/basic-project/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
var a = 1;


const a = 1;
21 changes: 21 additions & 0 deletions website/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "../packages/@biomejs/biome/configuration_schema.json",
"files": {
"ignore": ["**/dist/**", "**/.astro/**", "**/assets/**"]
},
"formatter": {
"ignore": ["configuration-schema.json"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noNonNullAssertion": "off"
}
}
},
"organizeImports": {
"enabled": true
}
}
4 changes: 2 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"start": "astro dev",
"format": "cargo biome-cli-dev format --write .",
"tsc": "tsc --skipLibCheck",
"check": "cargo biome-cli-dev check ./",
"check:apply": "cargo biome-cli-dev check ./ --apply-unsafe",
"check": "cargo biome-cli-dev check .",
"check:apply": "cargo biome-cli-dev check . --apply-unsafe",
"start:playground": "pnpm build:wasm-dev && pnpm start",
"build": "pnpm build:wasm && pnpm build:js",
"build:js": "astro build",
Expand Down

0 comments on commit 236d9f5

Please sign in to comment.