rubocop-g2 1.6.0 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78336eed3c07bfeec4e0b69c5aff3c25afe16a829a7189ed845d324ffbf1e000
4
- data.tar.gz: ec8ba26224f063994a158ef7924c124e08146bebc79908f83499e3e20b07c14f
3
+ metadata.gz: a0d87aea83dd481168c720b74ef346eb287790b5fb361617e34926e2e594fdc6
4
+ data.tar.gz: 7af47137f5f989fdfe3143beb7662b94dc892ff7fb3f26594e55227fede04b1e
5
5
  SHA512:
6
- metadata.gz: 341ea0af56943e1029e7909a382f1da8ff2a332ca8c7d62a39cca6c631aa73c0ce5de58a85c7f5e0f7ac26e9964c4c02f24fa53249b1c7def23f71c3525cc54b
7
- data.tar.gz: 3ec4fe034ba044d66d9796cefedc31dbad4eadca4476ab4f2cf819dac6edcab4f8c78470d2b7300669fe5aff84de5c71a81dcfbb9718e17ac285f9131665e3b4
6
+ metadata.gz: 12ffe75d1138d09a1d86f3eeb25752707f04897442059b1b8ddeca1b6bd1cc5365baabef0c45880a92b58df2a7e7ca96dd6a463235d7ad9f296e383a791a66d0
7
+ data.tar.gz: f86d5a5065034f92de4106e9ed94c16875354a5b83c276af5a1bd7c1582810f63958fac98c986bd5d1d5bd3435cdc5dcae623e4952c4629478df84808ebebd87
@@ -0,0 +1,7 @@
1
+ name: Build
2
+ on:
3
+ pull_request:
4
+
5
+ jobs:
6
+ test:
7
+ uses: ./.github/workflows/test.yml
@@ -0,0 +1,18 @@
1
+ name: Build
2
+ on:
3
+ push:
4
+ tags:
5
+ - "v*"
6
+
7
+ jobs:
8
+ test:
9
+ uses: ./.github/workflows/test.yml
10
+ release:
11
+ runs-on: ubuntu-22.04
12
+ needs: test
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - name: Build and publish gem
16
+ uses: g2crowd/gh-actions/actions/publish-gem@v1.0.0
17
+ with:
18
+ github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,25 @@
1
+ on:
2
+ workflow_call:
3
+ inputs:
4
+ runs-on:
5
+ required: false
6
+ type: string
7
+ default: "ubuntu-22.04"
8
+ ruby-version:
9
+ required: false
10
+ type: string
11
+ default: '3.2.2'
12
+
13
+
14
+ jobs:
15
+ test:
16
+ name: Run Specs
17
+ runs-on: ${{ inputs.runs-on }}
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ inputs.ruby-version }}
23
+ bundler-cache: true
24
+ - name: Run Specs
25
+ run: bundle exec rspec spec
data/.rubocop.yml CHANGED
@@ -1,105 +1,17 @@
1
+ inherit_from:
2
+ - config/ruby/default.yml
3
+ - config/rspec/default.yml
4
+
1
5
  require:
2
6
  - rubocop-rspec
3
7
 
4
- Layout/SpaceAroundMethodCallOperator:
5
- Enabled: false
6
-
7
- Layout/SpaceBeforeFirstArg:
8
- Enabled: false
9
-
10
- Layout/MultilineOperationIndentation:
11
- Enabled: false
12
-
13
- Layout/ClassStructure:
14
- Enabled: true
15
-
16
- Layout/MultilineMethodCallIndentation:
17
- EnforcedStyle: indented_relative_to_receiver
18
-
19
- Layout/EmptyLineAfterGuardClause:
20
- Enabled: false
21
-
22
- Layout/LineLength:
23
- Max: 120
24
- IgnoredPatterns:
25
- - ^#
26
-
27
- Lint/AssignmentInCondition:
28
- Enabled: false
29
-
30
- Lint/RaiseException:
31
- Enabled: true
32
-
33
- Lint/StructNewOverride:
34
- Enabled: true
35
-
36
- Metrics/AbcSize:
37
- Max: 20
38
-
39
- Metrics/BlockLength:
40
- Enabled: false
41
-
42
- Metrics/ClassLength:
43
- Max: 500
44
-
45
- Metrics/MethodLength:
46
- Max: 15
47
-
48
- Metrics/ParameterLists:
49
- Max: 5
50
-
51
- Style/AndOr:
52
- Enabled: false
53
-
54
- Style/ClassAndModuleChildren:
55
- AutoCorrect: true
8
+ AllCops:
9
+ NewCops: enable
10
+ SuggestExtensions: false
11
+ TargetRubyVersion: 2.7
56
12
 
