Sha256: e024f8d0fb82bca737c4cd2f21f5e8ffb9bf54f218d23948055bbab183066f5f

Contents?: true

Size: 1.58 KB

Versions: 20

Compression:

Stored size: 1.58 KB

Contents

module SlimLint
  # Base implementation for all lint checks.
  #
  # @abstract
  class Linter
    # Include definitions for Sexp pattern-matching helpers.
    include SexpVisitor
    extend SexpVisitor::DSL

    # List of lints reported by this linter.
    #
    # @todo Remove once spec/support/shared_linter_context returns an array of
    #   lints for the subject instead of the linter itself.
    attr_reader :lints

    # Initializes a linter with the specified configuration.
    #
    # @param config [Hash] configuration for this linter
    def initialize(config)
      @config = config
      @lints = []
    end

    # Runs the linter against the given Slim document.
    #
    # @param document [SlimLint::Document]
    def run(document)
      @document = document
      @lints = []
      trigger_pattern_callbacks(document.sexp)
      @lints
    end

    # Returns the simple name for this linter.
    #
    # @return [String]
    def name
      self.class.name.split('::').last
    end

    private

    attr_reader :config, :document

    # Record a lint for reporting back to the user.
    #
    # @param node [#line] node to extract the line number from
    # @param message [String] error/warning to display to the user
    def report_lint(node, message)
      @lints << SlimLint::Lint.new(self, @document.file, node.line, message)
    end

    # Parse Ruby code into an abstract syntax tree.
    #
    # @param source [String] Ruby code to parse
    # @return [AST::Node]
    def parse_ruby(source)
      @ruby_parser ||= SlimLint::RubyParser.new
      @ruby_parser.parse(source)
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
slim_lint-0.15.1 lib/slim_lint/linter.rb
slim_lint-0.15.0 lib/slim_lint/linter.rb
slim_lint-0.14.0 lib/slim_lint/linter.rb
slim_lint-0.13.0 lib/slim_lint/linter.rb
slim_lint-0.12.0 lib/slim_lint/linter.rb
slim_lint-0.11.0 lib/slim_lint/linter.rb
slim_lint-0.10.0 lib/slim_lint/linter.rb
slim_lint-0.9.0 lib/slim_lint/linter.rb
slim_lint-0.8.3 lib/slim_lint/linter.rb
slim_lint-0.8.2 lib/slim_lint/linter.rb
slim_lint-0.8.1 lib/slim_lint/linter.rb
slim_lint-0.8.0 lib/slim_lint/linter.rb
slim_lint-0.7.2 lib/slim_lint/linter.rb
slim_lint-0.7.1 lib/slim_lint/linter.rb
slim_lint-0.7.0 lib/slim_lint/linter.rb
slim_lint-0.6.1 lib/slim_lint/linter.rb
slim_lint-0.6.0 lib/slim_lint/linter.rb
slim_lint-0.5.0 lib/slim_lint/linter.rb
slim_lint-0.4.0 lib/slim_lint/linter.rb
slim_lint-0.3.0 lib/slim_lint/linter.rb