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

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 +25 -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 +49 -20
  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
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rubomatic
4
- module Html
5
- module Cop
6
- module Layout
7
- class LineLength < Rubomatic::Html::Cop::Layout::Base
8
- # Name for the cop
9
- #
10
- # @return [String]
11
- #
12
- def self.name
13
- [department, 'LineLength'].join('/')
14
- end
15
-
16
- # @see super
17
- def run_for_line(line, index)
18
- return if line.size <= 120
19
-
20
- puts("#{file}:#{index}: is over 120 characters")
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rubomatic
4
- module Html
5
- module Cop
6
- module Layout
7
- class MultipleLineBreaks < Rubomatic::Html::Cop::Layout::Base
8
- # @return [Boolean] tracks multiple consecutive line breaks
9
- attr_accessor :prev_break
10
-
11
- # Name for the cop
12
- #
13
- # @return [String]
14
- #
15
- def self.name
16
- [department, 'MultipleLineBreaks'].join('/')
17
- end
18
-
19
- # :nodoc:
20
- def initialize(file)
21
- super
22
-
23
- @prev_break = false
24
- end
25
-
26
- # @see super
27
- def run_for_line(line, index)
28
- if prev_break && line.empty?
29
- puts("#{file}:#{index}: has multiple line breaks")
30
- elsif line.empty?
31
- @prev_break = true
32
- else
33
- @prev_break = false
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rubomatic
4
- module Html
5
- module Cop
6
- module Layout
7
- class TrailingWhitespace < Rubomatic::Html::Cop::Layout::Base
8
- # Name for the cop
9
- #
10
- # @return [String]
11
- #
12
- def self.name
13
- [department, 'TrailingWhitespace'].join('/')
14
- end
15
-
16
- # @see super
17
- def run_for_line(line, index)
18
- return unless line.match?(/\s\z/i)
19
-
20
- puts("#{file}:#{index}: has trailing whitespace")
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rubomatic
4
- module Html
5
- module Cop
6
- module Style
7
- class Base < Rubomatic::Html::Cop::Base
8
- # Department for cop
9
- #
10
- # @return [String]
11
- #
12
- def self.department
13
- 'Style'
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rubomatic
4
- module Html
5
- module Cop
6
- module Style
7
- class PartialInstanceVariable < Rubomatic::Html::Cop::Style::Base
8
- # Name for the cop
9
- #
10
- # @return [String]
11
- #
12
- def self.name
13
- [department, 'PartialInstanceVariable'].join('/')
14
- end
15
-
16
- # @see super
17
- def run_for_line(line, index)
18
- return unless File.basename(file).match?(/^_/i)
19
-
20
- return unless line.match?(/@/i)
21
-
22
- puts("#{file}:#{index}: might use an instance variable")
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rubomatic
4
- module Html
5
- VERSION = '1.1.0-rc.4'
6
- end
7
- end
@@ -1,115 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pathname'
4
- require_relative 'html/cop/cops'
5
- require_relative 'html/version'
6
- require 'yaml'
7
-
8
- module Rubomatic
9
- module Html
10
- class Runner
11
- PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
12
- CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
13
- CONFIG = ::YAML.safe_load(CONFIG_DEFAULT.read).freeze
14
-
15
- # @return [Array<String>]
16
- attr_accessor :files_to_lint
17
- # @return [Hash]
18
- attr_accessor :config
19
-
20
- # @param linted_files [Array<String>]
21
- #
22
- def initialize(linted_files)
23
- files_to_lint = Array(linted_files)
24
-
25
- if files_to_lint.empty?
26
- files_to_lint = Dir[File.join('app', 'views', '**', '*')]
27
- end
28
-
29
- @files_to_lint = files_to_lint
30
-
31
- custom_config = ::YAML.safe_load(Pathname.new('.rubomatic-html.yml').read).freeze
32
-
33
- config = {}
34
-
35
- CONFIG.each do |cop, cop_config|
36
- config[cop] = {}
37
- config[cop][:enabled] = cop_config['Enabled']
38
- config[cop][:exclude] = Array(cop_config['Exclude'])
39
-
40
- if custom_config.fetch(cop, {}).has_key?('Enabled')
41
- config[cop][:enabled] = custom_config[cop]['Enabled']
42
- end
43
-
44
- if custom_config.fetch(cop, {}).has_key?('Exclude')
45
- config[cop][:exclude] = Array(custom_config[cop]['Exclude'])
46
- end
47
- end
48
-
49
- @config = config
50
- end
51
-
52
- # Runs all cops against all files
53
- #
54
- # @return [void]
55
- #
56
- def run
57
- all_config = config.fetch('AllCops')
58
-
59
- files_to_lint.each do |file|
60
- next if all_config.fetch(:exclude).any? { |ignored| file.end_with?(ignored) }
61
-
62
- ext = File.extname(file)
63
-
64
- next if ext.match?(/haml/i)
65
-
66
- check_it = ext.match?(/html/i)
67
- check_it ||= ext.match?(/erb\z/i)
68
-
69
- next unless check_it
70
-
71
- run_file(file)
72
- end
73
- end
74
-
75
- private
76
-
77
- # List of all cops available
78
- #
79
- # @return [Array<*>]
80
- #
81
- def all_cops
82
- @all_cops ||= [
83
- Rubomatic::Html::Cop::Layout::LineLength,
84
- Rubomatic::Html::Cop::Layout::MultipleLineBreaks,
85
- Rubomatic::Html::Cop::Layout::TrailingWhitespace,
86
- Rubomatic::Html::Cop::Style::PartialInstanceVariable
87
- ]
88
- end
89
-
90
- # Runs all cops against a given file
91
- #
92
- # @param file [String]
93
- #
94
- # @return [void]
95
- #
96
- def run_file(file)
97
- cops = all_cops.filter_map do |cop|
98
- next unless config.dig(cop.name, :enabled)
99
-
100
- cop.new(file)
101
- end
102
-
103
- return if cops.empty?
104
-
105
- File.open(file).each_line(chomp: true).with_index(1) do |line, index|
106
- cops.each do |cop|
107
- next if config.dig(cop.class.name).fetch(:exclude, []).any? { |ignored| file.end_with?(ignored) }
108
-
109
- cop.run_for_line(line, index)
110
- end
111
- end
112
- end
113
- end
114
- end
115
- end