From: Charlie Fish Date: Sun, 4 Jul 2021 17:42:51 +0000 (-0600) Subject: Adding basic lint script X-Git-Tag: aggregated-20250518~474^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=056ec9d4d0ed82e48afd43fc1c64236e55a8796b;p=thirdparty%2Fblocklistproject%2Flists.git Adding basic lint script --- diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..4cacb00 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 index 0000000..0f853ab --- /dev/null +++ b/scripts/lint.js @@ -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); +})();