Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more rules to dangerfile #1703

Merged
merged 4 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to get away with just using this regex:

if (/^services\/.+\/[^\.]+(?:(?!\.tester))\.js$/.test(file)) {

But the way you have it currently is more self explanatory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case the longer expression is more readable

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