Class: RemLint::Rules::ColorComponentRange
- Inherits:
-
RemLint::Rule
- Object
- RemLint::Rule
- RemLint::Rules::ColorComponentRange
- Defined in:
- lib/remlint/rules/color_component_range.rb
Overview
Colour components outside 0-255.
Remind rejects them -- if (r > 255 || g > 255 || b > 255) return E_2HIGH
in src/funcs.c for ansicolor, and the same bound in src/var.c for
$DefaultColor -- but only when the line runs, and rem2ps silently
clamps instead (src/rem2ps.c). A component typed as 2555 therefore
renders as something plausible in one output mode and fails in another,
which is the worst way for a mistake to behave.
Three places carry components, and all three are hand-typed integers in practice, which is exactly when a linter can help:
SPECIAL COLOR r g b <text> examples/astro has sixteen of these
SPECIAL SHADE r g b tests/shade.rem has one per weekday
[ansicolor(r, g, b)] examples/ansitext, examples/alignment
ansicolor also takes a one-argument form (ansicolor(""), the reset)
and an optional fourth background flag; only the three components are
range-checked, and only when they are literal integers.
Constant Summary collapse
- MINIMUM =
0- MAXIMUM =
255- SPECIAL_KINDS =
COLOR, and the spelling Remind also accepts. %w[COLOR COLOUR SHADE].freeze
- SPECIAL =
SPECIAL COLOR 255 128 0 rest...-- three integers after the keyword. /\A(?<kind>[A-Za-z]+)\s+(?<r>-?\d+)\s+(?<g>-?\d+)\s+(?<b>-?\d+)\b/- CHANNELS =
%w[red green blue].freeze
Constants inherited from RemLint::Rule
Instance Attribute Summary
Attributes inherited from RemLint::Rule
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_severity ⇒ Object
38 39 40 |
# File 'lib/remlint/rules/color_component_range.rb', line 38 def self.default_severity "error" end |
.description ⇒ Object
42 43 44 |
# File 'lib/remlint/rules/color_component_range.rb', line 42 def self.description "Colour components outside the 0-255 Remind accepts." end |
Instance Method Details
#check ⇒ Object
46 47 48 49 50 51 |
# File 'lib/remlint/rules/color_component_range.rb', line 46 def check document.code_commands.each do |command| check_special(command) check_ansicolor(command) end end |