@markuplint/rules 4.10.2 → 4.10.4

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/CHANGELOG.md CHANGED
@@ -3,13 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [4.10.2](https://github.com/markuplint/markuplint/compare/@markuplint/rules@4.10.1...@markuplint/rules@4.10.2) (2024-10-15)
6
+ ## [4.10.4](https://github.com/markuplint/markuplint/compare/@markuplint/rules@4.10.3...@markuplint/rules@4.10.4) (2024-10-28)
7
7
 
8
8
  **Note:** Version bump only for package @markuplint/rules
9
9
 
10
+ ## [4.10.3](https://github.com/markuplint/markuplint/compare/@markuplint/rules@4.10.2...@markuplint/rules@4.10.3) (2024-10-27)
10
11
 
12
+ **Note:** Version bump only for package @markuplint/rules
11
13
 
14
+ ## [4.10.2](https://github.com/markuplint/markuplint/compare/@markuplint/rules@4.10.1...@markuplint/rules@4.10.2) (2024-10-15)
12
15
 
16
+ **Note:** Version bump only for package @markuplint/rules
13
17
 
14
18
  ## [4.10.1](https://github.com/markuplint/markuplint/compare/@markuplint/rules@4.10.0...@markuplint/rules@4.10.1) (2024-10-14)
15
19
 
@@ -0,0 +1,2 @@
1
+ declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<boolean, null>>;
2
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import { createRule } from "@markuplint/ml-core";
2
+ import meta from "./meta.js";
3
+ export default createRule({
4
+ meta: meta,
5
+ defaultValue: true,
6
+ defaultOptions: null,
7
+ async verify({ document, report, t }) {
8
+ // Element
9
+ await document.walkOn("Element", (el) => {
10
+ const raw = el.raw.trim();
11
+ if (/./.test(raw)) {
12
+ report({
13
+ scope: el,
14
+ message: t("It is {0}", "issue"),
15
+ });
16
+ }
17
+ });
18
+ // Attribute
19
+ await document.walkOn("Attr", (attr) => {
20
+ if (/./.test(attr.name)) {
21
+ report({
22
+ scope: attr,
23
+ line: attr.nameNode?.startLine,
24
+ col: attr.nameNode?.startCol,
25
+ raw: attr.nameNode?.raw,
26
+ message: t("It is {0}", "issue"),
27
+ });
28
+ }
29
+ });
30
+ },
31
+ });
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ readonly category: "validation";
3
+ };
4
+ export default _default;
@@ -0,0 +1,3 @@
1
+ export default {
2
+ category: "validation",
3
+ };
@@ -0,0 +1,8 @@
1
+ import type { Specs } from './types.js';
2
+ type Condition = {
3
+ selector: string;
4
+ hasCustom: boolean;
5
+ hasText: boolean;
6
+ };
7
+ export declare function optCondition(query: string, specs: Specs): Readonly<Condition>;
8
+ export {};
@@ -0,0 +1,54 @@
1
+ import { contentModelCategoryToTagNames } from '@markuplint/ml-spec';
2
+ const conditionWithoutSpecs = {
3
+ '#custom': {
4
+ selector: '#custom',
5
+ hasCustom: true,
6
+ hasText: false,
7
+ },
8
+ '#text': {
9
+ selector: '#text',
10
+ hasCustom: false,
11
+ hasText: true,
12
+ },
13
+ };
14
+ const optConditionSpecsBaseCaches = new Map();
15
+ export function optCondition(query, specs) {
16
+ const condWithoutSpecs = conditionWithoutSpecs[query];
17
+ if (condWithoutSpecs) {
18
+ return condWithoutSpecs;
19
+ }
20
+ const queryCaches = optConditionSpecsBaseCaches.get(specs) ?? new Map();
21
+ const cached = queryCaches.get(query);
22
+ if (cached) {
23
+ return cached;
24
+ }
25
+ let hasCustom = false;
26
+ let hasText = false;
27
+ const selector = query.replace(/^:model\(([^)]+)\)|^#([a-z-]+)/, (_, $model, _model) => {
28
+ const _selectors = contentModelCategoryToTagNames(`#${$model ?? _model}`, specs.def);
29
+ if (_selectors.length === 0) {
30
+ throw new Error(`${$model ?? _model} is empty`);
31
+ }
32
+ const selectors = [];
33
+ for (const selector of _selectors) {
34
+ if (selector === '#custom') {
35
+ hasCustom = true;
36
+ continue;
37
+ }
38
+ if (selector === '#text') {
39
+ hasText = true;
40
+ continue;
41
+ }
42
+ selectors.push(selector);
43
+ }
44
+ return `:is(${selectors.join(',')})`;
45
+ });
46
+ const result = {
47
+ selector,
48
+ hasCustom,
49
+ hasText,
50
+ };
51
+ queryCaches.set(query, result);
52
+ optConditionSpecsBaseCaches.set(specs, queryCaches);
53
+ return result;
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/rules",
3
- "version": "4.10.2",
3
+ "version": "4.10.4",
4
4
  "description": "Built-in rules of markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -25,12 +25,12 @@
25
25
  "./lib/permitted-contents/debug.js": "./lib/permitted-contents/debug.browser.js"
26
26
  },
27
27
  "dependencies": {
28
- "@markuplint/html-spec": "4.9.3",
29
- "@markuplint/ml-core": "4.10.1",
30
- "@markuplint/ml-spec": "4.7.2",
31
- "@markuplint/selector": "4.6.9",
32
- "@markuplint/shared": "4.4.7",
33
- "@markuplint/types": "4.6.2",
28
+ "@markuplint/html-spec": "4.10.1",
29
+ "@markuplint/ml-core": "4.10.3",
30
+ "@markuplint/ml-spec": "4.8.1",
31
+ "@markuplint/selector": "4.6.11",
32
+ "@markuplint/shared": "4.4.9",
33
+ "@markuplint/types": "4.6.4",
34
34
  "@types/debug": "4.1.12",
35
35
  "@ungap/structured-clone": "1.2.0",
36
36
  "ansi-colors": "4.1.3",
@@ -38,5 +38,5 @@
38
38
  "debug": "4.3.7",
39
39
  "type-fest": "4.26.1"
40
40
  },
41
- "gitHead": "c8c82d36c2e48d191091cbc22ca1b99ed0704b9f"
41
+ "gitHead": "60a8a7149bd4441e89972ca21b90033afb05b89e"
42
42
  }