Migrate linter to rubocop-rails-omakase

This commit is contained in:
Marc Anguera Insa
2025-03-23 16:49:27 +01:00
parent 00c555eb16
commit b7ef4a6a95
27 changed files with 65 additions and 280 deletions

View File

@ -1,244 +1,25 @@
require: rubocop-rails
# Omakase Ruby styling for Rails
inherit_gem:
rubocop-rails-omakase: rubocop.yml
# Your own specialized rules go here
AllCops:
Exclude:
- db/schema.rb
- "db/**/*"
- "config/**/*"
Naming/AccessorMethodName:
Layout/SpaceInsideArrayLiteralBrackets:
Enabled: false
Rails/HttpPositionalArguments:
Enabled: true
Style/Alias:
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: false
Style/ArrayJoin:
Layout/CaseIndentation:
Enabled: false
Style/AsciiComments:
Layout/EndAlignment:
Enabled: false
Naming/AsciiIdentifiers:
Enabled: false
Style/Attr:
Enabled: false
Metrics/BlockNesting:
Enabled: false
Style/CaseEquality:
Enabled: false
Style/CharacterLiteral:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Metrics/ClassLength:
Enabled: false
Style/ClassVars:
Enabled: false
Style/CollectionMethods:
PreferredMethods:
find: detect
reduce: inject
collect: map
find_all: select
Style/ColonMethodCall:
Enabled: false
Style/CommentAnnotation:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Style/Documentation:
Enabled: false
Layout/DotPosition:
EnforcedStyle: trailing
Layout/ConditionPosition:
Enabled: false
Style/DoubleNegation:
Enabled: false
Style/EachWithObject:
Enabled: false
Style/EmptyLiteral:
Enabled: false
Style/Encoding:
Enabled: false
Style/EvenOdd:
Enabled: false
Naming/FileName:
Enabled: false
Style/FormatString:
Enabled: false
Style/GlobalVars:
Enabled: false
Style/GuardClause:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Style/IfWithSemicolon:
Enabled: false
Style/InlineComment:
Enabled: false
Style/Lambda:
Enabled: false
Style/LambdaCall:
Enabled: false
Style/LineEndConcatenation:
Enabled: false
Layout/LineLength:
Max: 100
Metrics/MethodLength:
Enabled: false
Style/ModuleFunction:
Enabled: false
Style/NegatedIf:
Enabled: false
Style/NegatedWhile:
Enabled: false
Style/Next:
Enabled: false
Style/NilComparison:
Enabled: false
Style/Not:
Enabled: false
Style/NumericLiterals:
Enabled: false
Style/OneLineConditional:
Enabled: false
Metrics/ParameterLists:
Layout/ElseAlignment:
Enabled: false
Style/PercentLiteralDelimiters:
Enabled: false
Style/PerlBackrefs:
Enabled: false
Naming/PredicateName:
ForbiddenPrefixes:
- is_
Style/Proc:
Enabled: false
Style/RaiseArgs:
Enabled: false
Style/RegexpLiteral:
Enabled: false
Style/SelfAssignment:
Enabled: false
Style/SingleLineBlockParams:
Enabled: false
Style/SingleLineMethods:
Enabled: false
Style/SignalException:
Enabled: false
Style/SpecialGlobalVars:
Enabled: false
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/VariableInterpolation:
Enabled: false
Style/TrailingCommaInArrayLiteral:
Enabled: false
Style/TrailingCommaInHashLiteral:
Enabled: false
Style/TrailingCommaInArguments:
Enabled: false
Style/TrivialAccessors:
Enabled: false
Style/WhenThen:
Enabled: false
Style/WhileUntilModifier:
Enabled: false
Lint/AmbiguousOperator:
Enabled: false
Lint/AmbiguousRegexpLiteral:
Enabled: false
Lint/AssignmentInCondition:
Enabled: false
Lint/DeprecatedClassMethods:
Enabled: false
Lint/ElseLayout:
Enabled: false
Lint/SuppressedException:
Enabled: false
Lint/LiteralInInterpolation:
Enabled: false
Lint/Loop:
Enabled: false
Lint/ParenthesesAsGroupedExpression:
Enabled: false
Lint/RequireParentheses:
Enabled: false
Lint/UnderscorePrefixedVariableName:
Enabled: false
Lint/Void:
Enabled: false
Lint/FlipFlop:
Enabled: false

