@electron/lint-roller 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ import { addError, filterTokens } from 'markdownlint/helpers';
2
+
3
+ import { fromMarkdown } from 'mdast-util-from-markdown';
4
+ import { visit } from 'unist-util-visit';
5
+
6
+ export const names = ['EMD002', 'no-angle-brackets'];
7
+ export const description = 'No unescaped opening angle brackets in text (does not play nice with MDX)';
8
+ export const tags = ['brackets'];
9
+
10
+ const UNESCAPED_REGEX = /(?<!\\)<(?!\s)/g;
11
+
12
+ function EMD002(params, onError) {
13
+ filterTokens(params, 'inline', (token) => {
14
+ for (const childToken of token.children) {
15
+ // childToken.line has the raw content, but may also contain
16
+ // more content than just childToken.content. Since we need
17
+ // the raw content to detect escaped angle brackets, parse
18
+ // the raw content of any match a second time to avoid any
19
+ // false positives.
20
+ if (
21
+ childToken.type === 'text' &&
22
+ childToken.markup !== '&lt;' &&
23
+ childToken.markup !== '&#60;' &&
24
+ childToken.content.includes('<') &&
25
+ childToken.line.match(UNESCAPED_REGEX) !== null
26
+ ) {
27
+ // The AST produced by mdast is easier to work with here
28
+ // since it gives position data within the line
29
+ const tree = fromMarkdown(childToken.line);
30
+
31
+ visit(
32
+ tree,
33
+ (node) => node.type === 'text',
34
+ (node) => {
35
+ const rawContent = childToken.line.slice(node.position.start.offset, node.position.end.offset);
36
+
37
+ if (rawContent.match(UNESCAPED_REGEX) !== null) {
38
+ addError(onError, token.lineNumber, 'Unescaped opening angle bracket');
39
+ }
40
+ },
41
+ );
42
+ }
43
+ }
44
+ });
45
+ };
46
+
47
+ export { EMD002 as function };