@markuplint/types 2.0.0 → 2.2.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.
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkAutoComplete = void 0;
4
+ const debug_1 = require("../debug");
4
5
  const get_candicate_1 = require("../get-candicate");
5
6
  const match_result_1 = require("../match-result");
6
7
  const token_1 = require("../token");
8
+ const acLog = debug_1.log.extend('autocomplete');
7
9
  /**
8
10
  * https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-section
9
11
  */
@@ -80,6 +82,10 @@ const contactableFieldNames = [
80
82
  'email',
81
83
  'impp',
82
84
  ];
85
+ /**
86
+ * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-webauthn
87
+ */
88
+ const webauthnFieldNames = ['webauthn'];
83
89
  const URL_AUTOCOMPLET = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete';
84
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';
85
91
  const URL_NAMED_GROUP = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-section';
@@ -110,6 +116,7 @@ const checkAutoComplete = () => value => {
110
116
  ref: URL_AUTOCOMPLET,
111
117
  });
112
118
  if (!listingChecked.matched) {
119
+ acLog('Unmatch: %s', listingChecked.reason);
113
120
  return listingChecked;
114
121
  }
115
122
  const idents = tokens.getIdentTokens();
@@ -126,6 +133,7 @@ const checkAutoComplete = () => value => {
126
133
  // > (i.e. the "on" and "off" keywords are not allowed).
127
134
  if (head.match(['on', 'off'], true)) {
128
135
  if (tail.length) {
136
+ acLog('[Unmatched ("%s")] Unexpected pair with "on" or "off": "%s"', value, tail.value);
129
137
  return tail[0].unmatched({
130
138
  reason: 'extra-token',
131
139
  expects: [
@@ -146,6 +154,7 @@ const checkAutoComplete = () => value => {
146
154
  hasNamedGroup = true;
147
155
  const sectionToken = tail.search(namedGroup);
148
156
  if (sectionToken) {
157
+ acLog('[Unmatched ("%s")] Deprecated in autofill named group: "%s"', value, sectionToken.value);
149
158
  return sectionToken.unmatched({
150
159
  partName: 'autofill named group',
151
160
  reason: 'duplicated',
@@ -168,6 +177,7 @@ const checkAutoComplete = () => value => {
168
177
  hasPartOfAddress = true;
169
178
  const partToken = tail.search(partOfAddress);
170
179
  if (partToken) {
180
+ acLog('[Unmatched ("%s")] Duplicated values: "%s"', value, partToken.value);
171
181
  return partToken.unmatched({
172
182
  reason: 'duplicated',
173
183
  expects: [
@@ -196,6 +206,7 @@ const checkAutoComplete = () => value => {
196
206
  }
197
207
  if (!contactableFiledToken.match(contactableFieldNames, true)) {
198
208
  const candicate = (0, get_candicate_1.getCandicate)(contactableFiledToken.value, contactableFieldNames);
209
+ acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, contactableFiledToken.value);
199
210
  return contactableFiledToken.unmatched({
200
211
  reason: 'unexpected-token',
201
212
  expects: contactableFieldNames.slice().map(token => ({
@@ -207,6 +218,16 @@ const checkAutoComplete = () => value => {
207
218
  });
208
219
  }
209
220
  if (tail[1]) {
221
+ if (tail[1].match(webauthnFieldNames)) {
222
+ return (0, match_result_1.matched)();
223
+ }
224
+ const candicate = (0, get_candicate_1.getCandicate)(tail[1].value, webauthnFieldNames);
225
+ if (candicate) {
226
+ acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[1].value, candicate);
227
+ }
228
+ else {
229
+ acLog('[Unmatched ("%s")] Unnecessarily token: "%s"', value, tail[1].value);
230
+ }
210
231
  return tail[1].unmatched({
211
232
  reason: 'extra-token',
212
233
  expects: [
@@ -222,6 +243,16 @@ const checkAutoComplete = () => value => {
222
243
  }
223
244
  if (head.match([...autofillFieldNames, ...contactableFieldNames], true)) {
224
245
  if (tail.length) {
246
+ if (tail[0].match(webauthnFieldNames)) {
247
+ return (0, match_result_1.matched)();
248
+ }
249
+ const candicate = (0, get_candicate_1.getCandicate)(tail[0].value, webauthnFieldNames);
250
+ if (candicate) {
251
+ acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[0].value, candicate);
252
+ }
253
+ else {
254
+ acLog('[Unmatched ("%s")] Unnecessarily token: "%s"', value, tail[0].value);
255
+ }
225
256
  return tail[0].unmatched({
226
257
  reason: 'extra-token',
227
258
  expects: [
@@ -235,6 +266,9 @@ const checkAutoComplete = () => value => {
235
266
  }
236
267
  return (0, match_result_1.matched)();
237
268
  }
269
+ if (head.match(webauthnFieldNames)) {
270
+ return (0, match_result_1.matched)();
271
+ }
238
272
  const expects = [
239
273
  {
240
274
  type: 'common',
@@ -272,6 +306,12 @@ const checkAutoComplete = () => value => {
272
306
  candicate = (0, get_candicate_1.getCandicate)(head.value, autofillFieldNames, contactingTokens, contactableFieldNames);
273
307
  }
274
308
  candicate = candicate || (0, get_candicate_1.getCandicate)(head.value, autofillFieldNames);
309
+ if (candicate) {
310
+ acLog('[Unmatched ("%s")] Unexpected token: "%s", Do you mean "%s"? ', value, head.value, candicate);
311
+ }
312
+ else {
313
+ acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, head.value);
314
+ }
275
315
  return head.unmatched({
276
316
  reason: 'unexpected-token',
277
317
  expects,
@@ -2,28 +2,37 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const check_autocomplete_1 = require("./check-autocomplete");
4
4
  const check = (0, check_autocomplete_1.checkAutoComplete)();
5
- test('valid', () => {
5
+ test('basic', () => {
6
6
  expect(check('on').matched).toBe(true);
7
+ expect(check('on webauthn').matched).toBe(false);
7
8
  expect(check('off').matched).toBe(true);
9
+ expect(check('off webauthn').matched).toBe(false);
8
10
  expect(check('name').matched).toBe(true);
9
11
  expect(check('given-name').matched).toBe(true);
12
+ expect(check('given-name webauthn').matched).toBe(true);
13
+ expect(check('given-name webauthun').matched).toBe(false);
10
14
  expect(check('section-').matched).toBe(true);
11
15
  expect(check('section-foo').matched).toBe(true);
16
+ expect(check('section-foo webauthn').matched).toBe(true);
12
17
  expect(check('section-foo name').matched).toBe(true);
18
+ expect(check('section-foo name webauthn').matched).toBe(true);
13
19
  expect(check('section-foo shipping name').matched).toBe(true);
14
20
  expect(check('section-foo billing name').matched).toBe(true);
15
21
  expect(check('section-foo billing home').matched).toBe(true);
16
22
  expect(check('section-foo billing work').matched).toBe(true);
17
23
  expect(check('section-foo billing home tel').matched).toBe(true);
18
24
  expect(check('section-foo billing work email').matched).toBe(true);
25
+ expect(check('section-foo billing work email webauthn').matched).toBe(true);
19
26
  expect(check('shipping name').matched).toBe(true);
20
27
  expect(check('billing name').matched).toBe(true);
21
28
  expect(check('billing home').matched).toBe(true);
22
29
  expect(check('billing work').matched).toBe(true);
23
30
  expect(check('billing home tel').matched).toBe(true);
24
31
  expect(check('billing work email').matched).toBe(true);
32
+ expect(check('billing work email webauthn').matched).toBe(true);
25
33
  expect(check('home tel').matched).toBe(true);
26
34
  expect(check('work email').matched).toBe(true);
35
+ expect(check('work email webauthn').matched).toBe(true);
27
36
  });
28
37
  test('unexpected-token', () => {
29
38
  expect(check('section-foo , name')).toStrictEqual({
@@ -1,23 +1,3 @@
1
1
  import type { TokenEachCheck } from '../../token/token-collection';
2
- export declare const datetimeTokenCheck: Record<
3
- | 'year'
4
- | 'month'
5
- | 'date'
6
- | 'hour'
7
- | 'minute'
8
- | 'second'
9
- | 'secondFractionalPart'
10
- | 'week'
11
- | 'hyphen'
12
- | 'coron'
13
- | 'extra'
14
- | 'coronOrEnd'
15
- | 'decimalPointOrEnd'
16
- | 'localDateTimeSeparator'
17
- | 'normalizedlocalDateTimeSeparator'
18
- | 'plusOrMinusSign'
19
- | 'weekSign',
20
- TokenEachCheck
21
- > &
22
- Record<'_year' | '_month', number | null>;
2
+ export declare const datetimeTokenCheck: Record<'year' | 'month' | 'date' | 'hour' | 'minute' | 'second' | 'secondFractionalPart' | 'week' | 'hyphen' | 'coron' | 'extra' | 'coronOrEnd' | 'decimalPointOrEnd' | 'localDateTimeSeparator' | 'normalizedlocalDateTimeSeparator' | 'plusOrMinusSign' | 'weekSign', TokenEachCheck> & Record<'_year' | '_month', number | null>;
23
3
  export declare function getMaxWeekNum(year: number): number;
@@ -4,4 +4,4 @@ import type { CustomSyntaxChecker } from '../../types';
4
4
  * @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#time-zones
5
5
  */
6
6
  export declare const checkTimeZoneOffsetString: CustomSyntaxChecker;
7
- export declare function parseTimeZone(zone: string | Token): import('../../types').Result;
7
+ export declare function parseTimeZone(zone: string | Token): import("../../types").Result;
@@ -4,8 +4,8 @@ import type { CustomSyntaxChecker } from '../types';
4
4
  * @see https://mimesniff.spec.whatwg.org/#valid-mime-type
5
5
  */
6
6
  export declare const checkMIMEType: CustomSyntaxChecker<{
7
- /**
8
- * @see https://mimesniff.spec.whatwg.org/#valid-mime-type-with-no-parameters
9
- */
10
- withoutParameters?: boolean;
7
+ /**
8
+ * @see https://mimesniff.spec.whatwg.org/#valid-mime-type-with-no-parameters
9
+ */
10
+ withoutParameters?: boolean;
11
11
  }>;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkMIMEType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  // @ts-ignore
6
- const whatwg_mimetype_1 = (0, tslib_1.__importDefault)(require("whatwg-mimetype"));
6
+ const whatwg_mimetype_1 = tslib_1.__importDefault(require("whatwg-mimetype"));
7
7
  const match_result_1 = require("../match-result");
8
8
  const token_1 = require("../token");
9
9
  const expects = (withoutParameters) => [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/types",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
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>",
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "bcp-47": "1",
21
21
  "css-tree": "1",
22
- "debug": "^4.3.3",
22
+ "debug": "^4.3.4",
23
23
  "leven": "3",
24
24
  "whatwg-mimetype": "2"
25
25
  },
@@ -29,5 +29,5 @@
29
29
  "@types/debug": "^4.1.7",
30
30
  "@types/whatwg-mimetype": "^2.1.1"
31
31
  },
32
- "gitHead": "de81fc514acdf472f87184e3499e9364258f9b66"
32
+ "gitHead": "c28258b756d8c42890698e26c03cdc02c6833489"
33
33
  }
@@ -2,28 +2,37 @@ import { checkAutoComplete } from './check-autocomplete';
2
2
 
3
3
  const check = checkAutoComplete();
4
4
 
5
- test('valid', () => {
5
+ test('basic', () => {
6
6
  expect(check('on').matched).toBe(true);
7
+ expect(check('on webauthn').matched).toBe(false);
7
8
  expect(check('off').matched).toBe(true);
9
+ expect(check('off webauthn').matched).toBe(false);
8
10
  expect(check('name').matched).toBe(true);
9
11
  expect(check('given-name').matched).toBe(true);
12
+ expect(check('given-name webauthn').matched).toBe(true);
13
+ expect(check('given-name webauthun').matched).toBe(false);
10
14
  expect(check('section-').matched).toBe(true);
11
15
  expect(check('section-foo').matched).toBe(true);
16
+ expect(check('section-foo webauthn').matched).toBe(true);
12
17
  expect(check('section-foo name').matched).toBe(true);
18
+ expect(check('section-foo name webauthn').matched).toBe(true);
13
19
  expect(check('section-foo shipping name').matched).toBe(true);
14
20
  expect(check('section-foo billing name').matched).toBe(true);
15
21
  expect(check('section-foo billing home').matched).toBe(true);
16
22
  expect(check('section-foo billing work').matched).toBe(true);
17
23
  expect(check('section-foo billing home tel').matched).toBe(true);
18
24
  expect(check('section-foo billing work email').matched).toBe(true);
25
+ expect(check('section-foo billing work email webauthn').matched).toBe(true);
19
26
  expect(check('shipping name').matched).toBe(true);
20
27
  expect(check('billing name').matched).toBe(true);
21
28
  expect(check('billing home').matched).toBe(true);
22
29
  expect(check('billing work').matched).toBe(true);
23
30
  expect(check('billing home tel').matched).toBe(true);
24
31
  expect(check('billing work email').matched).toBe(true);
32
+ expect(check('billing work email webauthn').matched).toBe(true);
25
33
  expect(check('home tel').matched).toBe(true);
26
34
  expect(check('work email').matched).toBe(true);
35
+ expect(check('work email webauthn').matched).toBe(true);
27
36
  });
28
37
 
29
38
  test('unexpected-token', () => {
@@ -1,10 +1,13 @@
1
1
  import type { Expect } from '..';
2
2
  import type { CustomSyntaxChecker } from '../types';
3
3
 
4
+ import { log } from '../debug';
4
5
  import { getCandicate } from '../get-candicate';
5
6
  import { matched } from '../match-result';
6
7
  import { TokenCollection } from '../token';
7
8
 
9
+ const acLog = log.extend('autocomplete');
10
+
8
11
  /**
9
12
  * https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-section
10
13
  */
@@ -86,6 +89,11 @@ const contactableFieldNames = [
86
89
  'impp',
87
90
  ];
88
91
 
92
+ /**
93
+ * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-webauthn
94
+ */
95
+ const webauthnFieldNames = ['webauthn'];
96
+
89
97
  const URL_AUTOCOMPLET = 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete';
90
98
  const URL_ON_OFF =
91
99
  'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-on-2';
@@ -123,6 +131,7 @@ export const checkAutoComplete: CustomSyntaxChecker = () => value => {
123
131
  ref: URL_AUTOCOMPLET,
124
132
  });
125
133
  if (!listingChecked.matched) {
134
+ acLog('Unmatch: %s', listingChecked.reason);
126
135
  return listingChecked;
127
136
  }
128
137
 
@@ -141,6 +150,7 @@ export const checkAutoComplete: CustomSyntaxChecker = () => value => {
141
150
  // > (i.e. the "on" and "off" keywords are not allowed).
142
151
  if (head.match(['on', 'off'], true)) {
143
152
  if (tail.length) {
153
+ acLog('[Unmatched ("%s")] Unexpected pair with "on" or "off": "%s"', value, tail.value);
144
154
  return tail[0].unmatched({
145
155
  reason: 'extra-token',
146
156
  expects: [
@@ -163,6 +173,7 @@ export const checkAutoComplete: CustomSyntaxChecker = () => value => {
163
173
  hasNamedGroup = true;
164
174
  const sectionToken = tail.search(namedGroup);
165
175
  if (sectionToken) {
176
+ acLog('[Unmatched ("%s")] Deprecated in autofill named group: "%s"', value, sectionToken.value);
166
177
  return sectionToken.unmatched({
167
178
  partName: 'autofill named group',
168
179
  reason: 'duplicated',
@@ -188,6 +199,7 @@ export const checkAutoComplete: CustomSyntaxChecker = () => value => {
188
199
  hasPartOfAddress = true;
189
200
  const partToken = tail.search(partOfAddress);
190
201
  if (partToken) {
202
+ acLog('[Unmatched ("%s")] Duplicated values: "%s"', value, partToken.value);
191
203
  return partToken.unmatched({
192
204
  reason: 'duplicated',
193
205
  expects: [
@@ -220,6 +232,7 @@ export const checkAutoComplete: CustomSyntaxChecker = () => value => {
220
232
 
221
233
  if (!contactableFiledToken.match(contactableFieldNames, true)) {
222
234
  const candicate = getCandicate(contactableFiledToken.value, contactableFieldNames);
235
+ acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, contactableFiledToken.value);
223
236
  return contactableFiledToken.unmatched({
224
237
  reason: 'unexpected-token',
225
238
  expects: contactableFieldNames.slice().map(token => ({
@@ -232,6 +245,23 @@ export const checkAutoComplete: CustomSyntaxChecker = () => value => {
232
245
  }
233
246
 
234
247
  if (tail[1]) {
248
+ if (tail[1].match(webauthnFieldNames)) {
249
+ return matched();
250
+ }
251
+
252
+ const candicate = getCandicate(tail[1].value, webauthnFieldNames);
253
+
254
+ if (candicate) {
255
+ acLog(
256
+ '[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ',
257
+ value,
258
+ tail[1].value,
259
+ candicate,
260
+ );
261
+ } else {
262
+ acLog('[Unmatched ("%s")] Unnecessarily token: "%s"', value, tail[1].value);
263
+ }
264
+
235
265
  return tail[1].unmatched({
236
266
  reason: 'extra-token',
237
267
  expects: [
@@ -249,6 +279,23 @@ export const checkAutoComplete: CustomSyntaxChecker = () => value => {
249
279
 
250
280
  if (head.match([...autofillFieldNames, ...contactableFieldNames], true)) {
251
281
  if (tail.length) {
282
+ if (tail[0].match(webauthnFieldNames)) {
283
+ return matched();
284
+ }
285
+
286
+ const candicate = getCandicate(tail[0].value, webauthnFieldNames);
287
+
288
+ if (candicate) {
289
+ acLog(
290
+ '[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ',
291
+ value,
292
+ tail[0].value,
293
+ candicate,
294
+ );
295
+ } else {
296
+ acLog('[Unmatched ("%s")] Unnecessarily token: "%s"', value, tail[0].value);
297
+ }
298
+
252
299
  return tail[0].unmatched({
253
300
  reason: 'extra-token',
254
301
  expects: [
@@ -264,6 +311,10 @@ export const checkAutoComplete: CustomSyntaxChecker = () => value => {
264
311
  return matched();
265
312
  }
266
313
 
314
+ if (head.match(webauthnFieldNames)) {
315
+ return matched();
316
+ }
317
+
267
318
  const expects: Expect[] = [
268
319
  {
269
320
  type: 'common',
@@ -315,6 +366,11 @@ export const checkAutoComplete: CustomSyntaxChecker = () => value => {
315
366
 
316
367
  candicate = candicate || getCandicate(head.value, autofillFieldNames);
317
368
 
369
+ if (candicate) {
370
+ acLog('[Unmatched ("%s")] Unexpected token: "%s", Do you mean "%s"? ', value, head.value, candicate);
371
+ } else {
372
+ acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, head.value);
373
+ }
318
374
  return head.unmatched({
319
375
  reason: 'unexpected-token',
320
376
  expects,