View File

@ -45,8 +45,7 @@ end
group :development, :test do
gem 'byebug', '~> 11.0'
gem 'rubocop', '~> 1.6', require: false
gem 'rubocop-rails', '~> 2.9', require: false
gem 'rubocop-rails-omakase', require: false
gem 'dotenv-rails', '~> 3.1.7'
end

View File

@ -92,7 +92,7 @@ GEM
arbre (1.7.0)
activesupport (>= 3.0.0)
ruby2_keywords (>= 0.0.2)
ast (2.4.2)
ast (2.4.3)
autoprefixer-rails (10.4.19.0)
execjs (~> 2)
aws-eventstream (1.3.0)
@ -206,7 +206,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.9.1)
json (2.10.2)
json_translate (4.0.1)
activerecord (>= 4.2.0)
kaminari (1.2.2)
@ -221,11 +221,12 @@ GEM
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
language_server-protocol (3.17.0.3)
language_server-protocol (3.17.0.4)
launchy (2.5.2)
addressable (~> 2.8)
letter_opener (1.7.0)
launchy (~> 2.2)
lint_roller (1.1.0)
localeapp (3.3.0)
gli
i18n (>= 0.7, < 2)
@ -267,7 +268,7 @@ GEM
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.26.3)
parser (3.3.6.0)
parser (3.3.7.2)
ast (~> 2.4.1)
racc
pdf-core (0.10.0)
@ -378,23 +379,33 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.2)
rubocop (1.69.2)
rubocop (1.74.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
rubocop-rails (2.28.0)
rubocop-ast (1.41.0)
parser (>= 3.3.7.2)
rubocop-performance (1.24.0)
lint_roller (~> 1.1)
rubocop (>= 1.72.1, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rails (2.30.3)
activesupport (>= 4.2.0)
lint_roller (~> 1.1)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop (>= 1.72.1, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rails-omakase (1.1.0)
rubocop (>= 1.72)
rubocop-performance (>= 1.24)
rubocop-rails (>= 2.30)
ruby-progressbar (1.13.0)
ruby-vips (2.2.2)
ffi (~> 1.12)
@ -453,7 +464,7 @@ GEM
concurrent-ruby (~> 1.0)
uglifier (4.2.1)
execjs (>= 0.3.0, < 3)
unicode-display_width (3.1.3)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
useragent (0.16.11)
@ -513,8 +524,7 @@ DEPENDENCIES
rails-i18n (~> 7.0)
rdiscount (~> 2.2.7)
rspec-rails (~> 6.0)
rubocop (~> 1.6)
rubocop-rails (~> 2.9)
rubocop-rails-omakase
rubyzip (~> 2.3.0)
sassc-rails (~> 2.1.2)
select2-rails (~> 4.0.13)

View File

@ -101,12 +101,18 @@ In order to configure the application you can use the following ENV variables:
Any kind of feedback, bug report, idea or enhancement are really appreciated.
To contribute, just fork the repo, hack on it and send a pull request. Don't forget to add tests for behaviour changes and run the test suite:
To contribute, just fork the repo, hack on it and send a pull request. Don't forget to add tests for behaviour changes and run the test suite by:
```
bundle exec rspec
```
You can also run the linter by:
```
bundle exec rubocop
```
👉 Further information in our [Wiki](https://github.com/coopdevs/timeoverflow/wiki).
## License

View File

@ -4,7 +4,7 @@ module WithTransferParams
:destination,
:amount,
:reason,
:post_id,
:post_id
]
permitted_transfer_params.push(:source) if admin?

View File

@ -153,7 +153,7 @@ class StatisticsController < ApplicationController
35..44 => "35-44",
45..54 => "45-54",
55..64 => "55-64",
65..100 => "65+",
65..100 => "65+"
}
end

View File

@ -26,7 +26,7 @@
#
# From controllers, one can pass `self.class.helpers`, and from tests it is
# enough to use ApplicationController.new.view_context.
#
#
class ViewModel
attr_reader :object, :view, :routes
@ -36,4 +36,3 @@ class ViewModel
@routes = Rails.application.routes.url_helpers
end
end

View File

@ -13,7 +13,7 @@ module ApplicationHelper
end
def gravatar_url(user, size = 32)
gravatar_id = Digest::MD5::hexdigest(user.email).downcase
gravatar_id = Digest::MD5.hexdigest(user.email).downcase
gravatar_options = {
set: "set1",
gravatar: "hashed",

View File

@ -8,7 +8,7 @@ module GlyphHelper
"organization" => "tower"
}
def glyph(kind, title=nil)
def glyph(kind, title = nil)
kind = kind.to_s.underscore
content_tag :span, "",
class: "glyphicon glyphicon-#{glyph_name(kind)}",

View File

@ -1,7 +1,7 @@
module PostsHelper
def members_for_select(post)
members = current_organization.members.active.order("members.member_uid").
map { |mem| ["#{mem.member_uid} #{mem.user.to_s}", mem.user_id] }
map { |mem| ["#{mem.member_uid} #{mem.user}", mem.user_id] }
options_for_select(members, selected: post.user.id || current_user.id)
end

View File

@ -27,7 +27,7 @@ class Member < ApplicationRecord
delegate :balance, to: :account, prefix: true, allow_nil: true
delegate :gender, :date_of_birth, to: :user, prefix: true, allow_nil: true
scope :by_month, -> (month) { where(created_at: month.beginning_of_month..month.end_of_month) }
scope :by_month, ->(month) { where(created_at: month.beginning_of_month..month.end_of_month) }
scope :active, -> { where active: true }
scope :by_organization, ->(org) { where(organization_id: org) if org }

View File

@ -9,7 +9,7 @@ class Movement < ApplicationRecord
belongs_to :account, optional: true
belongs_to :transfer, optional: true
scope :by_month, -> (month) { where(created_at: month.beginning_of_month..month.end_of_month) }
scope :by_month, ->(month) { where(created_at: month.beginning_of_month..month.end_of_month) }
validates :amount, numericality: { other_than: 0 }

View File

@ -87,7 +87,7 @@ class User < ApplicationRecord
persister = ::Persister::MemberPersister.new(member)
persister.save
return member if member.persisted?
member if member.persisted?
end
def active?(organization)

View File

@ -22,4 +22,3 @@ module Operations
end
end
end

View File

@ -43,7 +43,7 @@ RSpec.describe InquiriesController do
expect do
post "create", params: { inquiry: { user: another_member.user,
category_id: test_category.id,
title: "New title" }}
title: "New title" } }
end.to change(Inquiry, :count).by(1)
end
end

