@glion/lint-profile-field-repetition 0.14.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Rethink Health
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ import type { Root } from "@glion/ast";
2
+ /**
3
+ * Lint rule that flags fields with multiple repetitions when the profile
4
+ * declares `repeatable: false`.
5
+ *
6
+ * A field with a single repetition is always valid regardless of the
7
+ * `repeatable` flag. Only fields with 2+ repetitions on a non-repeatable
8
+ * field are reported.
9
+ *
10
+ * Segments without a known profile (e.g., Z-segments) are silently skipped.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * unified().use(hl7v2LintFieldRepetition);
15
+ * ```;
16
+ */
17
+ declare const hl7v2LintFieldRepetition: import("unified-lint-rule").Plugin<Root, unknown>;
18
+ export default hl7v2LintFieldRepetition;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIvC;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,wBAAwB,mDAuC7B,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ import { SKIP, visit } from "@glion/util-visit";
2
+ import { lintRule } from "unified-lint-rule";
3
+ //#region src/index.ts
4
+ /**
5
+ * Lint rule that flags fields with multiple repetitions when the profile
6
+ * declares `repeatable: false`.
7
+ *
8
+ * A field with a single repetition is always valid regardless of the
9
+ * `repeatable` flag. Only fields with 2+ repetitions on a non-repeatable
10
+ * field are reported.
11
+ *
12
+ * Segments without a known profile (e.g., Z-segments) are silently skipped.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * unified().use(hl7v2LintFieldRepetition);
17
+ * ```;
18
+ */
19
+ const hl7v2LintFieldRepetition = lintRule({ origin: "hl7v2-lint:field-repetition" }, (tree, file) => {
20
+ const ctx = file.data.profile;
21
+ if (!ctx) return;
22
+ visit(tree, "segment", (segment, segmentAncestors) => {
23
+ const fieldDef = ctx.fields.get(segment.name);
24
+ if (!fieldDef) return SKIP;
25
+ visit(segment, "field", (fieldNode, _fieldAncestors, info) => {
26
+ const profile = fieldDef.bySequence.get(info.sequence);
27
+ if (!profile || profile.repeatable) return SKIP;
28
+ const count = fieldNode.children.length;
29
+ if (count > 1) {
30
+ const name = profile.name ? ` (${profile.name})` : "";
31
+ file.message(`Field ${segment.name}-${info.sequence}${name} is not repeatable but has ${count} repetitions`, {
32
+ ancestors: [
33
+ ...segmentAncestors,
34
+ segment,
35
+ fieldNode
36
+ ],
37
+ place: fieldNode.position
38
+ });
39
+ }
40
+ return SKIP;
41
+ });
42
+ return SKIP;
43
+ });
44
+ });
45
+ //#endregion
46
+ export { hl7v2LintFieldRepetition as default };
47
+
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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\";\nimport type { Root } from \"@glion/ast\";\nimport { SKIP, visit } from \"@glion/util-visit\";\nimport { lintRule } from \"unified-lint-rule\";\n\n/**\n * Lint rule that flags fields with multiple repetitions when the profile\n * declares `repeatable: false`.\n *\n * A field with a single repetition is always valid regardless of the\n * `repeatable` flag. Only fields with 2+ repetitions on a non-repeatable\n * field are reported.\n *\n * Segments without a known profile (e.g., Z-segments) are silently skipped.\n *\n * @example\n * ```typescript\n * unified().use(hl7v2LintFieldRepetition);\n * ```;\n */\nconst hl7v2LintFieldRepetition = lintRule<Root>(\n { origin: \"hl7v2-lint:field-repetition\" },\n (tree, file) => {\n const ctx = file.data.profile;\n if (!ctx) {\n return;\n }\n\n visit(tree, \"segment\", (segment, segmentAncestors) => {\n const fieldDef = ctx.fields.get(segment.name);\n if (!fieldDef) {\n return SKIP;\n }\n\n visit(segment, \"field\", (fieldNode, _fieldAncestors, info) => {\n const profile = fieldDef.bySequence.get(info.sequence);\n\n if (!profile || profile.repeatable) {\n return SKIP;\n }\n\n const count = fieldNode.children.length;\n if (count > 1) {\n const name = profile.name ? ` (${profile.name})` : \"\";\n file.message(\n `Field ${segment.name}-${info.sequence}${name} is not repeatable but has ${count} repetitions`,\n {\n ancestors: [...segmentAncestors, segment, fieldNode],\n place: fieldNode.position,\n }\n );\n }\n\n return SKIP;\n });\n\n return SKIP;\n });\n }\n);\n\nexport default hl7v2LintFieldRepetition;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,MAAM,2BAA2B,SAC/B,EAAE,QAAQ,+BAA+B,GACxC,MAAM,SAAS;CACd,MAAM,MAAM,KAAK,KAAK;AACtB,KAAI,CAAC,IACH;AAGF,OAAM,MAAM,YAAY,SAAS,qBAAqB;EACpD,MAAM,WAAW,IAAI,OAAO,IAAI,QAAQ,KAAK;AAC7C,MAAI,CAAC,SACH,QAAO;AAGT,QAAM,SAAS,UAAU,WAAW,iBAAiB,SAAS;GAC5D,MAAM,UAAU,SAAS,WAAW,IAAI,KAAK,SAAS;AAEtD,OAAI,CAAC,WAAW,QAAQ,WACtB,QAAO;GAGT,MAAM,QAAQ,UAAU,SAAS;AACjC,OAAI,QAAQ,GAAG;IACb,MAAM,OAAO,QAAQ,OAAO,KAAK,QAAQ,KAAK,KAAK;AACnD,SAAK,QACH,SAAS,QAAQ,KAAK,GAAG,KAAK,WAAW,KAAK,6BAA6B,MAAM,eACjF;KACE,WAAW;MAAC,GAAG;MAAkB;MAAS;MAAU;KACpD,OAAO,UAAU;KAClB,CACF;;AAGH,UAAO;IACP;AAEF,SAAO;GACP;EAEL"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@glion/lint-profile-field-repetition",
3
+ "version": "0.14.1",
4
+ "description": "Lint rule that flags non-repeatable fields with multiple repetitions",
5
+ "keywords": [
6
+ "health",
7
+ "healthcare",
8
+ "hl7",
9
+ "hl7v2",
10
+ "nodejs",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://glion.dev",
14
+ "license": "MIT",
15
+ "author": {
16
+ "name": "Melek Somai",
17
+ "email": "melek@rethinkhealth.io"
18
+ },
19
+ "repository": "rethinkhealth/glion.git",
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "type": "module",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": "./dist/index.js"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "dependencies": {
32
+ "unified-lint-rule": "3.0.1",
33
+ "@glion/util-visit": "0.14.1",
34
+ "@glion/ast": "0.14.1"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^25.5.0",
38
+ "@vitest/coverage-v8": "4.1.2",
39
+ "tsdown": "0.21.7",
40
+ "typescript": "^5.9.3",
41
+ "unified": "^11.0.5",
42
+ "vfile": "^6.0.3",
43
+ "vitest": "4.1.2",
44
+ "@glion/tsconfig": "0.0.1",
45
+ "@glion/testing": "0.0.2",
46
+ "@glion/builder": "0.14.1",
47
+ "@glion/annotate-profile-context": "0.14.1"
48
+ },
49
+ "engines": {
50
+ "node": ">=18"
51
+ },
52
+ "scripts": {
53
+ "build": "tsdown && tsc --emitDeclarationOnly",
54
+ "check-types": "tsc --noEmit",
55
+ "bench": "vitest bench --run",
56
+ "test": "vitest run",
57
+ "test:coverage": "vitest run --coverage",
58
+ "test:watch": "vitest"
59
+ }
60
+ }