UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

47 lines 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.USELESS_LOOP = void 0; const extract_cfg_1 = require("../../control-flow/extract-cfg"); const useless_loop_1 = require("../../control-flow/useless-loop"); const vertex_1 = require("../../dataflow/graph/vertex"); const flowr_search_builder_1 = require("../../search/flowr-search-builder"); const dfg_1 = require("../../util/mermaid/dfg"); const linter_format_1 = require("../linter-format"); const linter_tags_1 = require("../linter-tags"); exports.USELESS_LOOP = { createSearch: () => flowr_search_builder_1.Q.all().filter(vertex_1.VertexType.FunctionCall), processSearchResult: (elements, config, data) => { const cfg = (0, extract_cfg_1.extractCfg)(data.normalize, data.config, data.dataflow.graph); const results = elements.getElements().filter(e => { const vertex = data.dataflow.graph.getVertex(e.node.info.id); return vertex && (0, vertex_1.isFunctionCallVertex)(vertex) && vertex.origin !== 'unnamed' && config.loopyFunctions.has(vertex.origin[0]); }).filter(loop => (0, useless_loop_1.onlyLoopsOnce)(loop.node.info.id, data.dataflow.graph, cfg, data.normalize, data.config)).map(res => ({ certainty: linter_format_1.LintingResultCertainty.Certain, name: res.node.lexeme, range: res.node.info.fullRange })); return { results: results, '.meta': { numOfUselessLoops: results.length } }; }, prettyPrint: { [linter_format_1.LintingPrettyPrintContext.Query]: result => `${result.name}-loop at ${(0, dfg_1.formatRange)(result.range)} only loops once`, [linter_format_1.LintingPrettyPrintContext.Full]: result => `${result.name}-loop at ${(0, dfg_1.formatRange)(result.range)} only loops once` }, info: { name: 'Useless Loops', description: 'Detect loops which only iterate once', certainty: linter_format_1.LintingRuleCertainty.BestEffort, tags: [linter_tags_1.LintingRuleTag.Smell, linter_tags_1.LintingRuleTag.Readability], defaultConfig: { loopyFunctions: useless_loop_1.loopyFunctions } } }; //# sourceMappingURL=useless-loop.js.map