rubomatic-html 1.0.0.pre.rc.1 → 1.0.0.pre.rc.2

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: e2f2a32770e85334243d284515902d43d6b9ec393092ac0fed1b64427c89dd17
4
- data.tar.gz: 16a9377107af3898f1ed1bf22032ae1b5a7aea3d329744005e83c4fd6b3b5a3f
3
+ metadata.gz: e6d3802d73770d3ccbae7d8e839acde0c32abfe1ef2c152055427314592ffa2e
4
+ data.tar.gz: f7178a5a78a6035d9753f857585b62d89715c8a4bc73ac14b0f6edeebb3384e2
5
5
  SHA512:
6
- metadata.gz: 37fba14024cbbaea3e6ddb1375228c75b4a96714be1a0e6857afd6b107be8a55e6f647844ce283eab86275321c48024e0ab0cc77131ea7bc080bcbea2ed9fe0b
7
- data.tar.gz: 96548eb6af14568262d2c5ac31dd651bc564e2a3f822f689f23c46f67faf99d82d8fb2623963c39ac1ea42a67c1648148aa535d464162f479957fae58bd80a85
6
+ metadata.gz: 7364fd3dc91a378fb3a8f90e6a6be658af69595e96dfd76aa31777860d872e8b1465a1a414d717cfb26c9e80a428b9cf18be481b5fdba73479ed5f63816c1319
7
+ data.tar.gz: ce4389c15e8c177e6b36aab2dca657af54dae5db0f8af505e2e081b6ca4ec859543438f58e67150b69b6b694b436219b31d6851f231607af6aff4fad674c8467
data/LICENSE.txt CHANGED
@@ -1,20 +1,32 @@
1
- Copyright (c) 2023 Brands Insurance
1
+ The Clear BSD License
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
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
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
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
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ Enabled: true
3
+
4
+ Layout/LineLength:
5
+ Enabled: true
6
+
7
+ Layout/MultipleLineBreaks:
8
+ Enabled: true
9
+
10
+ Layout/TrailingWhitespace:
11
+ Enabled: true
12
+
13
+ Style/PartialInstanceVariable:
14
+ Enabled: true
@@ -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,7 @@
1
+ = Style
2
+
3
+ Style cops check for stylistic consistency of your code
4
+
5
+ == Cops
6
+
7
+ * xref:./partial_instance_variable/README.adoc[``Style/PartialInstanceVariable``]
@@ -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
- require 'rubomatic-html'
3
+ # frozen_string_literal: true
4
+
4
5
  require 'optparse'
6
+ require 'rubomatic-html'
5
7
 
6
8
  options = {}
7
- parser = OptionParser.new do |parser|
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
- RubomaticHtml::Runner.new(options[:'linting-files'], options.fetch(:'ignored-files', [])).run
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.size.zero?
19
+ if prev_break && line.empty?
19
20
  puts("#{file}:#{index}: has multiple line breaks")
20
- elsif line.size.zero?
21
+ elsif line.empty?
21
22
  @prev_break = true
22
23
  else
23
24
  @prev_break = false
@@ -7,6 +7,7 @@ module RubomaticHtml
7
7
  # @see super
8
8
  def run_for_line(line, index)
9
9
  return unless File.basename(file).match?(/^_/i)
10
+
10
11
  return unless line.match?(/@/i)
11
12
 
12
13
  puts("#{file}:#{index}: might use an instance variable")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubomaticHtml
4
- VERSION = '1.0.0-rc.1'
4
+ VERSION = '1.0.0-rc.2'
5
5
  end
@@ -1,26 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'rubomatic-html/version'
4
3
  require_relative 'rubomatic-html/cop/cops'
4
+ require_relative 'rubomatic-html/version'
5
+ require 'yaml'
5
6
 
6
7
  module RubomaticHtml
7
8
  class Runner
8
9
  # @return [Array<String>]
9
10
  attr_accessor :files_to_lint
10
- # @return [Array<String>]
11
- attr_accessor :files_to_ignore
11
+ # @return [Hash]
12
+ attr_accessor :config
13
+
14
+ PROJECT_ROOT = Pathname.new(__dir__).parent.expand_path.freeze
15
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
16
+ CONFIG = ::YAML.safe_load(CONFIG_DEFAULT.read).freeze
12
17
 
13
18
  # @param linted_files [Array<String>]
14
- # @param ignored_files [Array<String>]
15
19
  #
16
- def initialize(linted_files, ignored_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
-
20
+ def initialize(linted_files)
24
21
  files_to_lint = Array(linted_files)
25
22
 
26
23
  if files_to_lint.empty?
@@ -28,14 +25,38 @@ module RubomaticHtml
28
25
  end
29
26
 
30
27
  @files_to_lint = files_to_lint
31
- @files_to_ignore = files_to_ignore
28
+
29
+ custom_config = ::YAML.safe_load('.rubomatic-html.yml').freeze
30
+
31
+ config = {}
32
+
33
+ CONFIG.each do |cop, cop_config|
34
+ config[cop] = {}
35
+ config[cop][:enabled] = cop_config['Enabled']
36
+ config[cop][:exclude] = Array(cop_config['Exclude'])
37
+
38
+ if custom_config.fetch(cop, {}).has_key?('Enabled')
39
+ config[cop][:enabled] = custom_config[cop]['Enabled']
40
+ end
41
+ if custom_config.fetch(cop, {}).has_key?('Exclude')
42
+ config[cop][:exclude] = Array(custom_config[cop]['Exclude'])
43
+ end
44
+ end
45
+
46
+ @config = config
32
47
  end
33
48
 
49
+ # Runs all cops against all files
50
+ #
51
+ # @return [void]
52
+ #
34
53
  def run
54
+ all_config = config.fetch('AllCops')
35
55
  files_to_lint.each do |file|
36
- next if files_to_ignore.any? { |ignored| file.end_with?(ignored) }
56
+ next if all_config.fetch(:exclude).any? { |ignored| file.end_with?(ignored) }
37
57
 
38
58
  ext = File.extname(file)
59
+
39
60
  next if ext.match?(/haml/i)
40
61
 
41
62
  check_it = ext.match?(/html/i)
@@ -49,6 +70,10 @@ module RubomaticHtml
49
70
 
50
71
  private
51
72
 
73
+ # List of all cops available
74
+ #
75
+ # @return [Array<*>]
76
+ #
52
77
  def all_cops
53
78
  @all_cops ||= [
54
79
  RubomaticHtml::Cop::Layout::LineLength,
@@ -58,11 +83,25 @@ module RubomaticHtml
58
83
  ]
59
84
  end
60
85
 
86
+ # Runs all cops against a given file
87
+ #
88
+ # @param file [String]
89
+ #
90
+ # @return [void]
91
+ #
61
92
  def run_file(file)
62
- cops = all_cops.map { |cop| cop.new(file) }
93
+ cops = all_cops.filter_map do |cop|
94
+ next unless config.dig(cop.to_s, :enabled)
95
+
96
+ cop.new(file)
97
+ end
63
98
 
64
99
  File.open(file).each_line(chomp: true).with_index(1) do |line, index|
65
- cops.each { |cop| cop.run_for_line(line, index) }
100
+ cops.each do |cop|
101
+ next if config.dig(cop.to_s).fetch(:exclude, []).any? { |ignored| file.end_with?(ignored) }
102
+
103
+ cop.run_for_line(line, index)
104
+ end
66
105
  end
67
106
  end
68
107
  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.1
4
+ version: 1.0.0.pre.rc.2
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