@glion/lint-segment-header-length 0.22.0 → 0.23.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/README.md CHANGED
@@ -37,7 +37,7 @@ console.error(reporter([file]));
37
37
 
38
38
  A `unified` lint rule plugin. Takes no options.
39
39
 
40
- Visits every `segment` node and reports one message per segment whose `name.length !== 3`. The reported text names how many characters to add or remove to reach the three-character target.
40
+ Visits every `segment` node and reports one message per segment whose Segment ID is not three characters long, with `actual` set to the Segment ID.
41
41
 
42
42
  ```ts
43
43
  import type { Plugin } from "unified";
@@ -72,7 +72,7 @@ PID1|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
72
72
  Reported message:
73
73
 
74
74
  ```
75
- Unexpected 4 header length, expected 3 characters, remove 1 character
75
+ The Segment ID `PID1` is 4 characters long; a Segment ID must be exactly 3 characters.
76
76
  ```
77
77
 
78
78
  A two-character segment name:
@@ -84,10 +84,16 @@ MS|^~\&|...
84
84
  Reported message:
85
85
 
86
86
  ```
87
- Unexpected 2 header length, expected 3 characters, add 1 character
87
+ The Segment ID `MS` is 2 characters long; a Segment ID must be exactly 3 characters.
88
88
  ```
89
89
 
90
- The delta between the actual length and three is interpolated with pluralization (`remove 1 character`, `add 2 characters`). One message is reported per offending segment.
90
+ A segment with an empty Segment ID, such as a line that starts with the field separator, is reported as:
91
+
92
+ ```
93
+ The segment has an empty Segment ID; a Segment ID must be exactly 3 characters.
94
+ ```
95
+
96
+ One message is reported per offending segment.
91
97
 
92
98
  ## Part of Glion
93
99
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKvC;;GAEG;AACH,QAAA,MAAM,4BAA4B,qDAuBjC,CAAC;AAEF,eAAe,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAYvC;;GAEG;AACH,QAAA,MAAM,4BAA4B,qDA2BjC,CAAC;AAEF,eAAe,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -2,20 +2,32 @@ import pluralize from "pluralize";
2
2
  import { lintRule } from "unified-lint-rule";
3
3
  import { SKIP, visitParents } from "unist-util-visit-parents";
4
4
  //#region src/index.ts
5
+ const messages = {
6
+ emptySegmentId: "The segment has an empty Segment ID; a Segment ID must be exactly 3 characters.",
7
+ segmentIdLength: (segmentId) => `The Segment ID \`${segmentId}\` is ${pluralize("character", segmentId.length, true)} long; a Segment ID must be exactly 3 characters.`
8
+ };
5
9
  /**
6
10
  * Hl7v2-lint rule to warn when segment header length is invalid.
7
11
  */
