rubocop-betterment 1.8.2 → 1.13.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: dad4b799b42ff956d077416311a5bcbe8ccf9bde1d80199650591afc5bf4e769
4
- data.tar.gz: f194b9cd4100956e414069fa722d06f299bfa76615a2f4a3bc80ca15f8aac3ee
3
+ metadata.gz: cc4eabc0685d064150b4545175e96ee1c848ad32f53bf35f83b5125a7c309b82
4
+ data.tar.gz: 258718477b39bb37af975daae5f1d4db1ea7e4adb55d7b8ee6b3757aee5dbfbd
5
5
  SHA512:
6
- metadata.gz: 35d0c88facf8eb1e9a41c32a8a000caf3b97fd250f237fe5dd13b043df7af3f80fc7acf9b1eefddeceda946c8b0f0f33c3ca8c13b961a4c69f49224fdf594f52
7
- data.tar.gz: a98a6b5f06d19cb8754d3b7b1ed998f79a7259821796c26e61142671f9e73ead325c5e780b1ffe11f15140b88fcb3bc68f3bc318a0d0ad15afb6b505b6a48541
6
+ metadata.gz: 692eb066b0e6b45d0c7049f90acc66c600d1a6b24793ba691975112ccd5a7ddcfc01b3674dc180fecf9eb75dd4445c826d30864b4fbea1768e53df1fceb1c2e4
7
+ data.tar.gz: 7cee25dc098dbabbdac9ae42a10ada567047e211c445cb6ecef7405ae6da89a03927c044f3fb9781a2bb6e48b7fb3fa1f608f820076d4828159477cee8864914
@@ -8,7 +8,6 @@ AllCops:
8
8
  Exclude:
9
9
  - 'bin/**/*'
10
10
  - 'db/**/*'
11
- - 'config/**/*'
12
11
  - 'vendor/**/*'
13
12
  - 'frontend/**/*'
14
13
  - 'build/**/*'
@@ -44,6 +43,10 @@ Layout/MultilineMethodCallIndentation:
44
43
  Layout/MultilineOperationIndentation:
45
44
  EnforcedStyle: indented
46
45
 
46
+ # Disabling because of a bug in rubocop: https://github.com/rubocop-hq/rubocop/issues/6918
47
+ Layout/RescueEnsureAlignment:
48
+ Enabled: false
49
+
47
50
  Lint/AmbiguousBlockAssociation:
48
51
  Exclude:
49
52
  - 'spec/**/*'
@@ -63,27 +66,32 @@ Lint/BooleanSymbol:
63
66
  Metrics/AbcSize:
64
67
  Exclude:
65
68
  - 'spec/**/*'
69
+ - 'webvalve/**/*'
66
70
 
67
71
  Metrics/BlockLength:
68
72
  Enabled: false
69
73
 
70
74
  Metrics/ClassLength:
71
75
  Max: 250
76
+ Exclude:
77
+ - 'webvalve/**/*'
72
78
 
73
79
  Metrics/CyclomaticComplexity:
74
80
  Max: 10
75
81
  Exclude:
76
82
  - 'spec/**/*'
83
+ - 'webvalve/**/*'
77
84
 
78
85
  Metrics/LineLength:
79
86
  Max: 140
80
87
 
81
88
  Metrics/MethodLength:
82
- Exclude:
83
- - 'spec/**/*'
89
+ Enabled: false
84
90
 
85
91
  Metrics/ModuleLength:
86
92
  Max: 250
93
+ Exclude:
94
+ - 'webvalve/**/*'
87
95
 
88
96
  Metrics/ParameterLists:
89
97
  Max: 5
@@ -92,6 +100,7 @@ Metrics/ParameterLists:
92
100
  Metrics/PerceivedComplexity:
93
101
  Exclude:
94
102
  - 'spec/**/*'
103
+ - 'webvalve/**/*'
95
104
 
96
105
  Naming/HeredocDelimiterNaming:
97
106
  Enabled: false
@@ -248,5 +257,15 @@ Style/StringLiterals:
248
257
  Style/SymbolProc:
249
258
  Enabled: false
250
259
 
260
+ # Use a trailing comma to keep diffs clean when elements are inserted or removed
261
+ Style/TrailingCommaInArguments:
262
+ EnforcedStyleForMultiline: comma
263
+
264
+ Style/TrailingCommaInArrayLiteral:
265
+ EnforcedStyleForMultiline: comma
266
+
267
+ Style/TrailingCommaInHashLiteral:
268
+ EnforcedStyleForMultiline: comma
269
+
251
270
  Style/YodaCondition:
252
271
  Enabled: false
@@ -2,3 +2,5 @@ require 'rubocop'
2
2
  require 'rubocop/cop/betterment/timeout'
3
3
  require 'rubocop/cop/betterment/memoization_with_arguments'
4
4
  require 'rubocop/cop/betterment/site_prism_loaded'
