UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

53 lines 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeLinterQuery = executeLinterQuery; const linter_rules_1 = require("../../../linter/linter-rules"); const log_1 = require("../../../util/log"); const linter_executor_1 = require("../../../linter/linter-executor"); const gas_1 = require("../../../gas"); const linter_output_1 = require("../../../linter/linter-output"); const version_1 = require("../../../util/version"); const assert_1 = require("../../../util/assert"); /** * Executes the given linter queries using the provided analyzer. * A query without an explicit rule list runs only the rules that are active by default. * @see {@link executeLintingRule} * @see {@link LinterRuleInformation#activeByDefault} - opts a rule out of the default rule set */ async function executeLinterQuery({ analyzer }, queries) { // no explicit rules: run the rules that opt in via activeByDefault (default true), minus those the (project-kind // specialized) config disables -- e.g. software-has-license/-tests are off for a lone script or a notebook const disabled = new Set(analyzer.flowrConfig.linter.disabledRules); const defaultRules = Object.keys(linter_rules_1.LintingRules) .filter((name) => linter_rules_1.LintingRules[name].info.activeByDefault !== false && !disabled.has(name)); const flattened = queries.flatMap(q => q.rules ?? defaultRules); const distinct = new Set(flattened); if (distinct.size !== flattened.length) { const pretty = [...distinct].filter(r => flattened.indexOf(r) !== flattened.lastIndexOf(r)).map(r => typeof r === 'string' ? r : r.name).join(', '); log_1.log.warn(`Linter query collection contains duplicate rules ${pretty}, only linting for each rule once`); } // typed loosely to avoid a too-complex mapped-union at the indexed writes below; cast back on return const results = { results: {} }; const start = Date.now(); const gas = analyzer.inspectContext().gas; for (const entry of distinct) { const ruleName = typeof entry === 'string' ? entry : entry.name; if (gas.checkGas(gas_1.GasFeatureKey.Linter) >= 2 /* GasLevel.Critical */) { log_1.log.warn(`Skipping linting rule ${ruleName} due to resource pressure (gas: critical). See ${gas_1.GasWikiRef}`); results.results[ruleName] = { error: new Error(`skipped due to resource pressure (gas: critical), see ${gas_1.GasWikiRef}`) }; continue; } results.results[ruleName] = await (0, linter_executor_1.executeLintingRule)(ruleName, analyzer, entry?.config); } /* rendered here, not when printing, so an api client gets it too */ const format = queries.map(q => q.format).find(assert_1.isNotUndefined); const formatted = format ? (0, linter_output_1.formatLints)(results.results, format, (0, version_1.flowrVersion)().toString()) : undefined; return { ...results, ...(formatted ? { formatted } : {}), '.meta': { timing: Date.now() - start } }; } //# sourceMappingURL=linter-query-executor.js.map