Skip to content

Commit

Permalink
add linter for custom rules relating to datapacks/resourcepacks
Browse files Browse the repository at this point in the history
- `yarn start lint.resourcepack`
  • Loading branch information
TheAfroOfDoom committed Jan 8, 2024
1 parent 255be7e commit a50e084
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/resourcepack.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = {
check: 'prettier --check .',
fix: 'prettier --write .',
},
resourcepack: `node ./package-scripts/run-linting-rules --glob "${resourcepackGlob}"`,
},
},
};
47 changes: 47 additions & 0 deletions package-scripts/run-linting-rules.js
Original file line number Diff line number Diff line change
@@ -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();
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 42 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a50e084

Please sign in to comment.