rf-stylez 0.2.12 → 0.2.15
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 +4 -4
- data/lib/rf/stylez.rb +3 -0
- data/lib/rf/stylez/version.rb +1 -1
- data/lib/rubocop/cop/lint/no_grape_api.rb +27 -0
- data/lib/rubocop/cop/lint/use_positive_int32_validator.rb +46 -0
- data/ruby/rubocop.yml +9 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4637e73990ffdf9494d85b346bef5679a32cfb2f7dd80cf4a619e2367a16f0e3
|
4
|
+
data.tar.gz: b8bc8869394241260e18f9fad024473a8ead0330fe06d099ca1af56c1b32dff7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 501fc3fb8b183136ae320a937ca6e02f52162d057c7d93897e1424fe6a25f8b3bb6410ccf95de8a3b959854d4f7f6f455e9704ea7337e27cc5c932d1a9923e66
|
7
|
+
data.tar.gz: 2a969a0daac927c764988423b3c03aa283e8ee202d62e11c323c144dc3dc4bdf7752d348abb48cbcb74cb80c1595ef3bc445eb358ca2848b53da3065c1490faf
|
data/lib/rf/stylez.rb
CHANGED
data/lib/rf/stylez/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# @example
|
7
|
+
# # bad
|
8
|
+
# class Foo < Grape::API
|
9
|
+
#
|
10
|
+
# # good
|
11
|
+
# class Foo < Api::AuthBase
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# class Foo < Api::Base
|
15
|
+
class NoGrapeAPI < Cop
|
16
|
+
MSG = 'Prefer inheriting `Api::AuthBase` or `Api::Base` instead of `Grape::API`.'.freeze
|
17
|
+
|
18
|
+
def_node_matcher :inherits_Grape_API?, '(class (const ...) (const (const nil? :Grape) :API) ...)'
|
19
|
+
|
20
|
+
def on_class(node)
|
21
|
+
return unless inherits_Grape_API?(node)
|
22
|
+
add_offense(node)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'byebug'
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Lint
|
7
|
+
# @example
|
8
|
+
# # bad
|
9
|
+
# params do
|
10
|
+
# requires :id, type: Integer
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# params do
|
15
|
+
# requires :id, type: Integer, positive_int32: true
|
16
|
+
# end
|
17
|
+
class UsePositiveInt32Validator < Cop
|
18
|
+
MSG = 'If this Integer maps to a postgres Integer column, validate with `positive_int32: true`'.freeze
|
19
|
+
|
20
|
+
# if a params block, return all the nodes in it
|
21
|
+
def_node_matcher :is_grape_params?, '(block (send nil? :params) (args) $...)'
|
22
|
+
# check if the param is `requires` / `optional`
|
23
|
+
def_node_search :find_params_hashes, <<~PATTERN
|
24
|
+
(send nil? {:requires :optional}
|
25
|
+
(sym _)
|
26
|
+
$(hash ...) ...)
|
27
|
+
PATTERN
|
28
|
+
# check if hash contains `type: Integer`
|
29
|
+
def_node_search :is_type_integer?, '(pair (sym :type) (const nil? :Integer))'
|
30
|
+
# check if the hash contains the `positive_int32` validator
|
31
|
+
def_node_search :validates_integer?, '(pair (sym :positive_int32) (true))'
|
32
|
+
|
33
|
+
def on_block(node)
|
34
|
+
params = is_grape_params?(node)
|
35
|
+
return unless
|
36
|
+
hash = find_params_hashes(node)
|
37
|
+
hash&.each do |param|
|
38
|
+
if is_type_integer?(param) && !validates_integer?(param)
|
39
|
+
add_offense(param)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/ruby/rubocop.yml
CHANGED
@@ -19,12 +19,17 @@ inherit_from:
|
|
19
19
|
require:
|
20
20
|
- rf/stylez
|
21
21
|
|
22
|
+
# Custom cops
|
22
23
|
Lint/NoENV:
|
23
24
|
Enabled: true
|
24
25
|
Lint/NoHTTParty:
|
25
26
|
Enabled: true
|
26
27
|
Lint/Obscure:
|
27
28
|
Enabled: true
|
29
|
+
Lint/NoGrapeAPI:
|
30
|
+
Enabled: true
|
31
|
+
Lint/UserPositiveInt32Validator:
|
32
|
+
Enabled: true
|
28
33
|
|
29
34
|
# Good style cops
|
30
35
|
Layout/BlockAlignment:
|
@@ -105,6 +110,10 @@ Naming/FileName:
|
|
105
110
|
Naming/MethodName:
|
106
111
|
Enabled: true
|
107
112
|
|
113
|
+
Style/SpecialGlobalVars:
|
114
|
+
Enabled: true
|
115
|
+
Style/GlobalVars:
|
116
|
+
Enabled: true
|
108
117
|
Style/FrozenStringLiteralComment:
|
109
118
|
Enabled: true
|
110
119
|
EnforcedStyle: always
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rf-stylez
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emanuel Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -100,8 +100,10 @@ files:
|
|
100
100
|
- lib/rf/stylez.rb
|
101
101
|
- lib/rf/stylez/version.rb
|
102
102
|
- lib/rubocop/cop/lint/no_env.rb
|
103
|
+
- lib/rubocop/cop/lint/no_grape_api.rb
|
103
104
|
- lib/rubocop/cop/lint/no_http_party.rb
|
104
105
|
- lib/rubocop/cop/lint/obscure.rb
|
106
|
+
- lib/rubocop/cop/lint/use_positive_int32_validator.rb
|
105
107
|
- rf-stylez.gemspec
|
106
108
|
- ruby/rubocop.yml
|
107
109
|
- ruby/rubocop_lint.yml
|