Skip to content

Commit

Permalink
chore: additional fixes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Jan 29, 2025
1 parent 9c82a18 commit ad4da5c
Show file tree
Hide file tree
Showing 22 changed files with 5,980 additions and 418 deletions.
5 changes: 2 additions & 3 deletions crates/biome_cli/src/execute/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,10 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic>
if write {
let mut configuration_file = biome_config_file;
let format_options = JsonFormatOptions::default();
let formatted = format_node(format_options, &tree.syntax())
let formatted = format_node(format_options, tree.syntax())
.ok()
.map(|formatted| formatted.print())
.and_then(|printed| printed.ok())
.map(|formatted| formatted);
.and_then(|printed| printed.ok());

if let Some(formatted) = formatted {
configuration_file.set_content(formatted.as_code().as_bytes())?;
Expand Down
160 changes: 160 additions & 0 deletions crates/biome_cli/tests/cases/migrate_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//! Migrations for Biome v2
use crate::run_cli;
use crate::snap_test::{assert_cli_snapshot, SnapshotPayload};
use biome_console::BufferConsole;
use biome_fs::MemoryFileSystem;
use bpaf::Args;
use camino::Utf8Path;

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

let configuration_path = Utf8Path::new("biome.json");
fs.insert(
configuration_path.into(),
r#"{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"files": {
"ignore": [
"**/dist",
"**/tmp",
"**/fixtures",
"packages/knip/package.json",
"packages/knip/vendor/bash-parser/index.js",
"packages/docs/.astro"
]
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedVariables": "error",
"noUnusedImports": "error"
},
"complexity": {
"useLiteralKeys": "off"
},
"nursery": {
"noRestrictedImports": {
"level": "error",
"options": {
"paths": {
"node:path": "Please use src/util/path.js instead.",
"path": "Please use src/util/path.js instead."
}
}
}
},
"style": {
"noParameterAssign": "off",
"useNodeAssertStrict": "error"
},
"suspicious": {
"noConsoleLog": "error",
"noExplicitAny": "off"
}
}
},
"formatter": {
"enabled": true,
"lineWidth": 120,
"indentStyle": "space",
"formatWithErrors": true
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"arrowParentheses": "asNeeded",
"trailingCommas": "es5"
}
},
"json": {
"formatter": {
"lineWidth": 80
}
},
"css": {
"formatter": {
"quoteStyle": "single"
}
},
"overrides": [
{
"include": ["*.astro"],
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "off",
"noUnusedImports": "off"
}
}
}
},
{
"include": [
"packages/docs",
"packages/knip/scripts",
"packages/knip/src/cli.ts",
"packages/knip/src/reporters",
"packages/knip/src/util/cli-arguments.ts",
"packages/knip/src/util/debug.ts"
],
"linter": {
"rules": {
"suspicious": {
"noConsoleLog": "off"
}
}
}
},
{
"include": ["packages/knip/fixtures"],
"organizeImports": {
"enabled": false
},
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "off",
"noUnusedImports": "off"
},
"style": {
"useImportType": "off"
}
}
}
},
{
"include": ["packages/knip/test/util/get-inputs-from-scripts.test.ts"],
"formatter": {
"lineWidth": 200
}
}
]
}"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["migrate", "--write"].as_slice()),
);

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

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_successfully_migrate_knip",
fs,
console,
result,
));
}
1 change: 1 addition & 0 deletions crates/biome_cli/tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod handle_vue_files;
mod included_files;
mod linter_domains;
mod linter_groups_plain;
mod migrate_v2;
mod overrides_formatter;
mod overrides_linter;
mod overrides_organize_imports;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
snapshot_kind: text
---
## `biome.json`

```json
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"files": {
"includes": [
"**",
"!**/dist",
"!**/tmp",
"!**/fixtures",
"!**/packages/knip/package.json",
"!**/packages/knip/vendor/bash-parser/index.js",
"!**/packages/docs/.astro"
]
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"style": {
"noParameterAssign": "off",
"useNodeAssertStrict": "error",
"useLiteralEnumMembers": "error",
"noArguments": "error",
"useShorthandFunctionType": "error",
"useExportType": "error",
"useDefaultParameterLast": "error",
"noCommaOperator": "error",
"useSingleVarDeclarator": "error",
"useNodejsImportProtocol": "error",
"useConst": "error",
"noNonNullAssertion": "error",
"noInferrableTypes": "error",
"useExponentiationOperator": "error",
"noUselessElse": "error",
"useSelfClosingElements": "error",
"useNumberNamespace": "error",
"useAsConstAssertion": "error",
"noUnusedTemplateLiteral": "error",
"useNumericLiterals": "error",
"useTemplate": "error",
"useEnumInitializers": "error"
},
"nursery": {
"noRestrictedImports": {
"level": "error",
"options": {
"paths": {
"node:path": "Please use src/util/path.js instead.",
"path": "Please use src/util/path.js instead."
}
}
}
},
"complexity": {
"useLiteralKeys": "off"
},
"suspicious": {
"noConsole": {
"level": "error",
"options": {
"allow": ["log"]
}
},
"noExplicitAny": "off"
},
"correctness": {
"noUnusedVariables": "error",
"noUnusedImports": "error"
}
}
},
"formatter": {
"enabled": true,
"lineWidth": 120,
"indentStyle": "space",
"formatWithErrors": true
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"arrowParentheses": "asNeeded",
"trailingCommas": "es5"
}
},
"json": {
"formatter": {
"lineWidth": 80
}
},
"css": {
"formatter": {
"quoteStyle": "single"
}
},
"overrides": [
{
"includes": ["**/*.astro"],
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "off",
"noUnusedImports": "off"
}
}
}
},
{
"includes": [
"**/packages/docs/**",
"**/packages/knip/scripts/**",
"**/packages/knip/src/cli.ts",
"**/packages/knip/src/reporters/**",
"**/packages/knip/src/util/cli-arguments.ts",
"**/packages/knip/src/util/debug.ts"
],
"linter": {
"rules": {
"suspicious": {
"noConsole": {
"level": "off",
"options": {
"allow": ["log"]
}
}
}
}
}
},
{
"includes": ["**/packages/knip/fixtures/**"],
"assist": {
"source": {
"organizeImports": "off"
}
},
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "off",
"noUnusedImports": "off"
},
"style": {
"useImportType": "off"
}
}
}
},
{
"includes": [
"**/packages/knip/test/util/get-inputs-from-scripts.test.ts"
],
"formatter": {
"lineWidth": 200
}
}
]
}
```

# Emitted Messages

```block
The configuration biome.json has been successfully migrated.
```
Loading

0 comments on commit ad4da5c

Please sign in to comment.