@eagleoutice/eslint-config-flowr 2.1.8 → 2.1.10
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 +11 -1
- package/index.js +2 -1
- package/package.json +1 -1
- package/pattern-type.d.ts +2 -0
- package/patterns.d.ts +1 -3
- package/patterns.js +488 -209
- package/rules/replacement-pattern.js +26 -7
- package/rules/ts-types.d.ts +7 -0
- package/rules/use-instead.js +26 -15
- package/rules/util.d.ts +13 -1
- package/rules/util.js +111 -6
package/README.md
CHANGED
|
@@ -72,6 +72,7 @@ To add one, append to [`patterns.ts`](patterns.ts):
|
|
|
72
72
|
| `replace` | the replacement, required. `{{name}}` is a capture's source text, `{{name\|last}}` keeps the part behind its last dot, turning `VertexType.Use` into `Use` |
|
|
73
73
|
| `capture` | name to a path relative to the match |
|
|
74
74
|
| `declaredIn` | path to a file the node's symbol must come from, so an unrelated `types` or `tag` does not match. The declaring file itself is exempt |
|
|
75
|
+
| `helperIn` | path to the file the replacement's helper lives in, for a shape without a flowR symbol to pin; in a program without that file the pattern stays silent |
|
|
75
76
|
| `sameText` | pairs of paths that must spell the same code, esquery has no back-references |
|
|
76
77
|
| `message` | what to tell the reader, filled from the captures like `replace` |
|
|
77
78
|
| `fix` | `true` always fixes, `false` always suggests, which is right when the replacement can change type narrowing. Omitted, it fixes when the replacement is in scope |
|
|
@@ -84,10 +85,16 @@ The shipped set groups into families:
|
|
|
84
85
|
| `edge-*` | `e.types === T`, `(e.types & T) !== 0`, and the bitmask spellings around them | `DfEdge` |
|
|
85
86
|
| `vertex-is*`, `vertex-has-origin` | `v.tag === VertexType.X`, `DfgVertex.isFunctionCall(v) && v.origin.includes(o)` | `DfgVertex` |
|
|
86
87
|
| `node-is*` | `n.type === RType.X`, negated and through `?.` | `RSymbol`, `RFunctionCall`, and the rest of the `R*` node objects |
|
|
87
|
-
| `argument-is-*`, `call-is-*`, `list-is-implicit` | a guard written out, `RFunctionCall.is(n) && n.named` | the narrower guard of the same object |
|
|
88
|
+
| `argument-is-*`, `call-is-*`, `list-is-implicit` | a guard written out, `RFunctionCall.is(n) && n.named`, `RFunctionCall.isNamed(c) && Identifier.getName(c.functionName.content) === 'f'` (also with a set's `has`, and negated) | the narrower guard of the same object, `RFunctionCall.isNamed(c, 'f')` |
|
|
88
89
|
| `symbol-name-comparison*` | `symbol.content === 'name'`, which misses `pkg::name` because an identifier with a namespace is an array | `Identifier.getName` / `Identifier.matches` |
|
|
89
90
|
| `graph-edges-from`, `graph-edges-to` | `g.outgoingEdges(id) ?? []` / `?? NoEdges`, a fallback the total accessors already are | `edgesFrom` / `edgesTo` |
|
|
90
91
|
| `location-range-hop`, `location-at-node`, `accessor-undefined-guard`, `identifier-tostring-fallback` | an unwrap, a positional destructure, or an absent-value guard in front of a reader that passes `undefined` through by itself | `SourceLocation`, `Identifier` |
|
|
92
|
+
| `node-lexeme*`, `node-own-lexeme*`, `node-range*`, `node-own-range*`, `range-*`, `node-id-recover-name` | `x.info.fullLexeme ?? x.lexeme`, `x.info.fullRange ?? x.location` (and the reverse orders), `range?.[0]`, `idMap.get(id)?.lexeme` | `RNode.lexeme`, `RNode.ownLexeme`, `SourceRange.fromNode`, `SourceRange.ownFromNode` and the range readers, `NodeId.recoverName` |
|
|
93
|
+
| `unpack-arg*`, `find-named-arg*`, `call-sole-argument`, `call-called-name*`, `callee-lexeme-comparison*` | argument and callee reads written out, `lexeme` compared against a name | `RArgument.valueOf`, `RArgument.findNamed`, `RFunctionCall.soleArgument`, `calledName`, `isNamed` |
|
|
94
|
+
| `vertex-origin-includes`, `vertex-lacks-origin`, `vertex-has-origin-array`, `vertex-name-comparison*` | origin lists read by hand, a call compared by its spelling | `DfgVertex.hasOrigin`, `Dataflow.qualify` |
|
|
95
|
+
| `edge-targets`, `edge-sources`, `edge-has-type-between`, `graph-vertices-of-type`, `environment-frames` | walks over edges, vertices and environment frames spelled out | `Dataflow.targetsOf`, `Dataflow.sourcesOf`, `Dataflow.hasEdge`, `verticesOfType`, `REnvironment.frames` |
|
|
96
|
+
| `built-in-id-*`, `to-built-in-*` | the `built-in:` prefix handled by hand | `NodeId.isBuiltIn`, `NodeId.toBuiltIn` |
|
|
97
|
+
| `remove-r-quotes`, `escape-regex`, `identifier-split`, `unique-array*`, `array-equal`, `sort-code-unit` | text, set and array chores with a helper | `RString.unquote`, `escapeRegex`, `Identifier.parse`, `uniqueArray`, `arrayEqual`, `compareByCodeUnit` |
|
|
91
98
|
| `some-instead-of-filter-length`, `array-sum` | a full walk where a helper does it once | `some`, `arraySum` |
|
|
92
99
|
|
|
93
100
|
A pattern is exempt in the file `declaredIn` resolves to, which is why a shape only earns a place here when the
|
|
@@ -95,6 +102,9 @@ match names a flowR symbol: without one the rule cannot tell the helper's own bo
|
|
|
95
102
|
`@lintIgnore` on the declaration would be papering over that. A guard that *is* the raw comparison
|
|
96
103
|
(`RSymbol.is` compares `type` against `RType.Symbol`) is the case the tag is actually for.
|
|
97
104
|
|
|
105
|
+
A match inside a function named like the one the replacement calls is never reported either: that is the helper's
|
|
106
|
+
own body (`escapeRegex` spelling out the class it escapes), where the fix would make the helper call itself.
|
|
107
|
+
|
|
98
108
|
An own `patterns` array replaces the defaults rather than merging with them. To propose one, open an issue with the
|
|
99
109
|
[replacement pattern template](.github/ISSUE_TEMPLATE/replacement-pattern.yaml).
|
|
100
110
|
|
package/index.js
CHANGED
|
@@ -55,7 +55,8 @@ const config = [
|
|
|
55
55
|
* so it would force every consumer to strip it again before bundling. */
|
|
56
56
|
'no-restricted-imports': ['error', {
|
|
57
57
|
patterns: [{
|
|
58
|
-
|
|
58
|
+
/* `node:test` has no bare name */
|
|
59
|
+
group: ['node:*', 'node:*/*', '!node:test'],
|
|
59
60
|
message: 'Import the bare module (`path`, not `node:path`) so a bundler can swap it for a browser polyfill.'
|
|
60
61
|
}]
|
|
61
62
|
}],
|
package/package.json
CHANGED
package/pattern-type.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface ReplacementPattern {
|
|
|
11
11
|
readonly replace: string;
|
|
12
12
|
/** path to a substring of the file its symbol must be declared in */
|
|
13
13
|
readonly declaredIn?: Readonly<Record<string, string>>;
|
|
14
|
+
/** path to a substring of the file the replacement's helper lives in; without that file in the program the pattern stays silent */
|
|
15
|
+
readonly helperIn?: string;
|
|
14
16
|
/** pairs of paths that have to spell the same code */
|
|
15
17
|
readonly sameText?: readonly (readonly string[])[];
|
|
16
18
|
/** `true` forces the autofix, `false` forces a suggestion */
|
package/patterns.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Default patterns of `flowr/replacement-pattern`, see the README for the format.
|
|
3
|
-
* The helpers they point at live in flowR
|
|
4
|
-
* `dataflow/graph/vertex`, `NoEdges` in `dataflow/graph/graph`, the `RNode` helpers in
|
|
5
|
-
* `r-bridge/lang-4.x/ast/model`, and the collection helpers in `util/collections`.
|
|
3
|
+
* The helpers they point at live in flowR, the paths below are the files declaring them.
|
|
6
4
|
*/
|
|
7
5
|
import type { ReplacementPattern } from './pattern-type';
|
|
8
6
|
declare const patterns: readonly ReplacementPattern[];
|