UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

70 lines (69 loc) 4.32 kB
import { type LintingResult, LintingRuleCertainty, type LintQuickFix } from '../linter-format'; import type { MergeableRecord } from '../../util/objects'; import { LintingRuleTag } from '../linter-tags'; import type { SyntaxNode } from 'web-tree-sitter'; /** The direction a fix takes to repair an error: add text, remove text, or comment the region out. */ export type FixDirection = 'add' | 'remove' | 'comment'; export interface SyntacticallyValidResult extends LintingResult { readonly message: string; readonly kind: 'missing' | 'error'; } export interface SyntacticallyValidConfig extends MergeableRecord { /** Names of {@link SyntaxErrorFixPatterns|auto-fix patterns} to disable (default none). */ readonly disabledFixes: readonly string[]; /** Preferred {@link FixDirection}; each error gets a single fix, favouring a candidate of this direction. */ readonly preferFix: FixDirection; } export interface SyntacticallyValidMetadata extends MergeableRecord { readonly errors: number; readonly fixable: number; readonly parser: string; } /** One pass over an error region, blind to strings and comments. */ export interface RegionScan { /** The closing delimiters the region leaves open, innermost first. */ readonly closers: readonly string[]; /** Offset of every `%` outside a string or comment; an odd count means an unclosed `%...%` operator. */ readonly percentAt: readonly number[]; } /** A `missing` (parser-inserted, zero-width) or `error` (un-parseable) tree-sitter node. */ export interface SyntaxErrorFinding { readonly kind: 'missing' | 'error'; readonly node: SyntaxNode; /** The source line the node starts on, for patterns judging a pasted line rather than a token. */ readonly line: string; /** The region, scanned on first use. */ readonly scan: RegionScan; } /** An extensible auto-fix pattern; append to {@link SyntaxErrorFixPatterns} to teach the rule new repairs. */ export interface SyntaxErrorFixPattern { readonly name: string; readonly description: string; readonly direction: FixDirection; readonly appliesTo: (finding: SyntaxErrorFinding) => boolean; readonly quickFix: (finding: SyntaxErrorFinding, file: string | undefined) => LintQuickFix; } /** The built-in auto-fix patterns; append a {@link SyntaxErrorFixPattern} to add repairs. */ export declare const SyntaxErrorFixPatterns: SyntaxErrorFixPattern[]; export declare const SYNTACTICALLY_VALID: { readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"from", [], import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, 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: SyntacticallyValidConfig, data: import("../../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>) => Promise<{ results: SyntacticallyValidResult[]; ".meta": SyntacticallyValidMetadata; }>; readonly prettyPrint: { readonly query: (result: SyntacticallyValidResult) => string; readonly full: (result: SyntacticallyValidResult) => string; }; readonly info: { readonly name: "Syntactically Valid"; readonly description: "Checks whether the code is free of syntax errors, using the configured (error-tolerant) parser, and offers extensible quick-fixes to repair them."; readonly tags: readonly [LintingRuleTag.Bug, LintingRuleTag.Robustness, LintingRuleTag.QuickFix]; readonly certainty: LintingRuleCertainty.BestEffort; readonly activeByDefault: false; readonly defaultConfig: { readonly disabledFixes: readonly []; readonly preferFix: "remove"; }; }; };