erb_lint 0.0.34 → 0.0.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65e35ea36e2654316241c7267aca2f9b581fa7eb5c858008a80dfc098c07a187
4
- data.tar.gz: db35c2f60f85651728bec14a853fc8d7060e93e686c9cababa55bccb3dd46c49
3
+ metadata.gz: 1bec7519ea346d89eb70e485c59015ea8faae7f4c85f4e3b450a4f8853eaa9b5
4
+ data.tar.gz: dba705708221bc3b5a71c57d6d9cbf1db2f7c8afbfaa7ed45fc63e71433383b5
5
5
  SHA512:
6
- metadata.gz: dbe12716e085e0baa6beef5c1395bf86874f442db6087c2d1312315cb4d60704cca5a007a3843738197d58fa0025d35b993bbbed5606ca9a3c71b81928d365e2
7
- data.tar.gz: 7bb3506036e3a098cb9c688c20373a80bc413a6528fcb05b951e16996dd62eea358c01658f5b2aceb4d4b1b4bc63afa7ad53d852478b2b49d549a13f3da6ed1c
6
+ metadata.gz: 770cd1f544b749a7210949b1221ec4401349cb30bf9a171c1b7677c3d051f9887e264d62e1c8b86c5b09c593bc96b24b867a35b2bf11f4dfe2d8a17f54332d5c
7
+ data.tar.gz: ae1f2c592fba2fce5a70eb0620024c49cdca3173388791036bb9e2ed56b3b0cbdf3e6361c0b68c94fc222640aba5422c6fd5c15d8691fa019d0a9cfc038e96a3
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rubocop'
4
+
3
5
  require 'erb_lint/corrector'
4
6
  require 'erb_lint/file_loader'
5
7
  require 'erb_lint/linter_config'
@@ -17,11 +17,22 @@ module ERBLint
17
17
  end
18
18
 
19
19
  def corrector
20
- RuboCop::Cop::Corrector.new(@processed_source.source_buffer, corrections)
20
+ BASE.new(@processed_source.source_buffer, corrections)
21
21
  end
22
22
 
23
- def diagnostics
24
- corrector.diagnostics
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
- def autocorrect(processed_source, offense)
39
- return unless offense.context
40
-
41
- lambda do |corrector|
42
- passthrough = Utils::OffsetCorrector.new(
43
- processed_source,
44
- corrector,
45
- offense.context[:offset],
46
- offense.context[:bound_range],
47
- )
48
- offense.context[:rubocop_correction].call(passthrough)
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
- team = build_team
71
- team.inspect_file(source)
72
- team.cops.each do |cop|
73
- correction_offset = 0
74
- cop.offenses.reject(&:disabled?).each do |rubocop_offense|
75
- if rubocop_offense.corrected?
76
- correction = cop.corrections[correction_offset]
77
- correction_offset += 1
78
- end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ERBLint
4
- VERSION = '0.0.34'
4
+ VERSION = '0.0.35'
5
5
  end
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.34
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-15 00:00:00.000000000 Z
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.4.0
208
+ version: 2.5.0
181
209
  required_rubygems_version: !ruby/object:Gem::Requirement
182
210
  requirements:
183
211
  - - ">="