Class: Templatecop::Offense
- Inherits:
-
Object
- Object
- Templatecop::Offense
- Extended by:
- Forwardable
- Defined in:
- lib/templatecop/offense.rb
Instance Attribute Summary collapse
- #file_path ⇒ String readonly
- #offset ⇒ Integer readonly
Instance Method Summary collapse
-
#initialize(file_path:, offset:, rubocop_offense:, source:) ⇒ Offense
constructor
A new instance of Offense.
- #location ⇒ Parser::Source::Range
- #marshal_dump ⇒ Hash
- #marshal_load(hash) ⇒ Object
Constructor Details
#initialize(file_path:, offset:, rubocop_offense:, source:) ⇒ Offense
Returns a new instance of Offense.
40 41 42 43 44 45 |
# File 'lib/templatecop/offense.rb', line 40 def initialize(file_path:, offset:, rubocop_offense:, source:) @file_path = file_path @offset = offset @rubocop_offense = rubocop_offense @source = source end |
Instance Attribute Details
#file_path ⇒ String (readonly)
13 14 15 |
# File 'lib/templatecop/offense.rb', line 13 def file_path @file_path end |
#offset ⇒ Integer (readonly)
16 17 18 |
# File 'lib/templatecop/offense.rb', line 16 def offset @offset end |
Instance Method Details
#location ⇒ Parser::Source::Range
48 49 50 51 52 53 54 |
# File 'lib/templatecop/offense.rb', line 48 def location @location ||= ::Parser::Source::Range.new( buffer, @rubocop_offense.location.begin_pos + @offset, @rubocop_offense.location.end_pos + @offset ) end |
#marshal_dump ⇒ Hash
Note:
For Parallel.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/templatecop/offense.rb', line 58 def marshal_dump { begin_pos: @rubocop_offense.location.begin_pos, cop_name: @rubocop_offense.cop_name, end_pos: @rubocop_offense.location.end_pos, file_path: @file_path, message: @rubocop_offense..dup.force_encoding(::Encoding::UTF_8).scrub, offset: @offset, severity: @rubocop_offense.severity.to_s, source: @source, status: @rubocop_offense.status } end |
#marshal_load(hash) ⇒ Object
Note:
For Parallel.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/templatecop/offense.rb', line 74 def marshal_load(hash) @file_path = hash[:file_path] @offset = hash[:offset] @rubocop_offense = ::RuboCop::Cop::Offense.new( hash[:severity], ::Parser::Source::Range.new( ::Parser::Source::Buffer.new( @file_path, source: @source ), hash[:begin_pos], hash[:end_pos] ), hash[:message], hash[:cop_name], hash[:status].to_sym ) @source = hash[:source] end |