Merge pull request #3799 from consul/rubocop_all

Merge basic and standard rubocop files in one file
This commit is contained in:
Javier Martín
2019-10-25 23:50:15 +02:00
committed by GitHub
19 changed files with 378 additions and 372 deletions

View File

@@ -1,6 +1,6 @@
rubocop:
config_file: .rubocop_basic.yml
version: 0.72.0
config_file: .rubocop.yml
version: 0.75.0
scss:
config_file: .scss-lint.yml
erblint:

View File

@@ -1,4 +1,172 @@
inherit_from: .rubocop_basic.yml
require:
- rubocop-performance
- rubocop-rails
- rubocop-rspec
AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
Exclude:
- "db/schema.rb"
DisabledByDefault: true
Bundler/DuplicatedGem:
Enabled: true
Bundler/OrderedGems:
Enabled: true
Capybara/CurrentPathExpectation:
Enabled: true
Capybara/FeatureMethods:
Enabled: true
EnabledMethods:
- scenario
- xscenario
FactoryBot/AttributeDefinedStatically:
Enabled: true
Layout/EmptyLineAfterGuardClause:
Enabled: true
Layout/EmptyLineBetweenDefs:
Enabled: true
Layout/EmptyLines:
Enabled: true
Layout/EmptyLinesAroundAccessModifier:
Enabled: true
Layout/EmptyLinesAroundBlockBody:
Enabled: true
Layout/EmptyLinesAroundClassBody:
Enabled: true
Layout/EmptyLinesAroundMethodBody:
Enabled: true
Layout/EmptyLinesAroundModuleBody:
Enabled: true
Layout/EndOfLine:
EnforcedStyle: lf
Layout/ExtraSpacing:
Enabled: true
Layout/IndentationConsistency:
EnforcedStyle: indented_internal_methods
Layout/IndentationWidth:
Enabled: true
Layout/MultilineBlockLayout:
Enabled: true
Layout/SpaceAfterColon:
Enabled: true
Layout/SpaceAfterComma:
Enabled: true
Layout/SpaceAfterMethodName:
Enabled: true
Layout/SpaceAfterNot:
Enabled: true
Layout/SpaceAfterSemicolon:
Enabled: true
Layout/SpaceAroundBlockParameters:
Enabled: true
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true
Layout/SpaceAroundOperators:
Enabled: true
Layout/SpaceBeforeBlockBraces:
Enabled: true
Layout/SpaceBeforeComma:
Enabled: true
Layout/SpaceBeforeComment:
Enabled: true
Layout/SpaceBeforeFirstArg:
Enabled: true
Layout/SpaceBeforeSemicolon:
Enabled: true
Layout/SpaceInsideArrayLiteralBrackets:
Enabled: true
Layout/SpaceInsideArrayPercentLiteral:
Enabled: true
Layout/SpaceInsideBlockBraces:
Enabled: true
Layout/SpaceInsideHashLiteralBraces:
Enabled: true
EnforcedStyle: compact
Layout/SpaceInsideParens:
Enabled: true
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: true
Layout/SpaceInsideRangeLiteral:
Enabled: true
Layout/SpaceInsideReferenceBrackets:
Enabled: true
Layout/SpaceInsideStringInterpolation:
Enabled: true
Layout/Tab:
Enabled: true
Layout/TrailingBlankLines:
Enabled: true
Layout/TrailingWhitespace:
Enabled: true
Lint/AmbiguousRegexpLiteral:
Enabled: true
Lint/DuplicateMethods:
Enabled: true
Lint/LiteralAsCondition:
Enabled: true
Lint/ParenthesesAsGroupedExpression:
Enabled: true
Lint/ShadowingOuterLocalVariable:
Enabled: true
Lint/StringConversionInInterpolation:
Enabled: true
Lint/UselessAssignment:
Enabled: true
Metrics/LineLength:
Max: 110
Severity: refactor
Performance/CompareWithBlock:
Enabled: true
@@ -15,17 +183,186 @@ Performance/EndWith:
Performance/StartWith:
Enabled: true
Rails/HasManyOrHasOneDependent:
Rails/ActionFilter:
Enabled: true
Rails/ApplicationJob:
Enabled: true
Rails/ApplicationRecord:
Enabled: true
Rails/CreateTableWithTimestamps:
Enabled: true
Exclude:
- "db/migrate/201[5-8]*"
Rails/Date:
Enabled: true
Rails/DynamicFindBy:
Enabled: true
Severity: refactor
Rails/EnumUniqueness:
Enabled: true
Rails/EnvironmentComparison:
Enabled: true
Rails/FindBy:
Enabled: true
Rails/FindEach:
Enabled: true
Rails/HasAndBelongsToMany:
Enabled: true
Rails/HasManyOrHasOneDependent:
Enabled: true
Severity: refactor
Rails/HttpPositionalArguments:
Enabled: true
Rails/InverseOf:
Enabled: true
Exclude:
- "app/models/related_content.rb"
Rails/NotNullColumn:
Enabled: true
Exclude:
- "db/migrate/201[5-7]*"
Rails/OutputSafety:
Enabled: true
Severity: warning
Exclude:
- app/helpers/text_with_links_helper.rb
Rails/PluralizationGrammar:
Enabled: true
Rails/Presence:
Enabled: true
Rails/RelativeDateConstant:
Enabled: true
Rails/RequestReferer:
Enabled: true
Rails/ReversibleMigration:
Enabled: true
Rails/SafeNavigation:
Enabled: true
ConvertTry: true
Rails/SaveBang:
Enabled: true
Severity: refactor
Rails/SkipsModelValidations:
Enabled: true
Blacklist:
- update_attribute
Exclude:
- lib/acts_as_paranoid_aliases.rb
Rails/TimeZone:
Enabled: true
Rails/UnknownEnv:
Enabled: true
Environments:
- development
- test
- production
- preproduction
- staging
Rails/Validation:
Enabled: true
RSpec/AroundBlock:
Enabled: true
RSpec/BeforeAfterAll:
Enabled: true
RSpec/DescribedClass:
Enabled: true
EnforcedStyle: explicit
RSpec/EmptyExampleGroup:
Enabled: true
Exclude:
- spec/factories/**/*
RSpec/EmptyLineAfterExampleGroup:
Enabled: true
Exclude:
- spec/factories/**/*
RSpec/ExampleWording:
Enabled: true
RSpec/Focus:
Enabled: true
RSpec/HookArgument:
Enabled: true
RSpec/InstanceVariable:
Enabled: true
Exclude:
- spec/controllers/concerns/has_filters_spec.rb
- spec/controllers/concerns/has_orders_spec.rb
RSpec/LetBeforeExamples:
Enabled: true
RSpec/LetSetup:
Enabled: true
RSpec/NotToNot:
Enabled: true
RSpec/OverwritingSetup:
Enabled: true
RSpec/RepeatedExample:
Enabled: true
RSpec/ScatteredLet:
Enabled: true
RSpec/ScatteredSetup:
Enabled: true
RSpec/VoidExpect:
Enabled: true
Security/Eval:
Enabled: true
Security/JSONLoad:
Enabled: true
Security/MarshalLoad:
Enabled: true
Security/YAMLLoad:
Enabled: true
Style/BlockDelimiters:
Enabled: true
Style/PercentLiteralDelimiters:
Enabled: true
Style/SafeNavigation:
Enabled: true
Style/StringLiterals:
EnforcedStyle: double_quotes

