@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.
- package/LICENSE +661 -0
- package/NOTICE +29 -0
- package/README.md +34 -0
- package/dist/engine/config.d.ts +33 -0
- package/dist/engine/config.d.ts.map +1 -0
- package/dist/engine/config.js +61 -0
- package/dist/engine/config.js.map +1 -0
- package/dist/engine/ignore.d.ts +8 -0
- package/dist/engine/ignore.d.ts.map +1 -0
- package/dist/engine/ignore.js +17 -0
- package/dist/engine/ignore.js.map +1 -0
- package/dist/engine/lint.d.ts +38 -0
- package/dist/engine/lint.d.ts.map +1 -0
- package/dist/engine/lint.js +33 -0
- package/dist/engine/lint.js.map +1 -0
- package/dist/engine/rank.d.ts +24 -0
- package/dist/engine/rank.d.ts.map +1 -0
- package/dist/engine/rank.js +38 -0
- package/dist/engine/rank.js.map +1 -0
- package/dist/engine/run.d.ts +21 -0
- package/dist/engine/run.d.ts.map +1 -0
- package/dist/engine/run.js +43 -0
- package/dist/engine/run.js.map +1 -0
- package/dist/format/index.d.ts +11 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +21 -0
- package/dist/format/index.js.map +1 -0
- package/dist/format/json.d.ts +4 -0
- package/dist/format/json.d.ts.map +1 -0
- package/dist/format/json.js +20 -0
- package/dist/format/json.js.map +1 -0
- package/dist/format/markdown.d.ts +4 -0
- package/dist/format/markdown.d.ts.map +1 -0
- package/dist/format/markdown.js +28 -0
- package/dist/format/markdown.js.map +1 -0
- package/dist/format/sarif.d.ts +4 -0
- package/dist/format/sarif.d.ts.map +1 -0
- package/dist/format/sarif.js +77 -0
- package/dist/format/sarif.js.map +1 -0
- package/dist/format/text.d.ts +31 -0
- package/dist/format/text.d.ts.map +1 -0
- package/dist/format/text.js +57 -0
- package/dist/format/text.js.map +1 -0
- package/dist/index/build.d.ts +11 -0
- package/dist/index/build.d.ts.map +1 -0
- package/dist/index/build.js +11 -0
- package/dist/index/build.js.map +1 -0
- package/dist/index/references.d.ts +37 -0
- package/dist/index/references.d.ts.map +1 -0
- package/dist/index/references.js +126 -0
- package/dist/index/references.js.map +1 -0
- package/dist/index/relationships.d.ts +10 -0
- package/dist/index/relationships.d.ts.map +1 -0
- package/dist/index/relationships.js +24 -0
- package/dist/index/relationships.js.map +1 -0
- package/dist/index/usage.d.ts +11 -0
- package/dist/index/usage.d.ts.map +1 -0
- package/dist/index/usage.js +25 -0
- package/dist/index/usage.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/model/build.d.ts +9 -0
- package/dist/model/build.d.ts.map +1 -0
- package/dist/model/build.js +282 -0
- package/dist/model/build.js.map +1 -0
- package/dist/model/names.d.ts +12 -0
- package/dist/model/names.d.ts.map +1 -0
- package/dist/model/names.js +21 -0
- package/dist/model/names.js.map +1 -0
- package/dist/model/types.d.ts +150 -0
- package/dist/model/types.d.ts.map +1 -0
- package/dist/model/types.js +2 -0
- package/dist/model/types.js.map +1 -0
- package/dist/rules/helpers.d.ts +54 -0
- package/dist/rules/helpers.d.ts.map +1 -0
- package/dist/rules/helpers.js +189 -0
- package/dist/rules/helpers.js.map +1 -0
- package/dist/rules/index.d.ts +3 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +4 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/microsoft-bpa/bpa-rules.data.d.ts +12 -0
- package/dist/rules/microsoft-bpa/bpa-rules.data.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/bpa-rules.data.js +664 -0
- package/dist/rules/microsoft-bpa/bpa-rules.data.js.map +1 -0
- package/dist/rules/microsoft-bpa/columns.d.ts +14 -0
- package/dist/rules/microsoft-bpa/columns.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/columns.js +117 -0
- package/dist/rules/microsoft-bpa/columns.js.map +1 -0
- package/dist/rules/microsoft-bpa/define.d.ts +14 -0
- package/dist/rules/microsoft-bpa/define.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/define.js +75 -0
- package/dist/rules/microsoft-bpa/define.js.map +1 -0
- package/dist/rules/microsoft-bpa/dependencies.d.ts +11 -0
- package/dist/rules/microsoft-bpa/dependencies.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/dependencies.js +56 -0
- package/dist/rules/microsoft-bpa/dependencies.js.map +1 -0
- package/dist/rules/microsoft-bpa/index.d.ts +4 -0
- package/dist/rules/microsoft-bpa/index.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/index.js +20 -0
- package/dist/rules/microsoft-bpa/index.js.map +1 -0
- package/dist/rules/microsoft-bpa/live-model.d.ts +3 -0
- package/dist/rules/microsoft-bpa/live-model.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/live-model.js +10 -0
- package/dist/rules/microsoft-bpa/live-model.js.map +1 -0
- package/dist/rules/microsoft-bpa/measures.d.ts +15 -0
- package/dist/rules/microsoft-bpa/measures.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/measures.js +69 -0
- package/dist/rules/microsoft-bpa/measures.js.map +1 -0
- package/dist/rules/microsoft-bpa/naming.d.ts +14 -0
- package/dist/rules/microsoft-bpa/naming.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/naming.js +47 -0
- package/dist/rules/microsoft-bpa/naming.js.map +1 -0
- package/dist/rules/microsoft-bpa/relationships.d.ts +14 -0
- package/dist/rules/microsoft-bpa/relationships.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/relationships.js +97 -0
- package/dist/rules/microsoft-bpa/relationships.js.map +1 -0
- package/dist/rules/microsoft-bpa/tables.d.ts +16 -0
- package/dist/rules/microsoft-bpa/tables.d.ts.map +1 -0
- package/dist/rules/microsoft-bpa/tables.js +147 -0
- package/dist/rules/microsoft-bpa/tables.js.map +1 -0
- package/dist/rules/parse-issue.d.ts +4 -0
- package/dist/rules/parse-issue.d.ts.map +1 -0
- package/dist/rules/parse-issue.js +19 -0
- package/dist/rules/parse-issue.js.map +1 -0
- package/dist/rules/rule-summaries.data.d.ts +3 -0
- package/dist/rules/rule-summaries.data.d.ts.map +1 -0
- package/dist/rules/rule-summaries.data.js +78 -0
- package/dist/rules/rule-summaries.data.js.map +1 -0
- package/dist/rules/types.d.ts +42 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +15 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/tmdl/parse.d.ts +7 -0
- package/dist/tmdl/parse.d.ts.map +1 -0
- package/dist/tmdl/parse.js +196 -0
- package/dist/tmdl/parse.js.map +1 -0
- package/dist/tmdl/quote.d.ts +5 -0
- package/dist/tmdl/quote.d.ts.map +1 -0
- package/dist/tmdl/quote.js +15 -0
- package/dist/tmdl/quote.js.map +1 -0
- package/dist/tmdl/types.d.ts +32 -0
- package/dist/tmdl/types.d.ts.map +1 -0
- package/dist/tmdl/types.js +2 -0
- package/dist/tmdl/types.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +51 -0
- package/src/engine/config.ts +91 -0
- package/src/engine/ignore.ts +18 -0
- package/src/engine/lint.ts +79 -0
- package/src/engine/rank.ts +67 -0
- package/src/engine/run.ts +67 -0
- package/src/format/index.ts +37 -0
- package/src/format/json.ts +22 -0
- package/src/format/markdown.ts +37 -0
- package/src/format/sarif.ts +85 -0
- package/src/format/text.ts +90 -0
- package/src/index/build.ts +18 -0
- package/src/index/references.ts +170 -0
- package/src/index/relationships.ts +33 -0
- package/src/index/usage.ts +33 -0
- package/src/index.ts +80 -0
- package/src/model/build.ts +306 -0
- package/src/model/names.ts +31 -0
- package/src/model/types.ts +165 -0
- package/src/rules/helpers.ts +223 -0
- package/src/rules/index.ts +5 -0
- package/src/rules/microsoft-bpa/bpa-rules.data.ts +782 -0
- package/src/rules/microsoft-bpa/columns.ts +192 -0
- package/src/rules/microsoft-bpa/define.ts +84 -0
- package/src/rules/microsoft-bpa/dependencies.ts +95 -0
- package/src/rules/microsoft-bpa/index.ts +22 -0
- package/src/rules/microsoft-bpa/live-model.ts +10 -0
- package/src/rules/microsoft-bpa/measures.ts +143 -0
- package/src/rules/microsoft-bpa/naming.ts +104 -0
- package/src/rules/microsoft-bpa/relationships.ts +189 -0
- package/src/rules/microsoft-bpa/tables.ts +249 -0
- package/src/rules/parse-issue.ts +23 -0
- package/src/rules/rule-summaries.data.ts +144 -0
- package/src/rules/types.ts +87 -0
- package/src/tmdl/parse.ts +194 -0
- package/src/tmdl/quote.ts +15 -0
- package/src/tmdl/types.ts +34 -0
- 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
|
+
}
|