Sha256: b0d81ed9b17bf6a085a35933d6a5bac6810ad9a56ad51be3afed28e450f29431

Contents?: true

Size: 1.8 KB

Versions: 192

Compression:

Stored size: 1.8 KB

Contents

# A syntax checker for JSON.
# @api public
require 'puppet/syntax_checkers'
class Puppet::SyntaxCheckers::EPP < Puppet::Plugins::SyntaxCheckers::SyntaxChecker

  # Checks the text for Puppet Language EPP syntax issues and reports them to the given acceptor.
  #
  # Error messages from the checker are capped at 100 chars from the source text.
  #
  # @param text [String] The text to check
  # @param syntax [String] The syntax identifier in mime style (only accepts 'pp')
  # @param acceptor [#accept] A Diagnostic acceptor
  # @param source_pos [Puppet::Pops::Adapters::SourcePosAdapter] A source pos adapter with location information
  # @api public
  #
  def check(text, syntax, acceptor, source_pos)
    raise ArgumentError.new(_("EPP syntax checker: the text to check must be a String.")) unless text.is_a?(String)
    raise ArgumentError.new(_("EPP syntax checker: the syntax identifier must be a String, e.g. pp")) unless syntax == 'epp'
    raise ArgumentError.new(_("EPP syntax checker: invalid Acceptor, got: '%{klass}'.") % { klass: acceptor.class.name }) unless acceptor.is_a?(Puppet::Pops::Validation::Acceptor)

    begin
      Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.singleton.parse_string(text)
    rescue => e
      # Cap the message to 100 chars and replace newlines
      msg = _("EPP syntax checker: \"%{message}\"") % { message: e.message().slice(0,500).gsub(/\r?\n/, "\\n") }

      # TODO: improve the pops API to allow simpler diagnostic creation while still maintaining capabilities
      # and the issue code. (In this case especially, where there is only a single error message being issued).
      #
      issue = Puppet::Pops::Issues::issue(:ILLEGAL_EPP) { msg }
      acceptor.accept(Puppet::Pops::Validation::Diagnostic.new(:error, issue, source_pos.file, source_pos, {}))
    end
  end
end

Version data entries

192 entries across 192 versions & 1 rubygems

Version Path
puppet-6.25.0 lib/puppet/syntax_checkers/epp.rb
puppet-6.25.0-x86-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-6.25.0-x64-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-6.25.0-universal-darwin lib/puppet/syntax_checkers/epp.rb
puppet-6.24.0 lib/puppet/syntax_checkers/epp.rb
puppet-6.24.0-x86-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-6.24.0-x64-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-6.24.0-universal-darwin lib/puppet/syntax_checkers/epp.rb
puppet-6.23.0 lib/puppet/syntax_checkers/epp.rb
puppet-6.23.0-x86-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-6.23.0-x64-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-6.23.0-universal-darwin lib/puppet/syntax_checkers/epp.rb
puppet-6.22.1 lib/puppet/syntax_checkers/epp.rb
puppet-6.22.1-x86-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-6.22.1-x64-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-6.22.1-universal-darwin lib/puppet/syntax_checkers/epp.rb
puppet-7.6.1 lib/puppet/syntax_checkers/epp.rb
puppet-7.6.1-x86-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-7.6.1-x64-mingw32 lib/puppet/syntax_checkers/epp.rb
puppet-7.6.1-universal-darwin lib/puppet/syntax_checkers/epp.rb