-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add linter for custom rules relating to datapacks/resourcepacks
- `yarn start lint.resourcepack`
- Loading branch information
1 parent
255be7e
commit 45bc624
Showing
5 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 custom lint scripts on resourcepack | ||
run: yarn start lint.resourcepack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters