erb_lint 0.1.1 → 0.1.2
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 +3 -6
- data/lib/erb_lint/linter_config.rb +2 -0
- data/lib/erb_lint/linters/allowed_script_type.rb +4 -3
- data/lib/erb_lint/linters/deprecated_classes.rb +1 -0
- data/lib/erb_lint/linters/hard_coded_string.rb +3 -0
- data/lib/erb_lint/linters/no_javascript_tag_helper.rb +3 -1
- data/lib/erb_lint/linters/partial_instance_variable.rb +1 -1
- data/lib/erb_lint/linters/require_input_autocomplete.rb +2 -2
- data/lib/erb_lint/linters/require_script_nonce.rb +2 -2
- data/lib/erb_lint/linters/rubocop.rb +2 -0
- data/lib/erb_lint/linters/self_closing_tag.rb +1 -0
- data/lib/erb_lint/linters/space_around_erb_tag.rb +5 -4
- data/lib/erb_lint/linters/space_in_html_tag.rb +1 -0
- data/lib/erb_lint/offense.rb +1 -0
- data/lib/erb_lint/reporter.rb +2 -0
- data/lib/erb_lint/reporters/compact_reporter.rb +9 -2
- data/lib/erb_lint/reporters/multiline_reporter.rb +1 -0
- data/lib/erb_lint/runner.rb +2 -1
- data/lib/erb_lint/runner_config.rb +1 -0
- data/lib/erb_lint/runner_config_resolver.rb +1 -0
- data/lib/erb_lint/stats.rb +4 -0
- data/lib/erb_lint/utils/block_map.rb +1 -0
- data/lib/erb_lint/utils/offset_corrector.rb +1 -1
- data/lib/erb_lint/utils/ruby_to_erb.rb +1 -0
- data/lib/erb_lint/version.rb +1 -1
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97583caf4e48c7c5b8a6d2e1bf4c17add7bac9693ef6032be0fb22f9d46f4fa4
|
4
|
+
data.tar.gz: 3d1dba73d37680a0339936a12a6c2a048b473a7c9077518f54edd1aa037c4ce5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a043d8859ef059100dd809112f8768908f2ec8df59a52991c09ea995d2181aeabf06c105b3d12eef13ddbbed15d220edbdd88941fe6a55a23fd5c600aa55623d
|
7
|
+
data.tar.gz: 805102e771aac93e6a75017dde3f88deee018dceff3c8c57f2ddcdea88f97f241980efc17885999989733952e771e0538a75eaf67566499e61534c9e64476f75
|
data/lib/erb_lint/cli.rb
CHANGED
@@ -50,6 +50,7 @@ module ERBLint
|
|
50
50
|
@options[:fail_level] ||= severity_level_for_name(:refactor)
|
51
51
|
@stats.files = lint_files.size
|
52
52
|
@stats.linters = enabled_linter_classes.size
|
53
|
+
@stats.autocorrectable_linters = enabled_linter_classes.count(&:support_autocorrect?)
|
53
54
|
|
54
55
|
reporter = Reporter.create_reporter(@options[:format], @stats, autocorrect?)
|
55
56
|
reporter.preview
|
@@ -232,11 +233,7 @@ module ERBLint
|
|
232
233
|
|
233
234
|
def enabled_linter_classes
|
234
235
|
@enabled_linter_classes ||= ERBLint::LinterRegistry.linters
|
235
|
-
.select { |klass|
|
236
|
-
end
|
237
|
-
|
238
|
-
def linter_can_run?(klass)
|
239
|
-
!autocorrect? || klass.support_autocorrect?
|
236
|
+
.select { |klass| enabled_linter_names.include?(klass.simple_name.underscore) }
|
240
237
|
end
|
241
238
|
|
242
239
|
def relative_filename(filename)
|
@@ -325,7 +322,7 @@ module ERBLint
|
|
325
322
|
|
326
323
|
def format_options_help
|
327
324
|
"Report offenses in the given format: "\
|
328
|
-
|
325
|
+
"(#{Reporter.available_formats.join(", ")}) (default: multiline)"
|
329
326
|
end
|
330
327
|
|
331
328
|
def invalid_format_error_message(given_format)
|
@@ -29,6 +29,7 @@ module ERBLint
|
|
29
29
|
if (extra_keys = given_keys - allowed_keys).any?
|
30
30
|
raise Error, "Given key is not allowed: #{extra_keys.join(", ")}"
|
31
31
|
end
|
32
|
+
|
32
33
|
super(config)
|
33
34
|
rescue SmartProperties::InitializationError => e
|
34
35
|
raise Error, "The following properties are required to be set: #{e.properties}"
|
@@ -40,6 +41,7 @@ module ERBLint
|
|
40
41
|
unless self.class.properties.key?(name)
|
41
42
|
raise Error, "No such property: #{name}"
|
42
43
|
end
|
44
|
+
|
43
45
|
super
|
44
46
|
end
|
45
47
|
|
@@ -31,7 +31,7 @@ module ERBLint
|
|
31
31
|
add_offense(
|
32
32
|
name_node.loc,
|
33
33
|
"Avoid using inline `<script>` tags altogether. "\
|
34
|
-
|
34
|
+
"Instead, move javascript code into a static file."
|
35
35
|
)
|
36
36
|
next
|
37
37
|
end
|
@@ -50,8 +50,8 @@ module ERBLint
|
|
50
50
|
add_offense(
|
51
51
|
type_attribute.loc,
|
52
52
|
"Avoid using #{type_attribute.value.inspect} as type for `<script>` tag. "\
|
53
|
-
|
54
|
-
|
53
|
+
"Must be one of: #{@config.allowed_types.join(", ")}"\
|
54
|
+
"#{" (or no type attribute)" if @config.allow_blank?}."
|
55
55
|
)
|
56
56
|
end
|
57
57
|
end
|
@@ -59,6 +59,7 @@ module ERBLint
|
|
59
59
|
|
60
60
|
def autocorrect(_processed_source, offense)
|
61
61
|
return unless offense.context
|
62
|
+
|
62
63
|
lambda do |corrector|
|
63
64
|
type_attribute, = *offense.context
|
64
65
|
if type_attribute.nil?
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "set"
|
3
4
|
require "better_html/tree/tag"
|
4
5
|
require "active_support/core_ext/string/inflections"
|
@@ -83,6 +84,7 @@ module ERBLint
|
|
83
84
|
string = offense.source_range.source
|
84
85
|
return unless (klass = load_corrector)
|
85
86
|
return unless string.strip.length > 1
|
87
|
+
|
86
88
|
node = ::RuboCop::AST::StrNode.new(:str, [string])
|
87
89
|
corrector = klass.new(node, processed_source.filename, corrector_i18n_load_path, offense.source_range)
|
88
90
|
corrector.autocorrect(tag_start: "<%= ", tag_end: " %>")
|
@@ -100,6 +102,7 @@ module ERBLint
|
|
100
102
|
def load_corrector
|
101
103
|
corrector_name = @config["corrector"].fetch("name") { raise MissingCorrector }
|
102
104
|
raise ForbiddenCorrector unless ALLOWED_CORRECTORS.include?(corrector_name)
|
105
|
+
|
103
106
|
require @config["corrector"].fetch("path") { raise MissingCorrector }
|
104
107
|
|
105
108
|
corrector_name.safe_constantize
|
@@ -22,6 +22,7 @@ module ERBLint
|
|
22
22
|
indicator_node, _, code_node, _ = *erb_node
|
23
23
|
indicator = indicator_node&.loc&.source
|
24
24
|
next if indicator == "#"
|
25
|
+
|
25
26
|
source = code_node.loc.source
|
26
27
|
|
27
28
|
ruby_node =
|
@@ -31,13 +32,14 @@ module ERBLint
|
|
31
32
|
nil
|
32
33
|
end
|
33
34
|
next unless ruby_node
|
35
|
+
|
34
36
|
send_node = ruby_node.descendants(:send).first
|
35
37
|
next unless send_node&.method_name?(:javascript_tag)
|
36
38
|
|
37
39
|
add_offense(
|
38
40
|
erb_node.loc,
|
39
41
|
"Avoid using 'javascript_tag do' as it confuses tests "\
|
40
|
-
|
42
|
+
"that validate html, use inline <script> instead",
|
41
43
|
[erb_node, send_node]
|
42
44
|
)
|
43
45
|
end
|
@@ -8,7 +8,7 @@ module ERBLint
|
|
8
8
|
|
9
9
|
def run(processed_source)
|
10
10
|
instance_variable_regex = /\s@\w+/
|
11
|
-
return unless processed_source.filename.match?(
|
11
|
+
return unless processed_source.filename.match?(%r{(\A|.*/)_[^/\s]*\.html\.erb\z}) &&
|
12
12
|
processed_source.file_content.match?(instance_variable_regex)
|
13
13
|
|
14
14
|
add_offense(
|
@@ -63,7 +63,7 @@ module ERBLint
|
|
63
63
|
add_offense(
|
64
64
|
tag_node.to_a[1].loc,
|
65
65
|
"Input tag is missing an autocomplete attribute. If no "\
|
66
|
-
|
66
|
+
"autocomplete behaviour is desired, use the value `off` or `nope`.",
|
67
67
|
[autocomplete_attribute]
|
68
68
|
)
|
69
69
|
end
|
@@ -97,7 +97,7 @@ module ERBLint
|
|
97
97
|
add_offense(
|
98
98
|
erb_node.loc,
|
99
99
|
"Input field helper is missing an autocomplete attribute. If no "\
|
100
|
-
|
100
|
+
"autocomplete behaviour is desired, use the value `off` or `nope`.",
|
101
101
|
[erb_node, send_node]
|
102
102
|
)
|
103
103
|
end
|
@@ -74,8 +74,8 @@ module ERBLint
|
|
74
74
|
|
75
75
|
def tag_helper?(send_node)
|
76
76
|
send_node&.method_name?(:javascript_tag) ||
|
77
|
-
|
78
|
-
|
77
|
+
send_node&.method_name?(:javascript_include_tag) ||
|
78
|
+
send_node&.method_name?(:javascript_pack_tag)
|
79
79
|
end
|
80
80
|
|
81
81
|
def code_comment?(indicator_node)
|
@@ -37,6 +37,7 @@ module ERBLint
|
|
37
37
|
if ::RuboCop::Version::STRING.to_f >= 0.87
|
38
38
|
def autocorrect(_processed_source, offense)
|
39
39
|
return unless offense.context
|
40
|
+
|
40
41
|
rubocop_correction = offense.context[:rubocop_correction]
|
41
42
|
return unless rubocop_correction
|
42
43
|
|
@@ -150,6 +151,7 @@ module ERBLint
|
|
150
151
|
@rubocop_config,
|
151
152
|
extra_details: true,
|
152
153
|
display_cop_names: true,
|
154
|
+
autocorrect: true,
|
153
155
|
auto_correct: true,
|
154
156
|
stdin: "",
|
155
157
|
)
|
@@ -16,6 +16,7 @@ module ERBLint
|
|
16
16
|
indicator_node, ltrim, code_node, rtrim = *erb_node
|
17
17
|
indicator = indicator_node&.loc&.source
|
18
18
|
next if indicator == "#" || indicator == "%"
|
19
|
+
|
19
20
|
code = code_node.children.first
|
20
21
|
|
21
22
|
start_spaces = code.match(START_SPACES)&.captures&.first || ""
|
@@ -23,7 +24,7 @@ module ERBLint
|
|
23
24
|
add_offense(
|
24
25
|
code_node.loc.resize(start_spaces.size),
|
25
26
|
"Use 1 space after `<%#{indicator}#{ltrim&.loc&.source}` "\
|
26
|
-
|
27
|
+
"instead of #{start_spaces.size} space#{"s" if start_spaces.size > 1}.",
|
27
28
|
" "
|
28
29
|
)
|
29
30
|
elsif start_spaces.count("\n") > 1
|
@@ -31,7 +32,7 @@ module ERBLint
|
|
31
32
|
add_offense(
|
32
33
|
code_node.loc.resize(start_spaces.size),
|
33
34
|
"Use 1 newline after `<%#{indicator&.loc&.source}#{ltrim&.loc&.source}` "\
|
34
|
-
|
35
|
+
"instead of #{start_spaces.count("\n")}.",
|
35
36
|
"#{lines.first}\n#{lines.last}"
|
36
37
|
)
|
37
38
|
end
|
@@ -41,7 +42,7 @@ module ERBLint
|
|
41
42
|
add_offense(
|
42
43
|
code_node.loc.end.adjust(begin_pos: -end_spaces.size),
|
43
44
|
"Use 1 space before `#{rtrim&.loc&.source}%>` "\
|
44
|
-
|
45
|
+
"instead of #{end_spaces.size} space#{"s" if start_spaces.size > 1}.",
|
45
46
|
" "
|
46
47
|
)
|
47
48
|
elsif end_spaces.count("\n") > 1
|
@@ -49,7 +50,7 @@ module ERBLint
|
|
49
50
|
add_offense(
|
50
51
|
code_node.loc.end.adjust(begin_pos: -end_spaces.size),
|
51
52
|
"Use 1 newline before `#{rtrim&.loc&.source}%>` "\
|
52
|
-
|
53
|
+
"instead of #{end_spaces.count("\n")}.",
|
53
54
|
"#{lines.first}\n#{lines.last}"
|
54
55
|
)
|
55
56
|
end
|
data/lib/erb_lint/offense.rb
CHANGED
data/lib/erb_lint/reporter.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "active_support/core_ext/class"
|
3
4
|
require "active_support/core_ext/module/delegation"
|
4
5
|
|
@@ -34,6 +35,7 @@ module ERBLint
|
|
34
35
|
private
|
35
36
|
|
36
37
|
attr_reader :stats, :autocorrect
|
38
|
+
|
37
39
|
delegate :processed_files, to: :stats
|
38
40
|
end
|
39
41
|
end
|
@@ -4,8 +4,7 @@ module ERBLint
|
|
4
4
|
module Reporters
|
5
5
|
class CompactReporter < Reporter
|
6
6
|
def preview
|
7
|
-
puts "
|
8
|
-
"#{stats.linters} #{"autocorrectable " if autocorrect}linters..."
|
7
|
+
puts "#{linting} #{stats.files} files with #{linters}..."
|
9
8
|
end
|
10
9
|
|
11
10
|
def show
|
@@ -21,6 +20,14 @@ module ERBLint
|
|
21
20
|
|
22
21
|
private
|
23
22
|
|
23
|
+
def linting
|
24
|
+
"Linting" + (autocorrect ? " and autocorrecting" : "")
|
25
|
+
end
|
26
|
+
|
27
|
+
def linters
|
28
|
+
"#{stats.linters} linters" + (autocorrect ? " (#{stats.autocorrectable_linters} autocorrectable)" : "")
|
29
|
+
end
|
30
|
+
|
24
31
|
def format_offense(filename, offense)
|
25
32
|
[
|
26
33
|
"#{filename}:",
|
data/lib/erb_lint/runner.rb
CHANGED
@@ -18,8 +18,9 @@ module ERBLint
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def run(processed_source)
|
21
|
+
relative_filename = processed_source.filename.delete_prefix("#{@file_loader.base_path}/")
|
21
22
|
@linters
|
22
|
-
.reject { |linter| linter.excludes_file?(
|
23
|
+
.reject { |linter| linter.excludes_file?(relative_filename) }
|
23
24
|
.each do |linter|
|
24
25
|
linter.run(processed_source)
|
25
26
|
@offenses.concat(linter.offenses)
|
data/lib/erb_lint/stats.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module ERBLint
|
3
4
|
class Stats
|
4
5
|
attr_accessor :ignored,
|
@@ -6,6 +7,7 @@ module ERBLint
|
|
6
7
|
:corrected,
|
7
8
|
:exceptions,
|
8
9
|
:linters,
|
10
|
+
:autocorrectable_linters,
|
9
11
|
:files,
|
10
12
|
:processed_files
|
11
13
|
|
@@ -15,6 +17,7 @@ module ERBLint
|
|
15
17
|
corrected: 0,
|
16
18
|
exceptions: 0,
|
17
19
|
linters: 0,
|
20
|
+
autocorrectable_linters: 0,
|
18
21
|
files: 0,
|
19
22
|
processed_files: {}
|
20
23
|
)
|
@@ -23,6 +26,7 @@ module ERBLint
|
|
23
26
|
@corrected = corrected
|
24
27
|
@exceptions = exceptions
|
25
28
|
@linters = linters
|
29
|
+
@autocorrectable_linters = autocorrectable_linters
|
26
30
|
@files = files
|
27
31
|
@processed_files = processed_files
|
28
32
|
end
|
data/lib/erb_lint/version.rb
CHANGED
metadata
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erb_lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2022-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: better_html
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.0.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.0.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: html_tokenizer
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 2.7.1.4
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rainbow
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: smart_properties
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
224
|
requirements: []
|
225
|
-
rubygems_version: 3.
|
225
|
+
rubygems_version: 3.3.3
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: ERB lint tool
|