erb_lint 0.0.35 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/erblint +1 -1
- data/lib/erb_lint.rb +1 -17
- data/lib/erb_lint/all.rb +26 -0
- data/lib/erb_lint/cli.rb +101 -54
- data/lib/erb_lint/corrector.rb +1 -1
- data/lib/erb_lint/linter.rb +6 -5
- data/lib/erb_lint/linter_config.rb +3 -3
- data/lib/erb_lint/linter_registry.rb +14 -5
- data/lib/erb_lint/linters/allowed_script_type.rb +7 -7
- data/lib/erb_lint/linters/closing_erb_tag_indent.rb +2 -2
- data/lib/erb_lint/linters/deprecated_classes.rb +7 -7
- data/lib/erb_lint/linters/erb_safety.rb +2 -2
- data/lib/erb_lint/linters/extra_newline.rb +1 -1
- data/lib/erb_lint/linters/final_newline.rb +2 -2
- data/lib/erb_lint/linters/hard_coded_string.rb +36 -16
- data/lib/erb_lint/linters/no_javascript_tag_helper.rb +8 -8
- data/lib/erb_lint/linters/partial_instance_variable.rb +23 -0
- data/lib/erb_lint/linters/require_input_autocomplete.rb +121 -0
- data/lib/erb_lint/linters/require_script_nonce.rb +92 -0
- data/lib/erb_lint/linters/right_trim.rb +1 -1
- data/lib/erb_lint/linters/rubocop.rb +11 -11
- data/lib/erb_lint/linters/rubocop_text.rb +1 -1
- data/lib/erb_lint/linters/self_closing_tag.rb +5 -7
- data/lib/erb_lint/linters/space_around_erb_tag.rb +5 -5
- data/lib/erb_lint/linters/space_in_html_tag.rb +6 -6
- data/lib/erb_lint/linters/space_indentation.rb +1 -1
- data/lib/erb_lint/linters/trailing_whitespace.rb +1 -1
- data/lib/erb_lint/offense.rb +15 -4
- data/lib/erb_lint/reporter.rb +39 -0
- data/lib/erb_lint/reporters/compact_reporter.rb +66 -0
- data/lib/erb_lint/reporters/json_reporter.rb +72 -0
- data/lib/erb_lint/reporters/multiline_reporter.rb +22 -0
- data/lib/erb_lint/runner.rb +1 -2
- data/lib/erb_lint/runner_config.rb +8 -7
- data/lib/erb_lint/runner_config_resolver.rb +4 -4
- data/lib/erb_lint/stats.rb +30 -0
- data/lib/erb_lint/utils/block_map.rb +2 -2
- data/lib/erb_lint/utils/offset_corrector.rb +1 -1
- data/lib/erb_lint/utils/ruby_to_erb.rb +5 -5
- data/lib/erb_lint/utils/severity_levels.rb +16 -0
- data/lib/erb_lint/version.rb +1 -1
- metadata +17 -7
@@ -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
@@ -8,9 +8,8 @@ module ERBLint
|
|
8
8
|
def initialize(file_loader, config)
|
9
9
|
@file_loader = file_loader
|
10
10
|
@config = config || RunnerConfig.default
|
11
|
-
raise ArgumentError,
|
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))
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "erb_lint/runner_config_resolver"
|
4
4
|
|
5
5
|
module ERBLint
|
6
6
|
class RunnerConfig
|
@@ -9,7 +9,7 @@ module ERBLint
|
|
9
9
|
def initialize(config = nil, file_loader = nil)
|
10
10
|
@config = (config || {}).dup.deep_stringify_keys
|
11
11
|
|
12
|
-
resolver.resolve_inheritance_from_gems(@config, @config.delete(
|
12
|
+
resolver.resolve_inheritance_from_gems(@config, @config.delete("inherit_gem"))
|
13
13
|
resolver.resolve_inheritance(@config, file_loader) if file_loader
|
14
14
|
@config.delete("inherit_from")
|
15
15
|
end
|
@@ -24,7 +24,7 @@ module ERBLint
|
|
24
24
|
elsif klass.is_a?(Class) && klass <= ERBLint::Linter
|
25
25
|
klass.simple_name
|
26
26
|
else
|
27
|
-
raise ArgumentError,
|
27
|
+
raise ArgumentError, "expected String or linter class"
|
28
28
|
end
|
29
29
|
linter_klass = LinterRegistry.find_by_name(klass_name)
|
30
30
|
raise Error, "#{klass_name}: linter not found (is it loaded?)" unless linter_klass
|
@@ -32,7 +32,7 @@ module ERBLint
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def global_exclude
|
35
|
-
@config[
|
35
|
+
@config["exclude"] || []
|
36
36
|
end
|
37
37
|
|
38
38
|
def merge(other_config)
|
@@ -61,6 +61,7 @@ module ERBLint
|
|
61
61
|
SpaceIndentation: { enabled: default_enabled },
|
62
62
|
SpaceInHtmlTag: { enabled: default_enabled },
|
63
63
|
TrailingWhitespace: { enabled: default_enabled },
|
64
|
+
RequireInputAutocomplete: { enabled: default_enabled },
|
64
65
|
},
|
65
66
|
)
|
66
67
|
end
|
@@ -74,13 +75,13 @@ module ERBLint
|
|
74
75
|
private
|
75
76
|
|
76
77
|
def linters_config
|
77
|
-
@config[
|
78
|
+
@config["linters"] || {}
|
78
79
|
end
|
79
80
|
|
80
81
|
def config_hash_for_linter(klass_name)
|
81
82
|
config_hash = linters_config[klass_name] || {}
|
82
|
-
config_hash[
|
83
|
-
config_hash[
|
83
|
+
config_hash["exclude"] ||= []
|
84
|
+
config_hash["exclude"].concat(global_exclude) if config_hash["exclude"].is_a?(Array)
|
84
85
|
config_hash
|
85
86
|
end
|
86
87
|
|
@@ -24,7 +24,7 @@
|
|
24
24
|
module ERBLint
|
25
25
|
class RunnerConfigResolver
|
26
26
|
def resolve_inheritance(hash, file_loader)
|
27
|
-
inherited_files = Array(hash[
|
27
|
+
inherited_files = Array(hash["inherit_from"])
|
28
28
|
base_configs(file_loader, inherited_files).reverse_each do |base_config|
|
29
29
|
base_config.each do |k, v|
|
30
30
|
next unless v.is_a?(Hash)
|
@@ -36,12 +36,12 @@ module ERBLint
|
|
36
36
|
|
37
37
|
def resolve_inheritance_from_gems(hash, gems)
|
38
38
|
(gems || {}).each_pair do |gem_name, config_path|
|
39
|
-
raise(ArgumentError, "can't inherit configuration from the erb-lint gem") if gem_name ==
|
39
|
+
raise(ArgumentError, "can't inherit configuration from the erb-lint gem") if gem_name == "erb-lint"
|
40
40
|
|
41
|
-
hash[
|
41
|
+
hash["inherit_from"] = Array(hash["inherit_from"])
|
42
42
|
Array(config_path).reverse_each do |path|
|
43
43
|
# Put gem configuration first so local configuration overrides it.
|
44
|
-
hash[
|
44
|
+
hash["inherit_from"].unshift(gem_config_path(gem_name, path))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ERBLint
|
3
|
+
class Stats
|
4
|
+
attr_accessor :ignored,
|
5
|
+
:found,
|
6
|
+
:corrected,
|
7
|
+
:exceptions,
|
8
|
+
:linters,
|
9
|
+
:files,
|
10
|
+
:processed_files
|
11
|
+
|
12
|
+
def initialize(
|
13
|
+
ignored: 0,
|
14
|
+
found: 0,
|
15
|
+
corrected: 0,
|
16
|
+
exceptions: 0,
|
17
|
+
linters: 0,
|
18
|
+
files: 0,
|
19
|
+
processed_files: {}
|
20
|
+
)
|
21
|
+
@ignored = ignored
|
22
|
+
@found = found
|
23
|
+
@corrected = corrected
|
24
|
+
@exceptions = exceptions
|
25
|
+
@linters = linters
|
26
|
+
@files = files
|
27
|
+
@processed_files = processed_files
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -9,10 +9,10 @@ module ERBLint
|
|
9
9
|
def html_options_to_tag_attributes(hash_node)
|
10
10
|
hash_node.children.map do |pair_node|
|
11
11
|
key_node, value_node = *pair_node
|
12
|
-
key = ruby_to_erb(key_node,
|
13
|
-
value = ruby_to_erb(value_node,
|
14
|
-
[key, "\"#{value}\""].join(
|
15
|
-
end.join(
|
12
|
+
key = ruby_to_erb(key_node, "=") { |s| s.tr("_", "-") }
|
13
|
+
value = ruby_to_erb(value_node, "=") { |s| escape_quote(s) }
|
14
|
+
[key, "\"#{value}\""].join("=")
|
15
|
+
end.join(" ")
|
16
16
|
end
|
17
17
|
|
18
18
|
def ruby_to_erb(node, indicator = nil, &block)
|
@@ -43,7 +43,7 @@ module ERBLint
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def escape_quote(str)
|
46
|
-
str.gsub('"',
|
46
|
+
str.gsub('"', """)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ERBLint
|
4
|
+
module Utils
|
5
|
+
module SeverityLevels
|
6
|
+
SEVERITY_NAMES = [:info, :refactor, :convention, :warning, :error, :fatal].freeze
|
7
|
+
|
8
|
+
SEVERITY_CODE_TABLE = { I: :info, R: :refactor, C: :convention,
|
9
|
+
W: :warning, E: :error, F: :fatal, }.freeze
|
10
|
+
|
11
|
+
def severity_level_for_name(name)
|
12
|
+
SEVERITY_NAMES.index(name || :error) + 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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.
|
4
|
+
version: 0.1.1
|
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-07-28 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
|
@@ -160,6 +160,7 @@ extra_rdoc_files: []
|
|
160
160
|
files:
|
161
161
|
- exe/erblint
|
162
162
|
- lib/erb_lint.rb
|
163
|
+
- lib/erb_lint/all.rb
|
163
164
|
- lib/erb_lint/cli.rb
|
164
165
|
- lib/erb_lint/corrector.rb
|
165
166
|
- lib/erb_lint/file_loader.rb
|
@@ -175,6 +176,9 @@ files:
|
|
175
176
|
- lib/erb_lint/linters/hard_coded_string.rb
|
176
177
|
- lib/erb_lint/linters/no_javascript_tag_helper.rb
|
177
178
|
- lib/erb_lint/linters/parser_errors.rb
|
179
|
+
- lib/erb_lint/linters/partial_instance_variable.rb
|
180
|
+
- lib/erb_lint/linters/require_input_autocomplete.rb
|
181
|
+
- lib/erb_lint/linters/require_script_nonce.rb
|
178
182
|
- lib/erb_lint/linters/right_trim.rb
|
179
183
|
- lib/erb_lint/linters/rubocop.rb
|
180
184
|
- lib/erb_lint/linters/rubocop_text.rb
|
@@ -185,12 +189,18 @@ files:
|
|
185
189
|
- lib/erb_lint/linters/trailing_whitespace.rb
|
186
190
|
- lib/erb_lint/offense.rb
|
187
191
|
- lib/erb_lint/processed_source.rb
|
192
|
+
- lib/erb_lint/reporter.rb
|
193
|
+
- lib/erb_lint/reporters/compact_reporter.rb
|
194
|
+
- lib/erb_lint/reporters/json_reporter.rb
|
195
|
+
- lib/erb_lint/reporters/multiline_reporter.rb
|
188
196
|
- lib/erb_lint/runner.rb
|
189
197
|
- lib/erb_lint/runner_config.rb
|
190
198
|
- lib/erb_lint/runner_config_resolver.rb
|
199
|
+
- lib/erb_lint/stats.rb
|
191
200
|
- lib/erb_lint/utils/block_map.rb
|
192
201
|
- lib/erb_lint/utils/offset_corrector.rb
|
193
202
|
- lib/erb_lint/utils/ruby_to_erb.rb
|
203
|
+
- lib/erb_lint/utils/severity_levels.rb
|
194
204
|
- lib/erb_lint/version.rb
|
195
205
|
homepage: https://github.com/Shopify/erb-lint
|
196
206
|
licenses:
|
@@ -212,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
222
|
- !ruby/object:Gem::Version
|
213
223
|
version: '0'
|
214
224
|
requirements: []
|
215
|
-
rubygems_version: 3.
|
225
|
+
rubygems_version: 3.2.20
|
216
226
|
signing_key:
|
217
227
|
specification_version: 4
|
218
228
|
summary: ERB lint tool
|