@bscotch/stitch
Version:
Stitch: The GameMaker Studio 2 Asset Pipeline Development Kit.
54 lines • 1.91 kB
JavaScript
import chalk from 'chalk';
import paths from '../utility/paths.js';
export class Linter {
project;
_report;
constructor(project, options) {
this.project = project;
this._report = this.lint(options);
}
/** Shallow clone of the raw report. */
getReport() {
return { ...this._report };
}
/** Console-friendly report */
getReportString() {
const _clickablePath = (token) => {
const path = paths.relative(process.cwd(), token.location.filepathAbsolute);
return path.includes(' ') ? `"${path}"` : path;
};
const report = [];
if (this._report.nonreferencedFunctions) {
report.push('', chalk.yellow('Nonreferenced Functions'));
for (const func of this._report.nonreferencedFunctions) {
report.push(_clickablePath(func));
}
}
if (this._report.outdatedFunctionReferences) {
report.push('', chalk.red('Outdated Function Version References'));
for (const func of this._report.outdatedFunctionReferences) {
report.push(_clickablePath(func));
}
}
return report.join('\n');
}
/** Lint this project, resulting in a report of potential issues. */
lint(options) {
const funcs = this.project.findGlobalFunctionReferences({
versionSuffix: options?.versionSuffix,
});
const report = {
nonreferencedFunctions: funcs
.filter((f) => f.references.length == 0)
.map((f) => f.token),
};
if (options?.versionSuffix) {
report.outdatedFunctionReferences = funcs
.map((f) => f.references.filter((r) => !r.isCorrectVersion))
.flat(1);
}
this._report = report;
return report;
}
}
//# sourceMappingURL=Linter.js.map