rubomatic-html 1.1.0.pre.rc.4 → 1.1.0.pre.rc.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +10 -1
  3. data/config/default.yml +28 -0
  4. data/docs/cops/style/README.adoc +9 -0
  5. data/docs/cops/style/no_fields_for/README.adoc +28 -0
  6. data/docs/cops/style/no_form_for/README.adoc +28 -0
  7. data/docs/cops/style/no_form_tag/README.adoc +28 -0
  8. data/docs/cops/style/no_on_before_unload/README.adoc +29 -0
  9. data/docs/cops/style/no_on_click/README.adoc +29 -0
  10. data/docs/cops/style/no_on_drag/README.adoc +29 -0
  11. data/docs/cops/style/no_on_load/README.adoc +29 -0
  12. data/docs/cops/style/no_on_unload/README.adoc +29 -0
  13. data/docs/cops/style/no_on_wheel/README.adoc +29 -0
  14. data/exe/rubomatic-html +1 -1
  15. data/lib/rubomatic-html/cop/base.rb +58 -0
  16. data/lib/rubomatic-html/cop/cops.rb +19 -0
  17. data/lib/rubomatic-html/cop/layout/base.rb +17 -0
  18. data/lib/rubomatic-html/cop/layout/line_length.rb +28 -0
  19. data/lib/rubomatic-html/cop/layout/multiple_line_breaks.rb +42 -0
  20. data/lib/rubomatic-html/cop/layout/trailing_whitespace.rb +28 -0
  21. data/lib/rubomatic-html/cop/style/base.rb +17 -0
  22. data/lib/rubomatic-html/cop/style/no_fields_for.rb +28 -0
  23. data/lib/rubomatic-html/cop/style/no_form_for.rb +28 -0
  24. data/lib/rubomatic-html/cop/style/no_form_tag.rb +28 -0
  25. data/lib/rubomatic-html/cop/style/no_on_attribute.rb +31 -0
  26. data/lib/rubomatic-html/cop/style/no_on_before_unload.rb +27 -0
  27. data/lib/rubomatic-html/cop/style/no_on_click.rb +27 -0
  28. data/lib/rubomatic-html/cop/style/no_on_drag.rb +27 -0
  29. data/lib/rubomatic-html/cop/style/no_on_load.rb +27 -0
  30. data/lib/rubomatic-html/cop/style/no_on_unload.rb +27 -0
  31. data/lib/rubomatic-html/cop/style/no_on_wheel.rb +27 -0
  32. data/lib/rubomatic-html/cop/style/partial_instance_variable.rb +44 -0
  33. data/lib/rubomatic-html/generator/cop_readme_injector.rb +48 -0
  34. data/lib/rubomatic-html/generator/dept_readme_injector.rb +111 -0
  35. data/lib/rubomatic-html/generator.rb +330 -0
  36. data/lib/rubomatic-html/inject.rb +19 -0
  37. data/lib/rubomatic-html/runner.rb +129 -0
  38. data/lib/rubomatic-html/version.rb +5 -0
  39. data/lib/rubomatic-html.rb +11 -1
  40. metadata +47 -18
  41. data/lib/rubomatic/html/cop/base.rb +0 -42
  42. data/lib/rubomatic/html/cop/cops.rb +0 -9
  43. data/lib/rubomatic/html/cop/layout/base.rb +0 -19
  44. data/lib/rubomatic/html/cop/layout/line_length.rb +0 -26
  45. data/lib/rubomatic/html/cop/layout/multiple_line_breaks.rb +0 -40
  46. data/lib/rubomatic/html/cop/layout/trailing_whitespace.rb +0 -26
  47. data/lib/rubomatic/html/cop/style/base.rb +0 -19
  48. data/lib/rubomatic/html/cop/style/partial_instance_variable.rb +0 -28
  49. data/lib/rubomatic/html/version.rb +0 -7
  50. data/lib/rubomatic/html.rb +0 -115
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f52910879670f3735917444c9f07cdd5e48482e86eee31dfba5e9ef5a07d6592
4
- data.tar.gz: b17f6e50c324ebe35f6c17eff1bb3668dfe7c83c4eb1ef80bae75dd37e370e58
3
+ metadata.gz: 467e4c9c16de255810fdc5d1058d29d3e340560f32c2453fd0f8bc914103455c
4
+ data.tar.gz: 182aa194c22b44ada0459778a4b3fda459607c260348322a320616e3801d223c
5
5
  SHA512:
