@pbiplint/core 0.1.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.
Files changed (189) hide show
  1. package/LICENSE +661 -0
  2. package/NOTICE +29 -0
  3. package/README.md +34 -0
  4. package/dist/engine/config.d.ts +33 -0
  5. package/dist/engine/config.d.ts.map +1 -0
  6. package/dist/engine/config.js +61 -0
  7. package/dist/engine/config.js.map +1 -0
  8. package/dist/engine/ignore.d.ts +8 -0
  9. package/dist/engine/ignore.d.ts.map +1 -0
  10. package/dist/engine/ignore.js +17 -0
  11. package/dist/engine/ignore.js.map +1 -0
  12. package/dist/engine/lint.d.ts +38 -0
  13. package/dist/engine/lint.d.ts.map +1 -0
  14. package/dist/engine/lint.js +33 -0
  15. package/dist/engine/lint.js.map +1 -0
  16. package/dist/engine/rank.d.ts +24 -0
  17. package/dist/engine/rank.d.ts.map +1 -0
  18. package/dist/engine/rank.js +38 -0
  19. package/dist/engine/rank.js.map +1 -0
  20. package/dist/engine/run.d.ts +21 -0
  21. package/dist/engine/run.d.ts.map +1 -0
  22. package/dist/engine/run.js +43 -0
  23. package/dist/engine/run.js.map +1 -0
  24. package/dist/format/index.d.ts +11 -0
  25. package/dist/format/index.d.ts.map +1 -0
  26. package/dist/format/index.js +21 -0
  27. package/dist/format/index.js.map +1 -0
  28. package/dist/format/json.d.ts +4 -0
  29. package/dist/format/json.d.ts.map +1 -0
  30. package/dist/format/json.js +20 -0
  31. package/dist/format/json.js.map +1 -0
  32. package/dist/format/markdown.d.ts +4 -0
  33. package/dist/format/markdown.d.ts.map +1 -0
  34. package/dist/format/markdown.js +28 -0
  35. package/dist/format/markdown.js.map +1 -0
  36. package/dist/format/sarif.d.ts +4 -0
  37. package/dist/format/sarif.d.ts.map +1 -0
  38. package/dist/format/sarif.js +77 -0
  39. package/dist/format/sarif.js.map +1 -0
  40. package/dist/format/text.d.ts +31 -0
  41. package/dist/format/text.d.ts.map +1 -0
  42. package/dist/format/text.js +57 -0
  43. package/dist/format/text.js.map +1 -0
  44. package/dist/index/build.d.ts +11 -0
  45. package/dist/index/build.d.ts.map +1 -0
  46. package/dist/index/build.js +11 -0
  47. package/dist/index/build.js.map +1 -0
  48. package/dist/index/references.d.ts +37 -0
  49. package/dist/index/references.d.ts.map +1 -0
  50. package/dist/index/references.js +126 -0
  51. package/dist/index/references.js.map +1 -0
  52. package/dist/index/relationships.d.ts +10 -0
  53. package/dist/index/relationships.d.ts.map +1 -0
  54. package/dist/index/relationships.js +24 -0
  55. package/dist/index/relationships.js.map +1 -0
  56. package/dist/index/usage.d.ts +11 -0
  57. package/dist/index/usage.d.ts.map +1 -0
  58. package/dist/index/usage.js +25 -0
  59. package/dist/index/usage.js.map +1 -0
  60. package/dist/index.d.ts +25 -0
  61. package/dist/index.d.ts.map +1 -0
  62. package/dist/index.js +21 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/model/build.d.ts +9 -0
  65. package/dist/model/build.d.ts.map +1 -0
  66. package/dist/model/build.js +282 -0
  67. package/dist/model/build.js.map +1 -0
  68. package/dist/model/names.d.ts +12 -0
  69. package/dist/model/names.d.ts.map +1 -0
  70. package/dist/model/names.js +21 -0
  71. package/dist/model/names.js.map +1 -0
  72. package/dist/model/types.d.ts +150 -0
  73. package/dist/model/types.d.ts.map +1 -0
  74. package/dist/model/types.js +2 -0
  75. package/dist/model/types.js.map +1 -0
  76. package/dist/rules/helpers.d.ts +54 -0
  77. package/dist/rules/helpers.d.ts.map +1 -0
  78. package/dist/rules/helpers.js +189 -0
  79. package/dist/rules/helpers.js.map +1 -0
  80. package/dist/rules/index.d.ts +3 -0
  81. package/dist/rules/index.d.ts.map +1 -0
  82. package/dist/rules/index.js +4 -0
  83. package/dist/rules/index.js.map +1 -0
  84. package/dist/rules/microsoft-bpa/bpa-rules.data.d.ts +12 -0
  85. package/dist/rules/microsoft-bpa/bpa-rules.data.d.ts.map +1 -0
  86. package/dist/rules/microsoft-bpa/bpa-rules.data.js +664 -0
  87. package/dist/rules/microsoft-bpa/bpa-rules.data.js.map +1 -0
  88. package/dist/rules/microsoft-bpa/columns.d.ts +14 -0
  89. package/dist/rules/microsoft-bpa/columns.d.ts.map +1 -0
  90. package/dist/rules/microsoft-bpa/columns.js +117 -0
  91. package/dist/rules/microsoft-bpa/columns.js.map +1 -0
  92. package/dist/rules/microsoft-bpa/define.d.ts +14 -0
  93. package/dist/rules/microsoft-bpa/define.d.ts.map +1 -0
  94. package/dist/rules/microsoft-bpa/define.js +75 -0
  95. package/dist/rules/microsoft-bpa/define.js.map +1 -0
  96. package/dist/rules/microsoft-bpa/dependencies.d.ts +11 -0
  97. package/dist/rules/microsoft-bpa/dependencies.d.ts.map +1 -0
  98. package/dist/rules/microsoft-bpa/dependencies.js +56 -0
  99. package/dist/rules/microsoft-bpa/dependencies.js.map +1 -0
  100. package/dist/rules/microsoft-bpa/index.d.ts +4 -0
  101. package/dist/rules/microsoft-bpa/index.d.ts.map +1 -0
  102. package/dist/rules/microsoft-bpa/index.js +20 -0
  103. package/dist/rules/microsoft-bpa/index.js.map +1 -0
  104. package/dist/rules/microsoft-bpa/live-model.d.ts +3 -0
  105. package/dist/rules/microsoft-bpa/live-model.d.ts.map +1 -0
  106. package/dist/rules/microsoft-bpa/live-model.js +10 -0
  107. package/dist/rules/microsoft-bpa/live-model.js.map +1 -0
  108. package/dist/rules/microsoft-bpa/measures.d.ts +15 -0
  109. package/dist/rules/microsoft-bpa/measures.d.ts.map +1 -0
  110. package/dist/rules/microsoft-bpa/measures.js +69 -0
  111. package/dist/rules/microsoft-bpa/measures.js.map +1 -0
  112. package/dist/rules/microsoft-bpa/naming.d.ts +14 -0
  113. package/dist/rules/microsoft-bpa/naming.d.ts.map +1 -0
  114. package/dist/rules/microsoft-bpa/naming.js +47 -0
  115. package/dist/rules/microsoft-bpa/naming.js.map +1 -0
  116. package/dist/rules/microsoft-bpa/relationships.d.ts +14 -0
  117. package/dist/rules/microsoft-bpa/relationships.d.ts.map +1 -0
  118. package/dist/rules/microsoft-bpa/relationships.js +97 -0
  119. package/dist/rules/microsoft-bpa/relationships.js.map +1 -0
  120. package/dist/rules/microsoft-bpa/tables.d.ts +16 -0
  121. package/dist/rules/microsoft-bpa/tables.d.ts.map +1 -0
  122. package/dist/rules/microsoft-bpa/tables.js +147 -0
  123. package/dist/rules/microsoft-bpa/tables.js.map +1 -0
  124. package/dist/rules/parse-issue.d.ts +4 -0
  125. package/dist/rules/parse-issue.d.ts.map +1 -0
  126. package/dist/rules/parse-issue.js +19 -0
  127. package/dist/rules/parse-issue.js.map +1 -0
  128. package/dist/rules/rule-summaries.data.d.ts +3 -0
  129. package/dist/rules/rule-summaries.data.d.ts.map +1 -0
  130. package/dist/rules/rule-summaries.data.js +78 -0
  131. package/dist/rules/rule-summaries.data.js.map +1 -0
  132. package/dist/rules/types.d.ts +42 -0
  133. package/dist/rules/types.d.ts.map +1 -0
  134. package/dist/rules/types.js +15 -0
  135. package/dist/rules/types.js.map +1 -0
  136. package/dist/tmdl/parse.d.ts +7 -0
  137. package/dist/tmdl/parse.d.ts.map +1 -0
  138. package/dist/tmdl/parse.js +196 -0
  139. package/dist/tmdl/parse.js.map +1 -0
  140. package/dist/tmdl/quote.d.ts +5 -0
  141. package/dist/tmdl/quote.d.ts.map +1 -0
  142. package/dist/tmdl/quote.js +15 -0
  143. package/dist/tmdl/quote.js.map +1 -0
  144. package/dist/tmdl/types.d.ts +32 -0
  145. package/dist/tmdl/types.d.ts.map +1 -0
  146. package/dist/tmdl/types.js +2 -0
  147. package/dist/tmdl/types.js.map +1 -0
  148. package/dist/version.d.ts +2 -0
  149. package/dist/version.d.ts.map +1 -0
  150. package/dist/version.js +3 -0
  151. package/dist/version.js.map +1 -0
  152. package/package.json +51 -0
  153. package/src/engine/config.ts +91 -0
  154. package/src/engine/ignore.ts +18 -0
  155. package/src/engine/lint.ts +79 -0
  156. package/src/engine/rank.ts +67 -0
  157. package/src/engine/run.ts +67 -0
  158. package/src/format/index.ts +37 -0
  159. package/src/format/json.ts +22 -0
  160. package/src/format/markdown.ts +37 -0
  161. package/src/format/sarif.ts +85 -0
  162. package/src/format/text.ts +90 -0
  163. package/src/index/build.ts +18 -0
  164. package/src/index/references.ts +170 -0
  165. package/src/index/relationships.ts +33 -0
  166. package/src/index/usage.ts +33 -0
  167. package/src/index.ts +80 -0
  168. package/src/model/build.ts +306 -0
  169. package/src/model/names.ts +31 -0
  170. package/src/model/types.ts +165 -0
  171. package/src/rules/helpers.ts +223 -0
  172. package/src/rules/index.ts +5 -0
  173. package/src/rules/microsoft-bpa/bpa-rules.data.ts +782 -0
  174. package/src/rules/microsoft-bpa/columns.ts +192 -0
  175. package/src/rules/microsoft-bpa/define.ts +84 -0
  176. package/src/rules/microsoft-bpa/dependencies.ts +95 -0
  177. package/src/rules/microsoft-bpa/index.ts +22 -0
  178. package/src/rules/microsoft-bpa/live-model.ts +10 -0
  179. package/src/rules/microsoft-bpa/measures.ts +143 -0
  180. package/src/rules/microsoft-bpa/naming.ts +104 -0
  181. package/src/rules/microsoft-bpa/relationships.ts +189 -0
  182. package/src/rules/microsoft-bpa/tables.ts +249 -0
  183. package/src/rules/parse-issue.ts +23 -0
  184. package/src/rules/rule-summaries.data.ts +144 -0
  185. package/src/rules/types.ts +87 -0
  186. package/src/tmdl/parse.ts +194 -0
  187. package/src/tmdl/quote.ts +15 -0
  188. package/src/tmdl/types.ts +34 -0
  189. package/src/version.ts +2 -0
