3
3
"use strict" ;
4
4
5
5
const { addError } = require ( "../helpers" ) ;
6
- const { addRangeToSet, filterByTypes } = require ( "../helpers/micromark.cjs" ) ;
6
+ const { addRangeToSet } = require ( "../helpers/micromark.cjs" ) ;
7
+ const { filterByTypesCached } = require ( "./cache" ) ;
7
8
8
9
// eslint-disable-next-line jsdoc/valid-types
9
10
/** @type import("./markdownlint").Rule */
@@ -17,17 +18,16 @@ module.exports = {
17
18
brSpaces = Number ( ( brSpaces === undefined ) ? 2 : brSpaces ) ;
18
19
const listItemEmptyLines = ! ! params . config . list_item_empty_lines ;
19
20
const strict = ! ! params . config . strict ;
20
- const { tokens } = params . parsers . micromark ;
21
21
const codeBlockLineNumbers = new Set ( ) ;
22
- for ( const codeBlock of filterByTypes ( tokens , [ "codeFenced" ] ) ) {
22
+ for ( const codeBlock of filterByTypesCached ( [ "codeFenced" ] ) ) {
23
23
addRangeToSet ( codeBlockLineNumbers , codeBlock . startLine + 1 , codeBlock . endLine - 1 ) ;
24
24
}
25
- for ( const codeBlock of filterByTypes ( tokens , [ "codeIndented" ] ) ) {
25
+ for ( const codeBlock of filterByTypesCached ( [ "codeIndented" ] ) ) {
26
26
addRangeToSet ( codeBlockLineNumbers , codeBlock . startLine , codeBlock . endLine ) ;
27
27
}
28
28
const listItemLineNumbers = new Set ( ) ;
29
29
if ( listItemEmptyLines ) {
30
- for ( const listBlock of filterByTypes ( tokens , [ "listOrdered" , "listUnordered" ] ) ) {
30
+ for ( const listBlock of filterByTypesCached ( [ "listOrdered" , "listUnordered" ] ) ) {
31
31
addRangeToSet ( listItemLineNumbers , listBlock . startLine , listBlock . endLine ) ;
32
32
let trailingIndent = true ;
33
33
for ( let i = listBlock . children . length - 1 ; i >= 0 ; i -- ) {
@@ -53,10 +53,10 @@ module.exports = {
53
53
const paragraphLineNumbers = new Set ( ) ;
54
54
const codeInlineLineNumbers = new Set ( ) ;
55
55
if ( strict ) {
56
- for ( const paragraph of filterByTypes ( tokens , [ "paragraph" ] ) ) {
56
+ for ( const paragraph of filterByTypesCached ( [ "paragraph" ] ) ) {
57
57
addRangeToSet ( paragraphLineNumbers , paragraph . startLine , paragraph . endLine - 1 ) ;
58
58
}
59
- for ( const codeText of filterByTypes ( tokens , [ "codeText" ] ) ) {
59
+ for ( const codeText of filterByTypesCached ( [ "codeText" ] ) ) {
60
60
addRangeToSet ( codeInlineLineNumbers , codeText . startLine , codeText . endLine - 1 ) ;
61
61
}
62
62
}
0 commit comments