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.
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.
-
#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
- #raw_lines ⇒ Object
- #valid_syntax? ⇒ Boolean
Constructor Details
#initialize(source, path = nil) ⇒ ProcessedSource
Returns a new instance of ProcessedSource.
15 16 17 18 19 |
# File 'lib/rubocop/processed_source.rb', line 15 def initialize(source, path = nil) @path = path @diagnostics = [] parse(source) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
8 9 10 |
# File 'lib/rubocop/processed_source.rb', line 8 def ast @ast end |
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
8 9 10 |
# File 'lib/rubocop/processed_source.rb', line 8 def buffer @buffer end |
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
8 9 10 |
# File 'lib/rubocop/processed_source.rb', line 8 def comments @comments end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
8 9 10 |
# File 'lib/rubocop/processed_source.rb', line 8 def diagnostics @diagnostics end |
#parser_error ⇒ Object (readonly)
Returns the value of attribute parser_error.
8 9 10 |
# File 'lib/rubocop/processed_source.rb', line 8 def parser_error @parser_error end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/rubocop/processed_source.rb', line 8 def path @path end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
8 9 10 |
# File 'lib/rubocop/processed_source.rb', line 8 def tokens @tokens end |
Class Method Details
.from_file(path) ⇒ Object
11 12 13 |
# File 'lib/rubocop/processed_source.rb', line 11 def self.from_file(path) new(File.read(path), path) end |
Instance Method Details
#[](*args) ⇒ Object
47 48 49 |
# File 'lib/rubocop/processed_source.rb', line 47 def [](*args) lines[*args] end |
#comment_config ⇒ Object
21 22 23 |
# File 'lib/rubocop/processed_source.rb', line 21 def comment_config @comment_config ||= CommentConfig.new(self) end |
#disabled_line_ranges ⇒ Object
25 26 27 |
# File 'lib/rubocop/processed_source.rb', line 25 def disabled_line_ranges comment_config.cop_disabled_line_ranges end |
#lines ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/rubocop/processed_source.rb', line 29 def lines if @lines @lines else init_lines @lines end end |
#raw_lines ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/rubocop/processed_source.rb', line 38 def raw_lines if @raw_lines @raw_lines else init_lines @raw_lines end end |
#valid_syntax? ⇒ Boolean
51 52 53 54 |
# File 'lib/rubocop/processed_source.rb', line 51 def valid_syntax? return false if @parser_error @diagnostics.none? { |d| [:error, :fatal].include?(d.level) } end |