Class: RemLint::Rules::TranslateCommand

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

Overview

TRANSLATE commands Remind will not accept, or will reject silently.

TRANSLATE has five forms and nothing else parses:

TRANSLATE "original" "translated"
TRANSLATE "original"            (removes one)
TRANSLATE CLEAR
TRANSLATE DUMP
TRANSLATE LOAD "file"

The bare-word forms are the ones that go wrong, because they are one forgotten pair of quotes away from being a translation of the literal string "CLEAR".

The other half is the one that matters to a translator. A translated string has to carry the same % escapes as the original, in the same order -- Remind compares them and refuses the translation outright if they differ. The message then stays in English, which looks like a missing translation rather than a rejected one.

Constant Summary collapse

BARE_WORDS =
%w[CLEAR DUMP].freeze
LOAD =
"LOAD"
ESCAPE =

%a, %*b, %<Header> and the rest -- anything the substitution filter would replace, which both sides have to agree on.

/%\*?(?:<[^>]*>|\{[^}]*\}|\([^)]*\)|.)/
STRING =
/\A\s*"(?:[^"\\]|\\.)*"/

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



37
38
39
# File 'lib/remlint/rules/translate_command.rb', line 37

def self.default_severity
  "warning"
end

.descriptionObject



41
42
43
# File 'lib/remlint/rules/translate_command.rb', line 41

def self.description
  "A TRANSLATE that is not one of Remind's five forms, or whose escapes do not match."
end

Instance Method Details

#checkObject



45
46
47
48
49
50
51
# File 'lib/remlint/rules/translate_command.rb', line 45

def check
  document.code_commands.each do |command|
    if command.keyword?("TRANSLATE")
      check_command(command)
    end
  end
end