View File

@@ -1,338 +0,0 @@
require:
- rubocop-performance
- rubocop-rails
- rubocop-rspec
AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
Exclude:
- "db/schema.rb"
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Bundler/DuplicatedGem:
Enabled: true
Bundler/OrderedGems:
Enabled: true
Capybara/CurrentPathExpectation:
Enabled: true
Capybara/FeatureMethods:
Enabled: true
EnabledMethods:
- scenario
- xscenario
FactoryBot/AttributeDefinedStatically:
Enabled: true
Layout/EmptyLineAfterGuardClause:
Enabled: true
Layout/EmptyLineBetweenDefs:
Enabled: true
Layout/EmptyLinesAroundAccessModifier:
Enabled: true
Layout/EmptyLinesAroundBlockBody:
Enabled: true
Layout/EmptyLinesAroundClassBody:
Enabled: true
Layout/EmptyLinesAroundMethodBody:
Enabled: true
Layout/EmptyLinesAroundModuleBody:
Enabled: true
Layout/ExtraSpacing:
Enabled: true
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true
Layout/IndentationConsistency:
EnforcedStyle: indented_internal_methods
Layout/IndentationWidth:
Enabled: true
Layout/EmptyLines:
Enabled: true
Layout/EndOfLine:
EnforcedStyle: lf
Layout/MultilineBlockLayout:
Enabled: true
Layout/SpaceAfterColon:
Enabled: true
Layout/SpaceAfterComma:
Enabled: true
Layout/SpaceAfterMethodName:
Enabled: true
Layout/SpaceAfterNot:
Enabled: true
Layout/SpaceAfterSemicolon:
Enabled: true
Layout/SpaceAroundBlockParameters:
Enabled: true
Layout/SpaceAroundOperators:
Enabled: true
Layout/SpaceBeforeBlockBraces:
Enabled: true
Layout/SpaceBeforeComma:
Enabled: true
Layout/SpaceBeforeComment:
Enabled: true
Layout/SpaceBeforeFirstArg:
Enabled: true
Layout/SpaceBeforeSemicolon:
Enabled: true
Layout/SpaceInsideArrayLiteralBrackets:
Enabled: true
Layout/SpaceInsideArrayPercentLiteral:
Enabled: true
Layout/SpaceInsideBlockBraces:
Enabled: true
Layout/SpaceInsideHashLiteralBraces:
Enabled: true
EnforcedStyle: compact
Layout/SpaceInsideParens:
Enabled: true
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: true
Layout/SpaceInsideRangeLiteral:
Enabled: true
Layout/SpaceInsideReferenceBrackets:
Enabled: true
Layout/SpaceInsideStringInterpolation:
Enabled: true
Layout/Tab:
Enabled: true
Layout/TrailingBlankLines:
Enabled: true
Layout/TrailingWhitespace:
Enabled: true
Lint/AmbiguousRegexpLiteral:
Enabled: true
Lint/DuplicateMethods:
Enabled: true
Lint/LiteralAsCondition:
Enabled: true
Lint/ParenthesesAsGroupedExpression:
Enabled: true
Lint/ShadowingOuterLocalVariable:
Enabled: true
Lint/StringConversionInInterpolation:
Enabled: true
Lint/UselessAssignment:
Enabled: true
Metrics/LineLength:
Max: 110
Severity: refactor
Rails/ActionFilter:
Enabled: true
Rails/ApplicationJob:
Enabled: true
Rails/ApplicationRecord:
Enabled: true
Rails/CreateTableWithTimestamps:
Enabled: true
Exclude:
- "db/migrate/201[5-8]*"
Rails/Date:
Enabled: true
Rails/DynamicFindBy:
Enabled: true
Severity: refactor
Rails/EnumUniqueness:
Enabled: true
Rails/EnvironmentComparison:
Enabled: true
Rails/FindBy:
Enabled: true
Rails/FindEach:
Enabled: true
Rails/HttpPositionalArguments:
Enabled: true
Rails/HasAndBelongsToMany:
Enabled: true
Rails/InverseOf:
Enabled: true
Exclude:
- "app/models/related_content.rb"
Rails/NotNullColumn:
Enabled: true
Exclude:
- "db/migrate/201[5-7]*"
Rails/OutputSafety:
Enabled: true
Severity: warning
Exclude:
- app/helpers/text_with_links_helper.rb
Rails/PluralizationGrammar:
Enabled: true
Rails/Presence:
Enabled: true
Rails/RelativeDateConstant:
Enabled: true
Rails/RequestReferer:
Enabled: true
Rails/ReversibleMigration:
Enabled: true
Rails/SafeNavigation:
Enabled: true
ConvertTry: true
Rails/SaveBang:
Enabled: true
Severity: refactor
Rails/TimeZone:
Enabled: true
Rails/UnknownEnv:
Enabled: true
Environments:
- development
- test
- production
- preproduction
- staging
Rails/Validation:
Enabled: true
RSpec/AroundBlock:
Enabled: true
RSpec/BeforeAfterAll:
Enabled: true
RSpec/DescribedClass:
Enabled: true
EnforcedStyle: explicit
RSpec/EmptyExampleGroup:
Enabled: true
Exclude:
- spec/factories/**/*
RSpec/EmptyLineAfterExampleGroup:
Enabled: true
Exclude:
- spec/factories/**/*
RSpec/ExampleWording:
Enabled: true
RSpec/Focus:
Enabled: true
RSpec/HookArgument:
Enabled: true
RSpec/InstanceVariable:
Enabled: true
Exclude:
- spec/controllers/concerns/has_filters_spec.rb
- spec/controllers/concerns/has_orders_spec.rb
RSpec/LetBeforeExamples:
Enabled: true
RSpec/LetSetup:
Enabled: true
RSpec/NotToNot:
Enabled: true
RSpec/OverwritingSetup:
Enabled: true
RSpec/RepeatedExample:
Enabled: true
RSpec/ScatteredLet:
Enabled: true
RSpec/ScatteredSetup:
Enabled: true
RSpec/VoidExpect:
Enabled: true
Security/Eval:
Enabled: true
Style/BlockDelimiters:
Enabled: true
Style/PercentLiteralDelimiters:
Enabled: true
Style/SafeNavigation:
Enabled: true
Style/StringLiterals:
EnforcedStyle: double_quotes

