erb_lint 0.6.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba9ef5f8b8a251d649dd1cffba1094d770471a630d0fa66b402621883ea3b050
4
- data.tar.gz: db969c9e8bacc58b20fa9ad568c98263225c8bbf41f2d32f1b5d9f44a4c58aab
3
+ metadata.gz: 4e807585b8a00451e330b435923fc4e2331c9611e8a33bd5e5da46adde7e0ccd
4
+ data.tar.gz: e6177dae0f60d4341b742dec86b6c4b27e5393bcdd288d8ce4aba5fde7e2fca8
5
5
  SHA512:
6
- metadata.gz: a1d9e86c1862a41bb8cc2d1ae520af38ced2390e3d06c3d9bc9550a434993de502167c87adf93a780fec7f87d4921e77367e8bf8c546bf59c6f88908d0208039
7
- data.tar.gz: 468ef87d28e39aa2fb0166cdfc98bee1f1f7349d21a9a5e2c08a81f5aab47c067d1d440d6466cf28077f5d72984b9d0018bdc23af2e3b91a6127bfc46f850f5a
6
+ metadata.gz: 98d2e86ff32c0c6811897361f269bf883c21debab7cfa03d3155a37c5fa55ae498a8768ac048c05674a21878512cf252264b993271020b514b62d275d2cfb2b7
7
+ data.tar.gz: 962beffee36db0703e13c6b0736caf14cefed27bd6f1f744a9dad8b06dfe3d099fb34701bade912a160f245248c764dcd2374d80f82e2db8bf30b3d42a988d26
data/exe/erb_lint ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib_path = File.expand_path("#{__dir__}/../lib")
5
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
6
+
7
+ require "erb_lint/cli"
8
+
9
+ cli = ERBLint::CLI.new
10
+ exit(cli.run)
data/exe/erblint CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+ lib_path = File.expand_path("#{__dir__}/../lib")
5
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
5
6
 
6
- require "erb_lint/cli"
7
+ require "rainbow"
7
8
 
8
- cli = ERBLint::CLI.new
9
- exit(cli.run)
9
+ warn(Rainbow("Calling `erblint` is deprecated, please call the renamed executable `erb_lint` instead.").yellow)
10
+ exec(File.join(__dir__, "erb_lint"), *ARGV)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ERBLint
4
4
  class Cache
5
- CACHE_DIRECTORY = ".erb-lint-cache"
5
+ CACHE_DIRECTORY = ".erb_lint_cache"
6
6
 
7
7
  def initialize(config, cache_dir = nil)
8
8
  @config = config
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
- DEFAULT_CONFIG_FILENAME = ".erb-lint.yml"
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 erb-lint, " \
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
@@ -161,7 +162,7 @@ module ERBLint
161
162
  runner.run(processed_source)
162
163
  break unless autocorrect? && runner.offenses.any?
163
164
 
164
- corrector = correct(processed_source, runner.offenses)
165
+ corrector = corrector(processed_source, runner.offenses)
165
166
  break if corrector.corrections.empty?
166
167
  break if processed_source.file_content == corrector.corrected_content
167
168
 
@@ -201,10 +202,8 @@ module ERBLint
201
202
  $stdin.binmode.read.force_encoding(Encoding::UTF_8)
202
203
  end
203
204
 
204
- def correct(processed_source, offenses)
205
- corrector = ERBLint::Corrector.new(processed_source, offenses)
206
- failure!(corrector.diagnostics.join(", ")) if corrector.diagnostics.any?
207
- corrector
205
+ def corrector(processed_source, offenses)
206
+ ERBLint::Corrector.new(processed_source, offenses)
208
207
  end
209
208
 
210
209
  def config_filename
@@ -215,6 +214,13 @@ module ERBLint
215
214
  if File.exist?(config_filename)
216
215
  config = RunnerConfig.new(file_loader.yaml(config_filename), file_loader)
217
216
  @config = RunnerConfig.default_for(config)
