Skip to content

Commit 0799152

Browse files
authored
Merge pull request #763 from rodjek/issue-759
Restore Ruby 1.8.7 support
2 parents 03c5e3d + f1efeba commit 0799152

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+114
-61
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Style/MethodCalledOnDoEndBlock:
6262
Style/RegexpLiteral:
6363
EnforcedStyle: percent_r
6464
Style/TrailingCommaInArguments:
65-
EnforcedStyleForMultiline: comma
65+
EnforcedStyleForMultiline: no_comma
6666
Style/TrailingCommaInLiteral:
6767
EnforcedStyleForMultiline: comma
6868
Style/FormatStringToken:

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ script:
1111
env:
1212
- CHECK=ci
1313
rvm:
14+
- 1.8.7
1415
- 1.9.3
1516
- 2.0.0
1617
- 2.1.10

lib/puppet-lint.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require 'puppet-lint/data'
99
require 'puppet-lint/checks'
1010
require 'puppet-lint/bin'
11+
require 'puppet-lint/monkeypatches'
1112

1213
class PuppetLint::NoCodeError < StandardError; end
1314
class PuppetLint::NoFix < StandardError; end

lib/puppet-lint/checks.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run(fileinfo, data)
6868

6969
@problems
7070
rescue => e
71-
puts <<-END.gsub(%r{^ {6}}, '')
71+
$stdout.puts <<-END.gsub(%r{^ {6}}, '')
7272
Whoops! It looks like puppet-lint has encountered an error that it doesn't
7373
know how to handle. Please open an issue at https://github.com/rodjek/puppet-lint
7474
and paste the following output into the issue description.
@@ -80,15 +80,15 @@ def run(fileinfo, data)
8080
END
8181

8282
if File.readable?(fileinfo)
83-
puts [
83+
$stdout.puts [
8484
'file contents:',
8585
'```',
8686
File.read(fileinfo),
8787
'```',
8888
].join("\n")
8989
end
9090

91-
puts [
91+
$stdout.puts [
9292
'error:',
9393
'```',
9494
"#{e.class}: #{e.message}",

lib/puppet-lint/configuration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def self.add_check(check)
5050
#
5151
# <option>=(value)
5252
def method_missing(method, *args, &_block)
53-
super unless method.to_s =~ %r{^(?<option>\w+)=?$}
53+
super unless method.to_s =~ %r{^(\w+)=?$}
5454

55-
option = Regexp.last_match(:option)
55+
option = Regexp.last_match(1)
5656
add_option(option.to_s) if settings[option].nil?
5757
settings[option] = args[0] unless args.empty?
5858
end

lib/puppet-lint/lexer.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def heredoc_queue
170170
# \v == vertical tab
171171
# \f == form feed
172172
# \p{Zs} == ASCII + Unicode non-linebreaking whitespace
173-
WHITESPACE_RE = %r{[\t\v\f\p{Zs}]}
173+
WHITESPACE_RE = RUBY_VERSION == '1.8.7' ? %r{[\t\v\f ]} : %r{[\t\v\f\p{Zs}]}
174174

175175
# Internal: Access the internal token storage.
176176
#
@@ -266,7 +266,7 @@ def tokenise(code)
266266
else
267267
heredoc_tag = heredoc_queue.shift
268268
heredoc_name = heredoc_tag[%r{\A"?(.+?)"?(:.+?)?(/.*)?\Z}, 1]
269-
str_contents = StringScanner.new(code[i + length..-1]).scan_until(%r{\|?\s*-?\s*#{heredoc_name}})
269+
str_contents = StringScanner.new(code[(i + length)..-1]).scan_until(%r{\|?\s*-?\s*#{heredoc_name}})
270270
interpolate_heredoc(str_contents, heredoc_tag)
271271
length += str_contents.size
272272
end
@@ -282,8 +282,8 @@ def tokenise(code)
282282
unless heredoc_queue.empty?
283283
heredoc_tag = heredoc_queue.shift
284284
heredoc_name = heredoc_tag[%r{\A"?(.+?)"?(:.+?)?(/.*)?\Z}, 1]
285-
str_contents = StringScanner.new(code[i + length..-1]).scan_until(%r{\|?\s*-?\s*#{heredoc_name}})
286-
_ = code[0..i + length].split("\n")
285+
str_contents = StringScanner.new(code[(i + length)..-1]).scan_until(%r{\|?\s*-?\s*#{heredoc_name}})
286+
_ = code[0..(i + length)].split("\n")
287287
interpolate_heredoc(str_contents, heredoc_tag)
288288
length += str_contents.size
289289
end
@@ -557,8 +557,8 @@ def get_heredoc_segment(string, eos_text, interpolate = true)
557557

558558
str = string.scan_until(regexp)
559559
begin
560-
str =~ %r{\A(?<value>.*?)(?<terminator>[$]+|\|?\s*-?#{Regexp.escape(eos_text)})\Z}m
561-
[Regexp.last_match(:value), Regexp.last_match(:terminator)]
560+
str =~ %r{\A(.*?)([$]+|\|?\s*-?#{Regexp.escape(eos_text)})\Z}m
561+
[Regexp.last_match(1), Regexp.last_match(2)]
562562
rescue
563563
[nil, nil]
564564
end

lib/puppet-lint/monkeypatches.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
begin
2+
'%{test}' % { :test => 'replaced' } == 'replaced' # rubocop:disable Style/FormatString
3+
rescue
4+
# monkeypatch String#% into Ruby 1.8.7
5+
class String
6+
Percent = instance_method('%') unless defined?(Percent)
7+
8+
def %(*a, &b)
9+
a.flatten!
10+
11+
string = case a.last
12+
when Hash
13+
expand(a.pop)
14+
else
15+
self
16+
end
17+
18+
if a.empty?
19+
string
20+
else
21+
Percent.bind(string).call(a, &b)
22+
end
23+
end
24+
25+
def expand!(vars = {})
26+
loop do
27+
changed = false
28+
vars.each do |var, value|
29+
var = var.to_s
30+
var.gsub!(%r{[^a-zA-Z0-9_]}, '')
31+
changed = gsub!(%r{\%\{#{var}\}}, value.to_s)
32+
end
33+
break unless changed
34+
end
35+
self
36+
end
37+
38+
def expand(opts = {})
39+
dup.expand!(opts)
40+
end
41+
end
42+
end
43+
44+
unless String.respond_to?(:prepend)
45+
# monkeypatch String#prepend into Ruby 1.8.7
46+
class String
47+
def prepend(lead)
48+
replace("#{lead}#{self}")
49+
end
50+
end
51+
end

lib/puppet-lint/optparser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def self.build
4444
opts.on(
4545
'--error-level LEVEL',
4646
[:all, :warning, :error],
47-
'The level of error to return (warning, error or all).',
47+
'The level of error to return (warning, error or all).'
4848
) do |el|
4949
PuppetLint.configuration.error_level = el
5050
end

lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def check
1212
:message => 'arrow should be on the right operand\'s line',
1313
:line => token.line,
1414
:column => token.column,
15-
:token => token,
15+
:token => token
1616
)
1717
end
1818
end

lib/puppet-lint/plugins/check_classes/autoloader_layout.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def check
2727
:error,
2828
:message => "#{title_token.value} not in autoload module layout",
2929
:line => title_token.line,
30-
:column => title_token.column,
30+
:column => title_token.column
3131
)
3232
end
3333
end

0 commit comments

Comments
 (0)