@markuplint/types 2.2.0 → 3.0.0-alpha.1
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 +1 -1
- package/gen/specific-schema.json +6 -6
- package/lib/check-multi-types.d.ts +1 -1
- package/lib/css-syntax.spec.js +1 -1
- package/lib/defs.js +4 -4
- package/lib/get-candidate.d.ts +3 -0
- package/lib/{get-candicate.js → get-candidate.js} +8 -8
- package/lib/list.spec.js +4 -4
- package/lib/match-result.d.ts +1 -1
- package/lib/number.js +4 -4
- package/lib/primitive/is-uint.d.ts +1 -1
- package/lib/primitive/is-uint.js +4 -4
- package/lib/token/token-collection.d.ts +21 -21
- package/lib/token/token-collection.js +101 -101
- package/lib/token/token-collection.spec.js +2 -2
- package/lib/token/token.d.ts +22 -22
- package/lib/token/token.js +36 -36
- package/lib/types.d.ts +2 -2
- package/lib/types.schema.d.ts +3 -0
- package/lib/whatwg/check-autocomplete.js +23 -23
- package/lib/whatwg/check-autocomplete.spec.js +9 -9
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
- package/lib/whatwg/check-datetime/datetime-tokens.js +16 -16
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +3 -3
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +2 -2
- package/lib/whatwg/check-datetime/time-string.js +1 -1
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +4 -4
- package/lib/whatwg/check-mime-type.js +1 -1
- package/lib/whatwg/check-mime-type.spec.js +3 -3
- package/package.json +4 -4
- package/src/css-syntax.spec.ts +1 -1
- package/src/defs.ts +4 -4
- package/src/{get-candicate.ts → get-candidate.ts} +6 -6
- package/src/list.spec.ts +4 -4
- package/src/number.ts +4 -4
- package/src/primitive/is-uint.ts +4 -4
- package/src/token/token-collection.spec.ts +2 -2
- package/src/token/token-collection.ts +113 -113
- package/src/token/token.ts +58 -58
- package/src/types.schema.ts +3 -0
- package/src/types.ts +2 -2
- package/src/whatwg/check-autocomplete.spec.ts +9 -9
- package/src/whatwg/check-autocomplete.ts +23 -23
- package/src/whatwg/check-datetime/datetime-tokens.ts +18 -18
- package/src/whatwg/check-datetime/global-date-and-time-string.ts +3 -3
- package/src/whatwg/check-datetime/local-date-and-time-string.ts +4 -4
- package/src/whatwg/check-datetime/time-string.ts +2 -2
- package/src/whatwg/check-datetime/time-zone-offset-string.ts +4 -4
- package/src/whatwg/check-mime-type.spec.ts +3 -3
- package/src/whatwg/check-mime-type.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/types.schema.json +3 -1
- package/lib/get-candicate.d.ts +0 -3
package/lib/token/token.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
|
|
2
2
|
export declare class Token {
|
|
3
3
|
#private;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
static
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
column: number;
|
|
11
|
-
};
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
6
|
+
*/
|
|
7
|
+
static readonly Comma = 18;
|
|
8
|
+
static readonly Ident = 1;
|
|
9
|
+
static readonly WhiteSpace = 13;
|
|
12
10
|
/**
|
|
13
11
|
* ASCII whitespace is
|
|
14
12
|
* - U+0009 TAB
|
|
@@ -20,36 +18,38 @@ export declare class Token {
|
|
|
20
18
|
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
21
19
|
*/
|
|
22
20
|
static readonly whitespace: ReadonlyArray<string>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
static
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
static getCol(value: string, offset: number): number;
|
|
22
|
+
static getLine(value: string, offset: number): number;
|
|
23
|
+
static getType(value: string, separators?: string[]): 1 | 18 | 13;
|
|
24
|
+
static shiftLocation(token: Token, offset: number): {
|
|
25
|
+
offset: number;
|
|
26
|
+
line: number;
|
|
27
|
+
column: number;
|
|
28
|
+
};
|
|
29
|
+
readonly offset: number;
|
|
29
30
|
readonly type: number;
|
|
30
31
|
readonly value: string;
|
|
31
|
-
readonly offset: number;
|
|
32
32
|
constructor(value: string, offset: number, originalValue: string, separators?: string[]);
|
|
33
33
|
get length(): number;
|
|
34
34
|
get origin(): string;
|
|
35
|
-
unmatched(options?: UnmatchedResultOptions & {
|
|
36
|
-
ref?: string;
|
|
37
|
-
reason?: UnmatchedResultReason;
|
|
38
|
-
}): UnmatchedResult;
|
|
39
35
|
/**
|
|
40
36
|
*
|
|
41
37
|
* @param value The token value or the token type or its list
|
|
42
38
|
*/
|
|
43
|
-
|
|
39
|
+
includes(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean;
|
|
44
40
|
/**
|
|
45
41
|
*
|
|
46
42
|
* @param value The token value or the token type or its list
|
|
47
43
|
*/
|
|
48
|
-
|
|
49
|
-
toNumber(): number;
|
|
44
|
+
match(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean;
|
|
50
45
|
toJSON(): {
|
|
51
46
|
type: number;
|
|
52
47
|
value: string;
|
|
53
48
|
offset: number;
|
|
54
49
|
};
|
|
50
|
+
toNumber(): number;
|
|
51
|
+
unmatched(options?: UnmatchedResultOptions & {
|
|
52
|
+
ref?: string;
|
|
53
|
+
reason?: UnmatchedResultReason;
|
|
54
|
+
}): UnmatchedResult;
|
|
55
55
|
}
|
package/lib/token/token.js
CHANGED
|
@@ -11,6 +11,13 @@ class Token {
|
|
|
11
11
|
this.offset = offset;
|
|
12
12
|
tslib_1.__classPrivateFieldSet(this, _Token_originalValue, originalValue, "f");
|
|
13
13
|
}
|
|
14
|
+
static getCol(value, offset) {
|
|
15
|
+
const lines = value.slice(0, offset).split(/\n/g);
|
|
16
|
+
return lines[lines.length - 1].length + 1;
|
|
17
|
+
}
|
|
18
|
+
static getLine(value, offset) {
|
|
19
|
+
return value.slice(0, offset).split(/\n/g).length;
|
|
20
|
+
}
|
|
14
21
|
static getType(value, separators) {
|
|
15
22
|
if (Token.whitespace.includes(value[0])) {
|
|
16
23
|
return Token.WhiteSpace;
|
|
@@ -23,13 +30,6 @@ class Token {
|
|
|
23
30
|
}
|
|
24
31
|
return Token.Ident;
|
|
25
32
|
}
|
|
26
|
-
static getLine(value, offset) {
|
|
27
|
-
return value.slice(0, offset).split(/\n/g).length;
|
|
28
|
-
}
|
|
29
|
-
static getCol(value, offset) {
|
|
30
|
-
const lines = value.slice(0, offset).split(/\n/g);
|
|
31
|
-
return lines[lines.length - 1].length + 1;
|
|
32
|
-
}
|
|
33
33
|
static shiftLocation(token, offset) {
|
|
34
34
|
const shifted = token.offset + offset;
|
|
35
35
|
return {
|
|
@@ -44,32 +44,18 @@ class Token {
|
|
|
44
44
|
get origin() {
|
|
45
45
|
return tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f");
|
|
46
46
|
}
|
|
47
|
-
unmatched(options) {
|
|
48
|
-
var _a;
|
|
49
|
-
return {
|
|
50
|
-
...options,
|
|
51
|
-
matched: false,
|
|
52
|
-
ref: (options === null || options === void 0 ? void 0 : options.ref) || null,
|
|
53
|
-
raw: this.value,
|
|
54
|
-
offset: this.offset,
|
|
55
|
-
length: this.value.length,
|
|
56
|
-
line: Token.getLine(tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f"), this.offset),
|
|
57
|
-
column: Token.getCol(tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f"), this.offset),
|
|
58
|
-
reason: (_a = options === null || options === void 0 ? void 0 : options.reason) !== null && _a !== void 0 ? _a : 'syntax-error',
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
47
|
/**
|
|
62
48
|
*
|
|
63
49
|
* @param value The token value or the token type or its list
|
|
64
50
|
*/
|
|
65
|
-
|
|
51
|
+
includes(value, caseInsensitive) {
|
|
66
52
|
if (Array.isArray(value)) {
|
|
67
|
-
return value.some(v => this.
|
|
53
|
+
return value.some(v => this.includes(v));
|
|
68
54
|
}
|
|
69
55
|
if (typeof value === 'string') {
|
|
70
56
|
const a = caseInsensitive ? this.value.toLowerCase() : this.value;
|
|
71
57
|
const b = caseInsensitive ? value.toLowerCase() : value;
|
|
72
|
-
return a
|
|
58
|
+
return a.indexOf(b) !== -1;
|
|
73
59
|
}
|
|
74
60
|
if (value instanceof RegExp) {
|
|
75
61
|
const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
|
|
@@ -81,14 +67,14 @@ class Token {
|
|
|
81
67
|
*
|
|
82
68
|
* @param value The token value or the token type or its list
|
|
83
69
|
*/
|
|
84
|
-
|
|
70
|
+
match(value, caseInsensitive) {
|
|
85
71
|
if (Array.isArray(value)) {
|
|
86
|
-
return value.some(v => this.
|
|
72
|
+
return value.some(v => this.match(v));
|
|
87
73
|
}
|
|
88
74
|
if (typeof value === 'string') {
|
|
89
75
|
const a = caseInsensitive ? this.value.toLowerCase() : this.value;
|
|
90
76
|
const b = caseInsensitive ? value.toLowerCase() : value;
|
|
91
|
-
return a
|
|
77
|
+
return a === b;
|
|
92
78
|
}
|
|
93
79
|
if (value instanceof RegExp) {
|
|
94
80
|
const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
|
|
@@ -96,9 +82,6 @@ class Token {
|
|
|
96
82
|
}
|
|
97
83
|
return this.type === value;
|
|
98
84
|
}
|
|
99
|
-
toNumber() {
|
|
100
|
-
return parseFloat(this.value);
|
|
101
|
-
}
|
|
102
85
|
toJSON() {
|
|
103
86
|
return {
|
|
104
87
|
type: this.type,
|
|
@@ -106,9 +89,32 @@ class Token {
|
|
|
106
89
|
offset: this.offset,
|
|
107
90
|
};
|
|
108
91
|
}
|
|
92
|
+
toNumber() {
|
|
93
|
+
return parseFloat(this.value);
|
|
94
|
+
}
|
|
95
|
+
unmatched(options) {
|
|
96
|
+
var _a;
|
|
97
|
+
return {
|
|
98
|
+
...options,
|
|
99
|
+
matched: false,
|
|
100
|
+
ref: (options === null || options === void 0 ? void 0 : options.ref) || null,
|
|
101
|
+
raw: this.value,
|
|
102
|
+
offset: this.offset,
|
|
103
|
+
length: this.value.length,
|
|
104
|
+
line: Token.getLine(tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f"), this.offset),
|
|
105
|
+
column: Token.getCol(tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f"), this.offset),
|
|
106
|
+
reason: (_a = options === null || options === void 0 ? void 0 : options.reason) !== null && _a !== void 0 ? _a : 'syntax-error',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
109
|
}
|
|
110
110
|
exports.Token = Token;
|
|
111
111
|
_Token_originalValue = new WeakMap();
|
|
112
|
+
/**
|
|
113
|
+
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
114
|
+
*/
|
|
115
|
+
Token.Comma = 18;
|
|
116
|
+
Token.Ident = 1;
|
|
117
|
+
Token.WhiteSpace = 13;
|
|
112
118
|
/**
|
|
113
119
|
* ASCII whitespace is
|
|
114
120
|
* - U+0009 TAB
|
|
@@ -120,9 +126,3 @@ _Token_originalValue = new WeakMap();
|
|
|
120
126
|
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
121
127
|
*/
|
|
122
128
|
Token.whitespace = ['\u0009', '\u000A', '\u000C', '\u000D', '\u0020'];
|
|
123
|
-
/**
|
|
124
|
-
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
125
|
-
*/
|
|
126
|
-
Token.Ident = 1;
|
|
127
|
-
Token.WhiteSpace = 13;
|
|
128
|
-
Token.Comma = 18;
|
package/lib/types.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare type UnmatchedResultOptions = {
|
|
|
16
16
|
partName?: string;
|
|
17
17
|
expects?: Expect[];
|
|
18
18
|
extra?: Expect;
|
|
19
|
-
|
|
19
|
+
candidate?: string;
|
|
20
20
|
};
|
|
21
21
|
export declare type UnmatchedResultReason = 'syntax-error' | 'typo' | 'missing-token' | 'missing-comma' | 'unexpected-token' | 'unexpected-space' | 'unexpected-newline' | 'unexpected-comma' | 'empty-token' | 'out-of-range' | 'doesnt-exist-in-enum' | 'duplicated' | 'illegal-combination' | 'illegal-order' | 'extra-token' | 'must-be-percent-encoded' | 'must-be-serialized' | {
|
|
22
22
|
type: 'out-of-range';
|
|
@@ -37,7 +37,7 @@ export declare type MatchedResult = {
|
|
|
37
37
|
matched: true;
|
|
38
38
|
};
|
|
39
39
|
export declare type Expect = {
|
|
40
|
-
type: 'const' | 'format' | 'syntax' | '
|
|
40
|
+
type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
|
|
41
41
|
value: string;
|
|
42
42
|
};
|
|
43
43
|
export declare type FormattedPrimitiveTypeCheck = (value: string) => boolean;
|
package/lib/types.schema.d.ts
CHANGED
|
@@ -32,6 +32,9 @@ export interface List {
|
|
|
32
32
|
* [Enumerated attributes](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute)
|
|
33
33
|
*/
|
|
34
34
|
export interface Enum {
|
|
35
|
+
/**
|
|
36
|
+
* @minItems 1
|
|
37
|
+
*/
|
|
35
38
|
enum: [string, ...string[]];
|
|
36
39
|
disallowToSurroundBySpaces?: boolean;
|
|
37
40
|
caseInsensitive?: boolean;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkAutoComplete = void 0;
|
|
4
4
|
const debug_1 = require("../debug");
|
|
5
|
-
const
|
|
5
|
+
const get_candidate_1 = require("../get-candidate");
|
|
6
6
|
const match_result_1 = require("../match-result");
|
|
7
7
|
const token_1 = require("../token");
|
|
8
8
|
const acLog = debug_1.log.extend('autocomplete');
|
|
@@ -86,7 +86,7 @@ const contactableFieldNames = [
|
|
|
86
86
|
* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-webauthn
|
|
87
87
|
*/
|
|
88
88
|
const webauthnFieldNames = ['webauthn'];
|
|
89
|
-
const
|
|
89
|
+
const URL_AUTOCOMPLETE = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete';
|
|
90
90
|
const URL_ON_OFF = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-on-2';
|
|
91
91
|
const URL_NAMED_GROUP = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-section';
|
|
92
92
|
const URL_PART_OF_ADDRESS = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-shipping';
|
|
@@ -113,14 +113,14 @@ const checkAutoComplete = () => value => {
|
|
|
113
113
|
value: 'autocomplete',
|
|
114
114
|
},
|
|
115
115
|
],
|
|
116
|
-
ref:
|
|
116
|
+
ref: URL_AUTOCOMPLETE,
|
|
117
117
|
});
|
|
118
118
|
if (!listingChecked.matched) {
|
|
119
119
|
acLog('Unmatch: %s', listingChecked.reason);
|
|
120
120
|
return listingChecked;
|
|
121
121
|
}
|
|
122
|
-
const
|
|
123
|
-
const headAndTail1 =
|
|
122
|
+
const identTokens = tokens.getIdentTokens();
|
|
123
|
+
const headAndTail1 = identTokens.headAndTail();
|
|
124
124
|
let { head, tail } = headAndTail1;
|
|
125
125
|
if (!head) {
|
|
126
126
|
// Never
|
|
@@ -205,7 +205,7 @@ const checkAutoComplete = () => value => {
|
|
|
205
205
|
return (0, match_result_1.matched)();
|
|
206
206
|
}
|
|
207
207
|
if (!contactableFiledToken.match(contactableFieldNames, true)) {
|
|
208
|
-
const
|
|
208
|
+
const candidate = (0, get_candidate_1.getCandidate)(contactableFiledToken.value, contactableFieldNames);
|
|
209
209
|
acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, contactableFiledToken.value);
|
|
210
210
|
return contactableFiledToken.unmatched({
|
|
211
211
|
reason: 'unexpected-token',
|
|
@@ -213,7 +213,7 @@ const checkAutoComplete = () => value => {
|
|
|
213
213
|
type: 'const',
|
|
214
214
|
value: token,
|
|
215
215
|
})),
|
|
216
|
-
|
|
216
|
+
candidate,
|
|
217
217
|
ref: URL_CONTACTABLE_FIELD,
|
|
218
218
|
});
|
|
219
219
|
}
|
|
@@ -221,9 +221,9 @@ const checkAutoComplete = () => value => {
|
|
|
221
221
|
if (tail[1].match(webauthnFieldNames)) {
|
|
222
222
|
return (0, match_result_1.matched)();
|
|
223
223
|
}
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
226
|
-
acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[1].value,
|
|
224
|
+
const candidate = (0, get_candidate_1.getCandidate)(tail[1].value, webauthnFieldNames);
|
|
225
|
+
if (candidate) {
|
|
226
|
+
acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[1].value, candidate);
|
|
227
227
|
}
|
|
228
228
|
else {
|
|
229
229
|
acLog('[Unmatched ("%s")] Unnecessarily token: "%s"', value, tail[1].value);
|
|
@@ -246,9 +246,9 @@ const checkAutoComplete = () => value => {
|
|
|
246
246
|
if (tail[0].match(webauthnFieldNames)) {
|
|
247
247
|
return (0, match_result_1.matched)();
|
|
248
248
|
}
|
|
249
|
-
const
|
|
250
|
-
if (
|
|
251
|
-
acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[0].value,
|
|
249
|
+
const candidate = (0, get_candidate_1.getCandidate)(tail[0].value, webauthnFieldNames);
|
|
250
|
+
if (candidate) {
|
|
251
|
+
acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[0].value, candidate);
|
|
252
252
|
}
|
|
253
253
|
else {
|
|
254
254
|
acLog('[Unmatched ("%s")] Unnecessarily token: "%s"', value, tail[0].value);
|
|
@@ -275,7 +275,7 @@ const checkAutoComplete = () => value => {
|
|
|
275
275
|
value: 'autofill field name',
|
|
276
276
|
},
|
|
277
277
|
];
|
|
278
|
-
let
|
|
278
|
+
let candidate;
|
|
279
279
|
if (!hasNamedGroup) {
|
|
280
280
|
expects.unshift({
|
|
281
281
|
type: 'common',
|
|
@@ -283,9 +283,9 @@ const checkAutoComplete = () => value => {
|
|
|
283
283
|
});
|
|
284
284
|
// Potentially typo a named group
|
|
285
285
|
const [prefix, namedGroupStr] = head.value.split('-');
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
|
|
286
|
+
const candidatePrefix = (0, get_candidate_1.getCandidate)(prefix, 'section');
|
|
287
|
+
if (candidatePrefix) {
|
|
288
|
+
candidate = `${candidatePrefix}-${namedGroupStr || ''}`;
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
else if (!hasPartOfAddress) {
|
|
@@ -296,18 +296,18 @@ const checkAutoComplete = () => value => {
|
|
|
296
296
|
type: 'const',
|
|
297
297
|
value: token,
|
|
298
298
|
})));
|
|
299
|
-
|
|
299
|
+
candidate = (0, get_candidate_1.getCandidate)(head.value, partOfAddress, autofillFieldNames, contactingTokens, contactableFieldNames);
|
|
300
300
|
}
|
|
301
301
|
else if (!hasContactingToken) {
|
|
302
302
|
expects.push(...contactingTokens.slice().map(token => ({
|
|
303
303
|
type: 'const',
|
|
304
304
|
value: token,
|
|
305
305
|
})));
|
|
306
|
-
|
|
306
|
+
candidate = (0, get_candidate_1.getCandidate)(head.value, autofillFieldNames, contactingTokens, contactableFieldNames);
|
|
307
307
|
}
|
|
308
|
-
|
|
309
|
-
if (
|
|
310
|
-
acLog('[Unmatched ("%s")] Unexpected token: "%s", Do you mean "%s"? ', value, head.value,
|
|
308
|
+
candidate = candidate || (0, get_candidate_1.getCandidate)(head.value, autofillFieldNames);
|
|
309
|
+
if (candidate) {
|
|
310
|
+
acLog('[Unmatched ("%s")] Unexpected token: "%s", Do you mean "%s"? ', value, head.value, candidate);
|
|
311
311
|
}
|
|
312
312
|
else {
|
|
313
313
|
acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, head.value);
|
|
@@ -315,7 +315,7 @@ const checkAutoComplete = () => value => {
|
|
|
315
315
|
return head.unmatched({
|
|
316
316
|
reason: 'unexpected-token',
|
|
317
317
|
expects,
|
|
318
|
-
|
|
318
|
+
candidate,
|
|
319
319
|
ref: URL_AUTOFILL_FIELD,
|
|
320
320
|
});
|
|
321
321
|
};
|
|
@@ -48,7 +48,7 @@ test('unexpected-token', () => {
|
|
|
48
48
|
{ type: 'const', value: 'shipping' },
|
|
49
49
|
{ type: 'common', value: 'autofill field name' },
|
|
50
50
|
],
|
|
51
|
-
|
|
51
|
+
candidate: undefined,
|
|
52
52
|
ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
|
|
53
53
|
});
|
|
54
54
|
});
|
|
@@ -65,7 +65,7 @@ test('unexpected-token', () => {
|
|
|
65
65
|
{ type: 'common', value: 'autofill named group' },
|
|
66
66
|
{ type: 'common', value: 'autofill field name' },
|
|
67
67
|
],
|
|
68
|
-
|
|
68
|
+
candidate: undefined,
|
|
69
69
|
ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
|
|
70
70
|
});
|
|
71
71
|
});
|
|
@@ -83,7 +83,7 @@ test('unexpected-token', () => {
|
|
|
83
83
|
{ type: 'const', value: 'shipping' },
|
|
84
84
|
{ type: 'common', value: 'autofill field name' },
|
|
85
85
|
],
|
|
86
|
-
|
|
86
|
+
candidate: 'name',
|
|
87
87
|
ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
|
|
88
88
|
});
|
|
89
89
|
expect(check('section-foo shipping neme')).toStrictEqual({
|
|
@@ -102,12 +102,12 @@ test('unexpected-token', () => {
|
|
|
102
102
|
{ type: 'const', value: 'fax' },
|
|
103
103
|
{ type: 'const', value: 'pager' },
|
|
104
104
|
],
|
|
105
|
-
|
|
105
|
+
candidate: 'name',
|
|
106
106
|
ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
|
|
107
107
|
});
|
|
108
|
-
expect(check('section-foo shipping home
|
|
108
|
+
expect(check('section-foo shipping home name')).toStrictEqual({
|
|
109
109
|
matched: false,
|
|
110
|
-
raw: '
|
|
110
|
+
raw: 'name',
|
|
111
111
|
offset: 26,
|
|
112
112
|
length: 4,
|
|
113
113
|
line: 1,
|
|
@@ -125,7 +125,7 @@ test('unexpected-token', () => {
|
|
|
125
125
|
{ type: 'const', value: 'email' },
|
|
126
126
|
{ type: 'const', value: 'impp' },
|
|
127
127
|
],
|
|
128
|
-
|
|
128
|
+
candidate: undefined,
|
|
129
129
|
ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-tel',
|
|
130
130
|
});
|
|
131
131
|
expect(check('section-foo shipping home emall')).toStrictEqual({
|
|
@@ -148,7 +148,7 @@ test('unexpected-token', () => {
|
|
|
148
148
|
{ type: 'const', value: 'email' },
|
|
149
149
|
{ type: 'const', value: 'impp' },
|
|
150
150
|
],
|
|
151
|
-
|
|
151
|
+
candidate: 'email',
|
|
152
152
|
ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-tel',
|
|
153
153
|
});
|
|
154
154
|
});
|
|
@@ -373,7 +373,7 @@ test('typo', () => {
|
|
|
373
373
|
{ type: 'common', value: 'autofill named group' },
|
|
374
374
|
{ type: 'common', value: 'autofill field name' },
|
|
375
375
|
],
|
|
376
|
-
|
|
376
|
+
candidate: 'section-foo',
|
|
377
377
|
ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
|
|
378
378
|
});
|
|
379
379
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenEachCheck } from '../../token/token-collection';
|
|
2
|
-
export declare const datetimeTokenCheck: Record<'year' | 'month' | 'date' | 'hour' | 'minute' | 'second' | 'secondFractionalPart' | 'week' | 'hyphen' | '
|
|
2
|
+
export declare const datetimeTokenCheck: Record<'year' | 'month' | 'date' | 'hour' | 'minute' | 'second' | 'secondFractionalPart' | 'week' | 'hyphen' | 'colon' | 'extra' | 'colonOrEnd' | 'decimalPointOrEnd' | 'localDateTimeSeparator' | 'normalizedlocalDateTimeSeparator' | 'plusOrMinusSign' | 'weekSign', TokenEachCheck> & Record<'_year' | '_month', number | null>;
|
|
3
3
|
export declare function getMaxWeekNum(year: number): number;
|
|
@@ -317,18 +317,18 @@ exports.datetimeTokenCheck = {
|
|
|
317
317
|
/**
|
|
318
318
|
* > A U+003A COLON character (:)
|
|
319
319
|
*/
|
|
320
|
-
|
|
321
|
-
(0, debug_1.log)('Parsing Datetime
|
|
322
|
-
if (!
|
|
320
|
+
colon(colon) {
|
|
321
|
+
(0, debug_1.log)('Parsing Datetime colon: "%s"', colon === null || colon === void 0 ? void 0 : colon.value);
|
|
322
|
+
if (!colon || !colon.value) {
|
|
323
323
|
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
324
|
-
expects: [{ type: 'common', value: '
|
|
324
|
+
expects: [{ type: 'common', value: 'colon' }],
|
|
325
325
|
partName: 'time',
|
|
326
326
|
});
|
|
327
327
|
}
|
|
328
|
-
if (!
|
|
329
|
-
return
|
|
328
|
+
if (!colon.match(':')) {
|
|
329
|
+
return colon.unmatched({
|
|
330
330
|
reason: 'unexpected-token',
|
|
331
|
-
expects: [{ type: 'common', value: '
|
|
331
|
+
expects: [{ type: 'common', value: 'colon' }],
|
|
332
332
|
partName: 'time',
|
|
333
333
|
});
|
|
334
334
|
}
|
|
@@ -338,14 +338,14 @@ exports.datetimeTokenCheck = {
|
|
|
338
338
|
* or
|
|
339
339
|
* End of token
|
|
340
340
|
*/
|
|
341
|
-
|
|
342
|
-
if (!
|
|
341
|
+
colonOrEnd(colon) {
|
|
342
|
+
if (!colon || !colon.value) {
|
|
343
343
|
return (0, match_result_1.matched)();
|
|
344
344
|
}
|
|
345
|
-
if (!
|
|
346
|
-
return
|
|
345
|
+
if (!colon.match(':')) {
|
|
346
|
+
return colon.unmatched({
|
|
347
347
|
reason: 'unexpected-token',
|
|
348
|
-
expects: [{ type: 'common', value: '
|
|
348
|
+
expects: [{ type: 'common', value: 'colon' }],
|
|
349
349
|
partName: 'time',
|
|
350
350
|
});
|
|
351
351
|
}
|
|
@@ -413,8 +413,8 @@ exports.datetimeTokenCheck = {
|
|
|
413
413
|
* > a U+002D HYPHEN-MINUS character (-),
|
|
414
414
|
* > representing the sign of the time-zone offset
|
|
415
415
|
*/
|
|
416
|
-
plusOrMinusSign(
|
|
417
|
-
if (!
|
|
416
|
+
plusOrMinusSign(colon) {
|
|
417
|
+
if (!colon) {
|
|
418
418
|
return (0, match_result_1.unmatched)('', 'missing-token', {
|
|
419
419
|
expects: [
|
|
420
420
|
{ type: 'const', value: '+' },
|
|
@@ -423,8 +423,8 @@ exports.datetimeTokenCheck = {
|
|
|
423
423
|
partName: 'time-zone',
|
|
424
424
|
});
|
|
425
425
|
}
|
|
426
|
-
if (!
|
|
427
|
-
return
|
|
426
|
+
if (!colon.match(['+', '-'])) {
|
|
427
|
+
return colon.unmatched({
|
|
428
428
|
reason: 'unexpected-token',
|
|
429
429
|
expects: [
|
|
430
430
|
{ type: 'const', value: '+' },
|
|
@@ -36,13 +36,13 @@ const checkGlobalDateAndTimeString = () => function checkGlobalDateAndTimeString
|
|
|
36
36
|
/.*/,
|
|
37
37
|
]);
|
|
38
38
|
(0, debug_1.log)('Global Date and Time "%s" => %O', tokens.value, tokens);
|
|
39
|
-
const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.localDateTimeSeparator, datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.
|
|
39
|
+
const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.localDateTimeSeparator, datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.colon, datetime_tokens_1.datetimeTokenCheck.minute, second => {
|
|
40
40
|
if (!second || !second.value) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
const secondTokens = token_1.TokenCollection.fromPatterns(second, [/:?/, /[0-9]*/, /\.?/, /[0-9]*/]);
|
|
44
|
-
(0, debug_1.log)('
|
|
45
|
-
const res = secondTokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.
|
|
44
|
+
(0, debug_1.log)('Second Part: "%s" => %O', secondTokens.value, secondTokens);
|
|
45
|
+
const res = secondTokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.colon, datetime_tokens_1.datetimeTokenCheck.second, datetime_tokens_1.datetimeTokenCheck.decimalPointOrEnd, datetime_tokens_1.datetimeTokenCheck.secondFractionalPart);
|
|
46
46
|
if (!res.matched) {
|
|
47
47
|
return res;
|
|
48
48
|
}
|
|
@@ -38,7 +38,7 @@ const checkLocalDateAndTimeString = () => function checkLocalDateAndTimeString(v
|
|
|
38
38
|
/.[0-9]*/,
|
|
39
39
|
]);
|
|
40
40
|
(0, debug_1.log)('Local Date and Time: "%s" => %O', tokens.value, tokens);
|
|
41
|
-
const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.localDateTimeSeparator, datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.
|
|
41
|
+
const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.localDateTimeSeparator, datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.colon, datetime_tokens_1.datetimeTokenCheck.minute, datetime_tokens_1.datetimeTokenCheck.colonOrEnd, datetime_tokens_1.datetimeTokenCheck.second, datetime_tokens_1.datetimeTokenCheck.decimalPointOrEnd, datetime_tokens_1.datetimeTokenCheck.secondFractionalPart, datetime_tokens_1.datetimeTokenCheck.extra);
|
|
42
42
|
if (!res.matched) {
|
|
43
43
|
(0, debug_1.log)('Failed: %O', res);
|
|
44
44
|
}
|
|
@@ -79,7 +79,7 @@ const checkNormalizedLocalDateAndTimeString = () => function checkNormalizedLoca
|
|
|
79
79
|
/.[0-9]*/,
|
|
80
80
|
]);
|
|
81
81
|
(0, debug_1.log)('Normalized Local Date and Time: "%s" => %O', tokens.value, tokens);
|
|
82
|
-
const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.normalizedlocalDateTimeSeparator, datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.
|
|
82
|
+
const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.year, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.month, datetime_tokens_1.datetimeTokenCheck.hyphen, datetime_tokens_1.datetimeTokenCheck.date, datetime_tokens_1.datetimeTokenCheck.normalizedlocalDateTimeSeparator, datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.colon, datetime_tokens_1.datetimeTokenCheck.minute, datetime_tokens_1.datetimeTokenCheck.colonOrEnd, datetime_tokens_1.datetimeTokenCheck.second, datetime_tokens_1.datetimeTokenCheck.decimalPointOrEnd, datetime_tokens_1.datetimeTokenCheck.secondFractionalPart, datetime_tokens_1.datetimeTokenCheck.extra);
|
|
83
83
|
if (!res.matched) {
|
|
84
84
|
(0, debug_1.log)('Failed: %O', res);
|
|
85
85
|
return res;
|
|
@@ -26,7 +26,7 @@ const checkTimeString = () => function checkTimeString(value) {
|
|
|
26
26
|
/.[0-9]*/,
|
|
27
27
|
]);
|
|
28
28
|
(0, debug_1.log)('Time: "%s" => %O', tokens.value, tokens);
|
|
29
|
-
const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.
|
|
29
|
+
const res = tokens.eachCheck(datetime_tokens_1.datetimeTokenCheck.hour, datetime_tokens_1.datetimeTokenCheck.colon, datetime_tokens_1.datetimeTokenCheck.minute, datetime_tokens_1.datetimeTokenCheck.colonOrEnd, datetime_tokens_1.datetimeTokenCheck.second, datetime_tokens_1.datetimeTokenCheck.decimalPointOrEnd, datetime_tokens_1.datetimeTokenCheck.secondFractionalPart);
|
|
30
30
|
if (!res.matched) {
|
|
31
31
|
(0, debug_1.log)('Failed: %O', res);
|
|
32
32
|
}
|
|
@@ -55,12 +55,12 @@ function parseTimeZone(zone) {
|
|
|
55
55
|
partName: 'time-zone',
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
}, datetime_tokens_1.datetimeTokenCheck.hour,
|
|
59
|
-
if (!
|
|
58
|
+
}, datetime_tokens_1.datetimeTokenCheck.hour, colon => {
|
|
59
|
+
if (!colon || !colon.value) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
if (!
|
|
63
|
-
return
|
|
62
|
+
if (!colon.match(':')) {
|
|
63
|
+
return colon.unmatched({
|
|
64
64
|
reason: 'unexpected-token',
|
|
65
65
|
expects: [{ type: 'const', value: ':' }],
|
|
66
66
|
partName: 'time-zone',
|
|
@@ -34,7 +34,7 @@ const checkMIMEType = options => value => {
|
|
|
34
34
|
return new token_1.Token(extraToken, mimeType.essence.length, value).unmatched({
|
|
35
35
|
reason: 'extra-token',
|
|
36
36
|
expects: expects(withoutParameters),
|
|
37
|
-
|
|
37
|
+
candidate: mimeType.essence,
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
return (0, match_result_1.unmatched)(value, 'syntax-error', { expects: expects(withoutParameters) });
|
|
@@ -20,7 +20,7 @@ test('excrescence-token', () => {
|
|
|
20
20
|
ref: null,
|
|
21
21
|
});
|
|
22
22
|
expect(check('x/y;')).toStrictEqual({
|
|
23
|
-
|
|
23
|
+
candidate: 'x/y',
|
|
24
24
|
column: 4,
|
|
25
25
|
expects: [{ type: 'format', value: 'MIME Type' }],
|
|
26
26
|
length: 1,
|
|
@@ -32,7 +32,7 @@ test('excrescence-token', () => {
|
|
|
32
32
|
ref: null,
|
|
33
33
|
});
|
|
34
34
|
expect(checkNoParam('x/y;')).toStrictEqual({
|
|
35
|
-
|
|
35
|
+
candidate: 'x/y',
|
|
36
36
|
column: 4,
|
|
37
37
|
expects: [{ type: 'format', value: 'MIME Type with no parameters' }],
|
|
38
38
|
length: 1,
|
|
@@ -44,7 +44,7 @@ test('excrescence-token', () => {
|
|
|
44
44
|
ref: null,
|
|
45
45
|
});
|
|
46
46
|
expect(checkNoParam('x/y;a=b;c=D;E="F"')).toStrictEqual({
|
|
47
|
-
|
|
47
|
+
candidate: 'x/y',
|
|
48
48
|
column: 4,
|
|
49
49
|
expects: [{ type: 'format', value: 'MIME Type with no parameters' }],
|
|
50
50
|
length: 14,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
4
4
|
"description": "Types of attributes and properties and more",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/bcp-47": "1",
|
|
28
|
-
"@types/css-tree": "
|
|
28
|
+
"@types/css-tree": "1",
|
|
29
29
|
"@types/debug": "^4.1.7",
|
|
30
|
-
"@types/whatwg-mimetype": "
|
|
30
|
+
"@types/whatwg-mimetype": "2"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "56de89456146a06777eb5b6d4e8ba456147dd18b"
|
|
33
33
|
}
|