57
13
  Style/Documentation:
58
14
  Enabled: false
59
15
 
60
- Style/EmptyMethod:
61
- Enabled: false
62
-
63
- Style/ExponentialNotation:
64
- Enabled: false
65
-
66
- Style/FormatStringToken:
67
- EnforcedStyle: template
68
-
69
- Style/FrozenStringLiteralComment:
70
- Enabled: false
71
-
72
- Style/HashEachMethods:
73
- Enabled: true
74
-
75
- Style/HashTransformKeys:
76
- Enabled: false
77
-
78
- Style/HashTransformValues:
79
- Enabled: false
80
-
81
- Style/Lambda:
82
- Enabled: false
83
-
84
- Style/LambdaCall:
85
- Enabled: false
86
-
87
- Style/NumericLiterals:
88
- Enabled: false
89
-
90
- Style/PercentLiteralDelimiters:
91
- PreferredDelimiters:
92
- default: ()
93
- '%w': '()'
94
- '%W': '()'
95
- '%i': '()'
96
- '%I': '()'
97
-
98
- Style/SingleLineBlockParams:
99
- Enabled: false
100
-
101
- Style/SymbolProc:
102
- Enabled: false
103
-
104
16
  RSpec/ExampleLength:
105
- Enabled: false
17
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.1.1
1
+ ruby 3.2.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-g2 (1.5.3)
4
+ rubocop-g2 (1.9.2)
5
5
  rubocop (>= 0.82)
6
6
  rubocop-rails (>= 2.5)
7
7
  rubocop-rspec (>= 1.39)
@@ -9,30 +9,35 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.1)
12
+ activesupport (7.0.7)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
16
16
  tzinfo (~> 2.0)
17
17
  ast (2.4.2)
18
- coderay (1.1.2)
19
- concurrent-ruby (1.1.9)
18
+ base64 (0.1.1)
19
+ coderay (1.1.3)
20
+ concurrent-ruby (1.2.2)
20
21
  diff-lcs (1.3)
21
- i18n (1.8.11)
22
+ i18n (1.14.1)
22
23
  concurrent-ruby (~> 1.0)
23
- method_source (0.9.2)
24
- minitest (5.15.0)
25
- parallel (1.21.0)
26
- parser (3.1.0.0)
24
+ json (2.6.3)
25
+ language_server-protocol (3.17.0.3)
26
+ method_source (1.0.0)
27
+ minitest (5.19.0)
28
+ parallel (1.23.0)
29
+ parser (3.2.2.3)
27
30
  ast (~> 2.4.1)
28
- pry (0.12.2)
29
- coderay (~> 1.1.0)
30
- method_source (~> 0.9.0)
31
- rack (2.2.3)
32
- rainbow (3.0.0)
31
+ racc
32
+ pry (0.14.2)
33
+ coderay (~> 1.1)
34
+ method_source (~> 1.0)
35
+ racc (1.7.1)
36
+ rack (3.0.8)
37
+ rainbow (3.1.1)
33
38
  rake (12.3.3)
34
- regexp_parser (2.2.0)
35
- rexml (3.2.5)
39
+ regexp_parser (2.8.1)
40
+ rexml (3.2.6)
36
41
  rspec (3.8.0)
37
42
  rspec-core (~> 3.8.0)
38
43
  rspec-expectations (~> 3.8.0)
@@ -46,27 +51,36 @@ GEM
46
51
  diff-lcs (>= 1.2.0, < 2.0)
47
52
  rspec-support (~> 3.8.0)
48
53
  rspec-support (3.8.3)
49
- rubocop (1.24.1)
54
+ rubocop (1.56.1)
55
+ base64 (~> 0.1.1)
56
+ json (~> 2.3)
57
+ language_server-protocol (>= 3.17.0)
50
58
  parallel (~> 1.10)
51
- parser (>= 3.0.0.0)
59
+ parser (>= 3.2.2.3)
52
60
  rainbow (>= 2.2.2, < 4.0)
53
61
  regexp_parser (>= 1.8, < 3.0)