6
- metadata.gz: f3ec93a413b3b553b534b9930ac33cd3a012b74cbd896c6cf4a2db34c367c40737a7ccdbcdf7a01cf5f45e8b64c4c95a11f8391e48ad464b9a2306ccdaf8611a
7
- data.tar.gz: accb7976c86bf9f8fad66fb5db53f1586d33879ef8f5a1bbb9193e97369150fc5006e6ca19d000774451dce7e679259d473b8d6088c0b6c1e64a12ed2a1cac7b
6
+ metadata.gz: 28f2f50f3f52d4da719fd70cf87b02a91f4c8cd69d25cc1d63846b75eb5f5c1b022663ff7abf9470d61a7b471f4b5cbf0d567ede7474183e9029b1001ca016b7
7
+ data.tar.gz: 20e586355ef10cb218a39081d52b26fa349c119aff56e204d302f277d2855456f38b54d2efbe4d49f60867bf63501dc818db9c5ebe094ccf46db22fd5f855606
data/CHANGELOG.adoc CHANGED
@@ -1,3 +1,12 @@
1
- == 0.1.0
1
+ == 1.1.0
2
+
3
+ * Added
4
+
5
+ == 1.0.1
6
+
7
+ * Fix
8
+ ** No need to ``require 'bundler/setup'`` in script
9
+
10
+ == 1.0.0
2
11
 
3
12
  * Initial release
data/config/default.yml CHANGED
@@ -10,5 +10,33 @@ Layout/MultipleLineBreaks:
10
10
  Layout/TrailingWhitespace:
11
11
  Enabled: true
12
12
 
13
+ Style/NoFieldsFor:
14
+ Enabled: true
15
+
16
+ Style/NoFormFor:
17
+ Enabled: true
18
+
19
+ Style/NoFormTag:
20
+ Enabled: true
21
+
22
+ Style/NoOnBeforeUnload:
23
+ Enabled: true
24
+
25
+ Style/NoOnClick:
26
+ Enabled: true
27
+
28
+ Style/NoOnDrag:
29
+ Enabled: true
30
+
31
+ Style/NoOnLoad:
32
+ Enabled: true
33
+
34
+ Style/NoOnUnload:
35
+ Enabled: true
36
+
37
+ Style/NoOnWheel:
38
+ Enabled: true
39
+
13
40
  Style/PartialInstanceVariable:
14
41
  Enabled: true
42
+ AllowedIdentifiers: [ ]
@@ -4,4 +4,13 @@ Style cops check for stylistic consistency of your code
4
4
 
5
5
  == Cops
6
6
 
7
+ * xref:./no_fields_for/README.adoc[``Style/NoFieldsFor``]
8
+ * xref:./no_form_for/README.adoc[``Style/NoFormFor``]
9
+ * xref:./no_form_tag/README.adoc[``Style/NoFormTag``]
10
+ * xref:./no_on_before_unload/README.adoc[``Style/NoOnBeforeUnload``]
11
+ * xref:./no_on_click/README.adoc[``Style/NoOnClick``]
12
+ * xref:./no_on_drag/README.adoc[``Style/NoOnDrag``]
13
+ * xref:./no_on_load/README.adoc[``Style/NoOnLoad``]
14
+ * xref:./no_on_unload/README.adoc[``Style/NoOnUnload``]
15
+ * xref:./no_on_wheel/README.adoc[``Style/NoOnWheel``]
7
16
  * xref:./partial_instance_variable/README.adoc[``Style/PartialInstanceVariable``]
