Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@ jobs:
rspec:
runs-on: ubuntu-latest
environment: test
container:
image: ruby:3.0.6

steps:
- uses: actions/checkout@v1

- name: Gem cache
id: cache-bundle
uses: actions/cache@v1
- uses: ruby/setup-ruby@v1
with:
path: vendor/bundle
key: bundle-${{ hashFiles('**/Gemfile.lock') }}

- name: Bundle install
env:
RAILS_ENV: test
run: |
bundle install
ruby-version: '3.1' # Not needed with a .ruby-version, .tool-versions or mise.toml
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Run tests
env:
Expand All @@ -34,24 +24,14 @@ jobs:
rubocop:
runs-on: ubuntu-latest
environment: test
container:
image: ruby:3.0.6

steps:
- uses: actions/checkout@v1

- name: Gem cache
id: cache-bundle
uses: actions/cache@v1
- uses: ruby/setup-ruby@v1
with:
path: vendor/bundle
key: bundle-${{ hashFiles('**/Gemfile.lock') }}

- name: Bundle install
env:
RAILS_ENV: test
run: |
bundle install
ruby-version: '3.1' # Not needed with a .ruby-version, .tool-versions or mise.toml
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Run Rubocop
run: bundle exec rubocop
42 changes: 25 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
ast (2.4.3)
diff-lcs (1.5.0)
parallel (1.24.0)
parser (3.3.0.5)
json (2.15.2)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
parallel (1.27.0)
parser (3.3.10.0)
ast (~> 2.4.1)
racc
racc (1.7.3)
prism (1.6.0)
racc (1.8.1)
rainbow (3.1.1)
rake (12.3.3)
regexp_parser (2.9.0)
rexml (3.3.9)
regexp_parser (2.11.3)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
Expand All @@ -30,19 +33,24 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.31.0)
rubocop (1.81.0)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.18.0, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.47.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
ruby-progressbar (1.13.0)
unicode-display_width (2.5.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.1.0)

PLATFORMS
ruby
Expand All @@ -51,7 +59,7 @@ DEPENDENCIES
mavenlint!
rake (= 12.3.3)
rspec (= 3.12)
rubocop (= 1.31)
rubocop (= 1.81)

BUNDLED WITH
2.2.33
2.6.9
8 changes: 3 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task default: :spec
end
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task default: :spec
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/belongs_to_dependent_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Mavenlint
# end
#
# It is advised to put the dependent option on the other side of the association
class BelongsToDependentOption < RuboCop::Cop::Cop
class BelongsToDependentOption < RuboCop::Cop::Base
MSG = 'Do not use the dependent option with belongs_to associations. The option should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent'

def_node_matcher :bad_belongs_to?, <<~PATTERN
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/bigint_for_migration_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module RuboCop
module Cop
module Mavenlint
# Enforces that foreign key columns are bigint type
class BigIntForMigrationKeys < RuboCop::Cop::Cop
class BigIntForMigrationKeys < RuboCop::Cop::Base
FK_VIOLATION_MSG = 'Foreign keys must be of type BIGINT'
PK_VIOLATION_MSG = 'Primary keys must be of type BIGINT'

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/direct_factory_bot_invocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Cop
module Mavenlint
# Prevents invocation of factory bot directly and instead
# suggests user use the `create.a(:model)` pattern
class DirectFactoryBotInvocation < RuboCop::Cop::Cop
class DirectFactoryBotInvocation < RuboCop::Cop::Base
MSG = 'Direct calls to FactoryBot should be replaced with Mavenlink::ModelFactories calls'
FACTORY_BOT_METHODS = %i[create build].freeze

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/no_dependent_destroy_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Mavenlint
#
# Allowing deletion of account through active record associations can cause cascading data deletions. Account
# is a root object and shouldn't be deleted via active record associations
class NoDependentDestroyAccount < RuboCop::Cop::Cop
class NoDependentDestroyAccount < RuboCop::Cop::Base
MSG = 'Do not add an association to account with dependent destroy. The destroy should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent'

ASSOCIATIONS = %i[belongs_to has_many has_one has_and_belongs_to_many].freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/require_slow_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module RuboCop
module Cop
module Mavenlint
# Prevents use of slow capybara matchers
class RequireSlowHelpers < RuboCop::Cop::Cop
class RequireSlowHelpers < RuboCop::Cop::Base
MSG = 'Specs in the unit directory should not require rails_helper or spec_helper'
SLOW_HELPERS = %w[spec_helper rails_helper].freeze

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/unsafe_mass_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Mavenlint
# Allowing mass assignment of a foreign key column is dangerous for models that are created
# or updated through a publicly accessible endpoint, because the associated model isn't
# necessarily loaded and ran through security checks.
class UnsafeMassAssignment < RuboCop::Cop::Cop
class UnsafeMassAssignment < RuboCop::Cop::Base
MSG = 'Do not allow mass-assignment of foreign key columns. See https://github.com/mavenlink/welcome/wiki/Lint-Errors#unsafemassassignment'

