@@ -3,11 +3,19 @@ import type { RuleContext, ValueOf } from '@/types'
33import type { InlineElement } from '@/types/inline-element'
44import { createRule } from '@/utils'
55import { getNodeContext , getNodePosition , isNestedInlineElement } from '@/utils/ast'
6- import { INLINE_SPACE_MESSAGE_IDS as MESSAGE_IDS , validateSpace } from '@/utils/inline-element'
6+ import { validateSpace } from '@/utils/inline-element'
77import { getSpaceContext } from '@/utils/space'
88
99export const RULE_NAME = 'space-around-inline-element'
10-
10+ export const MESSAGE_IDS = {
11+ missingSpaceBefore : 'missingSpaceBefore' ,
12+ missingSpaceAfter : 'missingSpaceAfter' ,
13+ multipleSpacesBefore : 'multipleSpacesBefore' ,
14+ multipleSpacesAfter : 'multipleSpacesAfter' ,
15+ multipleSpacesAfterPunctuation : 'multipleSpacesAfterPunctuation' ,
16+ unexpectedSpaceBefore : 'unexpectedSpaceBefore' ,
17+ unexpectedSpaceAfter : 'unexpectedSpaceAfter' ,
18+ } as const
1119type MessageIds = ValueOf < typeof MESSAGE_IDS >
1220type Options = [ ]
1321
@@ -18,6 +26,47 @@ const BEFORE_INLINE_ELEMENT_MESSAGE_IDS = new Set<MessageIds>([
1826 MESSAGE_IDS . unexpectedSpaceBefore ,
1927] )
2028
29+ export default createRule < Options , MessageIds > ( {
30+ name : RULE_NAME ,
31+ meta : {
32+ type : 'layout' ,
33+ docs : {
34+ description : 'Enforce spacing around Markdown inline elements.' ,
35+ } ,
36+ messages : {
37+ missingSpaceBefore : 'A space is required before the inline element.' ,
38+ missingSpaceAfter : 'A space is required after the inline element.' ,
39+ multipleSpacesBefore : 'Use exactly one space before the inline element.' ,
40+ multipleSpacesAfter : 'Use exactly one space after the inline element.' ,
41+ multipleSpacesAfterPunctuation : 'Use one space after punctuation.' ,
42+ unexpectedSpaceBefore : 'Do not add a space between punctuation and the inline element.' ,
43+ unexpectedSpaceAfter : 'Do not add a space between the inline element and punctuation.' ,
44+ } ,
45+ fixable : 'whitespace' ,
46+ schema : [ ] ,
47+ } ,
48+ defaultOptions : [ ] ,
49+ create ( context ) {
50+ return {
51+ link ( node : Link ) {
52+ checkInlineElement ( context , node )
53+ } ,
54+ image ( node : Image ) {
55+ checkInlineElement ( context , node )
56+ } ,
57+ inlineCode ( node : InlineCode ) {
58+ checkInlineElement ( context , node )
59+ } ,
60+ emphasis ( node : Emphasis ) {
61+ checkInlineElement ( context , node )
62+ } ,
63+ strong ( node : Strong ) {
64+ checkInlineElement ( context , node )
65+ } ,
66+ }
67+ } ,
68+ } )
69+
2170/**
2271 * Checks one selected inline element and reports the fix range around it.
2372 */
@@ -63,44 +112,3 @@ function checkInlineElement(context: RuleContext<MessageIds, Options>, node: Inl
63112 } )
64113 }
65114}
66-
67- export default createRule < Options , MessageIds > ( {
68- name : RULE_NAME ,
69- meta : {
70- type : 'layout' ,
71- docs : {
72- description : 'Enforce spacing around Markdown inline elements.' ,
73- } ,
74- messages : {
75- missingSpaceBefore : 'A space is required before the inline element.' ,
76- missingSpaceAfter : 'A space is required after the inline element.' ,
77- multipleSpacesBefore : 'Use exactly one space before the inline element.' ,
78- multipleSpacesAfter : 'Use exactly one space after the inline element.' ,
79- multipleSpacesAfterPunctuation : 'Use one space after punctuation.' ,
80- unexpectedSpaceBefore : 'Do not add a space between punctuation and the inline element.' ,
81- unexpectedSpaceAfter : 'Do not add a space between the inline element and punctuation.' ,
82- } ,
83- fixable : 'whitespace' ,
84- schema : [ ] ,
85- } ,
86- defaultOptions : [ ] ,
87- create ( context ) {
88- return {
89- link ( node : Link ) {
90- checkInlineElement ( context , node )
91- } ,
92- image ( node : Image ) {
93- checkInlineElement ( context , node )
94- } ,
95- inlineCode ( node : InlineCode ) {
96- checkInlineElement ( context , node )
97- } ,
98- emphasis ( node : Emphasis ) {
99- checkInlineElement ( context , node )
100- } ,
101- strong ( node : Strong ) {
102- checkInlineElement ( context , node )
103- } ,
104- }
105- } ,
106- } )
0 commit comments