eslint-markdown 0.8.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,7 +11,7 @@ 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
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">;
@@ -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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-markdown",
3
- "version": "0.8.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
  };
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- // TODO
2
- // https://github.com/textlint-rule/textlint-rule-footnote-order