def on_send(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/use_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Mavenlint
# class SomeApiController < ApiController
# end
#
class UseApiController < RuboCop::Cop::Cop
class UseApiController < RuboCop::Cop::Base
MSG = 'Api Controllers should subclass `ApiController`.'
SUPERCLASS = 'ApiController'
BASE_PATTERN = '(const nil? :ApplicationController)'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/use_application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Mavenlint
# class SomeController < ApplicationController
# end
#
class UseApplicationController < RuboCop::Cop::Cop
class UseApplicationController < RuboCop::Cop::Base
MSG = 'Controllers should subclass `ApplicationController`.'
SUPERCLASS = 'ApplicationController'
BASE_PATTERN = '(const (const nil? :ActionController) :Base)'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/use_application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Mavenlint
# remove this custom cop and enable the built-in one.
# @see https://github.com/bbatsov/rubocop/blob/10a7041d23bcd579821b378dd351aeead7c3f082/lib/rubocop/cop/rails/application_record.rb
#
class UseApplicationRecord < RuboCop::Cop::Cop
class UseApplicationRecord < RuboCop::Cop::Base
MSG = 'Models should subclass `ApplicationRecord`.'
SUPERCLASS = 'ApplicationRecord'
BASE_PATTERN = '(const (const nil? :ActiveRecord) :Base)'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mavenlint/use_fast_capybara_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Mavenlint
# expect(page).to have_no_text('Hi')
#
# Which will pass as soon as the text is not detected without any timeout.
class UseFastCapybaraMatchers < RuboCop::Cop::Cop
class UseFastCapybaraMatchers < RuboCop::Cop::Base
MSG = 'Use a `to have_no_*` selector. See https://github.com/mavenlink/welcome/wiki/Lint-Errors#usefastcapybaramatchers'
CAPYBARA_MATCHERS = %i[have_button have_checked_field have_content have_css have_field have_link have_select
have_selector have_table have_text have_unchecked_field have_xpath].freeze
Expand Down
2 changes: 1 addition & 1 deletion mavenlint.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'rake', '12.3.3'
s.add_development_dependency 'rspec', '3.12'
s.add_development_dependency 'rubocop', '1.31'
s.add_development_dependency 'rubocop', '1.81'

s.required_ruby_version = '~> 3.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it 'registers an offense when belongs_to is invoked with the dependent option' do
expect_offense(<<~RUBY)
belongs_to :workspace, inverse_of: :foo, dependent: :destroy_all, autosave: true
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use the dependent option with belongs_to associations. The option should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/BelongsToDependentOption: Do not use the dependent option with belongs_to associations. The option should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent
RUBY
end

Expand Down
12 changes: 6 additions & 6 deletions spec/rubocop/cop/mavenlint/bigint_for_migration_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
expect_offense(<<~RUBY)
def up
change_column :preferences, :subject_id, :integer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Foreign keys must be of type BIGINT
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/BigIntForMigrationKeys: Foreign keys must be of type BIGINT
end
RUBY
end
Expand All @@ -32,7 +32,7 @@ def up
expect_offense(<<~RUBY)
def up
change_column :preferences, :id, :integer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Primary keys must be of type BIGINT
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/BigIntForMigrationKeys: Primary keys must be of type BIGINT
end
RUBY
end
Expand All @@ -53,7 +53,7 @@ def up
expect_offense(<<~RUBY)
def up
add_column :preferences, :subject_id, :integer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Foreign keys must be of type BIGINT
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/BigIntForMigrationKeys: Foreign keys must be of type BIGINT
end
RUBY
end
Expand All @@ -72,7 +72,7 @@ def up
expect_offense(<<~RUBY)
def up
add_column :preferences, :id, :integer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Primary keys must be of type BIGINT
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/BigIntForMigrationKeys: Primary keys must be of type BIGINT
end
RUBY
end
Expand All @@ -92,7 +92,7 @@ def up
it 'registers an offense when table is created with integer pk' do
expect_offense(<<~RUBY)
create_table "access_control_analytics_reports_claims", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Primary keys must be of type BIGINT
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/BigIntForMigrationKeys: Primary keys must be of type BIGINT
t.string "report_name", null: false
end
RUBY
Expand All @@ -105,7 +105,7 @@ def up
def change
create_table :new_account_invitations do |t|
t.integer :inviter_id, null: false
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Foreign keys must be of type BIGINT
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/BigIntForMigrationKeys: Foreign keys must be of type BIGINT
t.string :email_address, null: false
t.string :token, null: false, :limit => 36
t.timestamps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
it 'registers an offense when FactoryBot.create is used' do
expect_offense(<<~RUBY)
FactoryBot.create(:maven_participation, foo: 'bar')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Direct calls to FactoryBot should be replaced with Mavenlink::ModelFactories calls
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/DirectFactoryBotInvocation: Direct calls to FactoryBot should be replaced with Mavenlink::ModelFactories calls
RUBY
end

it 'registers an offense when FactoryBot.build is used' do
expect_offense(<<~RUBY)
FactoryBot.build(:maven_participation, foo: 'bar')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Direct calls to FactoryBot should be replaced with Mavenlink::ModelFactories calls
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/DirectFactoryBotInvocation: Direct calls to FactoryBot should be replaced with Mavenlink::ModelFactories calls
RUBY
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
dependent_destructives.each do |destructive|
%i[account accounts].each do |model|
it "registers an offense when #{association} :account has dependent: :#{destructive} option" do
message = ' Do not add an association to account with dependent destroy. The destroy should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent'
message = ' Mavenlint/NoDependentDestroyAccount: Do not add an association to account with dependent destroy. The destroy should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent'
ruby_code = "#{association} :#{model}, inverse_of: :foo, dependent: :#{destructive}, autosave: true"

message = message.rjust(ruby_code.length + message.length, '^')
Expand All @@ -34,19 +34,19 @@
it 'protects class name Account from dependent: :destroy' do
expect_offense(<<~RUBY)
belongs_to :invitee_account, dependent: :destroy, class_name: "Account"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not add an association to account with dependent destroy. The destroy should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/NoDependentDestroyAccount: Do not add an association to account with dependent destroy. The destroy should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent
RUBY

expect_offense(<<~RUBY)
belongs_to :invitee_account, dependent: :destroy, class_name: "::Account"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not add an association to account with dependent destroy. The destroy should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/NoDependentDestroyAccount: Do not add an association to account with dependent destroy. The destroy should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent
RUBY
end

it 'handles various args' do
expect_offense(<<~RUBY)
belongs_to :account, dependent: :destroy
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not add an association to account with dependent destroy. The destroy should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/NoDependentDestroyAccount: Do not add an association to account with dependent destroy. The destroy should go on the other side of the association. See https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-dependent
RUBY
end
end
4 changes: 2 additions & 2 deletions spec/rubocop/cop/mavenlint/require_slow_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
it 'registers an offense when require "spec_helper" is used' do
expect_offense(<<~RUBY)
require "spec_helper"
^^^^^^^^^^^^^^^^^^^^^ Specs in the unit directory should not require rails_helper or spec_helper
^^^^^^^^^^^^^^^^^^^^^ Mavenlint/RequireSlowHelpers: Specs in the unit directory should not require rails_helper or spec_helper
RUBY
end

it 'registers an offense when require "rails_helper" is used' do
expect_offense(<<~RUBY)
require "rails_helper"
^^^^^^^^^^^^^^^^^^^^^^ Specs in the unit directory should not require rails_helper or spec_helper
^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/RequireSlowHelpers: Specs in the unit directory should not require rails_helper or spec_helper
RUBY
end
end
2 changes: 1 addition & 1 deletion spec/rubocop/cop/mavenlint/unsafe_mass_assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it 'registers an offense when mass assignment of foreign keys is allowed' do
expect_offense(<<~RUBY)
attr_accessible :story, :name, :account_id, :level
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not allow mass-assignment of foreign key columns. See https://github.com/mavenlink/welcome/wiki/Lint-Errors#unsafemassassignment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/UnsafeMassAssignment: Do not allow mass-assignment of foreign key columns. See https://github.com/mavenlink/welcome/wiki/Lint-Errors#unsafemassassignment
RUBY
end

Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/mavenlint/use_api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it 'registers an offense when an api controller directly inherits from ApplicationController' do
expect_offense(<<~RUBY)
class MyController < ApplicationController; end
^^^^^^^^^^^^^^^^^^^^^ Api Controllers should subclass `ApiController`.
^^^^^^^^^^^^^^^^^^^^^ Mavenlint/UseApiController: Api Controllers should subclass `ApiController`.
RUBY
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it 'registers an offense when a controller directly inherits from ActionController::Base' do
expect_offense(<<~RUBY)
class MyController < ActionController::Base; end
^^^^^^^^^^^^^^^^^^^^^^ Controllers should subclass `ApplicationController`.
^^^^^^^^^^^^^^^^^^^^^^ Mavenlint/UseApplicationController: Controllers should subclass `ApplicationController`.
RUBY
end

Expand Down
Loading