@glion/lint-profile-backward-compatible 0.25.0 → 0.27.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Rethink Health
3
+ Copyright (c) 2023 Rethink Health, SUARL
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -79,7 +79,7 @@ DG1|1|I9|250.00|DIABETES
79
79
  Reported message:
80
80
 
81
81
  ```
82
- `DG1-4` (Diagnosis Description) has a value; v2.5.1 keeps it only for backward compatibility.
82
+ The data element has a value; v2.5.1 keeps it only for backward compatibility.
83
83
  ```
84
84
 
85
85
  A field is reported once, whichever of its repetitions has a value. A component is reported in each repetition that gives it a value.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAevC;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,2BAA2B,mDA8ChC,CAAC;AAEF,eAAe,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAA2B,IAAI,EAAgB,MAAM,YAAY,CAAC;AAe9E;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,2BAA2B,mDA4DhC,CAAC;AAEF,eAAe,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { lintRule } from "unified-lint-rule";
6
6
  //#region src/index.ts
7
7
  /** HL7v2 explicit null: the receiver deletes the element's value. */
8
8
  const EXPLICIT_NULL = "\"\"";
9
- const messages = { backwardCompatible: (id, name, version) => `\`${id}\` (${name}) has a value; v${version} keeps it only for backward compatibility.` };
9
+ const messages = { backwardCompatible: (version) => `The data element has a value; v${version} keeps it only for backward compatibility.` };
10
10
  /**
11
11
  * Lint rule that reports a value in any element whose optionality is `B`
12
12
  * (backward compatible): a field, a component, or a subcomponent.
@@ -31,18 +31,37 @@ const hl7v2LintBackwardCompatible = lintRule({
31
31
  }, (tree, file) => {
32
32
  const version = file.data.profile?.version;
33
33
  if (version === void 0) return;
34
- visit(tree, (node, ancestors) => {
35
- if (node.type !== "field" && node.type !== "component" && node.type !== "subcomponent") return;
36
- const id = node.data?.id;
37
- if (id === void 0 || node.data?.optionality !== Optionality.BackwardCompatible || isEmptyNode(node)) return;
34
+ /**
35
+ * Reports `node` when it is backward compatible and holds a value other
36
+ * than the explicit null. Returns whether `node` is backward compatible and
37
+ * not empty.
38
+ */
39
+ const report = (node, ancestors) => {
40
+ const { data } = node;
41
+ if (data?.optionality !== Optionality.BackwardCompatible || isEmptyNode(node)) return false;
38
42
  const value = toHl7v2(node, delimiters(tree));
39
- if (value === EXPLICIT_NULL) return SKIP;
40
- const message = file.message(messages.backwardCompatible(id, node.data?.name ?? "", version), {
41
- ancestors: [...ancestors, node],
42
- place: node.position
43
- });
44
- message.actual = value;
45
- message.expected = ["", EXPLICIT_NULL];
43
+ if (value !== EXPLICIT_NULL) {
44
+ const message = file.message(messages.backwardCompatible(version), {
45
+ ancestors,
46
+ place: node.position
47
+ });
48
+ message.actual = value;
49
+ message.expected = ["", EXPLICIT_NULL];
50
+ }
51
+ return true;
52
+ };
53
+ visit(tree, "field", (field, parents) => {
54
+ const fieldAncestors = [...parents, field];
55
+ if (report(field, fieldAncestors)) return SKIP;
56
+ for (const repetition of field.children) for (const component of repetition.children) {
57
+ const componentAncestors = [
58
+ ...fieldAncestors,
59
+ repetition,
60
+ component
61
+ ];
62
+ if (report(component, componentAncestors)) continue;
63
+ for (const subcomponent of component.children) report(subcomponent, [...componentAncestors, subcomponent]);
64
+ }
46
65
  return SKIP;
47
66
  });
