erb_lint 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/erb_lint +10 -0
- data/exe/erblint +5 -4
- data/lib/erb_lint/cache.rb +1 -1
- data/lib/erb_lint/cli.rb +10 -2
- data/lib/erb_lint/linter_registry.rb +11 -1
- data/lib/erb_lint/linters/hard_coded_string.rb +2 -0
- data/lib/erb_lint/linters/rubocop.rb +1 -1
- data/lib/erb_lint/reporters/junit_reporter.rb +41 -90
- data/lib/erb_lint/runner_config_resolver.rb +1 -1
- data/lib/erb_lint/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed317d0bcb868320c088c8788e5b14ba9f8224aab3e6ae2e4952e34df8fdefc4
|
4
|
+
data.tar.gz: 21fe3cfccf4d30225d11fa2f397186b5274bbb8d1fe6ff5bf593ac225bb327a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d281ca485b9763dc2d7e3b3297b429c2fa08f1f043e557b7a9ad9ab65c5e0e422d5ccabbd66f40e3da43088bc1b580dd9dab5213dca39a894a7b0da82c0e113c
|
7
|
+
data.tar.gz: 9907b4b4089693f5787c96b0e5cef7b1c9bd49b6831d6e6c42757fb69911a0905b395f468fab7c0339d3b0e166b6962d1a4db772476f669d659f6380e88a90c4
|
data/exe/erb_lint
ADDED
data/exe/erblint
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
lib_path = File.expand_path("#{__dir__}/../lib")
|
5
|
+
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
5
6
|
|
6
|
-
require "
|
7
|
+
require "rainbow"
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
warn(Rainbow("Calling `erblint` is deprecated, please call the renamed executable `erb_lint` instead.").yellow)
|
10
|
+
exec(File.join(__dir__, "erb_lint"), *ARGV)
|
data/lib/erb_lint/cache.rb
CHANGED
data/lib/erb_lint/cli.rb
CHANGED
@@ -13,7 +13,8 @@ module ERBLint
|
|
13
13
|
class CLI
|
14
14
|
include Utils::SeverityLevels
|
15
15
|
|
16
|
-
|
16
|
+
DEPRECATED_CONFIG_FILENAME = ".erb-lint.yml"
|
17
|
+
DEFAULT_CONFIG_FILENAME = ".erb_lint.yml"
|
17
18
|
DEFAULT_LINT_ALL_GLOB = "**/*.html{+*,}.erb"
|
18
19
|
|
19
20
|
class ExitWithFailure < RuntimeError; end
|
@@ -87,7 +88,7 @@ module ERBLint
|
|
87
88
|
rescue => e
|
88
89
|
@stats.exceptions += 1
|
89
90
|
puts "Exception occurred when processing: #{relative_filename(filename)}"
|
90
|
-
puts "If this file cannot be processed by
|
91
|
+
puts "If this file cannot be processed by erb_lint, " \
|
91
92
|
"you can exclude it in your configuration file."
|
92
93
|
puts e.message
|
93
94
|
puts Rainbow(e.backtrace.join("\n")).red
|
@@ -215,6 +216,13 @@ module ERBLint
|
|
215
216
|
if File.exist?(config_filename)
|
216
217
|
config = RunnerConfig.new(file_loader.yaml(config_filename), file_loader)
|
217
218
|
@config = RunnerConfig.default_for(config)
|
219
|
+
elsif File.exist?(DEPRECATED_CONFIG_FILENAME)
|
220
|
+
deprecation_message = "The config file has been renamed to `#{DEFAULT_CONFIG_FILENAME}` and " \
|
221
|
+
"`#{DEPRECATED_CONFIG_FILENAME}` is deprecated. " \
|
222
|
+
"Please rename your config file to `#{DEFAULT_CONFIG_FILENAME}`."
|
223
|
+
warn(Rainbow(deprecation_message).yellow)
|
224
|
+
config = RunnerConfig.new(file_loader.yaml(DEPRECATED_CONFIG_FILENAME), file_loader)
|
225
|
+
@config = RunnerConfig.default_for(config)
|
218
226
|
else
|
219
227
|
warn(Rainbow("#{config_filename} not found: using default config").yellow)
|
220
228
|
@config = RunnerConfig.default
|
@@ -3,7 +3,8 @@
|
|
3
3
|
module ERBLint
|
4
4
|
# Stores all linters available to the application.
|
5
5
|
module LinterRegistry
|
6
|
-
|
6
|
+
DEPRECATED_CUSTOM_LINTERS_DIR = ".erb-linters"
|
7
|
+
CUSTOM_LINTERS_DIR = ".erb_linters"
|
7
8
|
@loaded_linters = []
|
8
9
|
|
9
10
|
class << self
|
@@ -28,6 +29,15 @@ module ERBLint
|
|
28
29
|
|
29
30
|
def load_custom_linters(directory = CUSTOM_LINTERS_DIR)
|
30
31
|
ruby_files = Dir.glob(File.expand_path(File.join(directory, "**", "*.rb")))
|
32
|
+
|
33
|
+
deprecated_ruby_files = Dir.glob(File.expand_path(File.join(DEPRECATED_CUSTOM_LINTERS_DIR, "**", "*.rb")))
|
34
|
+
if deprecated_ruby_files.any?
|
35
|
+
deprecation_message = "The '#{DEPRECATED_CUSTOM_LINTERS_DIR}' directory for custom linters is deprecated. " \
|
36
|
+
"Please rename it to '#{CUSTOM_LINTERS_DIR}'"
|
37
|
+
warn(Rainbow(deprecation_message).yellow)
|
38
|
+
ruby_files.concat(deprecated_ruby_files)
|
39
|
+
end
|
40
|
+
|
31
41
|
ruby_files.each { |file| require file }
|
32
42
|
end
|
33
43
|
end
|
@@ -1,111 +1,62 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "rexml/document"
|
4
|
-
require "rexml/formatters/pretty"
|
5
|
-
|
6
3
|
module ERBLint
|
7
4
|
module Reporters
|
8
5
|
class JunitReporter < Reporter
|
6
|
+
ESCAPE_MAP = {
|
7
|
+
'"' => """,
|
8
|
+
"'" => "'",
|
9
|
+
"<" => "<",
|
10
|
+
">" => ">",
|
11
|
+
"&" => "&",
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
PROPERTIES = [
|
15
|
+
["erb_lint_version", ERBLint::VERSION],
|
16
|
+
["ruby_engine", RUBY_ENGINE],
|
17
|
+
["ruby_version", RUBY_VERSION],
|
18
|
+
["ruby_patchlevel", RUBY_PATCHLEVEL.to_s],
|
19
|
+
["ruby_platform", RUBY_PLATFORM],
|
20
|
+
].freeze
|
21
|
+
|
9
22
|
def preview; end
|
10
23
|
|
11
24
|
def show
|
12
|
-
xml =
|
13
|
-
|
14
|
-
REXML::Formatters::Pretty.new.write(xml, formatted_xml_string)
|
15
|
-
puts formatted_xml_string.string
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
CONTEXT = {
|
21
|
-
prologue_quote: :quote,
|
22
|
-
attribute_quote: :quote,
|
23
|
-
}
|
24
|
-
|
25
|
-
def create_junit_xml
|
26
|
-
# create prologue
|
27
|
-
xml = REXML::Document.new(nil, CONTEXT)
|
28
|
-
xml << REXML::XMLDecl.new("1.0", "UTF-8")
|
29
|
-
|
30
|
-
xml.add_element(create_testsuite_element)
|
25
|
+
puts %(<?xml version="1.0" encoding="UTF-8"?>)
|
26
|
+
puts %(<testsuite name="erblint" tests="#{@stats.processed_files.size}" failures="#{@stats.found}">)
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
failures = stats.found
|
38
|
-
testsuite_element = REXML::Element.new("testsuite", nil, CONTEXT)
|
39
|
-
testsuite_element.add_attribute("name", "erblint")
|
40
|
-
testsuite_element.add_attribute("tests", tests.to_s)
|
41
|
-
testsuite_element.add_attribute("failures", failures.to_s)
|
42
|
-
|
43
|
-
testsuite_element.add_element(create_properties)
|
28
|
+
puts %( <properties>)
|
29
|
+
PROPERTIES.each do |key, value|
|
30
|
+
puts %( <property name="#{xml_escape(key)}" value="#{xml_escape(value)}"/>)
|
31
|
+
end
|
32
|
+
puts %( </properties>)
|
44
33
|
|
45
34
|
processed_files.each do |filename, offenses|
|
35
|
+
filename_escaped = xml_escape(filename)
|
46
36
|
if offenses.empty?
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
37
|
+
puts %( <testcase name="#{filename_escaped}" file="#{filename_escaped}"/>)
|
38
|
+
else
|
39
|
+
offenses.each do |offense|
|
40
|
+
type = offense.simple_name
|
41
|
+
message = "#{type}: #{offense.message}"
|
42
|
+
body = "#{message} at #{filename}:#{offense.line_number}:#{offense.column}"
|
43
|
+
|
44
|
+
puts %( <testcase name="#{filename_escaped}" file="#{filename_escaped}" lineno="#{offense.line_number}">)
|
45
|
+
puts %( <failure message="#{xml_escape(message)}" type="#{xml_escape(type)}">)
|
46
|
+
puts %( #{xml_escape(body)})
|
47
|
+
puts %( </failure>)
|
48
|
+
puts %( </testcase>)
|
49
|
+
end
|
56
50
|
end
|
57
51
|
end
|
58
52
|
|
59
|
-
|
53
|
+
puts %(</testsuite>)
|
60
54
|
end
|
61
55
|
|
62
|
-
|
63
|
-
properties_element = REXML::Element.new("properties", nil, CONTEXT)
|
64
|
-
|
65
|
-
[
|
66
|
-
["erb_lint_version", ERBLint::VERSION],
|
67
|
-
["ruby_engine", RUBY_ENGINE],
|
68
|
-
["ruby_version", RUBY_VERSION],
|
69
|
-
["ruby_patchlevel", RUBY_PATCHLEVEL.to_s],
|
70
|
-
["ruby_platform", RUBY_PLATFORM],
|
71
|
-
].each do |property_attribute|
|
72
|
-
properties_element.add_element(create_property(*property_attribute))
|
73
|
-
end
|
74
|
-
|
75
|
-
properties_element
|
76
|
-
end
|
77
|
-
|
78
|
-
def create_property(name, value)
|
79
|
-
property_element = REXML::Element.new("property")
|
80
|
-
property_element.add_attribute("name", name)
|
81
|
-
property_element.add_attribute("value", value)
|
82
|
-
|
83
|
-
property_element
|
84
|
-
end
|
85
|
-
|
86
|
-
def create_testcase(filename, offense)
|
87
|
-
testcase_element = REXML::Element.new("testcase", nil, CONTEXT)
|
88
|
-
testcase_element.add_attribute("name", filename.to_s)
|
89
|
-
testcase_element.add_attribute("file", filename.to_s)
|
90
|
-
testcase_element.add_attribute("lineno", offense.line_number.to_s)
|
91
|
-
|
92
|
-
testcase_element.add_element(create_failure(filename, offense))
|
93
|
-
|
94
|
-
testcase_element
|
95
|
-
end
|
96
|
-
|
97
|
-
def create_failure(filename, offense)
|
98
|
-
message = offense.message
|
99
|
-
type = offense.simple_name
|
100
|
-
|
101
|
-
failure_element = REXML::Element.new("failure", nil, CONTEXT)
|
102
|
-
failure_element.add_attribute("message", "#{type}: #{message}")
|
103
|
-
failure_element.add_attribute("type", type.to_s)
|
104
|
-
|
105
|
-
cdata_element = REXML::CData.new("#{type}: #{message} at #{filename}:#{offense.line_number}:#{offense.column}")
|
106
|
-
failure_element.add_text(cdata_element)
|
56
|
+
private
|
107
57
|
|
108
|
-
|
58
|
+
def xml_escape(string)
|
59
|
+
string.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP)
|
109
60
|
end
|
110
61
|
end
|
111
62
|
end
|
@@ -37,7 +37,7 @@ module ERBLint
|
|
37
37
|
|
38
38
|
def resolve_inheritance_from_gems(hash, gems)
|
39
39
|
(gems || {}).each_pair do |gem_name, config_path|
|
40
|
-
raise(ArgumentError, "can't inherit configuration from the
|
40
|
+
raise(ArgumentError, "can't inherit configuration from the erb_lint gem") if gem_name == "erb_lint"
|
41
41
|
|
42
42
|
hash["inherit_from"] = Array(hash["inherit_from"])
|
43
43
|
Array(config_path).reverse_each do |path|
|
data/lib/erb_lint/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erb_lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Chan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -141,10 +141,12 @@ description: ERB Linter tool.
|
|
141
141
|
email:
|
142
142
|
- ruby@shopify.com
|
143
143
|
executables:
|
144
|
+
- erb_lint
|
144
145
|
- erblint
|
145
146
|
extensions: []
|
146
147
|
extra_rdoc_files: []
|
147
148
|
files:
|
149
|
+
- exe/erb_lint
|
148
150
|
- exe/erblint
|
149
151
|
- lib/erb_lint.rb
|
150
152
|
- lib/erb_lint/all.rb
|
@@ -196,7 +198,7 @@ files:
|
|
196
198
|
- lib/erb_lint/utils/ruby_to_erb.rb
|
197
199
|
- lib/erb_lint/utils/severity_levels.rb
|
198
200
|
- lib/erb_lint/version.rb
|
199
|
-
homepage: https://github.com/Shopify/
|
201
|
+
homepage: https://github.com/Shopify/erb_lint
|
200
202
|
licenses:
|
201
203
|
- MIT
|
202
204
|
metadata:
|
@@ -216,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
218
|
- !ruby/object:Gem::Version
|
217
219
|
version: '0'
|
218
220
|
requirements: []
|
219
|
-
rubygems_version: 3.5.
|
221
|
+
rubygems_version: 3.5.21
|
220
222
|
signing_key:
|
221
223
|
specification_version: 4
|
222
224
|
summary: ERB lint tool
|