View File

@@ -36,12 +36,12 @@ class DebatesController < ApplicationController
end
def unmark_featured
@debate.update_attribute(:featured_at, nil)
@debate.update!(featured_at: nil)
redirect_to request.query_parameters.merge(action: :index)
end
def mark_featured
@debate.update_attribute(:featured_at, Time.current)
@debate.update!(featured_at: Time.current)
redirect_to request.query_parameters.merge(action: :index)
end

View File

@@ -11,7 +11,7 @@ class Budget
include Globalizable
include Sanitizable
belongs_to :budget
belongs_to :budget, touch: true
belongs_to :next_phase, class_name: self.name, inverse_of: :prev_phase
has_one :prev_phase, class_name: self.name, foreign_key: :next_phase_id, inverse_of: :next_phase
@@ -24,7 +24,6 @@ class Budget
validate :next_phase_dates_valid?
after_save :adjust_date_ranges
after_save :touch_budget
scope :enabled, -> { where(enabled: true) }
scope :published, -> { enabled.where.not(kind: "drafting") }
@@ -70,10 +69,6 @@ class Budget
end
end
def touch_budget
budget.touch
end
def prev_phase_dates_valid?
if enabled? && starts_at.present? && prev_enabled_phase.present?
prev_enabled_phase.assign_attributes(ends_at: starts_at)