48
67
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// oxlint-disable-next-line no-unused-vars -- triggers VFile DataMap augmentation\nimport type { ProfileContext } from \"@glion/annotate-profile-context\";\n// oxlint-disable-next-line no-unused-vars -- triggers ComponentData and SubcomponentData augmentation\nimport type { hl7v2AnnotateProfileDatatypes } from \"@glion/annotate-profile-datatypes\";\n// oxlint-disable-next-line no-unused-vars -- triggers FieldData augmentation\nimport type { hl7v2AnnotateProfileFields } from \"@glion/annotate-profile-fields\";\nimport type { Root } from \"@glion/ast\";\nimport { toHl7v2 } from \"@glion/to-hl7v2\";\nimport { delimiters } from \"@glion/util-query\";\nimport { SKIP, visit } from \"@glion/util-visit\";\nimport { isEmptyNode, Optionality } from \"@glion/utils\";\nimport { lintRule } from \"unified-lint-rule\";\n\n/** HL7v2 explicit null: the receiver deletes the element's value. */\nconst EXPLICIT_NULL = '\"\"';\n\nconst messages = {\n backwardCompatible: (id: string, name: string, version: string) =>\n `\\`${id}\\` (${name}) has a value; v${version} keeps it only for backward compatibility.`,\n} as const;\n\n/**\n * Lint rule that reports a value in any element whose optionality is `B`\n * (backward compatible): a field, a component, or a subcomponent.\n *\n * Reads `optionality` from `node.data`, which the profile annotators write, so\n * `@glion/annotate-profile-fields` and `@glion/annotate-profile-datatypes`\n * MUST run before it. An empty element and the explicit null `\"\"` are\n * accepted.\n *\n * @example\n * ```typescript\n * unified()\n * .use(hl7v2AnnotateProfileContext)\n * .use(hl7v2AnnotateProfileFields)\n * .use(hl7v2AnnotateProfileDatatypes)\n * .use(hl7v2LintBackwardCompatible);\n * ```;\n */\nconst hl7v2LintBackwardCompatible = lintRule<Root>(\n {\n origin: \"hl7v2-lint:backward-compatible\",\n url: \"https://github.com/rethinkhealth/glion/tree/main/packages/lint-profile-backward-compatible#readme\",\n },\n (tree, file) => {\n const version = file.data.profile?.version;\n if (version === undefined) {\n return;\n }\n\n visit(tree, (node, ancestors) => {\n // Fields, components and subcomponents carry an optionality.\n if (\n node.type !== \"field\" &&\n node.type !== \"component\" &&\n node.type !== \"subcomponent\"\n ) {\n return;\n }\n\n // An element that is not reported may still have components that are.\n const id = node.data?.id;\n if (\n id === undefined ||\n node.data?.optionality !== Optionality.BackwardCompatible ||\n isEmptyNode(node)\n ) {\n return;\n }\n\n const value = toHl7v2(node, delimiters(tree));\n if (value === EXPLICIT_NULL) {\n return SKIP;\n }\n\n const message = file.message(\n messages.backwardCompatible(id, node.data?.name ?? \"\", version),\n { ancestors: [...ancestors, node], place: node.position }\n );\n message.actual = value;\n message.expected = [\"\", EXPLICIT_NULL];\n // The element is reported; its components need no report of their own.\n return SKIP;\n });\n }\n);\n\nexport default hl7v2LintBackwardCompatible;\n"],"mappings":";;;;;;;AAcA,MAAM,gBAAgB;AAEtB,MAAM,WAAW,EACf,qBAAqB,IAAY,MAAc,YAC7C,KAAK,GAAG,MAAM,KAAK,kBAAkB,QAAQ,6CAChD;;;;;;;;;;;;;;;;;;;AAoBD,MAAM,8BAA8B,SAClC;CACE,QAAQ;CACR,KAAK;CACN,GACA,MAAM,SAAS;CACd,MAAM,UAAU,KAAK,KAAK,SAAS;AACnC,KAAI,YAAY,KAAA,EACd;AAGF,OAAM,OAAO,MAAM,cAAc;AAE/B,MACE,KAAK,SAAS,WACd,KAAK,SAAS,eACd,KAAK,SAAS,eAEd;EAIF,MAAM,KAAK,KAAK,MAAM;AACtB,MACE,OAAO,KAAA,KACP,KAAK,MAAM,gBAAgB,YAAY,sBACvC,YAAY,KAAK,CAEjB;EAGF,MAAM,QAAQ,QAAQ,MAAM,WAAW,KAAK,CAAC;AAC7C,MAAI,UAAU,cACZ,QAAO;EAGT,MAAM,UAAU,KAAK,QACnB,SAAS,mBAAmB,IAAI,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAC/D;GAAE,WAAW,CAAC,GAAG,WAAW,KAAK;GAAE,OAAO,KAAK;GAAU,CAC1D;AACD,UAAQ,SAAS;AACjB,UAAQ,WAAW,CAAC,IAAI,cAAc;AAEtC,SAAO;GACP;EAEL"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// oxlint-disable-next-line no-unused-vars -- triggers VFile DataMap augmentation\nimport type { ProfileContext } from \"@glion/annotate-profile-context\";\n// oxlint-disable-next-line no-unused-vars -- triggers ComponentData and SubcomponentData augmentation\nimport type { hl7v2AnnotateProfileDatatypes } from \"@glion/annotate-profile-datatypes\";\n// oxlint-disable-next-line no-unused-vars -- triggers FieldData augmentation\nimport type { hl7v2AnnotateProfileFields } from \"@glion/annotate-profile-fields\";\nimport type { Component, Field, Nodes, Root, Subcomponent } from \"@glion/ast\";\nimport { toHl7v2 } from \"@glion/to-hl7v2\";\nimport { delimiters } from \"@glion/util-query\";\nimport { SKIP, visit } from \"@glion/util-visit\";\nimport { isEmptyNode, Optionality } from \"@glion/utils\";\nimport { lintRule } from \"unified-lint-rule\";\n\n/** HL7v2 explicit null: the receiver deletes the element's value. */\nconst EXPLICIT_NULL = '\"\"';\n\nconst messages = {\n backwardCompatible: (version: string) =>\n `The data element has a value; v${version} keeps it only for backward compatibility.`,\n} as const;\n\n/**\n * Lint rule that reports a value in any element whose optionality is `B`\n * (backward compatible): a field, a component, or a subcomponent.\n *\n * Reads `optionality` from `node.data`, which the profile annotators write, so\n * `@glion/annotate-profile-fields` and `@glion/annotate-profile-datatypes`\n * MUST run before it. An empty element and the explicit null `\"\"` are\n * accepted.\n *\n * @example\n * ```typescript\n * unified()\n * .use(hl7v2AnnotateProfileContext)\n * .use(hl7v2AnnotateProfileFields)\n * .use(hl7v2AnnotateProfileDatatypes)\n * .use(hl7v2LintBackwardCompatible);\n * ```;\n */\nconst hl7v2LintBackwardCompatible = lintRule<Root>(\n {\n origin: \"hl7v2-lint:backward-compatible\",\n url: \"https://github.com/rethinkhealth/glion/tree/main/packages/lint-profile-backward-compatible#readme\",\n },\n (tree, file) => {\n const version = file.data.profile?.version;\n if (version === undefined) {\n return;\n }\n\n /**\n * Reports `node` when it is backward compatible and holds a value other\n * than the explicit null. Returns whether `node` is backward compatible and\n * not empty.\n */\n const report = (\n node: Field | Component | Subcomponent,\n ancestors: Nodes[]\n ): boolean => {\n const { data } = node;\n if (\n data?.optionality !== Optionality.BackwardCompatible ||\n isEmptyNode(node)\n ) {\n return false;\n }\n\n const value = toHl7v2(node, delimiters(tree));\n if (value !== EXPLICIT_NULL) {\n const message = file.message(messages.backwardCompatible(version), {\n ancestors,\n place: node.position,\n });\n message.actual = value;\n message.expected = [\"\", EXPLICIT_NULL];\n }\n return true;\n };\n\n // A reported element's components need no report of their own.\n visit(tree, \"field\", (field, parents) => {\n const fieldAncestors = [...parents, field];\n if (report(field, fieldAncestors)) {\n return SKIP;\n }\n for (const repetition of field.children) {\n for (const component of repetition.children) {\n const componentAncestors = [...fieldAncestors, repetition, component];\n if (report(component, componentAncestors)) {\n continue;\n }\n for (const subcomponent of component.children) {\n report(subcomponent, [...componentAncestors, subcomponent]);\n }\n }\n }\n return SKIP;\n });\n }\n);\n\nexport default hl7v2LintBackwardCompatible;\n"],"mappings":";;;;;;;AAcA,MAAM,gBAAgB;AAEtB,MAAM,WAAW,EACf,qBAAqB,YACnB,kCAAkC,QAAQ,6CAC7C;;;;;;;;;;;;;;;;;;;AAoBD,MAAM,8BAA8B,SAClC;CACE,QAAQ;CACR,KAAK;CACN,GACA,MAAM,SAAS;CACd,MAAM,UAAU,KAAK,KAAK,SAAS;AACnC,KAAI,YAAY,KAAA,EACd;;;;;;CAQF,MAAM,UACJ,MACA,cACY;EACZ,MAAM,EAAE,SAAS;AACjB,MACE,MAAM,gBAAgB,YAAY,sBAClC,YAAY,KAAK,CAEjB,QAAO;EAGT,MAAM,QAAQ,QAAQ,MAAM,WAAW,KAAK,CAAC;AAC7C,MAAI,UAAU,eAAe;GAC3B,MAAM,UAAU,KAAK,QAAQ,SAAS,mBAAmB,QAAQ,EAAE;IACjE;IACA,OAAO,KAAK;IACb,CAAC;AACF,WAAQ,SAAS;AACjB,WAAQ,WAAW,CAAC,IAAI,cAAc;;AAExC,SAAO;;AAIT,OAAM,MAAM,UAAU,OAAO,YAAY;EACvC,MAAM,iBAAiB,CAAC,GAAG,SAAS,MAAM;AAC1C,MAAI,OAAO,OAAO,eAAe,CAC/B,QAAO;AAET,OAAK,MAAM,cAAc,MAAM,SAC7B,MAAK,MAAM,aAAa,WAAW,UAAU;GAC3C,MAAM,qBAAqB;IAAC,GAAG;IAAgB;IAAY;IAAU;AACrE,OAAI,OAAO,WAAW,mBAAmB,CACvC;AAEF,QAAK,MAAM,gBAAgB,UAAU,SACnC,QAAO,cAAc,CAAC,GAAG,oBAAoB,aAAa,CAAC;;AAIjE,SAAO;GACP;EAEL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/lint-profile-backward-compatible",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "description": "Lint rule that reports a value in an element HL7v2 keeps only for backward compatibility",
5
5
  "keywords": [
6
6
  "health",
@@ -34,15 +34,17 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "unified-lint-rule": "3.0.1",
37
- "@glion/annotate-profile-datatypes": "0.25.0",
38
- "@glion/annotate-profile-fields": "0.25.0",
39
- "@glion/ast": "0.25.0",
40
- "@glion/to-hl7v2": "0.25.0",
41
- "@glion/util-query": "0.25.0",
42
- "@glion/util-visit": "0.25.0",
43
- "@glion/utils": "0.25.0"
37
+ "@glion/annotate-profile-datatypes": "0.27.0",
38
+ "@glion/annotate-profile-fields": "0.27.0",
39
+ "@glion/ast": "0.27.0",
40
+ "@glion/to-hl7v2": "0.27.0",
41
+ "@glion/util-query": "0.27.0",
42
+ "@glion/util-visit": "0.27.0",
43
+ "@glion/utils": "0.27.0"
44
44
  },
