Skip to content

Commit

Permalink
Prep for rubocop ci (#2984)
Browse files Browse the repository at this point in the history
* Rubocop autofix

* Add example.com to ignore

* Complete initial setup for Rubocop

* Remove unused code

* Run rubocop on CI

* Update style guide yml

* Finalize Rubocop config/cops

* Remove comment annotation

* Disable MultilineMethodCallIndentation

* Remove unused code

* Remove unused code

* Fix double negation

* Fix cop

* Fix cop

* Group cops by type

* Fix cop
  • Loading branch information
siaw23-retired authored and jywarren committed Jul 9, 2018
1 parent 05fecd4 commit 5e65d08
Show file tree
Hide file tree
Showing 33 changed files with 333 additions and 361 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ config/initializers/secret_token.rb
public/system
public/lib
db/openid-store/
www.example.com/
dump.rdb
db/schema.rb
public/assets/application-*
todo.txt
Expand Down
42 changes: 36 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Start with Spotifys style guide as a base then customize from there
inherit_from:
- http://shopify.github.io/ruby-style-guide/rubocop.yml
- .rubocop_shopify_styleguide.yml
- .rubocop_todo.yml

# Apply rule to all cops
Expand All @@ -23,17 +23,47 @@ AllCops:
- 'Dangerfile'
TargetRubyVersion: '2.4'

Layout/MultilineMethodCallIndentation:
Enabled: false

Style/RegexpLiteral:
Enabled: false

Style/IfInsideElse:
Enabled: false

Style/DateTime:
Enabled: false

Style/CaseEquality:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Metrics/ParameterLists:
Lint/ParenthesesAsGroupedExpression:
Enabled: false

Metrics/ModuleLength:
Max: 303
Lint/EndAlignment:
Enabled: false

Lint/DefEndAlignment:
Enabled: false

Lint/SafeNavigationChain:
Enabled: false

Lint/AssignmentInCondition:
Enabled: false

Naming/AccessorMethodName:
Enabled: false

Metrics/ClassLength:
Max: 660
Enabled: false

Style/RegexpLiteral:
Metrics/ParameterLists:
Enabled: false

Metrics/ModuleLength:
Max: 303
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
AllCops:
Exclude:
- 'db/schema.rb'
DisabledByDefault: true

# http://shopify.github.io/ruby-style-guide/rubocop.yml
#
Layout/AccessModifierIndentation:
EnforcedStyle: indent
SupportedStyles:
Expand Down Expand Up @@ -107,14 +104,6 @@ Style/CommandLiteral:
- mixed
AllowInnerBackticks: false

Style/CommentAnnotation:
Keywords:
- TODO
- FIXME
- OPTIMIZE
- HACK
- REVIEW

Style/ConditionalAssignment:
EnforcedStyle: assign_to_condition
SupportedStyles:
Expand Down Expand Up @@ -200,9 +189,6 @@ Style/FrozenStringLiteralComment:
- always
- never

Style/GlobalVars:
AllowedVariables: []

Style/HashSyntax:
EnforcedStyle: ruby19
SupportedStyles:
Expand Down Expand Up @@ -368,6 +354,10 @@ Style/RegexpLiteral:

Style/SafeNavigation:
ConvertCodeThatCanStartToReturnNil: false
Enabled: true

Lint/SafeNavigationChain:
Enabled: true

Style/Semicolon:
AllowAsExpressionSeparator: false
Expand Down Expand Up @@ -506,39 +496,14 @@ Style/WordArray:
MinSize: 0
WordRegex: !ruby/regexp /\A[\p{Word}\n\t]+\z/

Metrics/BlockNesting:
Max: 3

Metrics/LineLength:
Max: 120
AllowHeredoc: true
AllowURI: true
URISchemes:
- http
- https
IgnoreCopDirectives: false
IgnoredPatterns:
- '\A\s*test(_\w+)?\s.*(do|->)(\s|\Z)'

Metrics/ParameterLists:
Max: 5
CountKeywordArgs: false

Lint/BlockAlignment:
Layout/BlockAlignment:
EnforcedStyleAlignWith: either
SupportedStylesAlignWith:
- either
- start_of_block
- start_of_line

Lint/EndAlignment:
EnforcedStyleAlignWith: variable
SupportedStylesAlignWith:
- keyword
- variable
- start_of_line

Lint/DefEndAlignment:
Layout/DefEndAlignment:
EnforcedStyleAlignWith: start_of_line
SupportedStylesAlignWith:
- start_of_line
Expand Down Expand Up @@ -760,9 +725,6 @@ Style/LineEndConcatenation:
Style/MethodCallWithoutArgsParentheses:
Enabled: true

Style/MethodMissing:
Enabled: true

Style/MultilineBlockChain:
Enabled: true

Expand Down Expand Up @@ -928,7 +890,7 @@ Lint/AmbiguousRegexpLiteral:
Lint/CircularArgumentReference:
Enabled: true

Lint/ConditionPosition:
Layout/ConditionPosition:
Enabled: true

Lint/Debugger:
Expand Down Expand Up @@ -1032,7 +994,10 @@ Lint/UnderscorePrefixedVariableName:
Lint/UnifiedInteger:
Enabled: true

Lint/UnneededDisable:
Lint/UnneededCopDisableDirective:
Enabled: true

Lint/UnneededCopEnableDirective:
Enabled: true

Lint/UnneededSplatExpansion:
Expand All @@ -1044,9 +1009,6 @@ Lint/UnreachableCode:
Lint/UselessAccessModifier:
ContextCreatingMethods: []

Lint/UselessAssignment:
Enabled: true

Lint/UselessComparison:
Enabled: true

Expand Down Expand Up @@ -1080,9 +1042,6 @@ Performance/FixedSize:
Performance/FlatMap:
EnabledForFlattenWithoutParams: false

Performance/HashEachMethods:
Enabled: true

Performance/LstripRstrip:
Enabled: true

Expand Down Expand Up @@ -1135,3 +1094,26 @@ Security/Eval:

Security/JSONLoad:
Enabled: true

Security/Open:
Enabled: true

Lint/BigDecimalNew:
Enabled: true

Style/TrailingBodyOnClass:
Enabled: true

Style/TrailingBodyOnModule:
Enabled: true

Layout/SpaceInsideReferenceBrackets:
EnforcedStyle: no_space
EnforcedStyleForEmptyBrackets: no_space
Enabled: true

Style/ModuleFunction:
EnforcedStyle: extend_self

Lint/OrderedMagicComments:
Enabled: true
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ services:
env:
- COMPOSE_FILE=./containers/docker-compose-testing.yml

before_script:
- bundle install
- bundle exec rubocop

before_install:
- echo -e "repo_token:\n $COVERALLS_REPO_TOKEN" >> ./.coveralls.yml

Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ gem 'figaro'
gem 'sanitize'
gem 'tzinfo-data', platforms: %i(mingw mswin x64_mingw jruby)
gem 'rails-controller-testing'

gem 'rubocop', '~> 0.52.1', require: false

# To implement incoming mail processing microframework
gem 'mailman', require: false
Expand Down Expand Up @@ -89,7 +89,6 @@ group :development do
gem "letter_opener"
gem "nifty-generators"
gem 'byebug', platform: :mri
gem 'rubocop', '~> 0.52.1', require: false
end

group :test, :development do
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ class AdminController < ApplicationController
before_action :require_user, only: %i(spam spam_revisions mark_comment_spam publish_comment)

# intended to provide integration tests for assets
def assets
end
def assets; end

def promote_admin
@user = User.find params[:id]
Expand Down Expand Up @@ -82,7 +81,7 @@ def spam
.order('nid DESC')
@nodes = if params[:type] == 'wiki'
@nodes.where(type: 'page', status: 1)
else
else
@nodes.where(status: 0)
end
else
Expand Down Expand Up @@ -195,7 +194,7 @@ def mark_spam_revision
@revision = Revision.find_by(vid: params[:vid])
@node = Node.find_by(nid: @revision.nid)

if(@node.revisions.length <= 1)
if @node.revisions.length <= 1
flash[:warning] = "You can't delete the last remaining revision of a page; try deleting the wiki page itself (if you're an admin) or contacting [email protected] for assistance."
redirect_to @node.path
return
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def set_sidebar(type = :generic, data = :all, args = {})
@notes = if params[:controller] == 'questions'
Node.questions
.joins(:revision)
else
else
Node.research_notes.joins(:revision).order('node.nid DESC').paginate(page: params[:page])
end

Expand Down Expand Up @@ -162,15 +162,15 @@ def comments_node_and_path
@node = if @comment.aid == 0
# finding node for node comments
@comment.node
else
else
# finding node for answer comments
@comment.answer.node
end

@path = if params[:type] && params[:type] == 'question'
# questions path
@node.path(:question)
else
else
# notes path
@node.path
end
Expand All @@ -188,7 +188,6 @@ def redirect_old_urls
end

def signed_in?
!!current_user
!current_user.nil?
end

end
4 changes: 2 additions & 2 deletions app/controllers/comment_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ def like_comment

@likes = comment.likes.group(:emoji_type).count
respond_with do |format|
format.js {
format.js do
render template: 'comment/like_comment'
}
end
end
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def research
@title = I18n.t('home_controller.community_research')
end
end

# trashy... clean this up!
# this will eventually be based on the profile_tags data where people can mark their location with "location:lat,lon"
def nearby
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/like_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def liked?
result = NodeSelection.find_by_user_id_and_nid(current_user.uid, params[:id])
result = if result.nil?
false
else
else
result.liking
end
render json: result
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/map_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def update
@revision.title = params[:title]
@revision.body = params[:body]

params[:tags]&.split(',').each do |tagname|
params[:tags]&.split(',')&.each do |tagname|
@node.add_tag(tagname, current_user)
end

Expand Down Expand Up @@ -131,7 +131,7 @@ def create
main_image: params[:main_image])

if saved
params[:tags]&.split(',').each do |tagname|
params[:tags]&.split(',')&.each do |tagname|
@node.add_tag(tagname, current_user)
end

Expand Down
Loading

0 comments on commit 5e65d08

Please sign in to comment.