Skip to content

Commit

Permalink
add more rules to dangerfile (#1703)
Browse files Browse the repository at this point in the history
* upgrade danger.js to latest version

* If PR contains tests using assert, suggest expect syntax

* if PR touches service, check service tester also touched
  • Loading branch information
chris48s authored May 30, 2018
1 parent 9d90bd1 commit 57a1bf2
Show file tree
Hide file tree
Showing 3 changed files with 391 additions and 212 deletions.
26 changes: 26 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,29 @@ if (capitals.created || underscores.created) {
'(dash-separated lowercase).',
].join(''));
}

const all_files = danger.git.created_files.concat(danger.git.modified_files);

all_files.forEach(function(file) {
danger.git.diffForFile(file).then(function(diff) {
if (/\+.*assert[(.]/.test(diff.diff)) {
warn([
`Found 'assert' statement added in ${file}. `,
'Please ensure tests are written using Chai ',
'[expect syntax](http://chaijs.com/guide/styles/#expect)'
].join(''));
}
});
});

all_files.forEach(function(file) {
if (/^services\/.+\/.+\.js$/.test(file) && file.endsWith('.js') && !file.endsWith('.tester.js')) {
const tester = file.replace('.js', '.tester.js');
if (all_files.indexOf(tester) == -1) {
warn([
`This PR modified ${file} but not ${tester}. `,
"That's okay so long as it's refactoring existing code.",
].join(''));
}
}
});
Loading

0 comments on commit 57a1bf2

Please sign in to comment.