@pagefront/lint-commerce 0.2.1 → 0.3.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 +3 -2
- package/dist/organization-catalogue.js +1 -1
- package/dist/rules/pdp-e-003.d.ts +11 -0
- package/dist/rules/pdp-e-003.js +55 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/catalogue.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { pdpE001 } from "./rules/pdp-e-001.js";
|
|
2
2
|
import { pdpE002 } from "./rules/pdp-e-002.js";
|
|
3
|
+
import { pdpE003 } from "./rules/pdp-e-003.js";
|
|
3
4
|
import { pdpW001 } from "./rules/pdp-w-001.js";
|
|
4
5
|
import { pdpW002 } from "./rules/pdp-w-002.js";
|
|
5
6
|
import { pdpW003 } from "./rules/pdp-w-003.js";
|
|
@@ -38,6 +39,6 @@ import { pdpI001 } from "./rules/pdp-i-001.js";
|
|
|
38
39
|
export const commerceCatalogue = {
|
|
39
40
|
vertical: "commerce",
|
|
40
41
|
formatVersion: "0.9",
|
|
41
|
-
catalogueVersion: "0.
|
|
42
|
-
rules: [pdpE001, pdpE002, 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],
|
|
42
|
+
catalogueVersion: "0.6.0",
|
|
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],
|
|
43
44
|
};
|
|
@@ -16,6 +16,6 @@ import { orgW006 } from "./rules/org-w-006.js";
|
|
|
16
16
|
export const organizationCatalogue = {
|
|
17
17
|
vertical: "commerce",
|
|
18
18
|
formatVersion: "0.9",
|
|
19
|
-
catalogueVersion: "0.
|
|
19
|
+
catalogueVersion: "0.6.0",
|
|
20
20
|
rules: [orgW001, orgW002, orgW003, orgW004, orgW005, orgW006],
|
|
21
21
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Rule } from "@pagefront/lint-core";
|
|
2
|
+
/**
|
|
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.
|
|
9
|
+
*/
|
|
10
|
+
export declare const VOCABULARY_IRI = "https://themachineweb.org/pagefront/vocabulary/";
|
|
11
|
+
export declare const pdpE003: Rule;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
8
|
+
*/
|
|
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
|
+
export const pdpE003 = {
|
|
38
|
+
id: "PDP-E-003",
|
|
39
|
+
title: "pagefront: term without the vocabulary prefix",
|
|
40
|
+
severity: "error",
|
|
41
|
+
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
|
+
},
|
|
51
|
+
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
|
+
remediation: 'Declare the prefix: `"@context": ["https://schema.org", {"pagefront": "https://themachineweb.org/pagefront/vocabulary/"}]`.',
|
|
53
|
+
introduced: "v0.9",
|
|
54
|
+
specReference: "vocabulary.md#how-to-use-this-vocabulary",
|
|
55
|
+
};
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED