Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Static code analysis via Rubocop (#857)
Browse files Browse the repository at this point in the history
* Add rubocop

* Autogenerate rubocop todo yml file

* Add rubocop step to CI

* Add target version to rubocop config

* Fix indentation of "private" macro

* Disable all cops by default 👮

* Rubocop: use 1.9 hash syntax

* Rubocop add cop for 2 spaces indent

* Add cop for case-when indent

* Add some more style cops but don't enable them yet

* Add and run cop for trailing whitespaces

* Add cop for redundant return statements

* Add and run cop for redundant "self"s

* Add and run cop for redundant parenthesis on method calls

* Add and run cops for method def parenthesis

* Add descriptions to cops

* Add and run cop for blank line around access modifier

* Add and run cop to remove random spaces 🚀

* Add and run rubocop for space before comments

* Add and run cops for spaces between comma, etc.

* Add and run cops for single blank line at the end of files

* Add and run cops for class and constant naming

* Add and run cop to not unnecessarily nest else in if

* Update setup instructions in Readme

Add instructions for running code analyzers and some general cleanup.

* Update contribution guide to include info about code analyzers
[ci skip]

* Remove rubocop todo-yml

[ci skip]

* Revert accidental space-issue

* Revert "Revert accidental space-issue"

This reverts commit 8034f74.

* Fix alignment of if-else in roles_controller

* Add and run cops for consistent indentation

Also: remove weird spec file that did not do anything.

* Add and run cops for if-else alignment

* Rephrase change in the contribution guide

[ci skip]

* Update rubocop docs with 1.8 hash example

[ci skip]

* Update travis.yml

Switch pipeline order: lint before tests

close #845
  • Loading branch information
klappradla authored Sep 18, 2017
1 parent 61315d3 commit db178cf
Show file tree
Hide file tree
Showing 112 changed files with 735 additions and 531 deletions.
206 changes: 206 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
AllCops:
TargetRubyVersion: 2.4
DisabledByDefault: true

#################### Layout ###############################

Layout/AccessModifierIndentation:
Description: Check indentation of private/protected visibility modifiers.
StyleGuide: '#indent-public-private-protected'
Enabled: true

Layout/InitialIndentation:
Description: >-
Checks the indentation of the first non-blank non-comment line in a file.
Enabled: true

Layout/IndentationWidth:
Description: "Use 2 spaces for indentation."
StyleGuide: "#spaces-indentation"
Enabled: true

Layout/IndentationConsistency:
Description: 'Keep indentation straight.'
StyleGuide: '#spaces-indentation'
Enabled: true

Layout/CaseIndentation:
Description: "Indentation of when in a case/when/[else/]end."
StyleGuide: "#indent-when-to-case"
Enabled: true

Layout/ElseAlignment:
Description: 'Align elses and elsifs correctly.'
Enabled: true

Layout/EmptyLinesAroundAccessModifier:
Description: "Keep blank lines around access modifiers."
StyleGuide: "#empty-lines-around-access-modifier"
Enabled: true

Lint/EndAlignment:
Description: 'Align ends correctly.'
Enabled: true

Layout/EndOfLine:
Description: "Use Unix-style line endings."
StyleGuide: "#crlf"
Enabled: true

Layout/ExtraSpacing:
Description: "Do not use unnecessary spacing."
Enabled: true

Layout/LeadingCommentSpace:
Description: "Comments should start with a space."
StyleGuide: "#hash-space"
Enabled: true

Layout/SpaceAfterColon:
Description: "Use spaces after colons."
StyleGuide: "#spaces-operators"
Enabled: true

Layout/SpaceAfterComma:
Description: "Use spaces after commas."
StyleGuide: '#spaces-operators'
Enabled: true

Layout/SpaceAfterMethodName:
Description: >-
Do not put a space between a method name and the opening
parenthesis in a method definition.
StyleGuide: "#parens-no-spaces"
Enabled: true

Layout/SpaceAfterNot:
Description: Tracks redundant space after the ! operator.
StyleGuide: "#no-space-bang"
Enabled: true

Layout/SpaceAfterSemicolon:
Description: "Use spaces after semicolons."
StyleGuide: '#spaces-operators'
Enabled: true

Layout/SpaceBeforeComma:
Description: "No spaces before commas."
Enabled: true

Layout/SpaceBeforeComment:
Description: >-
Checks for missing space between code and a comment on the
same line.
Enabled: true

Layout/SpaceBeforeSemicolon:
Description: "No spaces before semicolons."
Enabled: true

Layout/SpaceAroundOperators:
Description: "Use a single space around operators."
StyleGuide: "#spaces-operators"
Enabled: true

Layout/Tab:
Description: "No hard tabs."
StyleGuide: "#spaces-indentation"
Enabled: true

Layout/TrailingBlankLines:
Description: "Checks trailing blank lines and final newline."
StyleGuide: '#newline-eof'
Enabled: true

Layout/TrailingWhitespace:
Description: "Avoid trailing whitespace."
StyleGuide: "#no-trailing-whitespace"
Enabled: true

#################### Naming ##############################

Naming/ClassAndModuleCamelCase:
Description: "Use CamelCase for classes and modules."
StyleGuide: "#camelcase-classes"
Enabled: true

Naming/ConstantName:
Description: "Constants should use SCREAMING_SNAKE_CASE."
StyleGuide: "#screaming-snake-case"
Enabled: true

#################### Style ###############################

Style/ClassVars:
Description: 'Avoid the use of class variables.'
StyleGuide: '#no-class-vars'
Enabled: true

Style/DefWithParentheses:
Description: "Use def with parentheses when there are arguments."
StyleGuide: "#method-parens"
Enabled: true

Style/Encoding:
Description: "Use UTF-8 as the source file encoding."
StyleGuide: "#utf-8"
Enabled: true

# TODO
Style/FrozenStringLiteralComment:
Description: "Add frozen_string_literal comment to the top of files"
Include:
- "app/**/*.rb"
- "lib/**/*.rb"
Enabled: false

Style/HashSyntax:
Description: "Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2}"
EnforcedStyle: ruby19

Style/IfInsideElse:
Description: "Finds if nodes inside else, which can be converted to elsif."
Enabled: true

Style/MethodCallWithoutArgsParentheses:
Description: "Do not use parentheses for method calls with no arguments."
StyleGuide: "#method-invocation-parens"
Enabled: true

Style/MethodDefParentheses:
Description: >-
Checks if the method definitions have or don't have
parentheses.
StyleGuide: "#method-parens"
Enabled: true

Style/RedundantReturn:
Description: "Don't use return where it's not required."
Enabled: true

Style/RedundantSelf:
Description: "Don't use self where it's not needed."
Enabled: true

Style/TrailingCommaInArguments:
Description: "Checks for trailing comma in argument lists."
StyleGuide: "#no-trailing-params-comma"
Enabled: true

#################### Metrics ###############################

# TODO
Metrics/LineLength:
Description: "Limit lines to 80 characters."
StyleGuide: "#80-character-limits"
Enabled: false


#################### Bundler ###############################

Bundler/DuplicatedGem:
Description: "Checks for duplicate gem entries in Gemfile."
Enabled: true
Include:
- "**/Gemfile"
- "**/gems.rb"
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ before_script:
- bundle exec rake db:create db:schema:load RAILS_ENV=test
- npm install -g jshint
script:
- bundle exec rake spec
- bundle exec rubocop
- jshint app/assets/javascripts
- bundle exec rake spec
deploy:
- provider: heroku
api_key:
Expand Down
9 changes: 4 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ Before you start working, make sure no one else is already working on it: check

If you've confirmed that no one is working on the issue and would like to give it a go, feel free to leave a comment saying so! You could write something like the following:

```
I think I know how to fix this one! Will give it a try :thumbsup:
```
I think I know how to fix this one! Will give it a try :thumbsup:

### Creating a Pull Request

Expand All @@ -94,7 +92,8 @@ If you've cloned the app a while ago, you want to make sure that your cloned `ma

### Write Code

We aim to follow the [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) but we don't enforce it (i.e. there is no [RuboCop](https://github.com/bbatsov/rubocop)). The most important thing is probably just proper indentation: two whitespaces.
We aim to follow the [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) and have [RuboCop](https://github.com/bbatsov/rubocop) set up to make sure we stay consistent with some basic rules (see our [rubocop.yml](https://github.com/rails-girls-summer-of-code/rgsoc-teams/blob/master/.rubocop.yml) file for details).
But don't be afraid, those are friendly cops who are here to help you with formatting your code 👮

We prefer JavaScript (`*.js`) over CoffeeScript (`*.coffee`). jQuery is perfectly fine, but if you can, use [Vanilla JS instead of jQuery](https://gist.github.com/liamcurry/2597326). Indentation for JavaScript files: four whitespaces.

Expand All @@ -106,7 +105,7 @@ Make atomic commits with a descriptive commit message.

### Make a Pull Request

Github [provides documentation](https://help.github.com/articles/creating-a-pull-request/) on how to create a PR. A new PR (and any subsequent updates to it) will trigger running the test suite on Travis CI.
Github [provides documentation](https://help.github.com/articles/creating-a-pull-request/) on how to create a PR. A new PR (and any subsequent updates to it) will trigger running the test suite and automatic code analyzers on Travis CI.

If your contribution alters the way the Teams App looks (e.g. CSS changes), we kindly ask you to provide a few screenshots (before/after) that illustrate the change. It's much easier and quicker to review as we won't have to checkout the PR locally. You can drag'n'drop image files directly into the PR description or its comments section.

Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'database_cleaner'
gem 'byebug', require: !ENV['RM_INFO'] #require parameter is workaround for RubyMine with Rails ~> 4.1
gem 'byebug', require: !ENV['RM_INFO'] # require parameter is workaround for RubyMine with Rails ~> 4.1
gem 'ffaker'
end

Expand All @@ -70,4 +70,5 @@ group :test do
gem 'rspec-collection_matchers'
gem 'rspec-html-matchers'
gem 'rspec-activemodel-mocks'
gem 'rubocop', require: false
end
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.4.0)
arel (8.0.0)
ast (2.3.0)
autoprefixer-rails (7.1.4)
execjs
aws-sdk (2.10.29)
Expand Down Expand Up @@ -194,7 +195,11 @@ GEM
oauth2 (~> 1.0)
omniauth (~> 1.2)
orm_adapter (0.5.0)
parallel (1.12.0)
parser (2.4.0.0)
ast (~> 2.2)
pg (0.21.0)
powerpack (0.1.1)
pretender (0.3.1)
actionpack
pry (0.10.4)
Expand Down Expand Up @@ -239,6 +244,8 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.2.2)
rake
rake (12.1.0)
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
Expand Down Expand Up @@ -277,6 +284,14 @@ GEM
rspec-mocks (~> 3.6.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.3)
safe_yaml (1.0.4)
sass (3.5.1)
sass-listen (~> 4.0.0)
Expand Down Expand Up @@ -342,6 +357,7 @@ GEM
thread_safe (~> 0.1)
uglifier (3.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.3.0)
unicode_utils (1.4.0)
warden (1.2.7)
rack (>= 1.0)
Expand Down Expand Up @@ -396,6 +412,7 @@ DEPENDENCIES
rspec-collection_matchers
rspec-html-matchers
rspec-rails
rubocop
sass-rails
sentry-raven
shoulda
Expand Down
Loading

0 comments on commit db178cf

Please sign in to comment.