eslint-markdown 0.7.0 → 0.9.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.
@@ -11,9 +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
+ 'no-double-punctuation': import("../core/types.js").RuleModule<import("./no-double-punctuation.js").RuleOptions, import("./no-double-punctuation.js").MessageIds>;
15
15
  'no-double-space': import("../core/types.js").RuleModule<import("./no-double-space.js").RuleOptions, import("./no-double-space.js").MessageIds>;
16
- 'no-emoji': import("../core/types.js").RuleModule<[], "noEmoji">;
16
+ 'no-emoji': import("../core/types.js").RuleModule<import("./no-emoji.js").RuleOptions, "noEmoji">;
17
17
  'no-git-conflict-marker': import("../core/types.js").RuleModule<import("./no-git-conflict-marker.js").RuleOptions, "noGitConflictMarker">;
18
18
  'no-irregular-dash': import("../core/types.js").RuleModule<import("./no-irregular-dash.js").RuleOptions, "noIrregularDash">;
19
19
  'no-irregular-whitespace': import("../core/types.js").RuleModule<import("./no-irregular-whitespace.js").RuleOptions, "noIrregularWhitespace">;
@@ -7,6 +7,8 @@ declare const _default: {
7
7
  recommended: boolean;
8
8
  stylistic: false;
9
9
  };
10
+ fixable: "code";
11
+ hasSuggestions: true;
10
12
  schema: {
11
13
  type: "object";
12
14
  properties: {
@@ -28,6 +30,8 @@ declare const _default: {
28
30
  }];
29
31
  messages: {
30
32
  noDoublePunctuation: string;
33
+ suggestReplaceWithLeft: string;
34
+ suggestReplaceWithRight: string;
31
35
  };
32
36
  language: string;
33
37
  dialects: string[];
@@ -37,7 +41,7 @@ declare const _default: {
37
41
  Code: import("@eslint/markdown").MarkdownSourceCode;
38
42
  RuleOptions: RuleOptions;
39
43
  Node: import("mdast").Node;
40
- MessageIds: "noDoublePunctuation";
44
+ MessageIds: MessageIds;
41
45
  }>): {
42
46
  text(node: import("mdast").Text): void;
43
47
  };
@@ -46,4 +50,4 @@ export default _default;
46
50
  export type RuleOptions = [{
47
51
  allow: string[];
48
52
  }];
49
- export type MessageIds = "noDoublePunctuation";
53
+ export type MessageIds = "noDoublePunctuation" | "suggestReplaceWithLeft" | "suggestReplaceWithRight";
@@ -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.7.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "description": "Lint your Markdown with ESLint.🛠️",
6
6
  "exports": {
@@ -16,7 +16,7 @@ import { URL_RULE_DOCS } from '../core/constants.js';
16
16
  /**
17
17
  * @import { RuleModule } from '../core/types.js';
18
18
  * @typedef {[{ allow: string[] }]} RuleOptions
19
- * @typedef {'noDoublePunctuation'} MessageIds
19
+ * @typedef {'noDoublePunctuation' | 'suggestReplaceWithLeft' | 'suggestReplaceWithRight'} MessageIds
20
20
  */
21
21
 
22
22
  // --------------------------------------------------------------------------------
@@ -45,6 +45,10 @@ export default {
45
45
  stylistic: false,
46
46
  },
47
47
 
48
+ fixable: 'code',
49
+
50
+ hasSuggestions: true,
51
+
48
52
  schema: [
49
53
  {
50
54
  type: 'object',
@@ -72,6 +76,10 @@ export default {
72
76
 
73
77
  messages: {
74
78
  noDoublePunctuation: 'Double punctuation mark `{{ punctuation }}` is not allowed.',
79
+ suggestReplaceWithLeft:
80
+ 'Replace `{{ punctuation }}` with the left punctuation mark `{{ leftPunctuation }}`.',
81
+ suggestReplaceWithRight:
82
+ 'Replace `{{ punctuation }}` with the right punctuation mark `{{ rightPunctuation }}`.',
75
83
  },
76
84
 
77
85
  language: 'markdown',
@@ -96,7 +104,8 @@ export default {
96
104
 
97
105
  if (allow.includes(punctuation)) continue;
98
106
 
99
- context.report({
107
+ const [leftPunctuation, rightPunctuation] = punctuation;
108
+ const violation = /** @type {const} */ ({
100
109
  loc: {
101
110
  start: sourceCode.getLocFromIndex(startOffset),
102
111
  end: sourceCode.getLocFromIndex(endOffset),
@@ -108,6 +117,53 @@ export default {
108
117
 
109
118
  messageId: 'noDoublePunctuation',
110
119
  });
120
+
121
+ if (leftPunctuation === rightPunctuation) {
122
+ context.report({
123
+ ...violation,
124
+
125
+ fix(fixer) {
126
+ return fixer.replaceTextRange([startOffset, endOffset], leftPunctuation);
127
+ },
128
+ });
129
+ } else {
130
+ context.report({
131
+ ...violation,
132
+
133
+ suggest: [
134
+ {
135
+ messageId: 'suggestReplaceWithLeft',
136
+
137
+ data: {
138
+ punctuation,
139
+ leftPunctuation,
140
+ },
141
+
142
+ fix(fixer) {
143
+ return fixer.replaceTextRange(
144
+ [startOffset, endOffset],
145
+ leftPunctuation,
146
+ );
147
+ },
148
+ },
149
+ {
150
+ messageId: 'suggestReplaceWithRight',
151
+
152
+ data: {
153
+ punctuation,
154
+ rightPunctuation,
155
+ },
156
+
157
+ fix(fixer) {
158
+ return fixer.replaceTextRange(
159
+ [startOffset, endOffset],
160
+ rightPunctuation,
161
+ );
162
+ },
163
+ },
164
+ ],
165
+ });
166
+ }
111
167
  }
112
168
  },
113
169
  };
@@ -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
  },
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- // TODO
2
- // https://github.com/textlint-rule/textlint-rule-footnote-order