8
12
  const hl7v2LintSegmentHeaderLength = lintRule({
9
13
  origin: "hl7v2-lint:segment-header-length",
10
- url: "https://github.com/rethinkhealth/hl7v2/tree/main/packages/hl7v2-lint-segment-header-length#readme"
14
+ url: "https://github.com/rethinkhealth/glion/tree/main/packages/lint-segment-header-length#readme"
11
15
  }, (tree, file) => {
12
16
  visitParents(tree, "segment", (node, parents) => {
13
- const size = node.name.length;
14
- if (size === 3) return SKIP;
15
- file.message(`Unexpected ${size} header length, expected 3 characters, ${size > 3 ? `remove ${size - 3} ${pluralize("character", size - 3)}` : `add ${3 - size} ${pluralize("character", 3 - size)}`}`, {
17
+ if (node.name.length === 3) return SKIP;
18
+ if (node.name === "") {
19
+ const message = file.message(messages.emptySegmentId, {
20
+ ancestors: [...parents, node],
21
+ place: node.position
22
+ });
23
+ message.actual = "";
24
+ return SKIP;
25
+ }
26
+ const message = file.message(messages.segmentIdLength(node.name), {
16
27
  ancestors: [...parents, node],
17
28
  place: node.position
18
29
  });
30
+ message.actual = node.name;
19
31
  });
20
32
  });
21
33
  //#endregion
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Root } from \"@glion/ast\";\nimport pluralize from \"pluralize\";\nimport { lintRule } from \"unified-lint-rule\";\nimport { SKIP, visitParents } from \"unist-util-visit-parents\";\n\n/**\n * Hl7v2-lint rule to warn when segment header length is invalid.\n */\nconst hl7v2LintSegmentHeaderLength = lintRule<Root, undefined>(\n {\n origin: \"hl7v2-lint:segment-header-length\",\n url: \"https://github.com/rethinkhealth/hl7v2/tree/main/packages/hl7v2-lint-segment-header-length#readme\",\n },\n (tree, file) => {\n visitParents<Root, \"segment\">(tree, \"segment\", (node, parents) => {\n const size = node.name.length;\n\n if (size === 3) {\n return SKIP;\n }\n\n file.message(\n `Unexpected ${size} header length, expected 3 characters, ${\n size > 3\n ? `remove ${size - 3} ${pluralize(\"character\", size - 3)}`\n : `add ${3 - size} ${pluralize(\"character\", 3 - size)}`\n }`,\n { ancestors: [...parents, node], place: node.position }\n );\n });\n }\n);\n\nexport default hl7v2LintSegmentHeaderLength;\n"],"mappings":";;;;;;;AAQA,MAAM,+BAA+B,SACnC;CACE,QAAQ;CACR,KAAK;CACN,GACA,MAAM,SAAS;AACd,cAA8B,MAAM,YAAY,MAAM,YAAY;EAChE,MAAM,OAAO,KAAK,KAAK;AAEvB,MAAI,SAAS,EACX,QAAO;AAGT,OAAK,QACH,cAAc,KAAK,yCACjB,OAAO,IACH,UAAU,OAAO,EAAE,GAAG,UAAU,aAAa,OAAO,EAAE,KACtD,OAAO,IAAI,KAAK,GAAG,UAAU,aAAa,IAAI,KAAK,MAEzD;GAAE,WAAW,CAAC,GAAG,SAAS,KAAK;GAAE,OAAO,KAAK;GAAU,CACxD;GACD;EAEL"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Root } from \"@glion/ast\";\nimport pluralize from \"pluralize\";\nimport { lintRule } from \"unified-lint-rule\";\nimport { SKIP, visitParents } from \"unist-util-visit-parents\";\n\nconst messages = {\n emptySegmentId:\n \"The segment has an empty Segment ID; a Segment ID must be exactly 3 characters.\",\n segmentIdLength: (segmentId: string) =>\n `The Segment ID \\`${segmentId}\\` is ${pluralize(\"character\", segmentId.length, true)} long; a Segment ID must be exactly 3 characters.`,\n} as const;\n\n/**\n * Hl7v2-lint rule to warn when segment header length is invalid.\n */\nconst hl7v2LintSegmentHeaderLength = lintRule<Root, undefined>(\n {\n origin: \"hl7v2-lint:segment-header-length\",\n url: \"https://github.com/rethinkhealth/glion/tree/main/packages/lint-segment-header-length#readme\",\n },\n (tree, file) => {\n visitParents<Root, \"segment\">(tree, \"segment\", (node, parents) => {\n if (node.name.length === 3) {\n return SKIP;\n }\n\n if (node.name === \"\") {\n const message = file.message(messages.emptySegmentId, {\n ancestors: [...parents, node],\n place: node.position,\n });\n message.actual = \"\";\n return SKIP;\n }\n\n const message = file.message(messages.segmentIdLength(node.name), {\n ancestors: [...parents, node],\n place: node.position,\n });\n message.actual = node.name;\n });\n }\n);\n\nexport default hl7v2LintSegmentHeaderLength;\n"],"mappings":";;;;AAKA,MAAM,WAAW;CACf,gBACE;CACF,kBAAkB,cAChB,oBAAoB,UAAU,QAAQ,UAAU,aAAa,UAAU,QAAQ,KAAK,CAAC;CACxF;;;;AAKD,MAAM,+BAA+B,SACnC;CACE,QAAQ;CACR,KAAK;CACN,GACA,MAAM,SAAS;AACd,cAA8B,MAAM,YAAY,MAAM,YAAY;AAChE,MAAI,KAAK,KAAK,WAAW,EACvB,QAAO;AAGT,MAAI,KAAK,SAAS,IAAI;GACpB,MAAM,UAAU,KAAK,QAAQ,SAAS,gBAAgB;IACpD,WAAW,CAAC,GAAG,SAAS,KAAK;IAC7B,OAAO,KAAK;IACb,CAAC;AACF,WAAQ,SAAS;AACjB,UAAO;;EAGT,MAAM,UAAU,KAAK,QAAQ,SAAS,gBAAgB,KAAK,KAAK,EAAE;GAChE,WAAW,CAAC,GAAG,SAAS,KAAK;GAC7B,OAAO,KAAK;GACb,CAAC;AACF,UAAQ,SAAS,KAAK;GACtB;EAEL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/lint-segment-header-length",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "hl7v2-lint rule to warn when segment header length is invalid",
5
5
  "keywords": [
6
6
  "definition",
@@ -51,8 +51,8 @@
51
51
  "typescript": "6.0.3",
52
52
  "vfile": "^6.0.3",
53
53
  "vitest": "4.1.11",
54
- "@glion/builder": "0.22.0",
55
- "@glion/ast": "0.22.0",
54
+ "@glion/ast": "0.23.0",
55
+ "@glion/builder": "0.23.0",
56
56
  "@glion/check-readme": "0.18.0",
57
57
  "@glion/testing": "0.18.0",
58
58
  "@glion/tsconfig": "0.18.0"