@eagleoutice/flowr 2.13.0 → 2.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -23
- package/cli/common/options.d.ts +10 -0
- package/cli/common/options.js +2 -0
- package/cli/common/scripts-info.d.ts +10 -0
- package/cli/flowr.js +21 -5
- package/cli/repl/commands/repl-commands.d.ts +8 -0
- package/cli/repl/commands/repl-commands.js +27 -12
- package/cli/repl/commands/repl-query.js +9 -1
- package/cli/repl/commands/repl-signature.js +8 -1
- package/cli/repl/core.js +13 -10
- package/cli/repl/print-version.js +1 -1
- package/cli/repl/server/connection.d.ts +1 -1
- package/cli/repl/server/net.js +15 -0
- package/cli/slicer-app.d.ts +2 -0
- package/cli/slicer-app.js +2 -1
- package/config.d.ts +31 -0
- package/config.js +55 -2
- package/data/sigdb/sigdb.remote.json +1 -1
- package/dataflow/environments/identifier.d.ts +9 -8
- package/dataflow/environments/identifier.js +21 -13
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +29 -0
- package/dataflow/eval/resolve/resolve-working-directory.js +168 -0
- package/dataflow/extractor.js +2 -1
- package/dataflow/graph/df-helper.d.ts +3 -2
- package/dataflow/graph/df-helper.js +11 -15
- package/dataflow/graph/diff-dataflow-graph.js +1 -1
- package/dataflow/graph/graph-helper.js +2 -6
- package/dataflow/graph/graph.d.ts +24 -0
- package/dataflow/graph/graph.js +25 -1
- package/documentation/wiki-interface.js +1 -0
- package/documentation/wiki-linter.js +1 -0
- package/documentation/wiki-mk/doc-context.d.ts +10 -0
- package/documentation/wiki-mk/doc-context.js +3 -0
- package/documentation/wiki-query.js +4 -3
- package/documentation/wiki-signature-database.js +16 -6
- package/linter/linter-rules.d.ts +24 -2
- package/linter/linter-rules.js +3 -1
- package/linter/rules/absolute-path.d.ts +4 -4
- package/linter/rules/absolute-path.js +7 -5
- package/linter/rules/file-path-validity.d.ts +1 -1
- package/linter/rules/file-path-validity.js +48 -8
- package/linter/rules/function-finder-util.d.ts +2 -1
- package/linter/rules/syntactically-valid.d.ts +58 -0
- package/linter/rules/syntactically-valid.js +203 -0
- package/linter/rules/undefined-symbol.js +3 -2
- package/package.json +5 -4
- package/project/context/classify-project-kind.d.ts +40 -0
- package/project/context/classify-project-kind.js +76 -0
- package/project/context/flowr-analyzer-context.d.ts +2 -0
- package/project/context/flowr-analyzer-context.js +6 -0
- package/project/context/flowr-analyzer-dependencies-context.d.ts +23 -4
- package/project/context/flowr-analyzer-dependencies-context.js +23 -1
- package/project/context/flowr-analyzer-files-context.d.ts +18 -8
- package/project/context/flowr-analyzer-files-context.js +66 -68
- package/project/context/flowr-file.d.ts +5 -0
- package/project/context/flowr-file.js +5 -0
- package/project/dependency-version-space.d.ts +3 -1
- package/project/dependency-version-space.js +26 -20
- package/project/flowr-analyzer.d.ts +3 -0
- package/project/flowr-analyzer.js +4 -0
- package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.d.ts +12 -4
- package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +25 -10
- package/project/plugins/plugin-registry.d.ts +2 -1
- package/project/plugins/plugin-registry.js +4 -1
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.d.ts +57 -2
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +150 -28
- package/project/sigdb/decompress.d.ts +1 -1
- package/project/sigdb/decompress.js +4 -1
- package/project/sigdb/manifest.js +60 -26
- package/project/sigdb/sigdb-download.d.ts +6 -7
- package/project/sigdb/sigdb-download.js +30 -9
- package/queries/catalog/config-query/config-query-executor.js +3 -0
- package/queries/catalog/config-query/config-query-format.d.ts +5 -3
- package/queries/catalog/config-query/config-query-format.js +31 -21
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +0 -10
- package/queries/catalog/dependencies-query/dependencies-query-format.js +0 -106
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +21 -5
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +4 -2
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +17 -3
- package/queries/catalog/linter-query/linter-query-format.js +9 -2
- package/queries/catalog/signature-query/signature-query-executor.js +3 -0
- package/queries/catalog/signature-query/signature-query-render.js +4 -4
- package/queries/query.d.ts +4 -4
- package/queries/query.js +9 -2
- package/r-bridge/data/data.d.ts +5 -0
- package/r-bridge/data/data.js +6 -0
- package/r-bridge/retriever.js +6 -1
- package/r-bridge/shell.js +5 -0
- package/search/flowr-search-filters.d.ts +2 -1
- package/util/files.d.ts +6 -4
- package/util/files.js +30 -8
- package/util/mermaid/dfg.js +1 -1
- package/util/schema.d.ts +2 -0
- package/util/schema.js +13 -0
- package/util/text/ansi.d.ts +7 -3
- package/util/text/ansi.js +8 -5
- package/util/version.js +4 -4
|
@@ -948,7 +948,7 @@ To find out what a script _uses_, reach for the ${(0, doc_query_1.linkToQueryOfN
|
|
|
948
948
|
buildExplanation: async (shell, ctx) => {
|
|
949
949
|
const exampleCode = 'library(dplyr)\nmutate(mtcars, across(everything(), round))';
|
|
950
950
|
return `
|
|
951
|
-
A script rarely says which version of a package it needs
|
|
951
|
+
A script rarely says which version of a package it needs, but it shows you. If it passes an argument that a function only
|
|
952
952
|
gained in some release, it cannot run on anything older. This query turns that observation into a concrete version range per dependency.
|
|
953
953
|
|
|
954
954
|
It combines two sources of evidence:
|
|
@@ -963,8 +963,8 @@ Two things can raise a lower bound: calling a function that did not exist yet, o
|
|
|
963
963
|
function only gained later. Consider a script calling \`dplyr::across\`:
|
|
964
964
|
${(0, doc_code_1.codeBlock)('r', exampleCode)}
|
|
965
965
|
|
|
966
|
-
\`across\` was only introduced in dplyr 1.0.0, so the script cannot run on anything older
|
|
967
|
-
|
|
966
|
+
\`across\` was only introduced in dplyr 1.0.0, so the script cannot run on anything older. The result names the function
|
|
967
|
+
that produced the bound:
|
|
968
968
|
|
|
969
969
|
${await (0, doc_query_1.showQuery)(shell, exampleCode, [{ type: 'guess-dep-versions' }], { showCode: false, collapseResult: true, ctx })}
|
|
970
970
|
|
|
@@ -973,6 +973,7 @@ The guess can be narrowed further:
|
|
|
973
973
|
* \`packages\` restricts it to the dependencies you care about,
|
|
974
974
|
* \`date\` caps every guess to releases available at that point in time (\`YYYY.MM.DD\`, also \`YYYY\` or \`YYYY.MM\`),
|
|
975
975
|
* \`clean\` ignores the declared constraints entirely and guesses purely from usage,
|
|
976
|
+
* \`disabled\` excludes individual evidence sources by name (repl: \`--disabled\` followed by their one-letter codes shown in the legend below, e.g. \`--disabled ds\` drops \`declared\` and \`signature\`),
|
|
976
977
|
* \`maxCandidates\` caps how many candidate versions are listed per dependency,
|
|
977
978
|
* \`maxIterations\` bounds the two fixpoint loops (packages constrain each other, so the guess is iterated until it settles), and
|
|
978
979
|
* \`explode\` additionally enumerates concrete version _combinations_ (\`order\`, \`prefer\`, and \`limit\` control which and how many).
|
|
@@ -9,12 +9,15 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const doc_maker_1 = require("./wiki-mk/doc-maker");
|
|
10
10
|
const doc_files_1 = require("./doc-util/doc-files");
|
|
11
11
|
const reader_1 = require("../project/sigdb/reader");
|
|
12
|
+
// FnProp is a const enum referenced only via `typeof` (for linkE's member typing); a type-only import would break `typeof`
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
12
14
|
const schema_1 = require("../project/sigdb/schema");
|
|
13
15
|
const manifest_1 = require("../project/sigdb/manifest");
|
|
14
16
|
const codec_1 = require("../project/sigdb/codec");
|
|
15
17
|
const config_1 = require("../config");
|
|
16
18
|
const flowr_analyzer_package_versions_sigdb_plugin_1 = require("../project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin");
|
|
17
19
|
const flowr_analyzer_builder_1 = require("../project/flowr-analyzer-builder");
|
|
20
|
+
const flowr_analyzer_dependencies_context_1 = require("../project/context/flowr-analyzer-dependencies-context");
|
|
18
21
|
function cranDatabaseAvailable() {
|
|
19
22
|
return (0, manifest_1.defaultSigDbPath)('current') !== undefined || (0, manifest_1.defaultSigDbPath)('full') !== undefined;
|
|
20
23
|
}
|
|
@@ -231,17 +234,22 @@ Every function is a ${ctx.link('DecodedFunction')}:
|
|
|
231
234
|
|
|
232
235
|
Per version the source also answers declared dependencies (${ctx.link('ResolvedDependency')}), release dates, the plain export view (${ctx.link('LibraryExports')}), and the versions it carries (${ctx.link('AvailableVersion')}).
|
|
233
236
|
|
|
234
|
-
Beyond the flags above, ${ctx.link('DecodedFunction::props')} also carry ${ctx.
|
|
237
|
+
Beyond the flags above, ${ctx.link('DecodedFunction::props')} also carry ${ctx.linkE('FnProp', 'NoDoc')} (a documented package has no help page for this name), ${ctx.linkE('FnProp', 'S3Method')} (a registered S3 method, from the package NAMESPACE or base R's method table), and ${ctx.linkE('FnProp', 'S3Owner')} (an exported constructor for an S3 class this package OWNS: it also registers at least one S3 method for that class). The owned classes of a version are ${ctx.link('LibraryExports::s3Classes')}, and ${ctx.linkM(reader_1.SigDatabase, 'classOwner')} answers, for a class name, which package owns it (backed by a reverse index built once). This lets ${ctx.linkPage('wiki/Query API', 'version guessing')} mark a package used when the analyzed project's own NAMESPACE registers an S3 method for a class it owns, even with no direct call -- e.g. tseries's \`S3method("as.irts","zoo")\` marks \`zoo\` used.
|
|
235
238
|
|
|
236
239
|
These are derived on demand by the ${ctx.linkPage('wiki/Query API', 'signature query')}, not stored:
|
|
237
|
-
- the rdrr.io documentation link ${ctx.link('SignatureFunctionView::docUrl')} (base R \`/r/<pkg>/<topic>\`, CRAN \`/cran/<pkg>/man/<topic>\`), omitted for a ${ctx.
|
|
238
|
-
- the S3 method to generic backlink ${ctx.link('SignatureFunctionView::s3method')}, for a ${ctx.
|
|
240
|
+
- the rdrr.io documentation link ${ctx.link('SignatureFunctionView::docUrl')} (base R \`/r/<pkg>/<topic>\`, CRAN \`/cran/<pkg>/man/<topic>\`), omitted for a ${ctx.linkE('FnProp', 'NoDoc')} function
|
|
241
|
+
- the S3 method to generic backlink ${ctx.link('SignatureFunctionView::s3method')}, for a ${ctx.linkE('FnProp', 'S3Method')} function, resolving its generic
|
|
239
242
|
- the transitive call graph ${ctx.linkM(reader_1.SigDatabase, 'transitiveCallees')}, expanding the stored local callees inside one version
|
|
240
243
|
|
|
241
244
|
Read it back like this:
|
|
242
245
|
|
|
243
246
|
${ctx.code(accessTheDatabase, { dropLinesStart: 1 })}
|
|
244
247
|
|
|
248
|
+
To check what a project can resolve against without touching the raw sources, a ${ctx.linkPage('wiki/Analyzer', 'context')} exposes
|
|
249
|
+
${ctx.linkM(flowr_analyzer_dependencies_context_1.FlowrAnalyzerDependenciesContext, 'hasSignatureDatabase')} (a cheap presence check) and
|
|
250
|
+
${ctx.linkM(flowr_analyzer_dependencies_context_1.FlowrAnalyzerDependenciesContext, 'availableSignatureDatabases')} (the identifying names of the loaded databases), alongside the
|
|
251
|
+
richer ${ctx.linkM(flowr_analyzer_dependencies_context_1.FlowrAnalyzerDependenciesContext, 'loadedSignatureDatabases')} metadata.
|
|
252
|
+
|
|
245
253
|
## Configuration
|
|
246
254
|
|
|
247
255
|
The exports come from ${pluginLink('versions:sigdb')}, which reads bundled databases. It is enabled by
|
|
@@ -263,16 +271,18 @@ So \`library(stats)\` attaches that release's exports, and a bare \`sd()\` quali
|
|
|
263
271
|
without attaching the base namespaces to the graph. Set ${ctx.linkConfig('solver.sigdb.linkBaseR')} to also link them as
|
|
264
272
|
dataflow edges.
|
|
265
273
|
|
|
266
|
-
|
|
274
|
+
Signature shards are not committed to the repository because of their size (the \`current.*\` and \`history.*\` scopes
|
|
275
|
+
span tens of megabytes): the \`base.*\` floor (self-contained base-R signatures, a few hundred KB), the
|
|
267
276
|
\`current.*\` scope (every package's latest version) and \`history.*\` (every older version) all live as assets on the
|
|
268
277
|
free ${ctx.linkConfig('solver.sigdb.downloadRepo')} GitHub release. The only committed file is a tiny **link file**,
|
|
269
278
|
\`src/data/sigdb/sigdb.remote.json\`, which records the release tag and each shard's sha256 and size, so
|
|
270
|
-
|
|
279
|
+
${ctx.replCmd('signature')} download builds the direct release-CDN URL, verifies every shard by content hash,
|
|
271
280
|
and skips any already cached. Because the link file is versioned, a \`git pull\` that updates it re-syncs only the
|
|
272
281
|
shards whose hash changed — and with ${ctx.linkConfig('solver.sigdb.autoSync')} that check runs on startup and re-downloads in the
|
|
273
282
|
background; \`npm run build\` bakes the shards in as well. The richest downloaded scope is used (order \`full\` >
|
|
274
283
|
\`current\` > \`base\`), so once fetched \`library(stats)\` resolves. Any path in ${ctx.linkConfig('solver.sigdb.additionalPaths')} (or
|
|
275
284
|
\`$FLOWR_SIGDB_DIR\`) is searched alongside the default, so a downloaded bundle stays mounted on every start.
|
|
285
|
+
|
|
276
286
|
${databases ? `
|
|
277
287
|
## Bundled Databases
|
|
278
288
|
|
|
@@ -291,7 +301,7 @@ shared dictionary that its shards depend on, so it is decompressed the first tim
|
|
|
291
301
|
The flowR Docker images ship this dictionary already decompressed, so a container reads it in place and skips
|
|
292
302
|
that step (the load column above is the cost a plain npm install pays).
|
|
293
303
|
|
|
294
|
-
Every shard, dictionary, and manifest is published in both brotli (\`.br\`) and zstd (\`.zst\`, faster to decompress) compression, and flowR uses whichever the runtime supports: \`.zst\` when the Node version exposes [zstd](https://nodejs.org/api/zlib.html#zstd) (Node ≥ 22.15), otherwise \`.br\`.
|
|
304
|
+
Every shard, dictionary, and manifest is published in both brotli (\`.br\`) and zstd (\`.zst\`, faster to decompress) compression, and flowR uses whichever the runtime supports: \`.zst\` when the Node version exposes [zstd](https://nodejs.org/api/zlib.html#zstd) (Node ≥ 22.15), otherwise \`.br\`. ${ctx.replCmd('signature')} download fetches only that one variant per file, and ${ctx.replCmd('version')} reports the format each loaded database resolved to.
|
|
295
305
|
` : ''}
|
|
296
306
|
## Format
|
|
297
307
|
|
package/linter/linter-rules.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare const LintingRules: {
|
|
|
34
34
|
readonly name: "File Path Validity";
|
|
35
35
|
readonly description: "Checks whether file paths used in read and write operations are valid and point to existing files.";
|
|
36
36
|
readonly certainty: import("./linter-format").LintingRuleCertainty.BestEffort;
|
|
37
|
-
readonly tags: readonly [import("./linter-tags").LintingRuleTag.Robustness, import("./linter-tags").LintingRuleTag.Reproducibility, import("./linter-tags").LintingRuleTag.Bug];
|
|
37
|
+
readonly tags: readonly [import("./linter-tags").LintingRuleTag.Robustness, import("./linter-tags").LintingRuleTag.Reproducibility, import("./linter-tags").LintingRuleTag.Bug, import("./linter-tags").LintingRuleTag.QuickFix];
|
|
38
38
|
readonly defaultConfig: {
|
|
39
39
|
readonly additionalReadFunctions: readonly [];
|
|
40
40
|
readonly additionalWriteFunctions: readonly [];
|
|
@@ -101,7 +101,7 @@ export declare const LintingRules: {
|
|
|
101
101
|
};
|
|
102
102
|
readonly additionalPathFunctions: readonly [];
|
|
103
103
|
readonly absolutePathRegex: undefined;
|
|
104
|
-
readonly useAsWd: "@
|
|
104
|
+
readonly useAsWd: "@project";
|
|
105
105
|
readonly ignoreUrls: true;
|
|
106
106
|
};
|
|
107
107
|
};
|
|
@@ -379,6 +379,28 @@ export declare const LintingRules: {
|
|
|
379
379
|
};
|
|
380
380
|
};
|
|
381
381
|
};
|
|
382
|
+
readonly 'syntactically-valid': {
|
|
383
|
+
readonly createSearch: () => import("../search/flowr-search-builder").FlowrSearchBuilder<"all", [], 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>[]>>;
|
|
384
|
+
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: import("./rules/syntactically-valid").SyntacticallyValidConfig, data: import("../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>) => Promise<{
|
|
385
|
+
results: import("./rules/syntactically-valid").SyntacticallyValidResult[];
|
|
386
|
+
".meta": import("./rules/syntactically-valid").SyntacticallyValidMetadata;
|
|
387
|
+
}>;
|
|
388
|
+
readonly prettyPrint: {
|
|
389
|
+
readonly query: (result: import("./rules/syntactically-valid").SyntacticallyValidResult) => string;
|
|
390
|
+
readonly full: (result: import("./rules/syntactically-valid").SyntacticallyValidResult) => string;
|
|
391
|
+
};
|
|
392
|
+
readonly info: {
|
|
393
|
+
readonly name: "Syntactically Valid";
|
|
394
|
+
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.";
|
|
395
|
+
readonly tags: readonly [import("./linter-tags").LintingRuleTag.Bug, import("./linter-tags").LintingRuleTag.Robustness, import("./linter-tags").LintingRuleTag.QuickFix];
|
|
396
|
+
readonly certainty: import("./linter-format").LintingRuleCertainty.BestEffort;
|
|
397
|
+
readonly activeByDefault: false;
|
|
398
|
+
readonly defaultConfig: {
|
|
399
|
+
readonly disabledFixes: readonly [];
|
|
400
|
+
readonly preferFix: "remove";
|
|
401
|
+
};
|
|
402
|
+
};
|
|
403
|
+
};
|
|
382
404
|
};
|
|
383
405
|
export type LintingRuleNames = keyof typeof LintingRules;
|
|
384
406
|
export type LintingRuleMetadata<Name extends LintingRuleNames> = typeof LintingRules[Name] extends LintingRule<infer _Result, infer Metadata, infer _Config, infer _Info, infer _Elements> ? Metadata : never;
|
package/linter/linter-rules.js
CHANGED
|
@@ -18,6 +18,7 @@ const software_has_license_1 = require("./rules/software-has-license");
|
|
|
18
18
|
const software_has_tests_1 = require("./rules/software-has-tests");
|
|
19
19
|
const no_leaked_credentials_1 = require("./rules/no-leaked-credentials");
|
|
20
20
|
const undefined_symbol_1 = require("./rules/undefined-symbol");
|
|
21
|
+
const syntactically_valid_1 = require("./rules/syntactically-valid");
|
|
21
22
|
/**
|
|
22
23
|
* The registry of currently supported linting rules.
|
|
23
24
|
* A linting rule can be executed on a dataflow pipeline result using {@link executeLintingRule}.
|
|
@@ -39,6 +40,7 @@ exports.LintingRules = {
|
|
|
39
40
|
'software-has-license': software_has_license_1.SOFTWARE_HAS_LICENSE,
|
|
40
41
|
'software-has-tests': software_has_tests_1.SOFTWARE_HAS_TESTS,
|
|
41
42
|
'no-leaked-credentials': no_leaked_credentials_1.NO_LEAKED_CREDENTIALS,
|
|
42
|
-
'undefined-symbol': undefined_symbol_1.UNDEFINED_SYMBOL
|
|
43
|
+
'undefined-symbol': undefined_symbol_1.UNDEFINED_SYMBOL,
|
|
44
|
+
'syntactically-valid': syntactically_valid_1.SYNTACTICALLY_VALID
|
|
43
45
|
};
|
|
44
46
|
//# sourceMappingURL=linter-rules.js.map
|
|
@@ -5,7 +5,7 @@ import type { FunctionInfo } from '../../queries/catalog/dependencies-query/func
|
|
|
5
5
|
export interface AbsoluteFilePathResult extends LintingResult {
|
|
6
6
|
filePath: string;
|
|
7
7
|
}
|
|
8
|
-
type SupportedWd = '@script' | '@home' | string;
|
|
8
|
+
type SupportedWd = '@script' | '@home' | '@project' | string;
|
|
9
9
|
export interface AbsoluteFilePathConfig extends MergeableRecord {
|
|
10
10
|
/** Include paths that are built by functions, e.g., `file.path()` */
|
|
11
11
|
include: {
|
|
@@ -22,8 +22,8 @@ export interface AbsoluteFilePathConfig extends MergeableRecord {
|
|
|
22
22
|
*/
|
|
23
23
|
additionalPathFunctions: FunctionInfo[];
|
|
24
24
|
/**
|
|
25
|
-
* Which path
|
|
26
|
-
*
|
|
25
|
+
* Which path the relative-path quick fix is built against: `@project` (project root, falling back to the
|
|
26
|
+
* script when there is no root), `@script`, `@home`, or a literal directory.
|
|
27
27
|
*/
|
|
28
28
|
useAsWd: SupportedWd;
|
|
29
29
|
/** Automatically ignore URLs (http/https/ftp) so they are not reported as absolute paths. */
|
|
@@ -55,7 +55,7 @@ export declare const ABSOLUTE_PATH: {
|
|
|
55
55
|
};
|
|
56
56
|
readonly additionalPathFunctions: readonly [];
|
|
57
57
|
readonly absolutePathRegex: undefined;
|
|
58
|
-
readonly useAsWd: "@
|
|
58
|
+
readonly useAsWd: "@project";
|
|
59
59
|
readonly ignoreUrls: true;
|
|
60
60
|
};
|
|
61
61
|
};
|
|
@@ -22,15 +22,16 @@ const resolve_argument_1 = require("../../dataflow/eval/resolve/resolve-argument
|
|
|
22
22
|
const path_1 = __importDefault(require("path"));
|
|
23
23
|
const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
24
24
|
const other_path_functions_1 = require("../../queries/catalog/dependencies-query/function-info/other-path-functions");
|
|
25
|
-
function inferWd(file, wd) {
|
|
25
|
+
function inferWd(file, wd, ctx) {
|
|
26
26
|
if (wd === '@script') {
|
|
27
|
-
// we can use the script path as the working directory
|
|
28
27
|
return file;
|
|
29
28
|
}
|
|
30
29
|
else if (wd === '@home') {
|
|
31
|
-
// we can use the home directory as the working directory
|
|
32
30
|
return process.env.HOME || process.env.USERPROFILE || '';
|
|
33
31
|
}
|
|
32
|
+
else if (wd === '@project') {
|
|
33
|
+
return ctx.files.root() ?? file;
|
|
34
|
+
}
|
|
34
35
|
else {
|
|
35
36
|
return wd;
|
|
36
37
|
}
|
|
@@ -113,11 +114,12 @@ exports.ABSOLUTE_PATH = {
|
|
|
113
114
|
const regex = config.absolutePathRegex ? new RegExp(config.absolutePathRegex) : undefined;
|
|
114
115
|
const normalize = await data.normalize();
|
|
115
116
|
const dataflow = await data.dataflow();
|
|
117
|
+
const ctx = data.inspectContext();
|
|
116
118
|
return {
|
|
117
119
|
results: elements.getElements().flatMap(element => {
|
|
118
120
|
metadata.totalConsidered++;
|
|
119
121
|
const node = element.node;
|
|
120
|
-
const wd = inferWd(node.info.file, config.useAsWd);
|
|
122
|
+
const wd = inferWd(node.info.file, config.useAsWd, ctx);
|
|
121
123
|
if (r_string_1.RString.is(node)) {
|
|
122
124
|
const resolved = resolvePathForAbsoluteCheck(node.content.str, config.ignoreUrls);
|
|
123
125
|
if (resolved !== undefined && resolved.length >= 3 && (0, strings_1.isAbsolutePath)(resolved, regex)) {
|
|
@@ -200,7 +202,7 @@ exports.ABSOLUTE_PATH = {
|
|
|
200
202
|
},
|
|
201
203
|
additionalPathFunctions: [],
|
|
202
204
|
absolutePathRegex: undefined,
|
|
203
|
-
useAsWd: '@
|
|
205
|
+
useAsWd: '@project',
|
|
204
206
|
ignoreUrls: true
|
|
205
207
|
}
|
|
206
208
|
}
|
|
@@ -43,7 +43,7 @@ export declare const FILE_PATH_VALIDITY: {
|
|
|
43
43
|
readonly name: "File Path Validity";
|
|
44
44
|
readonly description: "Checks whether file paths used in read and write operations are valid and point to existing files.";
|
|
45
45
|
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
46
|
-
readonly tags: readonly [LintingRuleTag.Robustness, LintingRuleTag.Reproducibility, LintingRuleTag.Bug];
|
|
46
|
+
readonly tags: readonly [LintingRuleTag.Robustness, LintingRuleTag.Reproducibility, LintingRuleTag.Bug, LintingRuleTag.QuickFix];
|
|
47
47
|
readonly defaultConfig: {
|
|
48
48
|
readonly additionalReadFunctions: readonly [];
|
|
49
49
|
readonly additionalWriteFunctions: readonly [];
|
|
@@ -11,6 +11,11 @@ const logic_1 = require("../../util/logic");
|
|
|
11
11
|
const happens_before_1 = require("../../control-flow/happens-before");
|
|
12
12
|
const linter_tags_1 = require("../linter-tags");
|
|
13
13
|
const search_enrichers_1 = require("../../search/search-executor/search-enrichers");
|
|
14
|
+
const resolve_working_directory_1 = require("../../dataflow/eval/resolve/resolve-working-directory");
|
|
15
|
+
const config_1 = require("../../config");
|
|
16
|
+
const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
|
|
17
|
+
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
18
|
+
const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
14
19
|
async function urlExists(url) {
|
|
15
20
|
try {
|
|
16
21
|
const response = await fetch(url, { method: 'HEAD' });
|
|
@@ -36,6 +41,10 @@ exports.FILE_PATH_VALIDITY = {
|
|
|
36
41
|
totalValid: 0
|
|
37
42
|
};
|
|
38
43
|
const results = elements.enrichmentContent(search_enrichers_1.Enrichment.QueryData).queries['dependencies'];
|
|
44
|
+
const ctx = data.inspectContext();
|
|
45
|
+
const dfg = (await data.dataflow()).graph;
|
|
46
|
+
const resolveSource = data.flowrConfig.solver.resolveSource;
|
|
47
|
+
const wdRootsFor = resolve_working_directory_1.WorkingDirectory.rootsResolver(dfg, cfg, ctx);
|
|
39
48
|
const findings = await Promise.all(elements.getElements().map(async (element) => {
|
|
40
49
|
const matchingRead = results.read.find(r => r.nodeId === element.node.info.id);
|
|
41
50
|
if (!matchingRead) {
|
|
@@ -103,20 +112,25 @@ exports.FILE_PATH_VALIDITY = {
|
|
|
103
112
|
metadata.totalWritesBeforeAlways++;
|
|
104
113
|
return [];
|
|
105
114
|
}
|
|
106
|
-
// check if the file exists
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
115
|
+
// check if the file exists, resolving relative paths against the effective working directory
|
|
116
|
+
const value = matchingRead.value;
|
|
117
|
+
const referenceChain = element.node.info.file ? [element.node.info.file] : [];
|
|
118
|
+
const wdRoots = wdRootsFor(element.node.info.id, element.node.info.file);
|
|
119
|
+
const withWd = { ...resolveSource, searchPath: [...(resolveSource?.searchPath ?? []), ...wdRoots] };
|
|
120
|
+
const paths = (0, built_in_source_1.findSource)(withWd, value, { referenceChain, ctx });
|
|
111
121
|
if (paths && paths.length) {
|
|
112
122
|
metadata.totalValid++;
|
|
113
123
|
return [];
|
|
114
124
|
}
|
|
125
|
+
// a lax retry (drop leading dirs, ignore case) may surface a near match to offer as a quick fix
|
|
126
|
+
const near = (0, built_in_source_1.findSource)({ ...withWd, ignoreCapitalization: true, dropPaths: config_1.DropPathsOption.All }, value, { referenceChain, ctx });
|
|
127
|
+
const quickFix = dfg.idMap && near && near.length ? buildDidYouMeanFix(dfg.idMap, matchingRead.nodeId, value, near[0]) : undefined;
|
|
115
128
|
return [{
|
|
116
129
|
involvedId: matchingRead.nodeId,
|
|
117
130
|
loc,
|
|
118
|
-
filePath:
|
|
119
|
-
certainty: writesBefore && writesBefore.length && writesBefore.every(w => w === logic_1.Ternary.Maybe) ? linter_format_1.LintingResultCertainty.Uncertain : linter_format_1.LintingResultCertainty.Certain
|
|
131
|
+
filePath: value,
|
|
132
|
+
certainty: writesBefore && writesBefore.length && writesBefore.every(w => w === logic_1.Ternary.Maybe) ? linter_format_1.LintingResultCertainty.Uncertain : linter_format_1.LintingResultCertainty.Certain,
|
|
133
|
+
...(quickFix ? { quickFix } : {})
|
|
120
134
|
}];
|
|
121
135
|
}));
|
|
122
136
|
return {
|
|
@@ -129,7 +143,7 @@ exports.FILE_PATH_VALIDITY = {
|
|
|
129
143
|
description: 'Checks whether file paths used in read and write operations are valid and point to existing files.',
|
|
130
144
|
// checks all found paths for whether they're valid to ensure correctness, but doesn't handle non-constant paths so not all will be returned
|
|
131
145
|
certainty: linter_format_1.LintingRuleCertainty.BestEffort,
|
|
132
|
-
tags: [linter_tags_1.LintingRuleTag.Robustness, linter_tags_1.LintingRuleTag.Reproducibility, linter_tags_1.LintingRuleTag.Bug],
|
|
146
|
+
tags: [linter_tags_1.LintingRuleTag.Robustness, linter_tags_1.LintingRuleTag.Reproducibility, linter_tags_1.LintingRuleTag.Bug, linter_tags_1.LintingRuleTag.QuickFix],
|
|
133
147
|
defaultConfig: {
|
|
134
148
|
additionalReadFunctions: [],
|
|
135
149
|
additionalWriteFunctions: [],
|
|
@@ -149,4 +163,30 @@ function samePath(a, b, ignoreCapitalization) {
|
|
|
149
163
|
}
|
|
150
164
|
return a === b;
|
|
151
165
|
}
|
|
166
|
+
/** the string-literal path argument of a call whose resolved value is `value`, for anchoring a quick fix */
|
|
167
|
+
function pathArgStringNode(idMap, callId, value) {
|
|
168
|
+
const call = idMap.get(callId);
|
|
169
|
+
if (call?.type !== type_1.RType.FunctionCall) {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
for (const arg of call.arguments) {
|
|
173
|
+
if (arg !== r_function_call_1.EmptyArgument && arg.value && r_string_1.RString.is(arg.value) && arg.value.content.str === value) {
|
|
174
|
+
return arg.value;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
/** rewrite the read path to `found`, an existing file surfaced by the lax retry */
|
|
180
|
+
function buildDidYouMeanFix(idMap, callId, value, found) {
|
|
181
|
+
const str = pathArgStringNode(idMap, callId, value);
|
|
182
|
+
if (!str) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
return [{
|
|
186
|
+
type: 'replace',
|
|
187
|
+
loc: range_1.SourceLocation.fromNode(str) ?? range_1.SourceLocation.invalid(),
|
|
188
|
+
description: `Replace with existing path \`${found}\``,
|
|
189
|
+
replacement: str.content.quotes + found + str.content.quotes
|
|
190
|
+
}];
|
|
191
|
+
}
|
|
152
192
|
//# sourceMappingURL=file-path-validity.js.map
|
|
@@ -3,6 +3,7 @@ import type { FlowrSearchElement, FlowrSearchElements } from '../../search/flowr
|
|
|
3
3
|
import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
4
4
|
import type { MergeableRecord } from '../../util/objects';
|
|
5
5
|
import type { FunctionInfo } from '../../queries/catalog/dependencies-query/function-info/function-info';
|
|
6
|
+
import type { Identifier } from '../../dataflow/environments/identifier';
|
|
6
7
|
import { Ternary } from '../../util/logic';
|
|
7
8
|
import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
|
|
8
9
|
import type { AsyncOrSync } from 'ts-essentials';
|
|
@@ -17,7 +18,7 @@ export interface FunctionsToDetectConfig extends MergeableRecord {
|
|
|
17
18
|
/**
|
|
18
19
|
* The list of function names that should be marked in the given context.
|
|
19
20
|
*/
|
|
20
|
-
fns: readonly
|
|
21
|
+
fns: readonly Identifier[];
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* This helper object collects utility functions used to create linting rules that search for specific functions.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type LintingResult, LintingRuleCertainty, type LintQuickFix } from '../linter-format';
|
|
2
|
+
import type { MergeableRecord } from '../../util/objects';
|
|
3
|
+
import { LintingRuleTag } from '../linter-tags';
|
|
4
|
+
import type { SyntaxNode } from 'web-tree-sitter';
|
|
5
|
+
/** The direction a fix takes to repair an error: add text, remove text, or comment the region out. */
|
|
6
|
+
export type FixDirection = 'add' | 'remove' | 'comment';
|
|
7
|
+
export interface SyntacticallyValidResult extends LintingResult {
|
|
8
|
+
readonly message: string;
|
|
9
|
+
readonly kind: 'missing' | 'error';
|
|
10
|
+
}
|
|
11
|
+
export interface SyntacticallyValidConfig extends MergeableRecord {
|
|
12
|
+
/** Names of {@link SyntaxErrorFixPatterns|auto-fix patterns} to disable (default none). */
|
|
13
|
+
readonly disabledFixes: readonly string[];
|
|
14
|
+
/** Preferred {@link FixDirection}; each error gets a single fix, favouring a candidate of this direction. */
|
|
15
|
+
readonly preferFix: FixDirection;
|
|
16
|
+
}
|
|
17
|
+
export interface SyntacticallyValidMetadata extends MergeableRecord {
|
|
18
|
+
readonly errors: number;
|
|
19
|
+
readonly fixable: number;
|
|
20
|
+
readonly parser: string;
|
|
21
|
+
}
|
|
22
|
+
/** A `missing` (parser-inserted, zero-width) or `error` (un-parseable) tree-sitter node. */
|
|
23
|
+
export interface SyntaxErrorFinding {
|
|
24
|
+
readonly kind: 'missing' | 'error';
|
|
25
|
+
readonly node: SyntaxNode;
|
|
26
|
+
}
|
|
27
|
+
/** An extensible auto-fix pattern; append to {@link SyntaxErrorFixPatterns} to teach the rule new repairs. */
|
|
28
|
+
export interface SyntaxErrorFixPattern {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly description: string;
|
|
31
|
+
readonly direction: FixDirection;
|
|
32
|
+
readonly appliesTo: (finding: SyntaxErrorFinding) => boolean;
|
|
33
|
+
readonly quickFix: (finding: SyntaxErrorFinding, file: string | undefined) => LintQuickFix;
|
|
34
|
+
}
|
|
35
|
+
/** The built-in auto-fix patterns; append a {@link SyntaxErrorFixPattern} to add repairs. */
|
|
36
|
+
export declare const SyntaxErrorFixPatterns: SyntaxErrorFixPattern[];
|
|
37
|
+
export declare const SYNTACTICALLY_VALID: {
|
|
38
|
+
readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", [], 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>[]>>;
|
|
39
|
+
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<{
|
|
40
|
+
results: SyntacticallyValidResult[];
|
|
41
|
+
".meta": SyntacticallyValidMetadata;
|
|
42
|
+
}>;
|
|
43
|
+
readonly prettyPrint: {
|
|
44
|
+
readonly query: (result: SyntacticallyValidResult) => string;
|
|
45
|
+
readonly full: (result: SyntacticallyValidResult) => string;
|
|
46
|
+
};
|
|
47
|
+
readonly info: {
|
|
48
|
+
readonly name: "Syntactically Valid";
|
|
49
|
+
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.";
|
|
50
|
+
readonly tags: readonly [LintingRuleTag.Bug, LintingRuleTag.Robustness, LintingRuleTag.QuickFix];
|
|
51
|
+
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
52
|
+
readonly activeByDefault: false;
|
|
53
|
+
readonly defaultConfig: {
|
|
54
|
+
readonly disabledFixes: readonly [];
|
|
55
|
+
readonly preferFix: "remove";
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SYNTACTICALLY_VALID = exports.SyntaxErrorFixPatterns = void 0;
|
|
4
|
+
const linter_format_1 = require("../linter-format");
|
|
5
|
+
const flowr_search_builder_1 = require("../../search/flowr-search-builder");
|
|
6
|
+
const range_1 = require("../../util/range");
|
|
7
|
+
const linter_tags_1 = require("../linter-tags");
|
|
8
|
+
const DelimiterInsert = new Map([[')', ')'], ['}', '}'], [']', ']'], [']]', ']]'], ['"', '"'], ['\'', '\''], ['`', '`'], [',', ','], [';', ';']]);
|
|
9
|
+
const KeywordInsert = new Map([['in', ' in '], ['else', ' else ']]);
|
|
10
|
+
const OperatorToken = /^([-+*/^:~!<>=&|@$]+|<-|<<-|->|->>|\|>|%[^%]*%)$/;
|
|
11
|
+
const KnownOperators = ['%%', '%/%', '%*%', '%o%', '%x%', '%in%', '%>%', '%<>%', '%+%', '%||%'];
|
|
12
|
+
// tree-sitter is 0-based with an exclusive end column (matching flowR), so only the 1-based start shifts
|
|
13
|
+
const point = (p) => [p.row + 1, p.column + 1, p.row + 1, p.column];
|
|
14
|
+
const span = (n) => [n.startPosition.row + 1, n.startPosition.column + 1, n.endPosition.row + 1, n.endPosition.column];
|
|
15
|
+
const isDanglingOperator = (n) => !!n && !n.isNamed && OperatorToken.test(n.type);
|
|
16
|
+
/** The closing delimiters an unbalanced error region is missing, innermost first (skips strings/comments; `({` needs `})`). */
|
|
17
|
+
function bracketDeficit(text) {
|
|
18
|
+
const stack = [];
|
|
19
|
+
let quote;
|
|
20
|
+
for (let i = 0; i < text.length; i++) {
|
|
21
|
+
const c = text[i];
|
|
22
|
+
if (quote) {
|
|
23
|
+
if (c === '\\') {
|
|
24
|
+
i++;
|
|
25
|
+
}
|
|
26
|
+
else if (c === quote) {
|
|
27
|
+
quote = undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (c === '"' || c === '\'' || c === '`') {
|
|
31
|
+
quote = c;
|
|
32
|
+
}
|
|
33
|
+
else if (c === '#') {
|
|
34
|
+
while (i < text.length && text[i] !== '\n') {
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (c === '(') {
|
|
39
|
+
stack.push(')');
|
|
40
|
+
}
|
|
41
|
+
else if (c === '[') {
|
|
42
|
+
stack.push(text[i + 1] === '[' ? (i++, ']]') : ']');
|
|
43
|
+
}
|
|
44
|
+
else if (c === '{') {
|
|
45
|
+
stack.push('}');
|
|
46
|
+
}
|
|
47
|
+
else if ((c === ')' || c === '}') && stack[stack.length - 1] === c) {
|
|
48
|
+
stack.pop();
|
|
49
|
+
}
|
|
50
|
+
else if (c === ']') {
|
|
51
|
+
if (stack[stack.length - 1] === ']') {
|
|
52
|
+
stack.pop();
|
|
53
|
+
}
|
|
54
|
+
else if (stack[stack.length - 1] === ']]') {
|
|
55
|
+
stack[stack.length - 1] = ']';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return stack.reverse();
|
|
60
|
+
}
|
|
61
|
+
/** Fuzzy-complete the unfinished `%...` operator in an error region to the nearest known operator (else just close it). */
|
|
62
|
+
function operatorCompletion(node) {
|
|
63
|
+
const at = node.text.lastIndexOf('%');
|
|
64
|
+
const fragment = /^%[A-Za-z0-9]*/.exec(node.text.slice(at))?.[0] ?? '%';
|
|
65
|
+
const full = KnownOperators.find(op => op !== fragment && op.startsWith(fragment)) ?? fragment + '%';
|
|
66
|
+
const column = node.startPosition.column + at;
|
|
67
|
+
return { range: [node.startPosition.row + 1, column + 1, node.startPosition.row + 1, column + fragment.length], full };
|
|
68
|
+
}
|
|
69
|
+
const isMissingExpression = (f) => f.kind === 'missing' && !DelimiterInsert.has(f.node.type) && !KeywordInsert.has(f.node.type);
|
|
70
|
+
/** The built-in auto-fix patterns; append a {@link SyntaxErrorFixPattern} to add repairs. */
|
|
71
|
+
exports.SyntaxErrorFixPatterns = [
|
|
72
|
+
{
|
|
73
|
+
name: 'insert-missing-token',
|
|
74
|
+
description: 'Insert a delimiter, quote, or keyword the parser expected but did not find.',
|
|
75
|
+
direction: 'add',
|
|
76
|
+
appliesTo: f => f.kind === 'missing' && (DelimiterInsert.has(f.node.type) || KeywordInsert.has(f.node.type)),
|
|
77
|
+
quickFix: (f, file) => ({
|
|
78
|
+
type: 'replace',
|
|
79
|
+
loc: range_1.SourceLocation.from(point(f.node.startPosition), file),
|
|
80
|
+
description: `Insert missing \`${f.node.type}\``,
|
|
81
|
+
replacement: DelimiterInsert.get(f.node.type) ?? KeywordInsert.get(f.node.type)
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'remove-dangling-operator',
|
|
86
|
+
description: 'Drop a dangling operator whose operand the parser found missing.',
|
|
87
|
+
direction: 'remove',
|
|
88
|
+
appliesTo: f => isMissingExpression(f) && isDanglingOperator(f.node.previousSibling),
|
|
89
|
+
quickFix: (f, file) => ({ type: 'remove', loc: range_1.SourceLocation.from(span(f.node.previousSibling), file), description: `Remove the dangling \`${f.node.previousSibling.type}\`` })
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'insert-operand-placeholder',
|
|
93
|
+
description: 'Insert a `NULL` placeholder for a missing operand or body.',
|
|
94
|
+
direction: 'add',
|
|
95
|
+
appliesTo: isMissingExpression,
|
|
96
|
+
quickFix: (f, file) => ({ type: 'replace', loc: range_1.SourceLocation.from(point(f.node.startPosition), file), description: 'Insert placeholder `NULL`', replacement: ' NULL' })
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'balance-brackets',
|
|
100
|
+
description: 'Close an unbalanced region by appending the brackets that were left open.',
|
|
101
|
+
direction: 'add',
|
|
102
|
+
appliesTo: f => f.kind === 'error' && bracketDeficit(f.node.text).length > 0,
|
|
103
|
+
quickFix: (f, file) => {
|
|
104
|
+
const closers = bracketDeficit(f.node.text).join('');
|
|
105
|
+
return { type: 'replace', loc: range_1.SourceLocation.from(point(f.node.endPosition), file), description: `Add missing closing \`${closers}\``, replacement: closers };
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'complete-operator',
|
|
110
|
+
description: 'Complete an unfinished `%...%` operator to the nearest known one.',
|
|
111
|
+
direction: 'add',
|
|
112
|
+
appliesTo: f => f.kind === 'error' && !f.node.text.includes('\n') && (f.node.text.match(/%/g)?.length ?? 0) % 2 === 1,
|
|
113
|
+
quickFix: (f, file) => {
|
|
114
|
+
const { range, full } = operatorCompletion(f.node);
|
|
115
|
+
return { type: 'replace', loc: range_1.SourceLocation.from(range, file), description: `Complete operator to \`${full}\``, replacement: full };
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'comment-out',
|
|
120
|
+
description: 'Comment out an un-parseable region so the rest of the file still parses.',
|
|
121
|
+
direction: 'comment',
|
|
122
|
+
appliesTo: f => f.kind === 'error' && !f.node.text.includes('\n'),
|
|
123
|
+
quickFix: (f, file) => ({ type: 'replace', loc: range_1.SourceLocation.from(span(f.node), file), description: 'Comment out the offending code', replacement: '# ' + f.node.text })
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
/** Collect the outermost `missing`/`error` nodes, pruning subtrees the parser reports as clean. */
|
|
127
|
+
function collectFindings(node, out = []) {
|
|
128
|
+
if (node.isMissing) {
|
|
129
|
+
out.push({ kind: 'missing', node });
|
|
130
|
+
}
|
|
131
|
+
else if (node.isError) {
|
|
132
|
+
out.push({ kind: 'error', node });
|
|
133
|
+
}
|
|
134
|
+
else if (node.hasError) {
|
|
135
|
+
for (const child of node.children) {
|
|
136
|
+
collectFindings(child, out);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
function describe(finding) {
|
|
142
|
+
if (finding.kind === 'missing') {
|
|
143
|
+
return `Missing \`${finding.node.type}\``;
|
|
144
|
+
}
|
|
145
|
+
const text = finding.node.text.replace(/\s+/g, ' ').trim();
|
|
146
|
+
return `Unexpected \`${text.length > 30 ? text.slice(0, 27) + '...' : text}\``;
|
|
147
|
+
}
|
|
148
|
+
exports.SYNTACTICALLY_VALID = {
|
|
149
|
+
createSearch: () => flowr_search_builder_1.Q.all(),
|
|
150
|
+
processSearchResult: async (_elements, config, data) => {
|
|
151
|
+
const parser = data.parserInformation().name;
|
|
152
|
+
const results = [];
|
|
153
|
+
// only tree-sitter recovers from syntax errors; a hard parser aborts before the linter ever runs
|
|
154
|
+
if (parser === 'tree-sitter') {
|
|
155
|
+
const patterns = exports.SyntaxErrorFixPatterns.filter(p => !config.disabledFixes.includes(p.name));
|
|
156
|
+
for (const file of (await data.parse()).files) {
|
|
157
|
+
const root = file.parsed.rootNode;
|
|
158
|
+
if (!root.hasError) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
for (const finding of collectFindings(root)) {
|
|
162
|
+
// a single fix per error, favouring the preferred direction (alternatives are never emitted together)
|
|
163
|
+
let fix;
|
|
164
|
+
let best = 2;
|
|
165
|
+
for (const p of patterns) {
|
|
166
|
+
const rank = p.direction === config.preferFix ? 0 : 1;
|
|
167
|
+
if (rank < best && p.appliesTo(finding)) {
|
|
168
|
+
fix = p.quickFix(finding, file.filePath);
|
|
169
|
+
best = rank;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
results.push({
|
|
173
|
+
certainty: linter_format_1.LintingResultCertainty.Certain,
|
|
174
|
+
kind: finding.kind,
|
|
175
|
+
involvedId: undefined,
|
|
176
|
+
loc: range_1.SourceLocation.from(span(finding.node), file.filePath),
|
|
177
|
+
message: describe(finding),
|
|
178
|
+
quickFix: fix ? [fix] : undefined
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { results, '.meta': { parser, errors: results.length, fixable: results.filter(r => r.quickFix !== undefined).length } };
|
|
184
|
+
},
|
|
185
|
+
prettyPrint: {
|
|
186
|
+
[linter_format_1.LintingPrettyPrintContext.Query]: (result) => `${result.message} at ${range_1.SourceLocation.format(result.loc)}`,
|
|
187
|
+
[linter_format_1.LintingPrettyPrintContext.Full]: (result) => `Syntax error (${result.kind}): ${result.message} at ${range_1.SourceLocation.format(result.loc)}`
|
|
188
|
+
},
|
|
189
|
+
info: {
|
|
190
|
+
name: 'Syntactically Valid',
|
|
191
|
+
description: 'Checks whether the code is free of syntax errors, using the configured (error-tolerant) parser, and offers extensible quick-fixes to repair them.',
|
|
192
|
+
tags: [linter_tags_1.LintingRuleTag.Bug, linter_tags_1.LintingRuleTag.Robustness, linter_tags_1.LintingRuleTag.QuickFix],
|
|
193
|
+
// tree-sitter reports real syntax errors precisely, but a strict parse may collapse a region into fewer findings
|
|
194
|
+
certainty: linter_format_1.LintingRuleCertainty.BestEffort,
|
|
195
|
+
// only meaningful under tree-sitter, so opt-in rather than part of the default set
|
|
196
|
+
activeByDefault: false,
|
|
197
|
+
defaultConfig: {
|
|
198
|
+
disabledFixes: [],
|
|
199
|
+
preferFix: 'remove'
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
//# sourceMappingURL=syntactically-valid.js.map
|