diff --git a/.gitignore b/.gitignore index 16b297d50be4..3b3f9feb350b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/biome.json b/biome.json index cd66682cb39a..daa7e297b772 100644 --- a/biome.json +++ b/biome.json @@ -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 } } diff --git a/crates/biome_cli/src/execute/traverse.rs b/crates/biome_cli/src/execute/traverse.rs index b2080cd8d4b5..44ec845b35a4 100644 --- a/crates/biome_cli/src/execute/traverse.rs +++ b/crates/biome_cli/src/execute/traverse.rs @@ -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); diff --git a/crates/biome_fs/src/fs/os.rs b/crates/biome_fs/src/fs/os.rs index 11ced6e33e3c..26a114807bc8 100644 --- a/crates/biome_fs/src/fs/os.rs +++ b/crates/biome_fs/src/fs/os.rs @@ -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}, @@ -119,10 +119,31 @@ fn can_track_error(error: &ignore::Error) -> bool { } } +fn add_overrides<'a>(inputs_iter: impl Iterator, 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) { 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) @@ -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); }); @@ -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>, @@ -206,6 +236,9 @@ fn handle_dir<'scope>( // The unresolved origin path in case the directory is behind a symbolic link origin_path: Option, ) { + // 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; diff --git a/crates/biome_service/src/workspace.rs b/crates/biome_service/src/workspace.rs index 46bb0fc13856..ebabe914b0c6 100644 --- a/crates/biome_service/src/workspace.rs +++ b/crates/biome_service/src/workspace.rs @@ -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 { @@ -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)] @@ -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, + // @ematipico TODO: have a better data structure for this pub gitignore_matches: Vec, } diff --git a/editors/intellij/src/test/testData/basic-project/index.js b/editors/intellij/src/test/testData/basic-project/index.js index d8bd7624f78e..54b82a09ad54 100644 --- a/editors/intellij/src/test/testData/basic-project/index.js +++ b/editors/intellij/src/test/testData/basic-project/index.js @@ -1,3 +1 @@ -var a = 1; - - +const a = 1; diff --git a/website/biome.json b/website/biome.json new file mode 100644 index 000000000000..4017cac3ac8e --- /dev/null +++ b/website/biome.json @@ -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 + } +} diff --git a/website/package.json b/website/package.json index ca6525ce56b4..e8df026b30ed 100644 --- a/website/package.json +++ b/website/package.json @@ -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",