erb_lint 0.0.29 → 0.0.34
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/cli.rb +38 -26
- data/lib/erb_lint/file_loader.rb +8 -2
- data/lib/erb_lint/linters/no_javascript_tag_helper.rb +1 -0
- data/lib/erb_lint/linters/rubocop.rb +1 -3
- data/lib/erb_lint/runner_config.rb +19 -13
- data/lib/erb_lint/utils/offset_corrector.rb +18 -1
- data/lib/erb_lint/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65e35ea36e2654316241c7267aca2f9b581fa7eb5c858008a80dfc098c07a187
|
4
|
+
data.tar.gz: db35c2f60f85651728bec14a853fc8d7060e93e686c9cababa55bccb3dd46c49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbe12716e085e0baa6beef5c1395bf86874f442db6087c2d1312315cb4d60704cca5a007a3843738197d58fa0025d35b993bbbed5606ca9a3c71b81928d365e2
|
7
|
+
data.tar.gz: 7bb3506036e3a098cb9c688c20373a80bc413a6528fcb05b951e16996dd62eea358c01658f5b2aceb4d4b1b4bc63afa7ad53d852478b2b49d549a13f3da6ed1c
|
data/lib/erb_lint/cli.rb
CHANGED
@@ -17,10 +17,11 @@ module ERBLint
|
|
17
17
|
class ExitWithSuccess < RuntimeError; end
|
18
18
|
|
19
19
|
class Stats
|
20
|
-
attr_accessor :found, :corrected
|
20
|
+
attr_accessor :found, :corrected, :exceptions
|
21
21
|
def initialize
|
22
22
|
@found = 0
|
23
23
|
@corrected = 0
|
24
|
+
@exceptions = 0
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -32,15 +33,16 @@ module ERBLint
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def run(args = ARGV)
|
35
|
-
|
36
|
-
|
36
|
+
dupped_args = args.dup
|
37
|
+
load_options(dupped_args)
|
38
|
+
@files = dupped_args
|
37
39
|
|
38
40
|
load_config
|
39
41
|
|
40
42
|
if !@files.empty? && lint_files.empty?
|
41
|
-
|
43
|
+
failure!("no files found...\n")
|
42
44
|
elsif lint_files.empty?
|
43
|
-
|
45
|
+
failure!("no files found or given, specify files or config...\n#{option_parser}")
|
44
46
|
end
|
45
47
|
|
46
48
|
ensure_files_exist(lint_files)
|
@@ -53,11 +55,17 @@ module ERBLint
|
|
53
55
|
"#{enabled_linter_classes.size} #{'autocorrectable ' if autocorrect?}linters..."
|
54
56
|
puts
|
55
57
|
|
58
|
+
runner = ERBLint::Runner.new(file_loader, @config)
|
59
|
+
|
56
60
|
lint_files.each do |filename|
|
61
|
+
runner.clear_offenses
|
57
62
|
begin
|
58
|
-
run_with_corrections(filename)
|
63
|
+
run_with_corrections(runner, filename)
|
59
64
|
rescue => e
|
65
|
+
@stats.exceptions += 1
|
60
66
|
puts "Exception occured when processing: #{relative_filename(filename)}"
|
67
|
+
puts "If this file cannot be processed by erb-lint, "\
|
68
|
+
"you can exclude it in your configuration file."
|
61
69
|
puts e.message
|
62
70
|
puts Rainbow(e.backtrace.join("\n")).red
|
63
71
|
puts
|
@@ -79,7 +87,7 @@ module ERBLint
|
|
79
87
|
puts Rainbow("No errors were found in ERB files").green
|
80
88
|
end
|
81
89
|
|
82
|
-
@stats.found == 0
|
90
|
+
@stats.found == 0 && @stats.exceptions == 0
|
83
91
|
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, ExitWithFailure => e
|
84
92
|
warn(Rainbow(e.message).red)
|
85
93
|
false
|
@@ -97,10 +105,8 @@ module ERBLint
|
|
97
105
|
@options[:autocorrect]
|
98
106
|
end
|
99
107
|
|
100
|
-
def run_with_corrections(filename)
|
101
|
-
file_content = File.read(filename)
|
102
|
-
|
103
|
-
runner = ERBLint::Runner.new(file_loader, @config)
|
108
|
+
def run_with_corrections(runner, filename)
|
109
|
+
file_content = File.read(filename, encoding: Encoding::UTF_8)
|
104
110
|
|
105
111
|
7.times do
|
106
112
|
processed_source = ERBLint::ProcessedSource.new(filename, file_content)
|
@@ -144,14 +150,15 @@ module ERBLint
|
|
144
150
|
def load_config
|
145
151
|
if File.exist?(config_filename)
|
146
152
|
config = RunnerConfig.new(file_loader.yaml(config_filename), file_loader)
|
147
|
-
@config = RunnerConfig.
|
153
|
+
@config = RunnerConfig.default_for(config)
|
148
154
|
else
|
149
155
|
warn(Rainbow("#{config_filename} not found: using default config").yellow)
|
150
156
|
@config = RunnerConfig.default
|
151
157
|
end
|
152
|
-
@config.merge!(runner_config_override)
|
153
158
|
rescue Psych::SyntaxError => e
|
154
159
|
failure!("error parsing config: #{e.message}")
|
160
|
+
ensure
|
161
|
+
@config.merge!(runner_config_override)
|
155
162
|
end
|
156
163
|
|
157
164
|
def file_loader
|
@@ -163,17 +170,22 @@ module ERBLint
|
|
163
170
|
end
|
164
171
|
|
165
172
|
def lint_files
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
173
|
+
@lint_files ||=
|
174
|
+
if @options[:lint_all]
|
175
|
+
pattern = File.expand_path(glob, Dir.pwd)
|
176
|
+
Dir[pattern].select { |filename| !excluded?(filename) }
|
177
|
+
else
|
178
|
+
@files
|
179
|
+
.map { |f| Dir.exist?(f) ? Dir[File.join(f, glob)] : f }
|
180
|
+
.map { |f| f.include?('*') ? Dir[f] : f }
|
181
|
+
.flatten
|
182
|
+
.map { |f| File.expand_path(f, Dir.pwd) }
|
183
|
+
.select { |filename| !excluded?(filename) }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def glob
|
188
|
+
@config.to_hash["glob"] || DEFAULT_LINT_ALL_GLOB
|
177
189
|
end
|
178
190
|
|
179
191
|
def excluded?(filename)
|
@@ -246,7 +258,7 @@ module ERBLint
|
|
246
258
|
end
|
247
259
|
end
|
248
260
|
|
249
|
-
opts.on("--lint-all", "Lint all files matching #{DEFAULT_LINT_ALL_GLOB}") do |config|
|
261
|
+
opts.on("--lint-all", "Lint all files matching configured glob [default: #{DEFAULT_LINT_ALL_GLOB}]") do |config|
|
250
262
|
@options[:lint_all] = config
|
251
263
|
end
|
252
264
|
|
@@ -264,7 +276,7 @@ module ERBLint
|
|
264
276
|
@options[:enabled_linters] = linters
|
265
277
|
end
|
266
278
|
|
267
|
-
opts.on("--autocorrect", "Correct offenses
|
279
|
+
opts.on("-a", "--autocorrect", "Correct offenses automatically if possible (default: false)") do |config|
|
268
280
|
@options[:autocorrect] = config
|
269
281
|
end
|
270
282
|
|
data/lib/erb_lint/file_loader.rb
CHANGED
@@ -9,8 +9,14 @@ module ERBLint
|
|
9
9
|
@base_path = base_path
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
if RUBY_VERSION >= "2.6"
|
13
|
+
def yaml(filename)
|
14
|
+
YAML.safe_load(read_content(filename), permitted_classes: [Regexp, Symbol], filename: filename) || {}
|
15
|
+
end
|
16
|
+
else
|
17
|
+
def yaml(filename)
|
18
|
+
YAML.safe_load(read_content(filename), [Regexp, Symbol], [], false, filename) || {}
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
22
|
private
|
@@ -108,10 +108,8 @@ module ERBLint
|
|
108
108
|
if @only_cops.present?
|
109
109
|
selected_cops = RuboCop::Cop::Cop.all.select { |cop| cop.match?(@only_cops) }
|
110
110
|
RuboCop::Cop::Registry.new(selected_cops)
|
111
|
-
elsif @rubocop_config['Rails']['Enabled']
|
112
|
-
RuboCop::Cop::Registry.new(RuboCop::Cop::Cop.all)
|
113
111
|
else
|
114
|
-
RuboCop::Cop::Cop.
|
112
|
+
RuboCop::Cop::Registry.new(RuboCop::Cop::Cop.all)
|
115
113
|
end
|
116
114
|
end
|
117
115
|
|
@@ -45,24 +45,30 @@ module ERBLint
|
|
45
45
|
end
|
46
46
|
|
47
47
|
class << self
|
48
|
-
def default
|
48
|
+
def default(default_enabled: nil)
|
49
|
+
default_enabled = default_enabled.nil? ? true : default_enabled
|
49
50
|
new(
|
50
51
|
linters: {
|
51
|
-
AllowedScriptType: { enabled:
|
52
|
-
ClosingErbTagIndent: { enabled:
|
53
|
-
ExtraNewline: { enabled:
|
54
|
-
FinalNewline: { enabled:
|
55
|
-
NoJavascriptTagHelper: { enabled:
|
56
|
-
ParserErrors: { enabled:
|
57
|
-
RightTrim: { enabled:
|
58
|
-
SelfClosingTag: { enabled:
|
59
|
-
SpaceAroundErbTag: { enabled:
|
60
|
-
SpaceIndentation: { enabled:
|
61
|
-
SpaceInHtmlTag: { enabled:
|
62
|
-
TrailingWhitespace: { enabled:
|
52
|
+
AllowedScriptType: { enabled: default_enabled },
|
53
|
+
ClosingErbTagIndent: { enabled: default_enabled },
|
54
|
+
ExtraNewline: { enabled: default_enabled },
|
55
|
+
FinalNewline: { enabled: default_enabled },
|
56
|
+
NoJavascriptTagHelper: { enabled: default_enabled },
|
57
|
+
ParserErrors: { enabled: default_enabled },
|
58
|
+
RightTrim: { enabled: default_enabled },
|
59
|
+
SelfClosingTag: { enabled: default_enabled },
|
60
|
+
SpaceAroundErbTag: { enabled: default_enabled },
|
61
|
+
SpaceIndentation: { enabled: default_enabled },
|
62
|
+
SpaceInHtmlTag: { enabled: default_enabled },
|
63
|
+
TrailingWhitespace: { enabled: default_enabled },
|
63
64
|
},
|
64
65
|
)
|
65
66
|
end
|
67
|
+
|
68
|
+
def default_for(config)
|
69
|
+
default_linters_enabled = config.to_hash.dig("EnableDefaultLinters")
|
70
|
+
default(default_enabled: default_linters_enabled).merge(config)
|
71
|
+
end
|
66
72
|
end
|
67
73
|
|
68
74
|
private
|
@@ -38,7 +38,9 @@ module ERBLint
|
|
38
38
|
@corrector.remove_trailing(range_with_offset(range), size)
|
39
39
|
end
|
40
40
|
|
41
|
-
def range_with_offset(
|
41
|
+
def range_with_offset(node_or_range)
|
42
|
+
range = to_range(node_or_range)
|
43
|
+
|
42
44
|
@processed_source.to_source_range(
|
43
45
|
bound(@offset + range.begin_pos)..bound(@offset + (range.end_pos - 1))
|
44
46
|
)
|
@@ -50,6 +52,21 @@ module ERBLint
|
|
50
52
|
@bound_range.max,
|
51
53
|
].min
|
52
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def to_range(node_or_range)
|
59
|
+
case node_or_range
|
60
|
+
when ::RuboCop::AST::Node, ::Parser::Source::Comment
|
61
|
+
node_or_range.loc.expression
|
62
|
+
when ::Parser::Source::Range
|
63
|
+
node_or_range
|
64
|
+
else
|
65
|
+
raise TypeError,
|
66
|
+
'Expected a Parser::Source::Range, Comment or ' \
|
67
|
+
"Rubocop::AST::Node, got #{node_or_range.class}"
|
68
|
+
end
|
69
|
+
end
|
53
70
|
end
|
54
71
|
end
|
55
72
|
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.34
|
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: 2020-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: better_html
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.79'
|
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.79'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,7 +167,8 @@ files:
|
|
167
167
|
homepage: https://github.com/Shopify/erb-lint
|
168
168
|
licenses:
|
169
169
|
- MIT
|
170
|
-
metadata:
|
170
|
+
metadata:
|
171
|
+
allowed_push_host: https://rubygems.org
|
171
172
|
post_install_message:
|
172
173
|
rdoc_options: []
|
173
174
|
require_paths:
|
@@ -176,15 +177,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
177
|
requirements:
|
177
178
|
- - ">="
|
178
179
|
- !ruby/object:Gem::Version
|
179
|
-
version: 2.
|
180
|
+
version: 2.4.0
|
180
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
182
|
requirements:
|
182
183
|
- - ">="
|
183
184
|
- !ruby/object:Gem::Version
|
184
185
|
version: '0'
|
185
186
|
requirements: []
|
186
|
-
|
187
|
-
rubygems_version: 2.7.6
|
187
|
+
rubygems_version: 3.0.3
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: ERB lint tool
|