Skip to content

Commit

Permalink
Verify language json files format (#5233)
Browse files Browse the repository at this point in the history
  • Loading branch information
louislam authored Oct 23, 2024
1 parent 7a82ae0 commit 79a2618
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/json-yaml-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ jobs:
with:
comment: "true" # enable comment mode
exclude_file: ".github/config/exclude.txt" # gitignore style file for exclusions

check-lang-json:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- run: node ./extra/check-lang-json.js
27 changes: 27 additions & 0 deletions extra/check-lang-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// For #5231

const fs = require("fs");

let path = "./src/lang";

// list directories in the lang directory
let jsonFileList = fs.readdirSync(path);

for (let jsonFile of jsonFileList) {
if (!jsonFile.endsWith(".json")) {
continue;
}

let jsonPath = path + "/" + jsonFile;
let originalContent = fs.readFileSync(jsonPath, "utf8");
let langData = JSON.parse(originalContent);

let formattedContent = JSON.stringify(langData, null, 4) + "\n";

if (originalContent !== formattedContent) {
console.error(`File ${jsonFile} is not formatted correctly.`);
process.exit(1);
}
}

console.log("All lang json files are formatted correctly.");

0 comments on commit 79a2618

Please sign in to comment.