Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
OnkarRuikar committed Sep 28, 2024
1 parent a5e089d commit b44bcb1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/auto-cleanup-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
yarn content fix-flaws
yarn fix:md
yarn fix:fm
node scripts/sort_and_unique_file_lines.js .vscode/ignore-list.txt
node scripts/sort_and_unique_file_lines.js .vscode/terms-abbreviations.txt
- name: Create PR with only fixable issues
if: success()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spelling-check-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TITLE: Weekly spelling check
LABELS: reported by automation,good first issue
LABELS: reported by automation
BODY: |
Typos and unknown words:
Expand Down
6 changes: 6 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ export default {
`yarn filecheck ${filenames.join(" ")}`,
],
"*": (filenames) => [`node scripts/log-url-issues.js`],
".vscode/ignore-list.txt": (filenames) => [
`node scripts/sort_and_unique_file_lines.js .vscode/ignore-list.txt`,
],
".vscode/terms-abbreviations.txt": (filenames) => [
`node scripts/sort_and_unique_file_lines.js .vscode/terms-abbreviations.txt`,
],
};
50 changes: 50 additions & 0 deletions scripts/sort_and_unique_file_lines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import fs from "node:fs";
import path from "node:path";

const filePath = process.argv[2];
const check = process.argv[3] === "--check";

if (!fs.existsSync(filePath)) {
console.error(`File ${filePath} doesn't exist.`);
console.warn(
"Usage:\n\tnode scripts/sort_and_unique_file_lines.js <filePath> [--check]",
);
process.exit(1);
}

function equalsIgnoreCase(string1, string2) {
return new RegExp(`^${string1}$`, "gi").test(string2);
}

const uniq = [];
const content = fs.readFileSync(filePath, "utf-8");
const lines = content.split("\n").sort((a, b) => {
a = a.toUpperCase();
b = b.toUpperCase();
return a < b ? -1 : a > b ? 1 : 0;
});

for (let i = 0; i < lines.length; ) {
const line = lines[i];
if (line.trim() !== "") {
uniq.push(line);
while (equalsIgnoreCase(line, lines[++i]));
} else {
i++;
}
}

const sortedContent = uniq.join("\n") + "\n";
if (check) {
if (content !== sortedContent) {
console.error(
`The file is not formatted properly. Run 'node scripts/sort_and_unique_file_lines.js ${filePath}' to format the file.`,
);
process.exit(1);
} else {
console.log("The file looks good.");
process.exit(0);
}
}

fs.writeFileSync(filePath, sortedContent);

0 comments on commit b44bcb1

Please sign in to comment.