UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

50 lines 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEAD_CODE = void 0; const linter_format_1 = require("../linter-format"); const range_1 = require("../../util/range"); const flowr_search_builder_1 = require("../../search/flowr-search-builder"); const dfg_1 = require("../../util/mermaid/dfg"); const linter_tags_1 = require("../linter-tags"); const search_enrichers_1 = require("../../search/search-executor/search-enrichers"); const assert_1 = require("../../util/assert"); const cfg_simplification_1 = require("../../control-flow/cfg-simplification"); exports.DEAD_CODE = { createSearch: (config) => flowr_search_builder_1.Q.all().with(search_enrichers_1.Enrichment.CfgInformation, { checkReachable: true, simplificationPasses: config.simplificationPasses ?? [...cfg_simplification_1.DefaultCfgSimplificationOrder, 'analyze-dead-code'] }), processSearchResult: (elements, _config, _data) => { const meta = { consideredNodes: 0 }; return { results: (0, range_1.combineRanges)(...new Set(elements.getElements() .filter(element => { meta.consideredNodes++; const cfgInformation = (0, search_enrichers_1.enrichmentContent)(element, search_enrichers_1.Enrichment.CfgInformation); return cfgInformation.isRoot && !cfgInformation.isReachable; }) .map(element => element.node.info.fullRange ?? element.node.location) .filter(assert_1.isNotUndefined))) .map(range => ({ certainty: linter_format_1.LintingResultCertainty.Certain, range })), '.meta': meta }; }, prettyPrint: { [linter_format_1.LintingPrettyPrintContext.Query]: result => `Code at ${(0, dfg_1.formatRange)(result.range)}`, [linter_format_1.LintingPrettyPrintContext.Full]: result => `Code at ${(0, dfg_1.formatRange)(result.range)} can never be executed`, }, info: { name: 'Dead Code', tags: [linter_tags_1.LintingRuleTag.Smell, linter_tags_1.LintingRuleTag.Usability, linter_tags_1.LintingRuleTag.Reproducibility], // our limited dead code analysis causes complex cases of dead code not to be included in the linting result, but deadness is properly investigated for returned results certainty: linter_format_1.LintingRuleCertainty.BestEffort, description: 'Marks areas of code that are never reached during execution.', defaultConfig: {} } }; //# sourceMappingURL=dead-code.js.map