rubocop-betterment 1.10.0 → 1.11.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: 90431e9c1e2edefc54944622ad8885b0ae7bda94bcdea4e1364f766e6d88880a
4
- data.tar.gz: d1ee2fcf9fdebb45a726394ddaa36458454cecede00949ed70d43abbe66aa4cd
3
+ metadata.gz: 53a8c97fad6bd1efe6b5698e45325d58185d2f767c5b43375faff67721b69ad2
4
+ data.tar.gz: 99430282d066784a5e4dfca2fd9f872d86483c337a8b3aa8562785e3d2f4b808
5
5
  SHA512:
6
- metadata.gz: 4c0d493052df02777e92c08759c36e573c452994ed770d0e20059f3f9804f44f914ee1a2985137e0e8b68ec7205ae5125307aeb7f5b8d8fd9c2c2b8976b23b38
7
- data.tar.gz: 3fec119ef35007f33a3ce0ab48a2e3bcd2dbfc8abebb1d010e8ca27d728c5cd72cd466af9b2b6fb7b1ee787e88af1191cce90f28d5335fb12ce9b305ba1e36db
6
+ metadata.gz: 9915e7cd9a2b0fc718621baf131281ecdbac8ebc63d6d2fde808ea4c4af8677a6b85b44044d854a529a4b85aecb899e99aa6a285eaaeb276861195c7d00bb2c2
7
+ data.tar.gz: 468d83dfb01860aa77c24d3f938060b8d05c82ae75b0e46a3a1f887c27fd183cef2c002783c72472820ad506ee4134ac82cd4804631643ed2621be97f67e1d98
@@ -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
@@ -3,3 +3,4 @@ require 'rubocop/cop/betterment/timeout'
3
3
  require 'rubocop/cop/betterment/memoization_with_arguments'
4
4
  require 'rubocop/cop/betterment/site_prism_loaded'
5
5
  require 'rubocop/cop/betterment/spec_helper_required_outside_spec_dir'
6
+ require 'rubocop/cop/betterment/implicit_redirect_type'
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.10.0
4
+ version: 1.11.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-07-31 00:00:00.000000000 Z
11
+ date: 2019-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -91,6 +91,7 @@ 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
96
97
  - lib/rubocop/cop/betterment/spec_helper_required_outside_spec_dir.rb
@@ -114,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  - !ruby/object:Gem::Version
115
116
  version: '0'
116
117
  requirements: []
117
- rubygems_version: 3.0.3
118
+ rubygems_version: 3.0.6
118
119
  signing_key:
119
120
  specification_version: 4
120
121
  summary: Betterment rubocop configuration