@markuplint/rules 2.0.0-dev.2021117.3 → 2.0.0-dev.20211209.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/lib/create-message.d.ts +5 -0
- package/lib/create-message.js +256 -0
- package/lib/debug.d.ts +3 -0
- package/lib/debug.js +6 -0
- package/package.json +3 -3
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Translator } from '@markuplint/i18n';
|
|
2
|
+
import type { AttributeType } from '@markuplint/ml-spec';
|
|
3
|
+
import type { UnmatchedResult } from '@markuplint/types';
|
|
4
|
+
export declare function createMessageValueExpected(t: Translator, baseTarget: string, type: AttributeType, matches: UnmatchedResult): string;
|
|
5
|
+
export declare function __createMessageValueExpected(t: Translator, baseTarget: string, expected: string | null, matches: Pick<UnmatchedResult, 'partName' | 'reason' | 'raw' | 'candicate' | 'ref'>): string;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__createMessageValueExpected = exports.createMessageValueExpected = void 0;
|
|
4
|
+
const types_1 = require("@markuplint/types");
|
|
5
|
+
function createMessageValueExpected(t, baseTarget, type, matches) {
|
|
6
|
+
let target = baseTarget;
|
|
7
|
+
let listDescriptionPart;
|
|
8
|
+
let tokenType;
|
|
9
|
+
if ((0, types_1.isList)(type)) {
|
|
10
|
+
listDescriptionPart = t('{0} expects {1:c}', target, type.separator === 'space' ? 'space-separated list' : 'comma-separated list');
|
|
11
|
+
tokenType = type.token;
|
|
12
|
+
target = 'the content of the list';
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
tokenType = type;
|
|
16
|
+
}
|
|
17
|
+
const expected = createExpectedObject(tokenType, matches, t);
|
|
18
|
+
const message = [listDescriptionPart, __createMessageValueExpected(t, target, expected, matches)]
|
|
19
|
+
.filter(s => s)
|
|
20
|
+
.join(t('. '));
|
|
21
|
+
return message;
|
|
22
|
+
}
|
|
23
|
+
exports.createMessageValueExpected = createMessageValueExpected;
|
|
24
|
+
function __createMessageValueExpected(t, baseTarget, expected, matches) {
|
|
25
|
+
let target = baseTarget;
|
|
26
|
+
let reasonPart;
|
|
27
|
+
let expectPart;
|
|
28
|
+
let candicatePart;
|
|
29
|
+
let expectOrNeed = 'expects';
|
|
30
|
+
if (matches.partName) {
|
|
31
|
+
if (matches.partName === 'the content of the list') {
|
|
32
|
+
target = 'the content of the list';
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
target = t('{0} part of {1}', t('the {0}', matches.partName), target);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
switch (matches.reason) {
|
|
39
|
+
case 'doesnt-exist-in-enum': {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 'duplicated': {
|
|
43
|
+
reasonPart = t('{0} is {1:c}', target, 'duplicated');
|
|
44
|
+
target = 'it';
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'empty-token': {
|
|
48
|
+
reasonPart = t('{0} must not be {1}', target, 'empty');
|
|
49
|
+
target = 'it';
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case 'extra-token': {
|
|
53
|
+
const token = matches.partName || 'token';
|
|
54
|
+
reasonPart = t('Found {0}', t('extra {0}', token)) + ' ' + t([matches.raw]);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case 'illegal-combination': {
|
|
58
|
+
reasonPart = t('Found {0}', t('an {0}', 'illegal combination'));
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case 'illegal-order': {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'missing-comma': {
|
|
65
|
+
if (matches.partName) {
|
|
66
|
+
reasonPart = t('Missing {0} in {1}', t('a {0}', 'comma'), t('the {0} part', matches.partName));
|
|
67
|
+
target = 'it';
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
reasonPart = t('Missing {0}', t('a {0}', 'comma'));
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case 'missing-token': {
|
|
75
|
+
if (matches.partName) {
|
|
76
|
+
const part = t('the {0} part', matches.partName);
|
|
77
|
+
reasonPart = t('Missing {0}', part);
|
|
78
|
+
if (!expected) {
|
|
79
|
+
expected = part;
|
|
80
|
+
target = baseTarget;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
reasonPart = t('Missing {0}', t('a {0}', 'token'));
|
|
85
|
+
}
|
|
86
|
+
expectOrNeed = 'needs';
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case 'out-of-range': {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case 'syntax-error': {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'typo': {
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 'unexpected-comma': {
|
|
99
|
+
reasonPart = t('Found {0}', t('unexpected {0}', 'comma'));
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case 'unexpected-newline': {
|
|
103
|
+
reasonPart = t('Found {0}', t('unexpected {0}', 'newline'));
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case 'unexpected-space': {
|
|
107
|
+
reasonPart = t('Found {0}', t('unexpected {0}', 'whitespace'));
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case 'unexpected-token': {
|
|
111
|
+
const chars = t('unexpected {0}', 'characters');
|
|
112
|
+
if (matches.partName) {
|
|
113
|
+
const part = t('the {0} part', matches.partName);
|
|
114
|
+
reasonPart = t('{0} includes {1}', part, chars);
|
|
115
|
+
target = 'it';
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
reasonPart = t('It includes {0}', chars);
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
default: {
|
|
123
|
+
if ('type' in matches.reason) {
|
|
124
|
+
switch (matches.reason.type) {
|
|
125
|
+
case 'out-of-range-length-digit': {
|
|
126
|
+
const { gte, lte } = matches.reason;
|
|
127
|
+
let expectedDigits = null;
|
|
128
|
+
if (lte != null && gte === lte) {
|
|
129
|
+
expectedDigits = t('{0} digits', gte);
|
|
130
|
+
}
|
|
131
|
+
else if (lte != null) {
|
|
132
|
+
// expects = t('{0} that has {1}', t('the {0}', expects), t('{0} or more digits', gte));
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
expectedDigits = t('{0} or more digits', gte);
|
|
136
|
+
}
|
|
137
|
+
if (!expected) {
|
|
138
|
+
expected = expectedDigits;
|
|
139
|
+
}
|
|
140
|
+
else if (expected && expectedDigits) {
|
|
141
|
+
expected = t('{0:c} and {1:c}', expectedDigits, expected);
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case 'out-of-range': {
|
|
146
|
+
const expectedNum = createExpectedNumber(t, {
|
|
147
|
+
...matches.reason,
|
|
148
|
+
type: 'integer',
|
|
149
|
+
});
|
|
150
|
+
if (!expected) {
|
|
151
|
+
expected = expectedNum;
|
|
152
|
+
}
|
|
153
|
+
else if (expected) {
|
|
154
|
+
expected = t('{0:c} and {1:c}', expectedNum, expected);
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (expected) {
|
|
163
|
+
if (target === 'it') {
|
|
164
|
+
if (expectOrNeed === 'expects') {
|
|
165
|
+
expectPart = t('It expects {0:c}', expected);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
expectPart = t('It needs {0}', expected);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
if (expectOrNeed === 'expects') {
|
|
173
|
+
expectPart = t('{0} expects {1:c}', target, expected);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
expectPart = t('{0} needs {1}', target, expected);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (matches.candicate) {
|
|
181
|
+
candicatePart = t('Did you mean "{0*}"?', matches.candicate);
|
|
182
|
+
}
|
|
183
|
+
let message = [reasonPart, expectPart, candicatePart].filter(s => s).join(t('. '));
|
|
184
|
+
if (matches.ref) {
|
|
185
|
+
message += ` (${matches.ref})`;
|
|
186
|
+
}
|
|
187
|
+
return message;
|
|
188
|
+
}
|
|
189
|
+
exports.__createMessageValueExpected = __createMessageValueExpected;
|
|
190
|
+
function createExpectedObject(type, matches, t) {
|
|
191
|
+
var _a;
|
|
192
|
+
const expectedObject = [];
|
|
193
|
+
if ((_a = matches.expects) === null || _a === void 0 ? void 0 : _a.length) {
|
|
194
|
+
expectedObject.push(...matches.expects.map(expect => {
|
|
195
|
+
switch (expect.type) {
|
|
196
|
+
case 'common':
|
|
197
|
+
return expect.value;
|
|
198
|
+
case 'const':
|
|
199
|
+
return expect.value ? `%${expect.value}%` : '';
|
|
200
|
+
case 'format':
|
|
201
|
+
return t('the {0} format', expect.value);
|
|
202
|
+
case 'regxp':
|
|
203
|
+
return t('{0} ({1})', 'regular expression', expect.value);
|
|
204
|
+
case 'syntax':
|
|
205
|
+
if ((0, types_1.isKeyword)(type) && type[0] === '<') {
|
|
206
|
+
return t('the CSS Syntax "{0}"', expect.value);
|
|
207
|
+
}
|
|
208
|
+
return t('{0} syntax', expect.value);
|
|
209
|
+
}
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
else if ((0, types_1.isKeyword)(type)) {
|
|
213
|
+
if (type[0] === '<') {
|
|
214
|
+
expectedObject.push(t('the CSS Syntax "{0}"', type));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else if ((0, types_1.isEnum)(type)) {
|
|
218
|
+
expectedObject.push(...type.enum);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
expectedObject.push(createExpectedNumber(t, type));
|
|
222
|
+
}
|
|
223
|
+
const expects = expectedObject.length === 0
|
|
224
|
+
? null
|
|
225
|
+
: 1 < expectedObject.length
|
|
226
|
+
? t('either {0}', t(expectedObject))
|
|
227
|
+
: expectedObject[0];
|
|
228
|
+
return expects;
|
|
229
|
+
}
|
|
230
|
+
function createExpectedNumber(t, type) {
|
|
231
|
+
if (type.gt != null) {
|
|
232
|
+
if (type.lt != null) {
|
|
233
|
+
return t('{0} greater than {1} less than {2}', type.type, type.gt, type.lt);
|
|
234
|
+
}
|
|
235
|
+
if (type.lte != null) {
|
|
236
|
+
return t('{0} greater than {1} less than or equal to {2}', type.type, type.gt, type.lte);
|
|
237
|
+
}
|
|
238
|
+
return t('{0} greater than {1}', type.type, type.gt);
|
|
239
|
+
}
|
|
240
|
+
if (type.gte != null) {
|
|
241
|
+
if (type.lt != null) {
|
|
242
|
+
return t('{0} greater than or equal to {1} less than {2}', type.type, type.gte, type.lt);
|
|
243
|
+
}
|
|
244
|
+
if (type.lte != null) {
|
|
245
|
+
return t('{0} greater than or equal to {1} less than or equal to {2}', type.type, type.gte, type.lte);
|
|
246
|
+
}
|
|
247
|
+
return t('{0} greater than or equal to {1}', type.type, type.gte);
|
|
248
|
+
}
|
|
249
|
+
if (type.lt != null) {
|
|
250
|
+
return t('{0} less than {1}', type.type, type.lt);
|
|
251
|
+
}
|
|
252
|
+
if (type.lte != null) {
|
|
253
|
+
return t('{0} less than or equal to {1}', type.type, type.lte);
|
|
254
|
+
}
|
|
255
|
+
return type.type;
|
|
256
|
+
}
|
package/lib/debug.d.ts
ADDED
package/lib/debug.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/rules",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.20211209.0",
|
|
4
4
|
"description": "Rules for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@markuplint/html-spec": "2.0.0-dev.2021117.0",
|
|
21
|
-
"@markuplint/ml-core": "2.0.0-dev.
|
|
21
|
+
"@markuplint/ml-core": "2.0.0-dev.20211209.0",
|
|
22
22
|
"@markuplint/ml-spec": "2.0.0-dev.20211115.0",
|
|
23
23
|
"tslib": "^2.3.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "6c0d7ada880a331257624180d593f6d53b73e98f"
|
|
26
26
|
}
|