@glion/lint-segment-header-length 0.22.0 → 0.24.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 +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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
|
|
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
|
-
|
|
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
|
-
|
|
87
|
+
The Segment ID `MS` is 2 characters long; a Segment ID must be exactly 3 characters.
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
|
|
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
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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/
|
|
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
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
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/
|
|
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.
|
|
3
|
+
"version": "0.24.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/
|
|
55
|
-
"@glion/
|
|
54
|
+
"@glion/ast": "0.24.0",
|
|
55
|
+
"@glion/builder": "0.24.0",
|
|
56
56
|
"@glion/check-readme": "0.18.0",
|
|
57
57
|
"@glion/testing": "0.18.0",
|
|
58
58
|
"@glion/tsconfig": "0.18.0"
|