rubomatic-html 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +3 -1
- data/exe/rubomatic-html +24 -0
- data/lib/rubomatic-html/cop/base.rb +27 -0
- data/lib/rubomatic-html/cop/cops.rb +6 -0
- data/lib/rubomatic-html/cop/layout/line_length.rb +16 -0
- data/lib/rubomatic-html/cop/layout/multiple_line_breaks.rb +29 -0
- data/lib/rubomatic-html/cop/layout/trailing_whitespace.rb +16 -0
- data/lib/rubomatic-html/cop/style/partial_instance_variable.rb +17 -0
- data/lib/rubomatic-html/version.rb +1 -1
- data/lib/rubomatic_html.rb +63 -0
- metadata +11 -17
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
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
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
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubomaticHtml
|
4
|
+
module Cop
|
5
|
+
class Base
|
6
|
+
# @return [String]
|
7
|
+
attr_accessor :file
|
8
|
+
|
9
|
+
# :nodoc:
|
10
|
+
def initialize(file)
|
11
|
+
@file = file
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Outputs filename:line_number locations of HTML files that trigger the cop
|
17
|
+
#
|
18
|
+
# @param line [String] the line in the html
|
19
|
+
# @param index [Integer] the 1-index of the line
|
20
|
+
#
|
21
|
+
# @return [void]
|
22
|
+
#
|
23
|
+
def run_for_line(line, index)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubomaticHtml
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
class LineLength < RubomaticHtml::Cop::Base
|
7
|
+
# @see super
|
8
|
+
def run_for_line(line, index)
|
9
|
+
return if line.size <= 120
|
10
|
+
|
11
|
+
puts("#{file}:#{index}: is over 120 characters")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubomaticHtml
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
class TrailingWhitespace < RubomaticHtml::Cop::Base
|
7
|
+
# @see super
|
8
|
+
def run_for_line(line, index)
|
9
|
+
return unless line.match?(/\s\z/i)
|
10
|
+
|
11
|
+
puts("#{file}:#{index}: has trailing whitespace")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubomaticHtml
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
class PartialInstanceVariable < RubomaticHtml::Cop::Base
|
7
|
+
# @see super
|
8
|
+
def run_for_line(line, index)
|
9
|
+
return unless File.basename(file).match?(/^_/i)
|
10
|
+
return unless line.match?(/@/i)
|
11
|
+
|
12
|
+
puts("#{file}:#{index}: might use an instance variable")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
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,14 +1,14 @@
|
|
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
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubomatic
|
@@ -24,30 +24,24 @@ 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
|
44
|
-
executables:
|
30
|
+
executables:
|
31
|
+
- rubomatic-html
|
45
32
|
extensions: []
|
46
33
|
extra_rdoc_files: []
|
47
34
|
files:
|
48
35
|
- CHANGELOG.adoc
|
49
36
|
- LICENSE.txt
|
50
37
|
- README.adoc
|
38
|
+
- exe/rubomatic-html
|
39
|
+
- lib/rubomatic-html/cop/base.rb
|
40
|
+
- lib/rubomatic-html/cop/cops.rb
|
41
|
+
- lib/rubomatic-html/cop/layout/line_length.rb
|
42
|
+
- lib/rubomatic-html/cop/layout/multiple_line_breaks.rb
|
43
|
+
- lib/rubomatic-html/cop/layout/trailing_whitespace.rb
|
44
|
+
- lib/rubomatic-html/cop/style/partial_instance_variable.rb
|
51
45
|
- lib/rubomatic-html/version.rb
|
52
46
|
- lib/rubomatic_html.rb
|
53
47
|
homepage: https://github.com/BrandsInsurance/expert-chainsaw/
|