@@ -0,0 +1,28 @@
1
+ = ``Style/NoFieldsFor``
2
+
3
+ == Description
4
+
5
+ ``fields_for`` should be replaced with ``fields``
6
+
7
+ == Examples
8
+
9
+ [source,rhtml]
10
+ ----
11
+ <!-- Bad -->
12
+ <%= fields_for(:policies, policy, { index: policy.id }) do |pol_form| %>
13
+ <!-- Content -->
14
+ <% end %>
15
+
16
+ <!-- Good -->
17
+ <%= fields(:policies, model: policy, index: policy.id) do |pol_form| %>
18
+ <!-- Content -->
19
+ <% end %>
20
+ ----
21
+
22
+ == Configurable Attributes
23
+
24
+ There are no configurable attributes
25
+
26
+ == References
27
+
28
+ * https://github.com/BrandsInsurance/rubomatic-html/issues/8
@@ -0,0 +1,28 @@
1
+ = ``Style/NoFormFor``
2
+
3
+ == Description
4
+
5
+ ``form_for`` should be replaced with ``form_with``
6
+
7
+ == Examples
8
+
9
+ [source,rhtml]
10
+ ----
11
+ <!-- Bad -->
12
+ <%= form_for(policy) do |pol_form| %>
13
+ <!-- Content -->
14
+ <% end %>
15
+
16
+ <!-- Good -->
17
+ <%= form_with(model: policy) do |pol_form| %>
18
+ <!-- Content -->
19
+ <% end %>
20
+ ----
21
+
22
+ == Configurable Attributes
23
+
24
+ There are no configurable attributes
25
+
26
+ == References
27
+
28
+ * https://github.com/BrandsInsurance/rubomatic-html/issues/8
@@ -0,0 +1,28 @@
1
+ = ``Style/NoFormTag``
2
+
3
+ == Description
4
+
5
+ ``form_tag`` should be replaced with ``form_with``
6
+
7
+ == Examples
8
+
9
+ [source,rhtml]
10
+ ----
11
+ <!-- Bad -->
12
+ <%= form_tag(policy_path(policy)) do %>
13
+ <!-- Content -->
14
+ <% end %>
15
+
16
+ <!-- Good -->
17
+ <%= form_with(url: policy_path(policy)) do |form_helper| %>
18
+ <!-- Content -->
19
+ <% end %>
20
+ ----
21
+
22
+ == Configurable Attributes
23
+
24
+ There are no configurable attributes
25
+
26
+ == References
27
+
28
+ * https://github.com/BrandsInsurance/rubomatic-html/issues/8
@@ -0,0 +1,29 @@
1
+ = ``Style/NoOnBeforeUnload``
2
+
3
+ == Description
4
+
5
+ ``onbeforeunload`` attributes should not be used
6
+
7
+ == Examples
8
+
9
+ [source,rhtml]
10
+ ----
11
+ <!-- Bad -->
12
+ <body onbeforeunload="alert('Hello')">Beforeunload me</body>
13
+ <%= content_tag(:body, 'Beforeunload me', onbeforeunload: "alert('Hello')") %>
14
+ <%= content_tag(:body, 'Beforeunload me', 'onbeforeunload' => "alert('Hello')") %>
15
+
16
+ <!-- Good -->
17
+ <!-- Write code in javascript file to call alert('Hello') -->
18
+ <body>Beforeunload me</body>
19
+ <%= content_tag(:body, 'Beforeunload me') %>
20
+ <%= content_tag(:body, 'Beforeunload me') %>
21
+ ----
22
+
23
+ == Configurable Attributes
24
+
25
+ There are no configurable attributes
26
+
27
+ == References
28
+
29
+ * https://github.com/BrandsInsurance/expert-chainsaw/issues/234
@@ -0,0 +1,29 @@
1
+ = ``Style/NoOnClick``
2
+
3
+ == Description
4
+
5
+ ``onclick`` attributes should not be used
6
+
7
+ == Examples
8
+
9
+ [source,rhtml]
10
+ ----
11
+ <!-- Bad -->
12
+ <button type="button" onclick="alert('Hello')">Click me</button>
13
+ <%= button_tag('Click me', onclick: "alert('Hello')") %>
14
+ <%= button_tag('Click me', 'onclick' => "alert('Hello')") %>
15
+
16
+ <!-- Good -->
17
+ <!-- Write code in javascript file to call alert('Hello') -->
18
+ <button type="button">Click me</button>
19
+ <%= button_tag('Click me') %>
20
+ <%= button_tag('Click me') %>
21
+ ----
22
+
23
+ == Configurable Attributes
24
+
25
+ There are no configurable attributes
26
+
27
+ == References
28
+
29
+ * https://github.com/BrandsInsurance/expert-chainsaw/issues/234
@@ -0,0 +1,29 @@
1
+ = ``Style/NoOnDrag``
2
+
3
+ == Description
4
+
5
+ ``ondrag`` attributes should not be used
6
+
7
+ == Examples
8
+
9
+ [source,rhtml]
10
+ ----
11
+ <!-- Bad -->
12
+ <div ondrag="alert('Hello')">Drag me</div>
13
+ <%= content_tag(:div, 'Drag me', ondrag: "alert('Hello')") %>
14
+ <%= content_tag(:div, 'Drag me', 'ondrag' => "alert('Hello')") %>
15
+
16
+ <!-- Good -->
17
+ <!-- Write code in javascript file to call alert('Hello') -->
18
+ <div>Drag me</div>
19
+ <%= content_tag(:div, 'Drag me') %>
20
+ <%= content_tag(:div, 'Drag me') %>
21
+ ----
22
+
23
+ == Configurable Attributes
24
+
25
+ There are no configurable attributes
26
+
27
+ == References
28
+
29
+ * https://github.com/BrandsInsurance/expert-chainsaw/issues/234
@@ -0,0 +1,29 @@
1
+ = ``Style/NoOnLoad``
2
+
3
+ == Description
4
+
5
+ ``onload`` attributes should not be used
6
+
7
+ == Examples
8
+
9
+ [source,rhtml]
10
+ ----
11
+ <!-- Bad -->
12
+ <body onload="alert('Hello')">Load me</body>
13
+ <%= content_tag(:body, 'Load me', onload: "alert('Hello')") %>
14
+ <%= content_tag(:body, 'Load me', 'onload' => "alert('Hello')") %>
15
+
16
+ <!-- Good -->
17
+ <!-- Write code in javascript file to call alert('Hello') -->
18
+ <body>Load me</body>
19
+ <%= content_tag(:body, 'Load me') %>
20
+ <%= content_tag(:body, 'Load me') %>
21
+ ----
22
+
23
+ == Configurable Attributes
24
+
25
+ There are no configurable attributes
26
+
27
+ == References
28
+
29
+ * https://github.com/BrandsInsurance/expert-chainsaw/issues/234
@@ -0,0 +1,29 @@
1
+ = ``Style/NoOnUnload``
2
+
3
+ == Description
4
+
5
+ ``onunload`` attributes should not be used
6
+
7
+ == Examples
8
+
9
+ [source,rhtml]
10
+ ----
11
+ <!-- Bad -->
12
+ <body onunload="alert('Hello')">Unload me</body>
13
+ <%= content_tag(:body, 'Unload me', onunload: "alert('Hello')") %>
14
+ <%= content_tag(:body, 'Unload me', 'onunload' => "alert('Hello')") %>
15
+
16
+ <!-- Good -->
17
+ <!-- Write code in javascript file to call alert('Hello') -->
18
+ <body>Unload me</body>
19
+ <%= content_tag(:body, 'Unload me') %>
20
+ <%= content_tag(:body, 'Unload me') %>
21
+ ----
22
+
23
+ == Configurable Attributes
24
+
25
+ There are no configurable attributes
26
+
27
+ == References
28
+
29
+ * https://github.com/BrandsInsurance/expert-chainsaw/issues/234
@@ -0,0 +1,29 @@
1
+ = ``Style/NoOnWheel``
2
+
3
+ == Description
4
+
5
+ ``onwheel`` attributes should not be used
6
+
7
+ == Examples
8
+
9
+ [source,rhtml]
10
+ ----
11
+ <!-- Bad -->
12
+ <div onwheel="alert('Hello')">Wheel me</div>
13
+ <%= content_tag(:div, 'Wheel me', onwheel: "alert('Hello')") %>
14
+ <%= content_tag(:div, 'Wheel me', 'onwheel' => "alert('Hello')") %>
15
+
16
+ <!-- Good -->
17
+ <!-- Write code in javascript file to call alert('Hello') -->
18
+ <div>wheel me</div>
19
+ <%= content_tag(:div, 'Wheel me') %>
20
+ <%= content_tag(:div, 'Wheel me') %>
21
+ ----
22
+
23
+ == Configurable Attributes
24
+
25
+ There are no configurable attributes
26
+
27
+ == References
28
+
29
+ * https://github.com/BrandsInsurance/expert-chainsaw/issues/234
data/exe/rubomatic-html CHANGED
@@ -18,4 +18,4 @@ end
18
18
 