View File

@@ -21,7 +21,7 @@ class Poll::Question::Answer < ApplicationRecord
def self.order_answers(ordered_array)
ordered_array.each_with_index do |answer_id, order|
find(answer_id).update_attribute(:given_order, (order + 1))
find(answer_id).update_column(:given_order, (order + 1))
end
end

View File

@@ -27,7 +27,7 @@ describe CommentsController do
it "does not create a comment if the comments are closed" do
sign_in user
legal_process.update_attribute(:debate_end_date, Date.current - 1.day)
legal_process.update!(debate_end_date: Date.current - 1.day)
expect do
post :create, xhr: true,

View File

@@ -81,7 +81,7 @@ describe Legislation::AnnotationsController do
it "does not create an annotation if the process allegations phase is not open" do
sign_in user
legal_process.update_attribute(:allegations_end_date, Date.current - 1.day)
legal_process.update!(allegations_end_date: Date.current - 1.day)
expect do
post :create, xhr: true,

View File

@@ -41,7 +41,7 @@ describe Legislation::AnswersController do
it "does not create an answer if the process debate phase is not open" do
sign_in user
legal_process.update_attribute(:debate_end_date, Date.current - 1.day)
legal_process.update!(debate_end_date: Date.current - 1.day)
expect do
post :create, xhr: true,

View File

@@ -23,7 +23,7 @@ describe "Admin Notifications" do
scenario "Notification with invalid segment recipient" do
invalid_notification = create(:admin_notification)
invalid_notification.update_attribute(:segment_recipient, "invalid_segment")
invalid_notification.update_column(:segment_recipient, "invalid_segment")
visit admin_admin_notification_path(invalid_notification)
@@ -56,7 +56,7 @@ describe "Admin Notifications" do
scenario "Notifications with invalid segment recipient" do
invalid_notification = create(:admin_notification)
invalid_notification.update_attribute(:segment_recipient, "invalid_segment")
invalid_notification.update_column(:segment_recipient, "invalid_segment")
visit admin_admin_notifications_path
@@ -209,7 +209,7 @@ describe "Admin Notifications" do
scenario "Admin notification with invalid segment recipient cannot be sent", :js do
invalid_notification = create(:admin_notification)
invalid_notification.update_attribute(:segment_recipient, "invalid_segment")
invalid_notification.update_column(:segment_recipient, "invalid_segment")
visit admin_admin_notification_path(invalid_notification)
expect(page).not_to have_link("Send")