View File

@ -37,7 +37,7 @@ RSpec.describe MultiTransfersController, type: :controller do
post :step, params: params.merge!(
step: 5,
transfer: {amount: 3600, reason: 'because of reasons'}
transfer: { amount: 3600, reason: 'because of reasons' }
)
post :create, params: params
@ -69,7 +69,7 @@ RSpec.describe MultiTransfersController, type: :controller do
post :step, params: params.merge!(
step: 5,
transfer: {amount: 3600, reason: 'because of reasons'}
transfer: { amount: 3600, reason: 'because of reasons' }
)
post :create, params: params
@ -102,7 +102,7 @@ RSpec.describe MultiTransfersController, type: :controller do
post :step, params: params.merge!(
step: 5,
transfer: {amount: 3600, reason: 'because of reasons'}
transfer: { amount: 3600, reason: 'because of reasons' }
)
post :create, params: params
@ -128,4 +128,3 @@ RSpec.describe MultiTransfersController, type: :controller do
end
end
end

View File

@ -200,7 +200,6 @@ RSpec.describe OffersController, type: :controller do
get :show, params: { id: offer.id }
expect(assigns(:offer)).to eq(offer)
end
end
end

View File

@ -267,7 +267,6 @@ RSpec.describe UsersController do
describe "POST #create" do
context "with empty email" do
subject do
post "create", params: { user: Fabricate.to_params(:user,
username: user.username + "2",
@ -279,7 +278,6 @@ RSpec.describe UsersController do
before { login(admin_user) }
it "can create a user with empty email and generates dummy email" do
expect { subject }.to change(User, :count).by(1)
u = User.find_by(username: user.username + "2")
@ -335,7 +333,6 @@ RSpec.describe UsersController do
user.valid?
expect(user.errors[:email]).not_to be_empty
end
end
context 'with no logged user' do

View File

@ -32,7 +32,7 @@ RSpec.describe MemberDecorator do
describe '#link_to_self' do
subject { decorator.link_to_self }
it { is_expected.to match("members/#{member.user.id}")}
it { is_expected.to match("members/#{member.user.id}") }
end
describe '#mail_to' do
@ -84,16 +84,16 @@ RSpec.describe MemberDecorator do
describe '#toggle_manager_member_path' do
subject { decorator.toggle_manager_member_path }
it { is_expected.to include("members/#{member.id}/toggle_manager")}
it { is_expected.to include("members/#{member.id}/toggle_manager") }
end
describe '#cancel_member_path' do
subject { decorator.cancel_member_path }
it { is_expected.to include("members/#{member.id}")}
it { is_expected.to include("members/#{member.id}") }
end
describe '#toggle_active_member_path' do
subject { decorator.toggle_active_member_path }
it { is_expected.to include("members/#{member.id}/toggle_active")}
it { is_expected.to include("members/#{member.id}/toggle_active") }
end
end

View File

@ -1,3 +1,3 @@
Fabricator(:organization) do
name { Faker::Company.name }
end
end

View File

@ -14,7 +14,6 @@ Fabricator(:inquiry) do
description { Faker::Lorem.paragraph }
category { Fabricate(:category) }
active { true }
end
Fabricator(:offer) do

View File

@ -4,7 +4,7 @@ Fabricator(:user) do
date_of_birth { DateTime.now.utc }
phone { Faker::PhoneNumber.phone_number }
alt_phone { Faker::PhoneNumber.cell_phone }
address { Faker::Address.street_address + " " + Faker::Address.zip_code + " " + Faker::Address.city + " (" + Faker::Address.state + ")"}
address { Faker::Address.street_address + " " + Faker::Address.zip_code + " " + Faker::Address.city + " (" + Faker::Address.state + ")" }
gender { ["male", "female"].shuffle.first }
description { Faker::Lorem.paragraph }
last_sign_in_at { DateTime.new(2018, 10, 1) }

View File

@ -32,4 +32,3 @@ RSpec.feature 'create offer' do
end
end
end

View File

@ -16,7 +16,7 @@ RSpec.describe ApplicationHelper do
it 'returns url to gravatar when there is no avatar attached' do
user = Fabricate(:user)
gravatar_id = Digest::MD5::hexdigest(user.email).downcase
gravatar_id = Digest::MD5.hexdigest(user.email).downcase
expect(helper.avatar_url(user, 50)).to eq("https://www.gravatar.com/avatar/#{gravatar_id}.png?d=identicon&gravatar=hashed&set=set1&size=50x50")
end

View File

@ -9,7 +9,7 @@ RSpec.describe PostsHelper do
end
it "returns organization active members with member_uid and name" do
expect(helper.members_for_select(offer)).to match(/<option selected.*>#{member.member_uid} #{member.user.to_s}<\/option>/)
expect(helper.members_for_select(offer)).to match(/<option selected.*>#{member.member_uid} #{member.user}<\/option>/)
end
end
end

View File

@ -24,4 +24,3 @@ RSpec.describe Operations::Transfers::OneToMany do
end
end
end

View File

@ -37,4 +37,3 @@ RSpec.describe Operations::Transfers do
end
end
end