54
- rexml
55
- rubocop-ast (>= 1.15.1, < 2.0)
62
+ rexml (>= 3.2.5, < 4.0)
63
+ rubocop-ast (>= 1.28.1, < 2.0)
56
64
  ruby-progressbar (~> 1.7)
57
- unicode-display_width (>= 1.4.0, < 3.0)
58
- rubocop-ast (1.15.1)
59
- parser (>= 3.0.1.1)
60
- rubocop-rails (2.13.0)
65
+ unicode-display_width (>= 2.4.0, < 3.0)
66
+ rubocop-ast (1.29.0)
67
+ parser (>= 3.2.1.0)
68
+ rubocop-capybara (2.18.0)
69
+ rubocop (~> 1.41)
70
+ rubocop-factory_bot (2.23.1)
71
+ rubocop (~> 1.33)
72
+ rubocop-rails (2.20.2)
61
73
  activesupport (>= 4.2.0)
62
74
  rack (>= 1.1)
63
- rubocop (>= 1.7.0, < 2.0)
64
- rubocop-rspec (2.7.0)
65
- rubocop (~> 1.19)
66
- ruby-progressbar (1.11.0)
67
- tzinfo (2.0.4)
75
+ rubocop (>= 1.33.0, < 2.0)
76
+ rubocop-rspec (2.23.2)
77
+ rubocop (~> 1.33)
78
+ rubocop-capybara (~> 2.17)
79
+ rubocop-factory_bot (~> 2.22)
80
+ ruby-progressbar (1.13.0)
81
+ tzinfo (2.0.6)
68
82
  concurrent-ruby (~> 1.0)
69
- unicode-display_width (2.1.0)
83
+ unicode-display_width (2.4.2)
70
84
 
71
85
  PLATFORMS
72
86
  ruby
@@ -79,4 +93,4 @@ DEPENDENCIES
79
93
  rubocop-g2!
80
94
 
81
95
  BUNDLED WITH
82
- 2.3.10
96
+ 2.3.12
@@ -18,7 +18,7 @@ Layout/EmptyLineAfterGuardClause:
18
18
 
19
19
  Layout/LineLength:
20
20
  Max: 120
21
- IgnoredPatterns:
21
+ AllowedPatterns:
22
22
  - ^#
23
23
 
24
24
  Lint/AssignmentInCondition:
@@ -20,9 +20,11 @@ module RuboCop
20
20
  args.find(&:hash_type?)&.children&.map(&:children) || []
21
21
  end
22
22
 
23
+ # rubocop:disable Lint/BooleanSymbol
23
24
  def args_include_decorative?(args)
24
25
  args.include? [s(:sym, :decorative), s(:true)]
25
26
  end
27
+ # rubocop:enable Lint/BooleanSymbol
26
28
 
27
29
  def args_include_aria_label?(args)
28
30
  args.any? { |arg| arg.first == s(:sym, :aria_label) && arg.last != s(:nil) }
