1+ // @ts -ignore - markdownlint-rule-helpers doesn't provide TypeScript declarations
12import { addError , newLineRe } from 'markdownlint-rule-helpers'
23
4+ import type { RuleParams , RuleErrorCallback , MarkdownToken , Rule } from '@/content-linter/types'
5+
36// This rule looks for opening and closing HTML comment tags that
47// contain an expiration date in the format:
58//
@@ -8,20 +11,20 @@ import { addError, newLineRe } from 'markdownlint-rule-helpers'
811//
912// The `end expires` closing tag closes the content that is expired
1013// and must be removed.
11- export const expiredContent = {
14+ export const expiredContent : Rule = {
1215 names : [ 'GHD038' , 'expired-content' ] ,
1316 description : 'Expired content must be remediated.' ,
1417 tags : [ 'expired' ] ,
15- function : ( params , onError ) => {
16- const tokensToCheck = params . tokens . filter (
17- ( token ) => token . type === 'inline' || token . type === 'html_block' ,
18+ function : ( params : RuleParams , onError : RuleErrorCallback ) => {
19+ const tokensToCheck = ( params . tokens || [ ] ) . filter (
20+ ( token : MarkdownToken ) => token . type === 'inline' || token . type === 'html_block' ,
1821 )
1922
20- tokensToCheck . forEach ( ( token ) => {
23+ tokensToCheck . forEach ( ( token : MarkdownToken ) => {
2124 // Looking for just opening tag with format:
2225 // <!-- expires yyyy-mm-dd -->
23- const match = token . content . match ( / < ! - - \s * e x p i r e s \s ( \d \d \d \d ) - ( \d \d ) - ( \d \d ) \s * - - > / )
24- if ( ! match ) return
26+ const match = token . content ? .match ( / < ! - - \s * e x p i r e s \s ( \d \d \d \d ) - ( \d \d ) - ( \d \d ) \s * - - > / )
27+ if ( ! match || ! token . content ) return
2528
2629 const expireDate = new Date ( match . splice ( 1 , 3 ) . join ( ' ' ) )
2730 const today = new Date ( )
@@ -57,20 +60,20 @@ export const DAYS_TO_WARN_BEFORE_EXPIRED = 14
5760//
5861// The `end expires` closing tag closes the content that is expired
5962// and must be removed.
60- export const expiringSoon = {
63+ export const expiringSoon : Rule = {
6164 names : [ 'GHD039' , 'expiring-soon' ] ,
6265 description : 'Content that expires soon should be proactively addressed.' ,
6366 tags : [ 'expired' ] ,
64- function : ( params , onError ) => {
65- const tokensToCheck = params . tokens . filter (
66- ( token ) => token . type === 'inline' || token . type === 'html_block' ,
67+ function : ( params : RuleParams , onError : RuleErrorCallback ) => {
68+ const tokensToCheck = ( params . tokens || [ ] ) . filter (
69+ ( token : MarkdownToken ) => token . type === 'inline' || token . type === 'html_block' ,
6770 )
6871
69- tokensToCheck . forEach ( ( token ) => {
72+ tokensToCheck . forEach ( ( token : MarkdownToken ) => {
7073 // Looking for just opening tag with format:
7174 // <!-- expires yyyy-mm-dd -->
72- const match = token . content . match ( / < ! - - \s * e x p i r e s \s ( \d \d \d \d ) - ( \d \d ) - ( \d \d ) \s * - - > / )
73- if ( ! match ) return
75+ const match = token . content ? .match ( / < ! - - \s * e x p i r e s \s ( \d \d \d \d ) - ( \d \d ) - ( \d \d ) \s * - - > / )
76+ if ( ! match || ! token . content ) return
7477
7578 const expireDate = new Date ( match . splice ( 1 , 3 ) . join ( ' ' ) )
7679 const today = new Date ( )
0 commit comments