From 6181b0bf3c6cbed94a0c4bccdbbdfca2b588cb06 Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Fri, 23 Aug 2024 15:21:33 +0800 Subject: [PATCH 1/2] Add Error type to lexer tokens --- lib/puppet-lint/lexer.rb | 2 +- spec/unit/puppet-lint/lexer_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index 873795f1..a733dfa9 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -123,7 +123,7 @@ def heredoc_queue [:WHITESPACE, %r{\A(#{WHITESPACE_RE}+)}], # FIXME: Future breaking change, the following :TYPE tokens conflict with # the :TYPE keyword token. - [:TYPE, %r{\A(Integer|Float|Boolean|Regexp|String|Array|Hash|Resource|Class|Collection|Scalar|Numeric|CatalogEntry|Data|Tuple|Struct|Optional|NotUndef|Variant|Enum|Pattern|Any|Callable|Type|Runtime|Undef|Default|Sensitive)\b}], # rubocop:disable Layout/LineLength + [:TYPE, %r{\A(Integer|Float|Boolean|Regexp|String|Array|Hash|Resource|Class|Collection|Scalar|Numeric|CatalogEntry|Data|Tuple|Struct|Optional|NotUndef|Variant|Enum|Pattern|Any|Callable|Type|Runtime|Undef|Default|Sensitive|Error)\b}], # rubocop:disable Layout/LineLength [:CLASSREF, %r{\A(((::){0,1}[A-Z][-\w]*)+)}], [:NUMBER, %r{\A\b((?:0[xX][0-9A-Fa-f]+|0?\d+(?:\.\d+)?(?:[eE]-?\d+)?))\b}], [:FUNCTION_NAME, %r{#{NAME_RE}(?=\()}], diff --git a/spec/unit/puppet-lint/lexer_spec.rb b/spec/unit/puppet-lint/lexer_spec.rb index c74509b7..54832b2d 100644 --- a/spec/unit/puppet-lint/lexer_spec.rb +++ b/spec/unit/puppet-lint/lexer_spec.rb @@ -1390,6 +1390,12 @@ expect(token.value).to eq('Sensitive') end end + + it 'matches Error type' do + token = lexer.tokenise('Error').first + expect(token.type).to eq(:TYPE) + expect(token.value).to eq('Error') + end end context ':HEREDOC without interpolation' do From 25955224e1c471f04ed998c53c9e591be65bbaa1 Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Fri, 23 Aug 2024 15:23:28 +0800 Subject: [PATCH 2/2] Sort lexer type tokens --- lib/puppet-lint/lexer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index a733dfa9..504103ff 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -123,7 +123,7 @@ def heredoc_queue [:WHITESPACE, %r{\A(#{WHITESPACE_RE}+)}], # FIXME: Future breaking change, the following :TYPE tokens conflict with # the :TYPE keyword token. - [:TYPE, %r{\A(Integer|Float|Boolean|Regexp|String|Array|Hash|Resource|Class|Collection|Scalar|Numeric|CatalogEntry|Data|Tuple|Struct|Optional|NotUndef|Variant|Enum|Pattern|Any|Callable|Type|Runtime|Undef|Default|Sensitive|Error)\b}], # rubocop:disable Layout/LineLength + [:TYPE, %r{\A(Any|Array|Boolean|Callable|CatalogEntry|Class|Collection|Data|Default|Enum|Error|Float|Hash|Integer|NotUndef|Numeric|Optional|Pattern|Regexp|Resource|Runtime|Scalar|Sensitive|String|Struct|Tuple|Type|Undef|Variant)\b}], # rubocop:disable Layout/LineLength [:CLASSREF, %r{\A(((::){0,1}[A-Z][-\w]*)+)}], [:NUMBER, %r{\A\b((?:0[xX][0-9A-Fa-f]+|0?\d+(?:\.\d+)?(?:[eE]-?\d+)?))\b}], [:FUNCTION_NAME, %r{#{NAME_RE}(?=\()}],