sevencop 0.22.0 → 0.24.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +5 -16
- data/config/default.yml +16 -143
- data/lib/rubocop/cop/sevencop/rails_action_name.rb +61 -0
- data/lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb +23 -10
- data/lib/sevencop/cop_concerns.rb +0 -3
- data/lib/sevencop/version.rb +1 -1
- data/lib/sevencop.rb +1 -16
- metadata +3 -21
- data/lib/rubocop/cop/sevencop/rails_migration_add_check_constraint.rb +0 -111
- data/lib/rubocop/cop/sevencop/rails_migration_add_column_with_default_value.rb +0 -229
- data/lib/rubocop/cop/sevencop/rails_migration_add_foreign_key.rb +0 -166
- data/lib/rubocop/cop/sevencop/rails_migration_add_index_concurrently.rb +0 -164
- data/lib/rubocop/cop/sevencop/rails_migration_batch_in_batches.rb +0 -95
- data/lib/rubocop/cop/sevencop/rails_migration_batch_in_transaction.rb +0 -83
- data/lib/rubocop/cop/sevencop/rails_migration_batch_with_throttling.rb +0 -108
- data/lib/rubocop/cop/sevencop/rails_migration_change_column.rb +0 -113
- data/lib/rubocop/cop/sevencop/rails_migration_change_column_null.rb +0 -128
- data/lib/rubocop/cop/sevencop/rails_migration_create_table_force.rb +0 -89
- data/lib/rubocop/cop/sevencop/rails_migration_jsonb.rb +0 -131
- data/lib/rubocop/cop/sevencop/rails_migration_remove_column.rb +0 -258
- data/lib/rubocop/cop/sevencop/rails_migration_rename_column.rb +0 -81
- data/lib/rubocop/cop/sevencop/rails_migration_rename_table.rb +0 -79
- data/lib/rubocop/cop/sevencop/rails_migration_reserved_word_mysql.rb +0 -232
- data/lib/rubocop/cop/sevencop/rails_migration_unique_index_columns_count.rb +0 -92
- data/lib/sevencop/cop_concerns/batch_processing.rb +0 -32
- data/lib/sevencop/cop_concerns/column_type_method.rb +0 -26
- data/lib/sevencop/cop_concerns/disable_ddl_transaction.rb +0 -49
@@ -1,92 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module Sevencop
|
6
|
-
# Keep unique index columns count less than a specified number.
|
7
|
-
#
|
8
|
-
# Adding a non-unique index with more than three columns rarely improves performance.
|
9
|
-
# Instead, start an index with columns that narrow down the results the most.
|
10
|
-
#
|
11
|
-
# @example
|
12
|
-
# # bad
|
13
|
-
# add_index :users, %i[a b c d]
|
14
|
-
#
|
15
|
-
# # good (`MaxColumnsCount: 3` by default)
|
16
|
-
# add_index :users, %i[a b c]
|
17
|
-
class RailsMigrationUniqueIndexColumnsCount < RuboCop::Cop::Base
|
18
|
-
RESTRICT_ON_SEND = %i[
|
19
|
-
add_index
|
20
|
-
index
|
21
|
-
].freeze
|
22
|
-
|
23
|
-
# @param node [RuboCop::AST::SendNode]
|
24
|
-
# @return [void]
|
25
|
-
def on_send(node)
|
26
|
-
column_names_node = column_names_node_from(node)
|
27
|
-
return unless column_names_node
|
28
|
-
|
29
|
-
column_names_count = columns_count_from(column_names_node)
|
30
|
-
return if column_names_count <= max_columns_count
|
31
|
-
|
32
|
-
add_offense(
|
33
|
-
column_names_node,
|
34
|
-
message: "Keep unique index columns count less than #{max_columns_count}."
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# @!method column_names_node_from_add_index(node)
|
41
|
-
# @param node [RuboCop::AST::SendNode]
|
42
|
-
# @return [RuboCop::AST::Node, nil]
|
43
|
-
def_node_matcher :column_names_node_from_add_index, <<~PATTERN
|
44
|
-
(send
|
45
|
-
nil?
|
46
|
-
_
|
47
|
-
_
|
48
|
-
$({array | sym} ...)
|
49
|
-
)
|
50
|
-
PATTERN
|
51
|
-
|
52
|
-
# @!method column_names_node_from_index(node)
|
53
|
-
# @param node [RuboCop::AST::SendNode]
|
54
|
-
# @return [RuboCop::AST::Node, nil]
|
55
|
-
def_node_matcher :column_names_node_from_index, <<~PATTERN
|
56
|
-
(send
|
57
|
-
(lvar ...)
|
58
|
-
_
|
59
|
-
$({array | sym} ...)
|
60
|
-
)
|
61
|
-
PATTERN
|
62
|
-
|
63
|
-
# @param node [RuboCop::AST::SendNode]
|
64
|
-
# @return [RuboCop::AST::Node, nil]
|
65
|
-
def column_names_node_from(node)
|
66
|
-
case node.method_name
|
67
|
-
when :add_index
|
68
|
-
column_names_node_from_add_index(node)
|
69
|
-
when :index
|
70
|
-
column_names_node_from_index(node)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# @param node [RuboCop::AST::Node]
|
75
|
-
# @return [Integer, nil]
|
76
|
-
def columns_count_from(node)
|
77
|
-
case node.type
|
78
|
-
when :array
|
79
|
-
node.values.count
|
80
|
-
when :sym
|
81
|
-
1
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# @return [Integer]
|
86
|
-
def max_columns_count
|
87
|
-
cop_config['MaxColumnsCount']
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Sevencop
|
4
|
-
module CopConcerns
|
5
|
-
module BatchProcessing
|
6
|
-
BATCH_PROCESSING_METHOD_NAMES = ::Set.new(
|
7
|
-
%i[
|
8
|
-
delete_all
|
9
|
-
update_all
|
10
|
-
]
|
11
|
-
).freeze
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def included(klass)
|
15
|
-
super
|
16
|
-
klass.class_eval do
|
17
|
-
# @!method batch_processing?(node)
|
18
|
-
# @param node [RuboCop::AST::SendNode]
|
19
|
-
# @return [Boolean]
|
20
|
-
def_node_matcher :batch_processing?, <<~PATTERN
|
21
|
-
(send
|
22
|
-
!nil?
|
23
|
-
BATCH_PROCESSING_METHOD_NAMES
|
24
|
-
...
|
25
|
-
)
|
26
|
-
PATTERN
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Sevencop
|
4
|
-
module CopConcerns
|
5
|
-
module ColumnTypeMethod
|
6
|
-
COLUMN_TYPE_METHOD_NAMES = ::Set.new(
|
7
|
-
%i[
|
8
|
-
bigint
|
9
|
-
binary
|
10
|
-
blob
|
11
|
-
boolean
|
12
|
-
date
|
13
|
-
datetime
|
14
|
-
decimal
|
15
|
-
float
|
16
|
-
integer
|
17
|
-
numeric
|
18
|
-
primary_key
|
19
|
-
string
|
20
|
-
text
|
21
|
-
time
|
22
|
-
]
|
23
|
-
).freeze
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Sevencop
|
4
|
-
module CopConcerns
|
5
|
-
module DisableDdlTransaction
|
6
|
-
class << self
|
7
|
-
def included(klass)
|
8
|
-
super
|
9
|
-
klass.class_eval do
|
10
|
-
# @!method disable_ddl_transaction?(node)
|
11
|
-
# @param node [RuboCop::AST::SendNode]
|
12
|
-
# @return [Boolean]
|
13
|
-
def_node_matcher :disable_ddl_transaction?, <<~PATTERN
|
14
|
-
(send
|
15
|
-
nil?
|
16
|
-
:disable_ddl_transaction!
|
17
|
-
...
|
18
|
-
)
|
19
|
-
PATTERN
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
# @param corrector [RuboCop::Cop::Corrector]
|
27
|
-
# @param node [RuboCop::AST::SendNode]
|
28
|
-
# @return [void]
|
29
|
-
def insert_disable_ddl_transaction(
|
30
|
-
corrector,
|
31
|
-
node
|
32
|
-
)
|
33
|
-
corrector.insert_before(
|
34
|
-
node.each_ancestor(:def).first,
|
35
|
-
"disable_ddl_transaction!\n\n "
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
# @param node [RuboCop::AST::SendNode]
|
40
|
-
# @return [Boolean]
|
41
|
-
def within_disable_ddl_transaction?(node)
|
42
|
-
node.each_ancestor(:def).first&.left_siblings&.any? do |sibling|
|
43
|
-
sibling.is_a?(::RuboCop::AST::SendNode) &&
|
44
|
-
disable_ddl_transaction?(sibling)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|