rubocop-gusto 10.1.0 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/config/default.yml +11 -19
- data/config/rails.yml +7 -0
- data/exe/gusto-rubocop +2 -2
- data/exe/rubocop-gusto +2 -2
- data/lib/rubocop/cop/gusto/bootsnap_load_file.rb +2 -2
- data/lib/rubocop/cop/gusto/datadog_constant.rb +2 -2
- data/lib/rubocop/cop/gusto/execute_migration.rb +1 -1
- data/lib/rubocop/cop/gusto/factory_classes_or_modules.rb +1 -1
- data/lib/rubocop/cop/gusto/min_by_max_by.rb +1 -1
- data/lib/rubocop/cop/gusto/no_metaprogramming.rb +7 -7
- data/lib/rubocop/cop/gusto/no_rescue_error_message_checking.rb +1 -1
- data/lib/rubocop/cop/gusto/no_send.rb +1 -1
- data/lib/rubocop/cop/gusto/object_in.rb +1 -1
- data/lib/rubocop/cop/gusto/paperclip_or_attachable.rb +1 -1
- data/lib/rubocop/cop/gusto/perform_class_method.rb +2 -2
- data/lib/rubocop/cop/gusto/polymorphic_type_validation.rb +1 -1
- data/lib/rubocop/cop/gusto/prefer_process_last_status.rb +2 -2
- data/lib/rubocop/cop/gusto/rabl_extends.rb +2 -2
- data/lib/rubocop/cop/gusto/rails_env.rb +2 -2
- data/lib/rubocop/cop/gusto/rake_constants.rb +1 -1
- data/lib/rubocop/cop/gusto/regexp_bypass.rb +4 -4
- data/lib/rubocop/cop/gusto/sidekiq_params.rb +1 -1
- data/lib/rubocop/cop/gusto/toplevel_constants.rb +1 -1
- data/lib/rubocop/cop/gusto/use_paint_not_colorize.rb +7 -7
- data/lib/rubocop/cop/gusto/vcr_recordings.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/assignment_first.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/require_restrict_on_send.rb +1 -1
- data/lib/rubocop/gusto/cli.rb +7 -7
- data/lib/rubocop/gusto/config_yml.rb +36 -10
- data/lib/rubocop/gusto/init.rb +13 -13
- data/lib/rubocop/gusto/plugin.rb +5 -5
- data/lib/rubocop/gusto/templates/rubocop.yml +2 -2
- data/lib/rubocop/gusto/version.rb +1 -1
- data/lib/rubocop/gusto.rb +1 -1
- data/lib/rubocop-gusto.rb +6 -6
- metadata +11 -12
- data/lib/rubocop/cop/gusto/ignored_columns_assignment.rb +0 -42
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ad5b8322bb818e1f765532f2757ae7bcce5bf7275ef22ced8700f87883715972
|
|
4
|
+
data.tar.gz: aff19b02288f2b23afb2df259a2a63b441189527d9d91f2e115ab75c7a2f1746
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed0bc51d62ead56c64464e36bd9142d6600d2a05430fc78c0510b50d577ccdb10d376de287079bec788abca083e40804eb59e6056f45743b9f8ac80576df7067
|
|
7
|
+
data.tar.gz: 39af6427e9a5b54b167c26679c314272c26c178b645bcb141b373da48c6829ee1d61d515518398bdf64b9279e8f005ba618674cda144fd80d873988198c2066e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
## Pending
|
|
2
2
|
|
|
3
|
+
## 10.2.0
|
|
4
|
+
|
|
5
|
+
- Fix Sorbet sigil exclusions, exclude specs from strict, and add rubocop-sorbet dependency
|
|
6
|
+
- Add ActiveSupportExtensionsEnabled to rails config
|
|
7
|
+
- Fix infinite loop and splitting problem in init command
|
|
8
|
+
- Use default Style/InverseMethods configuration
|
|
9
|
+
|
|
10
|
+
## 10.1.1
|
|
11
|
+
|
|
12
|
+
- Opt in to Rails/IgnoredColumnsAssignment
|
|
13
|
+
- Revert "Add Gusto/IgnoredColumnAssignment"
|
|
14
|
+
- Update rubocop dependency from 1.79.0 to 1.79.1
|
|
15
|
+
|
|
16
|
+
## 10.1.0
|
|
17
|
+
|
|
18
|
+
- Add Gusto/IgnoredColumnAssignment cop
|
|
19
|
+
|
|
3
20
|
## 10.0.1
|
|
4
21
|
|
|
5
22
|
- Require rubocop >= 1.76 to ensure Naming/PredicatePrefix is available.
|
data/config/default.yml
CHANGED
|
@@ -2,6 +2,7 @@ plugins:
|
|
|
2
2
|
- rubocop-rspec
|
|
3
3
|
- rubocop-performance
|
|
4
4
|
- rubocop-rake
|
|
5
|
+
- rubocop-sorbet
|
|
5
6
|
|
|
6
7
|
# After you add a rule, sort this file with `bundle exec rubocop-gusto sort config/default.yml`
|
|
7
8
|
|
|
@@ -58,9 +59,6 @@ Gusto/FactoryClassesOrModules:
|
|
|
58
59
|
Include:
|
|
59
60
|
- 'spec/**/factories/*.rb'
|
|
60
61
|
|
|
61
|
-
Gusto/IgnoredColumnsAssignment:
|
|
62
|
-
Description: 'Use `+=` with an array for `ignored_columns` assignment instead of direct assignment.'
|
|
63
|
-
|
|
64
62
|
Gusto/MinByMaxBy:
|
|
65
63
|
Description: 'Checks for the use of `min` or `max` with a proc. Corrects to `min_by` or `max_by`.'
|
|
66
64
|
Safe: false
|
|
@@ -344,9 +342,6 @@ RSpec/DescribedClass:
|
|
|
344
342
|
|
|
345
343
|
RSpec/DescribedClassModuleWrapping:
|
|
346
344
|
Enabled: true
|
|
347
|
-
# TODO: improve this file matching pattern
|
|
348
|
-
Include:
|
|
349
|
-
- '**/spec/**/*_spec.rb'
|
|
350
345
|
|
|
351
346
|
RSpec/ExampleLength:
|
|
352
347
|
Enabled: false
|
|
@@ -429,7 +424,6 @@ Rake/ClassDefinitionInTask:
|
|
|
429
424
|
Enabled: false
|
|
430
425
|
|
|
431
426
|
Rake/Desc:
|
|
432
|
-
# TODO: Roll this out.
|
|
433
427
|
Enabled: true
|
|
434
428
|
|
|
435
429
|
Security/YAMLLoad:
|
|
@@ -446,11 +440,7 @@ Sorbet:
|
|
|
446
440
|
Sorbet/FalseSigil:
|
|
447
441
|
# We want to avoid `typed: ignore` as much as possible, as it breaks LSP tooling.
|
|
448
442
|
Include:
|
|
449
|
-
|
|
450
|
-
Exclude:
|
|
451
|
-
- bin/**/*
|
|
452
|
-
- db/**/*.rb
|
|
453
|
-
- script/**/*
|
|
443
|
+
- "**/*.{rb,rbi,rake,ru}"
|
|
454
444
|
|
|
455
445
|
Sorbet/Refinement:
|
|
456
446
|
# Still marked pending upstream, we contributed this and enable it here.
|
|
@@ -460,6 +450,13 @@ Sorbet/StrictSigil:
|
|
|
460
450
|
# Forgot the difference between typed levels? (ignore, false, true, strict, and strong)
|
|
461
451
|
# Check this out: https://sorbet.org/docs/static#file-level-granularity-strictness-levels
|
|
462
452
|
Enabled: true
|
|
453
|
+
Include:
|
|
454
|
+
- "**/*.{rb,rbi,rake,ru}"
|
|
455
|
+
Exclude:
|
|
456
|
+
- bin/**/*
|
|
457
|
+
- db/**/*.rb
|
|
458
|
+
- script/**/*
|
|
459
|
+
- spec/**/*spec.rb
|
|
463
460
|
|
|
464
461
|
Sorbet/ValidSigil:
|
|
465
462
|
Enabled: true
|
|
@@ -482,7 +479,6 @@ Style/Alias:
|
|
|
482
479
|
EnforcedStyle: prefer_alias_method
|
|
483
480
|
|
|
484
481
|
Style/AsciiComments:
|
|
485
|
-
# TODO: roll this out fully
|
|
486
482
|
Enabled: true
|
|
487
483
|
|
|
488
484
|
Style/AutoResourceCleanup:
|
|
@@ -545,9 +541,9 @@ Style/FrozenStringLiteralComment:
|
|
|
545
541
|
EnforcedStyle: always
|
|
546
542
|
Enabled: true
|
|
547
543
|
|
|
544
|
+
# This can make lines longer and impair readability
|
|
548
545
|
Style/GuardClause:
|
|
549
546
|
Enabled: false
|
|
550
|
-
MinBodyLength: 4
|
|
551
547
|
|
|
552
548
|
Style/HashEachMethods:
|
|
553
549
|
Enabled: true
|
|
@@ -562,7 +558,7 @@ Style/HashTransformValues:
|
|
|
562
558
|
Enabled: false
|
|
563
559
|
|
|
564
560
|
Style/IfInsideElse:
|
|
565
|
-
|
|
561
|
+
Enabled: false
|
|
566
562
|
|
|
567
563
|
Style/IfUnlessModifier:
|
|
568
564
|
Enabled: false
|
|
@@ -570,9 +566,6 @@ Style/IfUnlessModifier:
|
|
|
570
566
|
Style/ImplicitRuntimeError:
|
|
571
567
|
Enabled: false
|
|
572
568
|
|
|
573
|
-
Style/InverseMethods:
|
|
574
|
-
Enabled: false
|
|
575
|
-
|
|
576
569
|
Style/Lambda:
|
|
577
570
|
EnforcedStyle: literal
|
|
578
571
|
|
|
@@ -755,7 +748,6 @@ Style/SymbolProc:
|
|
|
755
748
|
Enabled: true
|
|
756
749
|
|
|
757
750
|
Style/TernaryParentheses:
|
|
758
|
-
Enabled: false
|
|
759
751
|
EnforcedStyle: require_parentheses_when_complex
|
|
760
752
|
|
|
761
753
|
Style/TrailingCommaInArguments:
|
data/config/rails.yml
CHANGED
|
@@ -7,6 +7,7 @@ plugins:
|
|
|
7
7
|
- rubocop-rails
|
|
8
8
|
|
|
9
9
|
AllCops:
|
|
10
|
+
ActiveSupportExtensionsEnabled: true
|
|
10
11
|
TargetRubyVersion: <%= RbConfig::CONFIG['RUBY_API_VERSION'] %>
|
|
11
12
|
MaxFilesInCache: 100000
|
|
12
13
|
Exclude:
|
|
@@ -16,6 +17,9 @@ AllCops:
|
|
|
16
17
|
- 'db/**/*schema.rb'
|
|
17
18
|
- 'db/seeds{.rb,/**/*}'
|
|
18
19
|
|
|
20
|
+
Performance/DoubleStartEndWith:
|
|
21
|
+
IncludeActiveSupportAliases: true
|
|
22
|
+
|
|
19
23
|
Rails:
|
|
20
24
|
Enabled: true
|
|
21
25
|
|
|
@@ -82,6 +86,9 @@ Rails/HttpPositionalArguments:
|
|
|
82
86
|
- packs/**/spec/{controllers,fixture_generators}/**/*
|
|
83
87
|
- spec/{controllers,fixture_generators}/**/*
|
|
84
88
|
|
|
89
|
+
Rails/IgnoredColumnsAssignment:
|
|
90
|
+
Enabled: true
|
|
91
|
+
|
|
85
92
|
Rails/InverseOf:
|
|
86
93
|
Include:
|
|
87
94
|
- '**/app/models/**/*'
|
data/exe/gusto-rubocop
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
# This file is here to conform to our gusto-* convention.
|
|
6
6
|
# rubocop gems have their own naming convention so we're doing both.
|
|
7
7
|
|
|
8
|
-
$LOAD_PATH.unshift(File.expand_path(
|
|
8
|
+
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
|
|
9
9
|
|
|
10
|
-
require
|
|
10
|
+
require "rubocop/gusto/cli"
|
|
11
11
|
|
|
12
12
|
RuboCop::Gusto::Cli.start(ARGV)
|
data/exe/rubocop-gusto
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
# typed: strict
|
|
4
4
|
|
|
5
|
-
$LOAD_PATH.unshift(File.expand_path(
|
|
5
|
+
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
|
|
6
6
|
|
|
7
|
-
require
|
|
7
|
+
require "rubocop/gusto/cli"
|
|
8
8
|
|
|
9
9
|
RuboCop::Gusto::Cli.start(ARGV)
|
|
@@ -9,10 +9,10 @@ module RuboCop
|
|
|
9
9
|
RESTRICT_ON_SEND = %i(load).freeze
|
|
10
10
|
|
|
11
11
|
# @!method yaml_or_json_load(node)
|
|
12
|
-
def_node_matcher :yaml_or_json_load,
|
|
12
|
+
def_node_matcher :yaml_or_json_load, "(send $(const nil? PROHIBITED_CONSTANTS) :load ...)"
|
|
13
13
|
|
|
14
14
|
# @!method file_read(node)
|
|
15
|
-
def_node_matcher :file_read,
|
|
15
|
+
def_node_matcher :file_read, "(send (const nil? :File) :read $_)"
|
|
16
16
|
|
|
17
17
|
# @!method load_inside_file_open(node)
|
|
18
18
|
def_node_matcher :load_inside_file_open, <<~PATTERN
|
|
@@ -4,8 +4,8 @@ module RuboCop
|
|
|
4
4
|
module Cop
|
|
5
5
|
module Gusto
|
|
6
6
|
class DatadogConstant < Base
|
|
7
|
-
MSG =
|
|
8
|
-
NAMESPACE =
|
|
7
|
+
MSG = "Do not call Datadog directly, use an appropriate wrapper library."
|
|
8
|
+
NAMESPACE = "Datadog"
|
|
9
9
|
|
|
10
10
|
def on_const(node)
|
|
11
11
|
add_offense(node) if node.const_name == NAMESPACE
|
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
|
4
4
|
module Cop
|
|
5
5
|
module Gusto
|
|
6
6
|
class ExecuteMigration < Base
|
|
7
|
-
MSG =
|
|
7
|
+
MSG = "Do not use `execute` to run raw SQL in a migration. Run the query from a backfill rake task or pass the SQL options to the `add_column`/`change_column` method."
|
|
8
8
|
RESTRICT_ON_SEND = [:execute].freeze
|
|
9
9
|
|
|
10
10
|
def on_send(node)
|
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
|
4
4
|
module Cop
|
|
5
5
|
module Gusto
|
|
6
6
|
class FactoryClassesOrModules < Base
|
|
7
|
-
MSG =
|
|
7
|
+
MSG = "Do not define modules or classes in factory directories - they break reloading"
|
|
8
8
|
|
|
9
9
|
def on_class(node)
|
|
10
10
|
add_offense(node)
|
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
|
26
26
|
class MinByMaxBy < Base
|
|
27
27
|
extend AutoCorrector
|
|
28
28
|
|
|
29
|
-
MSG =
|
|
29
|
+
MSG = "Use `%{method}_by` instead of `%{method}` with a proc like `&:my_method_proc`. `%{method}` expects Comparable elements."
|
|
30
30
|
RESTRICT_ON_SEND = %i(min max).freeze
|
|
31
31
|
|
|
32
32
|
def on_send(node)
|
|
@@ -94,35 +94,35 @@ module RuboCop
|
|
|
94
94
|
|
|
95
95
|
def on_defs(node)
|
|
96
96
|
included_definition?(node) do
|
|
97
|
-
add_offense(node, message:
|
|
97
|
+
add_offense(node, message: "self.included modifies the behavior of classes at runtime. Please avoid using if possible.")
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
inherited_definition?(node) do
|
|
101
|
-
add_offense(node, message:
|
|
101
|
+
add_offense(node, message: "self.inherited modifies the behavior of classes at runtime. Please avoid using if possible.")
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def on_def(node)
|
|
106
106
|
using_method_missing?(node) do
|
|
107
|
-
add_offense(node, message:
|
|
107
|
+
add_offense(node, message: "Please do not use method_missing. Instead, explicitly define the methods you expect to receive.")
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
def on_send(node)
|
|
112
112
|
using_define_method?(node) do
|
|
113
|
-
add_offense(node, message:
|
|
113
|
+
add_offense(node, message: "Please do not define methods dynamically, instead define them using `def` and explicitly. This helps readability for both humans and machines.")
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
using_define_singleton_method_on_klass_instance?(node) do
|
|
117
|
-
add_offense(node, message:
|
|
117
|
+
add_offense(node, message: "Please do not use define_singleton_method. Instead, define the method explicitly using `def self.my_method; end`")
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
using_instance_eval?(node) do
|
|
121
|
-
add_offense(node, message:
|
|
121
|
+
add_offense(node, message: "Please do not use instance_eval to augment behavior onto an instance. Instead, define the method you want to use in the class definition.")
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
using_class_eval?(node) do
|
|
125
|
-
add_offense(node, message:
|
|
125
|
+
add_offense(node, message: "Please do not use class_eval to augment behavior onto a class. Instead, define the method you want to use in the class definition.")
|
|
126
126
|
end
|
|
127
127
|
end
|
|
128
128
|
end
|
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
|
37
37
|
# end
|
|
38
38
|
#
|
|
39
39
|
class NoRescueErrorMessageChecking < Base
|
|
40
|
-
MSG =
|
|
40
|
+
MSG = "Avoid checking error message while handling exceptions. This is brittle and can break easily."
|
|
41
41
|
METHODS_TO_CHECK = %i(match? include? ==).to_set.freeze
|
|
42
42
|
|
|
43
43
|
def on_rescue(node)
|
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
|
14
14
|
# There's no better alternative, don't call private methods.
|
|
15
15
|
#
|
|
16
16
|
class NoSend < Base
|
|
17
|
-
MSG =
|
|
17
|
+
MSG = "Do not call a private method via `__send__`."
|
|
18
18
|
RESTRICT_ON_SEND = %i(__send__).freeze
|
|
19
19
|
|
|
20
20
|
# @!method invoke_private_method_send?(node)
|
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
|
16
16
|
# ('a'..'z').cover?('yellow') # => true
|
|
17
17
|
#
|
|
18
18
|
class ObjectIn < Base
|
|
19
|
-
MSG =
|
|
19
|
+
MSG = "Use `Range#cover?` instead of `Object#in?`."
|
|
20
20
|
RESTRICT_ON_SEND = [:in?].freeze
|
|
21
21
|
|
|
22
22
|
# @!method object_in(node)
|
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
|
5
5
|
module Cop
|
|
6
6
|
module Gusto
|
|
7
7
|
class PaperclipOrAttachable < Base
|
|
8
|
-
MSG =
|
|
8
|
+
MSG = "No more new paperclip or Attachable are allowed. New attachments should use ActiveStorage instead"
|
|
9
9
|
RESTRICT_ON_SEND = %i(has_attached_file has_pdf_attachment has_attachment).freeze
|
|
10
10
|
|
|
11
11
|
def on_send(node)
|
|
@@ -26,9 +26,9 @@ module RuboCop
|
|
|
26
26
|
# end
|
|
27
27
|
#
|
|
28
28
|
class PerformClassMethod < Base
|
|
29
|
-
MSG =
|
|
29
|
+
MSG = "Class-level `perform` method is being defined. Did you mean to use an instance method?"
|
|
30
30
|
WORKER_FALLBACK = %w(Sidekiq::Worker).freeze
|
|
31
|
-
WORKER_MODULES =
|
|
31
|
+
WORKER_MODULES = "WorkerModules"
|
|
32
32
|
|
|
33
33
|
def on_def(node)
|
|
34
34
|
return unless node.method?(:perform)
|
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
|
28
28
|
polymorphic_methods_for :subscription_detail, VALID_TYPES
|
|
29
29
|
MESSAGE
|
|
30
30
|
|
|
31
|
-
ALLOW_BLANK_MSG =
|
|
31
|
+
ALLOW_BLANK_MSG = "Polymorphic type validations cannot use allow_blank: true"
|
|
32
32
|
|
|
33
33
|
# @!method polymorphic_relation?(node)
|
|
34
34
|
def_node_matcher :polymorphic_relation?, <<~PATTERN
|
|
@@ -17,7 +17,7 @@ module RuboCop
|
|
|
17
17
|
class PreferProcessLastStatus < Base
|
|
18
18
|
extend AutoCorrector
|
|
19
19
|
|
|
20
|
-
MSG =
|
|
20
|
+
MSG = "Prefer using `Process.last_status` instead of the global variables: `$?` and `$CHILD_STATUS`."
|
|
21
21
|
OFFENDERS = Set[:$?, :$CHILD_STATUS].freeze
|
|
22
22
|
|
|
23
23
|
def on_gvar(node)
|
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def autocorrect(corrector, node)
|
|
30
|
-
corrector.replace(node,
|
|
30
|
+
corrector.replace(node, "Process.last_status")
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
@@ -19,8 +19,8 @@ module RuboCop
|
|
|
19
19
|
# child(:baz) { attributes :qux }
|
|
20
20
|
#
|
|
21
21
|
class RablExtends < Base
|
|
22
|
-
MSG =
|
|
23
|
-
RABL_EXTENSION =
|
|
22
|
+
MSG = "Avoid using Rabl extends as it has poor caching performance. Inline your JSON instead."
|
|
23
|
+
RABL_EXTENSION = ".rabl"
|
|
24
24
|
RESTRICT_ON_SEND = %i(extends).freeze
|
|
25
25
|
|
|
26
26
|
# @!method rabl_extends?(node)
|
|
@@ -51,8 +51,8 @@ module RuboCop
|
|
|
51
51
|
local?
|
|
52
52
|
)
|
|
53
53
|
).freeze
|
|
54
|
-
MSG =
|
|
55
|
-
PROHIBITED_CLASS =
|
|
54
|
+
MSG = "Use Feature Flags or config instead of `Rails.env`."
|
|
55
|
+
PROHIBITED_CLASS = "Rails"
|
|
56
56
|
RESTRICT_ON_SEND = %i(env).freeze
|
|
57
57
|
|
|
58
58
|
def on_send(node)
|
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
|
28
28
|
# end
|
|
29
29
|
#
|
|
30
30
|
class RakeConstants < Base
|
|
31
|
-
MSG =
|
|
31
|
+
MSG = "Do not define a constant in rake file, because they are sometimes `load`ed, instead of `require`d which can lead to warnings about redefining constants"
|
|
32
32
|
|
|
33
33
|
# @!method task_or_namespace?(node)
|
|
34
34
|
def_node_matcher :task_or_namespace?, <<-PATTERN
|
|
@@ -39,16 +39,16 @@ module RuboCop
|
|
|
39
39
|
extend AutoCorrector
|
|
40
40
|
|
|
41
41
|
MSG = 'Regular expressions matching a single line should use \A instead of ^ and \z instead of $'
|
|
42
|
-
PROHIBITED_ANCHOR =
|
|
43
|
-
PROHIBITED_END_ANCHOR =
|
|
42
|
+
PROHIBITED_ANCHOR = "^"
|
|
43
|
+
PROHIBITED_END_ANCHOR = "$"
|
|
44
44
|
|
|
45
45
|
def on_regexp(node)
|
|
46
|
-
return if node.children.find(&:regopt_type?)&.source&.include?(
|
|
46
|
+
return if node.children.find(&:regopt_type?)&.source&.include?("m")
|
|
47
47
|
|
|
48
48
|
first_child = node.children.first
|
|
49
49
|
return unless first_child && !first_child.regopt_type?
|
|
50
50
|
|
|
51
|
-
captureless_source = first_child.source.delete(
|
|
51
|
+
captureless_source = first_child.source.delete("()") # Remove parentheses to check actual content
|
|
52
52
|
return unless captureless_source.start_with?(PROHIBITED_ANCHOR) || captureless_source.end_with?(PROHIBITED_END_ANCHOR)
|
|
53
53
|
|
|
54
54
|
add_offense(first_child) do |corrector|
|
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
|
4
4
|
module Cop
|
|
5
5
|
module Gusto
|
|
6
6
|
class SidekiqParams < Base
|
|
7
|
-
MSG =
|
|
7
|
+
MSG = "Sidekiq perform methods cannot take keyword arguments"
|
|
8
8
|
PROHIBITED_ARG_TYPES = Set.new(%i(kwoptarg kwarg)).freeze
|
|
9
9
|
|
|
10
10
|
def on_def(node)
|
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
|
39
39
|
# FOO = 'bar' # config/initializers/foo.rb
|
|
40
40
|
#
|
|
41
41
|
class ToplevelConstants < Base
|
|
42
|
-
MSG =
|
|
42
|
+
MSG = "Top-level constants should be defined in an initializer. See https://github.com/Gusto/rubocop-gusto/blob/main/lib/rubocop/cop/gusto/toplevel_constants.rb"
|
|
43
43
|
|
|
44
44
|
def on_casgn(node)
|
|
45
45
|
# Allow nested constants
|
|
@@ -92,8 +92,8 @@ module RuboCop
|
|
|
92
92
|
)
|
|
93
93
|
).freeze
|
|
94
94
|
|
|
95
|
-
MSG =
|
|
96
|
-
PROHIBITED_CLASS =
|
|
95
|
+
MSG = "Use Paint instead of colorize for terminal colors."
|
|
96
|
+
PROHIBITED_CLASS = "String"
|
|
97
97
|
RESTRICT_ON_SEND = COLOR_METHODS
|
|
98
98
|
|
|
99
99
|
def on_send(node)
|
|
@@ -170,16 +170,16 @@ module RuboCop
|
|
|
170
170
|
elsif method_name == :uncolorize
|
|
171
171
|
# If uncolorize is called, convert to Paint.unpaint
|
|
172
172
|
return "Paint.unpaint(#{original_string.source})"
|
|
173
|
-
elsif method_name.start_with?(
|
|
173
|
+
elsif method_name.start_with?("on_")
|
|
174
174
|
# Background color
|
|
175
|
-
color_name = method_name.to_s.delete_prefix(
|
|
175
|
+
color_name = method_name.to_s.delete_prefix("on_")
|
|
176
176
|
background = ":#{color_name}"
|
|
177
177
|
elsif STYLE_MODIFIERS.include?(method_name)
|
|
178
178
|
# Style modifier
|
|
179
179
|
styles << ":#{method_name}"
|
|
180
|
-
elsif method_name.start_with?(
|
|
180
|
+
elsif method_name.start_with?("light_")
|
|
181
181
|
# Light/bright foreground color
|
|
182
|
-
color = method_name.to_s.delete_prefix(
|
|
182
|
+
color = method_name.to_s.delete_prefix("light_")
|
|
183
183
|
foreground = ":bright, :#{color}"
|
|
184
184
|
else
|
|
185
185
|
# Regular foreground color
|
|
@@ -221,7 +221,7 @@ module RuboCop
|
|
|
221
221
|
|
|
222
222
|
# Add nil as a placeholder for foreground if we only have a background
|
|
223
223
|
if background && !foreground
|
|
224
|
-
params <<
|
|
224
|
+
params << "nil"
|
|
225
225
|
elsif foreground
|
|
226
226
|
params << foreground
|
|
227
227
|
end
|
|
@@ -17,7 +17,7 @@ module RuboCop
|
|
|
17
17
|
class VcrRecordings < Base
|
|
18
18
|
extend AutoCorrector
|
|
19
19
|
|
|
20
|
-
MSG =
|
|
20
|
+
MSG = "VCR should be set to not record in tests. Please use vcr: {record: :none}."
|
|
21
21
|
|
|
22
22
|
# @!method vcr_recording?(node)
|
|
23
23
|
def_node_matcher :vcr_recording?, <<~PATTERN
|
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
|
29
29
|
return unless recording_enabled?(node.key.children.first, node.value.children.first)
|
|
30
30
|
|
|
31
31
|
add_offense(node) do |corrector|
|
|
32
|
-
replacement = node.source.sub(/: :\w*/,
|
|
32
|
+
replacement = node.source.sub(/: :\w*/, ": :none")
|
|
33
33
|
corrector.replace(node, replacement)
|
|
34
34
|
end
|
|
35
35
|
end
|
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
|
37
37
|
private
|
|
38
38
|
|
|
39
39
|
def vcr_setting?(node)
|
|
40
|
-
node.parent.parent.source.include?(
|
|
40
|
+
node.parent.parent.source.include?("vcr")
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def recording_enabled?(option, value)
|
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
|
38
38
|
after_class
|
|
39
39
|
after_module
|
|
40
40
|
).to_set.freeze
|
|
41
|
-
MSG =
|
|
41
|
+
MSG = "Avoid placing an assignment as the first action in `%{hook}`."
|
|
42
42
|
|
|
43
43
|
def on_def(node)
|
|
44
44
|
return unless HOOKS.include?(node.method_name)
|
|
@@ -24,7 +24,7 @@ module RuboCop
|
|
|
24
24
|
# NOTE: This works for us because we do not write cops that investigate every send node.
|
|
25
25
|
# Upstream Rubocop chose not to implement this as there are many cops in Core that investigate every node.
|
|
26
26
|
class RequireRestrictOnSend < Base
|
|
27
|
-
MSG =
|
|
27
|
+
MSG = "Missing `RESTRICT_ON_SEND` declaration when using `on_send` or `after_send`."
|
|
28
28
|
|
|
29
29
|
# @!method defined_send_callback?(node)
|
|
30
30
|
def_node_search :defined_send_callback?, <<~PATTERN
|
data/lib/rubocop/gusto/cli.rb
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require "thor"
|
|
4
|
+
require "rubocop/gusto/config_yml"
|
|
5
|
+
require "rubocop/gusto/init"
|
|
6
6
|
|
|
7
7
|
module RuboCop
|
|
8
8
|
module Gusto
|
|
9
9
|
class Cli < Thor
|
|
10
|
-
register(Init,
|
|
10
|
+
register(Init, "init", "init", "Initialize rubocop-gusto and update .rubocop.yml")
|
|
11
11
|
|
|
12
|
-
desc
|
|
13
|
-
method_option :output, type: :string, default: nil, desc:
|
|
14
|
-
def sort(rubocop_yml_path =
|
|
12
|
+
desc "sort [RUBOCOP_YML_PATH]", "Sort the cops in a .rubocop.yml file (default: .rubocop.yml)"
|
|
13
|
+
method_option :output, type: :string, default: nil, desc: "The path to the output file"
|
|
14
|
+
def sort(rubocop_yml_path = ".rubocop.yml")
|
|
15
15
|
say "Sorting #{rubocop_yml_path}..."
|
|
16
16
|
output_path = options[:output] || rubocop_yml_path
|
|
17
17
|
ConfigYml.load_file(rubocop_yml_path).sort!.write(output_path)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "pathname"
|
|
4
|
+
require "yaml"
|
|
4
5
|
|
|
5
6
|
module RuboCop
|
|
6
7
|
module Gusto
|
|
@@ -16,7 +17,7 @@ module RuboCop
|
|
|
16
17
|
INDENT_REGEX = /\A( |- )/
|
|
17
18
|
|
|
18
19
|
# @param [String] file_path the path to the .rubocop.yml file
|
|
19
|
-
def self.load_file(file_path =
|
|
20
|
+
def self.load_file(file_path = ".rubocop.yml")
|
|
20
21
|
new(File.readlines(file_path))
|
|
21
22
|
rescue Errno::ENOENT
|
|
22
23
|
new([])
|
|
@@ -33,7 +34,7 @@ module RuboCop
|
|
|
33
34
|
|
|
34
35
|
# Find if there's already an inherit_gem section and add the gem to it if needed
|
|
35
36
|
def add_inherit_gem(gem_name, *config_paths)
|
|
36
|
-
update_section_data(
|
|
37
|
+
update_section_data("inherit_gem") do |data|
|
|
37
38
|
data ||= {}
|
|
38
39
|
data[gem_name.to_s] = config_paths.flatten
|
|
39
40
|
data
|
|
@@ -42,7 +43,7 @@ module RuboCop
|
|
|
42
43
|
|
|
43
44
|
# Add a plugin to the plugins section or create it if it doesn't exist
|
|
44
45
|
def add_plugin(plugins)
|
|
45
|
-
update_section_data(
|
|
46
|
+
update_section_data("plugins") do |data|
|
|
46
47
|
data ||= []
|
|
47
48
|
data.concat(plugins).uniq
|
|
48
49
|
end
|
|
@@ -80,7 +81,7 @@ module RuboCop
|
|
|
80
81
|
end
|
|
81
82
|
|
|
82
83
|
# Sort the cops by their key name, putting comments at the top
|
|
83
|
-
cops.sort_by! { |cop| chunk_name(cop) ||
|
|
84
|
+
cops.sort_by! { |cop| chunk_name(cop) || "AAAAA/Comment?" }
|
|
84
85
|
|
|
85
86
|
self
|
|
86
87
|
end
|
|
@@ -110,21 +111,46 @@ module RuboCop
|
|
|
110
111
|
# Try to find a line that exactly matches KEY_REGEX
|
|
111
112
|
# Use rstrip, not strip, to preserve indentation
|
|
112
113
|
name_line = chunk.find { |line| line.rstrip.match?(KEY_REGEX) }
|
|
113
|
-
name_line
|
|
114
|
+
if name_line
|
|
115
|
+
name_line.rstrip.delete_suffix(":")
|
|
116
|
+
else
|
|
117
|
+
# Try to find a key with value on the same line (e.g., "inherit_from: .rubocop_todo.yml")
|
|
118
|
+
first_line = chunk.find { |line| !line.strip.empty? && !line.strip.start_with?("#") }
|
|
119
|
+
if first_line&.include?(":")
|
|
120
|
+
first_line.split(":").first.strip
|
|
121
|
+
end
|
|
122
|
+
end
|
|
114
123
|
end
|
|
115
124
|
|
|
116
125
|
# Splits the lines into blocks whenever we drop from indented to unindented
|
|
117
126
|
def chunk_blocks(lines)
|
|
118
|
-
# slice whenever we drop from indented to unindented
|
|
127
|
+
# slice whenever we drop from indented to unindented line
|
|
128
|
+
# or when we encounter a new top-level key after blank line(s)
|
|
119
129
|
chunks = lines.slice_when do |prev, line|
|
|
120
|
-
|
|
130
|
+
if prev.strip.empty?
|
|
131
|
+
# split when going from blank to non-indented non-blank
|
|
132
|
+
!line.match?(INDENT_REGEX) && !line.strip.empty?
|
|
133
|
+
elsif prev.match?(INDENT_REGEX)
|
|
134
|
+
# split when going from indented to non-blank unindented
|
|
135
|
+
!line.match?(INDENT_REGEX) && !line.strip.empty?
|
|
136
|
+
else
|
|
137
|
+
# prev is non-indented, split on blank lines too
|
|
138
|
+
line.strip.empty?
|
|
139
|
+
end
|
|
121
140
|
end
|
|
122
141
|
|
|
123
142
|
# Process each chunk to remove leading newlines and add 1 trailing newline
|
|
124
143
|
chunks.filter_map do |chunk|
|
|
125
144
|
# Remove leading and trailing empty lines
|
|
126
|
-
chunk.
|
|
127
|
-
|
|
145
|
+
until chunk.empty? || !chunk.first.strip.empty?
|
|
146
|
+
chunk.shift
|
|
147
|
+
end
|
|
148
|
+
until chunk.empty? || !chunk.last.strip.empty?
|
|
149
|
+
chunk.pop
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Skip empty chunks
|
|
153
|
+
next if chunk.empty?
|
|
128
154
|
|
|
129
155
|
# Ensure each chunk ends with a blank newline
|
|
130
156
|
chunk << "\n"
|
data/lib/rubocop/gusto/init.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require "pathname"
|
|
4
|
+
require "yaml"
|
|
5
|
+
require "rubocop/gusto/config_yml"
|
|
6
6
|
|
|
7
7
|
module RuboCop
|
|
8
8
|
module Gusto
|
|
@@ -11,48 +11,48 @@ module RuboCop
|
|
|
11
11
|
|
|
12
12
|
PLUGINS = %w(rubocop-gusto rubocop-rspec rubocop-performance rubocop-rake rubocop-rails).freeze
|
|
13
13
|
|
|
14
|
-
class_option :rubocop_yml, type: :string, default:
|
|
14
|
+
class_option :rubocop_yml, type: :string, default: ".rubocop.yml"
|
|
15
15
|
|
|
16
16
|
def self.source_root
|
|
17
|
-
File.expand_path(
|
|
17
|
+
File.expand_path("templates", __dir__)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def add_dependencies
|
|
21
21
|
if rails?
|
|
22
22
|
# we don't want rubocop-rails to be a dependency of the gem so that we can use this in non-rails gems
|
|
23
|
-
run
|
|
23
|
+
run "bundle show rubocop-rails >/dev/null || bundle add rubocop-rails --group development", capture: true
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
run
|
|
26
|
+
run "bundle binstub rubocop", capture: true
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def copy_config_files
|
|
30
30
|
config = ConfigYml.load_file(options[:rubocop_yml])
|
|
31
31
|
|
|
32
32
|
if config.empty?
|
|
33
|
-
template
|
|
33
|
+
template "rubocop.yml", options[:rubocop_yml]
|
|
34
34
|
config = ConfigYml.load_file(options[:rubocop_yml])
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
if rails?
|
|
38
|
-
config.add_inherit_gem(
|
|
38
|
+
config.add_inherit_gem("rubocop-gusto", "config/default.yml", "config/rails.yml")
|
|
39
39
|
config.add_plugin(PLUGINS)
|
|
40
40
|
else
|
|
41
|
-
config.add_inherit_gem(
|
|
41
|
+
config.add_inherit_gem("rubocop-gusto", "config/default.yml")
|
|
42
42
|
config.add_plugin(PLUGINS - %w(rubocop-rails))
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
config.sort!
|
|
46
46
|
config.write(options[:rubocop_yml])
|
|
47
|
-
say_status
|
|
47
|
+
say_status "update", options[:rubocop_yml]
|
|
48
48
|
|
|
49
|
-
create_file(
|
|
49
|
+
create_file(".rubocop_todo.yml", skip: true)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
private
|
|
53
53
|
|
|
54
54
|
def rails?
|
|
55
|
-
File.exist?(
|
|
55
|
+
File.exist?("config/application.rb")
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
end
|
data/lib/rubocop/gusto/plugin.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "lint_roller"
|
|
4
4
|
|
|
5
5
|
module RuboCop
|
|
6
6
|
module Gusto
|
|
@@ -8,9 +8,9 @@ module RuboCop
|
|
|
8
8
|
class Plugin < LintRoller::Plugin
|
|
9
9
|
def about
|
|
10
10
|
LintRoller::About.new(
|
|
11
|
-
name:
|
|
11
|
+
name: "rubocop-gusto",
|
|
12
12
|
version: RuboCop::Gusto::VERSION,
|
|
13
|
-
homepage:
|
|
13
|
+
homepage: "https://github.com/Gusto/rubocop-gusto",
|
|
14
14
|
description: "A collection of Gusto's standard RuboCop cops and rules."
|
|
15
15
|
)
|
|
16
16
|
end
|
|
@@ -20,9 +20,9 @@ module RuboCop
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def rules(_context)
|
|
23
|
-
project_root = Pathname.new(__dir__).join(
|
|
23
|
+
project_root = Pathname.new(__dir__).join("../../..")
|
|
24
24
|
|
|
25
|
-
LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join(
|
|
25
|
+
LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join("config", "default.yml"))
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
data/lib/rubocop/gusto.rb
CHANGED
data/lib/rubocop-gusto.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "rubocop"
|
|
4
|
+
require "rubocop-rspec"
|
|
5
5
|
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
8
|
-
require_relative
|
|
6
|
+
require_relative "rubocop/gusto"
|
|
7
|
+
require_relative "rubocop/gusto/version"
|
|
8
|
+
require_relative "rubocop/gusto/plugin"
|
|
9
9
|
|
|
10
10
|
# Require all cops
|
|
11
|
-
Dir.glob(File.join(File.dirname(__FILE__),
|
|
11
|
+
Dir.glob(File.join(File.dirname(__FILE__), "rubocop/cop/**/*.rb")).each do |file|
|
|
12
12
|
require file
|
|
13
13
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-gusto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 10.
|
|
4
|
+
version: 10.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gusto Engineering
|
|
@@ -10,7 +10,7 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: lint_roller
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
@@ -24,35 +24,35 @@ dependencies:
|
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
27
|
+
name: rubocop
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '1.76'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
39
|
+
version: '1.76'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
|
-
name: rubocop
|
|
41
|
+
name: rubocop-performance
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '
|
|
46
|
+
version: '0'
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: '
|
|
53
|
+
version: '0'
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
|
-
name: rubocop-
|
|
55
|
+
name: rubocop-rake
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
|
58
58
|
- - ">="
|
|
@@ -66,7 +66,7 @@ dependencies:
|
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '0'
|
|
68
68
|
- !ruby/object:Gem::Dependency
|
|
69
|
-
name: rubocop-
|
|
69
|
+
name: rubocop-rspec
|
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
|
71
71
|
requirements:
|
|
72
72
|
- - ">="
|
|
@@ -80,7 +80,7 @@ dependencies:
|
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
81
|
version: '0'
|
|
82
82
|
- !ruby/object:Gem::Dependency
|
|
83
|
-
name: rubocop-
|
|
83
|
+
name: rubocop-sorbet
|
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
|
86
86
|
- - ">="
|
|
@@ -127,7 +127,6 @@ files:
|
|
|
127
127
|
- lib/rubocop/cop/gusto/datadog_constant.rb
|
|
128
128
|
- lib/rubocop/cop/gusto/execute_migration.rb
|
|
129
129
|
- lib/rubocop/cop/gusto/factory_classes_or_modules.rb
|
|
130
|
-
- lib/rubocop/cop/gusto/ignored_columns_assignment.rb
|
|
131
130
|
- lib/rubocop/cop/gusto/min_by_max_by.rb
|
|
132
131
|
- lib/rubocop/cop/gusto/no_metaprogramming.rb
|
|
133
132
|
- lib/rubocop/cop/gusto/no_rescue_error_message_checking.rb
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module RuboCop
|
|
4
|
-
module Cop
|
|
5
|
-
module Gusto
|
|
6
|
-
# Enforces proper usage of `ignored_columns` assignment
|
|
7
|
-
#
|
|
8
|
-
# This cop ensures that `ignored_columns` is assigned using `+=` with an array
|
|
9
|
-
# instead of direct assignment, which will overwrite the existing list of
|
|
10
|
-
# ignored columns for the model, or overwrite the list it should inherit in the
|
|
11
|
-
# case of single table inheritance.
|
|
12
|
-
#
|
|
13
|
-
# @example
|
|
14
|
-
#
|
|
15
|
-
# # bad
|
|
16
|
-
# self.ignored_columns = :column_name
|
|
17
|
-
# self.ignored_columns = 'column_name'
|
|
18
|
-
# self.ignored_columns = [:column_name]
|
|
19
|
-
# self.ignored_columns = ['column_name']
|
|
20
|
-
#
|
|
21
|
-
# # good
|
|
22
|
-
# self.ignored_columns += [:column_name]
|
|
23
|
-
# self.ignored_columns += ['column_name']
|
|
24
|
-
#
|
|
25
|
-
class IgnoredColumnsAssignment < Base
|
|
26
|
-
MSG = 'Use `+=` with an array for `ignored_columns` assignment instead of direct assignment.'
|
|
27
|
-
RESTRICT_ON_SEND = %i(ignored_columns=).freeze
|
|
28
|
-
|
|
29
|
-
# @!method ignored_columns_direct_assignment?(node)
|
|
30
|
-
def_node_matcher :ignored_columns_direct_assignment?, <<~PATTERN
|
|
31
|
-
(send (self) :ignored_columns= _)
|
|
32
|
-
PATTERN
|
|
33
|
-
|
|
34
|
-
def on_send(node)
|
|
35
|
-
if ignored_columns_direct_assignment?(node)
|
|
36
|
-
add_offense(node.loc.selector)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|