UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

76 lines (60 loc) 3.35 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const log_1 = require("../../test/functionality/_helper/log"); const doc_auto_gen_1 = require("./doc-util/doc-auto-gen"); const doc_files_1 = require("./doc-util/doc-files"); const linter_rules_1 = require("../linter/linter-rules"); const doc_code_1 = require("./doc-util/doc-code"); const shell_1 = require("../r-bridge/shell"); const doc_query_1 = require("./doc-util/doc-query"); const doc_types_1 = require("./doc-util/doc-types"); const path_1 = __importDefault(require("path")); async function getText(shell) { const rVersion = (await shell.usedRVersion())?.format() ?? 'unknown'; return `${(0, doc_auto_gen_1.autoGenHeader)({ filename: module.filename, purpose: 'linter', rVersion })} This page describes the flowR linter, which is a tool that utilizes flowR's dataflow analysis to find common issues in R scripts. The linter can currently be used through the linter [query](${doc_files_1.FlowrWikiBaseRef}/Query%20API). ## Linting Rules The following linting rules are available: ${await rule(shell, 'deprecated-functions', 'DeprecatedFunctionsConfig', 'Deprecated Functions', 'This rule detects the usage of deprecated functions in code based on a predefined list of known deprecated functions.', ` first <- data.frame(x = c(1, 2, 3), y = c(1, 2, 3)) second <- data.frame(x = c(1, 3, 2), y = c(1, 3, 2)) dplyr::all_equal(first, second) `)} ${await rule(shell, 'file-path-validity', 'FilePathValidityConfig', 'File Path Validity', 'This rule finds places in the code where files are being read from. In such places, it checks whether the file path is valid and whether the file exists on disk.', ` my_data <- read.csv("C:/Users/me/Documents/My R Scripts/Reproducible.csv") `)} `.trim(); } async function rule(shell, name, configType, friendlyName, description, example) { const types = (0, doc_types_1.getTypesFromFolderAsMermaid)({ rootFolder: path_1.default.resolve('./src/linter/'), typeName: configType, inlineTypes: doc_types_1.mermaidHide }); return ` ### ${friendlyName} (\`${name}\`) ${description} <details> #### Configuration Linting rules can be configured by passing a configuration object to the linter query as shown in the example below. The \`${name}\` rule accepts the following configuration options: ${Object.getOwnPropertyNames(linter_rules_1.LintingRules[name].defaultConfig).sort().map(key => `- ${(0, doc_types_1.shortLink)(`${configType}:::${key}`, types.info)}\\\n${(0, doc_types_1.getDocumentationForType)(`${configType}::${key}`, types.info)}`).join('\n')} #### Example ${(0, doc_code_1.codeBlock)('r', example)} The linting query can be used to run this rule on the above example: ${await (0, doc_query_1.showQuery)(shell, example, [{ type: 'linter', rules: [{ name, config: {} }] }], { collapseQuery: true })} </details> `.trim(); } if (require.main === module) { (0, log_1.setMinLevelOfAllLogs)(6 /* LogLevel.Fatal */); const shell = new shell_1.RShell(); void getText(shell).then(str => { console.log(str); }).finally(() => { shell.close(); }); } //# sourceMappingURL=print-linter-wiki.js.map