View File

@@ -1832,7 +1832,7 @@ describe "Admin budget investments" do
end
scenario "Select an investment when some columns are not displayed", :js do
investment.update_attribute(:title, "Don't display me, please!")
investment.update!(title: "Don't display me, please!")
visit admin_budget_budget_investments_path(budget)
within("#js-columns-selector") { find("strong", text: "Columns").click }

View File

@@ -19,7 +19,7 @@ describe "Admin download user emails" do
admin_without_email = create(:user, newsletter: true, email: "no_email@consul.dev")
create(:administrator, user: admin_without_email)
admin_without_email.update_attribute(:email, nil)
admin_without_email.update_column(:email, nil)
end
scenario "returns the selected users segment csv file" do

View File

@@ -23,7 +23,7 @@ describe "Admin newsletter emails" do
scenario "Invalid newsletter" do
invalid_newsletter = create(:newsletter)
invalid_newsletter.update_attribute(:segment_recipient, "invalid_segment")
invalid_newsletter.update_column(:segment_recipient, "invalid_segment")
visit admin_newsletter_path(invalid_newsletter)
@@ -50,7 +50,7 @@ describe "Admin newsletter emails" do
scenario "Invalid newsletter" do
invalid_newsletter = create(:newsletter)
invalid_newsletter.update_attribute(:segment_recipient, "invalid_segment")
invalid_newsletter.update_column(:segment_recipient, "invalid_segment")
visit admin_newsletters_path
@@ -136,7 +136,7 @@ describe "Admin newsletter emails" do
scenario "Invalid newsletter cannot be sent", :js do
invalid_newsletter = create(:newsletter)
invalid_newsletter.update_attribute(:segment_recipient, "invalid_segment")
invalid_newsletter.update_column(:segment_recipient, "invalid_segment")
visit admin_newsletter_path(invalid_newsletter)
expect(page).not_to have_link("Send")

View File

@@ -94,7 +94,7 @@ describe "Legislation" do
end
scenario "cannot answer question when phase not open" do
process.update_attribute(:debate_end_date, Date.current - 1.day)
process.update!(debate_end_date: Date.current - 1.day)
question = process.questions.first
create(:legislation_question_option, question: question, value: "Yes")
create(:legislation_question_option, question: question, value: "No")

View File

@@ -133,7 +133,7 @@ describe EmailDigest do
it "returns false if email does not exist" do
user = create(:user)
user.update_attribute(:email, nil)
user.email = nil
email_digest = EmailDigest.new(user)
expect(email_digest.valid_email?).to be(false)

View File

@@ -989,7 +989,7 @@ describe Budget::Investment do
user.erase
user.update!(document_number: nil)
expect(user.document_number).to be_blank
investment.touch
investment.valid?
expect(investment.responsible_name).to eq("123456")
end
end

View File

@@ -115,6 +115,18 @@ describe Budget::Phase do
end
end
describe "#save" do
it "touches the budget when it's updated" do
budget = create(:budget)
travel(10.seconds) do
budget.current_phase.update!(enabled: false)
expect(budget.updated_at).to eq Time.current
end
end
end
describe "#adjust_date_ranges" do
let(:prev_enabled_phase) { second_phase.prev_enabled_phase }
let(:next_enabled_phase) { second_phase.next_enabled_phase }

View File

@@ -13,11 +13,11 @@ shared_examples_for "globalizable" do |factory_name|
let(:attribute) { required_fields.sample || fields.sample }
before do
record.update_attribute(attribute, "In English")
record.update!(attribute => "In English")
I18n.with_locale(:es) do
record.update!(required_fields.map { |field| [field, "En español"] }.to_h)
record.update_attribute(attribute, "En español")
record.update!(attribute => "En español")
end
record.reload
@@ -156,7 +156,7 @@ shared_examples_for "globalizable" do |factory_name|
before do
I18n.with_locale(:de) do
record.update!(required_fields.map { |field| [field, "Deutsch"] }.to_h)
record.update_attribute(attribute, "Deutsch")
record.update!(attribute => "Deutsch")
end
end

View File

@@ -253,7 +253,7 @@ describe Proposal do
proposal = create(:proposal)
tag_list = ["tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7"]
proposal.update_attribute(:tag_list, tag_list)
proposal.update!(tag_list: tag_list)
expect(proposal.update_cached_votes).to eq(true)
end