19
19
  parsed.parse!(into: options)
20
20
 
21
- Rubomatic::Html::Runner.new(options[:'linting-files']).run
21
+ RubomaticHtml::Runner.new(options[:'linting-files']).run
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ class Base
6
+ # @return [String]
7
+ attr_accessor :file
8
+ # @return [Hash]
9
+ attr_accessor :config
10
+
11
+ class << self
12
+ # @return [Boolean]
13
+ def abstract_cop?
14
+ true
15
+ end
16
+
17
+ # Name for cop
18
+ #
19
+ # @return [String]
20
+ #
21
+ def name
22
+ 'Base'
23
+ end
24
+
25
+ # Returns a hash whose keys represent the allowed config options and the values transform them from YML to ruby
26
+ #
27
+ # @return [Hash]
28
+ #
29
+ def allowed_config_transform
30
+ {}.freeze
31
+ end
32
+ end
33
+
34
+ # :nodoc:
35
+ def initialize(file, config)
36
+ @file = file
37
+ @config = config
38
+ end
39
+
40
+ private
41
+
42
+ # Outputs filename:line_number locations of HTML files that trigger the cop
43
+ #
44
+ # @param _line [String] the line in the html
45
+ # @param _index [Integer] the 1-index of the line
46
+ #
47
+ # @return [void]
48
+ #
49
+ def run_for_line(_line, _index)
50
+ error_message = <<~TEXT
51
+ Warning: Method `run_for_line` needs overridden! Some cops may not display failing messages.
52
+ TEXT
53
+
54
+ puts("\e[33m#{error_message}\e[0m")
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+ require_relative 'layout/base'
5
+ require_relative 'layout/line_length'
6
+ require_relative 'layout/multiple_line_breaks'
7
+ require_relative 'layout/trailing_whitespace'
8
+ require_relative 'style/base'
9
+ require_relative 'style/no_fields_for'
10
+ require_relative 'style/no_form_for'
11
+ require_relative 'style/no_form_tag'
12
+ require_relative 'style/no_on_attribute'
13
+ require_relative 'style/no_on_before_unload'
14
+ require_relative 'style/no_on_click'
15
+ require_relative 'style/no_on_drag'
16
+ require_relative 'style/no_on_load'
17
+ require_relative 'style/no_on_unload'
18
+ require_relative 'style/no_on_wheel'
19
+ require_relative 'style/partial_instance_variable'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ module Layout
6
+ class Base < RubomaticHtml::Cop::Base
7
+ # Department for cop
8
+ #
9
+ # @return [String]
10
+ #
11
+ def self.department
12
+ 'Layout'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ module Layout
6
+ class LineLength < RubomaticHtml::Cop::Layout::Base
7
+ class << self
8
+ # @see super
9
+ def abstract_cop?
10
+ false
11
+ end
12
+
13
+ # @see super
14
+ def name
15
+ [department, 'LineLength'].join('/')
16
+ end
17
+ end
18
+
19
+ # @see super
20
+ def run_for_line(line, index)
21
+ return if line.size <= 120
22
+
23
+ puts("#{file}:#{index}: is over 120 characters")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ module Layout
6
+ class MultipleLineBreaks < RubomaticHtml::Cop::Layout::Base
7
+ # @return [Boolean] tracks multiple consecutive line breaks
8
+ attr_accessor :prev_break
9
+
10
+ class << self
11
+ # @see super
12
+ def abstract_cop?
13
+ false
14
+ end
15
+
16
+ # @see super
17
+ def name
18
+ [department, 'MultipleLineBreaks'].join('/')
19
+ end
20
+ end
21
+
22
+ # :nodoc:
23
+ def initialize(...)
24
+ super(...)
25
+
26
+ @prev_break = false
27
+ end
28
+
29
+ # @see super
30
+ def run_for_line(line, index)
31
+ if prev_break && line.empty?
32
+ puts("#{file}:#{index}: has multiple line breaks")
33
+ elsif line.empty?
34
+ @prev_break = true
35
+ else
36
+ @prev_break = false
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ module Layout
6
+ class TrailingWhitespace < RubomaticHtml::Cop::Layout::Base
7
+ class << self
8
+ # @see super
9
+ def abstract_cop?
10
+ false
11
+ end
12
+
13
+ # @see super
14
+ def name
15
+ [department, 'TrailingWhitespace'].join('/')
16
+ end
17
+ end
18
+
19
+ # @see super
20
+ def run_for_line(line, index)
21
+ return unless line.match?(/\s\z/i)
22
+
23
+ puts("#{file}:#{index}: has trailing whitespace")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ module Style
6
+ class Base < RubomaticHtml::Cop::Base
7
+ # Department for cop
8
+ #
9
+ # @return [String]
10
+ #
11
+ def self.department
12
+ 'Style'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ module Style
6
+ class NoFieldsFor < RubomaticHtml::Cop::Style::Base
7
+ class << self
8
+ # @see super
9
+ def abstract_cop?
10
+ false
11
+ end
12
+
13
+ # @see super
14
+ def name
15
+ [department, 'NoFieldsFor'].join('/')
16
+ end
17
+ end
18
+
19
+ # @see super
20
+ def run_for_line(line, index)
21
+ return unless line.match?(/fields_for/i)
22
+
23
+ puts("#{file}:#{index}: calls `fields_for`. Use `fields` instead")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ module Style
6
+ class NoFormFor < RubomaticHtml::Cop::Style::Base
7
+ class << self
8
+ # @see super
9
+ def abstract_cop?
10
+ false
11
+ end
12
+
13
+ # @see super
14
+ def name
15
+ [department, 'NoFormFor'].join('/')
16
+ end
17
+ end
18
+
19
+ # @see super
20
+ def run_for_line(line, index)
21
+ return unless line.match?(/form_for/i)
22
+
23
+ puts("#{file}:#{index}: calls `form_for`. Use `form_with` instead")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ module Style
6
+ class NoFormTag < RubomaticHtml::Cop::Style::Base
7
+ class << self
8
+ # @see super
9
+ def abstract_cop?
10
+ false
11
+ end
12
+
13
+ # @see super
14
+ def name
15
+ [department, 'NoFormTag'].join('/')
16
+ end
17
+ end
18
+
19
+ # @see super
20
+ def run_for_line(line, index)
21
+ return unless line.match?(/form_tag/i)
22
+
23
+ puts("#{file}:#{index}: calls `form_tag`. Use `form_with` instead")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubomaticHtml
4
+ module Cop
5
+ module Style
6
+ class NoOnAttribute < RubomaticHtml::Cop::Style::Base
7
+ # @return [String]
8
+ attr_accessor :html_attr
9
+
10
+ # @see super
11
+ def run_for_line(line, index)
12
+ # `onclick:` or `onclick=`
13
+ has_on_click = line.match?(/#{html_attr}[:=]/i)
14
+
15
+ # `:onclick=>` or `:onclick =>`
16
+ has_on_click ||= line.match?(/:#{html_attr} ?=>/i)
17
+
18
+ # `'onclick'=>` or `'onclick' =>`
19
+ has_on_click ||= line.match?(/'#{html_attr}' ?=>/i)
20
+
21
+ # `"onclick"=>` or `"onclick" =>`
22
+ has_on_click ||= line.match?(/"#{html_attr}" ?=>/i)
23
+
24
+ return unless has_on_click
25
+
26
+ puts("#{file}:#{index}: might use an #{html_attr} attribute")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end