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

refactor: initial project layout #4846

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 24 additions & 24 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ biome_yaml_parser = { version = "0.0.1", path = "./crates/biome_yaml_
biome_yaml_syntax = { version = "0.0.1", path = "./crates/biome_yaml_syntax" }

biome_markup = { version = "0.5.7", path = "./crates/biome_markup" }
biome_package = { version = "0.5.7", path = "./crates/biome_package" }
biome_parser = { version = "0.5.7", path = "./crates/biome_parser" }
biome_project = { version = "0.5.7", path = "./crates/biome_project" }
biome_rowan = { version = "0.5.7", path = "./crates/biome_rowan" }
biome_string_case = { version = "0.5.7", path = "./crates/biome_string_case" }
biome_suppression = { version = "0.5.7", path = "./crates/biome_suppression" }
Expand Down
20 changes: 0 additions & 20 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,20 +635,6 @@ pub(crate) fn validate_configuration_diagnostics(
Ok(())
}

fn resolve_manifest(fs: &dyn FileSystem) -> Result<Option<(BiomePath, String)>, WorkspaceError> {
let result = fs.auto_search(
&fs.working_directory().unwrap_or_default(),
&["package.json"],
false,
)?;

if let Some(result) = result {
return Ok(Some((BiomePath::new(result.file_path), result.content)));
}

Ok(None)
}

fn get_files_to_process_with_cli_options(
since: Option<&str>,
changed: bool,
Expand Down Expand Up @@ -774,7 +760,6 @@ pub(crate) trait CommandRunner: Sized {
/// - Configure the VCS integration
/// - Computes the paths to traverse/handle. This changes based on the VCS arguments that were passed.
/// - Register a project folder using the working directory.
/// - Resolves the closets manifest AKA `package.json` and registers it.
/// - Updates the settings that belong to the project registered
fn configure_workspace(
&mut self,
Expand Down Expand Up @@ -807,11 +792,6 @@ pub(crate) trait CommandRunner: Sized {
open_uninitialized: true,
})?;

let manifest_data = resolve_manifest(fs)?;

if let Some((path, content)) = manifest_data {
workspace.set_manifest_for_project((project_key, path, content).into())?;
}
workspace.update_settings(UpdateSettingsParams {
project_key,
workspace_directory: configuration_path.map(BiomePath::from),
Expand Down
158 changes: 157 additions & 1 deletion crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::configs::{
};
use crate::snap_test::{assert_file_contents, markup_to_string, SnapshotPayload};
use crate::{
assert_cli_snapshot, run_cli, run_cli_with_dyn_fs, FORMATTED, LINT_ERROR, PARSE_ERROR,
assert_cli_snapshot, run_cli, run_cli_with_dyn_fs, run_cli_with_server_workspace, FORMATTED,
LINT_ERROR, PARSE_ERROR,
};
use biome_console::{markup, BufferConsole, LogLevel, MarkupBuf};
use biome_fs::{ErrorEntry, FileSystemExt, MemoryFileSystem, OsFileSystem};
Expand Down Expand Up @@ -3841,3 +3842,158 @@ fn linter_shows_the_default_severity_of_rule_on() {
result,
));
}

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

fs.insert(
Utf8Path::new("biome.json").into(),
r#"{
"linter": {
"rules": {
"correctness": {
"noUndeclaredDependencies": "on"
}
}
}
}"#
.as_bytes(),
);

fs.insert(
Utf8Path::new("frontend/package.json").into(),
r#"{
"dependencies": {
"react": "19.0.0"
}
}"#
.as_bytes(),
);

let file = Utf8Path::new("frontend/file1.js");
fs.insert(file.into(), r#"import 'react-dom'"#.as_bytes());
let (fs, result) = run_cli_with_server_workspace(
fs,
&mut console,
Args::from(["lint", file.as_str()].as_slice()),
);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"linter_finds_package_json_for_no_undeclared_dependencies",
fs,
console,
result,
));
}

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

fs.insert(
Utf8Path::new("biome.json").into(),
r#"{
"linter": {
"rules": {
"correctness": {
"noUndeclaredDependencies": "on"
}
}
}
}"#
.as_bytes(),
);

fs.insert(
Utf8Path::new("package.json").into(),
r#"{
"dependencies": {
"react-dom": "19.0.0"
}
}"#
.as_bytes(),
);

fs.insert(
Utf8Path::new("frontend/package.json").into(),
r#"{
"dependencies": {
"react": "19.0.0"
}
}"#
.as_bytes(),
);

let file = Utf8Path::new("frontend/file1.js");
fs.insert(file.into(), r#"import 'react-dom'"#.as_bytes());
let (fs, result) = run_cli_with_server_workspace(
fs,
&mut console,
Args::from(["lint", file.as_str()].as_slice()),
);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"linter_finds_nested_package_json_for_no_undeclared_dependencies",
fs,
console,
result,
));
}

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

fs.insert(
Utf8Path::new("biome.json").into(),
r#"{
"linter": {
"rules": {
"correctness": {
"noUndeclaredDependencies": "on"
}
}
}
}"#
.as_bytes(),
);

fs.insert(
Utf8Path::new("package.json").into(),
r#"{
"dependencies": {
"react": "19.0.0"
}
}"#
.as_bytes(),
);

fs.insert(
Utf8Path::new("frontend/package.json").into(),
r#"{
"dependencies": {
"react-dom": "19.0.0"
}
}"#
.as_bytes(),
);

let file = Utf8Path::new("frontend/file1.js");
fs.insert(file.into(), r#"import 'react-dom'"#.as_bytes());
let (fs, result) = run_cli_with_server_workspace(
fs,
&mut console,
Args::from(["lint", file.as_str()].as_slice()),
);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"linter_finds_nested_package_json_for_no_undeclared_dependencies_inversed",
fs,
console,
result,
));
}
37 changes: 37 additions & 0 deletions crates/biome_cli/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,40 @@ pub(crate) fn run_cli_with_dyn_fs(
}
}
}

/// Create an [App] instance using the provided [FileSystem] and [Console]
/// instance, and using an in-process server instance of the workspace
pub(crate) fn run_cli_with_server_workspace(
fs: MemoryFileSystem,
console: &mut dyn Console,
args: bpaf::Args,
) -> (MemoryFileSystem, Result<(), CliDiagnostic>) {
use biome_service::{workspace, WorkspaceRef};

let files = fs.files.clone();

let workspace = workspace::server(Box::new(fs));
let app = App::new(console, WorkspaceRef::Owned(workspace));

let mut session = CliSession { app };
let command = biome_command().run_inner(args);
let result = match command {
Ok(command) => session.run(command),
Err(failure) => {
if let ParseFailure::Stdout(help, _) = &failure {
let console = &mut session.app.console;
console.log(markup! {{help.to_string()}});
Ok(())
} else {
Err(CliDiagnostic::parse_error_bpaf(failure))
}
}
};

// This is a little bit of a workaround to allow us to easily create
// a snapshot of the files even though the original file system was
// consumed by the workspace.
let fs = MemoryFileSystem::from_files(files);

(fs, result)
}
Loading
Loading