@platform-sec/eslint-plugin-sensitive-string 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +193 -2
- package/dist/ast.d.ts +172 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +418 -0
- package/dist/ast.js.map +1 -0
- package/dist/configs.d.ts +38 -0
- package/dist/configs.d.ts.map +1 -0
- package/dist/configs.js +131 -0
- package/dist/configs.js.map +1 -0
- package/dist/docs.d.ts +28 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +33 -0
- package/dist/docs.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/log-calls.d.ts +28 -0
- package/dist/log-calls.d.ts.map +1 -0
- package/dist/log-calls.js +80 -0
- package/dist/log-calls.js.map +1 -0
- package/dist/options.d.ts +32 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +56 -0
- package/dist/options.js.map +1 -0
- package/dist/rules/explicit-class.d.ts +3 -0
- package/dist/rules/explicit-class.d.ts.map +1 -0
- package/dist/rules/explicit-class.js +93 -0
- package/dist/rules/explicit-class.js.map +1 -0
- package/dist/rules/no-allow-unaudited.d.ts +3 -0
- package/dist/rules/no-allow-unaudited.d.ts.map +1 -0
- package/dist/rules/no-allow-unaudited.js +92 -0
- package/dist/rules/no-allow-unaudited.js.map +1 -0
- package/dist/rules/no-credential-equality.d.ts +3 -0
- package/dist/rules/no-credential-equality.d.ts.map +1 -0
- package/dist/rules/no-credential-equality.js +146 -0
- package/dist/rules/no-credential-equality.js.map +1 -0
- package/dist/rules/no-log-reveal.d.ts +3 -0
- package/dist/rules/no-log-reveal.d.ts.map +1 -0
- package/dist/rules/no-log-reveal.js +67 -0
- package/dist/rules/no-log-reveal.js.map +1 -0
- package/dist/rules/no-network-sensitive.d.ts +3 -0
- package/dist/rules/no-network-sensitive.d.ts.map +1 -0
- package/dist/rules/no-network-sensitive.js +106 -0
- package/dist/rules/no-network-sensitive.js.map +1 -0
- package/dist/rules/no-password-fast-hash.d.ts +3 -0
- package/dist/rules/no-password-fast-hash.d.ts.map +1 -0
- package/dist/rules/no-password-fast-hash.js +84 -0
- package/dist/rules/no-password-fast-hash.js.map +1 -0
- package/dist/rules/no-stringify-sensitive.d.ts +3 -0
- package/dist/rules/no-stringify-sensitive.d.ts.map +1 -0
- package/dist/rules/no-stringify-sensitive.js +96 -0
- package/dist/rules/no-stringify-sensitive.js.map +1 -0
- package/dist/rules/prefer-safe-log.d.ts +3 -0
- package/dist/rules/prefer-safe-log.d.ts.map +1 -0
- package/dist/rules/prefer-safe-log.js +85 -0
- package/dist/rules/prefer-safe-log.js.map +1 -0
- package/dist/rules/require-reveal-context.d.ts +3 -0
- package/dist/rules/require-reveal-context.d.ts.map +1 -0
- package/dist/rules/require-reveal-context.js +149 -0
- package/dist/rules/require-reveal-context.js.map +1 -0
- package/dist/type-info.d.ts +134 -0
- package/dist/type-info.d.ts.map +1 -0
- package/dist/type-info.js +282 -0
- package/dist/type-info.js.map +1 -0
- package/dist/types.d.ts +137 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/docs/rules/explicit-class.md +62 -0
- package/docs/rules/no-allow-unaudited.md +93 -0
- package/docs/rules/no-credential-equality.md +69 -0
- package/docs/rules/no-log-reveal.md +104 -0
- package/docs/rules/no-network-sensitive.md +74 -0
- package/docs/rules/no-password-fast-hash.md +95 -0
- package/docs/rules/no-stringify-sensitive.md +144 -0
- package/docs/rules/prefer-safe-log.md +131 -0
- package/docs/rules/require-reveal-context.md +128 -0
- package/package.json +49 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 AppSec Science, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,194 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @platform-sec/eslint-plugin-sensitive-string
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lint rules for the mistakes
|
|
4
|
+
[`@platform-sec/sensitive-string-core`](../sensitive-core)'s type system cannot
|
|
5
|
+
catch.
|
|
6
|
+
|
|
7
|
+
A type keeps a secret wrapped. It cannot stop `console.log(secret.reveal())`,
|
|
8
|
+
because the reveal produces an ordinary string and logging a string is ordinary
|
|
9
|
+
code. The same goes for `password.reveal() === input`, which type-checks
|
|
10
|
+
perfectly and leaks the password to a timing attack. Nine rules read the call
|
|
11
|
+
instead: seven from its shape alone, two from the types of its arguments.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add -D @platform-sec/eslint-plugin-sensitive-string
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
ESLint 8.40 or newer is a peer dependency, and nothing else is. The seven
|
|
20
|
+
untyped rules work from the syntax alone, so they run under any parser and cost
|
|
21
|
+
nothing beyond the parse.
|
|
22
|
+
|
|
23
|
+
The other two ask what a value's type *contains*, which no syntax answers, so
|
|
24
|
+
they need a TypeScript program: `@typescript-eslint/parser` with `project` or
|
|
25
|
+
`projectService` set. They live only in the `-type-checked` presets, so a
|
|
26
|
+
project that has not configured one never meets them.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
Flat config, `eslint.config.js`:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import sensitive from '@platform-sec/eslint-plugin-sensitive-string';
|
|
34
|
+
|
|
35
|
+
export default [sensitive.configs.recommended];
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
eslintrc, `.eslintrc.cjs`:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
module.exports = {
|
|
42
|
+
extends: ['plugin:@platform-sec/sensitive-string/legacy-recommended'],
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or set rules individually:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
{
|
|
50
|
+
plugins: { '@platform-sec/sensitive-string': sensitive },
|
|
51
|
+
rules: {
|
|
52
|
+
'@platform-sec/sensitive-string/no-log-reveal': 'error',
|
|
53
|
+
'@platform-sec/sensitive-string/no-credential-equality': 'error',
|
|
54
|
+
'@platform-sec/sensitive-string/no-network-sensitive': 'error',
|
|
55
|
+
'@platform-sec/sensitive-string/explicit-class': 'warn',
|
|
56
|
+
'@platform-sec/sensitive-string/require-reveal-context': 'warn',
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Those six are the untyped rules. `no-stringify-sensitive` and `prefer-safe-log`
|
|
62
|
+
are set the same way, under a config that gives them a program: see
|
|
63
|
+
[Type-aware linting](#type-aware-linting).
|
|
64
|
+
|
|
65
|
+
The plugin's package name is `eslint-plugin-sensitive-string` under the
|
|
66
|
+
`@platform-sec` scope, so ESLint addresses it as
|
|
67
|
+
`@platform-sec/sensitive-string`.
|
|
68
|
+
|
|
69
|
+
## Rules
|
|
70
|
+
|
|
71
|
+
Syntax only, in `recommended`:
|
|
72
|
+
|
|
73
|
+
| Rule | `recommended` | Catches |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| [no-log-reveal](docs/rules/no-log-reveal.md) | error | `console.log(x.reveal())`, `logger.info({ k: x.reveal() })` |
|
|
76
|
+
| [no-credential-equality](docs/rules/no-credential-equality.md) | error | `x.reveal() === y`, `switch (x.reveal())` |
|
|
77
|
+
| [no-network-sensitive](docs/rules/no-network-sensitive.md) | error | `fetch(url, { body: x.reveal() })` |
|
|
78
|
+
| [explicit-class](docs/rules/explicit-class.md) | warn | `new SensitiveString(v)` with no class |
|
|
79
|
+
| [require-reveal-context](docs/rules/require-reveal-context.md) | warn | `x.reveal()` with no context and no enclosing `withRevealContext`, and the same for `mask()`, `hash()`, `hmac()` and `serialize()` where types are available |
|
|
80
|
+
| [no-password-fast-hash](docs/rules/no-password-fast-hash.md) | warn | `password.hash('sha256')`, a fast digest where a KDF belongs |
|
|
81
|
+
| [no-allow-unaudited](docs/rules/no-allow-unaudited.md) | error | `fromWorkerPayload(d, { allowUnaudited: true })`, which drops an audit hook the sender asked for |
|
|
82
|
+
|
|
83
|
+
Type-aware, in `recommended-type-checked` only:
|
|
84
|
+
|
|
85
|
+
| Rule | `recommended-type-checked` | Catches |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| [no-stringify-sensitive](docs/rules/no-stringify-sensitive.md) | error | `JSON.stringify(payload)` where `payload` holds a `SensitiveString` or a `serialize()` result |
|
|
88
|
+
| [prefer-safe-log](docs/rules/prefer-safe-log.md) | warn | `console.log(user)` where `user` holds one |
|
|
89
|
+
|
|
90
|
+
## Presets
|
|
91
|
+
|
|
92
|
+
| Preset | Format | Rules |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `configs.recommended` | flat | the seven untyped |
|
|
95
|
+
| `configs.strict` | flat | the seven untyped, harder |
|
|
96
|
+
| `configs['recommended-type-checked']` | flat | all nine |
|
|
97
|
+
| `configs['strict-type-checked']` | flat | all nine, harder |
|
|
98
|
+
| `configs['disable-type-checked']` | flat | turns the two type-aware rules off |
|
|
99
|
+
| `configs['legacy-recommended']` | eslintrc | the seven untyped |
|
|
100
|
+
| `configs['legacy-strict']` | eslintrc | the seven untyped, harder |
|
|
101
|
+
| `configs['legacy-recommended-type-checked']` | eslintrc | all nine |
|
|
102
|
+
| `configs['legacy-strict-type-checked']` | eslintrc | all nine, harder |
|
|
103
|
+
| `configs['legacy-disable-type-checked']` | eslintrc | turns the two type-aware rules off |
|
|
104
|
+
|
|
105
|
+
Both formats configure the same rules at the same severities, and a test holds
|
|
106
|
+
them to it.
|
|
107
|
+
|
|
108
|
+
`recommended` errors on the three rules that catch a value escaping, and on
|
|
109
|
+
`no-allow-unaudited`, which catches an audit control being switched off and is
|
|
110
|
+
never wrong about it. It warns on the three that reason about something they
|
|
111
|
+
cannot see: a context installed in a caller, a class supplied through a spread,
|
|
112
|
+
and a password recognised by what the variable holding it is called. A warning
|
|
113
|
+
is the honest severity for a check that can be wrong.
|
|
114
|
+
|
|
115
|
+
`strict` raises everything to error, requires a `reason` in every reveal
|
|
116
|
+
context, and sets `allowWithContext: false` on `no-network-sensitive`, so the
|
|
117
|
+
only way a value leaves the process is `serialize()`.
|
|
118
|
+
|
|
119
|
+
## Type-aware linting
|
|
120
|
+
|
|
121
|
+
The `-type-checked` presets add `no-stringify-sensitive` and `prefer-safe-log`
|
|
122
|
+
to their untyped namesakes. Both need a `ts.Program`:
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
import sensitive from '@platform-sec/eslint-plugin-sensitive-string';
|
|
126
|
+
import tseslint from 'typescript-eslint';
|
|
127
|
+
|
|
128
|
+
export default [
|
|
129
|
+
{
|
|
130
|
+
files: ['**/*.ts'],
|
|
131
|
+
languageOptions: {
|
|
132
|
+
parser: tseslint.parser,
|
|
133
|
+
parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname },
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
sensitive.configs['recommended-type-checked'],
|
|
137
|
+
// Files no tsconfig.json covers have no types to read.
|
|
138
|
+
{ files: ['**/*.js'], ...sensitive.configs['disable-type-checked'] },
|
|
139
|
+
];
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Applied to a file with no program, both rules report that fact once, on the
|
|
143
|
+
file, rather than falling silent. Silence would be the worse failure: a rule
|
|
144
|
+
that reports nothing looks exactly like a rule that found nothing, and these
|
|
145
|
+
two get read as "no sensitive value is being stringified or logged here".
|
|
146
|
+
`disable-type-checked` is what turns them off where that is expected.
|
|
147
|
+
|
|
148
|
+
`require-reveal-context` is a third case: it works without a program and uses
|
|
149
|
+
one when it is there. `reveal()` is matched by name in every configuration;
|
|
150
|
+
`mask()`, `hash()`, `hmac()` and `serialize()` are checked only where the
|
|
151
|
+
receiver's type can be read, because `bcrypt` and `node:crypto` have a `hash`,
|
|
152
|
+
every ORM has a `serialize`, and a rule that reported those would be turned off
|
|
153
|
+
within the hour. It stays enabled under `disable-type-checked`, where it does
|
|
154
|
+
the half of its job that needs no types.
|
|
155
|
+
|
|
156
|
+
## Suggestions, not fixes
|
|
157
|
+
|
|
158
|
+
No rule here is auto-fixable. Two offer editor suggestions, which a person
|
|
159
|
+
accepts one at a time:
|
|
160
|
+
|
|
161
|
+
- `no-credential-equality` rewrites `a.reveal() === b` to `a.equals(b)`,
|
|
162
|
+
carrying any reveal context across into `equals()`'s second parameter.
|
|
163
|
+
- `explicit-class` offers each sensitivity class.
|
|
164
|
+
|
|
165
|
+
`--fix` rewrites files with nobody reading the diff, and every rewrite these
|
|
166
|
+
rules would make changes behaviour: `equals()` can throw where `reveal()` did
|
|
167
|
+
not, and a sensitivity class cannot be guessed from syntax at all.
|
|
168
|
+
|
|
169
|
+
## Precision
|
|
170
|
+
|
|
171
|
+
Every rule that asks for an argument treats an explicit `undefined` as the
|
|
172
|
+
absence of one: `reveal(undefined)` and `new SensitiveString(v, undefined)`
|
|
173
|
+
satisfy a signature and decide nothing, so accepting them would make passing
|
|
174
|
+
`undefined` the shortest way to silence a rule while looking like compliance
|
|
175
|
+
with it.
|
|
176
|
+
|
|
177
|
+
Beyond that, every rule has a shape it cannot see and a shape it reports too
|
|
178
|
+
eagerly. Each rule's documentation ends with a "Known limits" section saying
|
|
179
|
+
which. Three general points:
|
|
180
|
+
|
|
181
|
+
- **A logger or HTTP client under an unfamiliar name is invisible.** Every rule
|
|
182
|
+
that matches one takes an option naming the ones a project uses.
|
|
183
|
+
- **A value revealed into a variable and used later is not tracked.** Reveal at
|
|
184
|
+
the point of use, which is better practice anyway: it keeps the raw string's
|
|
185
|
+
lifetime as short as the library can make it.
|
|
186
|
+
- **The two type-aware rules match a type by its name**, so anything called
|
|
187
|
+
`SensitiveString` counts and a project's own wrapper does not until
|
|
188
|
+
`sensitiveTypes` names it. Resolving the declaration back to this library
|
|
189
|
+
would be more precise and would break under bundlers, path aliases and
|
|
190
|
+
re-exports.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|
package/dist/ast.d.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser-agnostic AST access.
|
|
3
|
+
*
|
|
4
|
+
* Every rule in this plugin reduces to two questions: "is this call a call to
|
|
5
|
+
* something I care about" and "does this expression contain a `.reveal()`
|
|
6
|
+
* anywhere inside it". Both are answered here, once, so a gap fixed for one
|
|
7
|
+
* rule is fixed for all of them.
|
|
8
|
+
*/
|
|
9
|
+
import type { AstNode, RuleContext, SourceCode } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* The method that hands out the raw value.
|
|
12
|
+
*
|
|
13
|
+
* Every rule keys off this name. It is a method name rather than a type, which
|
|
14
|
+
* is the whole tradeoff of an untyped rule: `magician.reveal()` looks the same
|
|
15
|
+
* as `apiKey.reveal()` to a parser. The rules that can narrow further (by
|
|
16
|
+
* requiring a log call or a network call around it) do; the ones that cannot
|
|
17
|
+
* say so in their documentation.
|
|
18
|
+
*/
|
|
19
|
+
export declare const REVEAL_METHOD = "reveal";
|
|
20
|
+
/**
|
|
21
|
+
* The expression inside any number of value-preserving wrappers.
|
|
22
|
+
*
|
|
23
|
+
* Idempotent and safe on a cyclic-looking tree: it only ever descends, and each
|
|
24
|
+
* step moves strictly inward.
|
|
25
|
+
*/
|
|
26
|
+
export declare function unwrap(node: AstNode): AstNode;
|
|
27
|
+
/** An `Identifier`'s name, or `undefined` for any other node. */
|
|
28
|
+
export declare function identifierName(node: AstNode): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The property name a member expression reads, when it is knowable statically.
|
|
31
|
+
*
|
|
32
|
+
* `x.reveal` and `x['reveal']` name the same method and both resolve here;
|
|
33
|
+
* `x[key]` does not, and yields `undefined` rather than a guess. Handling the
|
|
34
|
+
* computed-string form matters because it is the shortest way to write a call
|
|
35
|
+
* that a name-matching rule would otherwise miss.
|
|
36
|
+
*/
|
|
37
|
+
export declare function staticPropertyName(member: AstNode): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The property name an object-literal entry defines, when it is knowable
|
|
40
|
+
* statically. `{ reason: r }` and `{ 'reason': r }` both resolve; `{ [k]: r }`
|
|
41
|
+
* does not.
|
|
42
|
+
*/
|
|
43
|
+
export declare function staticKeyName(property: AstNode): string | undefined;
|
|
44
|
+
/** A `Literal`'s value when it is a string, otherwise `undefined`. */
|
|
45
|
+
export declare function literalString(node: AstNode): string | undefined;
|
|
46
|
+
/** An object expression's entries, or an empty list for any other node. */
|
|
47
|
+
export declare function objectProperties(node: AstNode): readonly AstNode[];
|
|
48
|
+
/** A binary or unary expression's operator, or `undefined` for any other node. */
|
|
49
|
+
export declare function operatorOf(node: AstNode): string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* A binary expression's operands, or `undefined` if it has none.
|
|
52
|
+
*
|
|
53
|
+
* Returned exactly as written, not unwrapped. Detection does not need them
|
|
54
|
+
* unwrapped, because {@link asMethodCall} unwraps whatever it is handed, while
|
|
55
|
+
* a rule that quotes an operand back into a suggestion does need the text the
|
|
56
|
+
* author wrote: unwrapping first would silently drop a cast from the rewrite.
|
|
57
|
+
*/
|
|
58
|
+
export declare function operandsOf(node: AstNode): {
|
|
59
|
+
readonly left: AstNode;
|
|
60
|
+
readonly right: AstNode;
|
|
61
|
+
} | undefined;
|
|
62
|
+
/** A switch statement's discriminant, as written, or `undefined`. */
|
|
63
|
+
export declare function discriminantOf(node: AstNode): AstNode | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Whether an argument is an explicit `undefined`, written either way.
|
|
66
|
+
*
|
|
67
|
+
* `reveal(undefined)` and `new SensitiveString(v, undefined)` satisfy a
|
|
68
|
+
* signature without deciding anything, so every rule that asks for an argument
|
|
69
|
+
* has to treat them as the absence of one. Otherwise the shortest way to
|
|
70
|
+
* silence any of those rules is to pass `undefined`, which reads like
|
|
71
|
+
* compliance and is not.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isExplicitUndefined(node: AstNode): boolean;
|
|
74
|
+
/** Whether a node is a spread, in either the ESTree or the legacy spelling. */
|
|
75
|
+
export declare function isSpread(node: AstNode): boolean;
|
|
76
|
+
/** A call expression's arguments, or an empty list for any other node. */
|
|
77
|
+
export declare function callArguments(node: AstNode): readonly AstNode[];
|
|
78
|
+
/** A call or `new` expression's callee, unwrapped, or `undefined`. */
|
|
79
|
+
export declare function calleeOf(node: AstNode): AstNode | undefined;
|
|
80
|
+
/** Whether any argument is a spread, which makes the argument count unknowable. */
|
|
81
|
+
export declare function hasSpreadArgument(node: AstNode): boolean;
|
|
82
|
+
/** A call whose callee reads a named method off some receiver. */
|
|
83
|
+
export interface MethodCall {
|
|
84
|
+
/** The `CallExpression`, already unwrapped. */
|
|
85
|
+
readonly call: AstNode;
|
|
86
|
+
/** The `MemberExpression` in callee position, already unwrapped. */
|
|
87
|
+
readonly callee: AstNode;
|
|
88
|
+
/** The receiver the method was read from: the `x` of `x.reveal()`. */
|
|
89
|
+
readonly receiver: AstNode;
|
|
90
|
+
/** The method name, resolved through a computed string key when needed. */
|
|
91
|
+
readonly method: string;
|
|
92
|
+
/** Whether any link in the callee is optional, as in `x?.reveal()`. */
|
|
93
|
+
readonly optional: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A node read as a method call, or `undefined` if it is not one.
|
|
97
|
+
*
|
|
98
|
+
* `optional` is reported rather than ignored so a rule that rewrites code can
|
|
99
|
+
* decline to: `x?.reveal() === y` and `x?.equals(y)` differ when `x` is nullish
|
|
100
|
+
* (`false` against `undefined`), and a suggestion is not the place to change
|
|
101
|
+
* that.
|
|
102
|
+
*/
|
|
103
|
+
export declare function asMethodCall(node: AstNode): MethodCall | undefined;
|
|
104
|
+
/** Whether a node is a call to one of `methods` on some receiver. */
|
|
105
|
+
export declare function isMethodCallNamed(node: AstNode, methods: ReadonlySet<string>): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Every identifier and static property name along a callee chain.
|
|
108
|
+
*
|
|
109
|
+
* `console.log` yields `['log', 'console']`, `this.logger.info` yields
|
|
110
|
+
* `['info', 'logger']`, and `logger.child({ req }).info` yields
|
|
111
|
+
* `['info', 'child', 'logger']`. Matching against the whole chain rather than
|
|
112
|
+
* against a leading identifier is what lets a rule recognise the ways a logger
|
|
113
|
+
* or an HTTP client is actually reached: as a field of `this`, as a property of
|
|
114
|
+
* a request, or through a builder call.
|
|
115
|
+
*
|
|
116
|
+
* A link whose name is not statically knowable is stepped over rather than
|
|
117
|
+
* stopped at: `handlers[i].logger.info` still yields `['info', 'logger']`, so an
|
|
118
|
+
* index into a collection does not hide the object behind it. The walk ends at
|
|
119
|
+
* the first node that is neither a member access nor a call, which is an
|
|
120
|
+
* identifier (collected) or `this` (not).
|
|
121
|
+
*/
|
|
122
|
+
export declare function calleeChainNames(callee: AstNode): readonly string[];
|
|
123
|
+
/**
|
|
124
|
+
* The `SourceCode` for the file being linted, across ESLint majors.
|
|
125
|
+
*
|
|
126
|
+
* ESLint 9 exposes it as a property and removed the getter; ESLint 8 has the
|
|
127
|
+
* getter from the start and gained the property in 8.40.
|
|
128
|
+
*/
|
|
129
|
+
export declare function getSourceCode(context: RuleContext): SourceCode | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* The ancestors of the node being visited, outermost first, across ESLint
|
|
132
|
+
* majors.
|
|
133
|
+
*
|
|
134
|
+
* ESLint 9 moved the call from the context onto `SourceCode` and made it take
|
|
135
|
+
* the node. The `SourceCode` form is tried first because ESLint 8.40, the
|
|
136
|
+
* oldest release this plugin supports, has both and warns on every use of the
|
|
137
|
+
* older one; a lint rule that prints a deprecation notice on each run is a rule
|
|
138
|
+
* people turn off.
|
|
139
|
+
*/
|
|
140
|
+
export declare function getAncestors(context: RuleContext, node: AstNode): readonly AstNode[];
|
|
141
|
+
/**
|
|
142
|
+
* The children of a node, according to the parser that produced it.
|
|
143
|
+
*
|
|
144
|
+
* The `visitorKeys` map is the parser's own answer, so a TypeScript-only or
|
|
145
|
+
* JSX-only field is followed without this package listing it.
|
|
146
|
+
*
|
|
147
|
+
* The fallback enumerates the node's own fields, and it runs both when the
|
|
148
|
+
* parser supplies no keys at all and when it supplies keys that say nothing
|
|
149
|
+
* about *this* node type. The second case is the one that matters: a custom
|
|
150
|
+
* parser or a syntax plugin can produce a node the map does not describe, and
|
|
151
|
+
* pruning that subtree would silently stop the search inside it. Enumerating is
|
|
152
|
+
* the safe direction to be wrong in. `parent` is excluded because following it
|
|
153
|
+
* would walk back up the tree and never terminate.
|
|
154
|
+
*/
|
|
155
|
+
export declare function childNodes(node: AstNode, visitorKeys: Readonly<Record<string, readonly string[]>> | undefined): readonly AstNode[];
|
|
156
|
+
/**
|
|
157
|
+
* Every call to one of `methods` inside `root`, `root` itself included, in
|
|
158
|
+
* source order.
|
|
159
|
+
*
|
|
160
|
+
* The search descends through everything, including function bodies. That is
|
|
161
|
+
* deliberate: `console.log(ids.map((id) => id.reveal()))` leaks exactly as much
|
|
162
|
+
* as `console.log(id.reveal())` does, and a callback is the ordinary way to
|
|
163
|
+
* write it. The cost is that logging a function that is never called, as in
|
|
164
|
+
* `console.log(() => secret.reveal())`, is reported too. Reporting an unused
|
|
165
|
+
* closure is a nuisance; missing a `map` over a list of secrets is a leak.
|
|
166
|
+
*
|
|
167
|
+
* A match does not end the descent into that node: `a.reveal().concat(b.reveal())`
|
|
168
|
+
* reports both. Each node is visited once, so the walk is linear in the size of
|
|
169
|
+
* the subtree.
|
|
170
|
+
*/
|
|
171
|
+
export declare function findMethodCalls(root: AstNode, methods: ReadonlySet<string>, visitorKeys: Readonly<Record<string, readonly string[]>> | undefined): readonly AstNode[];
|
|
172
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEnE;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,WAAW,CAAC;AAqDtC;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAU7C;AAED,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMhE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAWtE;AAED;;;;GAIG;AACH,wBAAgB,a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