Class: RuboCop::ProcessedSource
- Inherits:
-
Object
- Object
- RuboCop::ProcessedSource
- 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.
Constant Summary collapse
- STRING_SOURCE_NAME =
'(string)'
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#parser_error ⇒ Object
readonly
Returns the value of attribute parser_error.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#raw_source ⇒ Object
readonly
Returns the value of attribute raw_source.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #comment_config ⇒ Object
- #disabled_line_ranges ⇒ Object
-
#initialize(source, path = nil) ⇒ ProcessedSource
constructor
A new instance of ProcessedSource.
- #lines ⇒ Object
- #valid_syntax? ⇒ Boolean
Constructor Details
#initialize(source, path = nil) ⇒ ProcessedSource
Returns a new instance of ProcessedSource.
16 17 18 19 20 21 |
# File 'lib/rubocop/processed_source.rb', line 16 def initialize(source, path = nil) @raw_source = source @path = path @diagnostics = [] parse(source) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
9 10 11 |
# File 'lib/rubocop/processed_source.rb', line 9 def ast @ast end |
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
9 10 11 |
# File 'lib/rubocop/processed_source.rb', line 9 def buffer @buffer end |
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
9 10 11 |
# File 'lib/rubocop/processed_source.rb', line 9 def comments @comments end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
9 10 11 |
# File 'lib/rubocop/processed_source.rb', line 9 def diagnostics @diagnostics end |
#parser_error ⇒ Object (readonly)
Returns the value of attribute parser_error.
9 10 11 |
# File 'lib/rubocop/processed_source.rb', line 9 def parser_error @parser_error end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/rubocop/processed_source.rb', line 9 def path @path end |
#raw_source ⇒ Object (readonly)
Returns the value of attribute raw_source.
9 10 11 |
# File 'lib/rubocop/processed_source.rb', line 9 def raw_source @raw_source end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
9 10 11 |
# File 'lib/rubocop/processed_source.rb', line 9 def tokens @tokens end |
Class Method Details
.from_file(path) ⇒ Object
12 13 14 |
# File 'lib/rubocop/processed_source.rb', line 12 def self.from_file(path) new(File.read(path), path) end |
Instance Method Details
#[](*args) ⇒ Object
35 36 37 |
# File 'lib/rubocop/processed_source.rb', line 35 def [](*args) lines[*args] end |
#comment_config ⇒ Object
23 24 25 |
# File 'lib/rubocop/processed_source.rb', line 23 def comment_config @comment_config ||= CommentConfig.new(self) end |
#disabled_line_ranges ⇒ Object
27 28 29 |
# File 'lib/rubocop/processed_source.rb', line 27 def disabled_line_ranges comment_config.cop_disabled_line_ranges end |
#lines ⇒ Object
31 32 33 |
# File 'lib/rubocop/processed_source.rb', line 31 def lines @lines ||= raw_source.lines.map(&:chomp) end |
#valid_syntax? ⇒ Boolean
39 40 41 42 |
# File 'lib/rubocop/processed_source.rb', line 39 def valid_syntax? return false if @parser_error @diagnostics.none? { |d| [:error, :fatal].include?(d.level) } end |