@@ -0,0 +1,52 @@
1
+ module RuboCop
2
+ module Cop
3
+ module G2
4
+ class BanGlobalMethods < RuboCop::Cop::Cop
5
+ MSG = 'Do not define top-level methods.'.freeze
6
+
7
+ def_node_matcher :const_block?, <<~PATTERN
8
+ (block (send (const _ _) _+) _ _)
9
+ PATTERN
10
+
11
+ def_node_matcher :eval_block?, <<~PATTERN
12
+ (block (send _ /(class|instance)_eval/ _*) _ _)
13
+ PATTERN
14
+
15
+ def_node_matcher :describe_block?, <<~PATTERN
16
+ (block (send _ :describe _*) _ _)
17
+ PATTERN
18
+
19
+ def on_def(node)
20
+ node.each_ancestor do |ancestor|
21
+ return if ancestor.class_type? || ancestor.module_type?
22
+ return if const_block?(ancestor)
23
+ return if describe_block?(ancestor)
24
+
25
+ if eval_block?(ancestor)
26
+ evaled_obj = ancestor.children.first.receiver
27
+ return unless evaled_obj.nil? || evaled_obj.self_type?
28
+ end
29
+ end
30
+
31
+ add_offense node, message: MSG
32
+ end
33
+ alias on_defs on_def
34
+
35
+ def_node_matcher :define_method?, <<~PATTERN
36
+ (send _ /define_(singleton_)?method/ _)
37
+ PATTERN
38
+
39
+ def_node_matcher :send_define_method?, <<~PATTERN
40
+ (send _ /(public_)?send/ (_ /define_(singleton_)?method/) _)
41
+ PATTERN
42
+
43
+ def on_send(node)
44
+ return unless define_method?(node) || send_define_method?(node)
45
+ return unless node.receiver.nil? || node.receiver.self_type?
46
+
47
+ on_def(node)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,39 @@
1
+ require 'rubocop/cop/mixin/migrations_helper'
2
+ require_relative 'check_existence'
3
+
4
+ module RuboCop
5
+ module Cop
6
+ module G2
7
+ module Migrations
8
+ class Change < RuboCop::Cop::Cop
9
+ include RuboCop::Cop::MigrationsHelper
10
+
11
+ MSG = 'Replace `change` with `up` and `down` migration methods when using schema methods that should check existence'.freeze
12
+
13
+ def on_def(node)
14
+ return unless should_add_offense?(node)
15
+
16
+ add_offense node
17
+ end
18
+
19
+ private
20
+
21
+ def should_add_offense?(node)
22
+ node.method_name == :change &&
23
+ in_migration?(node) &&
24
+ includes_methods_with_existence_check?(node)
25
+ end
26
+
27
+ def includes_methods_with_existence_check?(node)
28
+ node.descendants.any?(&method(:method_with_existence_check?))
29
+ end
30
+
31
+ def method_with_existence_check?(node)
32
+ node.type == :send &&
33
+ RuboCop::Cop::G2::Migrations::CheckExistence::RESTRICT_ON_SEND.include?(node.method_name)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,98 @@
1
+ require 'rubocop/cop/mixin/migrations_helper'
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module G2
6
+ module Migrations
7
+ class CheckExistence < RuboCop::Cop::Cop
8
+ include RuboCop::Cop::MigrationsHelper
9
+
10
+ method_map = {
11
+ add_belongs_to: :remove_belongs_to,
12
+ add_check_constraint: :remove_check_constraint,
13
+ add_column: :remove_column,
14
+ add_foreign_key: :remove_foreign_key,
15
+ add_index: :remove_index,
16
+ add_reference: :remove_reference,
17
+ add_timestamps: :remove_timestamps,
18
+ create_join_table: :drop_join_table,
19
+ create_table: :drop_table
20
+ }
21
+
22
+ CONSTRUCTIVE_METHODS = method_map.keys.freeze
23
+ DESTRUCTIVE_METHODS = method_map.values.freeze
24
+ IF_EXISTS_MSG = 'Use `if_exists: true` option'.freeze
25
+ IF_NOT_EXISTS_MSG = 'Use `if_not_exists: true` option'.freeze
26
+ WITH_OPTIONS_NODE_TYPES = %i(block send).freeze
27
+
28
+ RESTRICT_ON_SEND = (CONSTRUCTIVE_METHODS + DESTRUCTIVE_METHODS).freeze
29
+
30
+ def on_send(node)
31
+ return unless in_migration?(node)
32
+
33
+ error = check_for_errors(node)
34
+ return unless error
35
+
36
+ add_offense node, message: error
37
+ end
38
+
39
+ private
40
+
41
+ def check_for_errors(node)
42
+ if constructive?(node)
43
+ check_if_not_exists(node)
44
+ elsif destructive?(node)
45
+ check_if_exists(node)
46
+ end
47
+ end
48
+
49
+ def constructive?(node)
50
+ CONSTRUCTIVE_METHODS.include? node.method_name
51
+ end
52
+
53
+ def destructive?(node)
54
+ DESTRUCTIVE_METHODS.include? node.method_name
55
+ end
56
+
57
+ def check_if_not_exists(node)
58
+ check_kwargs node, :if_not_exists, IF_NOT_EXISTS_MSG
59
+ end
60
+
61
+ def check_if_exists(node)
62
+ check_kwargs node, :if_exists, IF_EXISTS_MSG
63
+ end
64
+
65
+ def check_kwargs(node, arg_name, msg)
66
+ valid_kwarg = true_kwarg(arg_name)
67
+ return if has_kwarg?(node, valid_kwarg)
68
+
69
+ node.each_ancestor do |ancestor|
70
+ next unless is_with_options_call?(ancestor)
71
+
72
+ with_options_call = ancestor.type == :block ? ancestor.children.first : ancestor
73
+ return if has_kwarg?(with_options_call, valid_kwarg)
74
+ end
75
+
76
+ msg
77
+ end
78
+
79
+ def true_kwarg(arg_name)
80
+ s(:pair, s(:sym, arg_name), s(:true))
81
+ end
82
+
83
+ def is_with_options_call?(node)
84
+ WITH_OPTIONS_NODE_TYPES.include?(node.type) &&
85
+ node.method_name == :with_options
86
+ end
87
+
88
+ def has_kwarg?(node, check_kwarg)
89
+ node.arguments.any? do |arguments|
90
+ arguments.type == :hash &&
91
+ arguments.descendants.include?(check_kwarg)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'migrations/change'
2
+ require_relative 'migrations/check_existence'
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module G2
3
- VERSION = '1.6.0'.freeze
3
+ VERSION = '1.9.2'.freeze
4
4
  end
