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

Rubocop-suggested code style improvements #54

Merged
merged 15 commits into from
May 25, 2017

Conversation

harman28
Copy link
Contributor

@harman28 harman28 commented May 23, 2017

Ref: #51 - Rubocop throws up a lot of offenses

Details of all changes can be found in the commit messages.

Major changes:

  • Wikipedia.Configure has been aliased to Wikipedia.configure (camelCase): The older function still works, but I would recommend deprecating it and removing in a later release.
  • Perl-style special variables have been changed to their English aliases
  • Class method client in wikipedia.rb has been made private
  • Guard clauses have been used wherever possible
  • Hash syntax changed to Ruby 1.9 standard
  • An editorconfig file has been added
  • rubocop has been added as a development dependancy, and rake rubocop is added. We could also add it to the build step and maybe make it task default: [:spec, :rubocop]

I've mostly guessed at what the adopted style decisions of this repo are, based on the code I saw, and made rubocop configuration changes accordingly.

  • Metrics/LineLength: 120 seems reasonable
  • Metrics/MethodLength: This is 10 by default, but it finds offence in methods that really shouldn’t be any shorter. Set to 15.
  • Style/SpaceInsideParens: Disabled, appears to be a style decision
  • Style/SpaceInsidePercentLiteralDelimiters: Disabled, appears to be a style decision
  • Style/RescueModifier: Disabled, appears to be a style decision
  • Style/RegexpLiteral: Allowed inner slashes, to avoid having to use the %r literal
  • Style/Documentation: Can be enabled later

Please review.

* Adds top level comment for class
* Removes trailing space
* Disables cop for SpaceInsideParens
* Makes indentation consistent
* Uses Ruby 1.9 hash syntax
* Prefers single-quoted strings
* Sets MethodLength limit to 15
* Disables RescueModifier and SpaceInsidePercentLiteralDelimiters cops
* Uses guard clauses instead of large if/unless constructs
* Avoids assignments within conditional expressions
* Uses attr_reader for trivial reader method
* Allows inner slashes for RegexpLiteral cop
* Spacing
* Freezes version string
* Uses guard statements
* Disables Style/Documentation bot
* Changes `Configure` method to `configure` to adhere to snake_case
* Aliases `Configure` to maintain backward compatibility
* Updates examples and test uses of `Configure`
* Corrects syntax for `private` modifier on class method
* Uses $PROGRAM_NAME instead of $0
* Uses $LOAD_PATH instead of $:
* Uses Ruby 1.9 hash syntax
* Uses $LOAD_PATH instead of $:
* Removes unnecessary %q literal usage
* Removes unnecessary assignment
* Change array comparison logic from direct comparisons to loops of include checks
* Uses JSON.parse insted of JSON::load
* Breaks overly long lines
* Uses Ruby 1.9 hash syntax
@harman28 harman28 force-pushed the rubocop branch 2 times, most recently from 765060d to 578780c Compare May 23, 2017 13:33
@harman28 harman28 force-pushed the rubocop branch 2 times, most recently from a9ecd78 to 06581da Compare May 23, 2017 21:08
* Removes unnecessary tasks
* Calls `rspec` via Core::RakeTask instead of `system`
@pietromenna
Copy link
Collaborator

Thank you very much for your contributions @harman28 !

@pietromenna pietromenna merged commit ac1b1e2 into kenpratt:master May 25, 2017
@harman28 harman28 deleted the rubocop branch May 25, 2017 02:04
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