ezcater_rubocop 1.1.1 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 323c025da922f1cda50aabdabe7bf0869962acab4a539d31ab46e0f53e9cb7ae
4
- data.tar.gz: 9fefcf330dd581976919e2350c7c21394752d9b5ee22487e164d8b216e54fbab
3
+ metadata.gz: 5c15a00ae9ee7d51e47aaf97b9fb70308b94992ce89ea2f2240a9405021b90b1
4
+ data.tar.gz: 80c042251192d29ff9e3fda486fbd18cdd02e9231b3ba381650488dd86a0a14e
5
5
  SHA512:
6
- metadata.gz: 4cfb5f29b315f4b275f9b664864a289651395093a8f3aefd010bb233744b93d00639a24fefa5e7ba4600ad3fea76206c53c946932e3b0f6303919257dd605933
7
- data.tar.gz: 620ededc1b8d3c301bfb79d31de02953a5172167741e52b19475e747a4d24847e5a4a75e62fc8540d4eb75ae135e7e2a5cd74d4771ac6a67bb60a128db4859b7
6
+ metadata.gz: c0c6d395b37d422cbf0d63bd221dd1cc971da352b1af23d9b5c871e922731f8492095d2ceceea4cdb33a630b72bb7799acf69ddb4d9a1bf8046b8e587d1436d2
7
+ data.tar.gz: f6573e38d0e0b75df186f03941a72552854cb5f22c4fe8f488f2f013ae3d633e6b317b2d4212e22a3d706da795cd78a61ee5dd44e6632006b50fc303787f5780
data/CHANGELOG.md CHANGED
@@ -10,6 +10,10 @@ Prior to v1.0.0 this gem was versioned based on the `MAJOR`.`MINOR` version of R
10
10
 
11
11
  - ...
12
12
 
13
+ ## v1.2.0
14
+
15
+ - Add `Ezcater/RailsTopLevelSqlExecute` to replace `ActiveRecord::Base.connection.execute` with `execute` in `db/migrate/`.
16
+
13
17
  ## v1.1.1
14
18
 
15
19
  - Exclude `lib/tasks/` for `Ezcater/RailsEnv` and `Ezcater/DirectEnvCheck`.
@@ -47,6 +47,12 @@ Rails/UnknownEnv:
47
47
  - staging
48
48
  - production
49
49
 
50
+ Ezcater/RailsTopLevelSqlExecute:
51
+ Description: 'Use `execute` instead of `ActiveRecord::Base.connection.execute` in migrations.'
52
+ Enabled: true
53
+ Include:
54
+ - "db/migrate/**/*"
55
+
50
56
  Ezcater/RailsEnv:
51
57
  Description: 'Enforce the use of `Rails.configuration.x.<foo>` instead of checking `Rails.env`.'
52
58
  Enabled: true
@@ -17,6 +17,7 @@ RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
17
17
  require "rubocop/cop/ezcater/direct_env_check"
18
18
  require "rubocop/cop/ezcater/rails_configuration"
19
19
  require "rubocop/cop/ezcater/rails_env"
20
+ require "rubocop/cop/ezcater/rails_top_level_sql_execute"
20
21
  require "rubocop/cop/ezcater/require_gql_error_helpers"
21
22
  require "rubocop/cop/ezcater/rspec_match_ordered_array"
22
23
  require "rubocop/cop/ezcater/rspec_require_browser_mock"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EzcaterRubocop
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Ezcater
6
+ # Use `execute` instead of `ActiveRecord::Base.connection.execute` in migrations. The latter is redundant and
7
+ # can bypass migration safety checks.
8
+ #
9
+ # @example
10
+ #
11
+ # # good
12
+ # execute("...")
13
+ #
14
+ # # bad
15
+ # ActiveRecord::Base.connection.execute("...")
16
+ #
17
+ class RailsTopLevelSqlExecute < Cop
18
+ MSG = <<~END_MESSAGE.split("\n").join(" ")
19
+ Use `execute` instead of `ActiveRecord::Base.connection.execute` in migrations. The latter is
20
+ redundant and can bypass safety checks.
21
+ END_MESSAGE
22
+
23
+ def_node_matcher "ar_connection_execute", <<-PATTERN
24
+ (send (send (const (const _ :ActiveRecord) :Base) :connection) :execute _)
25
+ PATTERN
26
+
27
+ def on_send(node)
28
+ ar_connection_execute(node) do
29
+ add_offense(node, location: :expression, message: MSG)
30
+ end
31
+ end
32
+
33
+ def autocorrect(node)
34
+ lambda do |corrector|
35
+ range = Parser::Source::Range.new(
36
+ node.source_range.source_buffer,
37
+ node.source_range.begin_pos,
38
+ node.source_range.end_pos
39
+ )
40
+
41
+ corrector.replace(range, "execute(#{node.last_argument.source})")
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezcater_rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ezCater, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-02 00:00:00.000000000 Z
11
+ date: 2019-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -161,6 +161,7 @@ files:
161
161
  - lib/rubocop/cop/ezcater/direct_env_check.rb
162
162
  - lib/rubocop/cop/ezcater/rails_configuration.rb
163
163
  - lib/rubocop/cop/ezcater/rails_env.rb
164
+ - lib/rubocop/cop/ezcater/rails_top_level_sql_execute.rb
164
165
  - lib/rubocop/cop/ezcater/require_gql_error_helpers.rb
165
166
  - lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
166
167
  - lib/rubocop/cop/ezcater/rspec_match_ordered_array.rb