rubomatic-html 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2feb228bfcfe89977098ed0bcbd954f01d5c98d5463efef59a1d68b100b5562
4
- data.tar.gz: 49d1172eeadffa303d8638050429a5c2ae8c39e4844df5a5ae390c91efb11785
3
+ metadata.gz: 24500e8be719d33394abf55f3acb746181fb5507fc32e4084bbb09c17dff2b7f
4
+ data.tar.gz: b029dfee3fcec76a9a96e45a74f81fa63ce8440fcb130c060a1763a99d704bfc
5
5
  SHA512:
6
- metadata.gz: e606e10f3f7d0b03cb07eaac70f1c74af5c211a96b0b8e4ef5f5456513cf851e32cb6ba1f9dc21e35867d6884b1126cd8efc4406862f38473887494a6c5f0d92
7
- data.tar.gz: 1934e0c133299678113e12cd919b2513fb62f659bb0f26a944072b6c4641448a2df48327fec1ba090ee267ed65b9459b366d94d5390e6459afb28e476b4b372d
6
+ metadata.gz: 7c80e7b5db8754f5ce084d2fd0a888e15e8c60d3069fd21d5f1ce90443d4984410bbeb0dbf814f86a3c5443bcea99de07f812b47cf41762763ba318b96951541
7
+ data.tar.gz: ff966b0a358954f84a3345c358969110bc06d9797eac5e724f601f51a7b16fca75514a25ffecdf615072687be8ce8d999f7d7f250fbe10eae11730872ceff3bd
data/README.adoc CHANGED
@@ -1,6 +1,8 @@
1
1
  = RubomaticHtml
2
2
 
3
- Gem for shared html linting for BrandsInsurance
3
+ Gem for shared html linting for BrandsInsurance.
4
+
5
+ Make sure ran from project root
4
6
 
5
7
  == Installation
6
8
 
data/exe/rubomatic-html CHANGED
@@ -1,3 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- puts 1
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, line, index)
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 check_line
23
+ def run_for_line(line, index)
29
24
  end
30
25
  end
31
26
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+ require_relative 'layout/line_length'
5
+ require_relative 'layout/trailing_whitespace'
6
+ require_relative 'style/partial_instance_variable'
@@ -5,7 +5,7 @@ module RubomaticHtml
5
5
  module Layout
6
6
  class LineLength < RubomaticHtml::Cop::Base
7
7
  # @see super
8
- def check_line
8
+ def run_for_line(line, index)
9
9
  return if line.size <= 120
10
10
 
11
11
  puts("#{file}:#{index}: is over 120 characters")
@@ -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
@@ -5,7 +5,7 @@ module RubomaticHtml
5
5
  module Layout
6
6
  class TrailingWhitespace < RubomaticHtml::Cop::Base
7
7
  # @see super
8
- def check_line
8
+ def run_for_line(line, index)
9
9
  return unless line.match?(/\s\z/i)
10
10
 
11
11
  puts("#{file}:#{index}: has trailing whitespace")
@@ -5,7 +5,7 @@ module RubomaticHtml
5
5
  module Style
6
6
  class PartialInstanceVariable < RubomaticHtml::Cop::Base
7
7
  # @see super
8
- def check_line
8
+ def run_for_line(line, index)
9
9
  return unless File.basename(file).match?(/^_/i)
10
10
  return unless line.match?(/@/i)
11
11
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubomaticHtml
4
- VERSION = '0.2.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'rubomatic-html/version'
4
+ require_relative 'rubomatic-html/cop/cops'
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
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.2.0
4
+ version: 0.4.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
@@ -50,12 +36,14 @@ files:
50
36
  - LICENSE.txt
51
37
  - README.adoc
52
38
  - exe/rubomatic-html
39
+ - lib/rubomatic-html.rb
53
40
  - lib/rubomatic-html/cop/base.rb
41
+ - lib/rubomatic-html/cop/cops.rb
54
42
  - lib/rubomatic-html/cop/layout/line_length.rb
43
+ - lib/rubomatic-html/cop/layout/multiple_line_breaks.rb
55
44
  - lib/rubomatic-html/cop/layout/trailing_whitespace.rb
56
45
  - lib/rubomatic-html/cop/style/partial_instance_variable.rb
57
46
  - lib/rubomatic-html/version.rb
58
- - lib/rubomatic_html.rb
59
47
  homepage: https://github.com/BrandsInsurance/expert-chainsaw/
60
48
  licenses:
61
49
  - MIT
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'rubomatic-html/version'
4
-
5
- module RubomaticHtml
6
- end