diff --git a/crates/biome_cli/tests/commands/migrate_eslint.rs b/crates/biome_cli/tests/commands/migrate_eslint.rs index e5071301f13a..8c3aa0b1b26a 100644 --- a/crates/biome_cli/tests/commands/migrate_eslint.rs +++ b/crates/biome_cli/tests/commands/migrate_eslint.rs @@ -112,6 +112,59 @@ fn migrate_eslintrcjson_write() { )); } +#[test] +fn migrate_eslintrcjson_fix() { + let biomejson = r#"{ "linter": { "enabled": true } }"#; + let eslintrc = r#"{ + "ignorePatterns": [ + "**/*.test.js", // trailing comma amd comment + ], + "globals": { + "var1": "writable", + "var2": "readonly" + }, + "rules": { + "dot-notation": 0, + "default-param-last": "off", + "eqeqeq": "warn", + "getter-return": [2, + // support unknown options + { "allowImplicit": true } + ], + "no-eval": 1, + "no-extra-label": ["error"] + }, + "overrides": [{ + "files": ["bin/*.js", "lib/*.js"], + "excludedFiles": "*.test.js", + "rules": { + "eqeqeq": ["off"] + } + }], + "unknownField": "ignored" + }"#; + + let mut fs = MemoryFileSystem::default(); + fs.insert(Path::new("biome.json").into(), biomejson.as_bytes()); + fs.insert(Path::new(".eslintrc.json").into(), eslintrc.as_bytes()); + + let mut console = BufferConsole::default(); + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["migrate", "eslint", "--fix"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "migrate_eslintrcjson_fix", + fs, + console, + result, + )); +} + #[test] fn migrate_eslintrcjson_override_existing_config() { let biomejson = r#"{ "linter": { "rules": { "recommended": true, "suspicious": { "noDoubleEquals": "error" } } } }"#; diff --git a/crates/biome_cli/tests/commands/migrate_prettier.rs b/crates/biome_cli/tests/commands/migrate_prettier.rs index 40b5ea4f2f8b..6beb2a812fe5 100644 --- a/crates/biome_cli/tests/commands/migrate_prettier.rs +++ b/crates/biome_cli/tests/commands/migrate_prettier.rs @@ -230,6 +230,37 @@ fn prettier_migrate_write() { )); } +#[test] +fn prettier_migrate_fix() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let configuration = r#"{ "linter": { "enabled": true } }"#; + let prettier = r#"{ "useTabs": false, "semi": true, "singleQuote": true }"#; + + let configuration_path = Path::new("biome.json"); + fs.insert(configuration_path.into(), configuration.as_bytes()); + + let prettier_path = Path::new(".prettierrc"); + fs.insert(prettier_path.into(), prettier.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from([("migrate"), "prettier", "--fix"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "prettier_migrate_fix", + fs, + console, + result, + )); +} + #[test] fn prettierjson_migrate_write() { let mut fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/snapshots/main_commands_migrate_eslint/migrate_eslintrcjson_fix.snap b/crates/biome_cli/tests/snapshots/main_commands_migrate_eslint/migrate_eslintrcjson_fix.snap new file mode 100644 index 000000000000..93dad852c43f --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_migrate_eslint/migrate_eslintrcjson_fix.snap @@ -0,0 +1,68 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `biome.json` + +```json +{ + "linter": { + "enabled": true, + "rules": { + "recommended": false, + "complexity": { "noUselessLabel": "error", "useLiteralKeys": "off" }, + "security": { "noGlobalEval": "warn" }, + "style": { "useDefaultParameterLast": "off" }, + "suspicious": { "noDoubleEquals": "warn", "useGetterReturn": "error" } + }, + "ignore": ["**/*.test.js"] + }, + "javascript": { "globals": ["var2", "var1"] }, + "overrides": [ + { + "ignore": ["*.test.js"], + "include": ["bin/*.js", "lib/*.js"], + "linter": { "rules": { "suspicious": { "noDoubleEquals": "off" } } } + } + ] +} +``` + +## `.eslintrc.json` + +```json +{ + "ignorePatterns": [ + "**/*.test.js", // trailing comma amd comment + ], + "globals": { + "var1": "writable", + "var2": "readonly" + }, + "rules": { + "dot-notation": 0, + "default-param-last": "off", + "eqeqeq": "warn", + "getter-return": [2, + // support unknown options + { "allowImplicit": true } + ], + "no-eval": 1, + "no-extra-label": ["error"] + }, + "overrides": [{ + "files": ["bin/*.js", "lib/*.js"], + "excludedFiles": "*.test.js", + "rules": { + "eqeqeq": ["off"] + } + }], + "unknownField": "ignored" + } +``` + +# Emitted Messages + +```block +.eslintrc.json has been successfully migrated. +``` diff --git a/crates/biome_cli/tests/snapshots/main_commands_migrate_prettier/prettier_migrate_fix.snap b/crates/biome_cli/tests/snapshots/main_commands_migrate_prettier/prettier_migrate_fix.snap new file mode 100644 index 000000000000..9a5c4f229a72 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_migrate_prettier/prettier_migrate_fix.snap @@ -0,0 +1,45 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `biome.json` + +```json +{ + "formatter": { + "enabled": true, + "formatWithErrors": false, + "indentStyle": "space", + "indentWidth": 2, + "lineEnding": "lf", + "lineWidth": 80, + "attributePosition": "auto" + }, + "linter": { "enabled": true }, + "javascript": { + "formatter": { + "jsxQuoteStyle": "double", + "quoteProperties": "asNeeded", + "trailingCommas": "all", + "semicolons": "always", + "arrowParentheses": "always", + "bracketSpacing": true, + "bracketSameLine": false, + "quoteStyle": "single", + "attributePosition": "auto" + } + } +} +``` + +## `.prettierrc` + +```prettierrc +{ "useTabs": false, "semi": true, "singleQuote": true } +``` + +# Emitted Messages + +```block +.prettierrc has been successfully migrated. +```