Class: RemLint::Rules::DateOutOfRange

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

Overview

Dates outside the range Remind can represent.

Remind counts days from BASE, which is 1990, and represents YR_RANGE years, which is 4000 (src/custom.h.in). So 1990-01-01 to 5990-12-31 is not a policy, it is the type. A date below the floor cannot be stored at all.

Three of the book's rules asked for a slice of this each -- TriggerComponentRange, DateConstantBeforeEpoch, DateOutsideRepresentableRange -- and Appendix B's own note suggested collecting them. One rule keeps the message identical wherever the date was written.

Two shapes are checked: a spelled-out date in a trigger, and a single-quoted date constant in an expression. A day of 32 or a month nobody has is caught by the same walk.

Constant Summary collapse

FIRST_YEAR =
DateLiteral::EPOCH_YEAR
LAST_YEAR =
DateLiteral::LAST_YEAR
CONSTANT =

'1970-01-01', '2027-13-01' -- a date constant, which the lexer hands over whole.

%r{\A'(?<year>\d{4})[-/](?<month>\d{1,2})[-/](?<day>\d{1,2})}
DAYS_IN_MONTH =
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].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



34
35
36
# File 'lib/remlint/rules/date_out_of_range.rb', line 34

def self.default_severity
  "error"
end

.descriptionObject



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

def self.description
  "A date outside 1990-01-01 to 5990-12-31, or with an impossible component."
end

Instance Method Details

#checkObject



42
43
44
45
46
47
48
# File 'lib/remlint/rules/date_out_of_range.rb', line 42

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