Class: RemLint::Rules::UnbalancedDelimiters

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

Overview

Brackets and parentheses that never close, or that close each other.

Remind has Missing ']' and Missing ')' (src/err.h E_MISS_END, E_MISS_RIGHT_PAREN), so this reports something Remind agrees is wrong -- it just reports it without running the file, and names the line the delimiter opened on rather than the line parsing gave up at.

Two asymmetries matter, and both come from Remind treating unbracketed text as text:

A CLOSER WITH NOTHING OPEN IS NOT AN ERROR. MSG See note ] prints a bracket. Reporting it would make the rule unusable on message bodies, which is most of what a reminder file is.

PARENTHESES ONLY COUNT INSIDE AN EXPRESSION. MSG Call (555) 1234 is text, not a call with a missing operand. So parentheses are tracked inside [...], and in the arguments of the commands whose arguments are expressions -- IF, SET, FSET and friends -- and nowhere else.

String literals are skipped, because the lexer already took them whole: the ] in MSG a "]" b is inside a string and closes nothing.

Constant Summary collapse

EXPRESSION_COMMANDS =

Commands whose arguments Remind evaluates as an expression, so that parentheses in them are syntax rather than punctuation.

%w[
  IF IFTRIG SET FSET OMITFUNC EXPR MAX-OVERDUE
].freeze
CLOSER_FOR =
{ lbracket: :rbracket, lparen: :rparen }.freeze
GLYPH =
{ lbracket: "[", rbracket: "]", lparen: "(", rparen: ")" }.freeze

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



38
39
40
# File 'lib/remlint/rules/unbalanced_delimiters.rb', line 38

def self.default_severity
  "error"
end

.descriptionObject



42
43
44
# File 'lib/remlint/rules/unbalanced_delimiters.rb', line 42

def self.description
  "Brackets and parentheses that are never closed, or that close each other."
end

Instance Method Details

#checkObject



46
47
48
49
50
51
52
53
54
# File 'lib/remlint/rules/unbalanced_delimiters.rb', line 46

def check
  document.logical_lines.each_with_index do |logical_line, index|
    command = document.commands[index]

    if command.code?
      check_line(logical_line, command)
    end
  end
end