@eagleoutice/flowr 2.10.7 → 2.10.8
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 +9 -9
- package/abstract-interpretation/domains/multi-value-state-domain.d.ts +4 -10
- package/abstract-interpretation/domains/multi-value-state-domain.js +1 -6
- package/abstract-interpretation/domains/partial-product-domain.d.ts +6 -2
- package/abstract-interpretation/domains/partial-product-domain.js +7 -3
- package/documentation/wiki-linting-and-testing.js +1 -1
- package/documentation/wiki-mk/doc-context.d.ts +21 -1
- package/documentation/wiki-mk/doc-context.js +9 -0
- package/documentation/wiki-search.js +13 -2
- package/linter/linter-rules.d.ts +4 -2
- package/linter/rules/absolute-path.d.ts +3 -0
- package/linter/rules/absolute-path.js +37 -12
- package/linter/rules/file-path-validity.d.ts +9 -2
- package/linter/rules/file-path-validity.js +83 -36
- package/linter/rules/problematic-inputs.js +4 -1
- package/package.json +4 -3
- package/queries/catalog/dependencies-query/function-info/read-functions.js +21 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +18 -1
- package/queries/catalog/input-sources-query/input-source-functions.d.ts +3 -1
- package/queries/catalog/input-sources-query/input-source-functions.js +322 -46
- package/queries/catalog/input-sources-query/input-sources-query-executor.js +14 -9
- package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +4 -2
- package/queries/catalog/input-sources-query/input-sources-query-format.js +8 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +13 -6
- package/queries/catalog/input-sources-query/simple-input-classifier.js +33 -8
- package/queries/catalog/linter-query/linter-query-format.d.ts +2 -2
- package/queries/catalog/linter-query/linter-query-format.js +9 -3
- package/queries/query.d.ts +3 -2
- package/search/flowr-search-builder.d.ts +50 -16
- package/search/flowr-search-builder.js +33 -17
- package/search/flowr-search-filters.d.ts +10 -1
- package/search/flowr-search-filters.js +10 -0
- package/search/flowr-search.d.ts +8 -3
- package/search/search-executor/search-generators.d.ts +2 -0
- package/search/search-executor/search-generators.js +2 -2
- package/util/text/strings.d.ts +7 -0
- package/util/text/strings.js +23 -0
- package/util/version.js +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ It offers a wide variety of features, for example:
|
|
|
24
24
|
|
|
25
25
|
```shell
|
|
26
26
|
$ docker run -it --rm eagleoutice/flowr # or npm run flowr
|
|
27
|
-
flowR repl using flowR v2.10.
|
|
27
|
+
flowR repl using flowR v2.10.7, R grammar v14 (tree-sitter engine)
|
|
28
28
|
R> :query @linter "read.csv(\"/root/x.txt\")"
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -51,9 +51,9 @@ It offers a wide variety of features, for example:
|
|
|
51
51
|
╰ Naming Convention (naming-convention):
|
|
52
52
|
╰ Metadata: numMatches: 0, numBreak: 0, searchTimeMs: 0, processTimeMs: 0
|
|
53
53
|
╰ Network Functions (network-functions):
|
|
54
|
-
╰ Metadata: totalCalls: 0, totalFunctionDefinitions: 0, searchTimeMs: 0, processTimeMs:
|
|
54
|
+
╰ Metadata: totalCalls: 0, totalFunctionDefinitions: 0, searchTimeMs: 0, processTimeMs: 1
|
|
55
55
|
╰ Dataframe Access Validation (dataframe-access-validation):
|
|
56
|
-
╰ Metadata: numOperations: 0, numAccesses: 0, totalAccessed: 0, searchTimeMs: 0, processTimeMs:
|
|
56
|
+
╰ Metadata: numOperations: 0, numAccesses: 0, totalAccessed: 0, searchTimeMs: 0, processTimeMs: 0
|
|
57
57
|
╰ Dead Code (dead-code):
|
|
58
58
|
╰ Metadata: consideredNodes: 5, searchTimeMs: 0, processTimeMs: 0
|
|
59
59
|
╰ Useless Loops (useless-loop):
|
|
@@ -117,11 +117,11 @@ It offers a wide variety of features, for example:
|
|
|
117
117
|
╰ _Metadata_: <code>consideredNodes: 0, searchTimeMs: 0, processTimeMs: 0</code>\
|
|
118
118
|
╰ **Roxygen Arguments** (roxygen-arguments):\
|
|
119
119
|
╰ _Metadata_: <code>searchTimeMs: 0, processTimeMs: 0</code>\
|
|
120
|
-
_All queries together required ≈2 ms (1ms accuracy, total
|
|
120
|
+
_All queries together required ≈2 ms (1ms accuracy, total 2 ms)_
|
|
121
121
|
|
|
122
122
|
<details> <summary style="color:gray">Show Detailed Results as Json</summary>
|
|
123
123
|
|
|
124
|
-
The analysis required _2.
|
|
124
|
+
The analysis required _2.4 ms_ (including parsing and normalization and the query) within the generation environment.
|
|
125
125
|
|
|
126
126
|
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR.
|
|
127
127
|
Please consult the [Interface](https://github.com/flowr-analysis/flowr/wiki/Interface) wiki page for more information on how to get those.
|
|
@@ -342,7 +342,7 @@ It offers a wide variety of features, for example:
|
|
|
342
342
|
|
|
343
343
|
```shell
|
|
344
344
|
$ docker run -it --rm eagleoutice/flowr # or npm run flowr
|
|
345
|
-
flowR repl using flowR v2.10.
|
|
345
|
+
flowR repl using flowR v2.10.7, R grammar v14 (tree-sitter engine)
|
|
346
346
|
R> :query @static-slice (11@sum) file://test/testfiles/example.R
|
|
347
347
|
```
|
|
348
348
|
|
|
@@ -390,7 +390,7 @@ It offers a wide variety of features, for example:
|
|
|
390
390
|
|
|
391
391
|
|
|
392
392
|
* 🚀 **fast call-graph, data-, and control-flow graphs**\
|
|
393
|
-
Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">
|
|
393
|
+
Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">98.6 ms</span></i> (as of Jun 3, 2026)](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark),
|
|
394
394
|
_flowR_ can analyze the data- and control-flow of the average real-world R script. See the [benchmarks](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark) for more information,
|
|
395
395
|
and consult the [wiki pages](https://github.com/flowr-analysis/flowr/wiki/dataflow-graph) for more details on the [dataflow graphs](https://github.com/flowr-analysis/flowr/wiki/dataflow-graph) as well as [call graphs](https://github.com/flowr-analysis/flowr/wiki/dataflow-graph#perspectives-cg).
|
|
396
396
|
|
|
@@ -426,7 +426,7 @@ It offers a wide variety of features, for example:
|
|
|
426
426
|
|
|
427
427
|
```shell
|
|
428
428
|
$ docker run -it --rm eagleoutice/flowr # or npm run flowr
|
|
429
|
-
flowR repl using flowR v2.10.
|
|
429
|
+
flowR repl using flowR v2.10.7, R grammar v14 (tree-sitter engine)
|
|
430
430
|
R> :dataflow* test/testfiles/example.R
|
|
431
431
|
```
|
|
432
432
|
|
|
@@ -734,7 +734,7 @@ It offers a wide variety of features, for example:
|
|
|
734
734
|
```
|
|
735
735
|
|
|
736
736
|
|
|
737
|
-
(The analysis required
|
|
737
|
+
(The analysis required _1.9 ms_ (including parse and normalize, using the [tree-sitter](https://github.com/flowr-analysis/flowr/wiki/Engines) engine) within the generation environment.)
|
|
738
738
|
|
|
739
739
|
|
|
740
740
|
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
2
|
-
import { type AbstractProduct, PartialProductDomain } from './partial-product-domain';
|
|
2
|
+
import { type AbstractProduct, type ProductReduction, PartialProductDomain } from './partial-product-domain';
|
|
3
3
|
import { type StateDomainLift, StateAbstractDomain } from './state-abstract-domain';
|
|
4
|
-
/**
|
|
5
|
-
* A reduction function for abstract values of a product domain.
|
|
6
|
-
*/
|
|
7
|
-
export type Reduction<Product extends AbstractProduct> = (value: Product) => Product;
|
|
8
4
|
/**
|
|
9
5
|
* A multi-value state abstract domain that maps AST node IDs to multiple abstract values from different abstract domains.
|
|
10
6
|
* @template Product - Type of the abstract product of the multi-value domain combining multiple abstract values
|
|
11
7
|
* @see {@link NodeId} for the node IDs of the AST nodes
|
|
12
8
|
*/
|
|
13
9
|
export declare class MultiValueStateDomain<Product extends AbstractProduct, Value extends StateDomainLift<MultiValueDomain<Product>> = StateDomainLift<MultiValueDomain<Product>>> extends StateAbstractDomain<MultiValueDomain<Product>, Value> {
|
|
14
|
-
constructor(value: Value, domain: Required<Product>, reductions?: readonly
|
|
10
|
+
constructor(value: Value, domain: Required<Product>, reductions?: readonly ProductReduction<Product>[]);
|
|
15
11
|
create(value: StateDomainLift<MultiValueDomain<Product>>): this;
|
|
16
12
|
getValue<Key extends keyof Product>(node: NodeId, property: Key): Product[Key] | undefined;
|
|
17
13
|
hasValue(node: NodeId, property: keyof Product): boolean;
|
|
@@ -24,9 +20,7 @@ export declare class MultiValueStateDomain<Product extends AbstractProduct, Valu
|
|
|
24
20
|
* @see {@link MultiValueStateDomain} for a state abstract domain of a multi-value domain
|
|
25
21
|
*/
|
|
26
22
|
export declare class MultiValueDomain<Product extends AbstractProduct> extends PartialProductDomain<Product> {
|
|
27
|
-
|
|
28
|
-
constructor(value: Product, domain: Required<Product>, reductions?: readonly Reduction<Product>[]);
|
|
23
|
+
constructor(value: Product, domain: Required<Product>, reductions?: readonly ProductReduction<Product>[]);
|
|
29
24
|
create(value: Product): this;
|
|
30
|
-
static top<Product extends AbstractProduct>(domain: Required<Product>, reductions?: readonly
|
|
31
|
-
protected reduce(value: Product): Product;
|
|
25
|
+
static top<Product extends AbstractProduct>(domain: Required<Product>, reductions?: readonly ProductReduction<Product>[]): MultiValueDomain<Product>;
|
|
32
26
|
}
|
|
@@ -41,10 +41,8 @@ exports.MultiValueStateDomain = MultiValueStateDomain;
|
|
|
41
41
|
* @see {@link MultiValueStateDomain} for a state abstract domain of a multi-value domain
|
|
42
42
|
*/
|
|
43
43
|
class MultiValueDomain extends partial_product_domain_1.PartialProductDomain {
|
|
44
|
-
reductions;
|
|
45
44
|
constructor(value, domain, reductions = []) {
|
|
46
|
-
super(value, domain);
|
|
47
|
-
this.reductions = reductions;
|
|
45
|
+
super(value, domain, reductions);
|
|
48
46
|
}
|
|
49
47
|
create(value) {
|
|
50
48
|
return new MultiValueDomain(value, this.domain, this.reductions);
|
|
@@ -52,9 +50,6 @@ class MultiValueDomain extends partial_product_domain_1.PartialProductDomain {
|
|
|
52
50
|
static top(domain, reductions = []) {
|
|
53
51
|
return new MultiValueDomain({}, domain, reductions);
|
|
54
52
|
}
|
|
55
|
-
reduce(value) {
|
|
56
|
-
return this.reductions.reduce((current, reduction) => reduction(current), value);
|
|
57
|
-
}
|
|
58
53
|
}
|
|
59
54
|
exports.MultiValueDomain = MultiValueDomain;
|
|
60
55
|
//# sourceMappingURL=multi-value-state-domain.js.map
|
|
@@ -8,6 +8,8 @@ export type AbstractProduct<Domain extends AnyAbstractDomain = AnyAbstractDomain
|
|
|
8
8
|
export type ConcreteProductOf<Product extends AbstractProduct> = {
|
|
9
9
|
[Key in keyof Product]: Product[Key] extends AbstractDomain<infer Concrete, unknown, unknown, unknown> ? Concrete : never;
|
|
10
10
|
};
|
|
11
|
+
/** A reduction function of a reduced product domain refining the abstract value based on the values of its sub abstract domains. */
|
|
12
|
+
export type ProductReduction<Product extends AbstractProduct> = (value: Product) => Product;
|
|
11
13
|
/**
|
|
12
14
|
* A partial product abstract domain as named Cartesian product of (optional) sub abstract domains.
|
|
13
15
|
* The sub abstract domains are represented by a (partial) record mapping property names to abstract domains.
|
|
@@ -16,7 +18,8 @@ export type ConcreteProductOf<Product extends AbstractProduct> = {
|
|
|
16
18
|
*/
|
|
17
19
|
export declare abstract class PartialProductDomain<Product extends AbstractProduct> extends AbstractDomain<ConcreteProductOf<Product>, Product, Product, Product> {
|
|
18
20
|
readonly domain: Required<Product>;
|
|
19
|
-
|
|
21
|
+
readonly reductions: readonly ProductReduction<Product>[];
|
|
22
|
+
constructor(value: Product, domain: Required<Product>, reductions?: readonly ProductReduction<Product>[]);
|
|
20
23
|
abstract create(value: Product): this;
|
|
21
24
|
bottom(): this;
|
|
22
25
|
top(): this;
|
|
@@ -37,7 +40,8 @@ export declare abstract class PartialProductDomain<Product extends AbstractProdu
|
|
|
37
40
|
isValue(): boolean;
|
|
38
41
|
isValue(): this is this;
|
|
39
42
|
/**
|
|
40
|
-
*
|
|
43
|
+
* Applies the {@link reductions} of the (reduced) product domain to refine the abstract value based on its components.
|
|
44
|
+
* Subclasses may override this to implement a fixed reduction instead of (or in addition to) the configurable reductions.
|
|
41
45
|
*/
|
|
42
46
|
protected reduce(value: Product): Product;
|
|
43
47
|
}
|
|
@@ -12,8 +12,11 @@ const record_1 = require("../../util/record");
|
|
|
12
12
|
*/
|
|
13
13
|
class PartialProductDomain extends abstract_domain_1.AbstractDomain {
|
|
14
14
|
domain;
|
|
15
|
-
|
|
15
|
+
reductions;
|
|
16
|
+
constructor(value, domain, reductions = []) {
|
|
16
17
|
super(record_1.Record.mapProperties(value, entry => entry?.create(entry.value)));
|
|
18
|
+
// must be assigned before reduce is called, as the (overridable) reduce may depend on the reductions
|
|
19
|
+
this.reductions = reductions;
|
|
17
20
|
this._value = this.reduce(this.value);
|
|
18
21
|
this.domain = domain;
|
|
19
22
|
}
|
|
@@ -153,10 +156,11 @@ class PartialProductDomain extends abstract_domain_1.AbstractDomain {
|
|
|
153
156
|
return true;
|
|
154
157
|
}
|
|
155
158
|
/**
|
|
156
|
-
*
|
|
159
|
+
* Applies the {@link reductions} of the (reduced) product domain to refine the abstract value based on its components.
|
|
160
|
+
* Subclasses may override this to implement a fixed reduction instead of (or in addition to) the configurable reductions.
|
|
157
161
|
*/
|
|
158
162
|
reduce(value) {
|
|
159
|
-
return value;
|
|
163
|
+
return this.reductions.reduce((current, reduction) => reduction(current), value);
|
|
160
164
|
}
|
|
161
165
|
}
|
|
162
166
|
exports.PartialProductDomain = PartialProductDomain;
|
|
@@ -51,7 +51,7 @@ This command includes the construction of the docker image, the generation of th
|
|
|
51
51
|
|
|
52
52
|
The functionality tests represent conventional unit (and depending on your terminology component/api) tests.
|
|
53
53
|
We use [vitest](https://vitest.dev/) as our testing framework.
|
|
54
|
-
You can run the tests by issuing (some quick benchmarks may be available with \`
|
|
54
|
+
You can run the tests by issuing (some quick benchmarks may be available with \`npm run test:bench\`):
|
|
55
55
|
|
|
56
56
|
${(0, doc_code_1.codeBlock)('shell', 'npm run test')}
|
|
57
57
|
|
|
@@ -173,7 +173,27 @@ export interface GeneralDocContext {
|
|
|
173
173
|
*/
|
|
174
174
|
doc(element: ElementIdOrRef, filter?: Omit<ElementFilter, 'file'>): string;
|
|
175
175
|
/**
|
|
176
|
-
* Returns the
|
|
176
|
+
* Returns the documentation for a member of a class as Markdown string.
|
|
177
|
+
* This is a convenience method around {@link GeneralDocContext#doc|doc}.
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* docM(MyClass, 'myMethod')
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* Creates the documentation for the `myMethod` member of the `MyClass` class in the code base.
|
|
184
|
+
* @see {@link GeneralDocContext#doc|doc} - for the underlying impl.
|
|
185
|
+
* @see {@link GeneralDocContext#docO|docO} - to get documentation using an object reference instead of a class and member name.
|
|
186
|
+
*/
|
|
187
|
+
docM<T extends NamedPrototype>(cls: T, element: ProtoKeys<T> | StaticKeys<T>, filter?: Omit<ElementFilter, 'file'>): string;
|
|
188
|
+
/**
|
|
189
|
+
* Returns the documentation for a type/element definition which is retrieved from an object reference.
|
|
190
|
+
* This is similar to {@link GeneralDocContext#doc}, but it uses an object reference to identify the element.
|
|
191
|
+
*/
|
|
192
|
+
docO<T extends object & {
|
|
193
|
+
name: string;
|
|
194
|
+
}>(obj: T, element: keyof T, filter?: Omit<ElementFilter, 'file'>): string;
|
|
195
|
+
/**
|
|
196
|
+
* Returns the code snippet for a code element as Markdown string.
|
|
177
197
|
* @param element - The element to create a code snippet for, the name can be qualified with `::` to specify the class.
|
|
178
198
|
* @param fmt - Formatting options for the code snippet (see {@link FnElementInfo})
|
|
179
199
|
* @param filter - An optional filter to further specify the element to get the code for, in case multiple elements with the same name exist.
|
|
@@ -56,6 +56,15 @@ function makeDocContextForTypes(shell, ...rootFolders) {
|
|
|
56
56
|
doc(element, filter) {
|
|
57
57
|
return (0, doc_types_1.getDocumentationForType)(getNameFromElementIdOrRef(element), info, '', filter);
|
|
58
58
|
},
|
|
59
|
+
docM(cls, element, filter) {
|
|
60
|
+
const className = cls.prototype.constructor.name;
|
|
61
|
+
const fullName = `${className}::${String(element)}`;
|
|
62
|
+
return this.doc(fullName, filter);
|
|
63
|
+
},
|
|
64
|
+
docO(obj, element, filter) {
|
|
65
|
+
const fullName = `${obj.name}::${String(element)}`;
|
|
66
|
+
return this.doc(fullName, filter);
|
|
67
|
+
},
|
|
59
68
|
link(element, fmt, filter) {
|
|
60
69
|
(0, assert_1.guard)(filter?.file === undefined, 'filtering for files is not yet supported for link');
|
|
61
70
|
return (0, doc_types_1.shortLink)(getNameFromElementIdOrRef(element), info, fmt?.codeFont, fmt?.realNameWrapper, filter?.fuzzy, filter?.type);
|
|
@@ -38,16 +38,27 @@ and can be further refined with _transformers_ or _modifiers_.
|
|
|
38
38
|
Such queries can be constructed starting from the ${ctx.link('Q')} object (backed by ${ctx.link('FlowrSearchGenerator')}) and
|
|
39
39
|
are fully serializable so you can use them when communicating with the [Query API](${doc_files_1.FlowrWikiBaseRef}/Query%20API).
|
|
40
40
|
|
|
41
|
+
## File Path Filtering
|
|
42
|
+
|
|
43
|
+
Many convenience functions and the \`get\` generator support filtering by file path using the \`filePathRegex\` parameter.
|
|
44
|
+
This is useful when you want to search for nodes only in specific files.
|
|
45
|
+
Additionally, inline code (code without a file path) is treated as having an empty path \`""\` for regex matching purposes.
|
|
46
|
+
|
|
47
|
+
The ${ctx.link(flowr_search_builder_1.FlowrSearchGenerator)} provides several convenience functions for searching variables with file path filtering.
|
|
48
|
+
${ctx.linkO(flowr_search_builder_1.FlowrSearchGenerator, 'var')} and other functions like ${ctx.linkO(flowr_search_builder_1.FlowrSearchGenerator, 'get')}
|
|
49
|
+
also allow you to pass in a regex to only match files that fit your specified pattern!
|
|
50
|
+
|
|
51
|
+
|
|
41
52
|
We offer the following generators:
|
|
42
53
|
|
|
43
|
-
${Object.keys(flowr_search_builder_1.Q).sort().map(key => `- ${ctx.
|
|
54
|
+
${Object.keys(flowr_search_builder_1.Q).filter(n => n !== 'name').sort((a, b) => a.localeCompare(b)).map(key => `- ${ctx.linkO(flowr_search_builder_1.FlowrSearchGenerator, key)}\\\n${ctx.docO(flowr_search_builder_1.FlowrSearchGenerator, key)}`).join('\n')}
|
|
44
55
|
|
|
45
56
|
Likewise, we have a palette of _transformers_ and _modifiers_:
|
|
46
57
|
|
|
47
58
|
${
|
|
48
59
|
/* let's iterate over all methods of FlowrSearchBuilder */
|
|
49
60
|
Object.getOwnPropertyNames(Object.getPrototypeOf(new flowr_search_builder_1.FlowrSearchBuilder(undefined)))
|
|
50
|
-
.filter(n => n !== 'constructor').sort().map(key => `- ${ctx.
|
|
61
|
+
.filter(n => n !== 'constructor' && n !== 'name').sort().map(key => `- ${ctx.linkM(flowr_search_builder_1.FlowrSearchBuilder, key)}\\\n${ctx.docM(flowr_search_builder_1.FlowrSearchBuilder, key)}`).join('\n')}
|
|
51
62
|
|
|
52
63
|
Every search (and consequently the search pipeline) works with an array of ${ctx.link('FlowrSearchElement')} (neatly wrapped in ${ctx.link(flowr_search_1.FlowrSearchElements)}).
|
|
53
64
|
Hence, even operations such as \`.first\` or \`.last\` return an array of elements (albeit with a single or no element).
|
package/linter/linter-rules.d.ts
CHANGED
|
@@ -33,10 +33,10 @@ export declare const LintingRules: {
|
|
|
33
33
|
dataflow: import("../dataflow/info").DataflowInformation;
|
|
34
34
|
cfg: import("../control-flow/control-flow-graph").ControlFlowInformation;
|
|
35
35
|
analyzer: import("../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider;
|
|
36
|
-
}) => {
|
|
36
|
+
}) => Promise<{
|
|
37
37
|
results: import("./rules/file-path-validity").FilePathValidityResult[];
|
|
38
38
|
".meta": import("./rules/file-path-validity").FilePathValidityMetadata;
|
|
39
|
-
}
|
|
39
|
+
}>;
|
|
40
40
|
readonly info: {
|
|
41
41
|
readonly name: "File Path Validity";
|
|
42
42
|
readonly description: "Checks whether file paths used in read and write operations are valid and point to existing files.";
|
|
@@ -46,6 +46,7 @@ export declare const LintingRules: {
|
|
|
46
46
|
readonly additionalReadFunctions: readonly [];
|
|
47
47
|
readonly additionalWriteFunctions: readonly [];
|
|
48
48
|
readonly includeUnknown: false;
|
|
49
|
+
readonly checkUrls: false;
|
|
49
50
|
};
|
|
50
51
|
};
|
|
51
52
|
readonly prettyPrint: {
|
|
@@ -118,6 +119,7 @@ export declare const LintingRules: {
|
|
|
118
119
|
readonly additionalPathFunctions: readonly [];
|
|
119
120
|
readonly absolutePathRegex: undefined;
|
|
120
121
|
readonly useAsWd: "@script";
|
|
122
|
+
readonly ignoreUrls: true;
|
|
121
123
|
};
|
|
122
124
|
};
|
|
123
125
|
};
|
|
@@ -26,6 +26,8 @@ export interface AbsoluteFilePathConfig extends MergeableRecord {
|
|
|
26
26
|
* This is only relevant with quickfixes. In the future we may be sensitive to setwd etc.
|
|
27
27
|
*/
|
|
28
28
|
useAsWd: SupportedWd;
|
|
29
|
+
/** Automatically ignore URLs (http/https/ftp) so they are not reported as absolute paths. */
|
|
30
|
+
ignoreUrls: boolean;
|
|
29
31
|
}
|
|
30
32
|
export interface AbsoluteFilePathMetadata extends MergeableRecord {
|
|
31
33
|
totalConsidered: number;
|
|
@@ -59,6 +61,7 @@ export declare const ABSOLUTE_PATH: {
|
|
|
59
61
|
readonly additionalPathFunctions: readonly [];
|
|
60
62
|
readonly absolutePathRegex: undefined;
|
|
61
63
|
readonly useAsWd: "@script";
|
|
64
|
+
readonly ignoreUrls: true;
|
|
62
65
|
};
|
|
63
66
|
};
|
|
64
67
|
};
|
|
@@ -69,6 +69,19 @@ const PathFunctions = new Map([
|
|
|
69
69
|
return results;
|
|
70
70
|
}]
|
|
71
71
|
]);
|
|
72
|
+
/**
|
|
73
|
+
* Resolve a raw string value to the path that should be checked for absoluteness.
|
|
74
|
+
* - `file://` URIs: extract the local path (always checked, ignoreUrls has no effect)
|
|
75
|
+
* - remote URLs (http/s3/...): `undefined` when ignoreUrls is true (skip)
|
|
76
|
+
* - everything else: the value itself
|
|
77
|
+
*/
|
|
78
|
+
function resolvePathForAbsoluteCheck(value, ignoreUrls) {
|
|
79
|
+
const local = (0, strings_1.fileUrlToPath)(value);
|
|
80
|
+
if (local !== undefined) {
|
|
81
|
+
return local;
|
|
82
|
+
}
|
|
83
|
+
return ignoreUrls && (0, strings_1.isUrl)(value) ? undefined : value;
|
|
84
|
+
}
|
|
72
85
|
exports.ABSOLUTE_PATH = {
|
|
73
86
|
/* this can be done better once we have types */
|
|
74
87
|
createSearch: (config) => {
|
|
@@ -103,12 +116,13 @@ exports.ABSOLUTE_PATH = {
|
|
|
103
116
|
const node = element.node;
|
|
104
117
|
const wd = inferWd(node.info.file, config.useAsWd);
|
|
105
118
|
if (r_string_1.RString.is(node)) {
|
|
106
|
-
|
|
119
|
+
const resolved = resolvePathForAbsoluteCheck(node.content.str, config.ignoreUrls);
|
|
120
|
+
if (resolved !== undefined && resolved.length >= 3 && (0, strings_1.isAbsolutePath)(resolved, regex)) {
|
|
107
121
|
return [{
|
|
108
122
|
certainty: linter_format_1.LintingResultCertainty.Uncertain,
|
|
109
|
-
filePath:
|
|
123
|
+
filePath: resolved,
|
|
110
124
|
loc: range_1.SourceLocation.fromNode(node) ?? range_1.SourceLocation.invalid(),
|
|
111
|
-
quickFix: buildQuickFix(node,
|
|
125
|
+
quickFix: buildQuickFix(node, resolved, wd)
|
|
112
126
|
}];
|
|
113
127
|
}
|
|
114
128
|
else {
|
|
@@ -117,14 +131,21 @@ exports.ABSOLUTE_PATH = {
|
|
|
117
131
|
}
|
|
118
132
|
else if ((0, search_enrichers_1.enrichmentContent)(element, search_enrichers_1.Enrichment.QueryData)) {
|
|
119
133
|
const result = queryResults[(0, search_enrichers_1.enrichmentContent)(element, search_enrichers_1.Enrichment.QueryData).query];
|
|
120
|
-
const mappedStrings = result.read.
|
|
134
|
+
const mappedStrings = result.read.flatMap(r => {
|
|
135
|
+
if (r.value === undefined || r.value === dependencies_query_format_1.Unknown) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
const resolved = resolvePathForAbsoluteCheck(r.value, config.ignoreUrls);
|
|
139
|
+
if (resolved === undefined || !(0, strings_1.isAbsolutePath)(resolved, regex)) {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
121
142
|
const elem = data.normalize.idMap.get(r.nodeId);
|
|
122
|
-
return {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
return [{
|
|
144
|
+
certainty: linter_format_1.LintingResultCertainty.Certain,
|
|
145
|
+
filePath: resolved,
|
|
146
|
+
loc: elem ? range_1.SourceLocation.fromNode(elem) ?? range_1.SourceLocation.invalid() : range_1.SourceLocation.invalid(),
|
|
147
|
+
quickFix: buildQuickFix(elem, resolved, wd)
|
|
148
|
+
}];
|
|
128
149
|
});
|
|
129
150
|
if (mappedStrings.length > 0) {
|
|
130
151
|
return mappedStrings;
|
|
@@ -140,7 +161,10 @@ exports.ABSOLUTE_PATH = {
|
|
|
140
161
|
const handler = dfNode.name ? PathFunctions.get(dfNode.name) : undefined;
|
|
141
162
|
const strings = handler ? handler(data.dataflow.graph, dfNode, data.analyzer.inspectContext()) : [];
|
|
142
163
|
if (strings) {
|
|
143
|
-
return strings.
|
|
164
|
+
return strings.flatMap(s => {
|
|
165
|
+
const resolved = resolvePathForAbsoluteCheck(s, config.ignoreUrls);
|
|
166
|
+
return resolved !== undefined && (0, strings_1.isAbsolutePath)(resolved, regex) ? [resolved] : [];
|
|
167
|
+
}).map(str => ({
|
|
144
168
|
certainty: linter_format_1.LintingResultCertainty.Uncertain,
|
|
145
169
|
filePath: str,
|
|
146
170
|
loc: range_1.SourceLocation.fromNode(element.node) ?? range_1.SourceLocation.invalid(),
|
|
@@ -173,7 +197,8 @@ exports.ABSOLUTE_PATH = {
|
|
|
173
197
|
},
|
|
174
198
|
additionalPathFunctions: [],
|
|
175
199
|
absolutePathRegex: undefined,
|
|
176
|
-
useAsWd: '@script'
|
|
200
|
+
useAsWd: '@script',
|
|
201
|
+
ignoreUrls: true
|
|
177
202
|
}
|
|
178
203
|
}
|
|
179
204
|
};
|
|
@@ -20,6 +20,12 @@ export interface FilePathValidityConfig extends MergeableRecord {
|
|
|
20
20
|
* Whether unknown file paths should be included as linting results.
|
|
21
21
|
*/
|
|
22
22
|
includeUnknown: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether URLs should be validated by checking the endpoint exists.
|
|
25
|
+
* When `false` (default), URLs are silently ignored.
|
|
26
|
+
* When `true`, an HTTP HEAD request is made and the URL is reported if unreachable.
|
|
27
|
+
*/
|
|
28
|
+
checkUrls: boolean;
|
|
23
29
|
}
|
|
24
30
|
export interface FilePathValidityMetadata extends MergeableRecord {
|
|
25
31
|
totalReads: number;
|
|
@@ -34,10 +40,10 @@ export declare const FILE_PATH_VALIDITY: {
|
|
|
34
40
|
dataflow: import("../../dataflow/info").DataflowInformation;
|
|
35
41
|
cfg: import("../../control-flow/control-flow-graph").ControlFlowInformation;
|
|
36
42
|
analyzer: import("../../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider;
|
|
37
|
-
}) => {
|
|
43
|
+
}) => Promise<{
|
|
38
44
|
results: FilePathValidityResult[];
|
|
39
45
|
".meta": FilePathValidityMetadata;
|
|
40
|
-
}
|
|
46
|
+
}>;
|
|
41
47
|
readonly info: {
|
|
42
48
|
readonly name: "File Path Validity";
|
|
43
49
|
readonly description: "Checks whether file paths used in read and write operations are valid and point to existing files.";
|
|
@@ -47,6 +53,7 @@ export declare const FILE_PATH_VALIDITY: {
|
|
|
47
53
|
readonly additionalReadFunctions: readonly [];
|
|
48
54
|
readonly additionalWriteFunctions: readonly [];
|
|
49
55
|
readonly includeUnknown: false;
|
|
56
|
+
readonly checkUrls: false;
|
|
50
57
|
};
|
|
51
58
|
};
|
|
52
59
|
readonly prettyPrint: {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FILE_PATH_VALIDITY = void 0;
|
|
4
4
|
const linter_format_1 = require("../linter-format");
|
|
5
|
+
const strings_1 = require("../../util/text/strings");
|
|
5
6
|
const flowr_search_builder_1 = require("../../search/flowr-search-builder");
|
|
6
7
|
const range_1 = require("../../util/range");
|
|
7
8
|
const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
|
|
@@ -10,6 +11,15 @@ const logic_1 = require("../../util/logic");
|
|
|
10
11
|
const happens_before_1 = require("../../control-flow/happens-before");
|
|
11
12
|
const linter_tags_1 = require("../linter-tags");
|
|
12
13
|
const search_enrichers_1 = require("../../search/search-executor/search-enrichers");
|
|
14
|
+
async function urlExists(url) {
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch(url, { method: 'HEAD' });
|
|
17
|
+
return response.ok;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
13
23
|
exports.FILE_PATH_VALIDITY = {
|
|
14
24
|
createSearch: (config) => flowr_search_builder_1.Q.fromQuery({
|
|
15
25
|
type: 'dependencies',
|
|
@@ -17,7 +27,7 @@ exports.FILE_PATH_VALIDITY = {
|
|
|
17
27
|
readFunctions: config.additionalReadFunctions,
|
|
18
28
|
writeFunctions: config.additionalWriteFunctions
|
|
19
29
|
}).with(search_enrichers_1.Enrichment.CfgInformation),
|
|
20
|
-
processSearchResult: (elements, config, data) => {
|
|
30
|
+
processSearchResult: async (elements, config, data) => {
|
|
21
31
|
const cfg = elements.enrichmentContent(search_enrichers_1.Enrichment.CfgInformation).cfg.graph;
|
|
22
32
|
const metadata = {
|
|
23
33
|
totalReads: 0,
|
|
@@ -26,41 +36,35 @@ exports.FILE_PATH_VALIDITY = {
|
|
|
26
36
|
totalValid: 0
|
|
27
37
|
};
|
|
28
38
|
const results = elements.enrichmentContent(search_enrichers_1.Enrichment.QueryData).queries['dependencies'];
|
|
29
|
-
|
|
30
|
-
results
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
const findings = await Promise.all(elements.getElements().map(async (element) => {
|
|
40
|
+
const matchingRead = results.read.find(r => r.nodeId === element.node.info.id);
|
|
41
|
+
if (!matchingRead) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
metadata.totalReads++;
|
|
45
|
+
const loc = range_1.SourceLocation.fromNode(element.node);
|
|
46
|
+
if (!loc) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
// check if we can't parse the file path statically
|
|
50
|
+
if (matchingRead.value === dependencies_query_format_1.Unknown) {
|
|
51
|
+
metadata.totalUnknown++;
|
|
52
|
+
if (config.includeUnknown) {
|
|
53
|
+
return [{
|
|
54
|
+
involvedId: matchingRead.nodeId,
|
|
55
|
+
loc,
|
|
56
|
+
filePath: dependencies_query_format_1.Unknown,
|
|
57
|
+
certainty: linter_format_1.LintingResultCertainty.Uncertain
|
|
58
|
+
}];
|
|
34
59
|
}
|
|
35
|
-
|
|
36
|
-
const loc = range_1.SourceLocation.fromNode(element.node);
|
|
37
|
-
if (!loc) {
|
|
60
|
+
else {
|
|
38
61
|
return [];
|
|
39
62
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
involvedId: matchingRead.nodeId,
|
|
46
|
-
loc,
|
|
47
|
-
filePath: dependencies_query_format_1.Unknown,
|
|
48
|
-
certainty: linter_format_1.LintingResultCertainty.Uncertain
|
|
49
|
-
}];
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// check if any write to the same file happens before the read, and exclude this case if so
|
|
56
|
-
const writesToFile = results.write.filter(r => samePath(r.value, matchingRead.value, data.analyzer.flowrConfig.solver.resolveSource?.ignoreCapitalization));
|
|
57
|
-
const writesBefore = writesToFile.map(w => (0, happens_before_1.happensBefore)(cfg, w.nodeId, element.node.info.id));
|
|
58
|
-
if (writesBefore.some(w => w === logic_1.Ternary.Always)) {
|
|
59
|
-
metadata.totalWritesBeforeAlways++;
|
|
60
|
-
return [];
|
|
61
|
-
}
|
|
62
|
-
// check if the file exists!
|
|
63
|
-
const paths = (0, built_in_source_1.findSource)(data.analyzer.flowrConfig.solver.resolveSource, matchingRead.value, {
|
|
63
|
+
}
|
|
64
|
+
// file:// URIs are local paths; resolve and check existence directly
|
|
65
|
+
const localFromFileUrl = (0, strings_1.fileUrlToPath)(matchingRead.value);
|
|
66
|
+
if (localFromFileUrl !== undefined) {
|
|
67
|
+
const paths = (0, built_in_source_1.findSource)(data.analyzer.flowrConfig.solver.resolveSource, localFromFileUrl, {
|
|
64
68
|
referenceChain: element.node.info.file ? [element.node.info.file] : [],
|
|
65
69
|
ctx: data.analyzer.inspectContext()
|
|
66
70
|
});
|
|
@@ -68,13 +72,55 @@ exports.FILE_PATH_VALIDITY = {
|
|
|
68
72
|
metadata.totalValid++;
|
|
69
73
|
return [];
|
|
70
74
|
}
|
|
75
|
+
return [{
|
|
76
|
+
involvedId: matchingRead.nodeId,
|
|
77
|
+
loc,
|
|
78
|
+
filePath: localFromFileUrl,
|
|
79
|
+
certainty: linter_format_1.LintingResultCertainty.Certain
|
|
80
|
+
}];
|
|
81
|
+
}
|
|
82
|
+
// handle remote URLs separately from file paths
|
|
83
|
+
if ((0, strings_1.isUrl)(matchingRead.value)) {
|
|
84
|
+
if (!config.checkUrls) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
const exists = await urlExists(matchingRead.value);
|
|
88
|
+
if (exists) {
|
|
89
|
+
metadata.totalValid++;
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
71
92
|
return [{
|
|
72
93
|
involvedId: matchingRead.nodeId,
|
|
73
94
|
loc,
|
|
74
95
|
filePath: matchingRead.value,
|
|
75
|
-
certainty:
|
|
96
|
+
certainty: linter_format_1.LintingResultCertainty.Uncertain
|
|
76
97
|
}];
|
|
77
|
-
}
|
|
98
|
+
}
|
|
99
|
+
// check if any write to the same file happens before the read, and exclude this case if so
|
|
100
|
+
const writesToFile = results.write.filter(r => samePath(r.value, matchingRead.value, data.analyzer.flowrConfig.solver.resolveSource?.ignoreCapitalization));
|
|
101
|
+
const writesBefore = writesToFile.map(w => (0, happens_before_1.happensBefore)(cfg, w.nodeId, element.node.info.id));
|
|
102
|
+
if (writesBefore.some(w => w === logic_1.Ternary.Always)) {
|
|
103
|
+
metadata.totalWritesBeforeAlways++;
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
// check if the file exists!
|
|
107
|
+
const paths = (0, built_in_source_1.findSource)(data.analyzer.flowrConfig.solver.resolveSource, matchingRead.value, {
|
|
108
|
+
referenceChain: element.node.info.file ? [element.node.info.file] : [],
|
|
109
|
+
ctx: data.analyzer.inspectContext()
|
|
110
|
+
});
|
|
111
|
+
if (paths && paths.length) {
|
|
112
|
+
metadata.totalValid++;
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
return [{
|
|
116
|
+
involvedId: matchingRead.nodeId,
|
|
117
|
+
loc,
|
|
118
|
+
filePath: matchingRead.value,
|
|
119
|
+
certainty: writesBefore && writesBefore.length && writesBefore.every(w => w === logic_1.Ternary.Maybe) ? linter_format_1.LintingResultCertainty.Uncertain : linter_format_1.LintingResultCertainty.Certain
|
|
120
|
+
}];
|
|
121
|
+
}));
|
|
122
|
+
return {
|
|
123
|
+
results: findings.flat(),
|
|
78
124
|
'.meta': metadata
|
|
79
125
|
};
|
|
80
126
|
},
|
|
@@ -87,7 +133,8 @@ exports.FILE_PATH_VALIDITY = {
|
|
|
87
133
|
defaultConfig: {
|
|
88
134
|
additionalReadFunctions: [],
|
|
89
135
|
additionalWriteFunctions: [],
|
|
90
|
-
includeUnknown: false
|
|
136
|
+
includeUnknown: false,
|
|
137
|
+
checkUrls: false
|
|
91
138
|
}
|
|
92
139
|
},
|
|
93
140
|
prettyPrint: {
|
|
@@ -84,7 +84,10 @@ function checkPipeInjection(nid, loc, name, sources) {
|
|
|
84
84
|
exports.PROBLEMATIC_INPUTS = {
|
|
85
85
|
createSearch: config => {
|
|
86
86
|
const toQ = (name, subkind) => ({ type: 'call-context', callName: name, callNameExact: false, subkind });
|
|
87
|
-
return flowr_search_builder_1.Q.fromQuery(
|
|
87
|
+
return flowr_search_builder_1.Q.fromQuery([
|
|
88
|
+
...normalizePatternList(config?.consider, defaultConsider).map((n, i) => toQ(n, `fn-${i}`)),
|
|
89
|
+
...normalizePipeSpecs(config?.pipeCommandFunctions).map((s, i) => toQ(s.pattern, `pipe-${i}`))
|
|
90
|
+
]);
|
|
88
91
|
},
|
|
89
92
|
processSearchResult: async (elements, config, data) => {
|
|
90
93
|
const results = [];
|