erb_lint 0.0.34 → 0.0.35
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.rb +2 -0
- data/lib/erb_lint/corrector.rb +14 -3
- data/lib/erb_lint/linters/hard_coded_string.rb +1 -1
- data/lib/erb_lint/linters/rubocop.rb +62 -31
- data/lib/erb_lint/linters/rubocop_text.rb +2 -2
- data/lib/erb_lint/version.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bec7519ea346d89eb70e485c59015ea8faae7f4c85f4e3b450a4f8853eaa9b5
|
4
|
+
data.tar.gz: dba705708221bc3b5a71c57d6d9cbf1db2f7c8afbfaa7ed45fc63e71433383b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 770cd1f544b749a7210949b1221ec4401349cb30bf9a171c1b7677c3d051f9887e264d62e1c8b86c5b09c593bc96b24b867a35b2bf11f4dfe2d8a17f54332d5c
|
7
|
+
data.tar.gz: ae1f2c592fba2fce5a70eb0620024c49cdca3173388791036bb9e2ed56b3b0cbdf3e6361c0b68c94fc222640aba5422c6fd5c15d8691fa019d0a9cfc038e96a3
|
data/lib/erb_lint.rb
CHANGED
data/lib/erb_lint/corrector.rb
CHANGED
@@ -17,11 +17,22 @@ module ERBLint
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def corrector
|
20
|
-
|
20
|
+
BASE.new(@processed_source.source_buffer, corrections)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
corrector
|
23
|
+
if ::RuboCop::Version::STRING.to_f >= 0.87
|
24
|
+
require 'rubocop/cop/legacy/corrector'
|
25
|
+
BASE = ::RuboCop::Cop::Legacy::Corrector
|
26
|
+
|
27
|
+
def diagnostics
|
28
|
+
[]
|
29
|
+
end
|
30
|
+
else
|
31
|
+
BASE = ::RuboCop::Cop::Corrector
|
32
|
+
|
33
|
+
def diagnostics
|
34
|
+
corrector.diagnostics
|
35
|
+
end
|
25
36
|
end
|
26
37
|
end
|
27
38
|
end
|
@@ -63,7 +63,7 @@ module ERBLint
|
|
63
63
|
string = offense.source_range.source
|
64
64
|
return unless (klass = load_corrector)
|
65
65
|
return unless string.strip.length > 1
|
66
|
-
node = RuboCop::AST::StrNode.new(:str, [string])
|
66
|
+
node = ::RuboCop::AST::StrNode.new(:str, [string])
|
67
67
|
corrector = klass.new(node, processed_source.filename, corrector_i18n_load_path, offense.source_range)
|
68
68
|
corrector.autocorrect(tag_start: '<%= ', tag_end: ' %>')
|
69
69
|
rescue MissingCorrector, MissingI18nLoadPath
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'better_html'
|
4
|
-
require 'rubocop'
|
5
4
|
require 'tempfile'
|
6
5
|
require 'erb_lint/utils/offset_corrector'
|
7
6
|
|
@@ -26,7 +25,7 @@ module ERBLint
|
|
26
25
|
super
|
27
26
|
@only_cops = @config.only
|
28
27
|
custom_config = config_from_hash(@config.rubocop_config)
|
29
|
-
@rubocop_config = RuboCop::ConfigLoader.merge_with_default(custom_config, '')
|
28
|
+
@rubocop_config = ::RuboCop::ConfigLoader.merge_with_default(custom_config, '')
|
30
29
|
end
|
31
30
|
|
32
31
|
def run(processed_source)
|
@@ -35,17 +34,29 @@ module ERBLint
|
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
offense.context[:offset]
|
46
|
-
|
47
|
-
|
48
|
-
|
37
|
+
if ::RuboCop::Version::STRING.to_f >= 0.87
|
38
|
+
def autocorrect(_processed_source, offense)
|
39
|
+
return unless offense.context
|
40
|
+
rubocop_correction = offense.context[:rubocop_correction]
|
41
|
+
return unless rubocop_correction
|
42
|
+
|
43
|
+
lambda do |corrector|
|
44
|
+
corrector.import!(rubocop_correction, offset: offense.context[:offset])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
def autocorrect(processed_source, offense)
|
49
|
+
return unless offense.context
|
50
|
+
|
51
|
+
lambda do |corrector|
|
52
|
+
passthrough = Utils::OffsetCorrector.new(
|
53
|
+
processed_source,
|
54
|
+
corrector,
|
55
|
+
offense.context[:offset],
|
56
|
+
offense.context[:bound_range],
|
57
|
+
)
|
58
|
+
offense.context[:rubocop_correction].call(passthrough)
|
59
|
+
end
|
49
60
|
end
|
50
61
|
end
|
51
62
|
|
@@ -62,22 +73,23 @@ module ERBLint
|
|
62
73
|
original_source = code_node.loc.source
|
63
74
|
trimmed_source = original_source.sub(BLOCK_EXPR, '').sub(SUFFIX_EXPR, '')
|
64
75
|
alignment_column = code_node.loc.column
|
76
|
+
offset = code_node.loc.begin_pos - alignment_column
|
65
77
|
aligned_source = "#{' ' * alignment_column}#{trimmed_source}"
|
66
78
|
|
67
79
|
source = rubocop_processed_source(aligned_source, processed_source.filename)
|
68
80
|
return unless source.valid_syntax?
|
69
81
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
82
|
+
activate_team(processed_source, source, offset, code_node, build_team)
|
83
|
+
end
|
84
|
+
|
85
|
+
if ::RuboCop::Version::STRING.to_f >= 0.87
|
86
|
+
def activate_team(processed_source, source, offset, code_node, team)
|
87
|
+
report = team.investigate(source)
|
88
|
+
report.offenses.each do |rubocop_offense|
|
89
|
+
next if rubocop_offense.disabled?
|
90
|
+
|
91
|
+
correction = rubocop_offense.corrector if rubocop_offense.corrected?
|
79
92
|
|
80
|
-
offset = code_node.loc.begin_pos - alignment_column
|
81
93
|
offense_range = processed_source
|
82
94
|
.to_source_range(rubocop_offense.location)
|
83
95
|
.offset(offset)
|
@@ -85,6 +97,25 @@ module ERBLint
|
|
85
97
|
add_offense(rubocop_offense, offense_range, correction, offset, code_node.loc.range)
|
86
98
|
end
|
87
99
|
end
|
100
|
+
else
|
101
|
+
def activate_team(processed_source, source, offset, code_node, team)
|
102
|
+
team.inspect_file(source)
|
103
|
+
team.cops.each do |cop|
|
104
|
+
correction_offset = 0
|
105
|
+
cop.offenses.reject(&:disabled?).each do |rubocop_offense|
|
106
|
+
if rubocop_offense.corrected?
|
107
|
+
correction = cop.corrections[correction_offset]
|
108
|
+
correction_offset += 1
|
109
|
+
end
|
110
|
+
|
111
|
+
offense_range = processed_source
|
112
|
+
.to_source_range(rubocop_offense.location)
|
113
|
+
.offset(offset)
|
114
|
+
|
115
|
+
add_offense(rubocop_offense, offense_range, correction, offset, code_node.loc.range)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
88
119
|
end
|
89
120
|
|
90
121
|
def tempfile_from(filename, content)
|
@@ -97,7 +128,7 @@ module ERBLint
|
|
97
128
|
end
|
98
129
|
|
99
130
|
def rubocop_processed_source(content, filename)
|
100
|
-
RuboCop::ProcessedSource.new(
|
131
|
+
::RuboCop::ProcessedSource.new(
|
101
132
|
content,
|
102
133
|
@rubocop_config.target_ruby_version,
|
103
134
|
filename
|
@@ -106,15 +137,15 @@ module ERBLint
|
|
106
137
|
|
107
138
|
def cop_classes
|
108
139
|
if @only_cops.present?
|
109
|
-
selected_cops = RuboCop::Cop::Cop.all.select { |cop| cop.match?(@only_cops) }
|
110
|
-
RuboCop::Cop::Registry.new(selected_cops)
|
140
|
+
selected_cops = ::RuboCop::Cop::Cop.all.select { |cop| cop.match?(@only_cops) }
|
141
|
+
::RuboCop::Cop::Registry.new(selected_cops)
|
111
142
|
else
|
112
|
-
RuboCop::Cop::Registry.new(RuboCop::Cop::Cop.all)
|
143
|
+
::RuboCop::Cop::Registry.new(::RuboCop::Cop::Cop.all)
|
113
144
|
end
|
114
145
|
end
|
115
146
|
|
116
147
|
def build_team
|
117
|
-
RuboCop::Cop::Team.new(
|
148
|
+
::RuboCop::Cop::Team.new(
|
118
149
|
cop_classes,
|
119
150
|
@rubocop_config,
|
120
151
|
extra_details: true,
|
@@ -129,7 +160,7 @@ module ERBLint
|
|
129
160
|
resolve_inheritance(hash, inherit_from)
|
130
161
|
|
131
162
|
tempfile_from('.erblint-rubocop', hash.to_yaml) do |tempfile|
|
132
|
-
RuboCop::ConfigLoader.load_file(tempfile.path)
|
163
|
+
::RuboCop::ConfigLoader.load_file(tempfile.path)
|
133
164
|
end
|
134
165
|
end
|
135
166
|
|
@@ -137,7 +168,7 @@ module ERBLint
|
|
137
168
|
base_configs(inherit_from)
|
138
169
|
.reverse_each do |base_config|
|
139
170
|
base_config.each do |k, v|
|
140
|
-
hash[k] = hash.key?(k) ? RuboCop::ConfigLoader.merge(v, hash[k]) : v if v.is_a?(Hash)
|
171
|
+
hash[k] = hash.key?(k) ? ::RuboCop::ConfigLoader.merge(v, hash[k]) : v if v.is_a?(Hash)
|
141
172
|
end
|
142
173
|
end
|
143
174
|
end
|
@@ -146,7 +177,7 @@ module ERBLint
|
|
146
177
|
regex = URI::DEFAULT_PARSER.make_regexp(%w(http https))
|
147
178
|
configs = Array(inherit_from).compact.map do |base_name|
|
148
179
|
if base_name =~ /\A#{regex}\z/
|
149
|
-
RuboCop::ConfigLoader.load_file(RuboCop::RemoteConfig.new(base_name, Dir.pwd))
|
180
|
+
::RuboCop::ConfigLoader.load_file(::RuboCop::RemoteConfig.new(base_name, Dir.pwd))
|
150
181
|
else
|
151
182
|
config_from_hash(@file_loader.yaml(base_name))
|
152
183
|
end
|
@@ -28,9 +28,9 @@ module ERBLint
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def cop_classes
|
31
|
-
selected_cops = RuboCop::Cop::Cop.all.select { |cop| cop.match?(@only_cops) }
|
31
|
+
selected_cops = ::RuboCop::Cop::Cop.all.select { |cop| cop.match?(@only_cops) }
|
32
32
|
|
33
|
-
RuboCop::Cop::Registry.new(selected_cops)
|
33
|
+
::RuboCop::Cop::Registry.new(selected_cops)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
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.35
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Chan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: better_html
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.79'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: parser
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.7.1.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.7.1.4
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: activesupport
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +136,20 @@ dependencies:
|
|
122
136
|
- - ">="
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-shopify
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
125
153
|
description: ERB Linter tool.
|
126
154
|
email:
|
127
155
|
- justin.the.c@gmail.com
|
@@ -177,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
205
|
requirements:
|
178
206
|
- - ">="
|
179
207
|
- !ruby/object:Gem::Version
|
180
|
-
version: 2.
|
208
|
+
version: 2.5.0
|
181
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
210
|
requirements:
|
183
211
|
- - ">="
|