Class: Wool::SemicolonWarning

Inherits:
LineWarning show all
Defined in:
lib/wool/warnings/semicolon.rb

Overview

Warning for using semicolons outside of class declarations.

Instance Attribute Summary

Attributes inherited from Warning

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

Instance Method Summary collapse

Methods inherited from LineWarning

options

Methods inherited from Warning

all_types, all_warnings, concrete_warnings, #count_occurrences, #desc, #fixable?, #generated_warnings, #get_indent, #indent, inherited, 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

#find_sexps, #parse

Methods included from LexicalAnalysis

#find_keyword, #find_token, #lex, #select_token, #split_on_keyword, #split_on_token, #text_between_token_positions

Constructor Details

#initialize(*args) ⇒ SemicolonWarning

Returns a new instance of SemicolonWarning.



7
8
9
10
# File 'lib/wool/warnings/semicolon.rb', line 7

def initialize(*args)
  super
  self.severity = line =~ /['"]/ ? 2 : 4
end

Instance Method Details

#fix(line = self.body) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/wool/warnings/semicolon.rb', line 16

def fix(line = self.body)
  left, right = split_on_token(line, :on_semicolon)
  return line if right.empty?
  return right[1..-1] if left.empty?

  right = fix(right[1..-1])
  "#{indent left}\n#{indent right}"
end

#match?(line = self.body) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/wool/warnings/semicolon.rb', line 12

def match?(line = self.body)
  !!(find_token(line, :on_semicolon) && !find_keyword(line, :class))
end