5
5
  end
data/lib/rubocop_g2.rb CHANGED
@@ -8,3 +8,5 @@ require_relative 'rubocop/cop/g2/raw_connection_execute'
8
8
  require_relative 'rubocop/cop/g2/safe_connection_handling'
9
9
  require_relative 'rubocop/cop/g2/aggregates_model_boundary'
10
10
  require_relative 'rubocop/cop/g2/accessible_icons'
11
+ require_relative 'rubocop/cop/g2/migrations'
12
+ require_relative 'rubocop/cop/g2/ban_global_methods'
data/rubocop-g2.gemspec CHANGED
@@ -20,6 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
+
24
+ spec.metadata['homepage_uri'] = spec.homepage
25
+ spec.metadata['source_code_uri'] = "https://github.com/g2crowd/#{spec.name}"
26
+ spec.metadata['rubygems_mfa_required'] = 'true'
27
+ spec.required_ruby_version = '>= 2.7'
28
+
23
29
  spec.add_dependency 'rubocop', '>= 0.82'
24
30
  spec.add_dependency 'rubocop-rails', '>= 2.5'
25
31
  spec.add_dependency 'rubocop-rspec', '>= 1.39'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-g2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Mannino
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-24 00:00:00.000000000 Z
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -115,8 +115,12 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/build.yml"
119
+ - ".github/workflows/publish.yml"
120
+ - ".github/workflows/test.yml"
118
121
  - ".gitignore"
119
122
  - ".rubocop.yml"
123
+ - ".ruby-version"
120
124
  - ".tool-versions"
121
125
  - Gemfile
122
126
  - Gemfile.lock
@@ -129,7 +133,11 @@ files:
129
133
  - lib/rubocop/cop/g2/accessible_icons.rb
130
134
  - lib/rubocop/cop/g2/aggregates_model_boundary.rb
131
135
  - lib/rubocop/cop/g2/ban_decorators.rb
136
+ - lib/rubocop/cop/g2/ban_global_methods.rb
132
137
  - lib/rubocop/cop/g2/ban_sidekiq_worker.rb
138
+ - lib/rubocop/cop/g2/migrations.rb
139
+ - lib/rubocop/cop/g2/migrations/change.rb
140
+ - lib/rubocop/cop/g2/migrations/check_existence.rb
133
141
  - lib/rubocop/cop/g2/predicate_memoization.rb
134
142
  - lib/rubocop/cop/g2/raw_connection_execute.rb
135
143
  - lib/rubocop/cop/g2/safe_connection_handling.rb
@@ -138,7 +146,10 @@ files:
138
146
  - rubocop-g2.gemspec
139
147
  homepage: https://g2.com
140
148
  licenses: []
141
- metadata: {}
149
+ metadata:
150
+ homepage_uri: https://g2.com
151
+ source_code_uri: https://github.com/g2crowd/rubocop-g2
152
+ rubygems_mfa_required: 'true'
142
153
  post_install_message:
143
154
  rdoc_options: []
144
155
  require_paths:
@@ -147,14 +158,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
158
  requirements:
148
159
  - - ">="
149
160
  - !ruby/object:Gem::Version
150
- version: '0'
161
+ version: '2.7'
151
162
  required_rubygems_version: !ruby/object:Gem::Requirement
152
163
  requirements:
153
164
  - - ">="
154
165
  - !ruby/object:Gem::Version
155
166
  version: '0'
156
167
  requirements: []
157
- rubygems_version: 3.3.7
168
+ rubygems_version: 3.4.10
158
169
  signing_key:
159
170
  specification_version: 4
160
171
  summary: Custom cops for G2.