217
+ elsif File.exist?(DEPRECATED_CONFIG_FILENAME)
218
+ deprecation_message = "The config file has been renamed to `#{DEFAULT_CONFIG_FILENAME}` and " \
219
+ "`#{DEPRECATED_CONFIG_FILENAME}` is deprecated. " \
220
+ "Please rename your config file to `#{DEFAULT_CONFIG_FILENAME}`."
221
+ warn(Rainbow(deprecation_message).yellow)
222
+ config = RunnerConfig.new(file_loader.yaml(DEPRECATED_CONFIG_FILENAME), file_loader)
223
+ @config = RunnerConfig.default_for(config)
218
224
  else
219
225
  warn(Rainbow("#{config_filename} not found: using default config").yellow)
220
226
  @config = RunnerConfig.default
@@ -7,6 +7,8 @@ module ERBLint
7
7
  def initialize(processed_source, offenses)
8
8
  @processed_source = processed_source
9
9
  @offenses = offenses
10
+ corrector = RuboCop::Cop::Corrector.new(@processed_source.source_buffer)
11
+ correct!(corrector)
10
12
  @corrected_content = corrector.rewrite
11
13
  end
12
14
 
@@ -16,22 +18,9 @@ module ERBLint
16
18
  end.compact
17
19
  end
18
20
 
19
- def corrector
20
- BASE.new(@processed_source.source_buffer, corrections)
21
- end
22
-
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
21
+ def correct!(corrector)
22
+ corrections.each do |correction|
23
+ correction.call(corrector)
35
24
  end
36
25
  end
37
26
  end
@@ -9,14 +9,8 @@ module ERBLint
9
9
  @base_path = base_path
10
10
  end
11
11
 
12
- if RUBY_VERSION >= "2.6"
13
- def yaml(filename)
14
- YAML.safe_load(read_content(filename), permitted_classes: [Regexp, Symbol], filename: filename) || {}
15
- end
16
- else
17
- def yaml(filename)
18
- YAML.safe_load(read_content(filename), [Regexp, Symbol], [], false, filename) || {}
19
- end
12
+ def yaml(filename)
13
+ YAML.safe_load(read_content(filename), permitted_classes: [Regexp, Symbol], filename: filename) || {}
20
14
  end
21
15
 
22
16
  private
@@ -3,7 +3,8 @@
3
3
  module ERBLint
4
4
  # Stores all linters available to the application.
5
5
  module LinterRegistry
6
- CUSTOM_LINTERS_DIR = ".erb-linters"
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
@@ -41,6 +41,8 @@ module ERBLint
41
41
  "&emsp;",
42
42
  "&thinsp;",
43
43
  "&times;",
44
+ "&laquo;",
45
+ "&raquo;",
44
46
  ])
45
47
 
46
48
  class ConfigSchema < LinterConfig
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "better_html"
4
4
  require "tempfile"
5
- require "erb_lint/utils/offset_corrector"
6
5
 
7
6
  module ERBLint
8
7
  module Linters
@@ -36,30 +35,14 @@ module ERBLint
36
35
  end
37
36
  end
38
37
 
39
- if ::RuboCop::Version::STRING.to_f >= 0.87
40
- def autocorrect(_processed_source, offense)
41
- return unless offense.context
38
+ def autocorrect(_processed_source, offense)
39
+ return unless offense.context
42
40
 
43
- rubocop_correction = offense.context[:rubocop_correction]
44
- return unless rubocop_correction
41
+ rubocop_correction = offense.context[:rubocop_correction]
42
+ return unless rubocop_correction
45
43
 
46
- lambda do |corrector|
47
- corrector.import!(rubocop_correction, offset: offense.context[:offset])
48
- end
49
- end
50
- else
51
- def autocorrect(processed_source, offense)
52
- return unless offense.context
53
-
54
- lambda do |corrector|
55
- passthrough = Utils::OffsetCorrector.new(
56
- processed_source,
57
- corrector,
58
- offense.context[:offset],
59
- offense.context[:bound_range],
60
- )
61
- offense.context[:rubocop_correction].call(passthrough)
62
- end
44
+ lambda do |corrector|
45
+ corrector.import!(rubocop_correction, offset: offense.context[:offset])
63
46
  end
