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

Commit

Permalink
feat(vscode): enable JSON formatting (#4146)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
4 people committed Jan 10, 2023
1 parent 66fe775 commit 99ee725
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/rome_fs/src/fs/os.rs
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
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": "^9"
},
"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
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
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

0 comments on commit 99ee725

Please sign in to comment.