5
+ require 'rubocop/cop/betterment/spec_helper_required_outside_spec_dir'
6
+ require 'rubocop/cop/betterment/implicit_redirect_type'
@@ -0,0 +1,70 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Betterment
4
+ # Require explicit redirect statuses in routes.rb. Refer to the book for more details:
5
+ # https://github.com/Betterment/the-book/blob/master/platform-specific/ruby.markdown#use-temporary-redirects-eg-redirectstatus-302
6
+ #
7
+ # @example
8
+ # # bad
9
+ # get '/', redirect('/dashboard')
10
+ # get { |params, request| '/dashboard' }
11
+ #
12
+ # # good
13
+ # get '/', redirect('/dashboard', status: 301)
14
+ # get(status: 302) { |params, request| '/dashboard' }
15
+ class ImplicitRedirectType < Cop
16
+ ROUTES_FILE_NAME = 'routes.rb'.freeze
17
+ MSG =
18
+ 'Rails will create a permanent (301) redirect, which is dangerous. ' \
19
+ 'Please specify your desired status, e.g. redirect(..., status: 302)'.freeze
20
+
21
+ # redirect('/')
22
+ def_node_matcher :arg_form_without_options?, <<-PATTERN
23
+ (send nil? :redirect (str _))
24
+ PATTERN
25
+
26
+ # redirect { |_params, _request| '/' }
27
+ def_node_matcher :block_form_without_options?, <<-PATTERN
28
+ (block (send nil? :redirect) ...)
29
+ PATTERN
30
+
31
+ # redirect('/', foo: 'bar')
32
+ def_node_matcher :arg_form_with_options, <<-PATTERN
33
+ (send nil? :redirect (str _) (hash $...))
34
+ PATTERN
35
+
36
+ # redirect(foo: 'bar') { |_params, _request| '/' }
37
+ def_node_matcher :block_form_with_options, <<-PATTERN
38
+ (block (send nil? :redirect (hash $...)) ...)
39
+ PATTERN
40
+
41
+ # status: anything
42
+ def_node_matcher :valid_status_option?, <<-PATTERN
43
+ (pair (sym :status) _)
44
+ PATTERN
45
+
46
+ def on_block(node)
47
+ return unless routes_file?
48
+
49
+ if block_form_with_options(node) { |options| options.none?(&method(:valid_status_option?)) } || block_form_without_options?(node)
50
+ add_offense(node, message: MSG)
51
+ end
52
+ end
53
+
54
+ def on_send(node)
55
+ return unless routes_file?
56
+
57
+ if arg_form_with_options(node) { |options| options.none?(&method(:valid_status_option?)) } || arg_form_without_options?(node)
58
+ add_offense(node, message: MSG)
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def routes_file?
65
+ Pathname.new(processed_source.buffer.name).basename.to_s == ROUTES_FILE_NAME
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,38 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Betterment
4
+ # If a file requires spec_helper or rails_helper, make sure
5
+ # it is located in a spec/ directory.
6
+ #
7
+ # @example
8
+ # # bad
9
+ # app/models/whatever_spec.rb
10
+ # require 'rails_helper'
11
+ #
12
+ # # good
13
+ # spec/models/my_class_spec.rb
14
+ # require 'rails_helper'
15
+ class SpecHelperRequiredOutsideSpecDir < Cop
16
+ MSG = 'Spec helper required outside of a spec/ directory.'.freeze
17
+
18
+ def_node_matcher :requires_spec_helper?, <<-PATTERN
19
+ (send nil? :require
20
+ (str {"rails_helper" "spec_helper"}))
21
+ PATTERN
22
+
23
+ def on_send(node)
24
+ add_offense(node, message: MSG) if requires_spec_helper?(node) && !spec_directory?
25
+ end
26
+
27
+ private
28
+
29
+ def spec_directory?
30
+ Pathname.new(processed_source.buffer.name)
31
+ .relative_path_from(Pathname.pwd)
32
+ .to_s
33
+ .start_with?("spec#{File::SEPARATOR}")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-betterment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Development
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-20 00:00:00.000000000 Z
11
+ date: 2020-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -91,8 +91,10 @@ files:
91
91
  - STYLEGUIDE.md
92
92
  - config/default.yml
93
93
  - lib/rubocop/cop/betterment.rb
94
+ - lib/rubocop/cop/betterment/implicit_redirect_type.rb
94
95
  - lib/rubocop/cop/betterment/memoization_with_arguments.rb
95
96
  - lib/rubocop/cop/betterment/site_prism_loaded.rb
97
+ - lib/rubocop/cop/betterment/spec_helper_required_outside_spec_dir.rb
96
98
  - lib/rubocop/cop/betterment/timeout.rb
97
99
  homepage:
98
100
  licenses:
@@ -113,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
115
  - !ruby/object:Gem::Version
114
116
  version: '0'
115
117
  requirements: []
116
- rubygems_version: 3.0.4
118
+ rubygems_version: 3.1.3
117
119
  signing_key:
118
120
  specification_version: 4
119
121
  summary: Betterment rubocop configuration