]> git.ipfire.org Git - thirdparty/blocklistproject/lists.git/commitdiff
Adding basic lint script
authorCharlie Fish <fishcharlie@me.com>
Sun, 4 Jul 2021 17:42:51 +0000 (11:42 -0600)
committerCharlie Fish <fishcharlie@me.com>
Sun, 4 Jul 2021 17:42:51 +0000 (11:42 -0600)
.github/workflows/lint.yml [new file with mode: 0644]
scripts/lint.js [new file with mode: 0644]

diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
new file mode 100644 (file)
index 0000000..4cacb00
--- /dev/null
@@ -0,0 +1,16 @@
+name: Lint
+on:
+  push:
+  pull_request:
+    types: [opened, synchronize]
+
+jobs:
+  lint:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Use Node.js
+        uses: actions/setup-node@v1
+        with:
+          node-version: 15.x
+      - run: node scripts/lint.js
diff --git a/scripts/lint.js b/scripts/lint.js
new file mode 100644 (file)
index 0000000..0f853ab
--- /dev/null
@@ -0,0 +1,20 @@
+const fs = require("fs").promises;
+const path = require("path");
+
+(async () => {
+       let hasError = false;
+
+       const files = (await fs.readdir(path.join(__dirname, ".."))).filter((file) => file.endsWith(".txt")); // Array of strings, each representing a single file that ends in `.txt`
+       await Promise.all(files.filter((file) => file !== "everything.txt").map(async (file) => { // For each file
+               const fileContents = await fs.readFile(path.join(__dirname, "..", file), "utf8"); // Get file contents as a string
+
+               fileContents.split("\n").forEach((line, index) => {
+                       if (line.length > 0 && !line.startsWith("#") && !line.startsWith("0.0.0.0 ")) {
+                               console.error(`Line ${index + 1} in ${file} must start with "#" or "0.0.0.0 ".`);
+                               hasError = true;
+                       }
+               });
+       }));
+
+       process.exit(hasError ? 1 : 0);
+})();