45
45
  "devDependencies": {
46
+ "@stryker-mutator/core": "10.0.0",
47
+ "@stryker-mutator/vitest-runner": "10.0.0",
46
48
  "@types/node": "25.6.0",
47
49
  "@vitest/coverage-v8": "4.1.11",
48
50
  "publint": "0.3.18",
@@ -51,10 +53,10 @@
51
53
  "unified": "^11.0.5",
52
54
  "vfile": "^6.0.3",
53
55
  "vitest": "4.1.11",
54
- "@glion/annotate-profile-context": "0.25.0",
55
- "@glion/builder": "0.25.0",
56
+ "@glion/annotate-profile-context": "0.27.0",
57
+ "@glion/builder": "0.27.0",
56
58
  "@glion/check-readme": "0.18.0",
57
- "@glion/parser": "0.25.0",
59
+ "@glion/parser": "0.27.0",
58
60
  "@glion/testing": "0.18.0",
59
61
  "@glion/tsconfig": "0.18.0"
60
62
  },
@@ -65,9 +67,10 @@
65
67
  "build": "tsdown && tsc --emitDeclarationOnly",
66
68
  "check-types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
67
69
  "check:readme": "glion-check-readme",
70
+ "mutate": "stryker run",
71
+ "publint": "publint --strict",
68
72
  "test": "vitest run",
69
73
  "test:coverage": "vitest run --coverage",
70
- "test:watch": "vitest",
71
- "publint": "publint --strict"
74
+ "test:watch": "vitest"
72
75
  }
73
76
  }