Class: Wool::InlineCommentSpaceWarning
- Inherits:
-
LineWarning
- Object
- Struct
- Warning
- LineWarning
- Wool::InlineCommentSpaceWarning
- Defined in:
- lib/wool/warnings/comment_spacing.rb
Overview
Warning for insufficient space between inline comments and code
Constant Summary collapse
- OPTION_KEY =
:inline_comment_space
- DEFAULT_SPACE =
2
Instance Attribute Summary
Attributes inherited from Warning
#body, #file, #line_number, #name, #settings, #severity
Instance Method Summary collapse
Methods inherited from LineWarning
Methods inherited from Warning
all_types, all_warnings, concrete_warnings, #count_occurrences, #desc, #fixable?, #generated_warnings, #get_indent, #indent, inherited, #initialize, opt, options, setting_accessor, type
Methods included from Advice
#advice_counter, #after_advice, #argument_advice, #before_advice, #bump_advice_counter!, #with_advice
Methods included from ModuleExtensions
#attr_accessor_with_default, #cattr_accessor, #cattr_accessor_with_default, #cattr_get_and_setter, #cattr_reader, #cattr_writer
Methods included from SexpAnalysis
Methods included from LexicalAnalysis
#find_keyword, #find_token, #lex, #select_token, #split_on_keyword, #split_on_token, #text_between_token_positions
Constructor Details
This class inherits a constructor from Wool::Warning
Instance Method Details
#fix ⇒ Object
20 21 22 23 24 25 |
# File 'lib/wool/warnings/comment_spacing.rb', line 20 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 |
#match?(line = self.body) ⇒ Boolean
10 11 12 13 14 15 16 17 18 |
# File 'lib/wool/warnings/comment_spacing.rb', line 10 def match?(line = self.body) return false unless comment_token = find_token(:on_comment) comment_pos = comment_token.col - 1 left_of_comment = line[0..comment_pos] stripped = left_of_comment.rstrip return false if stripped.empty? padding_size = left_of_comment.size - stripped.size return spacing != padding_size end |
#spacing ⇒ Object
27 28 29 |
# File 'lib/wool/warnings/comment_spacing.rb', line 27 def spacing @settings[OPTION_KEY] || DEFAULT_SPACE end |