64
47
  end
65
48
 
@@ -85,39 +68,18 @@ module ERBLint
85
68
  activate_team(processed_source, source, offset, code_node, build_team)
86
69
  end
87
70
 
88
- if ::RuboCop::Version::STRING.to_f >= 0.87
89
- def activate_team(processed_source, source, offset, code_node, team)
90
- report = team.investigate(source)
91
- report.offenses.each do |rubocop_offense|
92
- next if rubocop_offense.disabled?
71
+ def activate_team(processed_source, source, offset, code_node, team)
72
+ report = team.investigate(source)
73
+ report.offenses.each do |rubocop_offense|
74
+ next if rubocop_offense.disabled?
93
75
 
94
- correction = rubocop_offense.corrector if rubocop_offense.corrected?
76
+ correction = rubocop_offense.corrector if rubocop_offense.corrected?
95
77
 
96
- offense_range = processed_source
97
- .to_source_range(rubocop_offense.location)
98
- .offset(offset)
78
+ offense_range = processed_source
79
+ .to_source_range(rubocop_offense.location)
80
+ .offset(offset)
99
81
 
100
- add_offense(rubocop_offense, offense_range, correction, offset, code_node.loc.range)
101
- end
102
- end
103
- else
104
- def activate_team(processed_source, source, offset, code_node, team)
105
- team.inspect_file(source)
106
- team.cops.each do |cop|
107
- correction_offset = 0
108
- cop.offenses.reject(&:disabled?).each do |rubocop_offense|
109
- if rubocop_offense.corrected?
110
- correction = cop.corrections[correction_offset]
111
- correction_offset += 1
112
- end
113
-
114
- offense_range = processed_source
115
- .to_source_range(rubocop_offense.location)
116
- .offset(offset)
117
-
118
- add_offense(rubocop_offense, offense_range, correction, offset, code_node.loc.range)
119
- end
120
- end
82
+ add_offense(rubocop_offense, offense_range, correction, offset, code_node.loc.range)
121
83
  end
122
84
  end
123
85
 
@@ -154,7 +116,7 @@ module ERBLint
154
116
  end
155
117
 
156
118
  def build_team
