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

Implement new Style/ExponentialNotation cop #7851

Merged
merged 1 commit into from Apr 10, 2020

Conversation

tdeo
Copy link
Contributor

@tdeo tdeo commented Apr 5, 2020

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.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@@ -0,0 +1,113 @@
# frozen_string_literal: true

# TODO: when finished, run `rake generate_cops_documentation` to update the docs
Copy link
Collaborator

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
Copy link
Collaborator

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.

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'
Copy link
Collaborator

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.

@tdeo
Copy link
Contributor Author

tdeo commented Apr 8, 2020

Thanks for the review, I just amended the commit and pushed the branch

@tdeo tdeo force-pushed the td/exponential_notation branch 2 times, most recently from d9e4bba to 98d9ae0 Compare April 9, 2020 17:02
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][])
Copy link
Collaborator

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.

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.
@tdeo
Copy link
Contributor Author

tdeo commented Apr 10, 2020

Amended and rebased again :)

@bbatsov bbatsov merged commit 00e8170 into rubocop:master Apr 10, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 10, 2020

Victory! 🎉 Thanks for working on this! 🙇‍♂️

@tdeo
Copy link
Contributor Author

tdeo commented Apr 10, 2020

Thanks 🎉

@tdeo tdeo deleted the td/exponential_notation branch April 10, 2020 12:35
koic added a commit to koic/rubocop that referenced this pull request Apr 13, 2020
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.
@koic koic mentioned this pull request Apr 13, 2020
8 tasks
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.

None yet

2 participants