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 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

This comment has been minimized.

Copy link
@bbatsov

bbatsov Apr 7, 2020

Collaborator

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

This comment has been minimized.

Copy link
@bbatsov

bbatsov Apr 7, 2020

Collaborator

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'

This comment has been minimized.

Copy link
@bbatsov

bbatsov Apr 7, 2020

Collaborator

That's normally used for links to resources like wikipedia, blog posts, etc.

@tdeo tdeo force-pushed the tdeo:td/exponential_notation branch from 4a60b22 to 8234573 Apr 8, 2020
@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 tdeo:td/exponential_notation branch 2 times, most recently from d9e4bba to 98d9ae0 Apr 9, 2020
@@ -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][])

This comment has been minimized.

Copy link
@bbatsov

bbatsov Apr 10, 2020

Collaborator

Btw, you should move this to master, as 0.81 was already released.

@tdeo tdeo force-pushed the tdeo:td/exponential_notation branch from 98d9ae0 to 3226f12 Apr 10, 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.
@tdeo tdeo force-pushed the tdeo:td/exponential_notation branch from 3226f12 to da236d5 Apr 10, 2020
@tdeo
Copy link
Contributor Author

tdeo commented Apr 10, 2020

Amended and rebased again :)

@bbatsov bbatsov merged commit 00e8170 into rubocop-hq:master Apr 10, 2020
25 checks passed
25 checks passed
ci/circleci: cc-setup Your tests passed on CircleCI!
Details
ci/circleci: cc-upload-coverage Your tests passed on CircleCI!
Details
ci/circleci: documentation-checks Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-rubocop Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.3-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.3-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.3-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.6-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.6-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.6-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.7-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.7-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.7-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-head-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-head-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-head-spec Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@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 tdeo:td/exponential_notation branch Apr 10, 2020
koic added a commit to koic/rubocop that referenced this pull request Apr 13, 2020
Follow rubocop-hq#7384, rubocop-hq#7857, and rubocop-hq#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-hq#7851.
@koic koic mentioned this pull request Apr 13, 2020
7 of 8 tasks complete
Neodelf added a commit to Neodelf/rubocop that referenced this pull request Apr 28, 2020
Follow rubocop-hq#7384, rubocop-hq#7857, and rubocop-hq#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-hq#7851.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.