Skip to content

Commit

Permalink
feat: enable eslint in danger
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Cipolleschi committed Aug 1, 2022
1 parent 6f9b758 commit 1ce6a69
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/danger_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: yarn install
working-directory: .
- run: yarn install
working-directory: bots
- name: Danger
Expand Down
33 changes: 33 additions & 0 deletions bots/dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

const {danger, fail, message, warn} = require('danger');
const includes = require('lodash.includes');
const { execSync } = require('child_process');
const fs = require('fs');

const isFromPhabricator =
danger.github.pr.body &&
Expand Down Expand Up @@ -112,3 +114,34 @@ if (isMergeRefStable) {
},
);
}

console.log("Running eslint on Danger")
const js_files = danger.git.modified_files.filter((name) => name.endsWith('.js') || name.endsWith('.jsx') )
if (js_files.length > 0) {
const joined_files = js_files.map((name) => process.cwd() + "/../" + name).join(' ');
try {
const res = execSync(`npx eslint ${joined_files[0]}`);// -f json ${joined_files}`);
console.log('Eslint result');
console.log(res.toString());
// const eslintOutput = fs.readFileSync('/tmp/eslint.output', 'utf8');
// const eslintJSON = JSON.parse(eslintOutput);
// const faultyFiles = eslintJSON.filter((file) => file.messages.length > 0);

// let messageText = ""
// faultyFiles.forEach((file) => {
// const path = file.filePath
// const splitPath = path.split("/")
// messageText += `${splitPath[splitPath.length - 1]} - ${path}\n`

// file.messages.forEach((msg) => {
// const emoji = msg.severity === 1 ? "⚠️" : msg.severity === 2 ? "⛔️" : "✅"
// const format = `${emoji} - [${msg.line}:${msg.column}] ${msg.message} (${msg.ruleId})\n`
// messageText += format
// })
// })
// warn(messageText);

} catch (err) {
fail(`Couldn't read the lint file output\n${err}`);
}
}

0 comments on commit 1ce6a69

Please sign in to comment.