Class: Laser::InlineCommentSpaceWarning

Inherits:
LineWarning show all
Defined in:
lib/laser/warnings/comment_spacing.rb

Overview

Warning for insufficient space between inline comments and code

Constant Summary

OPTION_KEY =
:inline_comment_space
DEFAULT_SPACE =
2

Instance Attribute Summary

Attributes inherited from Warning

#body, #file, #line_number, #name, #severity

Instance Method Summary (collapse)

Methods inherited from LineWarning

options

Instance Method Details

- (Object) fix



21
22
23
24
25
26
# File 'lib/laser/warnings/comment_spacing.rb', line 21

def fix
  comment_token = find_token(:on_comment)
  comment_pos = comment_token.col - 1
  left_of_comment = line[0..comment_pos].rstrip
  left_of_comment + (' ' * spacing) + comment_token.body
end

- (Boolean) match?(line = self.body)



11
12
13
14
15
16
17
18
19
# File 'lib/laser/warnings/comment_spacing.rb', line 11

def match?(line = self.body)
  return false unless comment_token = find_token(:on_comment)
  left_of_comment = line[0,comment_token.col].lstrip
  return false if left_of_comment[0,1] == '#'
  stripped = left_of_comment.rstrip
  return false if stripped.empty?
  padding_size = left_of_comment.size - stripped.size
  return spacing != padding_size
end

- (Object) spacing



28
29
30
# File 'lib/laser/warnings/comment_spacing.rb', line 28

def spacing
  @settings[OPTION_KEY] || DEFAULT_SPACE
end