Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(vscode): enable JSON formatting #4146

Merged
merged 10 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion crates/rome_fs/src/fs/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion editors/vscode/package-lock.json

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

8 changes: 5 additions & 3 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
"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": "^8 || ^9"
ematipico marked this conversation as resolved.
Show resolved Hide resolved
},
"capabilities": {
"untrustedWorkspaces": {
Expand Down Expand Up @@ -150,4 +152,4 @@
"resolve": "^1.22.1",
"vscode-languageclient": "^8.0.2"
}
}
}
16 changes: 15 additions & 1 deletion npm/js-api/tests/formatContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand All @@ -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, {
Expand Down
3 changes: 2 additions & 1 deletion npm/js-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"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",
Expand Down