erb_lint 0.0.35 → 0.0.36
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/lib/erb_lint.rb +7 -0
- data/lib/erb_lint/cli.rb +32 -34
- data/lib/erb_lint/linter.rb +1 -0
- data/lib/erb_lint/linter_registry.rb +12 -3
- data/lib/erb_lint/offense.rb +8 -0
- data/lib/erb_lint/reporter.rb +38 -0
- data/lib/erb_lint/reporters/compact_reporter.rb +60 -0
- data/lib/erb_lint/reporters/multiline_reporter.rb +22 -0
- data/lib/erb_lint/runner.rb +0 -1
- data/lib/erb_lint/stats.rb +27 -0
- data/lib/erb_lint/version.rb +1 -1
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63f417288a7c49d68dcd0a04bbf07d4c8fc31c424cec244ddebab39ed3e5fab4
|
4
|
+
data.tar.gz: 22649a4264e1c570fe4a39e4112ea402d5ae04da3aaf7c35d3ce685c6fff7e21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0c1a2bdef25b71c750708c661aea9504551f3bcc53e7ed2017056f15d2789be58e4f758fe3735885ff4da6d43c0501f99542ce764737a8c072c24f228239155
|
7
|
+
data.tar.gz: 0653d4ec366580de6a08aff33263e9415f96ecb4bc9e579db20979f8ffb0d238cc6db9e361877ca529eef2fdf45c98233ec1ddf39cb4c01d6560a2e30fa6b489
|
data/lib/erb_lint.rb
CHANGED
@@ -12,8 +12,15 @@ require 'erb_lint/processed_source'
|
|
12
12
|
require 'erb_lint/runner_config'
|
13
13
|
require 'erb_lint/runner'
|
14
14
|
require 'erb_lint/version'
|
15
|
+
require 'erb_lint/stats'
|
16
|
+
require 'erb_lint/reporter'
|
15
17
|
|
16
18
|
# Load linters
|
17
19
|
Dir[File.expand_path('erb_lint/linters/**/*.rb', File.dirname(__FILE__))].each do |file|
|
18
20
|
require file
|
19
21
|
end
|
22
|
+
|
23
|
+
# Load reporters
|
24
|
+
Dir[File.expand_path('erb_lint/reporters/**/*.rb', File.dirname(__FILE__))].each do |file|
|
25
|
+
require file
|
26
|
+
end
|
data/lib/erb_lint/cli.rb
CHANGED
@@ -14,16 +14,8 @@ module ERBLint
|
|
14
14
|
DEFAULT_LINT_ALL_GLOB = "**/*.html{+*,}.erb"
|
15
15
|
|
16
16
|
class ExitWithFailure < RuntimeError; end
|
17
|
-
class ExitWithSuccess < RuntimeError; end
|
18
17
|
|
19
|
-
class
|
20
|
-
attr_accessor :found, :corrected, :exceptions
|
21
|
-
def initialize
|
22
|
-
@found = 0
|
23
|
-
@corrected = 0
|
24
|
-
@exceptions = 0
|
25
|
-
end
|
26
|
-
end
|
18
|
+
class ExitWithSuccess < RuntimeError; end
|
27
19
|
|
28
20
|
def initialize
|
29
21
|
@options = {}
|
@@ -51,9 +43,12 @@ module ERBLint
|
|
51
43
|
failure!('no linter available with current configuration')
|
52
44
|
end
|
53
45
|
|
54
|
-
|
55
|
-
|
56
|
-
|
46
|
+
@options[:format] ||= :multiline
|
47
|
+
@stats.files = lint_files.size
|
48
|
+
@stats.linters = enabled_linter_classes.size
|
49
|
+
|
50
|
+
reporter = Reporter.create_reporter(@options[:format], @stats, autocorrect?)
|
51
|
+
reporter.preview
|
57
52
|
|
58
53
|
runner = ERBLint::Runner.new(file_loader, @config)
|
59
54
|
|
@@ -72,20 +67,7 @@ module ERBLint
|
|
72
67
|
end
|
73
68
|
end
|
74
69
|
|
75
|
-
|
76
|
-
corrected_found_diff = @stats.found - @stats.corrected
|
77
|
-
if corrected_found_diff > 0
|
78
|
-
warn(Rainbow(
|
79
|
-
"#{@stats.corrected} error(s) corrected and #{corrected_found_diff} error(s) remaining in ERB files"
|
80
|
-
).red)
|
81
|
-
else
|
82
|
-
puts Rainbow("#{@stats.corrected} error(s) corrected in ERB files").green
|
83
|
-
end
|
84
|
-
elsif @stats.found > 0
|
85
|
-
warn(Rainbow("#{@stats.found} error(s) were found in ERB files").red)
|
86
|
-
else
|
87
|
-
puts Rainbow("No errors were found in ERB files").green
|
88
|
-
end
|
70
|
+
reporter.show
|
89
71
|
|
90
72
|
@stats.found == 0 && @stats.exceptions == 0
|
91
73
|
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, ExitWithFailure => e
|
@@ -126,15 +108,12 @@ module ERBLint
|
|
126
108
|
file_content = corrector.corrected_content
|
127
109
|
runner.clear_offenses
|
128
110
|
end
|
111
|
+
offenses_filename = relative_filename(filename)
|
112
|
+
offenses = runner.offenses || []
|
129
113
|
|
130
|
-
@stats.found +=
|
131
|
-
|
132
|
-
|
133
|
-
#{offense.message}#{Rainbow(' (not autocorrected)').red if autocorrect?}
|
134
|
-
In file: #{relative_filename(filename)}:#{offense.line_range.begin}
|
135
|
-
|
136
|
-
EOF
|
137
|
-
end
|
114
|
+
@stats.found += offenses.size
|
115
|
+
@stats.processed_files[offenses_filename] ||= []
|
116
|
+
@stats.processed_files[offenses_filename] |= offenses
|
138
117
|
end
|
139
118
|
|
140
119
|
def correct(processed_source, offenses)
|
@@ -258,6 +237,15 @@ module ERBLint
|
|
258
237
|
end
|
259
238
|
end
|
260
239
|
|
240
|
+
opts.on("--format FORMAT", format_options_help) do |format|
|
241
|
+
unless Reporter.available_format?(format)
|
242
|
+
error_message = invalid_format_error_message(format)
|
243
|
+
failure!(error_message)
|
244
|
+
end
|
245
|
+
|
246
|
+
@options[:format] = format
|
247
|
+
end
|
248
|
+
|
261
249
|
opts.on("--lint-all", "Lint all files matching configured glob [default: #{DEFAULT_LINT_ALL_GLOB}]") do |config|
|
262
250
|
@options[:lint_all] = config
|
263
251
|
end
|
@@ -289,5 +277,15 @@ module ERBLint
|
|
289
277
|
end
|
290
278
|
end
|
291
279
|
end
|
280
|
+
|
281
|
+
def format_options_help
|
282
|
+
"Report offenses in the given format: "\
|
283
|
+
"(#{Reporter.available_formats.join(', ')}) (default: multiline)"
|
284
|
+
end
|
285
|
+
|
286
|
+
def invalid_format_error_message(given_format)
|
287
|
+
formats = Reporter.available_formats.map { |format| " - #{format}\n" }
|
288
|
+
"#{given_format}: is not a valid format. Available formats:\n#{formats.join}"
|
289
|
+
end
|
292
290
|
end
|
293
291
|
end
|
data/lib/erb_lint/linter.rb
CHANGED
@@ -14,6 +14,7 @@ module ERBLint
|
|
14
14
|
# `ERBLint::Linters::Foo.simple_name` #=> "Foo"
|
15
15
|
# `ERBLint::Linters::Compass::Bar.simple_name` #=> "Compass::Bar"
|
16
16
|
def inherited(linter)
|
17
|
+
super
|
17
18
|
linter.simple_name = if linter.name.start_with?('ERBLint::Linters::')
|
18
19
|
name_parts = linter.name.split('::')
|
19
20
|
name_parts[2..-1].join('::')
|
@@ -4,19 +4,28 @@ module ERBLint
|
|
4
4
|
# Stores all linters available to the application.
|
5
5
|
module LinterRegistry
|
6
6
|
CUSTOM_LINTERS_DIR = '.erb-linters'
|
7
|
-
@
|
7
|
+
@loaded_linters = []
|
8
8
|
|
9
9
|
class << self
|
10
|
-
|
10
|
+
def clear
|
11
|
+
@linters = nil
|
12
|
+
end
|
11
13
|
|
12
14
|
def included(linter_class)
|
13
|
-
@
|
15
|
+
@loaded_linters << linter_class
|
14
16
|
end
|
15
17
|
|
16
18
|
def find_by_name(name)
|
17
19
|
linters.detect { |linter| linter.simple_name == name }
|
18
20
|
end
|
19
21
|
|
22
|
+
def linters
|
23
|
+
@linters ||= begin
|
24
|
+
load_custom_linters
|
25
|
+
@loaded_linters
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
20
29
|
def load_custom_linters(directory = CUSTOM_LINTERS_DIR)
|
21
30
|
ruby_files = Dir.glob(File.expand_path(File.join(directory, '**', '*.rb')))
|
22
31
|
ruby_files.each { |file| require file }
|
data/lib/erb_lint/offense.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_support/core_ext/class'
|
3
|
+
|
4
|
+
module ERBLint
|
5
|
+
class Reporter
|
6
|
+
def self.create_reporter(format, *args)
|
7
|
+
reporter_klass = "#{ERBLint::Reporters}::#{format.to_s.camelize}Reporter".constantize
|
8
|
+
reporter_klass.new(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.available_format?(format)
|
12
|
+
available_formats.include?(format.to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.available_formats
|
16
|
+
descendants
|
17
|
+
.map(&:to_s)
|
18
|
+
.map(&:demodulize)
|
19
|
+
.map(&:underscore)
|
20
|
+
.map { |klass_name| klass_name.sub("_reporter", "") }
|
21
|
+
.sort
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(stats, autocorrect)
|
25
|
+
@stats = stats
|
26
|
+
@autocorrect = autocorrect
|
27
|
+
end
|
28
|
+
|
29
|
+
def preview; end
|
30
|
+
|
31
|
+
def show; end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_reader :stats, :autocorrect
|
36
|
+
delegate :processed_files, to: :stats
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ERBLint
|
4
|
+
module Reporters
|
5
|
+
class CompactReporter < Reporter
|
6
|
+
def preview
|
7
|
+
puts "Linting #{stats.files} files with "\
|
8
|
+
"#{stats.linters} #{'autocorrectable ' if autocorrect}linters..."
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
processed_files.each do |filename, offenses|
|
13
|
+
offenses.each do |offense|
|
14
|
+
puts format_offense(filename, offense)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
footer
|
19
|
+
summary
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def format_offense(filename, offense)
|
25
|
+
[
|
26
|
+
"#{filename}:",
|
27
|
+
"#{offense.line_number}:",
|
28
|
+
"#{offense.column}: ",
|
29
|
+
offense.message.to_s,
|
30
|
+
].join
|
31
|
+
end
|
32
|
+
|
33
|
+
def footer; end
|
34
|
+
|
35
|
+
def summary
|
36
|
+
if stats.corrected > 0
|
37
|
+
report_corrected_offenses
|
38
|
+
elsif stats.found > 0
|
39
|
+
warn(Rainbow("#{stats.found} error(s) were found in ERB files").red)
|
40
|
+
else
|
41
|
+
puts Rainbow("No errors were found in ERB files").green
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def report_corrected_offenses
|
46
|
+
corrected_found_diff = stats.found - stats.corrected
|
47
|
+
|
48
|
+
if corrected_found_diff > 0
|
49
|
+
message = Rainbow(
|
50
|
+
"#{stats.corrected} error(s) corrected and #{corrected_found_diff} error(s) remaining in ERB files"
|
51
|
+
).red
|
52
|
+
|
53
|
+
warn(message)
|
54
|
+
else
|
55
|
+
puts Rainbow("#{stats.corrected} error(s) corrected in ERB files").green
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "compact_reporter"
|
3
|
+
|
4
|
+
module ERBLint
|
5
|
+
module Reporters
|
6
|
+
class MultilineReporter < CompactReporter
|
7
|
+
private
|
8
|
+
|
9
|
+
def format_offense(filename, offense)
|
10
|
+
<<~EOF
|
11
|
+
|
12
|
+
#{offense.message}#{Rainbow(' (not autocorrected)').red if autocorrect}
|
13
|
+
In file: #{filename}:#{offense.line_number}
|
14
|
+
EOF
|
15
|
+
end
|
16
|
+
|
17
|
+
def footer
|
18
|
+
puts
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/erb_lint/runner.rb
CHANGED
@@ -10,7 +10,6 @@ module ERBLint
|
|
10
10
|
@config = config || RunnerConfig.default
|
11
11
|
raise ArgumentError, 'expect `config` to be a RunnerConfig instance' unless @config.is_a?(RunnerConfig)
|
12
12
|
|
13
|
-
LinterRegistry.load_custom_linters
|
14
13
|
linter_classes = LinterRegistry.linters.select { |klass| @config.for_linter(klass).enabled? }
|
15
14
|
@linters = linter_classes.map do |linter_class|
|
16
15
|
linter_class.new(@file_loader, @config.for_linter(linter_class))
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ERBLint
|
3
|
+
class Stats
|
4
|
+
attr_accessor :found,
|
5
|
+
:corrected,
|
6
|
+
:exceptions,
|
7
|
+
:linters,
|
8
|
+
:files,
|
9
|
+
:processed_files
|
10
|
+
|
11
|
+
def initialize(
|
12
|
+
found: 0,
|
13
|
+
corrected: 0,
|
14
|
+
exceptions: 0,
|
15
|
+
linters: 0,
|
16
|
+
files: 0,
|
17
|
+
processed_files: {}
|
18
|
+
)
|
19
|
+
@found = found
|
20
|
+
@corrected = corrected
|
21
|
+
@exceptions = exceptions
|
22
|
+
@linters = linters
|
23
|
+
@files = files
|
24
|
+
@processed_files = processed_files
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/erb_lint/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erb_lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.36
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Chan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: better_html
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rubocop
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: parser
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,9 +185,13 @@ files:
|
|
185
185
|
- lib/erb_lint/linters/trailing_whitespace.rb
|
186
186
|
- lib/erb_lint/offense.rb
|
187
187
|
- lib/erb_lint/processed_source.rb
|
188
|
+
- lib/erb_lint/reporter.rb
|
189
|
+
- lib/erb_lint/reporters/compact_reporter.rb
|
190
|
+
- lib/erb_lint/reporters/multiline_reporter.rb
|
188
191
|
- lib/erb_lint/runner.rb
|
189
192
|
- lib/erb_lint/runner_config.rb
|
190
193
|
- lib/erb_lint/runner_config_resolver.rb
|
194
|
+
- lib/erb_lint/stats.rb
|
191
195
|
- lib/erb_lint/utils/block_map.rb
|
192
196
|
- lib/erb_lint/utils/offset_corrector.rb
|
193
197
|
- lib/erb_lint/utils/ruby_to_erb.rb
|