Class: EagerEye::CommentParser
- Inherits:
-
Object
- Object
- EagerEye::CommentParser
- Defined in:
- lib/eager_eye/comment_parser.rb
Constant Summary collapse
- FILE_DISABLE_PATTERN =
/eager_eye:disable-file\s+(.+?)(?:\s+--|$)/i- NEXT_LINE_PATTERN =
/eager_eye:disable-next-line(?:\s+(.+?))?(?:\s+--|$)/i- BLOCK_START_PATTERN =
/eager_eye:disable-block(?:\s+(.+?))?(?:\s+--|$)/i- BLOCK_END_PATTERN =
/eager_eye:enable-block(?:\s+(.+?))?(?:\s+--|$)/i- INLINE_DISABLE_PATTERN =
/eager_eye:disable\s+(.+?)(?:\s+--|$)/i- ENABLE_PATTERN =
/eager_eye:enable(?:\s+(.+?))?(?:\s+--|$)/i
Instance Method Summary collapse
- #disabled_at?(line_number, detector_name) ⇒ Boolean
-
#initialize(source_code) ⇒ CommentParser
constructor
A new instance of CommentParser.
Constructor Details
#initialize(source_code) ⇒ CommentParser
Returns a new instance of CommentParser.
12 13 14 15 16 17 18 19 |
# File 'lib/eager_eye/comment_parser.rb', line 12 def initialize(source_code) @source_code = source_code.encode("UTF-8", invalid: :replace, undef: :replace) @lines = @source_code.lines @disabled_ranges = Hash.new { |h, k| h[k] = [] } @file_disabled = Set.new @current_disabled = Set.new parse_comments end |
Instance Method Details
#disabled_at?(line_number, detector_name) ⇒ Boolean
21 22 23 24 25 26 27 28 |
# File 'lib/eager_eye/comment_parser.rb', line 21 def disabled_at?(line_number, detector_name) return true if @file_disabled.include?(detector_name.to_s) return true if @file_disabled.include?("all") detector = detector_name.to_s @disabled_ranges[detector].any? { |range| range.cover?(line_number) } || @disabled_ranges["all"].any? { |range| range.cover?(line_number) } end |