Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions markdownlint-rules/emd002.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /(?<!\\)<(?!\s)/g;
Expand Down Expand Up @@ -32,16 +33,27 @@ function EMD002(params, onError) {
tree,
(node) => 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 };
19 changes: 14 additions & 5 deletions markdownlint-rules/emd003.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /(?<!\\){/g;
Expand All @@ -31,16 +32,24 @@ function EMD003(params, onError) {
tree,
(node) => 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 };
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions tests/__snapshots__/electron-markdownlint.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`electron-markdownlint should not allow opening angle brackets if EMD002 enabled 1`] = `
"<root>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]
<root>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]
<root>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]
"<root>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]
<root>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]
<root>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`] = `
"<root>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]
"<root>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]
"
`;