netsoft-danger 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/netsoft-circle +1 -1
- data/lib/netsoft-danger/version.rb +1 -1
- data/netsoft-danger.gemspec +0 -4
- metadata +2 -62
- data/lib/netsoft-danger.rb +0 -3
- data/lib/netsoft-danger/cops.rb +0 -1
- data/lib/netsoft-danger/cops/netsoft/auth_http_positional_arguments.rb +0 -142
- data/rubocop/config-2019-08-12.yml +0 -95
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 896e582de631d926bd01d4f5d98d0bde7f20f9a0ec129600bcea3eff09ffbb53
|
4
|
+
data.tar.gz: 9613d84bcd13e28594d387b66c1d1cc379d2f6ee62857e4ddcf2bce30761466a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9600eeb6dc24d45393f88ce2f4e956885209974d0910bec466354fca4950de21a78fad98986f2c1593074a44c72f95d8d0760254e6b08a5b3bd6b1a6daef5d39
|
7
|
+
data.tar.gz: 244fa8e69810e66bd44b37d6b156dc58229bc6ff6fe39f736928332f1209d200fc003651dc7c8f1863cc90d57dbb24f874e4075492239d33e3506829ecd752ec
|
data/bin/netsoft-circle
CHANGED
data/netsoft-danger.gemspec
CHANGED
@@ -17,9 +17,5 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.add_development_dependency 'rake'
|
19
19
|
s.add_runtime_dependency 'danger', '~> 5.0'
|
20
|
-
s.add_runtime_dependency 'rubocop', '~> 0.74.0'
|
21
|
-
s.add_runtime_dependency 'rubocop-rails', '~> 2.2.1'
|
22
|
-
s.add_runtime_dependency 'rubocop-performance', '~> 1.4.1'
|
23
|
-
s.add_runtime_dependency 'rubocop-rspec', '~> 1.35.0'
|
24
20
|
s.add_runtime_dependency 'thor'
|
25
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netsoft-danger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- urkle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,62 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '5.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rubocop
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.74.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.74.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop-rails
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2.2.1
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2.2.1
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop-performance
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 1.4.1
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.4.1
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 1.35.0
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 1.35.0
|
97
41
|
- !ruby/object:Gem::Dependency
|
98
42
|
name: thor
|
99
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,13 +69,9 @@ files:
|
|
125
69
|
- bin/tag_check.sh
|
126
70
|
- dangerfiles/issue.js
|
127
71
|
- dangerfiles/pr.js
|
128
|
-
- lib/netsoft-danger.rb
|
129
|
-
- lib/netsoft-danger/cops.rb
|
130
|
-
- lib/netsoft-danger/cops/netsoft/auth_http_positional_arguments.rb
|
131
72
|
- lib/netsoft-danger/version.rb
|
132
73
|
- netsoft-danger.gemspec
|
133
74
|
- package.json
|
134
|
-
- rubocop/config-2019-08-12.yml
|
135
75
|
- settings-peril.json
|
136
76
|
- yarn.lock
|
137
77
|
homepage: https://github.com/NetsoftHoldings/danger
|
data/lib/netsoft-danger.rb
DELETED
data/lib/netsoft-danger/cops.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require_relative 'cops/netsoft/auth_http_positional_arguments'
|
@@ -1,142 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rubocop/cop/mixin/target_rails_version'
|
4
|
-
|
5
|
-
module RuboCop
|
6
|
-
module Cop
|
7
|
-
module Netsoft
|
8
|
-
# This cop is used to identify usages of http methods like `get`, `post`,
|
9
|
-
# `put`, `patch` without the usage of keyword arguments in your tests and
|
10
|
-
# change them to use keyword args. This cop only applies to Rails >= 5.
|
11
|
-
# If you are running Rails < 5 you should disable the
|
12
|
-
# Netsoft/HttpPositionalArguments cop or set your TargetRailsVersion in your
|
13
|
-
# .rubocop.yml file to 4.0, etc.
|
14
|
-
#
|
15
|
-
# @example
|
16
|
-
# # bad
|
17
|
-
# get :new, { user_id: 1}
|
18
|
-
#
|
19
|
-
# # good
|
20
|
-
# get :new, params: { user_id: 1 }
|
21
|
-
class AuthHttpPositionalArguments < Cop
|
22
|
-
extend RuboCop::Cop::TargetRailsVersion
|
23
|
-
|
24
|
-
MSG = 'Use keyword arguments instead of ' \
|
25
|
-
'positional arguments for http call: `%<verb>s`.'.freeze
|
26
|
-
KEYWORD_ARGS = %i[
|
27
|
-
method params session body flash xhr as headers env
|
28
|
-
].freeze
|
29
|
-
HTTP_METHODS = %i[get post put patch delete head].freeze
|
30
|
-
HTTP_AUTH_METHODS = %i[get_with post_with put_with patch_with delete_with].freeze
|
31
|
-
|
32
|
-
minimum_target_rails_version 5.0
|
33
|
-
|
34
|
-
def_node_matcher :http_request?, <<-PATTERN
|
35
|
-
(send nil? {#{HTTP_METHODS.map(&:inspect).join(' ')}} !nil? $_ ...)
|
36
|
-
PATTERN
|
37
|
-
|
38
|
-
def_node_matcher :http_auth_request?, <<-PATTERN
|
39
|
-
(send nil? {#{HTTP_AUTH_METHODS.map(&:inspect).join(' ')}} !nil? !nil? $_ ...)
|
40
|
-
PATTERN
|
41
|
-
|
42
|
-
def on_send(node)
|
43
|
-
http_request?(node) do |data|
|
44
|
-
return unless needs_conversion?(data)
|
45
|
-
|
46
|
-
add_offense(node, location: :selector,
|
47
|
-
message: format(MSG, verb: node.method_name))
|
48
|
-
end
|
49
|
-
|
50
|
-
http_auth_request?(node) do |data|
|
51
|
-
return unless auth_needs_conversion?(data)
|
52
|
-
|
53
|
-
add_offense(node, location: :selector,
|
54
|
-
message: format(MSG, verb: node.method_name))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# given a pre Rails 5 method: get :new, {user_id: @user.id}, {}
|
59
|
-
#
|
60
|
-
# @return lambda of auto correct procedure
|
61
|
-
# the result should look like:
|
62
|
-
# get :new, params: { user_id: @user.id }, session: {}
|
63
|
-
# the http_method is the method used to call the controller
|
64
|
-
# the controller node can be a symbol, method, object or string
|
65
|
-
# that represents the path/action on the Rails controller
|
66
|
-
# the data is the http parameters and environment sent in
|
67
|
-
# the Rails 5 http call
|
68
|
-
def autocorrect(node)
|
69
|
-
has_auth = HTTP_AUTH_METHODS.include?(node.method_name.to_sym)
|
70
|
-
if has_auth
|
71
|
-
user, http_path, *data = *node.arguments
|
72
|
-
else
|
73
|
-
http_path, *data = *node.arguments
|
74
|
-
end
|
75
|
-
|
76
|
-
controller_action = http_path.source
|
77
|
-
params = convert_hash_data(data.first, 'params')
|
78
|
-
session = convert_hash_data(data.last, 'session') if data.size > 1
|
79
|
-
# the range of the text to replace, which is the whole line
|
80
|
-
code_to_replace = node.loc.expression
|
81
|
-
# what to replace with
|
82
|
-
format = parentheses_format(node)
|
83
|
-
new_code = format(format, name: node.method_name,
|
84
|
-
action: has_auth ? [user.source, controller_action].join(',') : controller_action,
|
85
|
-
params: params, session: session)
|
86
|
-
->(corrector) { corrector.replace(code_to_replace, new_code) }
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
def needs_conversion?(data)
|
92
|
-
return true unless data.hash_type?
|
93
|
-
|
94
|
-
data.each_pair.none? do |pair|
|
95
|
-
special_keyword_arg?(pair.key) ||
|
96
|
-
format_arg?(pair.key) && data.pairs.one?
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def auth_needs_conversion?(data)
|
101
|
-
return true unless data.hash_type?
|
102
|
-
|
103
|
-
data.each_pair.none? do |pair|
|
104
|
-
special_keyword_arg?(pair.key) ||
|
105
|
-
format_arg?(pair.key) && data.pairs.one?
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def special_keyword_arg?(node)
|
110
|
-
node.sym_type? && KEYWORD_ARGS.include?(node.value)
|
111
|
-
end
|
112
|
-
|
113
|
-
def format_arg?(node)
|
114
|
-
node.sym_type? && node.value == :format
|
115
|
-
end
|
116
|
-
|
117
|
-
def convert_hash_data(data, type)
|
118
|
-
return '' if data.hash_type? && data.empty?
|
119
|
-
|
120
|
-
hash_data = if data.hash_type?
|
121
|
-
format('{ %<data>s }',
|
122
|
-
data: data.pairs.map(&:source).join(', '))
|
123
|
-
else
|
124
|
-
# user supplies an object,
|
125
|
-
# no need to surround with braces
|
126
|
-
data.source
|
127
|
-
end
|
128
|
-
|
129
|
-
format(', %<type>s: %<hash_data>s', type: type, hash_data: hash_data)
|
130
|
-
end
|
131
|
-
|
132
|
-
def parentheses_format(node)
|
133
|
-
if parentheses?(node)
|
134
|
-
'%<name>s(%<action>s%<params>s%<session>s)'
|
135
|
-
else
|
136
|
-
'%<name>s %<action>s%<params>s%<session>s'
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- netsoft-danger
|
3
|
-
- rubocop-rails
|
4
|
-
- rubocop-performance
|
5
|
-
- rubocop-rspec
|
6
|
-
|
7
|
-
AllCops:
|
8
|
-
TargetRubyVersion: 2.4
|
9
|
-
TargetRailsVersion: 5.2
|
10
|
-
DisplayStyleGuide: true
|
11
|
-
StyleGuideBaseURL: https://rubystyle.guide
|
12
|
-
Exclude:
|
13
|
-
- 'db/**/*'
|
14
|
-
- 'coverage/**/*'
|
15
|
-
- 'log/**/*'
|
16
|
-
- 'public/**/*'
|
17
|
-
- 'tmp/**/*'
|
18
|
-
- 'spec/dummy/**/*'
|
19
|
-
- 'vendor/**/*'
|
20
|
-
|
21
|
-
Naming/RescuedExceptionsVariableName:
|
22
|
-
PreferredName: ex
|
23
|
-
Naming/UncommunicativeMethodParamName:
|
24
|
-
AllowedNames:
|
25
|
-
- me
|
26
|
-
- ex
|
27
|
-
|
28
|
-
Layout/AlignHash:
|
29
|
-
EnforcedHashRocketStyle: table
|
30
|
-
EnforcedColonStyle: table
|
31
|
-
Layout/ExtraSpacing:
|
32
|
-
AllowForAlignment: true
|
33
|
-
Layout/IndentAssignment:
|
34
|
-
IndentationWidth: 4
|
35
|
-
Layout/IndentFirstArrayElement:
|
36
|
-
EnforcedStyle: consistent
|
37
|
-
IndentationWidth: 4
|
38
|
-
Layout/IndentFirstHashElement:
|
39
|
-
EnforcedStyle: consistent
|
40
|
-
IndentationWidth: 4
|
41
|
-
Layout/SpaceInsideBlockBraces:
|
42
|
-
EnforcedStyle: no_space
|
43
|
-
SpaceBeforeBlockParameters: false
|
44
|
-
Layout/SpaceInsideHashLiteralBraces:
|
45
|
-
EnforcedStyle: no_space
|
46
|
-
|
47
|
-
Lint/AmbiguousBlockAssociation:
|
48
|
-
Exclude:
|
49
|
-
- spec/**/*
|
50
|
-
|
51
|
-
Rails:
|
52
|
-
Enabled: true
|
53
|
-
Rails/HttpPositionalArguments:
|
54
|
-
Enabled: false
|
55
|
-
Rails/SkipsModelValidations:
|
56
|
-
Whitelist:
|
57
|
-
- touch
|
58
|
-
- update_attribute
|
59
|
-
- update_counters
|
60
|
-
- increment_counter
|
61
|
-
- decrement_counter
|
62
|
-
Netsoft/AuthHttpPositionalArguments:
|
63
|
-
Enabled: true
|
64
|
-
Include:
|
65
|
-
- 'spec/controllers/**/*'
|
66
|
-
|
67
|
-
RSpec/ExpectChange:
|
68
|
-
EnforcedStyle: block
|
69
|
-
RSpec/ImplicitSubject:
|
70
|
-
Enabled: false
|
71
|
-
RSpec/MessageSpies:
|
72
|
-
Enabled: false
|
73
|
-
RSpec/NamedSubject:
|
74
|
-
Enabled: false
|
75
|
-
RSpec/NestedGroups:
|
76
|
-
Enabled: false
|
77
|
-
RSpec/NotToNot:
|
78
|
-
EnforcedStyle: to_not
|
79
|
-
|
80
|
-
Style/AndOr:
|
81
|
-
EnforcedStyle: conditionals
|
82
|
-
Style/BlockDelimiters:
|
83
|
-
EnforcedStyle: semantic
|
84
|
-
AllowBracesOnProceduralOneLiners: true
|
85
|
-
Style/MultilineBlockChain:
|
86
|
-
Enabled: false
|
87
|
-
Style/RescueModifier:
|
88
|
-
Enabled: false
|
89
|
-
Style/TrailingCommaInArrayLiteral:
|
90
|
-
EnforcedStyleForMultiline: comma
|
91
|
-
Style/TrailingCommaInHashLiteral:
|
92
|
-
EnforcedStyleForMultiline: comma
|
93
|
-
|
94
|
-
Metrics:
|
95
|
-
Enabled: false
|