Skip to content

Commit

Permalink
chore: add hardcoded _time values to name check
Browse files Browse the repository at this point in the history
Signed-off-by: Dustin Popp <[email protected]>
  • Loading branch information
dpopp07 committed Jan 6, 2025
1 parent 2ab9d95 commit 7bac905
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
17 changes: 12 additions & 5 deletions packages/ruleset/src/utils/date-based-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ function isDateBasedName(name) {
// Any name containing `_time_`.
/.*_time_.*/,

// Note: not including any name ending in `_time` because it was too easy
// to think of counterexamples. `running_time` in the "movies" API of our
// test document in this project is one of them.
// Not including any name ending in `_time` because there are
// counterexamples, but we still want to catch common date-based
// names that end in `_time`.
/^start_time$/,
/^end_time$/,
/^create_time$/,
/^created_time$/,
/^modify_time$/,
/^modified_time$/,
/^update_time$/,

// Any name containing `timestamp`.
/.*timestamp.*/,
Expand All @@ -72,10 +79,10 @@ function isDateBasedName(name) {
function isDateBasedValue(value) {
const regularExpressions = [
// Includes abbreviated month name.
/\b(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b/,
/^\b(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b/,

// Includes full month name.
/\b(January|February|March|April|May|June|July|August|September|October|November|December)\b/,
/^\b(January|February|March|April|May|June|July|August|September|October|November|December)\b/,

// Includes date in the format YYYY(./-)MM(./-)DD(T).
/\b\d{4}[./-](0?[1-9]|1[012])[./-]([012]?[1-9]|3[01])(\b|T)/,
Expand Down
17 changes: 10 additions & 7 deletions packages/ruleset/test/utils/date-based-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('Date-based utility functions', () => {

// Negative tests.
it('should return `false` for non-date time values', () => {
expect(isDateBasedValue('This certificate is good until June 2032')).toBe(
false
);
expect(isDateBasedValue('Octopus')).toBe(false);
expect(isDateBasedValue('12345678')).toBe(false);
expect(isDateBasedValue('0001-01-2000')).toBe(false);
Expand Down Expand Up @@ -56,19 +59,19 @@ describe('Date-based utility functions', () => {
expect(isDateBasedName('modified')).toBe(true);
expect(isDateBasedName('expired')).toBe(true);
expect(isDateBasedName('expires')).toBe(true);
// expect(isDateBasedName('start_time')).toBe(true);
expect(isDateBasedName('start_time')).toBe(true);
expect(isDateBasedName('start_date')).toBe(true);
// expect(isDateBasedName('end_time')).toBe(true);
expect(isDateBasedName('end_time')).toBe(true);
expect(isDateBasedName('end_date')).toBe(true);
// expect(isDateBasedName('create_time')).toBe(true);
expect(isDateBasedName('create_time')).toBe(true);
expect(isDateBasedName('create_date')).toBe(true);
// expect(isDateBasedName('created_time')).toBe(true);
expect(isDateBasedName('created_time')).toBe(true);
expect(isDateBasedName('created_date')).toBe(true);
// expect(isDateBasedName('modify_time')).toBe(true);
expect(isDateBasedName('modify_time')).toBe(true);
expect(isDateBasedName('modify_date')).toBe(true);
// expect(isDateBasedName('modified_time')).toBe(true);
expect(isDateBasedName('modified_time')).toBe(true);
expect(isDateBasedName('modified_date')).toBe(true);
// expect(isDateBasedName('update_time')).toBe(true);
expect(isDateBasedName('update_time')).toBe(true);
expect(isDateBasedName('update_date')).toBe(true);
});

Expand Down

0 comments on commit 7bac905

Please sign in to comment.