UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

90 lines (89 loc) 4.95 kB
import type { DataflowGraph } from '../../dataflow/graph/graph'; import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id'; import type { MergeableRecord } from '../../util/objects'; import { SourceLocation } from '../../util/range'; import { type LintingResult, type LintQuickFixReplacement, LintingRuleCertainty } from '../linter-format'; import { LintingRuleTag } from '../linter-tags'; export declare enum CasingConvention { CamelCase = "camelCase", PascalCase = "PascalCase", SnakeCase = "snake_case", ConstantCase = "CONSTANT_CASE", CamelSnakeCase = "camel_Snake_Case", PascalSnakeCase = "Pascal_Snake_Case", Unknown = "unknown" } export interface NamingConventionResult extends LintingResult { name: string; detectedCasing: CasingConvention; loc: SourceLocation; } /** * It is planned to have a config like ESLint */ export interface NamingConventionConfig extends MergeableRecord { /** which casing convention to enforce */ caseing: CasingConvention | 'auto'; /** if true non alphabetic characters are ignored */ ignoreNonAlpha: boolean; /** optional prefix to ignore on all identifiers, which is interpreted as a regular expression fragment (meaning special characters have to be escaped) */ ignorePrefix?: string; } export interface NamingConventionMetadata extends MergeableRecord { /** number of symbols matching the casing convetion */ numMatches: number; /** number of symbols breaking the casing convetion */ numBreak: number; } /** * Attempts to detect the possible casing conventions used in the given identifier and returns an array ordered by likelihood of the casing convention being correct. */ export declare function detectPotentialCasings(identifier: string, ignorePrefix?: string): CasingConvention[]; /** * Attempts to detect the possible casing conventions used in the given identifier and returns the first result. * The function {@link detectPotentialCasings} is generally preferred, as it returns all potential casings and not just the first one. */ export declare function detectCasing(identifier: string, ignorePrefix?: string): CasingConvention; /** * Determines the most used casing convention in the given list of symbols. */ export declare function getMostUsedCasing(symbols: { detectedCasing: CasingConvention; }[]): CasingConvention; /** * Attempts to fix the casing of the given identifier to match the provided convention. */ export declare function fixCasing(identifier: string, convention: CasingConvention, ignorePrefix?: string): string | undefined; /** * Creates quick fixes for renaming all references to the given node to match the provided replacement. */ export declare function createNamingConventionQuickFixes(graph: DataflowGraph, nodeId: NodeId, replacement: string, conv: CasingConvention): LintQuickFixReplacement[] | undefined; export declare const NAMING_CONVENTION: { readonly createSearch: (_config: NamingConventionConfig) => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"], import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, Promise<import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, [] | import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>>; readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: NamingConventionConfig, data: { normalize: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").NormalizedAst; dataflow: import("../../dataflow/info").DataflowInformation; cfg: import("../../control-flow/control-flow-graph").ControlFlowInformation; analyzer: import("../../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider; }) => { results: NamingConventionResult[]; '.meta': { numMatches: number; numBreak: number; }; }; readonly prettyPrint: { readonly query: (result: NamingConventionResult) => string; readonly full: (result: NamingConventionResult) => string; }; readonly info: { readonly name: "Naming Convention"; readonly certainty: LintingRuleCertainty.OverApproximative; readonly description: "Checks whether the symbols conform to a certain naming convention"; readonly tags: readonly [LintingRuleTag.Style, LintingRuleTag.QuickFix]; readonly defaultConfig: { readonly caseing: "auto"; readonly ignoreNonAlpha: true; }; }; };