Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
EliSchleifer committed Jan 5, 2024
1 parent 7a5aff5 commit ef3303f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
23 changes: 22 additions & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,23 @@ lint:
commands:
- name: lint
run: ${workspace}/bin/eslint.js --output-file ${tmpfile} --format json ${target}
- name: validateJson
files:
- json
commands:
- name: format
output: pass_fail
success_codes: [0, 1]
run: node ${workspace}/.trunk/validate-json.js --files ${target}
# read_output_from: stdout
# success_codes: [0, 2]
batch: true
# parser:
# runtime: python
# run: python3 ${plugin}/linters/prettier/prettier_to_sarif.py
enabled:
- eslint@8.56.0
- eslint
- validateJson
- actionlint@1.6.26
- checkov@3.1.38
- git-diff-check
Expand All @@ -50,6 +65,12 @@ lint:
# Default `check` mode will not run on anything in docs
paths:
- docs/**
# - linters: [validateJson]
# paths:
# # Ignore json
# - "**"
# # Except for files in config/
# - "!conf/**"
actions:
disabled:
- trunk-announce
Expand Down
43 changes: 43 additions & 0 deletions .trunk/validate-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node

const fs = require('fs');

// Get the command line arguments
const args = process.argv.slice(2);

// Find the index of the --files argument
const filesArgIndex = args.indexOf('--files');

// If --files is not found or there's no argument after it, print an error and exit
if (filesArgIndex === -1 || filesArgIndex === args.length - 1) {
console.error('Error: Expected --files argument followed by a comma-separated list of filenames');
process.exit(1);
}

// Get the filenames from the argument after --files, splitting on commas
const filenames = args[filesArgIndex + 1].split(',');

filenames.forEach(filename => {
fs.readFile(filename, 'utf8', (err, fileContents) => {
if (err) {
console.error(`Failed to read file ${filename}: ${err}`);
return;
}

try {
// Try to parse the file contents as JSON
JSON.parse(fileContents);
} catch (parseErr) {
const match = parseErr.message.match(/at position (\d+)/);
if (match) {
const position = parseInt(match[1], 10);
const lines = fileContents.slice(0, position).split('\n');
const line = lines.length;
const column = lines[lines.length - 1].length + 1;
console.error(`Failed to parse file ${filename} as JSON at line ${line}, column ${column}: ${parseErr}`);
} else {
console.error(`Failed to parse file ${filename} as JSON: ${parseErr}`);
}
}
});
});
4 changes: 2 additions & 2 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ target.lint = function([fix = false] = []) {
* There is a separate command `target.lintDocsJS` for linting JavaScript files in the `docs` directory.
*/
echo("Validating modified files with trunk check");
const lastReturn = exec(`trunk check ${fix ? " -y" : ""}`);
const lastReturn = exec(`${getBinFile("trunk")} check ${fix ? " -y" : ""}`);

if (lastReturn.code !== 0) {
exit(1);
Expand All @@ -516,7 +516,7 @@ target.lint = function([fix = false] = []) {
target.lintDocsJS = function([fix = false] = []) {
echo("Validating JavaScript files in the docs directory");
const lastReturn = exec(
`trunk check --filter=eslint --force ${fix ? "--fix" : ""} docs`
`${getBinFile("trunk")} check --filter=eslint --force ${fix ? "--fix" : ""} docs`
);

if (lastReturn.code !== 0) {
Expand Down
1 change: 1 addition & 0 deletions d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"filePath":"/home/eli/Github/eslint/Makefile.js","messages":[],"suppressedMessages":[],"errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":[{"ruleId":"no-extra-semi","replacedBy":[]},{"ruleId":"no-mixed-spaces-and-tabs","replacedBy":[]},{"ruleId":"array-bracket-spacing","replacedBy":[]},{"ruleId":"arrow-parens","replacedBy":[]},{"ruleId":"arrow-spacing","replacedBy":[]},{"ruleId":"indent","replacedBy":[]},{"ruleId":"block-spacing","replacedBy":[]},{"ruleId":"brace-style","replacedBy":[]},{"ruleId":"comma-dangle","replacedBy":[]},{"ruleId":"comma-spacing","replacedBy":[]},{"ruleId":"comma-style","replacedBy":[]},{"ruleId":"computed-property-spacing","replacedBy":[]},{"ruleId":"dot-location","replacedBy":[]},{"ruleId":"eol-last","replacedBy":[]},{"ruleId":"func-call-spacing","replacedBy":[]},{"ruleId":"function-call-argument-newline","replacedBy":[]},{"ruleId":"function-paren-newline","replacedBy":[]},{"ruleId":"generator-star-spacing","replacedBy":[]},{"ruleId":"key-spacing","replacedBy":[]},{"ruleId":"keyword-spacing","replacedBy":[]},{"ruleId":"lines-around-comment","replacedBy":[]},{"ruleId":"max-len","replacedBy":[]},{"ruleId":"max-statements-per-line","replacedBy":[]},{"ruleId":"new-parens","replacedBy":[]},{"ruleId":"no-confusing-arrow","replacedBy":[]},{"ruleId":"no-floating-decimal","replacedBy":[]},{"ruleId":"no-multi-spaces","replacedBy":[]},{"ruleId":"no-multiple-empty-lines","replacedBy":[]},{"ruleId":"no-new-object","replacedBy":["no-object-constructor"]},{"ruleId":"no-tabs","replacedBy":[]},{"ruleId":"no-trailing-spaces","replacedBy":[]},{"ruleId":"no-whitespace-before-property","replacedBy":[]},{"ruleId":"object-curly-newline","replacedBy":[]},{"ruleId":"object-curly-spacing","replacedBy":[]},{"ruleId":"object-property-newline","replacedBy":[]},{"ruleId":"one-var-declaration-per-line","replacedBy":[]},{"ruleId":"operator-linebreak","replacedBy":[]},{"ruleId":"padding-line-between-statements","replacedBy":[]},{"ruleId":"quotes","replacedBy":[]},{"ruleId":"quote-props","replacedBy":[]},{"ruleId":"rest-spread-spacing","replacedBy":[]},{"ruleId":"semi","replacedBy":[]},{"ruleId":"semi-spacing","replacedBy":[]},{"ruleId":"semi-style","replacedBy":[]},{"ruleId":"space-before-blocks","replacedBy":[]},{"ruleId":"space-before-function-paren","replacedBy":[]},{"ruleId":"space-in-parens","replacedBy":[]},{"ruleId":"space-infix-ops","replacedBy":[]},{"ruleId":"space-unary-ops","replacedBy":[]},{"ruleId":"spaced-comment","replacedBy":[]},{"ruleId":"switch-colon-spacing","replacedBy":[]},{"ruleId":"template-curly-spacing","replacedBy":[]},{"ruleId":"template-tag-spacing","replacedBy":[]},{"ruleId":"wrap-iife","replacedBy":[]},{"ruleId":"yield-star-spacing","replacedBy":[]}]}]

0 comments on commit ef3303f

Please sign in to comment.