File tree 2 files changed +10
-7
lines changed
lib/puppet-lint/plugins/legacy_facts
spec/unit/puppet-lint/plugins/legacy_facts 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -115,14 +115,9 @@ def check
115
115
tokens . select { |x | LEGACY_FACTS_VAR_TYPES . include? ( x . type ) } . each do |token |
116
116
fact_name = ''
117
117
118
- # This matches legacy facts defined in the fact hash that use the top scope
119
- # fact assignment.
120
- if token . value . start_with? ( '::facts[' )
121
- fact_name = token . value . match ( %r{::facts\[ '(.*)'\] } ) [ 1 ]
122
-
123
118
# This matches legacy facts defined in the fact hash.
124
- elsif token . value . start_with? ( " facts['" )
125
- fact_name = token . value . match ( %r{facts \[ '(.*)' \] } ) [ 1 ]
119
+ if ( match = ( token . value . match ( %r{(::)? facts\[ '(.*)' \] } ) || token . value . match ( %r{(::)?facts \[ (.*) \] } ) ) )
120
+ fact_name = match [ 2 ]
126
121
127
122
# This matches using legacy facts in a the new structured fact. For
128
123
# example this would match 'uuid' in $facts['uuid'] so it can be converted
Original file line number Diff line number Diff line change 121
121
expect ( problems ) . to have ( 1 ) . problem
122
122
end
123
123
end
124
+
125
+ context 'top scoped fact variable using unquoted legacy facts hash variable in interpolation' do
126
+ let ( :code ) { '$::facts[osfamily]' }
127
+
128
+ it 'detects a single problem' do
129
+ expect ( problems ) . to have ( 1 ) . problem
130
+ end
131
+ end
124
132
end
125
133
126
134
context 'with fix enabled' do
You can’t perform that action at this time.
0 commit comments