UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

113 lines 4.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LintingPrettyPrintContext = exports.LintingRuleCertainty = exports.LintingResultCertainty = exports.LintingResults = void 0; const assert_1 = require("../util/assert"); /** * Helper functions for working with {@link LintingResults}. */ exports.LintingResults = { /** * Checks whether the given linting results represent an error. * @see {@link LintingResultsError} * @see {@link LintingResults.isSuccess} */ isError(o) { return 'error' in o; }, /** * Checks whether the given linting results represent a successful execution. * @see {@link LintingResultsSuccess} * @see {@link LintingResults.isError} * @see {@link LintingResults.unpackSuccess} */ isSuccess(o) { return 'results' in o; }, /** * Unpacks the given linting results, throwing an error if they represent an error. */ unpackSuccess(o) { if (exports.LintingResults.isSuccess(o)) { return o; } throw new Error(exports.LintingResults.stringifyError(o)); }, /** * Gets all involved node IDs from the given linting results. * If the results represent an error, an empty set is returned. */ allInvolvedIds(res) { if (!res || exports.LintingResults.isError(res)) { return new Set(); } return new Set(res.results.flatMap(r => r.involvedId).filter(assert_1.isNotUndefined)); }, /** * Gets all locations from the given linting results, i.e. the `loc` property of all results that have a location. */ allLocations(res) { if (!res || exports.LintingResults.isError(res)) { return []; } return res.results.filter(exports.LintingResults.hasLocation).map(r => r.loc); }, /** * Stringifies the error contained in the given linting results error. */ stringifyError({ error }) { if (error instanceof Error) { return error.message; } if (typeof error === 'string') { return error; } try { return JSON.stringify(error); } catch { return String(error); } }, /** * Checks whether the given linting result has a location, i.e. whether it has a `loc` property. */ hasLocation(res) { return 'loc' in res; } }; var LintingResultCertainty; (function (LintingResultCertainty) { /** * The linting rule cannot say for sure whether the result is correct or not. * This linting certainty should be used for linting results whose calculations are based on estimations involving unknown side effects, reflection, etc. */ LintingResultCertainty["Uncertain"] = "uncertain"; /** * The linting rule is certain that the reported lint is real. * This linting certainty should be used for linting results whose calculations do not involve estimates or other unknown factors. */ LintingResultCertainty["Certain"] = "certain"; })(LintingResultCertainty || (exports.LintingResultCertainty = LintingResultCertainty = {})); var LintingRuleCertainty; (function (LintingRuleCertainty) { /** * Linting rules that are expected to have both high precision and high recall. */ LintingRuleCertainty["Exact"] = "exact"; /** * Linting rules that are expected to have high precision, but not necessarily high recall. * Rules with this certainty generally ensure that the results they return are correct, but may not return all results. */ LintingRuleCertainty["BestEffort"] = "best-effort"; /** * Linting rules that are expected to have high recall, but not necessarily high precision. * Rules with this certainty generally return all relevant results, but may also include some incorrect matches. */ LintingRuleCertainty["OverApproximative"] = "over-approximative"; })(LintingRuleCertainty || (exports.LintingRuleCertainty = LintingRuleCertainty = {})); var LintingPrettyPrintContext; (function (LintingPrettyPrintContext) { LintingPrettyPrintContext["Query"] = "query"; LintingPrettyPrintContext["Full"] = "full"; })(LintingPrettyPrintContext || (exports.LintingPrettyPrintContext = LintingPrettyPrintContext = {})); //# sourceMappingURL=linter-format.js.map