ezcater_rubocop 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/conf/rubocop_rails.yml +6 -0
- data/lib/ezcater_rubocop.rb +1 -0
- data/lib/ezcater_rubocop/version.rb +1 -1
- data/lib/rubocop/cop/ezcater/rails_top_level_sql_execute.rb +47 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c15a00ae9ee7d51e47aaf97b9fb70308b94992ce89ea2f2240a9405021b90b1
|
4
|
+
data.tar.gz: 80c042251192d29ff9e3fda486fbd18cdd02e9231b3ba381650488dd86a0a14e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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`.
|
data/conf/rubocop_rails.yml
CHANGED
@@ -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
|
data/lib/ezcater_rubocop.rb
CHANGED
@@ -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"
|
@@ -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.
|
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-
|
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
|