Sha256: 162bc0e30c3585a61fb17e8b8163e653eace45f425f6de12b15ce088ef2df5af
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
# encoding: utf-8 module Rubocop module Cop class Token attr_reader :pos, :type, :text def initialize(pos, type, text) @pos, @type, @text = pos, type, text end def to_s "[[#{@pos.line}, #{@pos.column}], #{@type}, #{@text.inspect}]" end end class Cop < Parser::AST::Processor extend AST::Sexp attr_accessor :offences attr_accessor :debug attr_writer :disabled_lines @all = [] @config = {} class << self attr_accessor :all attr_accessor :config end def self.inherited(subclass) all << subclass end def self.cop_name name.to_s.split('::').last end def initialize @offences = [] @debug = false end def has_report? !@offences.empty? end def inspect(source, tokens, ast, comments) process(ast) comments.each { |c| on_comment(c) } end def on_comment(comment) end def add_offence(severity, line_number, message) unless @disabled_lines && @disabled_lines.include?(line_number) message = debug ? "#{name}: #{message}" : message @offences << Offence.new(severity, line_number, message) end end def name self.class.cop_name end private def on_node(syms, sexp, excludes = []) yield sexp if Array(syms).include?(sexp.type) return if Array(excludes).include?(sexp.type) sexp.children.each do |elem| if Parser::AST::Node === elem on_node(syms, elem, excludes) { |s| yield s } end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.8.0 | lib/rubocop/cop/cop.rb |