Class: Rubocop::Cop::Cop

Inherits:
Parser::AST::Processor
  • Object
show all
Extended by:
AST::Sexp
Defined in:
lib/rubocop/cop/cop.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCop

Returns a new instance of Cop.



40
41
42
43
# File 'lib/rubocop/cop/cop.rb', line 40

def initialize
  @offences = []
  @debug = false
end

Class Attribute Details

.allObject

Returns the value of attribute all.



28
29
30
# File 'lib/rubocop/cop/cop.rb', line 28

def all
  @all
end

.configObject

Returns the value of attribute config.



29
30
31
# File 'lib/rubocop/cop/cop.rb', line 29

def config
  @config
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



21
22
23
# File 'lib/rubocop/cop/cop.rb', line 21

def debug
  @debug
end

#disabled_lines=(value) ⇒ Object (writeonly)

Sets the attribute disabled_lines

Parameters:

  • value

    the value to set the attribute disabled_lines to.



22
23
24
# File 'lib/rubocop/cop/cop.rb', line 22

def disabled_lines=(value)
  @disabled_lines = value
end

#offencesObject

Returns the value of attribute offences.



20
21
22
# File 'lib/rubocop/cop/cop.rb', line 20

def offences
  @offences
end

Class Method Details

.cop_nameObject



36
37
38
# File 'lib/rubocop/cop/cop.rb', line 36

def self.cop_name
  name.to_s.split('::').last
end

.inherited(subclass) ⇒ Object



32
33
34
# File 'lib/rubocop/cop/cop.rb', line 32

def self.inherited(subclass)
  all << subclass
end

Instance Method Details

#add_offence(severity, line_number, message) ⇒ Object



60
61
62
63
64
65
# File 'lib/rubocop/cop/cop.rb', line 60

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

#has_report?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/rubocop/cop/cop.rb', line 45

def has_report?
  !@offences.empty?
end

#ignore_node(node) ⇒ Object



57
58
# File 'lib/rubocop/cop/cop.rb', line 57

def ignore_node(node)
end

#inspect(source, tokens, ast, comments) ⇒ Object



49
50
51
52
# File 'lib/rubocop/cop/cop.rb', line 49

def inspect(source, tokens, ast, comments)
  process(ast)
  comments.each { |c| on_comment(c) }
end

#nameObject



67
68
69
# File 'lib/rubocop/cop/cop.rb', line 67

def name
  self.class.cop_name
end

#on_comment(comment) ⇒ Object



54
55
# File 'lib/rubocop/cop/cop.rb', line 54

def on_comment(comment)
end