@@ -0,0 +1,223 @@
1
+ import { columnRef, measureRef, relationshipName, tableRef } from "../model/names.js";
2
+ import type {
3
+ CalculationItem,
4
+ Column,
5
+ DataSource,
6
+ Hierarchy,
7
+ Level,
8
+ Measure,
9
+ Model,
10
+ NamedExpression,
11
+ Partition,
12
+ Perspective,
13
+ Relationship,
14
+ Role,
15
+ Table,
16
+ TablePermission,
17
+ } from "../model/types.js";
18
+ import type { ObjectType, RuleFinding } from "./types.js";
19
+
20
+ export const allColumns = (m: Model): Column[] => m.tables.flatMap((t) => t.columns);
21
+ export const allMeasures = (m: Model): Measure[] => m.tables.flatMap((t) => t.measures);
22
+ export const allPartitions = (m: Model): Partition[] => m.tables.flatMap((t) => t.partitions);
23
+ export const allHierarchies = (m: Model): Hierarchy[] => m.tables.flatMap((t) => t.hierarchies);
24
+ export const allLevels = (m: Model): Level[] => allHierarchies(m).flatMap((h) => h.levels);
25
+ export const allCalculationItems = (m: Model): CalculationItem[] =>
26
+ m.tables.flatMap((t) => t.calculationGroup?.items ?? []);
27
+ export const allTablePermissions = (m: Model): TablePermission[] =>
28
+ m.roles.flatMap((r) => r.tablePermissions);
29
+
30
+ export const dataType = (c: Column): string => (c.dataType ?? "").toLowerCase();
31
+ export const isNumericType = (c: Column): boolean =>
32
+ ["int64", "decimal", "double"].includes(dataType(c));
33
+ export const hiddenOrTableHidden = (c: Column): boolean => c.isHidden || c.table.isHidden;
34
+ export const isBlank = (s: string | undefined): boolean => s === undefined || s.trim() === "";
35
+ /** Escape a model object name for interpolation into a RegExp source. */
36
+ export const escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
37
+ /** Tabular Editor labels a table by its first partition's mode; DirectQuery tables are what several rules test for. */
38
+ export const isDirectQueryTable = (t: Table): boolean =>
39
+ t.kind === "table" && t.partitions[0]?.mode === "directquery";
40
+
41
+ /** Tables that satisfy the Table or CalculatedTable scope. Calculation group tables are only in the CalculationGroup scope. */
42
+ export const tablesInScope = (m: Model): Table[] =>
43
+ m.tables.filter((t) => t.kind !== "calculationGroup");
44
+
45
+ export const tableObjectType = (t: Table): ObjectType =>
46
+ t.kind === "calculated"
47
+ ? "CalculatedTable"
48
+ : t.kind === "calculationGroup"
49
+ ? "CalculationGroupTable"
50
+ : "Table";
51
+ export const columnObjectType = (c: Column): ObjectType =>
52
+ c.kind === "calculated"
53
+ ? "CalculatedColumn"
54
+ : c.kind === "calculatedTable"
55
+ ? "CalculatedTableColumn"
56
+ : "Column";
57
+
58
+ /** Finding factories. Object names follow Tabular Editor's display names (see the plan's naming table). */
59
+ export const finding = {
60
+ // A model synthesized because the folder has no model.tmdl has no real location, so Model
61
+ // findings carry none rather than pointing at line 0 of an empty file name.
62
+ model: (m: Model): RuleFinding => ({
63
+ objectType: "Model",
64
+ objectName: "Model",
65
+ ...(m.location.file === "" ? {} : { location: m.location }),
66
+ object: m,
67
+ }),
68
+ table: (t: Table): RuleFinding => ({
69
+ objectType: tableObjectType(t),
70
+ objectName: tableRef(t.name),
71
+ location: t.location,
72
+ object: t,
73
+ }),
74
+ column: (c: Column): RuleFinding => ({
75
+ objectType: columnObjectType(c),
76
+ objectName: columnRef(c.table.name, c.name),
77
+ location: c.location,
78
+ object: c,
79
+ }),
80
+ measure: (x: Measure): RuleFinding => ({
81
+ objectType: "Measure",
82
+ objectName: measureRef(x.name),
83
+ location: x.location,
84
+ object: x,
85
+ }),
86
+ partition: (p: Partition): RuleFinding => ({
87
+ objectType: "Partition",
88
+ objectName: p.name,
89
+ location: p.location,
90
+ detail: `table ${tableRef(p.table.name)}`,
91
+ object: p,
92
+ }),
93
+ relationship: (r: Relationship): RuleFinding => ({
94
+ objectType: "Relationship",
95
+ objectName: relationshipName(r),
96
+ location: r.location,
97
+ object: r,
98
+ }),
99
+ role: (r: Role): RuleFinding => ({
100
+ objectType: "Role",
101
+ objectName: r.name,
102
+ location: r.location,
103
+ object: r,
104
+ }),
105
+ tablePermission: (tp: TablePermission): RuleFinding => ({
106
+ objectType: "TablePermission",
107
+ objectName: tp.table,
108
+ location: tp.location,
109
+ detail: `role ${tp.role.name}`,
110
+ object: tp,
111
+ }),
112
+ perspective: (p: Perspective): RuleFinding => ({
113
+ objectType: "Perspective",
114
+ objectName: p.name,
115
+ location: p.location,
116
+ object: p,
117
+ }),
118
+ hierarchy: (h: Hierarchy): RuleFinding => ({
119
+ objectType: "Hierarchy",
120
+ objectName: h.name,
121
+ location: h.location,
122
+ detail: `table ${tableRef(h.table.name)}`,
123
+ object: h,
124
+ }),
125
+ level: (l: Level): RuleFinding => ({
126
+ objectType: "Level",
127
+ objectName: l.name,
128
+ location: l.location,
129
+ detail: `hierarchy ${l.hierarchy.name} in ${tableRef(l.hierarchy.table.name)}`,
130
+ object: l,
131
+ }),
132
+ calculationItem: (i: CalculationItem): RuleFinding => ({
133
+ objectType: "CalculationItem",
134
+ objectName: i.name,
135
+ location: i.location,
136
+ detail: `calculation group ${tableRef(i.table.name)}`,
137
+ object: i,
138
+ }),
139
+ expression: (e: NamedExpression): RuleFinding => ({
140
+ objectType: "NamedExpression",
141
+ objectName: e.name,
142
+ location: e.location,
143
+ object: e,
144
+ }),
145
+ dataSource: (d: DataSource): RuleFinding => ({
146
+ objectType: "DataSource",
147
+ objectName: d.name,
148
+ location: d.location,
149
+ object: d,
150
+ }),
151
+ };
152
+
153
+ export interface NamedObject {
154
+ finding: RuleFinding;
155
+ name: string;
156
+ description?: string;
157
+ }
158
+
159
+ /** Every object of the given types, in model order, for rules that only look at names or descriptions. */
160
+ export function namedObjects(m: Model, types: ObjectType[]): NamedObject[] {
161
+ const want = new Set(types);
162
+ const out: NamedObject[] = [];
163
+ const push = (f: RuleFinding, name: string, description?: string) => {
164
+ if (want.has(f.objectType)) out.push({ finding: f, name, description });
165
+ };
166
+ push(finding.model(m), m.name, m.description);
167
+ for (const t of m.tables) {
168
+ push(finding.table(t), t.name, t.description);
169
+ for (const c of t.columns) push(finding.column(c), c.name, c.description);
170
+ for (const x of t.measures) push(finding.measure(x), x.name, x.description);
171
+ for (const h of t.hierarchies) {
172
+ push(finding.hierarchy(h), h.name, h.description);
173
+ for (const l of h.levels) push(finding.level(l), l.name, l.description);
174
+ }
175
+ for (const p of t.partitions) push(finding.partition(p), p.name, p.description);
176
+ for (const i of t.calculationGroup?.items ?? [])
177
+ push(finding.calculationItem(i), i.name, i.description);
178
+ }
179
+ for (const r of m.relationships) push(finding.relationship(r), r.name, r.description);
180
+ for (const r of m.roles) {
181
+ push(finding.role(r), r.name, r.description);
182
+ for (const tp of r.tablePermissions) push(finding.tablePermission(tp), tp.name, tp.description);
183
+ }
184
+ for (const p of m.perspectives) push(finding.perspective(p), p.name, p.description);
185
+ for (const e of m.expressions) push(finding.expression(e), e.name, e.description);
186
+ for (const d of m.dataSources) push(finding.dataSource(d), d.name, d.description);
187
+ return out;
188
+ }
189
+
190
+ export type ExpressionKind = "measure" | "calculatedColumn" | "calculationItem";
191
+
192
+ export interface ExpressionObject {
193
+ kind: ExpressionKind;
194
+ finding: RuleFinding;
195
+ expression: string;
196
+ }
197
+
198
+ /** Measures, calculated columns, and calculation items (the objects DAX rules are scoped to), in model order. */
199
+ export function expressionObjects(m: Model, kinds: ExpressionKind[]): ExpressionObject[] {
200
+ const want = new Set(kinds);
201
+ const out: ExpressionObject[] = [];
202
+ for (const t of m.tables) {
203
+ if (want.has("measure"))
204
+ for (const x of t.measures)
205
+ out.push({ kind: "measure", finding: finding.measure(x), expression: x.expression });
206
+ if (want.has("calculatedColumn"))
207
+ for (const c of t.columns)
208
+ if (c.kind === "calculated")
209
+ out.push({
210
+ kind: "calculatedColumn",
211
+ finding: finding.column(c),
212
+ expression: c.expression ?? "",
213
+ });
214
+ if (want.has("calculationItem"))
215
+ for (const i of t.calculationGroup?.items ?? [])
216
+ out.push({
217
+ kind: "calculationItem",
218
+ finding: finding.calculationItem(i),
219
+ expression: i.expression,
220
+ });
221
+ }
222
+ return out;
223
+ }
@@ -0,0 +1,5 @@
1
+ import { microsoftBpaRules } from "./microsoft-bpa/index.js";
2
+ import { PARSE_ISSUE } from "./parse-issue.js";
3
+ import type { Rule } from "./types.js";
4
+
5
+ export const defaultRules: Rule[] = [PARSE_ISSUE, ...microsoftBpaRules];