rubocop-springest 0.6.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.
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module GitHub
8
+ class RailsViewRenderPathsExist < Cop
9
+ def_node_matcher :render?, <<-PATTERN
10
+ (send nil? :render $...)
11
+ PATTERN
12
+
13
+ def_node_matcher :render_str?, <<-PATTERN
14
+ (send nil? :render $(str $_) ...)
15
+ PATTERN
16
+
17
+ def_node_matcher :render_options?, <<-PATTERN
18
+ (send nil? :render (hash $...))
19
+ PATTERN
20
+
21
+ def_node_matcher :partial_key?, <<-PATTERN
22
+ (pair (sym :partial) $(str $_))
23
+ PATTERN
24
+
25
+ def on_send(node)
26
+ return unless cop_config["ViewPath"]
27
+
28
+ if args = render_str?(node)
29
+ node, path = args
30
+ unless resolve_partial(path.to_s)
31
+ add_offense(node, location: :expression, message: "Partial template could not be found")
32
+ end
33
+ elsif pairs = render_options?(node)
34
+ if pair = pairs.detect { |p| partial_key?(p) }
35
+ node, path = partial_key?(pair)
36
+
37
+ unless resolve_partial(path.to_s)
38
+ add_offense(node, location: :expression, message: "Partial template could not be found")
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ def resolve_partial(path)
45
+ parts = path.split(File::SEPARATOR)
46
+ parts << "_#{parts.pop}"
47
+ path = parts.join(File::SEPARATOR)
48
+
49
+ cop_config["ViewPath"].each do |view_path|
50
+ if m = Dir[File.join(config.path_relative_to_config(view_path), path) + "*"].first
51
+ return m
52
+ end
53
+ end
54
+ nil
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module GitHub
8
+ class RailsViewRenderShorthand < Cop
9
+ MSG = "Prefer `render` partial shorthand"
10
+
11
+ def_node_matcher :render_with_options?, <<-PATTERN
12
+ (send nil? :render (hash $...))
13
+ PATTERN
14
+
15
+ def_node_matcher :partial_key?, <<-PATTERN
16
+ (pair (sym :partial) $(str _))
17
+ PATTERN
18
+
19
+ def_node_matcher :locals_key?, <<-PATTERN
20
+ (pair (sym :locals) $_)
21
+ PATTERN
22
+
23
+ def on_send(node)
24
+ if option_pairs = render_with_options?(node)
25
+ partial_key = option_pairs.map { |pair| partial_key?(pair) }.compact.first
26
+ locals_key = option_pairs.map { |pair| locals_key?(pair) }.compact.first
27
+
28
+ if option_pairs.length == 1 && partial_key
29
+ add_offense(node, location: :expression, message: "Use `render #{partial_key.source}` instead")
30
+ elsif option_pairs.length == 2 && partial_key && locals_key
31
+ add_offense(node, location: :expression, message: "Use `render #{partial_key.source}, #{locals_key.source}` instead")
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ require "rubocop/cop/github/rails_application_record"
2
+ require "rubocop/cop/github/rails_controller_render_action_symbol"
3
+ require "rubocop/cop/github/rails_controller_render_literal"
4
+ require "rubocop/cop/github/rails_controller_render_paths_exist"
5
+ require "rubocop/cop/github/rails_controller_render_shorthand"
6
+ require "rubocop/cop/github/rails_render_inline"
7
+ require "rubocop/cop/github/rails_render_object_collection"
8
+ require "rubocop/cop/github/rails_view_render_literal"
9
+ require "rubocop/cop/github/rails_view_render_paths_exist"
10
+ require "rubocop/cop/github/rails_view_render_shorthand"
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-springest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Mulder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.51'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.51'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionview
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: erubis
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.7'
83
+ description: 'Code style checking for Springest Ruby repositories '
84
+ email:
85
+ - markmulder@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - README.md
92
+ - STYLEGUIDE.md
93
+ - config/default.yml
94
+ - config/rails.yml
95
+ - guides/rails-controller-render-shorthand.md
96
+ - guides/rails-render-inline.md
97
+ - guides/rails-render-literal.md
98
+ - lib/rubocop/cop/github.rb
99
+ - lib/rubocop/cop/github/rails_application_record.rb
100
+ - lib/rubocop/cop/github/rails_controller_render_action_symbol.rb
101
+ - lib/rubocop/cop/github/rails_controller_render_literal.rb
102
+ - lib/rubocop/cop/github/rails_controller_render_paths_exist.rb
103
+ - lib/rubocop/cop/github/rails_controller_render_shorthand.rb
104
+ - lib/rubocop/cop/github/rails_render_inline.rb
105
+ - lib/rubocop/cop/github/rails_render_object_collection.rb
106
+ - lib/rubocop/cop/github/rails_view_render_literal.rb
107
+ - lib/rubocop/cop/github/rails_view_render_paths_exist.rb
108
+ - lib/rubocop/cop/github/rails_view_render_shorthand.rb
109
+ homepage: https://github.com/springest/rubocop-springest
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 2.1.0
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.13
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: RuboCop Springest
133
+ test_files: []