157
- ::RuboCop::Cop::Team.new(
119
+ ::RuboCop::Cop::Team.mobilize(
158
120
  cop_classes,
159
121
  @rubocop_config,
160
122
  extra_details: true,
@@ -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
+ '"' => "&quot;",
8
+ "'" => "&apos;",
9
+ "<" => "&lt;",
10
+ ">" => "&gt;",
11
+ "&" => "&amp;",
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 = create_junit_xml
13
- formatted_xml_string = StringIO.new
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
- xml
33
- end
34
-
35
- def create_testsuite_element
36
- tests = stats.processed_files.size
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
- testcase_element = REXML::Element.new("testcase", nil, CONTEXT)
48
- testcase_element.add_attribute("name", filename.to_s)
49
- testcase_element.add_attribute("file", filename.to_s)
50
-
51
- testsuite_element.add_element(testcase_element)
52
- end
53
-
54
- offenses.each do |offense|
55
- testsuite_element.add_element(create_testcase(filename, offense))
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
- testsuite_element
53
+ puts %(</testsuite>)
60
54
  end
61
55
 
62
- def create_properties
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
- failure_element
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 erb-lint gem") if gem_name == "erb-lint"
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|
@@ -4,11 +4,11 @@ module ERBLint
4
4
  module Utils
5
5
  class InlineConfigs
6
6
  def self.rule_disable_comment_for_lines?(rule, lines)
7
- lines.match?(/# erblint:disable (?<rules>.*#{rule}).*/)
7
+ lines.match?(/# erb_?lint:disable (?<rules>.*#{rule}).*/)
8
8
  end
9
9
 
10
10
  def self.disabled_rules(line)
11
- line.match(/# erblint:disable (?<rules>.*) %>/)&.named_captures&.fetch("rules")
11
+ line.match(/# erb_?lint:disable (?<rules>.*) %>/)&.named_captures&.fetch("rules")
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ERBLint
4
- VERSION = "0.6.0"
4
+ VERSION = "0.8.0"
5
5
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Chan
8
8
  - Shopify Developers
9
- autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2024-08-01 00:00:00.000000000 Z
11
+ date: 2025-01-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
@@ -141,10 +140,12 @@ description: ERB Linter tool.
141
140
  email:
142
141
  - ruby@shopify.com
143
142
  executables:
143
+ - erb_lint
144
144
  - erblint
145
145
  extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
+ - exe/erb_lint
148
149
  - exe/erblint
149
150
  - lib/erb_lint.rb
150
151
  - lib/erb_lint/all.rb
@@ -192,16 +193,14 @@ files:
192
193
  - lib/erb_lint/stats.rb
193
194
  - lib/erb_lint/utils/block_map.rb
194
195
  - lib/erb_lint/utils/inline_configs.rb
195
- - lib/erb_lint/utils/offset_corrector.rb
196
196
  - lib/erb_lint/utils/ruby_to_erb.rb
197
197
  - lib/erb_lint/utils/severity_levels.rb
198
198
  - lib/erb_lint/version.rb
199
- homepage: https://github.com/Shopify/erb-lint
199
+ homepage: https://github.com/Shopify/erb_lint
200
200
  licenses:
201
201
  - MIT
202
202
  metadata:
203
203
  allowed_push_host: https://rubygems.org
204
- post_install_message:
205
204
  rdoc_options: []
206
205
  require_paths:
207
206
  - lib
@@ -216,8 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
215
  - !ruby/object:Gem::Version
217
216
  version: '0'
218
217
  requirements: []
219
- rubygems_version: 3.5.16
220
- signing_key:
218
+ rubygems_version: 3.6.2
221
219
  specification_version: 4
222
220
  summary: ERB lint tool
223
221
  test_files: []
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ERBLint
4
- module Utils
5
- class OffsetCorrector
6
- def initialize(processed_source, corrector, offset, bound_range)
7
- @processed_source = processed_source
8
- @corrector = corrector
9
- @offset = offset
10
- @bound_range = bound_range
11
- end
12
-
13
- def remove(range)
14
- @corrector.remove(range_with_offset(range))
15
- end
16
-
17
- def insert_before(range, content)
18
- @corrector.insert_before(range_with_offset(range), content)
19
- end
20
-
21
- def insert_after(range, content)
22
- @corrector.insert_after(range_with_offset(range), content)
23
- end
24
-
25
- def replace(range, content)
26
- @corrector.replace(range_with_offset(range), content)
27
- end
28
-
29
- def remove_preceding(range, size)
30
- @corrector.remove_preceding(range_with_offset(range), size)
31
- end
32
-
33
- def remove_leading(range, size)
34
- @corrector.remove_leading(range_with_offset(range), size)
35
- end
36
-
37
- def remove_trailing(range, size)
38
- @corrector.remove_trailing(range_with_offset(range), size)
39
- end
40
-
41
- def range_with_offset(node_or_range)
42
- range = to_range(node_or_range)
43
-
44
- @processed_source.to_source_range(
45
- bound(@offset + range.begin_pos)..bound(@offset + (range.end_pos - 1)),
46
- )
47
- end
48
-
49
- def bound(pos)
50
- pos.clamp(@bound_range.min, @bound_range.max)
51
- end
52
-
53
- private
54
-
55
- def to_range(node_or_range)
56
- case node_or_range
57
- when ::RuboCop::AST::Node, ::Parser::Source::Comment
58
- node_or_range.loc.expression
59
- when ::Parser::Source::Range
60
- node_or_range
61
- else
62
- raise TypeError,
63
- "Expected a Parser::Source::Range, Comment or " \
64
- "Rubocop::AST::Node, got #{node_or_range.class}"
65
- end
66
- end
67
- end
68
- end
69
- end