rubocop-g2 1.7.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: b484fad7593fa6a699916c560ed8ec2b5d4926496168486b48ff6fff18492bb3
4
- data.tar.gz: e4096d81c7896f473c6191e0f6f864f58d3a18e1872297ce2d32687400e78c2f
3
+ metadata.gz: a0d87aea83dd481168c720b74ef346eb287790b5fb361617e34926e2e594fdc6
4
+ data.tar.gz: 7af47137f5f989fdfe3143beb7662b94dc892ff7fb3f26594e55227fede04b1e
5
5
  SHA512:
6
- metadata.gz: 1483423826e3a387185ac626fc3b41a86531cddb705c5c9a02695c4534dc1353ae8504227ed5fc973fb3e1f1bec7068deda047a099cbd4df2d45709ebffd9ea3
7
- data.tar.gz: dafd8ef06fa641161e1eb9a0073a65de9ab78046adc79f1f9afbadf420d69aafd613244ad4c3e277e0de1b1e24473e911a208fdf4bb4377c77daaecd1916f012
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/.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.7.0)
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.2.4)
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.10)
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.10.0)
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.22.1)
26
- parser (3.1.2.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)
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)
32
37
  rainbow (3.1.1)
33
38
  rake (12.3.3)
34
- regexp_parser (2.3.1)
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.28.2)
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.1.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.17.0, < 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.17.0)
59
- parser (>= 3.1.1.0)
60
- rubocop-rails (2.14.2)
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.10.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
@@ -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.7.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,9 @@ 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}"
23
26
  spec.metadata['rubygems_mfa_required'] = 'true'
24
27
  spec.required_ruby_version = '>= 2.7'
25
28
 
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.7.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-04-28 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
@@ -139,6 +147,8 @@ files:
139
147
  homepage: https://g2.com
140
148
  licenses: []
141
149
  metadata:
150
+ homepage_uri: https://g2.com
151
+ source_code_uri: https://github.com/g2crowd/rubocop-g2
142
152
  rubygems_mfa_required: 'true'
143
153
  post_install_message:
144
154
  rdoc_options: []
@@ -155,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
165
  - !ruby/object:Gem::Version
156
166
  version: '0'
157
167
  requirements: []
158
- rubygems_version: 3.3.7
168
+ rubygems_version: 3.4.10
159
169
  signing_key:
160
170
  specification_version: 4
161
171
  summary: Custom cops for G2.