diff --git a/markdownlint-rules/emd002.mjs b/markdownlint-rules/emd002.mjs index 0d6da46..605acdd 100644 --- a/markdownlint-rules/emd002.mjs +++ b/markdownlint-rules/emd002.mjs @@ -4,7 +4,8 @@ import { fromMarkdown } from 'mdast-util-from-markdown'; import { visit } from 'unist-util-visit'; export const names = ['EMD002', 'no-angle-brackets']; -export const description = 'No unescaped opening angle brackets in text (does not play nice with MDX)'; +export const description = + 'No unescaped opening angle brackets in text (does not play nice with MDX)'; export const tags = ['brackets']; const UNESCAPED_REGEX = /(? node.type === 'text', (node) => { - const rawContent = childToken.line.slice(node.position.start.offset, node.position.end.offset); + const rawContent = childToken.line.slice( + node.position.start.offset, + node.position.end.offset, + ); - if (rawContent.match(UNESCAPED_REGEX) !== null) { - addError(onError, token.lineNumber, 'Unescaped opening angle bracket'); + const matches = rawContent.matchAll(UNESCAPED_REGEX); + + for (const match of matches) { + addError( + onError, + childToken.lineNumber, + 'Unescaped opening angle bracket', + undefined, + [node.position.start.offset + 1 + match.index, 1], + ); } }, ); } } }); -}; +} export { EMD002 as function }; diff --git a/markdownlint-rules/emd003.mjs b/markdownlint-rules/emd003.mjs index 51c44b4..8867895 100644 --- a/markdownlint-rules/emd003.mjs +++ b/markdownlint-rules/emd003.mjs @@ -4,7 +4,8 @@ import { fromMarkdown } from 'mdast-util-from-markdown'; import { visit } from 'unist-util-visit'; export const names = ['EMD003', 'no-curly-braces']; -export const description = 'No unescaped opening curly braces in text (does not play nice with MDX)'; +export const description = + 'No unescaped opening curly braces in text (does not play nice with MDX)'; export const tags = ['braces']; const UNESCAPED_REGEX = /(? node.type === 'text', (node) => { - const rawContent = childToken.line.slice(node.position.start.offset, node.position.end.offset); + const rawContent = childToken.line.slice( + node.position.start.offset, + node.position.end.offset, + ); - if (rawContent.match(UNESCAPED_REGEX) !== null) { - addError(onError, token.lineNumber, 'Unescaped opening curly brace'); + const matches = rawContent.matchAll(UNESCAPED_REGEX); + + for (const match of matches) { + addError(onError, childToken.lineNumber, 'Unescaped opening curly brace', undefined, [ + node.position.start.offset + 1 + match.index, + 1, + ]); } }, ); } } }); -}; +} export { EMD003 as function }; diff --git a/package.json b/package.json index ce878dd..4d654b4 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,11 @@ "build:emd002": "esbuild --platform=node --target=node18 --format=cjs --bundle --outfile=markdownlint-rules/emd002.js markdownlint-rules/emd002.mjs", "build:emd003": "esbuild --platform=node --target=node18 --format=cjs --bundle --outfile=markdownlint-rules/emd003.js markdownlint-rules/emd003.mjs", "prepublishOnly": "yarn run build", - "lint:eslint": "eslint \"{bin,lib,markdownlint-rules,tests}/**/*.{js,ts}\"", - "lint:eslint:fix": "eslint --fix \"{bin,lib,markdownlint-rules,tests}/**/*.{js,ts}\"", + "lint:eslint": "eslint \"{bin,lib,markdownlint-rules,tests}/**/*.{js,mjs,ts}\"", + "lint:eslint:fix": "eslint --fix \"{bin,lib,markdownlint-rules,tests}/**/*.{js,mjs,ts}\"", "lint:markdown": "yarn run build && node ./dist/bin/markdownlint-cli-wrapper.js \"*.md\" && node ./dist/bin/lint-markdown-links.js \"*.md\"", - "lint:prettier": "prettier --check \"{bin,lib,markdownlint-rules,tests}/**/*.{js,ts}\"", - "lint:prettier:fix": "prettier --write \"{bin,lib,markdownlint-rules,tests}/**/*.{js,ts}\"", + "lint:prettier": "prettier --check \"{bin,lib,markdownlint-rules,tests}/**/*.{js,mjs,ts}\"", + "lint:prettier:fix": "prettier --write \"{bin,lib,markdownlint-rules,tests}/**/*.{js,mjs,ts}\"", "lint": "yarn run lint:prettier && yarn run lint:markdown", "lint:fix": "yarn run lint:eslint:fix && yarn run lint:prettier:fix", "test": "yarn run build && jest" diff --git a/tests/__snapshots__/electron-markdownlint.spec.ts.snap b/tests/__snapshots__/electron-markdownlint.spec.ts.snap index 5c4181e..7eed76b 100644 --- a/tests/__snapshots__/electron-markdownlint.spec.ts.snap +++ b/tests/__snapshots__/electron-markdownlint.spec.ts.snap @@ -1,13 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`electron-markdownlint should not allow opening angle brackets if EMD002 enabled 1`] = ` -"angle-brackets.md:3 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] -angle-brackets.md:9 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] -angle-brackets.md:127 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] +"angle-brackets.md:3:13 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] +angle-brackets.md:9:16 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] +angle-brackets.md:127:21 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] " `; exports[`electron-markdownlint should not allow opening curly braces if EMD003 enabled 1`] = ` -"curly-braces.md:1 EMD003/no-curly-braces No unescaped opening curly braces in text (does not play nice with MDX) [Unescaped opening curly brace] +"curly-braces.md:6:1 EMD003/no-curly-braces No unescaped opening curly braces in text (does not play nice with MDX) [Unescaped opening curly brace] " `;