Skip to content

Commit

Permalink
chore(migrate): remove version check (#4990)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Jan 30, 2025
1 parent d76e8d3 commit b9a023e
Show file tree
Hide file tree
Showing 72 changed files with 7,453 additions and 729 deletions.
153 changes: 83 additions & 70 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,72 +1,85 @@
{
"$schema": "./packages/@biomejs/biome/configuration_schema.json",
"assist": {
"enabled": true,
"ignore": [
"./packages/@biomejs/biome/configuration_schema.json"
],
"actions": {
"source": {
"useSortedKeys": "off"
}
}
},
"css": {
"linter": {
"enabled": true
}
},
"files": {
"ignore": [
"crates/**",
"dist/**",
".astro/**",
"assets/**",
"packages/@biomejs/backend-jsonrpc/src/workspace.ts",
"public/**",
"**/__snapshots__",
"**/undefined/**",
"_fonts/**",
"packages/@biomejs/wasm-*",
"benchmark/target/**"
],
"include": [
"packages/aria-data/*.js",
"packages/@biomejs/**",
"packages/tailwindcss-config-analyzer/**",
"benchmark/**"
]
},
"formatter": {
"ignore": [
"configuration_schema.json"
]
},
"json": {
"formatter": {
"indentStyle": "space",
"lineWidth": 1
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUndeclaredDependencies": "error"
},
"style": {
"noNonNullAssertion": "off",
"useNodejsImportProtocol": "error"
},
"suspicious": {
"noVar": "on"
}
}
},
"vcs": {
"clientKind": "git",
"enabled": true,
"useIgnoreFile": true
}
"$schema": "./packages/@biomejs/biome/configuration_schema.json",
"assist": {
"enabled": true,
"ignore": ["./packages/@biomejs/biome/configuration_schema.json"],
"actions": {
"source": {
"useSortedKeys": "off"
}
}
},
"css": {
"linter": {
"enabled": true
}
},
"files": {
"includes": [
"**/packages/aria-data/*.js",
"**/packages/@biomejs/**",
"**/packages/tailwindcss-config-analyzer/**",
"**/benchmark/**",
"!**/crates/**",
"!**/dist/**",
"!**/.astro/**",
"!**/assets/**",
"!**/packages/@biomejs/backend-jsonrpc/src/workspace.ts",
"!**/public/**",
"!**/__snapshots__",
"!**/undefined/**",
"!**/_fonts/**",
"!**/packages/@biomejs/wasm-*",
"!**/benchmark/target/**"
]
},
"formatter": {
"includes": ["**", "!**/configuration_schema.json"]
},
"json": {
"formatter": {
"indentStyle": "space",
"lineWidth": 1
}
},
"linter": {
"enabled": true,
"rules": {
"style": {
"noNonNullAssertion": "off",
"useNodejsImportProtocol": "error",
"useLiteralEnumMembers": "error",
"noArguments": "error",
"noParameterAssign": "error",
"useShorthandFunctionType": "error",
"useExportType": "error",
"useDefaultParameterLast": "error",
"noCommaOperator": "error",
"useSingleVarDeclarator": "error",
"useConst": "error",
"noInferrableTypes": "error",
"useExponentiationOperator": "error",
"noUselessElse": "error",
"useSelfClosingElements": "error",
"useImportType": "error",
"useNumberNamespace": "error",
"useAsConstAssertion": "error",
"noUnusedTemplateLiteral": "error",
"useNumericLiterals": "error",
"useTemplate": "error",
"useEnumInitializers": "error"
},
"correctness": {
"noUndeclaredDependencies": "error"
},
"suspicious": {
"noVar": "on"
}
}
},
"vcs": {
"clientKind": "git",
"enabled": true,
"useIgnoreFile": true
}
}
6 changes: 1 addition & 5 deletions crates/biome_cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ impl CommandRunner for MigrateCommandPayload {
_workspace: &dyn Workspace,
project_key: ProjectKey,
) -> Result<Execution, CliDiagnostic> {
if let (Some(path), Some(directory_path)) = (
self.configuration_file_path.clone(),
self.configuration_directory_path.clone(),
) {
if let Some(path) = self.configuration_file_path.clone() {
Ok(Execution::new(TraversalMode::Migrate {
project_key,
write: self.should_write(),
configuration_file_path: path,
configuration_directory_path: directory_path,
sub_command: self.sub_command.clone(),
}))
} else {
Expand Down
42 changes: 22 additions & 20 deletions crates/biome_cli/src/execute/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use biome_deserialize::Merge;
use biome_diagnostics::Diagnostic;
use biome_diagnostics::{category, PrintDiagnostic};
use biome_formatter::ParseFormatNumberError;
use biome_fs::{BiomePath, ConfigName, FileSystemExt, OpenOptions};
use biome_fs::{BiomePath, OpenOptions};
use biome_json_formatter::context::JsonFormatOptions;
use biome_json_formatter::format_node;
use biome_json_parser::{parse_json_with_cache, JsonParserOptions};
use biome_json_syntax::{JsonFileSource, JsonRoot};
use biome_migrate::{migrate_configuration, ControlFlow};
Expand Down Expand Up @@ -38,7 +40,6 @@ pub(crate) struct MigratePayload<'a> {
pub(crate) project_key: ProjectKey,
pub(crate) write: bool,
pub(crate) configuration_file_path: Utf8PathBuf,
pub(crate) configuration_directory_path: Utf8PathBuf,
pub(crate) verbose: bool,
pub(crate) sub_command: Option<MigrateSubCommand>,
}
Expand All @@ -49,7 +50,6 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic>
project_key,
write,
configuration_file_path,
configuration_directory_path,
verbose,
sub_command,
} = migrate_payload;
Expand All @@ -69,6 +69,12 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic>
biome_config_file.read_to_string(&mut biome_config_content)?;

let biome_path = BiomePath::new(configuration_file_path.as_path());
let parse_options = match configuration_file_path.extension() {
Some("jsonc") => JsonParserOptions::default()
.with_allow_comments()
.with_allow_trailing_commas(),
_ => JsonParserOptions::default(),
};
workspace.open_file(OpenFileParams {
project_key,
path: biome_path.clone(),
Expand All @@ -77,11 +83,7 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic>
document_file_source: Some(JsonFileSource::json().into()),
persist_node_cache: false,
})?;
let parsed = parse_json_with_cache(
&biome_config_content,
&mut cache,
JsonParserOptions::default(),
);
let parsed = parse_json_with_cache(&biome_config_content, &mut cache, parse_options);

match sub_command {
Some(MigrateSubCommand::Prettier) => {
Expand Down Expand Up @@ -250,9 +252,6 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic>
}
}
None => {
let has_deprecated_configuration =
configuration_file_path.file_name() == Some("rome.json");

let mut errors = 0;
let mut tree = parsed.tree();
let mut actions = Vec::new();
Expand All @@ -261,7 +260,6 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic>
&tree,
AnalysisFilter::default(),
configuration_file_path.as_path(),
biome_configuration::VERSION.to_string(),
|signal| {
let current_diagnostic = signal.diagnostic();
if current_diagnostic.is_some() {
Expand Down Expand Up @@ -299,16 +297,20 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic>
}

let new_configuration_content = tree.to_string();
if biome_config_content != new_configuration_content || has_deprecated_configuration {
if biome_config_content != new_configuration_content {
if write {
let mut configuration_file = if has_deprecated_configuration {
let biome_file_path =
configuration_directory_path.join(ConfigName::biome_json());
fs.create_new(biome_file_path.as_path())?
let mut configuration_file = biome_config_file;
let format_options = JsonFormatOptions::default();
let formatted = format_node(format_options, tree.syntax())
.ok()
.map(|formatted| formatted.print())
.and_then(|printed| printed.ok());

if let Some(formatted) = formatted {
configuration_file.set_content(formatted.as_code().as_bytes())?;
} else {
biome_config_file
};
configuration_file.set_content(tree.to_string().as_bytes())?;
configuration_file.set_content(new_configuration_content.as_bytes())?;
}
console.log(markup!{
<Info>"The configuration "<Emphasis>{{configuration_file_path.to_string()}}</Emphasis>" has been successfully migrated."</Info>
})
Expand Down
4 changes: 0 additions & 4 deletions crates/biome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ pub enum TraversalMode {
write: bool,
/// The path to `biome.json`
configuration_file_path: Utf8PathBuf,
/// The path directory where `biome.json` is placed
configuration_directory_path: Utf8PathBuf,
sub_command: Option<MigrateSubCommand>,
},
/// This mode is enabled when running the command `biome search`
Expand Down Expand Up @@ -509,7 +507,6 @@ pub fn execute_mode(
project_key,
write,
configuration_file_path,
configuration_directory_path,
sub_command,
} = execution.traversal_mode
{
Expand All @@ -518,7 +515,6 @@ pub fn execute_mode(
project_key,
write,
configuration_file_path,
configuration_directory_path,
verbose: cli_options.verbose,
sub_command,
};
Expand Down
Loading

0 comments on commit b9a023e

Please sign in to comment.