rubomatic-html 1.0.0.pre.rc.8 → 1.1.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/rubomatic-html +1 -1
- data/lib/rubomatic/html/cop/base.rb +42 -0
- data/lib/rubomatic/html/cop/layout/base.rb +19 -0
- data/lib/rubomatic/html/cop/layout/line_length.rb +26 -0
- data/lib/rubomatic/html/cop/layout/multiple_line_breaks.rb +40 -0
- data/lib/rubomatic/html/cop/layout/trailing_whitespace.rb +26 -0
- data/lib/rubomatic/html/cop/style/base.rb +19 -0
- data/lib/rubomatic/html/cop/style/partial_instance_variable.rb +28 -0
- data/lib/rubomatic/html/version.rb +7 -0
- data/lib/rubomatic/html.rb +115 -0
- data/lib/rubomatic-html.rb +1 -109
- metadata +12 -11
- data/lib/rubomatic-html/cop/base.rb +0 -40
- data/lib/rubomatic-html/cop/layout/base.rb +0 -17
- data/lib/rubomatic-html/cop/layout/line_length.rb +0 -24
- data/lib/rubomatic-html/cop/layout/multiple_line_breaks.rb +0 -38
- data/lib/rubomatic-html/cop/layout/trailing_whitespace.rb +0 -24
- data/lib/rubomatic-html/cop/style/base.rb +0 -17
- data/lib/rubomatic-html/cop/style/partial_instance_variable.rb +0 -26
- data/lib/rubomatic-html/version.rb +0 -5
- /data/lib/{rubomatic-html → rubomatic/html}/cop/cops.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d985a291d36eb06963475488bcad31d4ef42b5287f39d8c471b51ac364d19fa
|
4
|
+
data.tar.gz: e940e2f30fa3c4d11ddb100838063b1e4d5ac34e27659e594d19ab82adc5e2c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4452adb9001087bf0d0c7aa7d4faee2992fdb827b3267bf9159cb3f5b218405b437200d832b2915c249f2c23f61a7f29005fb6d38b0f5b0f4b24a3528d16ff8f
|
7
|
+
data.tar.gz: 74e8d74a3aeddc5e00123a080718eb8d63df37d77a2eac0f6bbe1d581a977eec0cd9915e43824ef5e95e1bdec0f0624176de63099bb43eb5163131185a217ad1
|
data/exe/rubomatic-html
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rubomatic
|
4
|
+
module Html
|
5
|
+
module Cop
|
6
|
+
class Base
|
7
|
+
# @return [String]
|
8
|
+
attr_accessor :file
|
9
|
+
|
10
|
+
# Name for cop
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
#
|
14
|
+
def self.name
|
15
|
+
'Base'
|
16
|
+
end
|
17
|
+
|
18
|
+
# :nodoc:
|
19
|
+
def initialize(file)
|
20
|
+
@file = file
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Outputs filename:line_number locations of HTML files that trigger the cop
|
26
|
+
#
|
27
|
+
# @param _line [String] the line in the html
|
28
|
+
# @param _index [Integer] the 1-index of the line
|
29
|
+
#
|
30
|
+
# @return [void]
|
31
|
+
#
|
32
|
+
def run_for_line(_line, _index)
|
33
|
+
error_message = <<~TEXT
|
34
|
+
Warning: Method `run_for_line` needs overridden! Some cops may not display failing messages.
|
35
|
+
TEXT
|
36
|
+
|
37
|
+
puts("\e[33m#{error_message}\e[0m")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rubomatic
|
4
|
+
module Html
|
5
|
+
module Cop
|
6
|
+
module Layout
|
7
|
+
class Base < Rubomatic::Html::Cop::Base
|
8
|
+
# Department for cop
|
9
|
+
#
|
10
|
+
# @return [String]
|
11
|
+
#
|
12
|
+
def self.department
|
13
|
+
'Layout'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,40 @@
|
|
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
|
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,19 @@
|
|
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
|
@@ -0,0 +1,28 @@
|
|
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
|
@@ -0,0 +1,115 @@
|
|
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.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
|
data/lib/rubomatic-html.rb
CHANGED
@@ -1,111 +1,3 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative 'rubomatic-html/cop/cops'
|
5
|
-
require_relative 'rubomatic-html/version'
|
6
|
-
require 'yaml'
|
7
|
-
|
8
|
-
module RubomaticHtml
|
9
|
-
class Runner
|
10
|
-
# @return [Array<String>]
|
11
|
-
attr_accessor :files_to_lint
|
12
|
-
# @return [Hash]
|
13
|
-
attr_accessor :config
|
14
|
-
|
15
|
-
PROJECT_ROOT = Pathname.new(__dir__).parent.expand_path.freeze
|
16
|
-
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
17
|
-
CONFIG = ::YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
18
|
-
|
19
|
-
# @param linted_files [Array<String>]
|
20
|
-
#
|
21
|
-
def initialize(linted_files)
|
22
|
-
files_to_lint = Array(linted_files)
|
23
|
-
|
24
|
-
if files_to_lint.empty?
|
25
|
-
files_to_lint = Dir[File.join('app', 'views', '**', '*')]
|
26
|
-
end
|
27
|
-
|
28
|
-
@files_to_lint = files_to_lint
|
29
|
-
|
30
|
-
custom_config = ::YAML.safe_load(Pathname.new('.rubomatic-html.yml').read).freeze
|
31
|
-
|
32
|
-
config = {}
|
33
|
-
|
34
|
-
CONFIG.each do |cop, cop_config|
|
35
|
-
config[cop] = {}
|
36
|
-
config[cop][:enabled] = cop_config['Enabled']
|
37
|
-
config[cop][:exclude] = Array(cop_config['Exclude'])
|
38
|
-
|
39
|
-
if custom_config.fetch(cop, {}).has_key?('Enabled')
|
40
|
-
config[cop][:enabled] = custom_config[cop]['Enabled']
|
41
|
-
end
|
42
|
-
if custom_config.fetch(cop, {}).has_key?('Exclude')
|
43
|
-
config[cop][:exclude] = Array(custom_config[cop]['Exclude'])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
@config = config
|
48
|
-
end
|
49
|
-
|
50
|
-
# Runs all cops against all files
|
51
|
-
#
|
52
|
-
# @return [void]
|
53
|
-
#
|
54
|
-
def run
|
55
|
-
all_config = config.fetch('AllCops')
|
56
|
-
files_to_lint.each do |file|
|
57
|
-
next if all_config.fetch(:exclude).any? { |ignored| file.end_with?(ignored) }
|
58
|
-
|
59
|
-
ext = File.extname(file)
|
60
|
-
|
61
|
-
next if ext.match?(/haml/i)
|
62
|
-
|
63
|
-
check_it = ext.match?(/html/i)
|
64
|
-
check_it ||= ext.match?(/erb\z/i)
|
65
|
-
|
66
|
-
next unless check_it
|
67
|
-
|
68
|
-
run_file(file)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
# List of all cops available
|
75
|
-
#
|
76
|
-
# @return [Array<*>]
|
77
|
-
#
|
78
|
-
def all_cops
|
79
|
-
@all_cops ||= [
|
80
|
-
RubomaticHtml::Cop::Layout::LineLength,
|
81
|
-
RubomaticHtml::Cop::Layout::MultipleLineBreaks,
|
82
|
-
RubomaticHtml::Cop::Layout::TrailingWhitespace,
|
83
|
-
RubomaticHtml::Cop::Style::PartialInstanceVariable
|
84
|
-
]
|
85
|
-
end
|
86
|
-
|
87
|
-
# Runs all cops against a given file
|
88
|
-
#
|
89
|
-
# @param file [String]
|
90
|
-
#
|
91
|
-
# @return [void]
|
92
|
-
#
|
93
|
-
def run_file(file)
|
94
|
-
cops = all_cops.filter_map do |cop|
|
95
|
-
next unless config.dig(cop.name, :enabled)
|
96
|
-
|
97
|
-
cop.new(file)
|
98
|
-
end
|
99
|
-
|
100
|
-
return if cops.empty?
|
101
|
-
|
102
|
-
File.open(file).each_line(chomp: true).with_index(1) do |line, index|
|
103
|
-
cops.each do |cop|
|
104
|
-
next if config.dig(cop.class.name).fetch(:exclude, []).any? { |ignored| file.end_with?(ignored) }
|
105
|
-
|
106
|
-
cop.run_for_line(line, index)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
3
|
+
require_relative 'rubomatic/html'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubomatic-html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0.pre.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brands Insurance
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05
|
11
|
+
date: 2023-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubomatic
|
@@ -44,15 +44,16 @@ files:
|
|
44
44
|
- docs/cops/style/partial_instance_variable/README.adoc
|
45
45
|
- exe/rubomatic-html
|
46
46
|
- lib/rubomatic-html.rb
|
47
|
-
- lib/rubomatic
|
48
|
-
- lib/rubomatic
|
49
|
-
- lib/rubomatic
|
50
|
-
- lib/rubomatic
|
51
|
-
- lib/rubomatic
|
52
|
-
- lib/rubomatic
|
53
|
-
- lib/rubomatic
|
54
|
-
- lib/rubomatic
|
55
|
-
- lib/rubomatic
|
47
|
+
- lib/rubomatic/html.rb
|
48
|
+
- lib/rubomatic/html/cop/base.rb
|
49
|
+
- lib/rubomatic/html/cop/cops.rb
|
50
|
+
- lib/rubomatic/html/cop/layout/base.rb
|
51
|
+
- lib/rubomatic/html/cop/layout/line_length.rb
|
52
|
+
- lib/rubomatic/html/cop/layout/multiple_line_breaks.rb
|
53
|
+
- lib/rubomatic/html/cop/layout/trailing_whitespace.rb
|
54
|
+
- lib/rubomatic/html/cop/style/base.rb
|
55
|
+
- lib/rubomatic/html/cop/style/partial_instance_variable.rb
|
56
|
+
- lib/rubomatic/html/version.rb
|
56
57
|
homepage: https://github.com/BrandsInsurance/expert-chainsaw/
|
57
58
|
licenses:
|
58
59
|
- MIT
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubomaticHtml
|
4
|
-
module Cop
|
5
|
-
class Base
|
6
|
-
# Name for cop
|
7
|
-
#
|
8
|
-
# @return [String]
|
9
|
-
#
|
10
|
-
def self.name
|
11
|
-
'Base'
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [String]
|
15
|
-
attr_accessor :file
|
16
|
-
|
17
|
-
# :nodoc:
|
18
|
-
def initialize(file)
|
19
|
-
@file = file
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
# Outputs filename:line_number locations of HTML files that trigger the cop
|
25
|
-
#
|
26
|
-
# @param line [String] the line in the html
|
27
|
-
# @param index [Integer] the 1-index of the line
|
28
|
-
#
|
29
|
-
# @return [void]
|
30
|
-
#
|
31
|
-
def run_for_line(line, index)
|
32
|
-
error_message = <<~TEXT
|
33
|
-
Warning: Method `run_for_line` needs overridden! Some cops may not display failing messages.
|
34
|
-
TEXT
|
35
|
-
|
36
|
-
puts("\e[33m#{error_message}\e[0m")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubomaticHtml
|
4
|
-
module Cop
|
5
|
-
module Layout
|
6
|
-
class LineLength < RubomaticHtml::Cop::Layout::Base
|
7
|
-
# Name for the cop
|
8
|
-
#
|
9
|
-
# @return [String]
|
10
|
-
#
|
11
|
-
def self.name
|
12
|
-
[department, 'LineLength'].join('/')
|
13
|
-
end
|
14
|
-
|
15
|
-
# @see super
|
16
|
-
def run_for_line(line, index)
|
17
|
-
return if line.size <= 120
|
18
|
-
|
19
|
-
puts("#{file}:#{index}: is over 120 characters")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubomaticHtml
|
4
|
-
module Cop
|
5
|
-
module Layout
|
6
|
-
class MultipleLineBreaks < RubomaticHtml::Cop::Layout::Base
|
7
|
-
# Name for the cop
|
8
|
-
#
|
9
|
-
# @return [String]
|
10
|
-
#
|
11
|
-
def self.name
|
12
|
-
[department, 'MultipleLineBreaks'].join('/')
|
13
|
-
end
|
14
|
-
|
15
|
-
# @return [Boolean] tracks multiple consecutive line breaks
|
16
|
-
attr_accessor :prev_break
|
17
|
-
|
18
|
-
# :nodoc:
|
19
|
-
def initialize(file)
|
20
|
-
super
|
21
|
-
|
22
|
-
@prev_break = false
|
23
|
-
end
|
24
|
-
|
25
|
-
# @see super
|
26
|
-
def run_for_line(line, index)
|
27
|
-
if prev_break && line.empty?
|
28
|
-
puts("#{file}:#{index}: has multiple line breaks")
|
29
|
-
elsif line.empty?
|
30
|
-
@prev_break = true
|
31
|
-
else
|
32
|
-
@prev_break = false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubomaticHtml
|
4
|
-
module Cop
|
5
|
-
module Layout
|
6
|
-
class TrailingWhitespace < RubomaticHtml::Cop::Layout::Base
|
7
|
-
# Name for the cop
|
8
|
-
#
|
9
|
-
# @return [String]
|
10
|
-
#
|
11
|
-
def self.name
|
12
|
-
[department, 'TrailingWhitespace'].join('/')
|
13
|
-
end
|
14
|
-
|
15
|
-
# @see super
|
16
|
-
def run_for_line(line, index)
|
17
|
-
return unless line.match?(/\s\z/i)
|
18
|
-
|
19
|
-
puts("#{file}:#{index}: has trailing whitespace")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubomaticHtml
|
4
|
-
module Cop
|
5
|
-
module Style
|
6
|
-
class PartialInstanceVariable < RubomaticHtml::Cop::Style::Base
|
7
|
-
# Name for the cop
|
8
|
-
#
|
9
|
-
# @return [String]
|
10
|
-
#
|
11
|
-
def self.name
|
12
|
-
[department, 'PartialInstanceVariable'].join('/')
|
13
|
-
end
|
14
|
-
|
15
|
-
# @see super
|
16
|
-
def run_for_line(line, index)
|
17
|
-
return unless File.basename(file).match?(/^_/i)
|
18
|
-
|
19
|
-
return unless line.match?(/@/i)
|
20
|
-
|
21
|
-
puts("#{file}:#{index}: might use an instance variable")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
File without changes
|