eslint-markdown 0.6.1 → 0.8.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.
package/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # eslint-markdown
2
2
 
3
- [![lint](https://img.shields.io/github/actions/workflow/status/lumirlumir/npm-eslint-markdown/lint.yml?label=lint&color=6358d4&labelColor=333333&logo=github)](https://github.com/lumirlumir/npm-eslint-markdown/actions/workflows/lint.yml)
3
+ [![ci](https://img.shields.io/github/actions/workflow/status/lumirlumir/npm-eslint-markdown/ci.yml?label=ci&color=6358d4&labelColor=333333&logo=github)](https://github.com/lumirlumir/npm-eslint-markdown/actions/workflows/ci.yml)
4
4
  [![test](https://img.shields.io/github/actions/workflow/status/lumirlumir/npm-eslint-markdown/test.yml?label=test&color=6358d4&labelColor=333333&logo=github)](https://github.com/lumirlumir/npm-eslint-markdown/actions/workflows/test.yml)
5
- [![test-cross-platform](https://img.shields.io/github/actions/workflow/status/lumirlumir/npm-eslint-markdown/test-cross-platform.yml?label=test-cross-platform&color=6358d4&labelColor=333333&logo=github)](https://github.com/lumirlumir/npm-eslint-markdown/actions/workflows/test-cross-platform.yml)
6
5
  [![codecov](https://img.shields.io/codecov/c/gh/lumirlumir/npm-eslint-markdown?token=LJMUst9eR3&label=Codecov&color=6358d4&labelColor=333333&logo=codecov)](https://codecov.io/gh/lumirlumir/npm-eslint-markdown)
7
6
  ![Node Current](https://img.shields.io/node/v/eslint-markdown?color=6358d4&labelColor=333333&logo=node.js)
8
7
 
@@ -26,6 +26,7 @@ export default function all(plugin: ESLint.Plugin): {
26
26
  readonly 'md/consistent-unordered-list-style': "error";
27
27
  readonly 'md/no-control-character': "error";
28
28
  readonly 'md/no-curly-quote': "error";
29
+ readonly 'md/no-double-punctuation': "error";
29
30
  readonly 'md/no-double-space': "error";
30
31
  readonly 'md/no-emoji': "error";
31
32
  readonly 'md/no-git-conflict-marker': "error";
@@ -11,8 +11,9 @@ declare const _default: {
11
11
  'consistent-unordered-list-style': import("../core/types.js").RuleModule<import("./consistent-unordered-list-style.js").RuleOptions, "style">;
12
12
  'no-control-character': import("../core/types.js").RuleModule<import("./no-control-character.js").RuleOptions, "noControlCharacter">;
13
13
  'no-curly-quote': import("../core/types.js").RuleModule<import("./no-curly-quote.js").RuleOptions, "noCurlyQuote">;
14
+ 'no-double-punctuation': import("../core/types.js").RuleModule<import("./no-double-punctuation.js").RuleOptions, "noDoublePunctuation">;
14
15
  'no-double-space': import("../core/types.js").RuleModule<import("./no-double-space.js").RuleOptions, import("./no-double-space.js").MessageIds>;
15
- 'no-emoji': import("../core/types.js").RuleModule<[], "noEmoji">;
16
+ 'no-emoji': import("../core/types.js").RuleModule<import("./no-emoji.js").RuleOptions, "noEmoji">;
16
17
  'no-git-conflict-marker': import("../core/types.js").RuleModule<import("./no-git-conflict-marker.js").RuleOptions, "noGitConflictMarker">;
17
18
  'no-irregular-dash': import("../core/types.js").RuleModule<import("./no-irregular-dash.js").RuleOptions, "noIrregularDash">;
18
19
  'no-irregular-whitespace': import("../core/types.js").RuleModule<import("./no-irregular-whitespace.js").RuleOptions, "noIrregularWhitespace">;
@@ -0,0 +1,49 @@
1
+ declare const _default: {
2
+ meta: {
3
+ type: "problem";
4
+ docs: {
5
+ description: string;
6
+ url: string;
7
+ recommended: boolean;
8
+ stylistic: false;
9
+ };
10
+ schema: {
11
+ type: "object";
12
+ properties: {
13
+ allow: {
14
+ type: "array";
15
+ items: {
16
+ type: "string";
17
+ minLength: number;
18
+ maxLength: number;
19
+ pattern: string;
20
+ };
21
+ uniqueItems: true;
22
+ };
23
+ };
24
+ additionalProperties: false;
25
+ }[];
26
+ defaultOptions: [{
27
+ allow: never[];
28
+ }];
29
+ messages: {
30
+ noDoublePunctuation: string;
31
+ };
32
+ language: string;
33
+ dialects: string[];
34
+ };
35
+ create(context: import("@eslint/core").RuleContext<{
36
+ LangOptions: import("@eslint/markdown").MarkdownLanguageOptions;
37
+ Code: import("@eslint/markdown").MarkdownSourceCode;
38
+ RuleOptions: RuleOptions;
39
+ Node: import("mdast").Node;
40
+ MessageIds: "noDoublePunctuation";
41
+ }>): {
42
+ text(node: import("mdast").Text): void;
43
+ };
44
+ };
45
+ export default _default;
46
+ export type RuleOptions = [{
47
+ allow: string[];
48
+ }];
49
+ export type MessageIds = "noDoublePunctuation";
@@ -7,6 +7,22 @@ declare const _default: {
7
7
  recommended: boolean;
8
8
  stylistic: false;
9
9
  };
10
+ schema: {
11
+ type: "object";
12
+ properties: {
13
+ allow: {
14
+ type: "array";
15
+ items: {
16
+ type: "string";
17
+ };
18
+ uniqueItems: true;
19
+ };
20
+ };
21
+ additionalProperties: false;
22
+ }[];
23
+ defaultOptions: [{
24
+ allow: never[];
25
+ }];
10
26
  messages: {
11
27
  noEmoji: string;
12
28
  };
@@ -16,7 +32,7 @@ declare const _default: {
16
32
  create(context: import("@eslint/core").RuleContext<{
17
33
  LangOptions: import("@eslint/markdown").MarkdownLanguageOptions;
18
34
  Code: import("@eslint/markdown").MarkdownSourceCode;
19
- RuleOptions: [];
35
+ RuleOptions: RuleOptions;
20
36
  Node: import("mdast").Node;
21
37
  MessageIds: "noEmoji";
22
38
  }>): {
@@ -24,5 +40,7 @@ declare const _default: {
24
40
  };
25
41
  };
26
42
  export default _default;
27
- export type RuleOptions = [];
43
+ export type RuleOptions = [{
44
+ allow: string[];
45
+ }];
28
46
  export type MessageIds = "noEmoji";
@@ -7,6 +7,7 @@ declare const _default: {
7
7
  recommended: boolean;
8
8
  stylistic: false;
9
9
  };
10
+ fixable: "code";
10
11
  schema: {
11
12
  type: "object";
12
13
  properties: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-markdown",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "description": "Lint your Markdown with ESLint.🛠️",
6
6
  "exports": {
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "scripts": {
61
61
  "prepublishOnly": "npm run build",
62
- "build": "node ../../scripts/build-config.mjs && npx tsc && node ../../scripts/cp.mjs ../../LICENSE.md LICENSE.md ../../README.md README.md",
62
+ "build": "node ../../scripts/build-config.js && tsc && node ../../scripts/cp.js ../../LICENSE.md LICENSE.md ../../README.md README.md",
63
63
  "test": "npm run test:types && npm run test:unit",
64
64
  "test:types": "tsc -p ./tsconfig.test.json",
65
65
  "test:unit": "node --test"
@@ -75,7 +75,7 @@
75
75
  "dependencies": {
76
76
  "@eslint/markdown": "^7.5.1",
77
77
  "micromark-util-normalize-identifier": "^2.0.1",
78
- "parse5": "^8.0.0"
78
+ "parse5": "^8.0.1"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@types/mdast": "^4.0.4",
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @fileoverview `all` configuration.
3
- * WARNING: This file is autogenerated using the `scripts/build-config.mjs`
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
4
4
  */
5
5
 
6
6
  // --------------------------------------------------------------------------------
@@ -50,6 +50,7 @@ export default function all(plugin) {
50
50
  'md/consistent-unordered-list-style': 'error',
51
51
  'md/no-control-character': 'error',
52
52
  'md/no-curly-quote': 'error',
53
+ 'md/no-double-punctuation': 'error',
53
54
  'md/no-double-space': 'error',
54
55
  'md/no-emoji': 'error',
55
56
  'md/no-git-conflict-marker': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @fileoverview `base` configuration.
3
- * WARNING: This file is autogenerated using the `scripts/build-config.mjs`
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
4
4
  */
5
5
 
6
6
  // --------------------------------------------------------------------------------
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @fileoverview `recommended` configuration.
3
- * WARNING: This file is autogenerated using the `scripts/build-config.mjs`
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
4
4
  */
5
5
 
6
6
  // --------------------------------------------------------------------------------
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @fileoverview `stylistic` configuration.
3
- * WARNING: This file is autogenerated using the `scripts/build-config.mjs`
3
+ * WARNING: This file is autogenerated using the `scripts/build-config.js`
4
4
  */
5
5
 
6
6
  // --------------------------------------------------------------------------------
@@ -18,6 +18,7 @@ import consistentUnorderedListStyle from './consistent-unordered-list-style.js';
18
18
  // import noBoldParagraph from './no-bold-paragraph.js';
19
19
  import noControlCharacter from './no-control-character.js';
20
20
  import noCurlyQuote from './no-curly-quote.js';
21
+ import noDoublePunctuation from './no-double-punctuation.js';
21
22
  import noDoubleSpace from './no-double-space.js';
22
23
  import noEmoji from './no-emoji.js';
23
24
  import noGitConflictMarker from './no-git-conflict-marker.js';
@@ -45,6 +46,7 @@ export default {
45
46
  // 'no-bold-paragraph': noBoldParagraph,
46
47
  'no-control-character': noControlCharacter,
47
48
  'no-curly-quote': noCurlyQuote,
49
+ 'no-double-punctuation': noDoublePunctuation,
48
50
  'no-double-space': noDoubleSpace,
49
51
  'no-emoji': noEmoji,
50
52
  'no-git-conflict-marker': noGitConflictMarker,
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @fileoverview Rule to disallow double consecutive punctuation in text.
3
+ * @author 루밀LuMir(lumirlumir)
4
+ */
5
+
6
+ // --------------------------------------------------------------------------------
7
+ // Import
8
+ // --------------------------------------------------------------------------------
9
+
10
+ import { URL_RULE_DOCS } from '../core/constants.js';
11
+
12
+ // --------------------------------------------------------------------------------
13
+ // Typedef
14
+ // --------------------------------------------------------------------------------
15
+
16
+ /**
17
+ * @import { RuleModule } from '../core/types.js';
18
+ * @typedef {[{ allow: string[] }]} RuleOptions
19
+ * @typedef {'noDoublePunctuation'} MessageIds
20
+ */
21
+
22
+ // --------------------------------------------------------------------------------
23
+ // Helper
24
+ // --------------------------------------------------------------------------------
25
+
26
+ /**
27
+ * This pattern is based on the punctuation list used by `remark-lint`.
28
+ * @see https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-heading-punctuation#parameters
29
+ */
30
+ const doublePunctuationRegex = /(?:^|(?<=[^!,.:;?]))[!,.:;?]{2}(?:$|(?=[^!,.:;?]))/g;
31
+
32
+ // --------------------------------------------------------------------------------
33
+ // Rule Definition
34
+ // --------------------------------------------------------------------------------
35
+
36
+ /** @type {RuleModule<RuleOptions, MessageIds>} */
37
+ export default {
38
+ meta: {
39
+ type: 'problem',
40
+
41
+ docs: {
42
+ description: 'Disallow double consecutive punctuation in text',
43
+ url: URL_RULE_DOCS('no-double-punctuation'),
44
+ recommended: false,
45
+ stylistic: false,
46
+ },
47
+
48
+ schema: [
49
+ {
50
+ type: 'object',
51
+ properties: {
52
+ allow: {
53
+ type: 'array',
54
+ items: {
55
+ type: 'string',
56
+ minLength: 2,
57
+ maxLength: 2,
58
+ pattern: '^[!,.:;?]{2}$',
59
+ },
60
+ uniqueItems: true,
61
+ },
62
+ },
63
+ additionalProperties: false,
64
+ },
65
+ ],
66
+
67
+ defaultOptions: [
68
+ {
69
+ allow: [],
70
+ },
71
+ ],
72
+
73
+ messages: {
74
+ noDoublePunctuation: 'Double punctuation mark `{{ punctuation }}` is not allowed.',
75
+ },
76
+
77
+ language: 'markdown',
78
+
79
+ dialects: ['commonmark', 'gfm'],
80
+ },
81
+
82
+ create(context) {
83
+ const { sourceCode } = context;
84
+ const [{ allow }] = context.options;
85
+
86
+ return {
87
+ text(node) {
88
+ const [nodeStartOffset] = sourceCode.getRange(node);
89
+ const matches = sourceCode.getText(node).matchAll(doublePunctuationRegex);
90
+
91
+ for (const match of matches) {
92
+ const punctuation = match[0];
93
+
94
+ const startOffset = nodeStartOffset + match.index;
95
+ const endOffset = startOffset + punctuation.length;
96
+
97
+ if (allow.includes(punctuation)) continue;
98
+
99
+ context.report({
100
+ loc: {
101
+ start: sourceCode.getLocFromIndex(startOffset),
102
+ end: sourceCode.getLocFromIndex(endOffset),
103
+ },
104
+
105
+ data: {
106
+ punctuation,
107
+ },
108
+
109
+ messageId: 'noDoublePunctuation',
110
+ });
111
+ }
112
+ },
113
+ };
114
+ },
115
+ };
@@ -15,7 +15,7 @@ import { URL_RULE_DOCS } from '../core/constants.js';
15
15
 
16
16
  /**
17
17
  * @import { RuleModule } from '../core/types.js';
18
- * @typedef {[]} RuleOptions
18
+ * @typedef {[{ allow: string[] }]} RuleOptions
19
19
  * @typedef {'noEmoji'} MessageIds
20
20
  */
21
21
 
@@ -41,6 +41,28 @@ export default {
41
41
  stylistic: false,
42
42
  },
43
43
 
44
+ schema: [
45
+ {
46
+ type: 'object',
47
+ properties: {
48
+ allow: {
49
+ type: 'array',
50
+ items: {
51
+ type: 'string',
52
+ },
53
+ uniqueItems: true,
54
+ },
55
+ },
56
+ additionalProperties: false,
57
+ },
58
+ ],
59
+
60
+ defaultOptions: [
61
+ {
62
+ allow: [],
63
+ },
64
+ ],
65
+
44
66
  messages: {
45
67
  noEmoji: 'Emojis are not allowed.',
46
68
  },
@@ -52,6 +74,7 @@ export default {
52
74
 
53
75
  create(context) {
54
76
  const { sourceCode } = context;
77
+ const [{ allow }] = context.options;
55
78
 
56
79
  return {
57
80
  text(node) {
@@ -59,8 +82,12 @@ export default {
59
82
  const matches = sourceCode.getText(node).matchAll(emojiRegex);
60
83
 
61
84
  for (const match of matches) {
85
+ const emoji = match[0];
86
+
87
+ if (allow.includes(emoji)) continue;
88
+
62
89
  const startOffset = nodeStartOffset + match.index;
63
- const endOffset = startOffset + match[0].length;
90
+ const endOffset = startOffset + emoji.length;
64
91
 
65
92
  context.report({
66
93
  loc: {
@@ -24,7 +24,8 @@ import { URL_RULE_DOCS } from '../core/constants.js';
24
24
  // Helper
25
25
  // --------------------------------------------------------------------------------
26
26
 
27
- const gitConflictMarkerRegex = /(?:^|(?<=[\r\n]))(?:<{7}(?!<)|={7}(?!=)|>{7}(?!>))/gu;
27
+ const gitConflictMarkerRegex =
28
+ /(?:^|(?<=[\r\n]))(?<gitConflictMarker><{7}(?!<)|={7}(?!=)|>{7}(?!>))[^\r\n]*\r?\n?/gu;
28
29
 
29
30
  // --------------------------------------------------------------------------------
30
31
  // Rule Definition
@@ -42,6 +43,8 @@ export default {
42
43
  stylistic: false,
43
44
  },
44
45
 
46
+ fixable: 'code',
47
+
45
48
  schema: [
46
49
  {
47
50
  type: 'object',
@@ -99,7 +102,7 @@ export default {
99
102
  const matches = sourceCode.text.matchAll(gitConflictMarkerRegex);
100
103
 
101
104
  for (const match of matches) {
102
- const gitConflictMarker = match[0];
105
+ const gitConflictMarker = match[1];
103
106
 
104
107
  const startOffset = match.index;
105
108
  const endOffset = startOffset + gitConflictMarker.length;
@@ -117,6 +120,11 @@ export default {
117
120
  },
118
121
 
119
122
  messageId: 'noGitConflictMarker',
123
+
124
+ fix(fixer) {
125
+ // Remove the entire line containing the git conflict marker, including the newline character.
126
+ return fixer.removeRange([startOffset, startOffset + match[0].length]);
127
+ },
120
128
  });
121
129
  }
122
130
  },