1+ // @ts -ignore - markdownlint-rule-helpers doesn't have TypeScript declarations
12import { filterTokens } from 'markdownlint-rule-helpers'
23
34import { addFixErrorDetail , getRange } from '../helpers/utils'
45import { allLanguageKeys } from '@/languages/lib/languages'
6+ import type { RuleParams , RuleErrorCallback , Rule } from '../../types'
57
6- export const internalLinksNoLang = {
8+ export const internalLinksNoLang : Rule = {
79 names : [ 'GHD002' , 'internal-links-no-lang' ] ,
810 description : 'Internal links must not have a hardcoded language code' ,
911 tags : [ 'links' , 'url' ] ,
1012 parser : 'markdownit' ,
11- function : ( params , onError ) => {
12- filterTokens ( params , 'inline' , ( token ) => {
13+ function : ( params : RuleParams , onError : RuleErrorCallback ) => {
14+ // Using 'any' type for token as markdownlint-rule-helpers doesn't provide TypeScript types
15+ filterTokens ( params , 'inline' , ( token : any ) => {
1316 for ( const child of token . children ) {
1417 if ( child . type !== 'link_open' ) continue
1518
@@ -18,14 +21,17 @@ export const internalLinksNoLang = {
1821 // ['href', 'get-started'], ['target', '_blank'],
1922 // ['rel', 'canonical'],
2023 // ]
24+ // Attribute arrays are tuples of [attributeName, attributeValue] from markdownit parser
2125 const hrefsMissingSlashes = child . attrs
2226 // The attribute could also be `target` or `rel`
23- . filter ( ( attr ) => attr [ 0 ] === 'href' )
24- . filter ( ( attr ) => attr [ 1 ] . startsWith ( '/' ) || ! attr [ 1 ] . startsWith ( '//' ) )
27+ . filter ( ( attr : [ string , string ] ) => attr [ 0 ] === 'href' )
28+ . filter ( ( attr : [ string , string ] ) => attr [ 1 ] . startsWith ( '/' ) || ! attr [ 1 ] . startsWith ( '//' ) )
2529 // Filter out link paths that start with language code
26- . filter ( ( attr ) => allLanguageKeys . some ( ( lang ) => attr [ 1 ] . split ( '/' ) [ 1 ] === lang ) )
30+ . filter ( ( attr : [ string , string ] ) =>
31+ allLanguageKeys . some ( ( lang ) => attr [ 1 ] . split ( '/' ) [ 1 ] === lang ) ,
32+ )
2733 // Get the link path from the attribute
28- . map ( ( attr ) => attr [ 1 ] )
34+ . map ( ( attr : [ string , string ] ) => attr [ 1 ] )
2935 // Create errors for each link path that includes a language code
3036 for ( const linkPath of hrefsMissingSlashes ) {
3137 const range = getRange ( child . line , linkPath )
0 commit comments