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
Implement new Style/ExponentialNotation cop #7851
Conversation
@@ -0,0 +1,113 @@ | |||
# frozen_string_literal: true | |||
|
|||
# TODO: when finished, run `rake generate_cops_documentation` to update the docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should remove this line. :-)
module Cop | ||
module Style | ||
# This cop enforces consistency when using exponential notation | ||
# for numbers in the code (eg 1.2e4). Multiple modes can be selected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple modes -> Different style are supported.
That makes it consistent with RuboCop's terminology. I'd also add the explanations of the supported style before the examples - again, for consistency with other cops.
config/default.yml
Outdated
Style/ExponentialNotation: | ||
Description: 'When using exponential notation, favor a mantissa between 1 (inclusive) and 10 (exclusive).' | ||
StyleGuide: '#exponential-notation' | ||
Reference: 'https://github.com/rubocop-hq/ruby-style-guide/issues/803' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's normally used for links to resources like wikipedia, blog posts, etc.
4a60b22
to
8234573
Compare
Thanks for the review, I just amended the commit and pushed the branch |
d9e4bba
to
98d9ae0
Compare
CHANGELOG.md
Outdated
@@ -30,6 +30,7 @@ | |||
* [#7816](https://github.com/rubocop-hq/rubocop/pull/7816): Support Ruby 2.7's numbered parameter for `Style/Lambda`. ([@koic][]) | |||
* [#7829](https://github.com/rubocop-hq/rubocop/issues/7829): Fix an error for `Style/OneLineConditional` when one of the branches contains `next` keyword. ([@koic][]) | |||
* [#7384](https://github.com/rubocop-hq/rubocop/pull/7384): Add new `Style/DisableCopsWithinSourceCodeDirective` cop. ([@egze][]) | |||
* Add a new `Style/ExponentialNotation` cop. ([@tdeo][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, you should move this to master
, as 0.81 was already released.
98d9ae0
to
3226f12
Compare
This cop implements the rule describe in the "exponential notation" section of the ruby style guide. It allows for an additional style not mentionned in the guide, `integral` which allows only integer mantissa, without any trailing zero.
3226f12
to
da236d5
Compare
Amended and rebased again :) |
Victory! 🎉 Thanks for working on this! 🙇♂️ |
Thanks 🎉 |
Follow rubocop#7384, rubocop#7857, and rubocop#7869. This PR fixes the next release version with 0.82 because RuboCop 0.81 has been released. This version (0.82) is based on rubocop#7851.
This cop implements the rule describe in the "exponential notation"
section of the ruby style guide.
It allows for an additional style not mentionned in the guide,
integral
which allows only integer mantissa, without anytrailing zero.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.