feat(vscode): enable JSON formatting
MODIFY
crates/rome_fs/src/fs/os.rs
crates/rome_fs/src/fs/os.rs
@@ -259,7 +259,7 @@ fn handle_dir_entry<'scope>(
if file_type.is_file() {
if matches!(
path.file_name().and_then(OsStr::to_str),
- Some("package.json" | "package-lock.json" | "tsconfig.json")
+ Some("package.json" | "package-lock.json" | "tsconfig.json" | "jsconfig.json")
) {
return;
}

MODIFY
editors/vscode/package-lock.json
editors/vscode/package-lock.json
"vsce": "^2.11.0"
},
"engines": {
- "npm": "^8",
+ "npm": "^9",
"vscode": "^1.70.0"
}
},

MODIFY
editors/vscode/package.json
editors/vscode/package.json
"onLanguage:javascriptreact",
"onLanguage:typescript",
"onLanguage:typescriptreact",
+ "onLanguage:json",
"onCommand:rome.syntaxTree"
],
"main": "./out/main.js",
"repository": {
"type": "git",
- "url": "https://github.com/rome/tools.git"
+ "url": "https://github.com/rome/tools.git",
+ "directory": "editors/vscode"
},
"bugs": {
"url": "https://github.com/rome/tools/issues"
},
"engines": {
"vscode": "^1.70.0",
- "npm": "^8"
+ "npm": "^9"
},
"capabilities": {
"untrustedWorkspaces": {

MODIFY
npm/js-api/tests/formatContent.test.ts
npm/js-api/tests/formatContent.test.ts
@@ -13,7 +13,7 @@ describe("Rome WebAssembly formatContent", () => {
rome.shutdown();
});
- it("should format content", () => {
+ it("should format JavaScript content", () => {
const result = rome.formatContent("function f () { }", {
filePath: "example.js",
});
@@ -22,6 +22,20 @@ describe("Rome WebAssembly formatContent", () => {
expect(result.diagnostics).toEqual([]);
});
+ it("should format JSON content", () => {
+ const result = rome.formatContent(
+ '{ "lorem": "ipsum", "foo": false, "bar": 23, "lorem": "ipsum", "foo": false, "bar": 23 }',
+ {
+ filePath: "example.json",
+ },
+ );
+
+ expect(result.content).toEqual(
+ '{\n\t"lorem": "ipsum",\n\t"foo": false,\n\t"bar": 23,\n\t"lorem": "ipsum",\n\t"foo": false,\n\t"bar": 23\n}\n',
+ );
+ expect(result.diagnostics).toEqual([]);
+ });
+
it("should not format and have diagnostics", () => {
const content = "function () { }";
const result = rome.formatContent(content, {

MODIFY
npm/js-api/tsconfig.json
npm/js-api/tsconfig.json
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": true, /* Enable all strict type-checking options. */
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
+ "skipLibCheck": true, /* Skip type checking all .d.ts files. */
+ "lib": ["ES2021"]
},
"exclude": [
"./tests",

feat(vscode): enable JSON formatting (#4146)

Co-authored-by: Superchupu <53496941+SuperchupuDev@users.noreply.github.com>
Co-authored-by: Micha Reiser <micha@famreiser.ch>
Co-authored-by: Micha Reiser <micha@rome.tools>