@pagefront/lint-commerce 0.3.0 → 0.4.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/dist/catalogue.js +1 -1
- package/dist/organization-catalogue.js +3 -2
- package/dist/rules/context-prefix.d.ts +16 -0
- package/dist/rules/context-prefix.js +44 -0
- package/dist/rules/org-e-001.d.ts +7 -0
- package/dist/rules/org-e-001.js +17 -0
- package/dist/rules/pdp-e-003.d.ts +2 -6
- package/dist/rules/pdp-e-003.js +4 -42
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/catalogue.js
CHANGED
|
@@ -39,6 +39,6 @@ import { pdpI001 } from "./rules/pdp-i-001.js";
|
|
|
39
39
|
export const commerceCatalogue = {
|
|
40
40
|
vertical: "commerce",
|
|
41
41
|
formatVersion: "0.9",
|
|
42
|
-
catalogueVersion: "0.
|
|
42
|
+
catalogueVersion: "0.7.0",
|
|
43
43
|
rules: [pdpE001, pdpE002, pdpE003, pdpW001, pdpW002, pdpW003, pdpW004, pdpW005, pdpW006, pdpW007, pdpW008, pdpW009, pdpW010, pdpW011, pdpW012, pdpW013, pdpW014, pdpW015, pdpW016, pdpW017, pdpW018, pdpW019, pdpW020, pdpW021, pdpW022, pdpW023, pdpW024, pdpW025, pdpW026, pdpW027, pdpI001],
|
|
44
44
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { orgE001 } from "./rules/org-e-001.js";
|
|
1
2
|
import { orgW001 } from "./rules/org-w-001.js";
|
|
2
3
|
import { orgW002 } from "./rules/org-w-002.js";
|
|
3
4
|
import { orgW003 } from "./rules/org-w-003.js";
|
|
@@ -16,6 +17,6 @@ import { orgW006 } from "./rules/org-w-006.js";
|
|
|
16
17
|
export const organizationCatalogue = {
|
|
17
18
|
vertical: "commerce",
|
|
18
19
|
formatVersion: "0.9",
|
|
19
|
-
catalogueVersion: "0.
|
|
20
|
-
rules: [orgW001, orgW002, orgW003, orgW004, orgW005, orgW006],
|
|
20
|
+
catalogueVersion: "0.7.0",
|
|
21
|
+
rules: [orgE001, orgW001, orgW002, orgW003, orgW004, orgW005, orgW006],
|
|
21
22
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared by PDP-E-003 and ORG-E-001: does the data block declare the
|
|
3
|
+
* `pagefront` prefix, and which `pagefront:` term does it use first?
|
|
4
|
+
* A term is a property name or an `@type` value beginning with
|
|
5
|
+
* `pagefront:`, anywhere in the block; the walk is depth-first in
|
|
6
|
+
* document order, so the named term is the first one a reader meets.
|
|
7
|
+
*/
|
|
8
|
+
export declare const VOCABULARY_IRI = "https://themachineweb.org/pagefront/vocabulary/";
|
|
9
|
+
export declare const declaresPagefrontPrefix: (context: unknown) => boolean;
|
|
10
|
+
export declare const firstPagefrontTerm: (value: unknown) => string | undefined;
|
|
11
|
+
/** The check both rules share: null when the prefix is declared or no term is used. */
|
|
12
|
+
export declare const missingPrefixTerm: (data: unknown) => {
|
|
13
|
+
values: {
|
|
14
|
+
term: string;
|
|
15
|
+
};
|
|
16
|
+
} | null;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared by PDP-E-003 and ORG-E-001: does the data block declare the
|
|
3
|
+
* `pagefront` prefix, and which `pagefront:` term does it use first?
|
|
4
|
+
* A term is a property name or an `@type` value beginning with
|
|
5
|
+
* `pagefront:`, anywhere in the block; the walk is depth-first in
|
|
6
|
+
* document order, so the named term is the first one a reader meets.
|
|
7
|
+
*/
|
|
8
|
+
export const VOCABULARY_IRI = "https://themachineweb.org/pagefront/vocabulary/";
|
|
9
|
+
export const declaresPagefrontPrefix = (context) => Array.isArray(context) &&
|
|
10
|
+
context.some((entry) => typeof entry === "object" &&
|
|
11
|
+
entry !== null &&
|
|
12
|
+
!Array.isArray(entry) &&
|
|
13
|
+
entry["pagefront"] === VOCABULARY_IRI);
|
|
14
|
+
export const firstPagefrontTerm = (value) => {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
for (const item of value) {
|
|
17
|
+
const found = firstPagefrontTerm(item);
|
|
18
|
+
if (found !== undefined)
|
|
19
|
+
return found;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (typeof value !== "object" || value === null)
|
|
24
|
+
return undefined;
|
|
25
|
+
for (const [key, child] of Object.entries(value)) {
|
|
26
|
+
if (key.startsWith("pagefront:"))
|
|
27
|
+
return key;
|
|
28
|
+
if (key === "@type" && typeof child === "string" && child.startsWith("pagefront:"))
|
|
29
|
+
return child;
|
|
30
|
+
const found = firstPagefrontTerm(child);
|
|
31
|
+
if (found !== undefined)
|
|
32
|
+
return found;
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
};
|
|
36
|
+
/** The check both rules share: null when the prefix is declared or no term is used. */
|
|
37
|
+
export const missingPrefixTerm = (data) => {
|
|
38
|
+
if (typeof data !== "object" || data === null || Array.isArray(data))
|
|
39
|
+
return null;
|
|
40
|
+
if (declaresPagefrontPrefix(data["@context"]))
|
|
41
|
+
return null;
|
|
42
|
+
const term = firstPagefrontTerm(data);
|
|
43
|
+
return term === undefined ? null : { values: { term } };
|
|
44
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Rule } from "@pagefront/lint-core";
|
|
2
|
+
/**
|
|
3
|
+
* ORG-E-001 — `pagefront:` term without the vocabulary prefix in `@context`.
|
|
4
|
+
* Transcribed from commerce/spec/rules.md (normative). The organization
|
|
5
|
+
* counterpart of PDP-E-003; the check is shared (context-prefix.ts).
|
|
6
|
+
*/
|
|
7
|
+
export declare const orgE001: Rule;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { missingPrefixTerm } from "./context-prefix.js";
|
|
2
|
+
/**
|
|
3
|
+
* ORG-E-001 — `pagefront:` term without the vocabulary prefix in `@context`.
|
|
4
|
+
* Transcribed from commerce/spec/rules.md (normative). The organization
|
|
5
|
+
* counterpart of PDP-E-003; the check is shared (context-prefix.ts).
|
|
6
|
+
*/
|
|
7
|
+
export const orgE001 = {
|
|
8
|
+
id: "ORG-E-001",
|
|
9
|
+
title: "pagefront: term without the vocabulary prefix",
|
|
10
|
+
severity: "error",
|
|
11
|
+
target: "$.data",
|
|
12
|
+
check: (match) => missingPrefixTerm(match.value),
|
|
13
|
+
messageTemplate: "The Sheet uses `{term}` but `@context` at `{path}` does not declare the `pagefront` prefix, so the term does not resolve to the Pagefront vocabulary.",
|
|
14
|
+
remediation: 'Declare the prefix: `"@context": ["https://schema.org", {"pagefront": "https://themachineweb.org/pagefront/vocabulary/"}]`.',
|
|
15
|
+
introduced: "v0.9",
|
|
16
|
+
specReference: "vocabulary.md#how-to-use-this-vocabulary",
|
|
17
|
+
};
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { Rule } from "@pagefront/lint-core";
|
|
2
2
|
/**
|
|
3
3
|
* PDP-E-003 — `pagefront:` term without the vocabulary prefix in `@context`.
|
|
4
|
-
* Transcribed from commerce/spec/rules.md (normative).
|
|
5
|
-
*
|
|
6
|
-
* A term is a property name or an `@type` value beginning with
|
|
7
|
-
* `pagefront:`, anywhere in the data block. The walk is depth-first in
|
|
8
|
-
* document order, so the named term is the first one a reader meets.
|
|
4
|
+
* Transcribed from commerce/spec/rules.md (normative). The check is
|
|
5
|
+
* shared with ORG-E-001 (context-prefix.ts).
|
|
9
6
|
*/
|
|
10
|
-
export declare const VOCABULARY_IRI = "https://themachineweb.org/pagefront/vocabulary/";
|
|
11
7
|
export declare const pdpE003: Rule;
|
package/dist/rules/pdp-e-003.js
CHANGED
|
@@ -1,53 +1,15 @@
|
|
|
1
|
+
import { missingPrefixTerm } from "./context-prefix.js";
|
|
1
2
|
/**
|
|
2
3
|
* PDP-E-003 — `pagefront:` term without the vocabulary prefix in `@context`.
|
|
3
|
-
* Transcribed from commerce/spec/rules.md (normative).
|
|
4
|
-
*
|
|
5
|
-
* A term is a property name or an `@type` value beginning with
|
|
6
|
-
* `pagefront:`, anywhere in the data block. The walk is depth-first in
|
|
7
|
-
* document order, so the named term is the first one a reader meets.
|
|
4
|
+
* Transcribed from commerce/spec/rules.md (normative). The check is
|
|
5
|
+
* shared with ORG-E-001 (context-prefix.ts).
|
|
8
6
|
*/
|
|
9
|
-
export const VOCABULARY_IRI = "https://themachineweb.org/pagefront/vocabulary/";
|
|
10
|
-
const declaresPrefix = (context) => Array.isArray(context) &&
|
|
11
|
-
context.some((entry) => typeof entry === "object" &&
|
|
12
|
-
entry !== null &&
|
|
13
|
-
!Array.isArray(entry) &&
|
|
14
|
-
entry["pagefront"] === VOCABULARY_IRI);
|
|
15
|
-
const firstTerm = (value) => {
|
|
16
|
-
if (Array.isArray(value)) {
|
|
17
|
-
for (const item of value) {
|
|
18
|
-
const found = firstTerm(item);
|
|
19
|
-
if (found !== undefined)
|
|
20
|
-
return found;
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
if (typeof value !== "object" || value === null)
|
|
25
|
-
return undefined;
|
|
26
|
-
for (const [key, child] of Object.entries(value)) {
|
|
27
|
-
if (key.startsWith("pagefront:"))
|
|
28
|
-
return key;
|
|
29
|
-
if (key === "@type" && typeof child === "string" && child.startsWith("pagefront:"))
|
|
30
|
-
return child;
|
|
31
|
-
const found = firstTerm(child);
|
|
32
|
-
if (found !== undefined)
|
|
33
|
-
return found;
|
|
34
|
-
}
|
|
35
|
-
return undefined;
|
|
36
|
-
};
|
|
37
7
|
export const pdpE003 = {
|
|
38
8
|
id: "PDP-E-003",
|
|
39
9
|
title: "pagefront: term without the vocabulary prefix",
|
|
40
10
|
severity: "error",
|
|
41
11
|
target: "$.data",
|
|
42
|
-
check: (match) =>
|
|
43
|
-
const data = match.value;
|
|
44
|
-
if (typeof data !== "object" || data === null || Array.isArray(data))
|
|
45
|
-
return null;
|
|
46
|
-
if (declaresPrefix(data["@context"]))
|
|
47
|
-
return null;
|
|
48
|
-
const term = firstTerm(data);
|
|
49
|
-
return term === undefined ? null : { values: { term } };
|
|
50
|
-
},
|
|
12
|
+
check: (match) => missingPrefixTerm(match.value),
|
|
51
13
|
messageTemplate: "The Sheet uses `{term}` but `@context` at `{path}` does not declare the `pagefront` prefix, so the term does not resolve to the Pagefront vocabulary.",
|
|
52
14
|
remediation: 'Declare the prefix: `"@context": ["https://schema.org", {"pagefront": "https://themachineweb.org/pagefront/vocabulary/"}]`.',
|
|
53
15
|
introduced: "v0.9",
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED