@markuplint/rules 2.0.0-dev.2021117.1 → 2.0.0-dev.20211213.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.
@@ -0,0 +1,270 @@
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 unnecessaryPart;
29
+ let candicatePart;
30
+ let expectOrNeed = 'expects';
31
+ if (matches.partName) {
32
+ if (matches.partName === 'the content of the list') {
33
+ target = 'the content of the list';
34
+ }
35
+ else {
36
+ target = t('{0} part of {1}', t('the {0}', matches.partName), target);
37
+ }
38
+ }
39
+ switch (matches.reason) {
40
+ case 'doesnt-exist-in-enum': {
41
+ break;
42
+ }
43
+ case 'duplicated': {
44
+ reasonPart = t('{0} is {1:c}', target, 'duplicated');
45
+ target = 'it';
46
+ break;
47
+ }
48
+ case 'empty-token': {
49
+ reasonPart = t('{0} must not be {1}', target, 'empty');
50
+ target = 'it';
51
+ break;
52
+ }
53
+ case 'extra-token': {
54
+ const token = matches.partName || 'token';
55
+ reasonPart = t('Found {0}', t('extra {0}', token)) + ' ' + t([matches.raw]);
56
+ if (matches.extra) {
57
+ const extra = expectValueToWord(t, matches.extra, 'Any');
58
+ unnecessaryPart = t("It doesn't need {0}", extra);
59
+ }
60
+ break;
61
+ }
62
+ case 'illegal-combination': {
63
+ reasonPart = t('Found {0}', t('an {0}', 'illegal combination'));
64
+ break;
65
+ }
66
+ case 'illegal-order': {
67
+ break;
68
+ }
69
+ case 'missing-comma': {
70
+ if (matches.partName) {
71
+ reasonPart = t('Missing {0} in {1}', t('a {0}', 'comma'), t('the {0} part', matches.partName));
72
+ target = 'it';
73
+ }
74
+ else {
75
+ reasonPart = t('Missing {0}', t('a {0}', 'comma'));
76
+ }
77
+ break;
78
+ }
79
+ case 'missing-token': {
80
+ if (matches.partName) {
81
+ const part = t('the {0} part', matches.partName);
82
+ reasonPart = t('Missing {0}', part);
83
+ if (!expected) {
84
+ expected = part;
85
+ target = baseTarget;
86
+ }
87
+ }
88
+ else {
89
+ reasonPart = t('Missing {0}', t('a {0}', 'token'));
90
+ }
91
+ expectOrNeed = 'needs';
92
+ break;
93
+ }
94
+ case 'must-be-percent-encoded': {
95
+ break;
96
+ }
97
+ case 'must-be-serialized': {
98
+ break;
99
+ }
100
+ case 'out-of-range': {
101
+ break;
102
+ }
103
+ case 'syntax-error': {
104
+ break;
105
+ }
106
+ case 'typo': {
107
+ break;
108
+ }
109
+ case 'unexpected-comma': {
110
+ reasonPart = t('Found {0}', t('unexpected {0}', 'comma'));
111
+ break;
112
+ }
113
+ case 'unexpected-newline': {
114
+ reasonPart = t('Found {0}', t('unexpected {0}', 'newline'));
115
+ break;
116
+ }
117
+ case 'unexpected-space': {
118
+ reasonPart = t('Found {0}', t('unexpected {0}', 'whitespace'));
119
+ break;
120
+ }
121
+ case 'unexpected-token': {
122
+ const chars = t('unexpected {0}', 'characters');
123
+ if (matches.partName) {
124
+ const part = t('the {0} part', matches.partName);
125
+ reasonPart = t('{0} includes {1}', part, chars);
126
+ target = 'it';
127
+ }
128
+ else {
129
+ reasonPart = t('It includes {0}', chars);
130
+ }
131
+ break;
132
+ }
133
+ default: {
134
+ if ('type' in matches.reason) {
135
+ switch (matches.reason.type) {
136
+ case 'out-of-range-length-digit': {
137
+ const { gte, lte } = matches.reason;
138
+ let expectedDigits = null;
139
+ if (lte != null && gte === lte) {
140
+ expectedDigits = t('{0} digits', gte);
141
+ }
142
+ else if (lte != null) {
143
+ expectedDigits = t('{0} to {1} digits', gte, lte);
144
+ }
145
+ else {
146
+ expectedDigits = t('{0} or more digits', gte);
147
+ }
148
+ if (!expected) {
149
+ expected = expectedDigits;
150
+ }
151
+ else if (expected && expectedDigits) {
152
+ expected = t('{0:c} and {1:c}', expectedDigits, expected);
153
+ }
154
+ break;
155
+ }
156
+ case 'out-of-range': {
157
+ const expectedNum = createExpectedNumber(t, {
158
+ ...matches.reason,
159
+ type: 'integer',
160
+ });
161
+ if (!expected) {
162
+ expected = expectedNum;
163
+ }
164
+ else if (expected) {
165
+ expected = t('{0:c} and {1:c}', expectedNum, expected);
166
+ }
167
+ break;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
173
+ if (expected) {
174
+ if (target === 'it') {
175
+ if (expectOrNeed === 'expects') {
176
+ expectPart = t('It expects {0:c}', expected);
177
+ }
178
+ else {
179
+ expectPart = t('It needs {0}', expected);
180
+ }
181
+ }
182
+ else {
183
+ if (expectOrNeed === 'expects') {
184
+ expectPart = t('{0} expects {1:c}', target, expected);
185
+ }
186
+ else {
187
+ expectPart = t('{0} needs {1}', target, expected);
188
+ }
189
+ }
190
+ }
191
+ if (matches.candicate) {
192
+ candicatePart = t('Did you mean "{0*}"?', matches.candicate);
193
+ }
194
+ let message = [reasonPart, unnecessaryPart, expectPart, candicatePart].filter(s => s).join(t('. '));
195
+ if (matches.ref) {
196
+ message += ` (${matches.ref})`;
197
+ }
198
+ return message;
199
+ }
200
+ exports.__createMessageValueExpected = __createMessageValueExpected;
201
+ function createExpectedObject(type, matches, t) {
202
+ var _a;
203
+ const expectedObject = [];
204
+ if ((_a = matches.expects) === null || _a === void 0 ? void 0 : _a.length) {
205
+ expectedObject.push(...matches.expects.map(expect => {
206
+ return expectValueToWord(t, expect, type);
207
+ }));
208
+ }
209
+ else if ((0, types_1.isKeyword)(type)) {
210
+ if (type[0] === '<') {
211
+ expectedObject.push(t('the CSS Syntax "{0}"', type));
212
+ }
213
+ }
214
+ else if ((0, types_1.isEnum)(type)) {
215
+ expectedObject.push(...type.enum);
216
+ }
217
+ else {
218
+ expectedObject.push(createExpectedNumber(t, type));
219
+ }
220
+ const expects = expectedObject.length === 0
221
+ ? null
222
+ : 1 < expectedObject.length
223
+ ? t('either {0}', t(expectedObject))
224
+ : expectedObject[0];
225
+ return expects;
226
+ }
227
+ function expectValueToWord(t, expect, type) {
228
+ switch (expect.type) {
229
+ case 'common':
230
+ return expect.value;
231
+ case 'const':
232
+ return expect.value ? `%${expect.value}%` : '';
233
+ case 'format':
234
+ return t('the {0} format', expect.value);
235
+ case 'regxp':
236
+ return t('{0} ({1})', 'regular expression', expect.value);
237
+ case 'syntax':
238
+ if ((0, types_1.isKeyword)(type) && type[0] === '<') {
239
+ return t('the CSS Syntax "{0}"', expect.value);
240
+ }
241
+ return t('{0} syntax', expect.value);
242
+ }
243
+ }
244
+ function createExpectedNumber(t, type) {
245
+ if (type.gt != null) {
246
+ if (type.lt != null) {
247
+ return t('{0} greater than {1} less than {2}', type.type, type.gt, type.lt);
248
+ }
249
+ if (type.lte != null) {
250
+ return t('{0} greater than {1} less than or equal to {2}', type.type, type.gt, type.lte);
251
+ }
252
+ return t('{0} greater than {1}', type.type, type.gt);
253
+ }
254
+ if (type.gte != null) {
255
+ if (type.lt != null) {
256
+ return t('{0} greater than or equal to {1} less than {2}', type.type, type.gte, type.lt);
257
+ }
258
+ if (type.lte != null) {
259
+ return t('{0} greater than or equal to {1} less than or equal to {2}', type.type, type.gte, type.lte);
260
+ }
261
+ return t('{0} greater than or equal to {1}', type.type, type.gte);
262
+ }
263
+ if (type.lt != null) {
264
+ return t('{0} less than {1}', type.type, type.lt);
265
+ }
266
+ if (type.lte != null) {
267
+ return t('{0} less than or equal to {1}', type.type, type.lte);
268
+ }
269
+ return type.type;
270
+ }
package/lib/debug.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import debug from 'debug';
2
+ export declare type Log = debug.Debugger;
3
+ export declare const log: debug.Debugger;
package/lib/debug.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.log = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
6
+ exports.log = (0, debug_1.default)('markuplint-rules');
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
- const helpers_1 = require("../helpers");
5
4
  exports.default = (0, ml_core_1.createRule)({
6
5
  defaultValue: null,
7
6
  defaultOptions: null,
8
7
  async verify({ document, report, t }) {
9
8
  await document.walkOn('Element', async (element) => {
10
- const attrSpecs = (0, helpers_1.getAttrSpecs)(element.nameWithNS, document.specs);
9
+ const attrSpecs = (0, ml_core_1.getAttrSpecs)(element.nameWithNS, document.specs);
11
10
  if (!attrSpecs) {
12
11
  return;
13
12
  }
package/lib/helpers.d.ts CHANGED
@@ -1,7 +1,7 @@
1
+ import type { Log } from './debug';
1
2
  import type { Translator } from '@markuplint/i18n';
2
3
  import type { Element, RuleConfigValue } from '@markuplint/ml-core';
3
- import type { ARIRRoleAttribute, Attribute, MLMLSpec, PermittedRoles } from '@markuplint/ml-spec';
4
- export declare function getAttrSpecs(nameWithNS: string, { specs, def }: MLMLSpec): Attribute[] | null;
4
+ import type { ARIRRoleAttribute, Attribute, PermittedRoles } from '@markuplint/ml-spec';
5
5
  export declare function attrMatches<T extends RuleConfigValue, R>(node: Element<T, R>, condition: Attribute['condition']): boolean;
6
6
  export declare function match(needle: string, pattern: string): boolean;
7
7
  /**
@@ -21,9 +21,14 @@ export declare function match(needle: string, pattern: string): boolean;
21
21
  */
22
22
  export declare const rePCENChar: string;
23
23
  export declare function htmlSpec(nameWithNS: string): import("@markuplint/ml-spec").ElementSpec | null;
24
- export declare function isValidAttr(t: Translator, name: string, value: string, isDynamicValue: boolean, node: Element<any, any>, attrSpecs: Attribute[]): false | {
24
+ export declare function isValidAttr(t: Translator, name: string, value: string, isDynamicValue: boolean, node: Element<any, any>, attrSpecs: Attribute[], log?: Log): false | {
25
25
  invalidType: "non-existent" | "invalid-value";
26
26
  message: string;
27
+ loc?: {
28
+ raw: string;
29
+ line: number;
30
+ col: number;
31
+ } | undefined;
27
32
  };
28
33
  export declare function ariaSpec(): {
29
34
  roles: ARIRRoleAttribute[];
package/lib/helpers.js CHANGED
@@ -1,45 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkAria = exports.checkAriaValue = exports.getComputedRole = exports.getImplicitRole = exports.getPermittedRoles = exports.getRoleSpec = exports.ariaSpec = exports.isValidAttr = exports.htmlSpec = exports.rePCENChar = exports.match = exports.attrMatches = exports.getAttrSpecs = void 0;
3
+ exports.checkAria = exports.checkAriaValue = exports.getComputedRole = exports.getImplicitRole = exports.getPermittedRoles = exports.getRoleSpec = exports.ariaSpec = exports.isValidAttr = exports.htmlSpec = exports.rePCENChar = exports.match = exports.attrMatches = void 0;
4
4
  const html_spec_1 = require("@markuplint/html-spec");
5
5
  const attr_check_1 = require("./attr-check");
6
- function getAttrSpecs(nameWithNS, { specs, def }) {
7
- const spec = specs.find(spec => spec.name === nameWithNS);
8
- if (!spec) {
9
- return null;
10
- }
11
- const globalAttrs = def['#globalAttrs'];
12
- const attrs = [];
13
- if (!/[a-z]:[a-z]/i.test(nameWithNS)) {
14
- // It's HTML tag
15
- const hasGlobalAttr = spec.attributes.some(attr => attr === '#globalAttrs');
16
- if (hasGlobalAttr) {
17
- attrs.push(...(globalAttrs['#HTMLGlobalAttrs'] || []));
18
- }
19
- }
20
- for (const attr of spec.attributes) {
21
- if (typeof attr === 'string') {
22
- const globalAttr = globalAttrs[attr];
23
- if (!globalAttr) {
24
- continue;
25
- }
26
- attrs.push(...globalAttr);
27
- continue;
28
- }
29
- const definedIndex = attrs.findIndex(a => a.name === attr.name);
30
- if (definedIndex !== -1) {
31
- attrs[definedIndex] = {
32
- ...attrs[definedIndex],
33
- ...attr,
34
- };
35
- continue;
36
- }
37
- attrs.push(attr);
38
- }
39
- attrs.push(...(globalAttrs['#extends'] || []));
40
- return attrs;
41
- }
42
- exports.getAttrSpecs = getAttrSpecs;
43
6
  function attrMatches(node, condition) {
44
7
  if (!condition) {
45
8
  return true;
@@ -53,7 +16,10 @@ function attrMatches(node, condition) {
53
16
  let _node = node.parentNode;
54
17
  while (_node) {
55
18
  if (_node.type === 'Element') {
56
- if (_node.matches(condition.ancestor)) {
19
+ const condSelector = Array.isArray(condition.ancestor)
20
+ ? condition.ancestor.join(',')
21
+ : condition.ancestor;
22
+ if (_node.matches(condSelector)) {
57
23
  matched = true;
58
24
  break;
59
25
  }
@@ -114,9 +80,10 @@ function htmlSpec(nameWithNS) {
114
80
  return spec || null;
115
81
  }
116
82
  exports.htmlSpec = htmlSpec;
117
- function isValidAttr(t, name, value, isDynamicValue, node, attrSpecs) {
83
+ function isValidAttr(t, name, value, isDynamicValue, node, attrSpecs, log) {
118
84
  let invalid = false;
119
- const spec = attrSpecs.find(s => s.name === name);
85
+ const spec = attrSpecs.find(s => s.name.toLowerCase() === name.toLowerCase());
86
+ log && log('Spec of the %s attr: %o', name, spec);
120
87
  invalid = (0, attr_check_1.attrCheck)(t, name, value, false, spec);
121
88
  if (!invalid && spec && spec.condition && !node.hasSpreadAttr && !attrMatches(node, spec.condition)) {
122
89
  invalid = {
package/lib/index.d.ts CHANGED
@@ -15,13 +15,16 @@ declare const _default: {
15
15
  }>;
16
16
  'id-duplication': import("packages/@markuplint/ml-core/lib").RuleSeed<null, null>;
17
17
  indentation: import("packages/@markuplint/ml-core/lib").RuleSeed<import("./indentation").Value, import("./indentation").IndentationOptions>;
18
+ 'ineffective-attr': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, null>;
18
19
  'invalid-attr': import("packages/@markuplint/ml-core/lib").RuleSeed<true, {
19
20
  attrs?: Record<string, {
20
- enum: string[];
21
+ enum: [string, ...string[]];
21
22
  } | {
22
23
  pattern: string;
23
24
  } | {
24
25
  type: import("packages/@markuplint/ml-spec/lib").AttributeType;
26
+ } | {
27
+ disallowed: true;
25
28
  }> | undefined;
26
29
  ignoreAttrNamePrefix?: string | string[] | undefined;
27
30
  }>;
@@ -29,10 +32,14 @@ declare const _default: {
29
32
  ignoreRoles?: (("banner" | "main" | "complementary" | "contentinfo") | "form" | "navigation" | "region")[] | undefined;
30
33
  labelEachArea?: boolean | undefined;
31
34
  }>;
35
+ 'no-boolean-attr-value': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, null>;
32
36
  'permitted-contents': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-spec/lib").PermittedStructuresSchema[], {
33
37
  ignoreHasMutableChildren: boolean;
34
38
  }>;
35
- 'required-attr': import("packages/@markuplint/ml-core/lib").RuleSeed<string | string[], null>;
39
+ 'required-attr': import("packages/@markuplint/ml-core/lib").RuleSeed<string | (string | {
40
+ name: string;
41
+ value: string | string[];
42
+ })[], null>;
36
43
  'required-h1': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, import("./required-h1").RequiredH1Options>;
37
44
  'wai-aria': import("packages/@markuplint/ml-core/lib").RuleSeed<true, {
38
45
  checkingValue?: boolean | undefined;
package/lib/index.js CHANGED
@@ -15,8 +15,10 @@ const deprecated_element_1 = (0, tslib_1.__importDefault)(require("./deprecated-
15
15
  const doctype_1 = (0, tslib_1.__importDefault)(require("./doctype"));
16
16
  const id_duplication_1 = (0, tslib_1.__importDefault)(require("./id-duplication"));
17
17
  const indentation_1 = (0, tslib_1.__importDefault)(require("./indentation"));
18
+ const ineffective_attr_1 = (0, tslib_1.__importDefault)(require("./ineffective-attr"));
18
19
  const invalid_attr_1 = (0, tslib_1.__importDefault)(require("./invalid-attr"));
19
20
  const landmark_roles_1 = (0, tslib_1.__importDefault)(require("./landmark-roles"));
21
+ const no_boolean_attr_value_1 = (0, tslib_1.__importDefault)(require("./no-boolean-attr-value"));
20
22
  const permitted_contents_1 = (0, tslib_1.__importDefault)(require("./permitted-contents"));
21
23
  const required_attr_1 = (0, tslib_1.__importDefault)(require("./required-attr"));
22
24
  const required_h1_1 = (0, tslib_1.__importDefault)(require("./required-h1"));
@@ -36,8 +38,10 @@ exports.default = {
36
38
  doctype: doctype_1.default,
37
39
  'id-duplication': id_duplication_1.default,
38
40
  indentation: indentation_1.default,
41
+ 'ineffective-attr': ineffective_attr_1.default,
39
42
  'invalid-attr': invalid_attr_1.default,
40
43
  'landmark-roles': landmark_roles_1.default,
44
+ 'no-boolean-attr-value': no_boolean_attr_value_1.default,
41
45
  'permitted-contents': permitted_contents_1.default,
42
46
  'required-attr': required_attr_1.default,
43
47
  'required-h1': required_h1_1.default,
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, null>;
2
+ export default _default;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ml_core_1 = require("@markuplint/ml-core");
4
+ exports.default = (0, ml_core_1.createRule)({
5
+ defaultServerity: 'warning',
6
+ defaultValue: true,
7
+ defaultOptions: null,
8
+ async verify({ document, report, t }) {
9
+ document.walkOn('Element', el => {
10
+ const attrSpec = (0, ml_core_1.getAttrSpecs)(el.nameWithNS, document.specs);
11
+ if (!attrSpec) {
12
+ return;
13
+ }
14
+ for (const attr of el.attributes) {
15
+ if (attr.attrType === 'ps-attr') {
16
+ continue;
17
+ }
18
+ const name = attr.getName().potential;
19
+ const spec = attrSpec.find(s => s.name === name);
20
+ if (!spec) {
21
+ continue;
22
+ }
23
+ const ineffectiveConditions = spec.ineffective
24
+ ? Array.isArray(spec.ineffective)
25
+ ? spec.ineffective
26
+ : [spec.ineffective]
27
+ : [];
28
+ if (ineffectiveConditions.some(selector => el.matches(selector))) {
29
+ report({
30
+ scope: el,
31
+ raw: attr.raw,
32
+ line: attr.startLine,
33
+ col: attr.startCol,
34
+ message: t('{0} is {1:c}', t('the "{0}" {1}', name, 'attribute'), 'ineffective') +
35
+ t('. ') +
36
+ t("It doesn't need {0}", t('the {0}', 'attribute')),
37
+ });
38
+ }
39
+ }
40
+ });
41
+ },
42
+ });
@@ -4,11 +4,13 @@ declare type Option = {
4
4
  ignoreAttrNamePrefix?: string | string[];
5
5
  };
6
6
  declare type Rule = {
7
- enum: string[];
7
+ enum: [string, ...string[]];
8
8
  } | {
9
9
  pattern: string;
10
10
  } | {
11
11
  type: AttributeType;
12
+ } | {
13
+ disallowed: true;
12
14
  };
13
15
  declare const _default: import("@markuplint/ml-core").RuleSeed<true, Option>;
14
16
  export default _default;
@@ -2,13 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const attr_check_1 = require("../attr-check");
5
+ const debug_1 = require("../debug");
5
6
  const helpers_1 = require("../helpers");
7
+ const log = debug_1.log.extend('invalid-attr');
6
8
  exports.default = (0, ml_core_1.createRule)({
7
9
  defaultValue: true,
8
10
  defaultOptions: {},
9
11
  async verify({ document, report, t }) {
10
12
  await document.walkOn('Element', async (node) => {
11
- const attrSpecs = (0, helpers_1.getAttrSpecs)(node.nameWithNS, document.specs);
13
+ var _a, _b, _c, _d, _e, _f, _g, _h;
14
+ const attrSpecs = (0, ml_core_1.getAttrSpecs)(node.nameWithNS, document.specs);
12
15
  for (const attr of node.attributes) {
13
16
  if (attr.attrType === 'html-attr' && attr.isDirective) {
14
17
  continue;
@@ -61,9 +64,16 @@ exports.default = (0, ml_core_1.createRule)({
61
64
  else if ('type' in customRule) {
62
65
  invalid = (0, attr_check_1.attrCheck)(t, name, value, true, { name, type: customRule.type, description: '' });
63
66
  }
67
+ else if ('disallowed' in customRule && customRule.disallowed) {
68
+ invalid = {
69
+ invalidType: 'non-existent',
70
+ message: t('{0} is disallowed', t('the "{0}" {1}', name, 'attribute')),
71
+ };
72
+ }
64
73
  }
65
74
  else if (!node.isCustomElement && attrSpecs) {
66
- invalid = (0, helpers_1.isValidAttr)(t, name, value, (attr.attrType === 'html-attr' && attr.isDynamicValue) || false, node, attrSpecs);
75
+ log('Checking %s[%s="%s"]', node.nodeName, name, value);
76
+ invalid = (0, helpers_1.isValidAttr)(t, name, value, (attr.attrType === 'html-attr' && attr.isDynamicValue) || false, node, attrSpecs, log);
67
77
  }
68
78
  if (invalid) {
69
79
  switch (invalid.invalidType) {
@@ -71,9 +81,9 @@ exports.default = (0, ml_core_1.createRule)({
71
81
  report({
72
82
  scope: node,
73
83
  message: invalid.message,
74
- line: attrValue.line,
75
- col: attrValue.col,
76
- raw: value,
84
+ line: attrValue.line + ((_b = (_a = invalid.loc) === null || _a === void 0 ? void 0 : _a.line) !== null && _b !== void 0 ? _b : 0),
85
+ col: ((_c = invalid.loc) === null || _c === void 0 ? void 0 : _c.line) ? ((_d = invalid.loc) === null || _d === void 0 ? void 0 : _d.col) + 1 : attrValue.col + ((_f = (_e = invalid.loc) === null || _e === void 0 ? void 0 : _e.col) !== null && _f !== void 0 ? _f : 0),
86
+ raw: (_h = (_g = invalid.loc) === null || _g === void 0 ? void 0 : _g.raw) !== null && _h !== void 0 ? _h : value,
77
87
  });
78
88
  break;
79
89
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, null>;
2
+ export default _default;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ml_core_1 = require("@markuplint/ml-core");
4
+ exports.default = (0, ml_core_1.createRule)({
5
+ defaultServerity: 'warning',
6
+ defaultValue: true,
7
+ defaultOptions: null,
8
+ async verify({ document, report, t }) {
9
+ document.walkOn('Element', el => {
10
+ const attrSpec = (0, ml_core_1.getAttrSpecs)(el.nameWithNS, document.specs);
11
+ if (!attrSpec) {
12
+ return;
13
+ }
14
+ for (const attr of el.attributes) {
15
+ if (attr.attrType === 'ps-attr') {
16
+ continue;
17
+ }
18
+ const name = attr.getName().potential;
19
+ const spec = attrSpec.find(s => s.name === name);
20
+ if (!spec) {
21
+ continue;
22
+ }
23
+ if (spec.type !== 'Boolean') {
24
+ continue;
25
+ }
26
+ const extraTokens = [
27
+ attr.spacesBeforeEqual,
28
+ attr.equal,
29
+ attr.spacesAfterEqual,
30
+ attr.startQuote,
31
+ attr.value,
32
+ attr.endQuote,
33
+ ];
34
+ const extraRaw = extraTokens.reduce((raw, t) => raw + t.raw, '');
35
+ if (extraRaw) {
36
+ report({
37
+ scope: el,
38
+ raw: extraRaw,
39
+ line: attr.spacesBeforeEqual.startLine,
40
+ col: attr.spacesBeforeEqual.startCol,
41
+ message: t('{0} is {1}', t('the "{0}" {1}', name, 'attribute'), t('a {0}', 'boolean attribute')) +
42
+ t('. ') +
43
+ t("It doesn't need {0}", t('the {0}', 'value')),
44
+ });
45
+ }
46
+ }
47
+ });
48
+ },
49
+ });
@@ -1,3 +1,7 @@
1
- declare type RequiredAttributes = string | string[];
1
+ declare type RequiredAttributes = string | (string | Attr)[];
2
+ declare type Attr = {
3
+ name: string;
4
+ value: string | string[];
5
+ };
2
6
  declare const _default: import("@markuplint/ml-core").RuleSeed<RequiredAttributes, null>;
3
7
  export default _default;