diff --git a/.github/workflows/resourcepack.yml b/.github/workflows/resourcepack.yml new file mode 100644 index 000000000..98046d6e3 --- /dev/null +++ b/.github/workflows/resourcepack.yml @@ -0,0 +1,20 @@ +name: resourcepack + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Yarn 3.6.3 + run: corepack enable + - name: Setup cache + uses: actions/setup-node@v4 + with: + cache: 'yarn' + cache-dependency-path: yarn.lock + node-version-file: package.json + - run: yarn + - name: Run lint scripts on resourcepack + run: yarn start lint.resourcepack diff --git a/package-scripts.js b/package-scripts.js index 0bdf70f41..aab3ee55a 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -62,6 +62,7 @@ module.exports = { check: 'prettier --check .', fix: 'prettier --write .', }, + resourcepack: `node ./package-scripts/run-linting-rules --glob "${resourcepackGlob}"`, }, }, }; diff --git a/package-scripts/run-linting-rules.js b/package-scripts/run-linting-rules.js new file mode 100644 index 000000000..bb47d3b22 --- /dev/null +++ b/package-scripts/run-linting-rules.js @@ -0,0 +1,47 @@ +const chalk = require('chalk'); +const { globSync } = require('glob'); +const minimist = require('minimist'); + +const argv = minimist(process.argv.slice(2)); + +const rules = globSync('./package-scripts/linting-rules/*.js').map((rulePath) => + require(`${process.cwd()}/${rulePath}`), +); + +const main = () => { + if (typeof argv.glob === 'undefined') { + throw new Error('No glob provided for files to run linting rules on'); + } + + let errorCount = 0; + const files = globSync(argv.glob); + + for (const file of files) { + const errors = []; + for (const rule of rules) { + const ruleErrors = rule.function(file); + errors.push( + ...ruleErrors.map((error) => `${chalk.yellow(rule.name)}: ${error}`), + ); + } + if (errors.length > 0) { + console.log( + `${chalk.redBright('Error(s)')} in file: ${chalk.cyanBright(file)}`, + ); + for (const error of errors) { + console.log(error); + } + console.log(); + } + errorCount += errors.length; + } + + if (errorCount === 0) { + console.log( + chalk.greenBright(`No linting errors found for glob '${argv.glob}'!`), + ); + } + process.exit(errorCount); +}; + +main(); diff --git a/package.json b/package.json index a3f78a741..3e700da5f 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,12 @@ }, "devDependencies": { "bestzip": "1.1.6", + "chalk": "4.1.0", "cpy-cli": "5.0.0", "eslint": "8.56.0", + "glob": "10.3.10", "minimatch": "9.0.3", + "minimist": "1.2.8", "nps": "5.10.0", "nps-utils": "1.7.0", "prettier": "3.1.1", diff --git a/yarn.lock b/yarn.lock index c0dd34f5f..3c3d02150 100644 --- a/yarn.lock +++ b/yarn.lock @@ -480,6 +480,16 @@ __metadata: languageName: node linkType: hard +"chalk@npm:4.1.0": + version: 4.1.0 + resolution: "chalk@npm:4.1.0" + dependencies: + ansi-styles: ^4.1.0 + supports-color: ^7.1.0 + checksum: 5561c7b4c063badee3e16d04bce50bd033e1be1bf4c6948639275683ffa7a1993c44639b43c22b1c505f0f813a24b1889037eb182546b48946f9fe7cdd0e7d13 + languageName: node + linkType: hard + "chalk@npm:^2.0.1, chalk@npm:^2.4.1": version: 2.4.2 resolution: "chalk@npm:2.4.2" @@ -1297,6 +1307,21 @@ __metadata: languageName: node linkType: hard +"glob@npm:10.3.10": + version: 10.3.10 + resolution: "glob@npm:10.3.10" + dependencies: + foreground-child: ^3.1.0 + jackspeak: ^2.3.5 + minimatch: ^9.0.1 + minipass: ^5.0.0 || ^6.0.2 || ^7.0.0 + path-scurry: ^1.10.1 + bin: + glob: dist/esm/bin.mjs + checksum: 4f2fe2511e157b5a3f525a54092169a5f92405f24d2aed3142f4411df328baca13059f4182f1db1bf933e2c69c0bd89e57ae87edd8950cba8c7ccbe84f721cf3 + languageName: node + linkType: hard + "glob@npm:^10.2.5": version: 10.3.4 resolution: "glob@npm:10.3.4" @@ -1635,6 +1660,19 @@ __metadata: languageName: node linkType: hard +"jackspeak@npm:^2.3.5": + version: 2.3.6 + resolution: "jackspeak@npm:2.3.6" + dependencies: + "@isaacs/cliui": ^8.0.2 + "@pkgjs/parseargs": ^0.11.0 + dependenciesMeta: + "@pkgjs/parseargs": + optional: true + checksum: 57d43ad11eadc98cdfe7496612f6bbb5255ea69fe51ea431162db302c2a11011642f50cfad57288bd0aea78384a0612b16e131944ad8ecd09d619041c8531b54 + languageName: node + linkType: hard + "js-yaml@npm:^3.9.0": version: 3.14.1 resolution: "js-yaml@npm:3.14.1" @@ -1940,7 +1978,7 @@ __metadata: languageName: node linkType: hard -"minimist@npm:^1.1.3, minimist@npm:^1.2.0, minimist@npm:^1.2.6": +"minimist@npm:1.2.8, minimist@npm:^1.1.3, minimist@npm:^1.2.0, minimist@npm:^1.2.6": version: 1.2.8 resolution: "minimist@npm:1.2.8" checksum: 75a6d645fb122dad29c06a7597bddea977258957ed88d7a6df59b5cd3fe4a527e253e9bbf2e783e4b73657f9098b96a5fe96ab8a113655d4109108577ecf85b0 @@ -2100,9 +2138,12 @@ __metadata: resolution: "omega-flowey-minecraft-remastered@workspace:." dependencies: bestzip: 1.1.6 + chalk: 4.1.0 cpy-cli: 5.0.0 eslint: 8.56.0 + glob: 10.3.10 minimatch: 9.0.3 + minimist: 1.2.8 nps: 5.10.0 nps-utils: 1.7.0 prettier: 3.1.1