class Object
Constants
- FUNCTIONS_TO_BE_DECORATED
- STRINGY
- TRANSLATE_FUNCTION
Public Instance Methods
check()
click to toggle source
# File lib/puppet-lint/plugins/check_i18n.rb, line 5 def check tokens.select { |token| FUNCTIONS_TO_BE_DECORATED.include?(token.value) && function?(token) && message_not_decorated?(token) }.each do |token| function = token.value non_decorated_message = token.next_token.next_token interpolation = interpolation? non_decorated_message heredoc = heredoc? non_decorated_message message = if interpolation "#{function}(#{non_decorated_message.value}) should be decorated but interpolation is not supported at this time." elsif heredoc "'#{function}' messages should be decorated: eg #{TRANSLATE_FUNCTION}(#{non_decorated_message.value}) heredoc detected." else "'#{function}' messages should be decorated: eg #{TRANSLATE_FUNCTION}(#{non_decorated_message.value})" end notify :warning, message: message, line: token.line, column: non_decorated_message.column, token: non_decorated_message, interpolation: interpolation, heredoc: heredoc end end
fix(problem)
click to toggle source
# File lib/puppet-lint/plugins/check_i18n.rb, line 30 def fix(problem) return if problem[:interpolation] left_index = tokens.index(problem[:token]) right_index = if problem[:heredoc] tokens.index(problem[:token].find_token_of(:next, :NEWLINE, skip_blocks: true) || problem[:token].find_token_of(:next, :WHITESPACE, skip_blocks: true)) else tokens.index(problem[:token].find_token_of(:next, :RPAREN, skip_blocks: true)) end # order of insertion is important, we insert right to left, so as not to muddy the indexing tokens.insert(right_index, PuppetLint::Lexer::Token.new(:RPAREN, ')', 0, 0)) tokens.insert(left_index, PuppetLint::Lexer::Token.new(:NAME, TRANSLATE_FUNCTION, 0, 0)) tokens.insert((left_index + 1), PuppetLint::Lexer::Token.new(:LPAREN, '(', 0, 0)) end
function?(suspected_function)
click to toggle source
# File lib/puppet-lint/plugins/check_i18n.rb, line 46 def function?(suspected_function) suspected_function.type == :FUNCTION_NAME || suspected_function.type == :NAME end
heredoc?(token)
click to toggle source
# File lib/puppet-lint/plugins/check_i18n.rb, line 60 def heredoc?(token) token.type == :HEREDOC_OPEN end
interpolation?(token)
click to toggle source
# File lib/puppet-lint/plugins/check_i18n.rb, line 56 def interpolation?(token) token.type == :DQPRE end
message_not_decorated?(token)
click to toggle source
# File lib/puppet-lint/plugins/check_i18n.rb, line 50 def message_not_decorated?(token) # the next token is the openning round brace so grab the next suspected_i18n_function = token.next_token.next_token suspected_i18n_function.value != TRANSLATE_FUNCTION end