Class: Laser::UselessDoubleQuotesWarning
- Inherits:
-
FileWarning
- Object
- Struct
- Warning
- FileWarning
- Laser::UselessDoubleQuotesWarning
- Defined in:
- lib/laser/warnings/useless_double_quotes.rb
Overview
Warning for using semicolons outside of class declarations.
Instance Attribute Summary
Attributes inherited from Warning
#body, #file, #line_number, #name, #severity
Instance Method Summary (collapse)
Methods inherited from FileWarning
Instance Method Details
- (Object) fix(body = self.body)
34 35 36 37 |
# File 'lib/laser/warnings/useless_double_quotes.rb', line 34 def fix(body = self.body) body.gsub("\"#{quoted_string}\"", "'#{quoted_string}'"). gsub("%Q{#{quoted_string}}", "%q{#{quoted_string}}") end |
- (Boolean) match?(body = self.body)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/laser/warnings/useless_double_quotes.rb', line 15 def match?(body = self.body) list = find_sexps(:string_content) list.map do |sym, *parts| next if parts.size != 1 # ignore multiparts as they're fine inner_sym, text, pos = parts.first # skip if the string has a backslash or an apostrophe in it. next unless inner_sym == :@tstring_content && text !~ /(\\)|(')/ previous_char = body.lines.to_a[pos[0] - 1][pos[1]-1,1] uses_q_braces = (previous_char == '{' && body.lines.to_a[pos[0] - 1][pos[1]-3,2] == '%Q') if previous_char == '"' || uses_q_braces warning = Laser::UselessDoubleQuotesWarning.new( file, body, quoted_string: text, uses_q_braces: uses_q_braces) warning.line_number = pos[0] warning end end.compact end |