@pbiplint/core
v0.3.4
Published
Best-practice linter core for Power BI projects: the semantic model (TMDL) and the report (PBIR). Runs in the browser and in Node, makes no network calls.
Maintainers
Readme
@pbiplint/core
The linter behind pbiplint: parse TMDL and PBIR, build the semantic model
and the report, run the best-practice rules, rank the findings, and format them. Pure TypeScript
with no Node APIs and no network access, so it runs in a browser tab as well as in Node 20.19 or
later (or 22.12 or later). It has one dependency, Microsoft's M parser
(@microsoft/powerquery-parser, MIT), and still
makes no network call.
Installing the core on Node 20 prints npm's EBADENGINE warning, because the parser declares Node
22, and installs anyway; the parser uses nothing Node 22 added.
lint(files) takes both parts of a Power BI project, .tmdl files for the model and the report's
JSON (paths relative to each part's root), and returns findings for both, layers saying which
part was read, facts for "Report at a glance", and diagnostics for what a reader of the results
must know about the input, such as a file that could not be read. Either part alone is valid
input; with both parts, each is also checked against the other, for example the report for fields
the model does not have and the model for columns and measures the report never reaches.
From 0.3.0, lint() returns a Promise, because it reads M with Microsoft's Power Query parser,
whose parse is async.
import { formatText, lint } from "@pbiplint/core";
const result = await lint([
{ path: "definition/model.tmdl", text: modelTmdl },
{ path: "definition/tables/Sales.tmdl", text: salesTmdl },
]);
console.log(formatText(result)); // or formatJson, formatMarkdown, formatSarif
for (const group of result.groups) console.log(group.rule.id, group.findings.length, group.rule.url);result.groups is ranked by severity, then category, then count, exactly as the command line and
the website show it. Every rule has a page at https://pbiplint.com/rules/<slug>; group.rule.url
points at it.
showOnly(result, ruleIds, config) keeps a result to some rules' findings, as the command line's
--rule does: every rule still ran, result.summary.shown counts what is kept (the rest of the
summary stays the whole run's), failed follows the kept findings, summaryLine (and with it the
text and Markdown formats) says the result is filtered ("3 of 280 findings shown, 1 rule ..."), and
the JSON format carries summary.shown. It is absent on an unfiltered result.
The optional second argument, lint(files, options), takes the config, the rules to run, and
what the caller's input reader found besides the files. config is a pbiplint.config.json
object. rules lists the rules to run in place of the default set, defaultRules. diagnostics
are the reader's notices, such as a file it could not read, carried onto the result. absent
gives, per layer, why the reader left that layer out, for the skipped line. unreadPaths lists,
per layer, the files and folders the reader could not read, each relative to its part's root in
forward slashes and a folder with a trailing /; a path that is not a file the layer reads (a
.tmdl file for the model, a file isReportFile accepts for the report) is read as a folder. The
layer then knows what it lacks, so no finding or fact states what was not read. A TMDL line the
parser cannot place, including a declaration its object does not hold, such as a misspelt columm
under a table, is a PARSE_ISSUE error finding on that line rather than being dropped
silently.
The model rules are the Microsoft Best Practice Analyzer ruleset, each rule rebuilt in pbiplint and checked against Tabular Editor's findings, and pbiplint's own rules for a year or a date fixed in DAX, for DAX user-defined functions, for translations, and for decimal columns' format strings, four of them taking their test from Tabular Editor 3's built-in rules or Tabular Editor's community rule files and checked against Tabular Editor. The report rules are the 11 base rules of PBI Inspector by Nat Van Gulck, each rebuilt in pbiplint and checked against fab-inspector's findings, and pbiplint's own rules for the report and for the model and report together. A rebuilt rule behaves as its source does, apart from twelve documented differences from the Microsoft ruleset and six from PBI Inspector, each explained on its rule's page. A column whose TMDL names no type, as Power BI Desktop saves most calculated columns, is left out of the thirteen ported rules that test a column's type, where Tabular Editor reads the type from the column's DAX.
The Power Query rules read the M behind each table's partitions, the shared expressions, and
incremental refresh policies, parsed with Microsoft's Power Query parser, and the file's Power Query
options: 16 rules, MINIMIZE_POWER_QUERY_TRANSFORMATIONS and 15 of pbiplint's own, each with
rule.layer powerquery while its findings' layer stays model. A finding in M carries
location.column as well as its line. 123 rules in all, 41 of them built into pbiplint.
A finding's detail is English. From 0.3.2, a built-in rule's finding also carries the message
the detail was rendered from, messageId and params, so a caller can show it in another
language: findingDetail(finding, catalog?, locale?) renders it from a catalog (EN, the English
one, by default) and takes detail for a finding without one, and formatMessage(message, catalog?,
locale?) renders any message. A message ID is the rule's ID, or the rule's ID and a variant, such
as BROKEN_BOOKMARK_REFERENCE.activePage, and the IDs and their params are stable, so a catalog
written for one release keeps working. A finding's messageId can also be a message shared across
rules: context.table, context.role, context.level, or context.calculationGroup, the object's
context on some Microsoft BPA findings; query.finding or query.stepFinding, the frame that names
the query on a Power Query finding, with the rule's own message in params.finding; or
PARSE_ISSUE, with the reason nested in params.reason.
For the command line, install pbiplint. Source, issues,
and contributing: https://github.com/pbiplint/pbiplint.
License
Copyright (C) 2026 McKinley Consulting. GNU Affero General Public License, version 3 or later; see LICENSE. The vendored Microsoft ruleset and PBI Inspector rule metadata are MIT-licensed; see NOTICE. The name pbiplint and its logo are trademarks of McKinley Consulting.
