erb_lint 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/erb_lint.rb +1 -0
- data/lib/erb_lint/cli.rb +4 -5
- data/lib/erb_lint/linters/deprecated_classes.rb +8 -6
- data/lib/erb_lint/linters/erb_safety.rb +7 -6
- data/lib/erb_lint/linters/final_newline.rb +8 -6
- data/lib/erb_lint/linters/rubocop.rb +12 -6
- data/lib/erb_lint/offense.rb +27 -0
- data/lib/erb_lint/runner.rb +6 -6
- data/lib/erb_lint/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86e60e8bfa31cd289e7ead368d8eff2832a6a8f8
|
4
|
+
data.tar.gz: cae30be744c94ed73048403a4c1d911d2a5b8c15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5b8f374aecc1a4541bbaa363d65e8b8b38cf3d6ffb36f9f517b8057527205c48cb2225c190fcf35f2a2c0952b0aa5035439509d2c8e5b517905a18c848b2127
|
7
|
+
data.tar.gz: 3661165a60a0c6f6185957a6c61948e7d66c6cdaaa27c9e205ca39e340c75aa366094f1859e3ab4a9bd4d122744f73f4c66bd2e4086e060e89ec2f310ea7a4d9
|
data/lib/erb_lint.rb
CHANGED
data/lib/erb_lint/cli.rb
CHANGED
@@ -40,12 +40,11 @@ module ERBLint
|
|
40
40
|
runner_config = @config.merge(runner_config_override)
|
41
41
|
runner = ERBLint::Runner.new(file_loader, runner_config)
|
42
42
|
lint_files.each do |filename|
|
43
|
-
|
44
|
-
|
45
|
-
errors.each do |lint_error|
|
43
|
+
offenses = runner.run(filename, File.read(filename))
|
44
|
+
offenses.each do |offense|
|
46
45
|
puts <<~EOF
|
47
|
-
#{
|
48
|
-
In file: #{relative_filename(filename)}:#{
|
46
|
+
#{offense.message}
|
47
|
+
In file: #{relative_filename(filename)}:#{offense.line_range.begin}
|
49
48
|
|
50
49
|
EOF
|
51
50
|
errors_found = true
|
@@ -32,7 +32,7 @@ module ERBLint
|
|
32
32
|
errors = []
|
33
33
|
parser = build_parser(file_content)
|
34
34
|
class_name_with_loc(parser).each do |class_name, loc|
|
35
|
-
errors.push(*generate_errors(class_name, loc.
|
35
|
+
errors.push(*generate_errors(class_name, loc.line_range))
|
36
36
|
end
|
37
37
|
text_tags_content(parser).each do |content|
|
38
38
|
errors.push(*lint_file(content))
|
@@ -83,14 +83,16 @@ module ERBLint
|
|
83
83
|
parser.nodes_with_type(:tag)
|
84
84
|
end
|
85
85
|
|
86
|
-
def generate_errors(class_name,
|
86
|
+
def generate_errors(class_name, line_range)
|
87
87
|
violated_rules(class_name).map do |violated_rule|
|
88
88
|
suggestion = " #{violated_rule[:suggestion]}".rstrip
|
89
89
|
message = "Deprecated class `%s` detected matching the pattern `%s`.%s #{@addendum}".strip
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
|
91
|
+
Offense.new(
|
92
|
+
self,
|
93
|
+
line_range,
|
94
|
+
format(message, class_name, violated_rule[:class_expr], suggestion)
|
95
|
+
)
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
@@ -25,7 +25,7 @@ module ERBLint
|
|
25
25
|
errors = []
|
26
26
|
tester = Tester.new(file_content, config: better_html_config)
|
27
27
|
tester.errors.each do |error|
|
28
|
-
errors <<
|
28
|
+
errors << format_offense(error)
|
29
29
|
end
|
30
30
|
errors
|
31
31
|
end
|
@@ -44,11 +44,12 @@ module ERBLint
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
def format_offense(error)
|
48
|
+
Offense.new(
|
49
|
+
self,
|
50
|
+
error.location.line_range,
|
51
|
+
error.message
|
52
|
+
)
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
@@ -25,14 +25,16 @@ module ERBLint
|
|
25
25
|
ends_with_newline = lines.last.chars[-1] == "\n"
|
26
26
|
|
27
27
|
if @new_lines_should_be_present && !ends_with_newline
|
28
|
-
errors.
|
29
|
-
|
30
|
-
|
28
|
+
errors << Offense.new(
|
29
|
+
self,
|
30
|
+
Range.new(lines.length, lines.length),
|
31
|
+
'Missing a trailing newline at the end of the file.'
|
31
32
|
)
|
32
33
|
elsif !@new_lines_should_be_present && ends_with_newline
|
33
|
-
errors.
|
34
|
-
|
35
|
-
|
34
|
+
errors << Offense.new(
|
35
|
+
self,
|
36
|
+
Range.new(lines.length, lines.length),
|
37
|
+
'Remove the trailing newline at the end of the file.'
|
36
38
|
)
|
37
39
|
end
|
38
40
|
errors
|
@@ -37,7 +37,7 @@ module ERBLint
|
|
37
37
|
code = code.sub(BLOCK_EXPR, '')
|
38
38
|
offenses = inspect_content(code)
|
39
39
|
offenses&.each do |offense|
|
40
|
-
errors <<
|
40
|
+
errors << format_offense(file_content, code_node, offense)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
errors
|
@@ -82,11 +82,17 @@ module ERBLint
|
|
82
82
|
RuboCop::Cop::Team.new(cop_classes, @rubocop_config, extra_details: true, display_cop_names: true)
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
def format_offense(file_content, code_node, offense)
|
86
|
+
loc = BetterHtml::Tokenizer::Location.new(
|
87
|
+
file_content,
|
88
|
+
code_node.loc.start + offense.location.begin_pos,
|
89
|
+
code_node.loc.start + offense.location.end_pos - 1,
|
90
|
+
)
|
91
|
+
Offense.new(
|
92
|
+
self,
|
93
|
+
loc.line_range,
|
94
|
+
offense.message.strip
|
95
|
+
)
|
90
96
|
end
|
91
97
|
|
92
98
|
def config_from_hash(hash)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ERBLint
|
4
|
+
# Defines common functionality available to all linters.
|
5
|
+
class Offense
|
6
|
+
attr_reader :linter, :line_range, :message
|
7
|
+
|
8
|
+
def initialize(linter, line_range, message)
|
9
|
+
@linter = linter
|
10
|
+
@line_range = line_range
|
11
|
+
@message = message
|
12
|
+
end
|
13
|
+
|
14
|
+
def inspect
|
15
|
+
"#<#{self.class.name} linter=#{linter.class.name} "\
|
16
|
+
"line_range=#{line_range} "\
|
17
|
+
"message=#{message}>"
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(other)
|
21
|
+
other.class == self.class &&
|
22
|
+
other.linter == linter &&
|
23
|
+
other.line_range == line_range &&
|
24
|
+
other.message == message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/erb_lint/runner.rb
CHANGED
@@ -16,13 +16,13 @@ module ERBLint
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def run(filename, file_content)
|
19
|
-
|
20
|
-
|
21
|
-
{
|
22
|
-
|
23
|
-
|
24
|
-
}
|
19
|
+
offenses = []
|
20
|
+
@linters
|
21
|
+
.reject { |linter| linter.excludes_file?(filename) }
|
22
|
+
.each do |linter|
|
23
|
+
offenses += linter.lint_file(file_content)
|
25
24
|
end
|
25
|
+
offenses
|
26
26
|
end
|
27
27
|
end
|
28
28
|
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Chan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: better_html
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/erb_lint/linters/erb_safety.rb
|
142
142
|
- lib/erb_lint/linters/final_newline.rb
|
143
143
|
- lib/erb_lint/linters/rubocop.rb
|
144
|
+
- lib/erb_lint/offense.rb
|
144
145
|
- lib/erb_lint/runner.rb
|
145
146
|
- lib/erb_lint/runner_config.rb
|
146
147
|
- lib/erb_lint/version.rb
|