Class: RemLint::Rules::StringEscape

Inherits:
RemLint::Rule show all
Defined in:
lib/remlint/rules/string_escape.rb

Overview

Backslash escapes in a string that are not escapes.

Remind's escape set is \a \b \f \n \r \t \v and \xHH. Anything else reaches a default: branch in src/expr.c that emits the character and drops the backslash -- so \q is q, silently, with no way to tell it from a q somebody meant to type.

\\ and \" go through that same default branch, which is exactly how they work, so neither is reported: writing them is the fix, not the fault.

\x00 is different, and is the one case Remind refuses outright: a NUL cannot appear inside a Remind string, and the parser says so.

Constant Summary collapse

DEFINED =

From the switch(**in) over escapes in src/expr.c.

%w[a b f n r t v x].freeze
LITERAL =

Handled by the default branch, and correct.

['\\', '"', "'"].freeze
ESCAPE =
/\\(?<body>x[0-9a-fA-F]{1,2}|.)/
NUL =
/\Ax0+\z/

Constants inherited from RemLint::Rule

RemLint::Rule::REGISTRY

Instance Attribute Summary

Attributes inherited from RemLint::Rule

#config, #document, #offenses

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemLint::Rule

all, enabled_by_default?, find, inherited, #initialize, rule_name, #rule_name, #run

Constructor Details

This class inherits a constructor from RemLint::Rule

Class Method Details

.default_severityObject



31
32
33
# File 'lib/remlint/rules/string_escape.rb', line 31

def self.default_severity
  "warning"
end

.descriptionObject



35
36
37
# File 'lib/remlint/rules/string_escape.rb', line 35

def self.description
  "A backslash escape Remind does not define, or the prohibited \\x00."
end

Instance Method Details

#checkObject



39
40
41
42
43
44
45
# File 'lib/remlint/rules/string_escape.rb', line 39

def check
  document.logical_lines.each_with_index do |logical_line, index|
    if document.commands[index].code?
      check_line(logical_line)
    end
  end
end