Skip to content

Guard against divide by zero error #145

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

Merged
merged 3 commits into from
Oct 24, 2016
Merged

Conversation

ABaldwinHunter
Copy link
Contributor

Fixes a bug where empty js file could cause an analysis to error

e.g. https://codeclimate.com/github/parliamentofowls/test-repo-cc/builds/1

@codeclimate/review

Fixes a bug where empty js file could cause an analysis to error
@ABaldwinHunter
Copy link
Contributor Author

I slightly disagree with the rubocop setting we have that's telling me to

Use content.lines.count.nonzero? instead of content.lines.count != 0.

because I think it's less explicit and mathematical, but going to comply for now.

if content.lines.count != 0
ratio = content.chars.count / content.lines.count
ratio >= MINIFIED_AVG_LINE_LENGTH_CUTOFF
end
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw a comment on another PR this morning suggesting that a ? method should probably return a bool, which made sense to me. In which case an else... false branch here might make sense.

@ABaldwinHunter
Copy link
Contributor Author

@wfleming updated!

@wfleming
Copy link
Contributor

LGTM

@maxjacobson
Copy link
Contributor

Oo good catch. This was inspired by the eslint checker y'all wrote a few months ago, but I forgot that JS is a little more loosey-goosey with math 😬

@ABaldwinHunter ABaldwinHunter merged commit df02910 into master Oct 24, 2016
@ABaldwinHunter ABaldwinHunter deleted the abh-divide-by-zero branch October 24, 2016 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants