rubomatic-html 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/README.adoc +3 -1
- data/exe/rubomatic-html +22 -1
- data/lib/rubomatic-html/cop/base.rb +5 -10
- data/lib/rubomatic-html/cop/cops.rb +6 -0
- data/lib/rubomatic-html/cop/layout/line_length.rb +1 -1
- data/lib/rubomatic-html/cop/layout/multiple_line_breaks.rb +29 -0
- data/lib/rubomatic-html/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubomatic-html/cop/style/partial_instance_variable.rb +1 -1
- data/lib/rubomatic-html/version.rb +1 -1
- data/lib/rubomatic_html.rb +63 -0
- metadata +3 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de42c63dd8d7c9614c542c944569dc5605ec8203ecdeabafe10e1830968f6430
|
4
|
+
data.tar.gz: 8f145a25cde91e5b60e173f9d14ace922bfb0a88ccc6200b925afc4397afd95b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf883c5d6f31d92b2a16809f0a2fa7c34ce364e5bf98dd9bcb7977a3404ba21422e74f5282652d87766c38783fe6e4f54cbdfe4dfd7257a8308d53c81ea45681
|
7
|
+
data.tar.gz: 8aa6620bed7ef566f79d8d0053ceed56ee9b60a84307c9653b3a43bbdbc0988fbdbe38dceb420063ff4269d0082af225d0647657015e2de3fb2f38e7e2f35ccd
|
data/README.adoc
CHANGED
data/exe/rubomatic-html
CHANGED
@@ -1,3 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
require 'rubomatic-html'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
parser = OptionParser.new do |parser|
|
8
|
+
parser.on(
|
9
|
+
'-l',
|
10
|
+
'--linting-files comma,separated,list,of,files',
|
11
|
+
Array,
|
12
|
+
'List of files to lint. Defaults to check everything in app/views'
|
13
|
+
)
|
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 .lint_html_ignore'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
parser.parse!(into: options)
|
23
|
+
|
24
|
+
RubomaticHtml::Runner.new(options[:'linting-files'], options.fetch(:'ignored-files', [])).run
|
@@ -5,27 +5,22 @@ module RubomaticHtml
|
|
5
5
|
class Base
|
6
6
|
# @return [String]
|
7
7
|
attr_accessor :file
|
8
|
-
# @return [String]
|
9
|
-
attr_accessor :line
|
10
|
-
# @return [Integer]
|
11
|
-
attr_accessor :index
|
12
8
|
|
13
9
|
# :nodoc:
|
14
|
-
def initialize(file
|
10
|
+
def initialize(file)
|
15
11
|
@file = file
|
16
|
-
@line = line
|
17
|
-
@index = index
|
18
|
-
|
19
|
-
check_line
|
20
12
|
end
|
21
13
|
|
22
14
|
private
|
23
15
|
|
24
16
|
# Outputs filename:line_number locations of HTML files that trigger the cop
|
25
17
|
#
|
18
|
+
# @param line [String] the line in the html
|
19
|
+
# @param index [Integer] the 1-index of the line
|
20
|
+
#
|
26
21
|
# @return [void]
|
27
22
|
#
|
28
|
-
def
|
23
|
+
def run_for_line(line, index)
|
29
24
|
end
|
30
25
|
end
|
31
26
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubomaticHtml
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
class MultipleLineBreaks < RubomaticHtml::Cop::Base
|
7
|
+
# @return [Boolean]
|
8
|
+
attr_accessor :prev_break
|
9
|
+
|
10
|
+
def initialize(file)
|
11
|
+
super
|
12
|
+
|
13
|
+
@prev_break = false
|
14
|
+
end
|
15
|
+
|
16
|
+
# @see super
|
17
|
+
def run_for_line(line, index)
|
18
|
+
if prev_break && line.size.zero?
|
19
|
+
puts("#{file}:#{index}: has multiple line breaks")
|
20
|
+
elsif line.size.zero?
|
21
|
+
@prev_break = true
|
22
|
+
else
|
23
|
+
@prev_break = false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/rubomatic_html.rb
CHANGED
@@ -1,6 +1,69 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'rubomatic-html/version'
|
4
|
+
require_relative 'rubomatic-html/cop/cops'
|
4
5
|
|
5
6
|
module RubomaticHtml
|
7
|
+
class Runner
|
8
|
+
# @return [Array<String>]
|
9
|
+
attr_accessor :files_to_lint
|
10
|
+
# @return [Array<String>]
|
11
|
+
attr_accessor :files_to_ignore
|
12
|
+
|
13
|
+
# @param linted_files [Array<String>]
|
14
|
+
# @param ignored_files [Array<String>]
|
15
|
+
#
|
16
|
+
def initialize(linted_files, ignored_files)
|
17
|
+
files_to_ignore = Array(ignored_files)
|
18
|
+
ignore_file = '.lint_html_ignore'
|
19
|
+
|
20
|
+
if File.exist?(ignore_file)
|
21
|
+
files_to_ignore += File.readlines(ignore_file, chomp: true)
|
22
|
+
end
|
23
|
+
|
24
|
+
files_to_lint = Array(linted_files)
|
25
|
+
|
26
|
+
if files_to_lint.empty?
|
27
|
+
files_to_lint = Dir[File.join('app', 'views', '**', '*')]
|
28
|
+
end
|
29
|
+
|
30
|
+
@files_to_lint = files_to_lint
|
31
|
+
@files_to_ignore = files_to_ignore
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
files_to_lint.each do |file|
|
36
|
+
next if files_to_ignore.any? { |ignored| file.end_with?(ignored) }
|
37
|
+
|
38
|
+
ext = File.extname(file)
|
39
|
+
next if ext.match?(/haml/i)
|
40
|
+
|
41
|
+
check_it = ext.match?(/html/i)
|
42
|
+
check_it ||= ext.match?(/erb\z/i)
|
43
|
+
|
44
|
+
next unless check_it
|
45
|
+
|
46
|
+
run_file(file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def all_cops
|
53
|
+
@all_cops ||= [
|
54
|
+
RubomaticHtml::Cop::Layout::LineLength,
|
55
|
+
RubomaticHtml::Cop::Layout::MultipleLineBreaks,
|
56
|
+
RubomaticHtml::Cop::Layout::TrailingWhitespace,
|
57
|
+
RubomaticHtml::Cop::Style::PartialInstanceVariable
|
58
|
+
]
|
59
|
+
end
|
60
|
+
|
61
|
+
def run_file(file)
|
62
|
+
cops = all_cops.map { |cop| cop.new(file) }
|
63
|
+
|
64
|
+
File.open(file).each_line(chomp: true).with_index(1) do |line, index|
|
65
|
+
cops.each { |cop| cop.run_for_line(line, index) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
6
69
|
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: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brands Insurance
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.2.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rubocop-brands_insurance
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.3.0
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.3.0
|
41
27
|
description:
|
42
28
|
email:
|
43
29
|
- documents@brandsinsurance.com
|
@@ -51,7 +37,9 @@ files:
|
|
51
37
|
- README.adoc
|
52
38
|
- exe/rubomatic-html
|
53
39
|
- lib/rubomatic-html/cop/base.rb
|
40
|
+
- lib/rubomatic-html/cop/cops.rb
|
54
41
|
- lib/rubomatic-html/cop/layout/line_length.rb
|
42
|
+
- lib/rubomatic-html/cop/layout/multiple_line_breaks.rb
|
55
43
|
- lib/rubomatic-html/cop/layout/trailing_whitespace.rb
|
56
44
|
- lib/rubomatic-html/cop/style/partial_instance_variable.rb
|
57
45
|
- lib/rubomatic-html/version.rb
|