eslint-markdown 0.12.0 → 0.12.1
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.
- package/build/core/utils/index.d.ts +2 -1
- package/build/core/utils/index.js +2 -1
- package/build/core/utils/test-regex-stateless.d.ts +10 -0
- package/build/core/utils/test-regex-stateless.js +21 -0
- package/build/rules/allow-heading.js +1 -12
- package/build/rules/allow-image-url.js +3 -3
- package/build/rules/allow-link-url.js +3 -3
- package/package.json +1 -1
|
@@ -2,4 +2,5 @@ import escapeStringRegexp from './escape-string-regexp.js';
|
|
|
2
2
|
import getElementsByTagName from './html.js';
|
|
3
3
|
import isBlankLine from './is-blank-line.js';
|
|
4
4
|
import SkipRanges from './skip-ranges.js';
|
|
5
|
-
|
|
5
|
+
import testRegexStateless from './test-regex-stateless.js';
|
|
6
|
+
export { escapeStringRegexp, getElementsByTagName, isBlankLine, SkipRanges, testRegexStateless, };
|
|
@@ -2,4 +2,5 @@ import escapeStringRegexp from './escape-string-regexp.js';
|
|
|
2
2
|
import getElementsByTagName from './html.js';
|
|
3
3
|
import isBlankLine from './is-blank-line.js';
|
|
4
4
|
import SkipRanges from './skip-ranges.js';
|
|
5
|
-
|
|
5
|
+
import testRegexStateless from './test-regex-stateless.js';
|
|
6
|
+
export { escapeStringRegexp, getElementsByTagName, isBlankLine, SkipRanges, testRegexStateless, };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Utility to test a regular expression without mutating its state.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Tests a regex without mutating the state stored in its `lastIndex`.
|
|
6
|
+
* @param regex Regex to test.
|
|
7
|
+
* @param text Text to test.
|
|
8
|
+
* @returns Whether the regex matches the text.
|
|
9
|
+
*/
|
|
10
|
+
export default function testRegexStateless(regex: RegExp, text: string): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Utility to test a regular expression without mutating its state.
|
|
3
|
+
*/
|
|
4
|
+
// --------------------------------------------------------------------------------
|
|
5
|
+
// Helper
|
|
6
|
+
// --------------------------------------------------------------------------------
|
|
7
|
+
const statefulRegexFlagRegex = /[gy]/u;
|
|
8
|
+
// --------------------------------------------------------------------------------
|
|
9
|
+
// Export
|
|
10
|
+
// --------------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* Tests a regex without mutating the state stored in its `lastIndex`.
|
|
13
|
+
* @param regex Regex to test.
|
|
14
|
+
* @param text Text to test.
|
|
15
|
+
* @returns Whether the regex matches the text.
|
|
16
|
+
*/
|
|
17
|
+
export default function testRegexStateless(regex, text) {
|
|
18
|
+
return statefulRegexFlagRegex.test(regex.flags)
|
|
19
|
+
? new RegExp(regex).test(text)
|
|
20
|
+
: regex.test(text);
|
|
21
|
+
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @fileoverview Rule to enforce the use of allowed or disallowed headings.
|
|
3
3
|
* @author lumir(lumirlumir)
|
|
4
4
|
*/
|
|
5
|
+
import { testRegexStateless } from '../core/utils/index.js';
|
|
5
6
|
import { URL_RULE_DOCS } from '../core/constants.js';
|
|
6
7
|
// --------------------------------------------------------------------------------
|
|
7
8
|
// Helper
|
|
8
9
|
// --------------------------------------------------------------------------------
|
|
9
|
-
const statefulRegexFlagRegex = /[gy]/u;
|
|
10
10
|
const headingOptionsSchema = {
|
|
11
11
|
type: 'object',
|
|
12
12
|
properties: {
|
|
@@ -27,17 +27,6 @@ const headingOptionsSchema = {
|
|
|
27
27
|
},
|
|
28
28
|
additionalProperties: false,
|
|
29
29
|
};
|
|
30
|
-
/**
|
|
31
|
-
* Tests a regex without mutating the state stored in its `lastIndex`.
|
|
32
|
-
* @param regex Regex to test.
|
|
33
|
-
* @param text Text to test.
|
|
34
|
-
* @returns Whether the regex matches the text.
|
|
35
|
-
*/
|
|
36
|
-
function testRegexStateless(regex, text) {
|
|
37
|
-
return statefulRegexFlagRegex.test(regex.flags)
|
|
38
|
-
? new RegExp(regex).test(text)
|
|
39
|
-
: regex.test(text);
|
|
40
|
-
}
|
|
41
30
|
// --------------------------------------------------------------------------------
|
|
42
31
|
// Rule Definition
|
|
43
32
|
// --------------------------------------------------------------------------------
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @author lumir(lumirlumir)
|
|
4
4
|
*/
|
|
5
5
|
import { normalizeIdentifier } from 'micromark-util-normalize-identifier';
|
|
6
|
-
import { getElementsByTagName } from '../core/utils/index.js';
|
|
6
|
+
import { getElementsByTagName, testRegexStateless } from '../core/utils/index.js';
|
|
7
7
|
import { URL_RULE_DOCS } from '../core/constants.js';
|
|
8
8
|
// --------------------------------------------------------------------------------
|
|
9
9
|
// Rule Definition
|
|
@@ -114,7 +114,7 @@ export default {
|
|
|
114
114
|
* Therefore, calling the `some` method on an empty array will always return `false`.
|
|
115
115
|
*/
|
|
116
116
|
for (const { loc, url } of images) {
|
|
117
|
-
if (!allowUrls.some(regex => regex
|
|
117
|
+
if (!allowUrls.some(regex => testRegexStateless(regex, url))) {
|
|
118
118
|
context.report({
|
|
119
119
|
loc,
|
|
120
120
|
messageId: 'allowImageUrl',
|
|
@@ -124,7 +124,7 @@ export default {
|
|
|
124
124
|
},
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
|
-
if (disallowUrls.some(regex => regex
|
|
127
|
+
if (disallowUrls.some(regex => testRegexStateless(regex, url))) {
|
|
128
128
|
context.report({
|
|
129
129
|
loc,
|
|
130
130
|
messageId: 'disallowImageUrl',
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @author lumir(lumirlumir)
|
|
4
4
|
*/
|
|
5
5
|
import { normalizeIdentifier } from 'micromark-util-normalize-identifier';
|
|
6
|
-
import { getElementsByTagName } from '../core/utils/index.js';
|
|
6
|
+
import { getElementsByTagName, testRegexStateless } from '../core/utils/index.js';
|
|
7
7
|
import { URL_RULE_DOCS } from '../core/constants.js';
|
|
8
8
|
// --------------------------------------------------------------------------------
|
|
9
9
|
// Rule Definition
|
|
@@ -114,7 +114,7 @@ export default {
|
|
|
114
114
|
* Therefore, calling the `some` method on an empty array will always return `false`.
|
|
115
115
|
*/
|
|
116
116
|
for (const { loc, url } of links) {
|
|
117
|
-
if (!allowUrls.some(regex => regex
|
|
117
|
+
if (!allowUrls.some(regex => testRegexStateless(regex, url))) {
|
|
118
118
|
context.report({
|
|
119
119
|
loc,
|
|
120
120
|
messageId: 'allowLinkUrl',
|
|
@@ -124,7 +124,7 @@ export default {
|
|
|
124
124
|
},
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
|
-
if (disallowUrls.some(regex => regex
|
|
127
|
+
if (disallowUrls.some(regex => testRegexStateless(regex, url))) {
|
|
128
128
|
context.report({
|
|
129
129
|
loc,
|
|
130
130
|
messageId: 'disallowLinkUrl',
|