Class: Rubocop::ProcessedSource

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/processed_source.rb

Overview

ProcessedSource contains objects which are generated by Parser and other information such as disabled lines for cops. It also provides a convenient way to access source lines.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer, ast, comments, tokens, diagnostics) ⇒ ProcessedSource

Returns a new instance of ProcessedSource.



11
12
13
14
15
16
17
18
# File 'lib/rubocop/processed_source.rb', line 11

def initialize(buffer, ast, comments, tokens, diagnostics)
  @buffer = buffer
  @ast = ast
  @comments = comments
  @tokens = tokens
  @diagnostics = diagnostics
  @comment_config = CommentConfig.new(self)
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



8
9
10
# File 'lib/rubocop/processed_source.rb', line 8

def ast
  @ast
end

#bufferObject (readonly)

Returns the value of attribute buffer.



8
9
10
# File 'lib/rubocop/processed_source.rb', line 8

def buffer
  @buffer
end

#comment_configObject (readonly)

Returns the value of attribute comment_config.



8
9
10
# File 'lib/rubocop/processed_source.rb', line 8

def comment_config
  @comment_config
end

#commentsObject (readonly)

Returns the value of attribute comments.



8
9
10
# File 'lib/rubocop/processed_source.rb', line 8

def comments
  @comments
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



8
9
10
# File 'lib/rubocop/processed_source.rb', line 8

def diagnostics
  @diagnostics
end

#tokensObject (readonly)

Returns the value of attribute tokens.



8
9
10
# File 'lib/rubocop/processed_source.rb', line 8

def tokens
  @tokens
end

Instance Method Details

#[](*args) ⇒ Object



42
43
44
# File 'lib/rubocop/processed_source.rb', line 42

def [](*args)
  lines[*args]
end

#disabled_line_rangesObject



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

def disabled_line_ranges
  comment_config.cop_disabled_line_ranges
end

#file_pathObject



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

def file_path
  @buffer.name
end

#linesObject



24
25
26
27
28
29
30
31
# File 'lib/rubocop/processed_source.rb', line 24

def lines
  if @lines
    @lines
  else
    init_lines
    @lines
  end
end

#raw_linesObject



33
34
35
36
37
38
39
40
# File 'lib/rubocop/processed_source.rb', line 33

def raw_lines
  if @raw_lines
    @raw_lines
  else
    init_lines
    @raw_lines
  end
end

#valid_syntax?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rubocop/processed_source.rb', line 46

def valid_syntax?
  @diagnostics.none? { |d| [:error, :fatal].include?(d.level) }
end