Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Guard against divide by zero error #145

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants