rubomatic-html 1.0.0.pre.rc.1 → 1.0.0.pre.rc.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +29 -17
- data/README.adoc +5 -0
- data/config/default.yml +14 -0
- data/docs/cops/layout/README.adoc +9 -0
- data/docs/cops/layout/line_length/README.adoc +29 -0
- data/docs/cops/layout/multiple_line_breaks/README.adoc +29 -0
- data/docs/cops/layout/trailing_whitespace/README.adoc +24 -0
- data/docs/cops/style/README.adoc +7 -0
- data/docs/cops/style/partial_instance_variable/README.adoc +24 -0
- data/exe/rubomatic-html +8 -11
- data/lib/rubomatic-html/cop/layout/multiple_line_breaks.rb +4 -3
- data/lib/rubomatic-html/cop/style/partial_instance_variable.rb +1 -0
- data/lib/rubomatic-html/version.rb +1 -1
- data/lib/rubomatic-html.rb +56 -16
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f5a056afb02856ef5c386f8be9108d323025c28369c4301a6c9fa4e9e5bb18b
|
4
|
+
data.tar.gz: 57f9ef62088f15ebc9adf2249b1a5e299af013088fcb75e2af36f7fd3ff1c477
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09a04572be565aab75e30e0ce7ffd7ae792e71c53ab326395eac8cb06896abcf8b2743a7932b5c79c8a5f8e69904271977cee4b711a164aa3defc1b2578cab99'
|
7
|
+
data.tar.gz: 0aae7e87d719e4c16b0d190699f901406b2095bcfaf64123a1894fa00c9370b32bd194baaac86a8a047d7d2c5c1a28597dd9e591d95ce6d36329d4124ad2daf4
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,32 @@
|
|
1
|
-
|
1
|
+
The Clear BSD License
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
3
|
+
Copyright (c) 2023 Brands Insurance Agency, Inc.
|
4
|
+
All rights reserved.
|
10
5
|
|
11
|
-
|
12
|
-
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted (subject to the limitations in the disclaimer
|
8
|
+
below) provided that the following conditions are met:
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
* Redistributions of source code must retain the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer.
|
12
|
+
|
13
|
+
* Redistributions in binary form must reproduce the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer in the
|
15
|
+
documentation and/or other materials provided with the distribution.
|
16
|
+
|
17
|
+
* Neither the name of the copyright holder nor the names of its
|
18
|
+
contributors may be used to endorse or promote products derived from this
|
19
|
+
software without specific prior written permission.
|
20
|
+
|
21
|
+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
|
22
|
+
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
23
|
+
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
24
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
25
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
26
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
27
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
28
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
29
|
+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
30
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
POSSIBILITY OF SUCH DAMAGE.
|
data/README.adoc
CHANGED
@@ -44,6 +44,11 @@ app/views/shared/_global_email.html.erb
|
|
44
44
|
app/views/shared/_global_email_text.text.erb
|
45
45
|
----
|
46
46
|
|
47
|
+
== Departments
|
48
|
+
|
49
|
+
* xref:./docs/cops/layout/README.adoc[``Layout``]
|
50
|
+
* xref:./docs/cops/style/README.adoc[``Style``]
|
51
|
+
|
47
52
|
== Changelog
|
48
53
|
|
49
54
|
See xref:./CHANGELOG.adoc[CHANGELOG] see see changes
|
data/config/default.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
= Layout
|
2
|
+
|
3
|
+
Layout cops check for stylistic whitespace in your code
|
4
|
+
|
5
|
+
== Cops
|
6
|
+
|
7
|
+
* xref:./line_length/README.adoc[``Layout/LineLength``]
|
8
|
+
* xref:./multiple_line_breaks/README.adoc[``Layout/MultipleLineBreaks``]
|
9
|
+
* xref:./trailing_whitespace/README.adoc[``Layout/TrailingWhitespace``]
|
@@ -0,0 +1,29 @@
|
|
1
|
+
= ``Layout/LineLength``
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Alerts when you have lines in your ``html`` files longer than ``120`` characters
|
6
|
+
|
7
|
+
== Examples
|
8
|
+
|
9
|
+
[source,rhtml]
|
10
|
+
----
|
11
|
+
<!-- Bad -->
|
12
|
+
<%= render({ partial: 'policies/equipment_policies/partials/index_table', locals: { company: company, profile: profile, policy: policy, unit: unit, active: active } }) %>
|
13
|
+
|
14
|
+
<!-- Good -->
|
15
|
+
<%=
|
16
|
+
render({
|
17
|
+
partial: 'policies/equipment_policies/partials/index_table',
|
18
|
+
locals: { company: company, profile: profile, policy: policy, unit: unit, active: active }
|
19
|
+
})
|
20
|
+
%>
|
21
|
+
----
|
22
|
+
|
23
|
+
== Configurable Attributes
|
24
|
+
|
25
|
+
There are no configurable attributes
|
26
|
+
|
27
|
+
== References
|
28
|
+
|
29
|
+
* https://github.com/BrandsInsurance/expert-chainsaw/issues/136
|
@@ -0,0 +1,29 @@
|
|
1
|
+
= ``Layout/MultipleLineBreaks``
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Alerts when you have multiple consecutive line breaks your ``html`` files
|
6
|
+
|
7
|
+
== Examples
|
8
|
+
|
9
|
+
[source,rhtml]
|
10
|
+
----
|
11
|
+
<!-- Bad -->
|
12
|
+
<% a = 1 %>
|
13
|
+
|
14
|
+
|
15
|
+
<% b = 2 %>
|
16
|
+
|
17
|
+
<!-- Good -->
|
18
|
+
<% a = 1 %>
|
19
|
+
|
20
|
+
<% b = 2 %>
|
21
|
+
----
|
22
|
+
|
23
|
+
== Configurable Attributes
|
24
|
+
|
25
|
+
There are no configurable attributes
|
26
|
+
|
27
|
+
== References
|
28
|
+
|
29
|
+
* N/A
|
@@ -0,0 +1,24 @@
|
|
1
|
+
= ``Layout/TrailingWhitespace``
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Alerts when you have trailing whitespace in your ``html`` files
|
6
|
+
|
7
|
+
== Examples
|
8
|
+
|
9
|
+
[source,rhtml]
|
10
|
+
----
|
11
|
+
<!-- Bad -->
|
12
|
+
<% a = 1 %>[space]
|
13
|
+
|
14
|
+
<!-- Good -->
|
15
|
+
<% a = 1 %>
|
16
|
+
----
|
17
|
+
|
18
|
+
== Configurable Attributes
|
19
|
+
|
20
|
+
There are no configurable attributes
|
21
|
+
|
22
|
+
== References
|
23
|
+
|
24
|
+
* https://github.com/BrandsInsurance/expert-chainsaw/blob/main/ruby/RUBY_STYLE_GUIDE.adoc#no-trailing-whitespace
|
@@ -0,0 +1,24 @@
|
|
1
|
+
= ``Style/PartialInstanceVariable``
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Instance variables should not be used within partials
|
6
|
+
|
7
|
+
== Examples
|
8
|
+
|
9
|
+
[source,rhtml]
|
10
|
+
----
|
11
|
+
<!-- Bad (app/views/profiles/partials/_show.html.erb) -->
|
12
|
+
<%= @profile.id %>
|
13
|
+
|
14
|
+
<!-- Bad (app/views/profiles/partials/_show.html.erb) -->
|
15
|
+
<%= profile.id %>
|
16
|
+
----
|
17
|
+
|
18
|
+
== Configurable Attributes
|
19
|
+
|
20
|
+
There are no configurable attributes
|
21
|
+
|
22
|
+
== References
|
23
|
+
|
24
|
+
* https://github.com/BrandsInsurance/expert-chainsaw/issues/466
|
data/exe/rubomatic-html
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
4
5
|
require 'optparse'
|
6
|
+
require 'rubomatic-html'
|
5
7
|
|
6
8
|
options = {}
|
7
|
-
|
9
|
+
|
10
|
+
parsed = OptionParser.new do |parser|
|
8
11
|
parser.on(
|
9
12
|
'-l',
|
10
13
|
'--linting-files comma,separated,list,of,files',
|
11
14
|
Array,
|
12
15
|
'List of files to lint. Defaults to check everything in app/views'
|
13
16
|
)
|
14
|
-
|
15
|
-
parser.on(
|
16
|
-
'-i',
|
17
|
-
'--ignored-files comma,separated,list,of,files',
|
18
|
-
Array,
|
19
|
-
'List of files to ignore. Additionally ignores contents of .rubomatic_html_ignore'
|
20
|
-
)
|
21
17
|
end
|
22
|
-
parser.parse!(into: options)
|
23
18
|
|
24
|
-
|
19
|
+
parsed.parse!(into: options)
|
20
|
+
|
21
|
+
RubomaticHtml::Runner.new(options[:'linting-files']).run
|
@@ -4,9 +4,10 @@ module RubomaticHtml
|
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
6
|
class MultipleLineBreaks < RubomaticHtml::Cop::Base
|
7
|
-
# @return [Boolean]
|
7
|
+
# @return [Boolean] tracks multiple consecutive line breaks
|
8
8
|
attr_accessor :prev_break
|
9
9
|
|
10
|
+
# :nodoc:
|
10
11
|
def initialize(file)
|
11
12
|
super
|
12
13
|
|
@@ -15,9 +16,9 @@ module RubomaticHtml
|
|
15
16
|
|
16
17
|
# @see super
|
17
18
|
def run_for_line(line, index)
|
18
|
-
if prev_break && line.
|
19
|
+
if prev_break && line.empty?
|
19
20
|
puts("#{file}:#{index}: has multiple line breaks")
|
20
|
-
elsif line.
|
21
|
+
elsif line.empty?
|
21
22
|
@prev_break = true
|
22
23
|
else
|
23
24
|
@prev_break = false
|
data/lib/rubomatic-html.rb
CHANGED
@@ -1,26 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'pathname'
|
4
4
|
require_relative 'rubomatic-html/cop/cops'
|
5
|
+
require_relative 'rubomatic-html/version'
|
6
|
+
require 'yaml'
|
5
7
|
|
6
8
|
module RubomaticHtml
|
7
9
|
class Runner
|
8
10
|
# @return [Array<String>]
|
9
11
|
attr_accessor :files_to_lint
|
10
|
-
# @return [
|
11
|
-
attr_accessor :
|
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
|
12
18
|
|
13
19
|
# @param linted_files [Array<String>]
|
14
|
-
# @param ignored_files [Array<String>]
|
15
20
|
#
|
16
|
-
def initialize(linted_files
|
17
|
-
files_to_ignore = Array(ignored_files)
|
18
|
-
ignore_file = '.rubomatic_html_ignore'
|
19
|
-
|
20
|
-
if File.exist?(ignore_file)
|
21
|
-
files_to_ignore += File.readlines(ignore_file, chomp: true)
|
22
|
-
end
|
23
|
-
|
21
|
+
def initialize(linted_files)
|
24
22
|
files_to_lint = Array(linted_files)
|
25
23
|
|
26
24
|
if files_to_lint.empty?
|
@@ -28,14 +26,38 @@ module RubomaticHtml
|
|
28
26
|
end
|
29
27
|
|
30
28
|
@files_to_lint = files_to_lint
|
31
|
-
|
29
|
+
|
30
|
+
custom_config = ::YAML.safe_load('.rubomatic-html.yml').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
|
32
48
|
end
|
33
49
|
|
50
|
+
# Runs all cops against all files
|
51
|
+
#
|
52
|
+
# @return [void]
|
53
|
+
#
|
34
54
|
def run
|
55
|
+
all_config = config.fetch('AllCops')
|
35
56
|
files_to_lint.each do |file|
|
36
|
-
next if
|
57
|
+
next if all_config.fetch(:exclude).any? { |ignored| file.end_with?(ignored) }
|
37
58
|
|
38
59
|
ext = File.extname(file)
|
60
|
+
|
39
61
|
next if ext.match?(/haml/i)
|
40
62
|
|
41
63
|
check_it = ext.match?(/html/i)
|
@@ -49,6 +71,10 @@ module RubomaticHtml
|
|
49
71
|
|
50
72
|
private
|
51
73
|
|
74
|
+
# List of all cops available
|
75
|
+
#
|
76
|
+
# @return [Array<*>]
|
77
|
+
#
|
52
78
|
def all_cops
|
53
79
|
@all_cops ||= [
|
54
80
|
RubomaticHtml::Cop::Layout::LineLength,
|
@@ -58,11 +84,25 @@ module RubomaticHtml
|
|
58
84
|
]
|
59
85
|
end
|
60
86
|
|
87
|
+
# Runs all cops against a given file
|
88
|
+
#
|
89
|
+
# @param file [String]
|
90
|
+
#
|
91
|
+
# @return [void]
|
92
|
+
#
|
61
93
|
def run_file(file)
|
62
|
-
cops = all_cops.
|
94
|
+
cops = all_cops.filter_map do |cop|
|
95
|
+
next unless config.dig(cop.to_s, :enabled)
|
96
|
+
|
97
|
+
cop.new(file)
|
98
|
+
end
|
63
99
|
|
64
100
|
File.open(file).each_line(chomp: true).with_index(1) do |line, index|
|
65
|
-
cops.each
|
101
|
+
cops.each do |cop|
|
102
|
+
next if config.dig(cop.to_s).fetch(:exclude, []).any? { |ignored| file.end_with?(ignored) }
|
103
|
+
|
104
|
+
cop.run_for_line(line, index)
|
105
|
+
end
|
66
106
|
end
|
67
107
|
end
|
68
108
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubomatic-html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.rc.
|
4
|
+
version: 1.0.0.pre.rc.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brands Insurance
|
@@ -35,6 +35,13 @@ files:
|
|
35
35
|
- CHANGELOG.adoc
|
36
36
|
- LICENSE.txt
|
37
37
|
- README.adoc
|
38
|
+
- config/default.yml
|
39
|
+
- docs/cops/layout/README.adoc
|
40
|
+
- docs/cops/layout/line_length/README.adoc
|
41
|
+
- docs/cops/layout/multiple_line_breaks/README.adoc
|
42
|
+
- docs/cops/layout/trailing_whitespace/README.adoc
|
43
|
+
- docs/cops/style/README.adoc
|
44
|
+
- docs/cops/style/partial_instance_variable/README.adoc
|
38
45
|
- exe/rubomatic-html
|
39
46
|
- lib/rubomatic-html.rb
|
40
47
|
- lib/rubomatic-html/cop/base.rb
|