Spaces:
Paused
Paused
Upload folder using huggingface_hub (part 10)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- node_modules/eslint-config-flat-gitignore/LICENSE +21 -0
- node_modules/eslint-config-flat-gitignore/README.md +113 -0
- node_modules/eslint-config-flat-gitignore/package.json +67 -0
- node_modules/eslint-config-prettier/LICENSE +21 -0
- node_modules/eslint-config-prettier/README.md +928 -0
- node_modules/eslint-config-prettier/bin/cli.js +240 -0
- node_modules/eslint-config-prettier/bin/validators.js +86 -0
- node_modules/eslint-config-prettier/flat.d.ts +7 -0
- node_modules/eslint-config-prettier/flat.js +6 -0
- node_modules/eslint-config-prettier/index.d.ts +5 -0
- node_modules/eslint-config-prettier/index.js +395 -0
- node_modules/eslint-config-prettier/package.json +51 -0
- node_modules/eslint-config-prettier/prettier.d.ts +1 -0
- node_modules/eslint-config-prettier/prettier.js +10 -0
- node_modules/eslint-plugin-prettier/LICENSE.md +24 -0
- node_modules/eslint-plugin-prettier/README.md +199 -0
- node_modules/eslint-plugin-prettier/eslint-plugin-prettier.d.ts +5 -0
- node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js +306 -0
- node_modules/eslint-plugin-prettier/package.json +60 -0
- node_modules/eslint-plugin-prettier/recommended.d.ts +12 -0
- node_modules/eslint-plugin-prettier/recommended.js +18 -0
- node_modules/eslint-plugin-prettier/worker.mjs +187 -0
- node_modules/eslint-scope/LICENSE +22 -0
- node_modules/eslint-scope/README.md +207 -0
- node_modules/eslint-scope/lib/assert.js +17 -0
- node_modules/eslint-scope/lib/definition.js +85 -0
- node_modules/eslint-scope/lib/index.d.cts +1152 -0
- node_modules/eslint-scope/lib/index.d.ts +6 -0
- node_modules/eslint-scope/lib/index.js +175 -0
- node_modules/eslint-scope/lib/pattern-visitor.js +157 -0
- node_modules/eslint-scope/lib/reference.js +173 -0
- node_modules/eslint-scope/lib/referencer.js +817 -0
- node_modules/eslint-scope/lib/scope-manager.js +298 -0
- node_modules/eslint-scope/lib/scope.js +852 -0
- node_modules/eslint-scope/lib/variable.js +90 -0
- node_modules/eslint-scope/package.json +66 -0
- node_modules/eslint-visitor-keys/LICENSE +201 -0
- node_modules/eslint-visitor-keys/README.md +123 -0
- node_modules/eslint-visitor-keys/lib/index.js +67 -0
- node_modules/eslint-visitor-keys/lib/visitor-keys.js +118 -0
- node_modules/eslint-visitor-keys/package.json +57 -0
- node_modules/eslint/lib/rules/space-in-parens.js +374 -0
- node_modules/eslint/lib/rules/space-infix-ops.js +249 -0
- node_modules/eslint/lib/rules/space-unary-ops.js +400 -0
- node_modules/eslint/lib/rules/spaced-comment.js +447 -0
- node_modules/eslint/lib/rules/strict.js +324 -0
- node_modules/eslint/lib/rules/switch-colon-spacing.js +158 -0
- node_modules/eslint/lib/rules/symbol-description.js +70 -0
- node_modules/eslint/lib/rules/template-curly-spacing.js +168 -0
.gitattributes
CHANGED
|
@@ -39,3 +39,4 @@ node_modules/bare-url/prebuilds/linux-x64/bare-url.bare filter=lfs diff=lfs merg
|
|
| 39 |
node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
|
| 40 |
node_modules/bare-url/prebuilds/win32-x64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
|
| 41 |
node_modules/better-sqlite3/build/Release/better_sqlite3.node filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 39 |
node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
|
| 40 |
node_modules/bare-url/prebuilds/win32-x64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
|
| 41 |
node_modules/better-sqlite3/build/Release/better_sqlite3.node filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
node_modules/exif-parser/test/starfish.jpg filter=lfs diff=lfs merge=lfs -text
|
node_modules/eslint-config-flat-gitignore/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2022 Anthony Fu <https://github.com/antfu>
|
| 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.
|
node_modules/eslint-config-flat-gitignore/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# eslint-config-flat-gitignore
|
| 2 |
+
|
| 3 |
+
[![npm version][npm-version-src]][npm-version-href]
|
| 4 |
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
| 5 |
+
[![bundle][bundle-src]][bundle-href]
|
| 6 |
+
[![JSDocs][jsdocs-src]][jsdocs-href]
|
| 7 |
+
[![License][license-src]][license-href]
|
| 8 |
+
|
| 9 |
+
`.gitignore` support for [ESLint Flat Config](https://eslint.org/docs/latest/use/configure/configuration-files-new).
|
| 10 |
+
|
| 11 |
+
## Usage
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
npm i -D eslint-config-flat-gitignore
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
```js
|
| 18 |
+
// eslint.config.js
|
| 19 |
+
import gitignore from 'eslint-config-flat-gitignore'
|
| 20 |
+
|
| 21 |
+
export default [
|
| 22 |
+
// recommended putting it at the first
|
| 23 |
+
gitignore(),
|
| 24 |
+
// your other configs here
|
| 25 |
+
]
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
By default it will only looks for `.gitignore` but NOT `.eslintignore`, as we would recommended move away from `.eslintignore` to declare directly in `eslint.config.js` for single source of truth. If you still want it, you can pass the `files` option to specify the files to look for.
|
| 29 |
+
|
| 30 |
+
```js
|
| 31 |
+
gitignore({
|
| 32 |
+
files: [
|
| 33 |
+
'.gitignore',
|
| 34 |
+
'.eslintignore',
|
| 35 |
+
]
|
| 36 |
+
})
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
By default, this plugin throws if any of the ignore files are missing. This can be disabled by passing setting the `strict` option to `false`.
|
| 40 |
+
|
| 41 |
+
```js
|
| 42 |
+
gitignore({
|
| 43 |
+
files: [
|
| 44 |
+
'.gitignore',
|
| 45 |
+
'.eslintignore',
|
| 46 |
+
],
|
| 47 |
+
strict: false,
|
| 48 |
+
})
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
By default, this plugin will try to look up the directory tree and match the first `.gitignore` file. You can disable this by setting the `root` option to `true`, or specify the `files` option to a specific path.
|
| 52 |
+
|
| 53 |
+
```js
|
| 54 |
+
gitignore({
|
| 55 |
+
root: true
|
| 56 |
+
})
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
If you want to include recursive `.gitignore` files (for example in monorepos), enable the `recursive` option.
|
| 60 |
+
|
| 61 |
+
```js
|
| 62 |
+
gitignore({
|
| 63 |
+
recursive: true,
|
| 64 |
+
})
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
If you want recursive discovery but need to skip specific directory names, pass an object to `recursive` with `skipDirs`.
|
| 68 |
+
|
| 69 |
+
```js
|
| 70 |
+
gitignore({
|
| 71 |
+
recursive: {
|
| 72 |
+
// Skip any directory with this name at any depth
|
| 73 |
+
skipDirs: ['dist', 'coverage'],
|
| 74 |
+
},
|
| 75 |
+
})
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
`skipDirs` matches directory names (not paths) and applies in addition to the built-in skipped directories: `.git` and `node_modules`.
|
| 79 |
+
|
| 80 |
+
This plugin will also automatically detect git submodule file `.gitmodules` and ignore all files under the submodule dirs. If you want to disable or customize this behavior, you can pass the `filesGitModules` option.
|
| 81 |
+
|
| 82 |
+
<!-- eslint-skip -->
|
| 83 |
+
```js
|
| 84 |
+
gitignore({
|
| 85 |
+
filesGitModules: [], // disable
|
| 86 |
+
filesGitModules: ['path/to/.gitmodules'], // customize
|
| 87 |
+
})
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## Sponsors
|
| 91 |
+
|
| 92 |
+
<p align="center">
|
| 93 |
+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
| 94 |
+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg' alt='Sponsors' />
|
| 95 |
+
</a>
|
| 96 |
+
</p>
|
| 97 |
+
|
| 98 |
+
## License
|
| 99 |
+
|
| 100 |
+
[MIT](./LICENSE) License © 2023-PRESENT [Anthony Fu](https://github.com/antfu)
|
| 101 |
+
|
| 102 |
+
<!-- Badges -->
|
| 103 |
+
|
| 104 |
+
[npm-version-src]: https://img.shields.io/npm/v/eslint-config-flat-gitignore?style=flat&colorA=080f12&colorB=1fa669
|
| 105 |
+
[npm-version-href]: https://npmjs.com/package/eslint-config-flat-gitignore
|
| 106 |
+
[npm-downloads-src]: https://img.shields.io/npm/dm/eslint-config-flat-gitignore?style=flat&colorA=080f12&colorB=1fa669
|
| 107 |
+
[npm-downloads-href]: https://npmjs.com/package/eslint-config-flat-gitignore
|
| 108 |
+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/eslint-config-flat-gitignore?style=flat&colorA=080f12&colorB=1fa669&label=minzip
|
| 109 |
+
[bundle-href]: https://bundlephobia.com/result?p=eslint-config-flat-gitignore
|
| 110 |
+
[license-src]: https://img.shields.io/github/license/antfu/eslint-config-flat-gitignore.svg?style=flat&colorA=080f12&colorB=1fa669
|
| 111 |
+
[license-href]: https://github.com/antfu/eslint-config-flat-gitignore/blob/main/LICENSE
|
| 112 |
+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
|
| 113 |
+
[jsdocs-href]: https://www.jsdocs.io/package/eslint-config-flat-gitignore
|
node_modules/eslint-config-flat-gitignore/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "eslint-config-flat-gitignore",
|
| 3 |
+
"type": "module",
|
| 4 |
+
"version": "2.3.0",
|
| 5 |
+
"description": ".gitignore support for ESLint Flat Config",
|
| 6 |
+
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
| 7 |
+
"license": "MIT",
|
| 8 |
+
"funding": "https://github.com/sponsors/antfu",
|
| 9 |
+
"homepage": "https://github.com/antfu/eslint-config-flat-gitignore#readme",
|
| 10 |
+
"repository": {
|
| 11 |
+
"type": "git",
|
| 12 |
+
"url": "git+https://github.com/antfu/eslint-config-flat-gitignore.git"
|
| 13 |
+
},
|
| 14 |
+
"bugs": "https://github.com/antfu/eslint-config-flat-gitignore/issues",
|
| 15 |
+
"keywords": [
|
| 16 |
+
"eslint-config",
|
| 17 |
+
"eslint-flat-config"
|
| 18 |
+
],
|
| 19 |
+
"sideEffects": false,
|
| 20 |
+
"exports": {
|
| 21 |
+
".": "./dist/index.mjs"
|
| 22 |
+
},
|
| 23 |
+
"main": "./dist/index.mjs",
|
| 24 |
+
"module": "./dist/index.mjs",
|
| 25 |
+
"types": "./dist/index.d.mts",
|
| 26 |
+
"files": [
|
| 27 |
+
"dist"
|
| 28 |
+
],
|
| 29 |
+
"peerDependencies": {
|
| 30 |
+
"eslint": "^9.5.0 || ^10.0.0"
|
| 31 |
+
},
|
| 32 |
+
"dependencies": {
|
| 33 |
+
"@eslint/compat": "^2.0.3"
|
| 34 |
+
},
|
| 35 |
+
"devDependencies": {
|
| 36 |
+
"@antfu/eslint-config": "^7.7.3",
|
| 37 |
+
"@antfu/ni": "^30.0.0",
|
| 38 |
+
"@antfu/utils": "^9.3.0",
|
| 39 |
+
"@types/node": "^25.5.0",
|
| 40 |
+
"bumpp": "^11.0.1",
|
| 41 |
+
"eslint": "^10.1.0",
|
| 42 |
+
"find-up-simple": "^1.0.1",
|
| 43 |
+
"lint-staged": "^16.4.0",
|
| 44 |
+
"pnpm": "^10.32.1",
|
| 45 |
+
"simple-git-hooks": "^2.13.1",
|
| 46 |
+
"tsx": "^4.21.0",
|
| 47 |
+
"typescript": "^5.9.3",
|
| 48 |
+
"unbuild": "^3.6.1",
|
| 49 |
+
"vite": "^8.0.2",
|
| 50 |
+
"vitest": "^4.1.1"
|
| 51 |
+
},
|
| 52 |
+
"simple-git-hooks": {
|
| 53 |
+
"pre-commit": "pnpm lint-staged"
|
| 54 |
+
},
|
| 55 |
+
"lint-staged": {
|
| 56 |
+
"*": "eslint --fix"
|
| 57 |
+
},
|
| 58 |
+
"scripts": {
|
| 59 |
+
"build": "unbuild",
|
| 60 |
+
"dev": "unbuild --stub",
|
| 61 |
+
"lint": "eslint .",
|
| 62 |
+
"release": "bumpp",
|
| 63 |
+
"start": "tsx src/index.ts",
|
| 64 |
+
"test": "vitest --pool=forks",
|
| 65 |
+
"typecheck": "tsc --noEmit"
|
| 66 |
+
}
|
| 67 |
+
}
|
node_modules/eslint-config-prettier/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell and contributors
|
| 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
|
| 13 |
+
all 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
|
| 21 |
+
THE SOFTWARE.
|
node_modules/eslint-config-prettier/README.md
ADDED
|
@@ -0,0 +1,928 @@
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# eslint-config-prettier
|
| 2 |
+
|
| 3 |
+
Turns off all rules that are unnecessary or might conflict with [Prettier].
|
| 4 |
+
|
| 5 |
+
This lets you use your favorite shareable config without letting its stylistic choices get in the way when using Prettier.
|
| 6 |
+
|
| 7 |
+
Note that this config _only_ turns rules _off,_ so it only makes sense using it together with some other config.
|
| 8 |
+
|
| 9 |
+
[prettier]: https://github.com/prettier/prettier
|
| 10 |
+
|
| 11 |
+
## Installation
|
| 12 |
+
|
| 13 |
+
1. Install eslint-config-prettier:
|
| 14 |
+
|
| 15 |
+
```shell
|
| 16 |
+
npm i -D eslint-config-prettier
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
```shell
|
| 20 |
+
yarn add -D eslint-config-prettier
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
```shell
|
| 24 |
+
pnpm add -D eslint-config-prettier
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
```shell
|
| 28 |
+
bun add -D eslint-config-prettier
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
2. Add eslint-config-prettier to your ESLint configuration – either to [eslintrc] or to [eslint.config.js (flat config)].
|
| 32 |
+
|
| 33 |
+
- eslintrc: Add `"prettier"` to the "extends" array in your `.eslintrc.*` file. Make sure to put it **last,** so it gets the chance to override other configs.
|
| 34 |
+
|
| 35 |
+
<!-- prettier-ignore -->
|
| 36 |
+
```json
|
| 37 |
+
{
|
| 38 |
+
"extends": [
|
| 39 |
+
"some-other-config-you-use",
|
| 40 |
+
"prettier"
|
| 41 |
+
]
|
| 42 |
+
}
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
- eslint.config.js (flat config): Import eslint-config-prettier, and put it in the configuration array – **after** other configs that you want to override.
|
| 46 |
+
|
| 47 |
+
<!-- prettier-ignore -->
|
| 48 |
+
```js
|
| 49 |
+
import someConfig from "some-other-config-you-use";
|
| 50 |
+
// Note the `/flat` suffix here, the difference from default entry is that
|
| 51 |
+
// `/flat` added `name` property to the exported object to improve
|
| 52 |
+
// [config-inspector](https://eslint.org/blog/2024/04/eslint-config-inspector/) experience.
|
| 53 |
+
import eslintConfigPrettier from "eslint-config-prettier/flat";
|
| 54 |
+
|
| 55 |
+
export default [
|
| 56 |
+
someConfig,
|
| 57 |
+
eslintConfigPrettier,
|
| 58 |
+
];
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
3. Finally, run the [CLI helper tool](#cli-helper-tool) to find problems in the `"rules"` sections of your config.
|
| 62 |
+
|
| 63 |
+
> 👉 Using [eslint-plugin-prettier]? Check out [eslint-plugin-prettier’s recommended config][eslint-plugin-prettier-recommended].
|
| 64 |
+
|
| 65 |
+
### Plugins
|
| 66 |
+
|
| 67 |
+
eslint-config-prettier not only turns off _core_ rules, but also some from these plugins automatically:
|
| 68 |
+
|
| 69 |
+
- [@babel/eslint-plugin]
|
| 70 |
+
- [@stylistic/eslint-plugin]
|
| 71 |
+
- [@typescript-eslint/eslint-plugin]
|
| 72 |
+
- [eslint-plugin-babel]
|
| 73 |
+
- [eslint-plugin-flowtype]
|
| 74 |
+
- [eslint-plugin-react]
|
| 75 |
+
- [eslint-plugin-standard]
|
| 76 |
+
- [eslint-plugin-unicorn]
|
| 77 |
+
- [eslint-plugin-vue]
|
| 78 |
+
|
| 79 |
+
> ℹ️ Note: You might find guides on the Internet saying you should also extend stuff like `"prettier/react"`. Since version 8.0.0 of eslint-config-prettier, all you need to extend is `"prettier"`! That includes all plugins.
|
| 80 |
+
|
| 81 |
+
#### eslint.config.js (flat config) plugin caveat
|
| 82 |
+
|
| 83 |
+
With flat config, _you_ get to decide the plugin name! For example:
|
| 84 |
+
|
| 85 |
+
```js
|
| 86 |
+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
| 87 |
+
import eslintConfigPrettier from "eslint-config-prettier/flat";
|
| 88 |
+
|
| 89 |
+
export default [
|
| 90 |
+
{
|
| 91 |
+
plugins: {
|
| 92 |
+
// You’d typically use one of the following two:
|
| 93 |
+
// typescriptEslint: typescriptEslint,
|
| 94 |
+
// typescriptEslint,
|
| 95 |
+
// But in this example we give it another name.
|
| 96 |
+
// It might be tempting to use something shorter like “ts”:
|
| 97 |
+
ts: typescriptEslint, // 🚨 Don’t do this!
|
| 98 |
+
},
|
| 99 |
+
rules: {
|
| 100 |
+
// With eslintrc, this is _always_ called:
|
| 101 |
+
// @typescript-eslint/indent
|
| 102 |
+
// But in eslint.config.js (flat config), the name chosen above in `plugins` is used.
|
| 103 |
+
"ts/indent": "error", // 🚨 Don’t do this!
|
| 104 |
+
},
|
| 105 |
+
},
|
| 106 |
+
eslintConfigPrettier,
|
| 107 |
+
];
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
You might expect eslint-config-prettier to turn off `ts/indent`, but it won’t! Because eslint-config-prettier only turns off `@typescript-eslint/indent`. It cannot know what you chose to call the plugin. Same thing for the CLI helper tool.
|
| 111 |
+
|
| 112 |
+
Simply stick to the official plugin names and you’ll be all good.
|
| 113 |
+
|
| 114 |
+
If you encounter a shared _config_ that uses a non-standard plugin name, please ask them to use the standard name instead.
|
| 115 |
+
|
| 116 |
+
### Excluding deprecated rules
|
| 117 |
+
|
| 118 |
+
Some of the rules that eslint-config-prettier turns off may be deprecated, or even removed from ESLint. **This is perfectly fine,** but if you really need to omit the deprecated and removed rules, you can do so by setting the `ESLINT_CONFIG_PRETTIER_NO_DEPRECATED` environment variable to a non-empty value. For example:
|
| 119 |
+
|
| 120 |
+
```
|
| 121 |
+
env ESLINT_CONFIG_PRETTIER_NO_DEPRECATED=true npx eslint-find-rules --deprecated index.js
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
## CLI helper tool
|
| 125 |
+
|
| 126 |
+
eslint-config-prettier also ships with a little CLI tool to help you check if your configuration contains any rules that are unnecessary or conflict with Prettier. Here’s how to run it:
|
| 127 |
+
|
| 128 |
+
```
|
| 129 |
+
npx eslint-config-prettier path/to/main.js
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
(Change `path/to/main.js` to a file that exists in your project.)
|
| 133 |
+
|
| 134 |
+
### What and why
|
| 135 |
+
|
| 136 |
+
Now, let’s have a look at what it does and why you might want to use it.
|
| 137 |
+
|
| 138 |
+
🚨 This eslintrc example has a **conflicting rule** `"indent"` enabled:
|
| 139 |
+
|
| 140 |
+
<!-- prettier-ignore -->
|
| 141 |
+
```json
|
| 142 |
+
{
|
| 143 |
+
"extends": [
|
| 144 |
+
"some-other-config-you-use",
|
| 145 |
+
"prettier"
|
| 146 |
+
],
|
| 147 |
+
"rules": {
|
| 148 |
+
"indent": "error"
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
For eslintrc, while the `"prettier"` config can disable problematic rules in `"some-other-config-you-use"`, it cannot touch `"rules"`! (That’s how ESLint works – it lets you override configs you extend.) The CLI helper tool reports that `"indent"` conflicts with Prettier, so you can remove it. (Which is nice – simplifying your config!)
|
| 154 |
+
|
| 155 |
+
🚨 This eslint.config.js (flat config) example also has a **conflicting rule** `"indent"` enabled:
|
| 156 |
+
|
| 157 |
+
```js
|
| 158 |
+
import someConfig from "some-other-config-you-use";
|
| 159 |
+
import eslintConfigPrettier from "eslint-config-prettier/flat";
|
| 160 |
+
|
| 161 |
+
export default [
|
| 162 |
+
someConfig,
|
| 163 |
+
eslintConfigPrettier,
|
| 164 |
+
{
|
| 165 |
+
rules: {
|
| 166 |
+
indent: "error",
|
| 167 |
+
},
|
| 168 |
+
},
|
| 169 |
+
];
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
With the new ESLint “flat config” format, you can control what things override what yourself. One way of solving the above conflict is to reorder the config objects so that eslint-config-prettier is last:
|
| 173 |
+
|
| 174 |
+
```js
|
| 175 |
+
import someConfig from "some-other-config-you-use";
|
| 176 |
+
import eslintConfigPrettier from "eslint-config-prettier/flat";
|
| 177 |
+
|
| 178 |
+
export default [
|
| 179 |
+
someConfig,
|
| 180 |
+
{
|
| 181 |
+
rules: {
|
| 182 |
+
indent: "error",
|
| 183 |
+
},
|
| 184 |
+
},
|
| 185 |
+
eslintConfigPrettier, // eslint-config-prettier last
|
| 186 |
+
];
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
However, looking at the above config might feel confusing. It looks like we enable the `indent` rule, but in reality it’s disabled thanks to the `eslintConfigPrettier` line below it. Instead you might want to actually have your own rules _after_ eslint-config-prettier and run the CLI helper tool to find out about problems, so you can remove conflicting rules from the config file altogether (simplifying your config).
|
| 190 |
+
|
| 191 |
+
### Checking multiple files
|
| 192 |
+
|
| 193 |
+
In theory you need to run the tool for every single file in your project to be 100% sure that there are no conflicting rules, because ESLint supports having different rules for different files. Usually you’ll have about the same rules for all files, so it is good enough to run the command on one file. But if you use [multiple configuration files] or [overrides], you can provide several files to check:
|
| 194 |
+
|
| 195 |
+
```
|
| 196 |
+
npx eslint-config-prettier index.js test/index.js legacy/main.js
|
| 197 |
+
```
|
| 198 |
+
|
| 199 |
+
### Exit codes
|
| 200 |
+
|
| 201 |
+
- 0: No problems found.
|
| 202 |
+
- 1: Unexpected error.
|
| 203 |
+
- 2: Conflicting rules found.
|
| 204 |
+
|
| 205 |
+
### ESLINT_USE_FLAT_CONFIG environment variable
|
| 206 |
+
|
| 207 |
+
Just like ESLint itself, you can control the eslint-config-prettier CLI helper tool using the `ESLINT_USE_FLAT_CONFIG` environment variable:
|
| 208 |
+
|
| 209 |
+
- `ESLINT_USE_FLAT_CONFIG=true`: Only use eslint.config.js (flat config).
|
| 210 |
+
- `ESLINT_USE_FLAT_CONFIG=false`: Only use eslintrc files.
|
| 211 |
+
- Unset or any other value: First try eslint.config.js, then eslintrc.
|
| 212 |
+
|
| 213 |
+
> **Warning**
|
| 214 |
+
> For eslint.config.js (flat config), the CLI helper tool imports `eslint/use-at-your-own-risk` which may break at any time.
|
| 215 |
+
|
| 216 |
+
### Legacy
|
| 217 |
+
|
| 218 |
+
eslint-config-prettier versions before 7.0.0 had a slightly different CLI tool that was run in a different way. For example:
|
| 219 |
+
|
| 220 |
+
```
|
| 221 |
+
npx eslint --print-config index.js | npx eslint-config-prettier-check
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
If you find something like that in a tutorial, this is what the command looks like in 7.0.0 or later:
|
| 225 |
+
|
| 226 |
+
```
|
| 227 |
+
npx eslint-config-prettier index.js
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
## Special rules
|
| 231 |
+
|
| 232 |
+
There a few rules that eslint-config-prettier disables that actually can be enabled in some cases.
|
| 233 |
+
|
| 234 |
+
- Some require certain options. The CLI helper tool validates this.
|
| 235 |
+
- Some require special attention when writing code. The CLI helper tool warns you if any of those rules are enabled, but can’t tell if anything is problematic.
|
| 236 |
+
- Some can cause problems if using [eslint-plugin-prettier] and `--fix`.
|
| 237 |
+
|
| 238 |
+
For maximum ease of use, the special rules are disabled by default (provided that you include all needed things in `"extends"`). If you want them, you need to explicitly specify them in your ESLint config.
|
| 239 |
+
|
| 240 |
+
### [arrow-body-style] and [prefer-arrow-callback]
|
| 241 |
+
|
| 242 |
+
**These rules might cause problems if using [eslint-plugin-prettier] and `--fix`.**
|
| 243 |
+
|
| 244 |
+
See the [`arrow-body-style` and `prefer-arrow-callback` issue][eslint-plugin-prettier-autofix-issue] for details.
|
| 245 |
+
|
| 246 |
+
There are a couple of ways to turn these rules off:
|
| 247 |
+
|
| 248 |
+
- Put `"plugin:prettier/recommended"` in your `"extends"`. That’s [eslint-<strong>plugin</strong>-prettier’s recommended config][eslint-plugin-prettier-recommended].
|
| 249 |
+
- Put `"prettier/prettier"` in your `"extends"`. (Yes, there’s both a _rule_ called `"prettier/prettier"` and a _config_ called `"prettier/prettier"`.)
|
| 250 |
+
- Remove them from your config or turn them off manually.
|
| 251 |
+
|
| 252 |
+
It doesn’t matter which approach you use. `"plugin:prettier/recommended"` is probably the easiest.
|
| 253 |
+
|
| 254 |
+
Note: The CLI tool only reports these as problematic if the `"prettier/prettier"` _rule_ is enabled for the same file.
|
| 255 |
+
|
| 256 |
+
These rules are safe to use if you don’t use [eslint-plugin-prettier]. In other words, if you run `eslint --fix` and `prettier --write` as separate steps.
|
| 257 |
+
|
| 258 |
+
### [curly]
|
| 259 |
+
|
| 260 |
+
**This rule requires certain options.**
|
| 261 |
+
|
| 262 |
+
If a block (for example after `if`, `else`, `for` or `while`) contains only one statement, JavaScript allows omitting the curly braces around that statement. This rule enforces if or when those optional curly braces should be omitted.
|
| 263 |
+
|
| 264 |
+
If you use the `"multi-line"` or `"multi-or-nest"` option, the rule can conflict with Prettier.
|
| 265 |
+
|
| 266 |
+
For example, the `"multi-line"` option allows this line:
|
| 267 |
+
|
| 268 |
+
<!-- prettier-ignore -->
|
| 269 |
+
```js
|
| 270 |
+
if (cart.items && cart.items[0] && cart.items[0].quantity === 0) updateCart(cart);
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
However, Prettier might consider the line too long and turn it into the following, which the `"multi-line"` option does _not_ allow:
|
| 274 |
+
|
| 275 |
+
<!-- prettier-ignore -->
|
| 276 |
+
```js
|
| 277 |
+
if (cart.items && cart.items[0] && cart.items[0].quantity === 0)
|
| 278 |
+
updateCart(cart);
|
| 279 |
+
```
|
| 280 |
+
|
| 281 |
+
If you like this rule, it can be used just fine with Prettier as long as you don’t use the `"multi-line"` or `"multi-or-nest"` option.
|
| 282 |
+
|
| 283 |
+
Example ESLint configuration:
|
| 284 |
+
|
| 285 |
+
<!-- prettier-ignore -->
|
| 286 |
+
```json
|
| 287 |
+
{
|
| 288 |
+
"rules": {
|
| 289 |
+
"curly": ["error", "all"]
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
### [lines-around-comment] \(deprecated)
|
| 295 |
+
|
| 296 |
+
(The following applies to [@stylistic/lines-around-comment], [@stylistic/js/lines-around-comment], [@stylistic/ts/lines-around-comment], and [@typescript-eslint/lines-around-comment] as well.)
|
| 297 |
+
|
| 298 |
+
**This rule can be used with certain options.**
|
| 299 |
+
|
| 300 |
+
This rule requires empty lines before and/or after comments. Prettier preserves blank lines, with two exceptions:
|
| 301 |
+
|
| 302 |
+
- Several blank lines in a row are collapsed into a single blank line. This is fine.
|
| 303 |
+
- Blank lines at the beginning and end of blocks, objects and arrays are always removed. This may lead to conflicts.
|
| 304 |
+
|
| 305 |
+
By default, ESLint requires a blank line above the comment is this case:
|
| 306 |
+
|
| 307 |
+
<!-- prettier-ignore -->
|
| 308 |
+
```js
|
| 309 |
+
if (result) {
|
| 310 |
+
|
| 311 |
+
/* comment */
|
| 312 |
+
return result;
|
| 313 |
+
}
|
| 314 |
+
```
|
| 315 |
+
|
| 316 |
+
However, Prettier removes the blank line:
|
| 317 |
+
|
| 318 |
+
<!-- prettier-ignore -->
|
| 319 |
+
```js
|
| 320 |
+
if (result) {
|
| 321 |
+
/* comment */
|
| 322 |
+
return result;
|
| 323 |
+
}
|
| 324 |
+
```
|
| 325 |
+
|
| 326 |
+
If you like this rule, it can be used just fine with Prettier as long as you add some extra configuration to allow comments at the start and end of blocks, objects and arrays.
|
| 327 |
+
|
| 328 |
+
Example ESLint configuration:
|
| 329 |
+
|
| 330 |
+
<!-- prettier-ignore -->
|
| 331 |
+
```json
|
| 332 |
+
{
|
| 333 |
+
"rules": {
|
| 334 |
+
"lines-around-comment": [
|
| 335 |
+
"error",
|
| 336 |
+
{
|
| 337 |
+
"beforeBlockComment": true,
|
| 338 |
+
"afterBlockComment": true,
|
| 339 |
+
"beforeLineComment": true,
|
| 340 |
+
"afterLineComment": true,
|
| 341 |
+
"allowBlockStart": true,
|
| 342 |
+
"allowBlockEnd": true,
|
| 343 |
+
"allowObjectStart": true,
|
| 344 |
+
"allowObjectEnd": true,
|
| 345 |
+
"allowArrayStart": true,
|
| 346 |
+
"allowArrayEnd": true
|
| 347 |
+
}
|
| 348 |
+
]
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
```
|
| 352 |
+
|
| 353 |
+
### [max-len] \(deprecated)
|
| 354 |
+
|
| 355 |
+
(The following applies to [@stylistic/max-len], [@stylistic/js/max-len], and [vue/max-len] as well.)
|
| 356 |
+
|
| 357 |
+
**This rule requires special attention when writing code.**
|
| 358 |
+
|
| 359 |
+
Usually, Prettier takes care of following a maximum line length automatically. However, there are cases where Prettier can’t do anything, such as for long strings, regular expressions and comments. Those need to be split up by a human.
|
| 360 |
+
|
| 361 |
+
If you’d like to enforce an even stricter maximum line length policy than Prettier can provide automatically, you can enable this rule. Just remember to keep `max-len`’s options and Prettier’s `printWidth` option in sync.
|
| 362 |
+
|
| 363 |
+
Keep in mind that you might have to refactor code slightly if Prettier formats lines in a way that the `max-len` rule does not approve of.
|
| 364 |
+
|
| 365 |
+
Example ESLint configuration:
|
| 366 |
+
|
| 367 |
+
<!-- prettier-ignore -->
|
| 368 |
+
```json
|
| 369 |
+
{
|
| 370 |
+
"rules": {
|
| 371 |
+
"max-len": ["error", {"code": 80, "ignoreUrls": true}]
|
| 372 |
+
}
|
| 373 |
+
}
|
| 374 |
+
```
|
| 375 |
+
|
| 376 |
+
### [no-confusing-arrow] \(deprecated)
|
| 377 |
+
|
| 378 |
+
(The following applies to [@stylistic/no-confusing-arrow] and [@stylistic/js/no-confusing-arrow] as well.)
|
| 379 |
+
|
| 380 |
+
**This rule requires certain options.**
|
| 381 |
+
|
| 382 |
+
For example, the rule could warn about this line:
|
| 383 |
+
|
| 384 |
+
<!-- prettier-ignore -->
|
| 385 |
+
```js
|
| 386 |
+
var x = a => 1 ? 2 : 3;
|
| 387 |
+
```
|
| 388 |
+
|
| 389 |
+
With `{allowParens: true}` (the default since ESLint 6.0.0), adding parentheses is considered a valid way to avoid the arrow confusion:
|
| 390 |
+
|
| 391 |
+
<!-- prettier-ignore -->
|
| 392 |
+
```js
|
| 393 |
+
var x = a => (1 ? 2 : 3);
|
| 394 |
+
```
|
| 395 |
+
|
| 396 |
+
While Prettier keeps those parentheses, it removes them if the line is long enough to introduce a line break:
|
| 397 |
+
|
| 398 |
+
<!-- prettier-ignore -->
|
| 399 |
+
```js
|
| 400 |
+
EnterpriseCalculator.prototype.calculateImportantNumbers = inputNumber =>
|
| 401 |
+
1 ? 2 : 3;
|
| 402 |
+
```
|
| 403 |
+
|
| 404 |
+
With `{allowParens: false}`, ESLint instead suggests switching to an explicit return:
|
| 405 |
+
|
| 406 |
+
<!-- prettier-ignore -->
|
| 407 |
+
```js
|
| 408 |
+
var x = a => { return 1 ? 2 : 3; };
|
| 409 |
+
```
|
| 410 |
+
|
| 411 |
+
That causes no problems with Prettier.
|
| 412 |
+
|
| 413 |
+
If you like this rule, it can be used just fine with Prettier as long as the `allowParens` option is off.
|
| 414 |
+
|
| 415 |
+
Example ESLint configuration:
|
| 416 |
+
|
| 417 |
+
<!-- prettier-ignore -->
|
| 418 |
+
```json
|
| 419 |
+
{
|
| 420 |
+
"rules": {
|
| 421 |
+
"no-confusing-arrow": ["error", { "allowParens": false }]
|
| 422 |
+
}
|
| 423 |
+
}
|
| 424 |
+
```
|
| 425 |
+
|
| 426 |
+
(Note: The CLI helper tool considers `{allowParens: true}` to be the default, which is the case since ESLint 6.0.0. The tool will produce a warning if you use the default even if you use an older version of ESLint. It doesn’t hurt to explicitly set `{allowParens: false}` even though it is technically redundant. This way you are prepared for a future ESLint upgrade and the CLI tool can be kept simple.)
|
| 427 |
+
|
| 428 |
+
### [no-mixed-operators] \(deprecated)
|
| 429 |
+
|
| 430 |
+
(The following applies to [@stylistic/no-mixed-operators] and [@stylistic/js/no-mixed-operators] as well.)
|
| 431 |
+
|
| 432 |
+
**This rule requires special attention when writing code.**
|
| 433 |
+
|
| 434 |
+
This rule forbids mixing certain operators, such as `&&` and `||`.
|
| 435 |
+
|
| 436 |
+
For example, the rule could warn about this line:
|
| 437 |
+
|
| 438 |
+
<!-- prettier-ignore -->
|
| 439 |
+
```js
|
| 440 |
+
var foo = a + b * c;
|
| 441 |
+
```
|
| 442 |
+
|
| 443 |
+
The rule suggests adding parentheses, like this:
|
| 444 |
+
|
| 445 |
+
<!-- prettier-ignore -->
|
| 446 |
+
```js
|
| 447 |
+
var foo = a + (b * c);
|
| 448 |
+
```
|
| 449 |
+
|
| 450 |
+
However, Prettier removes many “unnecessary” parentheses, turning it back to:
|
| 451 |
+
|
| 452 |
+
<!-- prettier-ignore -->
|
| 453 |
+
```js
|
| 454 |
+
var foo = a + b * c;
|
| 455 |
+
```
|
| 456 |
+
|
| 457 |
+
If you want to use this rule with Prettier, you need to split the expression into another variable:
|
| 458 |
+
|
| 459 |
+
<!-- prettier-ignore -->
|
| 460 |
+
```js
|
| 461 |
+
var bar = b * c;
|
| 462 |
+
var foo = a + bar;
|
| 463 |
+
```
|
| 464 |
+
|
| 465 |
+
Keep in mind that Prettier prints _some_ “unnecessary” parentheses, though:
|
| 466 |
+
|
| 467 |
+
<!-- prettier-ignore -->
|
| 468 |
+
```js
|
| 469 |
+
var foo = (a && b) || c;
|
| 470 |
+
```
|
| 471 |
+
|
| 472 |
+
Example ESLint configuration:
|
| 473 |
+
|
| 474 |
+
<!-- prettier-ignore -->
|
| 475 |
+
```json
|
| 476 |
+
{
|
| 477 |
+
"rules": {
|
| 478 |
+
"no-mixed-operators": "error"
|
| 479 |
+
}
|
| 480 |
+
}
|
| 481 |
+
```
|
| 482 |
+
|
| 483 |
+
### [no-tabs] \(deprecated)
|
| 484 |
+
|
| 485 |
+
(The following applies to [@stylistic/no-tabs] and [@stylistic/js/no-tabs] as well.)
|
| 486 |
+
|
| 487 |
+
**This rule requires certain options.**
|
| 488 |
+
|
| 489 |
+
This rule disallows the use of tab characters. By default the rule forbids _all_ tab characters. That can be used just fine with Prettier as long as you don’t configure Prettier to indent using tabs.
|
| 490 |
+
|
| 491 |
+
Luckily, it’s possible to configure the rule so that it works regardless of whether Prettier uses spaces or tabs: Set `allowIndentationTabs` to `true`. This way Prettier takes care of your indentation, while the `no-tabs` takes care of potential tab characters anywhere else in your code.
|
| 492 |
+
|
| 493 |
+
Example ESLint configuration:
|
| 494 |
+
|
| 495 |
+
<!-- prettier-ignore -->
|
| 496 |
+
```json
|
| 497 |
+
{
|
| 498 |
+
"rules": {
|
| 499 |
+
"no-tabs": ["error", {"allowIndentationTabs": true}]
|
| 500 |
+
}
|
| 501 |
+
}
|
| 502 |
+
```
|
| 503 |
+
|
| 504 |
+
### [no-unexpected-multiline]
|
| 505 |
+
|
| 506 |
+
**This rule requires special attention when writing code.**
|
| 507 |
+
|
| 508 |
+
This rule disallows confusing multiline expressions where a newline looks like it is ending a statement, but is not.
|
| 509 |
+
|
| 510 |
+
For example, the rule could warn about this:
|
| 511 |
+
|
| 512 |
+
<!-- prettier-ignore -->
|
| 513 |
+
```js
|
| 514 |
+
var hello = "world"
|
| 515 |
+
[1, 2, 3].forEach(addNumber)
|
| 516 |
+
```
|
| 517 |
+
|
| 518 |
+
Prettier usually formats this in a way that makes it obvious that a semicolon was missing:
|
| 519 |
+
|
| 520 |
+
<!-- prettier-ignore -->
|
| 521 |
+
```js
|
| 522 |
+
var hello = "world"[(1, 2, 3)].forEach(addNumber);
|
| 523 |
+
```
|
| 524 |
+
|
| 525 |
+
However, there are cases where Prettier breaks things into several lines such that the `no-unexpected-multiline` conflicts.
|
| 526 |
+
|
| 527 |
+
<!-- prettier-ignore -->
|
| 528 |
+
```js
|
| 529 |
+
const value = text.trim().split("\n")[position].toLowerCase();
|
| 530 |
+
```
|
| 531 |
+
|
| 532 |
+
Prettier breaks it up into several lines, though, causing a conflict:
|
| 533 |
+
|
| 534 |
+
<!-- prettier-ignore -->
|
| 535 |
+
```js
|
| 536 |
+
const value = text
|
| 537 |
+
.trim()
|
| 538 |
+
.split("\n")
|
| 539 |
+
[position].toLowerCase();
|
| 540 |
+
```
|
| 541 |
+
|
| 542 |
+
If you like this rule, it can usually be used with Prettier without problems, but occasionally you might need to either temporarily disable the rule or refactor your code.
|
| 543 |
+
|
| 544 |
+
<!-- prettier-ignore -->
|
| 545 |
+
```js
|
| 546 |
+
const value = text
|
| 547 |
+
.trim()
|
| 548 |
+
.split("\n")
|
| 549 |
+
// eslint-disable-next-line no-unexpected-multiline
|
| 550 |
+
[position].toLowerCase();
|
| 551 |
+
|
| 552 |
+
// Or:
|
| 553 |
+
|
| 554 |
+
const lines = text.trim().split("\n");
|
| 555 |
+
const value = lines[position].toLowerCase();
|
| 556 |
+
```
|
| 557 |
+
|
| 558 |
+
**Note:** If you _do_ enable this rule, you have to run ESLint and Prettier as two separate steps (and ESLint first) in order to get any value out of it. Otherwise Prettier might reformat your code in such a way that ESLint never gets a chance to report anything (as seen in the first example).
|
| 559 |
+
|
| 560 |
+
Example configuration:
|
| 561 |
+
|
| 562 |
+
<!-- prettier-ignore -->
|
| 563 |
+
```json
|
| 564 |
+
{
|
| 565 |
+
"rules": {
|
| 566 |
+
"no-unexpected-multiline": "error"
|
| 567 |
+
}
|
| 568 |
+
}
|
| 569 |
+
```
|
| 570 |
+
|
| 571 |
+
### [quotes] \(deprecated)
|
| 572 |
+
|
| 573 |
+
(The following applies to [babel/quotes], [@stylistic/quotes], [@stylistic/js/quotes], [@stylistic/ts/quotes], and [@typescript-eslint/quotes] as well.)
|
| 574 |
+
|
| 575 |
+
**This rule requires certain options and certain Prettier options.**
|
| 576 |
+
|
| 577 |
+
Usually, you don’t need this rule at all. But there are two cases where it could be useful:
|
| 578 |
+
|
| 579 |
+
- To enforce the use of backticks rather than single or double quotes for strings.
|
| 580 |
+
- To forbid backticks where regular strings could have been used.
|
| 581 |
+
|
| 582 |
+
#### Enforce backticks
|
| 583 |
+
|
| 584 |
+
If you’d like all strings to use backticks (never quotes), enable the `"backtick"` option.
|
| 585 |
+
|
| 586 |
+
Example ESLint configuration:
|
| 587 |
+
|
| 588 |
+
<!-- prettier-ignore -->
|
| 589 |
+
```json
|
| 590 |
+
{
|
| 591 |
+
"rules": {
|
| 592 |
+
"quotes": ["error", "backtick"]
|
| 593 |
+
}
|
| 594 |
+
}
|
| 595 |
+
```
|
| 596 |
+
|
| 597 |
+
#### Forbid unnecessary backticks
|
| 598 |
+
|
| 599 |
+
In the following example, the first array item could have been written with quotes instead of backticks.
|
| 600 |
+
|
| 601 |
+
<!-- prettier-ignore -->
|
| 602 |
+
```js
|
| 603 |
+
const strings = [
|
| 604 |
+
`could have been a regular string`,
|
| 605 |
+
`
|
| 606 |
+
multiple
|
| 607 |
+
lines
|
| 608 |
+
`,
|
| 609 |
+
`uses ${interpolation}`,
|
| 610 |
+
String.raw`\tagged/`,
|
| 611 |
+
];
|
| 612 |
+
```
|
| 613 |
+
|
| 614 |
+
If you’d like ESLint to enforce `` `could have been a regular string` `` being written as either `"could have been a regular string"` or `'could have been a regular string'`, you need to use some specific configuration. The `quotes` rule has two options, a string option and an object option.
|
| 615 |
+
|
| 616 |
+
- The first (string) option needs to be set to `"single"` or `"double"` and be kept in sync with Prettier’s [singleQuote] option.
|
| 617 |
+
- The second (object) option needs the following properties:
|
| 618 |
+
- `"avoidEscape": true` to follow Prettier’s [string formatting rules].
|
| 619 |
+
- `"allowTemplateLiterals": false` to disallow unnecessary backticks.
|
| 620 |
+
|
| 621 |
+
##### Example double quote configuration
|
| 622 |
+
|
| 623 |
+
ESLint:
|
| 624 |
+
|
| 625 |
+
<!-- prettier-ignore -->
|
| 626 |
+
```json
|
| 627 |
+
{
|
| 628 |
+
"rules": {
|
| 629 |
+
"quotes": [
|
| 630 |
+
"error",
|
| 631 |
+
"double",
|
| 632 |
+
{ "avoidEscape": true, "allowTemplateLiterals": false }
|
| 633 |
+
]
|
| 634 |
+
}
|
| 635 |
+
}
|
| 636 |
+
```
|
| 637 |
+
|
| 638 |
+
Prettier (this is the default, so adding this is not required):
|
| 639 |
+
|
| 640 |
+
<!-- prettier-ignore -->
|
| 641 |
+
```json
|
| 642 |
+
{
|
| 643 |
+
"singleQuote": false
|
| 644 |
+
}
|
| 645 |
+
```
|
| 646 |
+
|
| 647 |
+
##### Example single quote configuration
|
| 648 |
+
|
| 649 |
+
ESLint:
|
| 650 |
+
|
| 651 |
+
<!-- prettier-ignore -->
|
| 652 |
+
```json
|
| 653 |
+
{
|
| 654 |
+
"rules": {
|
| 655 |
+
"quotes": [
|
| 656 |
+
"error",
|
| 657 |
+
"single",
|
| 658 |
+
{ "avoidEscape": true, "allowTemplateLiterals": false }
|
| 659 |
+
]
|
| 660 |
+
}
|
| 661 |
+
}
|
| 662 |
+
```
|
| 663 |
+
|
| 664 |
+
Prettier:
|
| 665 |
+
|
| 666 |
+
<!-- prettier-ignore -->
|
| 667 |
+
```json
|
| 668 |
+
{
|
| 669 |
+
"singleQuote": true
|
| 670 |
+
}
|
| 671 |
+
```
|
| 672 |
+
|
| 673 |
+
### [unicorn/template-indent]
|
| 674 |
+
|
| 675 |
+
**This rule can be used with certain options.**
|
| 676 |
+
|
| 677 |
+
This rule will automatically fix the indentation of multiline string templates, to keep them in alignment with the code they are found in. A configurable whitelist is used to ensure no whitespace-sensitive strings are edited.
|
| 678 |
+
|
| 679 |
+
Prettier deals with:
|
| 680 |
+
|
| 681 |
+
- HTML
|
| 682 |
+
- CSS
|
| 683 |
+
- GraphQL
|
| 684 |
+
- markdown
|
| 685 |
+
|
| 686 |
+
Using various tags, functions and comments.
|
| 687 |
+
|
| 688 |
+
`unicorn/template-indent` by default formats some of the same tagged templates, which can cause conflicts. For example, the rule and Prettier disagree about indentation in ternaries:
|
| 689 |
+
|
| 690 |
+
```js
|
| 691 |
+
condition
|
| 692 |
+
? null
|
| 693 |
+
: html`
|
| 694 |
+
<p>
|
| 695 |
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui
|
| 696 |
+
mauris.
|
| 697 |
+
</p>
|
| 698 |
+
`;
|
| 699 |
+
```
|
| 700 |
+
|
| 701 |
+
If you like this rule, it can be used just fine with Prettier as long as you configure the rule to not deal with the same templates as Prettier.
|
| 702 |
+
|
| 703 |
+
Example ESLint configuration:
|
| 704 |
+
|
| 705 |
+
<!-- prettier-ignore -->
|
| 706 |
+
```json
|
| 707 |
+
{
|
| 708 |
+
"rules": {
|
| 709 |
+
"unicorn/template-indent": [
|
| 710 |
+
"error",
|
| 711 |
+
{
|
| 712 |
+
"tags": [
|
| 713 |
+
"outdent",
|
| 714 |
+
"dedent",
|
| 715 |
+
"sql",
|
| 716 |
+
"styled"
|
| 717 |
+
],
|
| 718 |
+
"functions": [
|
| 719 |
+
"dedent",
|
| 720 |
+
"stripIndent"
|
| 721 |
+
],
|
| 722 |
+
"selectors": [],
|
| 723 |
+
"comments": [
|
| 724 |
+
"indent"
|
| 725 |
+
]
|
| 726 |
+
}
|
| 727 |
+
]
|
| 728 |
+
}
|
| 729 |
+
}
|
| 730 |
+
```
|
| 731 |
+
|
| 732 |
+
Note: If you use `"selectors"`, the CLI helper tool cannot detect if your selectors might cause conflicts.
|
| 733 |
+
|
| 734 |
+
### [vue/html-self-closing]
|
| 735 |
+
|
| 736 |
+
**This rule requires certain options.**
|
| 737 |
+
|
| 738 |
+
This rule enforces whether elements should be self-closing or not.
|
| 739 |
+
|
| 740 |
+
Prettier generally preserves the way you wrote your elements:
|
| 741 |
+
|
| 742 |
+
<!-- prettier-ignore -->
|
| 743 |
+
```vue
|
| 744 |
+
<div />
|
| 745 |
+
<div></div>
|
| 746 |
+
<MyComponent />
|
| 747 |
+
<MyComponent></MyComponent>
|
| 748 |
+
<svg><path d="" /></svg>
|
| 749 |
+
<svg><path d=""></path></svg>
|
| 750 |
+
```
|
| 751 |
+
|
| 752 |
+
But for known _void_ HTML elements, Prettier always uses the self-closing style. For example, `<img>` is turned into `<img />`.
|
| 753 |
+
|
| 754 |
+
If you like this rule, it can be used just fine with Prettier as long as you set `html.void` to `"any"`.
|
| 755 |
+
|
| 756 |
+
Example ESLint configuration:
|
| 757 |
+
|
| 758 |
+
<!-- prettier-ignore -->
|
| 759 |
+
```json
|
| 760 |
+
{
|
| 761 |
+
"rules": {
|
| 762 |
+
"vue/html-self-closing": [
|
| 763 |
+
"error",
|
| 764 |
+
{
|
| 765 |
+
"html": {
|
| 766 |
+
"void": "any"
|
| 767 |
+
}
|
| 768 |
+
}
|
| 769 |
+
]
|
| 770 |
+
}
|
| 771 |
+
}
|
| 772 |
+
```
|
| 773 |
+
|
| 774 |
+
## Other rules worth mentioning
|
| 775 |
+
|
| 776 |
+
These rules don’t conflict with Prettier, but have some gotchas when used with Prettier.
|
| 777 |
+
|
| 778 |
+
### [no-sequences]
|
| 779 |
+
|
| 780 |
+
This rule forbids using JavaScript’s confusing comma operator (sequence expressions). This piece of code is not doing what it looks like:
|
| 781 |
+
|
| 782 |
+
<!-- prettier-ignore -->
|
| 783 |
+
```js
|
| 784 |
+
matrix[4, 7];
|
| 785 |
+
```
|
| 786 |
+
|
| 787 |
+
Prettier adds parentheses to the above to make it clear that a sequence expression is used:
|
| 788 |
+
|
| 789 |
+
<!-- prettier-ignore -->
|
| 790 |
+
```js
|
| 791 |
+
matrix[(4, 7)];
|
| 792 |
+
```
|
| 793 |
+
|
| 794 |
+
However, the `no-sequences` rule allows comma operators if the expression sequence is explicitly wrapped in parentheses. Since Prettier automatically wraps them in parentheses, you might never see any warnings from ESLint about comma operators.
|
| 795 |
+
|
| 796 |
+
Ending up with an accidental sequence expression can easily happen while refactoring. If you want ESLint to catch such mistakes, it is recommended to forbid sequence expressions entirely using [no-restricted-syntax] \([as mentioned in the `no-sequences` documentation][no-sequences-full]):
|
| 797 |
+
|
| 798 |
+
<!-- prettier-ignore -->
|
| 799 |
+
```json
|
| 800 |
+
{
|
| 801 |
+
"rules": {
|
| 802 |
+
"no-restricted-syntax": ["error", "SequenceExpression"]
|
| 803 |
+
}
|
| 804 |
+
}
|
| 805 |
+
```
|
| 806 |
+
|
| 807 |
+
If you still need to use the comma operator for some edge case, you can place an `// eslint-disable-next-line no-restricted-syntax` comment on the line above the expression. `no-sequences` can safely be disabled if you use the `no-restricted-syntax` approach.
|
| 808 |
+
|
| 809 |
+
You can also supply a custom message if you want:
|
| 810 |
+
|
| 811 |
+
<!-- prettier-ignore -->
|
| 812 |
+
```json
|
| 813 |
+
{
|
| 814 |
+
"rules": {
|
| 815 |
+
"no-restricted-syntax": [
|
| 816 |
+
"error",
|
| 817 |
+
{
|
| 818 |
+
"selector": "SequenceExpression",
|
| 819 |
+
"message": "The comma operator is confusing and a common mistake. Don’t use it!"
|
| 820 |
+
}
|
| 821 |
+
]
|
| 822 |
+
}
|
| 823 |
+
}
|
| 824 |
+
```
|
| 825 |
+
|
| 826 |
+
## Contributing
|
| 827 |
+
|
| 828 |
+
See [package.json] for the exact versions of ESLint, Prettier and ESLint plugins that eslint-config-prettier has been tested with.
|
| 829 |
+
|
| 830 |
+
Have new rules been added since those versions? Have we missed any rules? Is there a plugin you would like to see exclusions for? Open an issue or a pull request!
|
| 831 |
+
|
| 832 |
+
If you’d like to add support for eslint-plugin-foobar, this is how you’d go about it:
|
| 833 |
+
|
| 834 |
+
First, add rules to `index.js`:
|
| 835 |
+
|
| 836 |
+
<!-- prettier-ignore -->
|
| 837 |
+
```js
|
| 838 |
+
"foobar/some-rule": "off"
|
| 839 |
+
```
|
| 840 |
+
|
| 841 |
+
Then, create `test-lint/foobar.js`:
|
| 842 |
+
|
| 843 |
+
<!-- prettier-ignore -->
|
| 844 |
+
```js
|
| 845 |
+
/* eslint-disable quotes */
|
| 846 |
+
"use strict";
|
| 847 |
+
|
| 848 |
+
// Prettier does not want spaces before the parentheses, but
|
| 849 |
+
// `plugin:foobar/recommended` wants one.
|
| 850 |
+
console.log();
|
| 851 |
+
```
|
| 852 |
+
|
| 853 |
+
`test-lint/foobar.js` must fail when used with eslint-plugin-foobar and eslint-plugin-prettier at the same time – until eslint-config-prettier is added to the ESLint config. The file should be formatted according to Prettier, and that formatting should disagree with the plugin.
|
| 854 |
+
|
| 855 |
+
Finally, you need to mention the plugin in several places:
|
| 856 |
+
|
| 857 |
+
- Add eslint-plugin-foobar to the "devDependencies" field in `package.json`.
|
| 858 |
+
- Make sure that at least one rule from eslint-plugin-foobar gets used in `.eslintrc.base.js` and `eslint.base.config.js`.
|
| 859 |
+
- Add it to the lists of supported plugins in this `README.md`.
|
| 860 |
+
|
| 861 |
+
When you’re done, run `npm test` to verify that you got it all right. It runs several other npm scripts:
|
| 862 |
+
|
| 863 |
+
- `"test:prettier"` checks that Prettier has been run on all files.
|
| 864 |
+
- `"test:eslint"` makes sure that the files in `test-lint/` pass ESLint when the exclusions from eslint-config-prettier are used. It also lints the code of eslint-config-prettier itself.
|
| 865 |
+
- `"test:lint-verify-fail"` is run by a test in `test/lint-verify-fail.test.js`.
|
| 866 |
+
- `"test:lint-rules"` is run by a test in `test/rules.test.js`.
|
| 867 |
+
- `"test:jest"` runs unit tests that check a number of things:
|
| 868 |
+
- That eslint-plugin-foobar is mentioned in all the places shown above.
|
| 869 |
+
- That no unknown rules are turned off. This helps catching typos, for example.
|
| 870 |
+
- That the CLI works.
|
| 871 |
+
- `"test:cli-sanity"` and `"test:cli-sanity-warning"` are sanity checks for the CLI.
|
| 872 |
+
|
| 873 |
+
## License
|
| 874 |
+
|
| 875 |
+
[MIT](LICENSE).
|
| 876 |
+
|
| 877 |
+
[@babel/eslint-plugin]: https://github.com/babel/babel/tree/main/eslint/babel-eslint-plugin
|
| 878 |
+
[@stylistic/eslint-plugin]: https://github.com/eslint-stylistic/eslint-stylistic
|
| 879 |
+
[@stylistic/lines-around-comment]: https://eslint.style/rules/default/lines-around-comment
|
| 880 |
+
[@stylistic/js/lines-around-comment]: https://eslint.style/rules/js/lines-around-comment
|
| 881 |
+
[@stylistic/ts/lines-around-comment]: https://eslint.style/rules/ts/lines-around-comment
|
| 882 |
+
[@stylistic/max-len]: https://eslint.style/rules/default/max-len
|
| 883 |
+
[@stylistic/js/max-len]: https://eslint.style/rules/js/max-len
|
| 884 |
+
[@stylistic/no-confusing-arrow]: https://eslint.style/rules/default/no-confusing-arrow
|
| 885 |
+
[@stylistic/js/no-confusing-arrow]: https://eslint.style/rules/js/no-confusing-arrow
|
| 886 |
+
[@stylistic/no-mixed-operators]: https://eslint.style/rules/default/no-mixed-operators
|
| 887 |
+
[@stylistic/js/no-mixed-operators]: https://eslint.style/rules/js/no-mixed-operators
|
| 888 |
+
[@stylistic/no-tabs]: https://eslint.style/rules/default/no-tabs
|
| 889 |
+
[@stylistic/js/no-tabs]: https://eslint.style/rules/js/no-tabs
|
| 890 |
+
[@stylistic/quotes]: https://eslint.style/rules/default/quotes
|
| 891 |
+
[@stylistic/js/quotes]: https://eslint.style/rules/js/quotes
|
| 892 |
+
[@stylistic/ts/quotes]: https://eslint.style/rules/ts/quotes
|
| 893 |
+
[@typescript-eslint/eslint-plugin]: https://github.com/typescript-eslint/typescript-eslint
|
| 894 |
+
[@typescript-eslint/lines-around-comment]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/lines-around-comment.md
|
| 895 |
+
[@typescript-eslint/quotes]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/quotes.md
|
| 896 |
+
[arrow-body-style]: https://eslint.org/docs/rules/arrow-body-style
|
| 897 |
+
[babel/quotes]: https://github.com/babel/eslint-plugin-babel#rules
|
| 898 |
+
[curly]: https://eslint.org/docs/rules/curly
|
| 899 |
+
[eslint-plugin-babel]: https://github.com/babel/eslint-plugin-babel
|
| 900 |
+
[eslint-plugin-flowtype]: https://github.com/gajus/eslint-plugin-flowtype
|
| 901 |
+
[eslint-plugin-prettier-autofix-issue]: https://github.com/prettier/eslint-plugin-prettier#arrow-body-style-and-prefer-arrow-callback-issue
|
| 902 |
+
[eslint-plugin-prettier-recommended]: https://github.com/prettier/eslint-plugin-prettier#recommended-configuration
|
| 903 |
+
[eslint-plugin-prettier]: https://github.com/prettier/eslint-plugin-prettier
|
| 904 |
+
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
|
| 905 |
+
[eslint-plugin-standard]: https://github.com/xjamundx/eslint-plugin-standard
|
| 906 |
+
[eslint-plugin-unicorn]: https://github.com/sindresorhus/eslint-plugin-unicorn
|
| 907 |
+
[eslint-plugin-vue]: https://github.com/vuejs/eslint-plugin-vue
|
| 908 |
+
[eslint.config.js (flat config)]: https://eslint.org/docs/latest/use/configure/configuration-files-new
|
| 909 |
+
[eslintrc]: https://eslint.org/docs/latest/use/configure/configuration-files
|
| 910 |
+
[lines-around-comment]: https://eslint.org/docs/rules/lines-around-comment
|
| 911 |
+
[max-len]: https://eslint.org/docs/rules/max-len
|
| 912 |
+
[multiple configuration files]: https://eslint.org/docs/user-guide/configuring#configuration-cascading-and-hierarchy
|
| 913 |
+
[no-confusing-arrow]: https://eslint.org/docs/rules/no-confusing-arrow
|
| 914 |
+
[no-mixed-operators]: https://eslint.org/docs/rules/no-mixed-operators
|
| 915 |
+
[no-restricted-syntax]: https://eslint.org/docs/rules/no-restricted-syntax
|
| 916 |
+
[no-sequences-full]: https://eslint.org/docs/rules/no-sequences#when-not-to-use-it
|
| 917 |
+
[no-sequences]: https://eslint.org/docs/rules/no-sequences
|
| 918 |
+
[no-tabs]: https://eslint.org/docs/rules/no-tabs
|
| 919 |
+
[no-unexpected-multiline]: https://eslint.org/docs/rules/no-unexpected-multiline
|
| 920 |
+
[overrides]: https://eslint.org/docs/user-guide/configuring#configuration-based-on-glob-patterns
|
| 921 |
+
[package.json]: https://github.com/prettier/eslint-config-prettier/blob/main/package.json
|
| 922 |
+
[prefer-arrow-callback]: https://eslint.org/docs/rules/prefer-arrow-callback
|
| 923 |
+
[quotes]: https://eslint.org/docs/rules/quotes
|
| 924 |
+
[singlequote]: https://prettier.io/docs/en/options.html#quotes
|
| 925 |
+
[string formatting rules]: https://prettier.io/docs/en/rationale.html#strings
|
| 926 |
+
[unicorn/template-indent]: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/template-indent.md
|
| 927 |
+
[vue/html-self-closing]: https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-self-closing.md
|
| 928 |
+
[vue/max-len]: https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/max-len.md
|
node_modules/eslint-config-prettier/bin/cli.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
|
| 3 |
+
"use strict";
|
| 4 |
+
|
| 5 |
+
const validators = require("./validators");
|
| 6 |
+
const config = require("..");
|
| 7 |
+
const prettier = require("../prettier");
|
| 8 |
+
|
| 9 |
+
// Require locally installed eslint, for `npx eslint-config-prettier` support
|
| 10 |
+
// with no local eslint-config-prettier installation.
|
| 11 |
+
const localRequire = (request) =>
|
| 12 |
+
require(
|
| 13 |
+
require.resolve(request, {
|
| 14 |
+
paths: [process.cwd(), ...require.resolve.paths("eslint")],
|
| 15 |
+
})
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
let experimentalApi = {};
|
| 19 |
+
try {
|
| 20 |
+
experimentalApi = localRequire("eslint/use-at-your-own-risk");
|
| 21 |
+
} catch (_error) {}
|
| 22 |
+
|
| 23 |
+
const { ESLint, FlatESLint = experimentalApi.FlatESLint } =
|
| 24 |
+
localRequire("eslint");
|
| 25 |
+
|
| 26 |
+
const SPECIAL_RULES_URL =
|
| 27 |
+
"https://github.com/prettier/eslint-config-prettier#special-rules";
|
| 28 |
+
|
| 29 |
+
const PRETTIER_RULES_URL =
|
| 30 |
+
"https://github.com/prettier/eslint-config-prettier#arrow-body-style-and-prefer-arrow-callback";
|
| 31 |
+
|
| 32 |
+
if (module === require.main) {
|
| 33 |
+
const args = process.argv.slice(2);
|
| 34 |
+
|
| 35 |
+
if (args.length === 0) {
|
| 36 |
+
console.error(help());
|
| 37 |
+
process.exit(1);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
const eslint = new ESLint();
|
| 41 |
+
const flatESLint = FlatESLint === undefined ? undefined : new FlatESLint();
|
| 42 |
+
|
| 43 |
+
Promise.all(
|
| 44 |
+
args.map((file) => {
|
| 45 |
+
switch (process.env.ESLINT_USE_FLAT_CONFIG) {
|
| 46 |
+
case "true": {
|
| 47 |
+
return flatESLint.calculateConfigForFile(file);
|
| 48 |
+
}
|
| 49 |
+
case "false": {
|
| 50 |
+
return eslint.calculateConfigForFile(file);
|
| 51 |
+
}
|
| 52 |
+
default: {
|
| 53 |
+
// This turns synchronous errors (such as `.calculateConfigForFile` not existing)
|
| 54 |
+
// and turns them into promise rejections.
|
| 55 |
+
return Promise.resolve()
|
| 56 |
+
.then(() => flatESLint.calculateConfigForFile(file))
|
| 57 |
+
.catch(() => eslint.calculateConfigForFile(file));
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
})
|
| 61 |
+
)
|
| 62 |
+
.then((configs) => {
|
| 63 |
+
const rules = configs.flatMap(
|
| 64 |
+
(
|
| 65 |
+
// Initializing config and rules for files that aren't included in the flat config,
|
| 66 |
+
// which is a very unlikely scenario, but should still be treated as a success
|
| 67 |
+
{ rules = {} } = {},
|
| 68 |
+
index
|
| 69 |
+
) => Object.entries(rules).map((entry) => [...entry, args[index]])
|
| 70 |
+
);
|
| 71 |
+
const result = processRules(rules);
|
| 72 |
+
if (result.stderr) {
|
| 73 |
+
console.error(result.stderr);
|
| 74 |
+
}
|
| 75 |
+
if (result.stdout) {
|
| 76 |
+
console.error(result.stdout);
|
| 77 |
+
}
|
| 78 |
+
process.exit(result.code);
|
| 79 |
+
})
|
| 80 |
+
.catch((error) => {
|
| 81 |
+
console.error(error.message);
|
| 82 |
+
process.exit(1);
|
| 83 |
+
});
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
function help() {
|
| 87 |
+
return `
|
| 88 |
+
Usage: npx eslint-config-prettier FILE...
|
| 89 |
+
|
| 90 |
+
Resolves an ESLint configuration for every given FILE and checks if they
|
| 91 |
+
contain rules that are unnecessary or conflict with Prettier. Example:
|
| 92 |
+
|
| 93 |
+
npx eslint-config-prettier index.js test/index.js other/file/to/check.js
|
| 94 |
+
|
| 95 |
+
Exit codes:
|
| 96 |
+
|
| 97 |
+
0: No automatically detectable problems found.
|
| 98 |
+
1: General error.
|
| 99 |
+
2: Conflicting rules found.
|
| 100 |
+
|
| 101 |
+
For more information, see:
|
| 102 |
+
https://github.com/prettier/eslint-config-prettier#cli-helper-tool
|
| 103 |
+
`.trim();
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
function processRules(configRules) {
|
| 107 |
+
const regularRules = filterRules(config.rules, (_, value) => value === "off");
|
| 108 |
+
const optionsRules = filterRules(
|
| 109 |
+
config.rules,
|
| 110 |
+
(ruleName, value) => value === 0 && ruleName in validators
|
| 111 |
+
);
|
| 112 |
+
const specialRules = filterRules(
|
| 113 |
+
config.rules,
|
| 114 |
+
(ruleName, value) => value === 0 && !(ruleName in validators)
|
| 115 |
+
);
|
| 116 |
+
|
| 117 |
+
const enabledRules = configRules
|
| 118 |
+
.map(([ruleName, value, source]) => {
|
| 119 |
+
const arrayValue = Array.isArray(value) ? value : [value];
|
| 120 |
+
const [level, ...options] = arrayValue;
|
| 121 |
+
const isOff = level === "off" || level === 0;
|
| 122 |
+
return isOff ? null : { ruleName, options, source };
|
| 123 |
+
})
|
| 124 |
+
.filter(Boolean);
|
| 125 |
+
|
| 126 |
+
const flaggedRules = enabledRules.filter(
|
| 127 |
+
({ ruleName }) => ruleName in config.rules
|
| 128 |
+
);
|
| 129 |
+
|
| 130 |
+
const regularFlaggedRuleNames = filterRuleNames(
|
| 131 |
+
flaggedRules,
|
| 132 |
+
({ ruleName }) => ruleName in regularRules
|
| 133 |
+
);
|
| 134 |
+
const optionsFlaggedRuleNames = filterRuleNames(
|
| 135 |
+
flaggedRules,
|
| 136 |
+
({ ruleName, ...rule }) =>
|
| 137 |
+
ruleName in optionsRules && !validators[ruleName](rule)
|
| 138 |
+
);
|
| 139 |
+
const specialFlaggedRuleNames = filterRuleNames(
|
| 140 |
+
flaggedRules,
|
| 141 |
+
({ ruleName }) => ruleName in specialRules
|
| 142 |
+
);
|
| 143 |
+
const prettierFlaggedRuleNames = filterRuleNames(
|
| 144 |
+
enabledRules,
|
| 145 |
+
({ ruleName, source }) =>
|
| 146 |
+
ruleName in prettier.rules &&
|
| 147 |
+
enabledRules.some(
|
| 148 |
+
(rule) =>
|
| 149 |
+
rule.ruleName === "prettier/prettier" && rule.source === source
|
| 150 |
+
)
|
| 151 |
+
);
|
| 152 |
+
|
| 153 |
+
const regularMessage = [
|
| 154 |
+
"The following rules are unnecessary or might conflict with Prettier:",
|
| 155 |
+
"",
|
| 156 |
+
printRuleNames(regularFlaggedRuleNames),
|
| 157 |
+
].join("\n");
|
| 158 |
+
|
| 159 |
+
const optionsMessage = [
|
| 160 |
+
"The following rules are enabled with config that might conflict with Prettier. See:",
|
| 161 |
+
SPECIAL_RULES_URL,
|
| 162 |
+
"",
|
| 163 |
+
printRuleNames(optionsFlaggedRuleNames),
|
| 164 |
+
].join("\n");
|
| 165 |
+
|
| 166 |
+
const specialMessage = [
|
| 167 |
+
"The following rules are enabled but cannot be automatically checked. See:",
|
| 168 |
+
SPECIAL_RULES_URL,
|
| 169 |
+
"",
|
| 170 |
+
printRuleNames(specialFlaggedRuleNames),
|
| 171 |
+
].join("\n");
|
| 172 |
+
|
| 173 |
+
const prettierMessage = [
|
| 174 |
+
"The following rules can cause issues when using eslint-plugin-prettier at the same time.",
|
| 175 |
+
"Only enable them if you know what you are doing! See:",
|
| 176 |
+
PRETTIER_RULES_URL,
|
| 177 |
+
"",
|
| 178 |
+
printRuleNames(prettierFlaggedRuleNames),
|
| 179 |
+
].join("\n");
|
| 180 |
+
|
| 181 |
+
if (
|
| 182 |
+
regularFlaggedRuleNames.length === 0 &&
|
| 183 |
+
optionsFlaggedRuleNames.length === 0
|
| 184 |
+
) {
|
| 185 |
+
const message =
|
| 186 |
+
specialFlaggedRuleNames.length === 0 &&
|
| 187 |
+
prettierFlaggedRuleNames.length === 0
|
| 188 |
+
? "No rules that are unnecessary or conflict with Prettier were found."
|
| 189 |
+
: [
|
| 190 |
+
specialFlaggedRuleNames.length === 0 ? null : specialMessage,
|
| 191 |
+
prettierFlaggedRuleNames.length === 0 ? null : prettierMessage,
|
| 192 |
+
"Other than that, no rules that are unnecessary or conflict with Prettier were found.",
|
| 193 |
+
]
|
| 194 |
+
.filter(Boolean)
|
| 195 |
+
.join("\n\n");
|
| 196 |
+
|
| 197 |
+
return {
|
| 198 |
+
stdout: message,
|
| 199 |
+
code: 0,
|
| 200 |
+
};
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
const message = [
|
| 204 |
+
regularFlaggedRuleNames.length === 0 ? null : regularMessage,
|
| 205 |
+
optionsFlaggedRuleNames.length === 0 ? null : optionsMessage,
|
| 206 |
+
specialFlaggedRuleNames.length === 0 ? null : specialMessage,
|
| 207 |
+
prettierFlaggedRuleNames.length === 0 ? null : prettierMessage,
|
| 208 |
+
]
|
| 209 |
+
.filter(Boolean)
|
| 210 |
+
.join("\n\n");
|
| 211 |
+
|
| 212 |
+
return {
|
| 213 |
+
stdout: message,
|
| 214 |
+
code: 2,
|
| 215 |
+
};
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
function filterRules(rules, fn) {
|
| 219 |
+
return Object.fromEntries(
|
| 220 |
+
Object.entries(rules)
|
| 221 |
+
.filter(([ruleName, value]) => fn(ruleName, value))
|
| 222 |
+
.map(([ruleName]) => [ruleName, true])
|
| 223 |
+
);
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
function filterRuleNames(rules, fn) {
|
| 227 |
+
return [
|
| 228 |
+
...new Set(rules.filter((rule) => fn(rule)).map((rule) => rule.ruleName)),
|
| 229 |
+
];
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
function printRuleNames(ruleNames) {
|
| 233 |
+
return ruleNames
|
| 234 |
+
.slice()
|
| 235 |
+
.sort()
|
| 236 |
+
.map((ruleName) => `- ${ruleName}`)
|
| 237 |
+
.join("\n");
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
exports.processRules = processRules;
|
node_modules/eslint-config-prettier/bin/validators.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
|
| 3 |
+
// These validator functions answer the question “Is the config valid?” – return
|
| 4 |
+
// `false` if the options DO conflict with Prettier, and `true` if they don’t.
|
| 5 |
+
|
| 6 |
+
module.exports = {
|
| 7 |
+
"curly"({ options }) {
|
| 8 |
+
if (options.length === 0) {
|
| 9 |
+
return true;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
const firstOption = options[0];
|
| 13 |
+
return firstOption !== "multi-line" && firstOption !== "multi-or-nest";
|
| 14 |
+
},
|
| 15 |
+
|
| 16 |
+
"lines-around-comment"({ options }) {
|
| 17 |
+
if (options.length === 0) {
|
| 18 |
+
return false;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const firstOption = options[0];
|
| 22 |
+
return Boolean(
|
| 23 |
+
firstOption &&
|
| 24 |
+
firstOption.allowBlockStart &&
|
| 25 |
+
firstOption.allowBlockEnd &&
|
| 26 |
+
firstOption.allowObjectStart &&
|
| 27 |
+
firstOption.allowObjectEnd &&
|
| 28 |
+
firstOption.allowArrayStart &&
|
| 29 |
+
firstOption.allowArrayEnd
|
| 30 |
+
);
|
| 31 |
+
},
|
| 32 |
+
|
| 33 |
+
"no-confusing-arrow"({ options }) {
|
| 34 |
+
if (options.length === 0) {
|
| 35 |
+
return false;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const firstOption = options[0];
|
| 39 |
+
return firstOption ? firstOption.allowParens === false : false;
|
| 40 |
+
},
|
| 41 |
+
|
| 42 |
+
"no-tabs"({ options }) {
|
| 43 |
+
if (options.length === 0) {
|
| 44 |
+
return false;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
const firstOption = options[0];
|
| 48 |
+
return Boolean(firstOption && firstOption.allowIndentationTabs);
|
| 49 |
+
},
|
| 50 |
+
|
| 51 |
+
"unicorn/template-indent"({ options }) {
|
| 52 |
+
if (options.length === 0) {
|
| 53 |
+
return false;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
const { comments = [], tags = [] } = options[0] || {};
|
| 57 |
+
|
| 58 |
+
return (
|
| 59 |
+
Array.isArray(comments) &&
|
| 60 |
+
Array.isArray(tags) &&
|
| 61 |
+
!(
|
| 62 |
+
comments.includes("GraphQL") ||
|
| 63 |
+
comments.includes("HTML") ||
|
| 64 |
+
tags.includes("css") ||
|
| 65 |
+
tags.includes("graphql") ||
|
| 66 |
+
tags.includes("gql") ||
|
| 67 |
+
tags.includes("html") ||
|
| 68 |
+
tags.includes("markdown") ||
|
| 69 |
+
tags.includes("md")
|
| 70 |
+
)
|
| 71 |
+
);
|
| 72 |
+
},
|
| 73 |
+
|
| 74 |
+
"vue/html-self-closing"({ options }) {
|
| 75 |
+
if (options.length === 0) {
|
| 76 |
+
return false;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
const firstOption = options[0];
|
| 80 |
+
return Boolean(
|
| 81 |
+
firstOption && firstOption.html && firstOption.html.void === "any"
|
| 82 |
+
// Enable when Prettier supports SVG: https://github.com/prettier/prettier/issues/5322
|
| 83 |
+
// && firstOption.svg === "any"
|
| 84 |
+
);
|
| 85 |
+
},
|
| 86 |
+
};
|
node_modules/eslint-config-prettier/flat.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import eslintConfigPrettier from "./index.js";
|
| 2 |
+
|
| 3 |
+
declare const eslintConfigPrettierFlat: typeof eslintConfigPrettier & {
|
| 4 |
+
name: "config-prettier";
|
| 5 |
+
};
|
| 6 |
+
|
| 7 |
+
export = eslintConfigPrettierFlat;
|
node_modules/eslint-config-prettier/flat.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
|
| 3 |
+
const { rules } = require("./index.js");
|
| 4 |
+
|
| 5 |
+
exports.name = "config-prettier";
|
| 6 |
+
exports.rules = rules;
|
node_modules/eslint-config-prettier/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const eslintConfigPrettier: {
|
| 2 |
+
rules: Record<string, 0 | "off">;
|
| 3 |
+
};
|
| 4 |
+
|
| 5 |
+
export = eslintConfigPrettier;
|
node_modules/eslint-config-prettier/index.js
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
|
| 3 |
+
const includeDeprecated = !process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED;
|
| 4 |
+
|
| 5 |
+
const specialRule = 0;
|
| 6 |
+
|
| 7 |
+
exports.rules = {
|
| 8 |
+
// The following rules can be used in some cases. See the README for more
|
| 9 |
+
// information. These are marked with `0` instead of `"off"` so that a
|
| 10 |
+
// script can distinguish them. Note that there are a few more of these
|
| 11 |
+
// in the deprecated section below.
|
| 12 |
+
"curly": specialRule,
|
| 13 |
+
"no-unexpected-multiline": specialRule,
|
| 14 |
+
"@stylistic/lines-around-comment": specialRule,
|
| 15 |
+
"@stylistic/max-len": specialRule,
|
| 16 |
+
"@stylistic/no-confusing-arrow": specialRule,
|
| 17 |
+
"@stylistic/no-mixed-operators": specialRule,
|
| 18 |
+
"@stylistic/no-tabs": specialRule,
|
| 19 |
+
"@stylistic/quotes": specialRule,
|
| 20 |
+
"@stylistic/js/lines-around-comment": specialRule,
|
| 21 |
+
"@stylistic/js/max-len": specialRule,
|
| 22 |
+
"@stylistic/js/no-confusing-arrow": specialRule,
|
| 23 |
+
"@stylistic/js/no-mixed-operators": specialRule,
|
| 24 |
+
"@stylistic/js/no-tabs": specialRule,
|
| 25 |
+
"@stylistic/js/quotes": specialRule,
|
| 26 |
+
"@stylistic/ts/lines-around-comment": specialRule,
|
| 27 |
+
"@stylistic/ts/quotes": specialRule,
|
| 28 |
+
"@typescript-eslint/lines-around-comment": specialRule,
|
| 29 |
+
"@typescript-eslint/quotes": specialRule,
|
| 30 |
+
"babel/quotes": specialRule,
|
| 31 |
+
"unicorn/template-indent": specialRule,
|
| 32 |
+
"vue/html-self-closing": specialRule,
|
| 33 |
+
"vue/max-len": specialRule,
|
| 34 |
+
|
| 35 |
+
// The rest are rules that you never need to enable when using Prettier.
|
| 36 |
+
"@babel/object-curly-spacing": "off",
|
| 37 |
+
"@babel/semi": "off",
|
| 38 |
+
"@stylistic/array-bracket-newline": "off",
|
| 39 |
+
"@stylistic/array-bracket-spacing": "off",
|
| 40 |
+
"@stylistic/array-element-newline": "off",
|
| 41 |
+
"@stylistic/arrow-parens": "off",
|
| 42 |
+
"@stylistic/arrow-spacing": "off",
|
| 43 |
+
"@stylistic/block-spacing": "off",
|
| 44 |
+
"@stylistic/brace-style": "off",
|
| 45 |
+
"@stylistic/comma-dangle": "off",
|
| 46 |
+
"@stylistic/comma-spacing": "off",
|
| 47 |
+
"@stylistic/comma-style": "off",
|
| 48 |
+
"@stylistic/computed-property-spacing": "off",
|
| 49 |
+
"@stylistic/dot-location": "off",
|
| 50 |
+
"@stylistic/eol-last": "off",
|
| 51 |
+
"@stylistic/func-call-spacing": "off",
|
| 52 |
+
"@stylistic/function-call-argument-newline": "off",
|
| 53 |
+
"@stylistic/function-call-spacing": "off",
|
| 54 |
+
"@stylistic/function-paren-newline": "off",
|
| 55 |
+
"@stylistic/generator-star-spacing": "off",
|
| 56 |
+
"@stylistic/implicit-arrow-linebreak": "off",
|
| 57 |
+
"@stylistic/indent": "off",
|
| 58 |
+
"@stylistic/jsx-quotes": "off",
|
| 59 |
+
"@stylistic/key-spacing": "off",
|
| 60 |
+
"@stylistic/keyword-spacing": "off",
|
| 61 |
+
"@stylistic/linebreak-style": "off",
|
| 62 |
+
"@stylistic/max-statements-per-line": "off",
|
| 63 |
+
"@stylistic/multiline-ternary": "off",
|
| 64 |
+
"@stylistic/new-parens": "off",
|
| 65 |
+
"@stylistic/newline-per-chained-call": "off",
|
| 66 |
+
"@stylistic/no-extra-parens": "off",
|
| 67 |
+
"@stylistic/no-extra-semi": "off",
|
| 68 |
+
"@stylistic/no-floating-decimal": "off",
|
| 69 |
+
"@stylistic/no-mixed-spaces-and-tabs": "off",
|
| 70 |
+
"@stylistic/no-multi-spaces": "off",
|
| 71 |
+
"@stylistic/no-multiple-empty-lines": "off",
|
| 72 |
+
"@stylistic/no-trailing-spaces": "off",
|
| 73 |
+
"@stylistic/no-whitespace-before-property": "off",
|
| 74 |
+
"@stylistic/nonblock-statement-body-position": "off",
|
| 75 |
+
"@stylistic/object-curly-newline": "off",
|
| 76 |
+
"@stylistic/object-curly-spacing": "off",
|
| 77 |
+
"@stylistic/object-property-newline": "off",
|
| 78 |
+
"@stylistic/one-var-declaration-per-line": "off",
|
| 79 |
+
"@stylistic/operator-linebreak": "off",
|
| 80 |
+
"@stylistic/padded-blocks": "off",
|
| 81 |
+
"@stylistic/quote-props": "off",
|
| 82 |
+
"@stylistic/rest-spread-spacing": "off",
|
| 83 |
+
"@stylistic/semi": "off",
|
| 84 |
+
"@stylistic/semi-spacing": "off",
|
| 85 |
+
"@stylistic/semi-style": "off",
|
| 86 |
+
"@stylistic/space-before-blocks": "off",
|
| 87 |
+
"@stylistic/space-before-function-paren": "off",
|
| 88 |
+
"@stylistic/space-in-parens": "off",
|
| 89 |
+
"@stylistic/space-infix-ops": "off",
|
| 90 |
+
"@stylistic/space-unary-ops": "off",
|
| 91 |
+
"@stylistic/switch-colon-spacing": "off",
|
| 92 |
+
"@stylistic/template-curly-spacing": "off",
|
| 93 |
+
"@stylistic/template-tag-spacing": "off",
|
| 94 |
+
"@stylistic/wrap-iife": "off",
|
| 95 |
+
"@stylistic/wrap-regex": "off",
|
| 96 |
+
"@stylistic/yield-star-spacing": "off",
|
| 97 |
+
"@stylistic/member-delimiter-style": "off",
|
| 98 |
+
"@stylistic/type-annotation-spacing": "off",
|
| 99 |
+
"@stylistic/jsx-child-element-spacing": "off",
|
| 100 |
+
"@stylistic/jsx-closing-bracket-location": "off",
|
| 101 |
+
"@stylistic/jsx-closing-tag-location": "off",
|
| 102 |
+
"@stylistic/jsx-curly-newline": "off",
|
| 103 |
+
"@stylistic/jsx-curly-spacing": "off",
|
| 104 |
+
"@stylistic/jsx-equals-spacing": "off",
|
| 105 |
+
"@stylistic/jsx-first-prop-new-line": "off",
|
| 106 |
+
"@stylistic/jsx-indent": "off",
|
| 107 |
+
"@stylistic/jsx-indent-props": "off",
|
| 108 |
+
"@stylistic/jsx-max-props-per-line": "off",
|
| 109 |
+
"@stylistic/jsx-newline": "off",
|
| 110 |
+
"@stylistic/jsx-one-expression-per-line": "off",
|
| 111 |
+
"@stylistic/jsx-props-no-multi-spaces": "off",
|
| 112 |
+
"@stylistic/jsx-tag-spacing": "off",
|
| 113 |
+
"@stylistic/jsx-wrap-multilines": "off",
|
| 114 |
+
"@stylistic/indent-binary-ops": "off",
|
| 115 |
+
"@stylistic/type-generic-spacing": "off",
|
| 116 |
+
"@stylistic/type-named-tuple-spacing": "off",
|
| 117 |
+
"@stylistic/js/array-bracket-newline": "off",
|
| 118 |
+
"@stylistic/js/array-bracket-spacing": "off",
|
| 119 |
+
"@stylistic/js/array-element-newline": "off",
|
| 120 |
+
"@stylistic/js/arrow-parens": "off",
|
| 121 |
+
"@stylistic/js/arrow-spacing": "off",
|
| 122 |
+
"@stylistic/js/block-spacing": "off",
|
| 123 |
+
"@stylistic/js/brace-style": "off",
|
| 124 |
+
"@stylistic/js/comma-dangle": "off",
|
| 125 |
+
"@stylistic/js/comma-spacing": "off",
|
| 126 |
+
"@stylistic/js/comma-style": "off",
|
| 127 |
+
"@stylistic/js/computed-property-spacing": "off",
|
| 128 |
+
"@stylistic/js/dot-location": "off",
|
| 129 |
+
"@stylistic/js/eol-last": "off",
|
| 130 |
+
"@stylistic/js/func-call-spacing": "off",
|
| 131 |
+
"@stylistic/js/function-call-argument-newline": "off",
|
| 132 |
+
"@stylistic/js/function-call-spacing": "off",
|
| 133 |
+
"@stylistic/js/function-paren-newline": "off",
|
| 134 |
+
"@stylistic/js/generator-star-spacing": "off",
|
| 135 |
+
"@stylistic/js/implicit-arrow-linebreak": "off",
|
| 136 |
+
"@stylistic/js/indent": "off",
|
| 137 |
+
"@stylistic/js/jsx-quotes": "off",
|
| 138 |
+
"@stylistic/js/key-spacing": "off",
|
| 139 |
+
"@stylistic/js/keyword-spacing": "off",
|
| 140 |
+
"@stylistic/js/linebreak-style": "off",
|
| 141 |
+
"@stylistic/js/max-statements-per-line": "off",
|
| 142 |
+
"@stylistic/js/multiline-ternary": "off",
|
| 143 |
+
"@stylistic/js/new-parens": "off",
|
| 144 |
+
"@stylistic/js/newline-per-chained-call": "off",
|
| 145 |
+
"@stylistic/js/no-extra-parens": "off",
|
| 146 |
+
"@stylistic/js/no-extra-semi": "off",
|
| 147 |
+
"@stylistic/js/no-floating-decimal": "off",
|
| 148 |
+
"@stylistic/js/no-mixed-spaces-and-tabs": "off",
|
| 149 |
+
"@stylistic/js/no-multi-spaces": "off",
|
| 150 |
+
"@stylistic/js/no-multiple-empty-lines": "off",
|
| 151 |
+
"@stylistic/js/no-trailing-spaces": "off",
|
| 152 |
+
"@stylistic/js/no-whitespace-before-property": "off",
|
| 153 |
+
"@stylistic/js/nonblock-statement-body-position": "off",
|
| 154 |
+
"@stylistic/js/object-curly-newline": "off",
|
| 155 |
+
"@stylistic/js/object-curly-spacing": "off",
|
| 156 |
+
"@stylistic/js/object-property-newline": "off",
|
| 157 |
+
"@stylistic/js/one-var-declaration-per-line": "off",
|
| 158 |
+
"@stylistic/js/operator-linebreak": "off",
|
| 159 |
+
"@stylistic/js/padded-blocks": "off",
|
| 160 |
+
"@stylistic/js/quote-props": "off",
|
| 161 |
+
"@stylistic/js/rest-spread-spacing": "off",
|
| 162 |
+
"@stylistic/js/semi": "off",
|
| 163 |
+
"@stylistic/js/semi-spacing": "off",
|
| 164 |
+
"@stylistic/js/semi-style": "off",
|
| 165 |
+
"@stylistic/js/space-before-blocks": "off",
|
| 166 |
+
"@stylistic/js/space-before-function-paren": "off",
|
| 167 |
+
"@stylistic/js/space-in-parens": "off",
|
| 168 |
+
"@stylistic/js/space-infix-ops": "off",
|
| 169 |
+
"@stylistic/js/space-unary-ops": "off",
|
| 170 |
+
"@stylistic/js/switch-colon-spacing": "off",
|
| 171 |
+
"@stylistic/js/template-curly-spacing": "off",
|
| 172 |
+
"@stylistic/js/template-tag-spacing": "off",
|
| 173 |
+
"@stylistic/js/wrap-iife": "off",
|
| 174 |
+
"@stylistic/js/wrap-regex": "off",
|
| 175 |
+
"@stylistic/js/yield-star-spacing": "off",
|
| 176 |
+
"@stylistic/ts/block-spacing": "off",
|
| 177 |
+
"@stylistic/ts/brace-style": "off",
|
| 178 |
+
"@stylistic/ts/comma-dangle": "off",
|
| 179 |
+
"@stylistic/ts/comma-spacing": "off",
|
| 180 |
+
"@stylistic/ts/func-call-spacing": "off",
|
| 181 |
+
"@stylistic/ts/function-call-spacing": "off",
|
| 182 |
+
"@stylistic/ts/indent": "off",
|
| 183 |
+
"@stylistic/ts/key-spacing": "off",
|
| 184 |
+
"@stylistic/ts/keyword-spacing": "off",
|
| 185 |
+
"@stylistic/ts/member-delimiter-style": "off",
|
| 186 |
+
"@stylistic/ts/no-extra-parens": "off",
|
| 187 |
+
"@stylistic/ts/no-extra-semi": "off",
|
| 188 |
+
"@stylistic/ts/object-curly-spacing": "off",
|
| 189 |
+
"@stylistic/ts/semi": "off",
|
| 190 |
+
"@stylistic/ts/space-before-blocks": "off",
|
| 191 |
+
"@stylistic/ts/space-before-function-paren": "off",
|
| 192 |
+
"@stylistic/ts/space-infix-ops": "off",
|
| 193 |
+
"@stylistic/ts/type-annotation-spacing": "off",
|
| 194 |
+
"@stylistic/jsx/jsx-child-element-spacing": "off",
|
| 195 |
+
"@stylistic/jsx/jsx-closing-bracket-location": "off",
|
| 196 |
+
"@stylistic/jsx/jsx-closing-tag-location": "off",
|
| 197 |
+
"@stylistic/jsx/jsx-curly-newline": "off",
|
| 198 |
+
"@stylistic/jsx/jsx-curly-spacing": "off",
|
| 199 |
+
"@stylistic/jsx/jsx-equals-spacing": "off",
|
| 200 |
+
"@stylistic/jsx/jsx-first-prop-new-line": "off",
|
| 201 |
+
"@stylistic/jsx/jsx-indent": "off",
|
| 202 |
+
"@stylistic/jsx/jsx-indent-props": "off",
|
| 203 |
+
"@stylistic/jsx/jsx-max-props-per-line": "off",
|
| 204 |
+
"@typescript-eslint/block-spacing": "off",
|
| 205 |
+
"@typescript-eslint/brace-style": "off",
|
| 206 |
+
"@typescript-eslint/comma-dangle": "off",
|
| 207 |
+
"@typescript-eslint/comma-spacing": "off",
|
| 208 |
+
"@typescript-eslint/func-call-spacing": "off",
|
| 209 |
+
"@typescript-eslint/indent": "off",
|
| 210 |
+
"@typescript-eslint/key-spacing": "off",
|
| 211 |
+
"@typescript-eslint/keyword-spacing": "off",
|
| 212 |
+
"@typescript-eslint/member-delimiter-style": "off",
|
| 213 |
+
"@typescript-eslint/no-extra-parens": "off",
|
| 214 |
+
"@typescript-eslint/no-extra-semi": "off",
|
| 215 |
+
"@typescript-eslint/object-curly-spacing": "off",
|
| 216 |
+
"@typescript-eslint/semi": "off",
|
| 217 |
+
"@typescript-eslint/space-before-blocks": "off",
|
| 218 |
+
"@typescript-eslint/space-before-function-paren": "off",
|
| 219 |
+
"@typescript-eslint/space-infix-ops": "off",
|
| 220 |
+
"@typescript-eslint/type-annotation-spacing": "off",
|
| 221 |
+
"babel/object-curly-spacing": "off",
|
| 222 |
+
"babel/semi": "off",
|
| 223 |
+
"flowtype/boolean-style": "off",
|
| 224 |
+
"flowtype/delimiter-dangle": "off",
|
| 225 |
+
"flowtype/generic-spacing": "off",
|
| 226 |
+
"flowtype/object-type-curly-spacing": "off",
|
| 227 |
+
"flowtype/object-type-delimiter": "off",
|
| 228 |
+
"flowtype/quotes": "off",
|
| 229 |
+
"flowtype/semi": "off",
|
| 230 |
+
"flowtype/space-after-type-colon": "off",
|
| 231 |
+
"flowtype/space-before-generic-bracket": "off",
|
| 232 |
+
"flowtype/space-before-type-colon": "off",
|
| 233 |
+
"flowtype/union-intersection-spacing": "off",
|
| 234 |
+
"react/jsx-child-element-spacing": "off",
|
| 235 |
+
"react/jsx-closing-bracket-location": "off",
|
| 236 |
+
"react/jsx-closing-tag-location": "off",
|
| 237 |
+
"react/jsx-curly-newline": "off",
|
| 238 |
+
"react/jsx-curly-spacing": "off",
|
| 239 |
+
"react/jsx-equals-spacing": "off",
|
| 240 |
+
"react/jsx-first-prop-new-line": "off",
|
| 241 |
+
"react/jsx-indent": "off",
|
| 242 |
+
"react/jsx-indent-props": "off",
|
| 243 |
+
"react/jsx-max-props-per-line": "off",
|
| 244 |
+
"react/jsx-newline": "off",
|
| 245 |
+
"react/jsx-one-expression-per-line": "off",
|
| 246 |
+
"react/jsx-props-no-multi-spaces": "off",
|
| 247 |
+
"react/jsx-tag-spacing": "off",
|
| 248 |
+
"react/jsx-wrap-multilines": "off",
|
| 249 |
+
"standard/array-bracket-even-spacing": "off",
|
| 250 |
+
"standard/computed-property-even-spacing": "off",
|
| 251 |
+
"standard/object-curly-even-spacing": "off",
|
| 252 |
+
"unicorn/empty-brace-spaces": "off",
|
| 253 |
+
"unicorn/no-nested-ternary": "off",
|
| 254 |
+
"unicorn/number-literal-case": "off",
|
| 255 |
+
"vue/array-bracket-newline": "off",
|
| 256 |
+
"vue/array-bracket-spacing": "off",
|
| 257 |
+
"vue/array-element-newline": "off",
|
| 258 |
+
"vue/arrow-spacing": "off",
|
| 259 |
+
"vue/block-spacing": "off",
|
| 260 |
+
"vue/block-tag-newline": "off",
|
| 261 |
+
"vue/brace-style": "off",
|
| 262 |
+
"vue/comma-dangle": "off",
|
| 263 |
+
"vue/comma-spacing": "off",
|
| 264 |
+
"vue/comma-style": "off",
|
| 265 |
+
"vue/dot-location": "off",
|
| 266 |
+
"vue/func-call-spacing": "off",
|
| 267 |
+
"vue/html-closing-bracket-newline": "off",
|
| 268 |
+
"vue/html-closing-bracket-spacing": "off",
|
| 269 |
+
"vue/html-end-tags": "off",
|
| 270 |
+
"vue/html-indent": "off",
|
| 271 |
+
"vue/html-quotes": "off",
|
| 272 |
+
"vue/key-spacing": "off",
|
| 273 |
+
"vue/keyword-spacing": "off",
|
| 274 |
+
"vue/max-attributes-per-line": "off",
|
| 275 |
+
"vue/multiline-html-element-content-newline": "off",
|
| 276 |
+
"vue/multiline-ternary": "off",
|
| 277 |
+
"vue/mustache-interpolation-spacing": "off",
|
| 278 |
+
"vue/no-extra-parens": "off",
|
| 279 |
+
"vue/no-multi-spaces": "off",
|
| 280 |
+
"vue/no-spaces-around-equal-signs-in-attribute": "off",
|
| 281 |
+
"vue/object-curly-newline": "off",
|
| 282 |
+
"vue/object-curly-spacing": "off",
|
| 283 |
+
"vue/object-property-newline": "off",
|
| 284 |
+
"vue/operator-linebreak": "off",
|
| 285 |
+
"vue/quote-props": "off",
|
| 286 |
+
"vue/script-indent": "off",
|
| 287 |
+
"vue/singleline-html-element-content-newline": "off",
|
| 288 |
+
"vue/space-in-parens": "off",
|
| 289 |
+
"vue/space-infix-ops": "off",
|
| 290 |
+
"vue/space-unary-ops": "off",
|
| 291 |
+
"vue/template-curly-spacing": "off",
|
| 292 |
+
|
| 293 |
+
...(includeDeprecated && {
|
| 294 |
+
// Removed in version 0.10.0.
|
| 295 |
+
// https://eslint.org/docs/latest/rules/space-unary-word-ops
|
| 296 |
+
"space-unary-word-ops": "off",
|
| 297 |
+
|
| 298 |
+
// Removed in version 1.0.0.
|
| 299 |
+
// https://github.com/eslint/eslint/issues/1898
|
| 300 |
+
"generator-star": "off",
|
| 301 |
+
"no-comma-dangle": "off",
|
| 302 |
+
"no-reserved-keys": "off",
|
| 303 |
+
"no-space-before-semi": "off",
|
| 304 |
+
"no-wrap-func": "off",
|
| 305 |
+
"space-after-function-name": "off",
|
| 306 |
+
"space-before-function-parentheses": "off",
|
| 307 |
+
"space-in-brackets": "off",
|
| 308 |
+
|
| 309 |
+
// Removed in version 2.0.0.
|
| 310 |
+
// https://github.com/eslint/eslint/issues/5032
|
| 311 |
+
"no-arrow-condition": "off",
|
| 312 |
+
"space-after-keywords": "off",
|
| 313 |
+
"space-before-keywords": "off",
|
| 314 |
+
"space-return-throw-case": "off",
|
| 315 |
+
|
| 316 |
+
// Deprecated since version 3.3.0.
|
| 317 |
+
// https://eslint.org/docs/rules/no-spaced-func
|
| 318 |
+
"no-spaced-func": "off",
|
| 319 |
+
|
| 320 |
+
// Deprecated since version 4.0.0.
|
| 321 |
+
// https://github.com/eslint/eslint/pull/8286
|
| 322 |
+
"indent-legacy": "off",
|
| 323 |
+
|
| 324 |
+
// Deprecated since version 8.53.0.
|
| 325 |
+
// https://eslint.org/blog/2023/10/deprecating-formatting-rules/
|
| 326 |
+
"array-bracket-newline": "off",
|
| 327 |
+
"array-bracket-spacing": "off",
|
| 328 |
+
"array-element-newline": "off",
|
| 329 |
+
"arrow-parens": "off",
|
| 330 |
+
"arrow-spacing": "off",
|
| 331 |
+
"block-spacing": "off",
|
| 332 |
+
"brace-style": "off",
|
| 333 |
+
"comma-dangle": "off",
|
| 334 |
+
"comma-spacing": "off",
|
| 335 |
+
"comma-style": "off",
|
| 336 |
+
"computed-property-spacing": "off",
|
| 337 |
+
"dot-location": "off",
|
| 338 |
+
"eol-last": "off",
|
| 339 |
+
"func-call-spacing": "off",
|
| 340 |
+
"function-call-argument-newline": "off",
|
| 341 |
+
"function-paren-newline": "off",
|
| 342 |
+
"generator-star-spacing": "off",
|
| 343 |
+
"implicit-arrow-linebreak": "off",
|
| 344 |
+
"indent": "off",
|
| 345 |
+
"jsx-quotes": "off",
|
| 346 |
+
"key-spacing": "off",
|
| 347 |
+
"keyword-spacing": "off",
|
| 348 |
+
"linebreak-style": "off",
|
| 349 |
+
"lines-around-comment": specialRule,
|
| 350 |
+
"max-len": specialRule,
|
| 351 |
+
"max-statements-per-line": "off",
|
| 352 |
+
"multiline-ternary": "off",
|
| 353 |
+
"new-parens": "off",
|
| 354 |
+
"newline-per-chained-call": "off",
|
| 355 |
+
"no-confusing-arrow": specialRule,
|
| 356 |
+
"no-extra-parens": "off",
|
| 357 |
+
"no-extra-semi": "off",
|
| 358 |
+
"no-floating-decimal": "off",
|
| 359 |
+
"no-mixed-operators": specialRule,
|
| 360 |
+
"no-mixed-spaces-and-tabs": "off",
|
| 361 |
+
"no-multi-spaces": "off",
|
| 362 |
+
"no-multiple-empty-lines": "off",
|
| 363 |
+
"no-tabs": specialRule,
|
| 364 |
+
"no-trailing-spaces": "off",
|
| 365 |
+
"no-whitespace-before-property": "off",
|
| 366 |
+
"nonblock-statement-body-position": "off",
|
| 367 |
+
"object-curly-newline": "off",
|
| 368 |
+
"object-curly-spacing": "off",
|
| 369 |
+
"object-property-newline": "off",
|
| 370 |
+
"one-var-declaration-per-line": "off",
|
| 371 |
+
"operator-linebreak": "off",
|
| 372 |
+
"padded-blocks": "off",
|
| 373 |
+
"quote-props": "off",
|
| 374 |
+
"quotes": specialRule,
|
| 375 |
+
"rest-spread-spacing": "off",
|
| 376 |
+
"semi": "off",
|
| 377 |
+
"semi-spacing": "off",
|
| 378 |
+
"semi-style": "off",
|
| 379 |
+
"space-before-blocks": "off",
|
| 380 |
+
"space-before-function-paren": "off",
|
| 381 |
+
"space-in-parens": "off",
|
| 382 |
+
"space-infix-ops": "off",
|
| 383 |
+
"space-unary-ops": "off",
|
| 384 |
+
"switch-colon-spacing": "off",
|
| 385 |
+
"template-curly-spacing": "off",
|
| 386 |
+
"template-tag-spacing": "off",
|
| 387 |
+
"wrap-iife": "off",
|
| 388 |
+
"wrap-regex": "off",
|
| 389 |
+
"yield-star-spacing": "off",
|
| 390 |
+
|
| 391 |
+
// Deprecated since version 7.0.0.
|
| 392 |
+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/CHANGELOG.md#700---2017-05-06
|
| 393 |
+
"react/jsx-space-before-closing": "off",
|
| 394 |
+
}),
|
| 395 |
+
};
|
node_modules/eslint-config-prettier/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "eslint-config-prettier",
|
| 3 |
+
"version": "10.1.8",
|
| 4 |
+
"type": "commonjs",
|
| 5 |
+
"description": "Turns off all rules that are unnecessary or might conflict with Prettier.",
|
| 6 |
+
"repository": "prettier/eslint-config-prettier",
|
| 7 |
+
"homepage": "https://github.com/prettier/eslint-config-prettier#readme",
|
| 8 |
+
"author": "Simon Lydell",
|
| 9 |
+
"maintainers": [
|
| 10 |
+
"JounQin (https://www.1stG.me) <admin@1stg.me>"
|
| 11 |
+
],
|
| 12 |
+
"funding": "https://opencollective.com/eslint-config-prettier",
|
| 13 |
+
"license": "MIT",
|
| 14 |
+
"bin": "bin/cli.js",
|
| 15 |
+
"main": "index.js",
|
| 16 |
+
"types": "index.d.ts",
|
| 17 |
+
"exports": {
|
| 18 |
+
".": {
|
| 19 |
+
"types": "./index.d.ts",
|
| 20 |
+
"default": "./index.js"
|
| 21 |
+
},
|
| 22 |
+
"./flat": {
|
| 23 |
+
"types": "./flat.d.ts",
|
| 24 |
+
"default": "./flat.js"
|
| 25 |
+
},
|
| 26 |
+
"./prettier": {
|
| 27 |
+
"types": "./prettier.d.ts",
|
| 28 |
+
"default": "./prettier.js"
|
| 29 |
+
},
|
| 30 |
+
"./package.json": "./package.json"
|
| 31 |
+
},
|
| 32 |
+
"files": [
|
| 33 |
+
"bin",
|
| 34 |
+
"flat.d.ts",
|
| 35 |
+
"flat.js",
|
| 36 |
+
"index.d.ts",
|
| 37 |
+
"index.js",
|
| 38 |
+
"prettier.d.ts",
|
| 39 |
+
"prettier.js"
|
| 40 |
+
],
|
| 41 |
+
"keywords": [
|
| 42 |
+
"eslint",
|
| 43 |
+
"eslintconfig",
|
| 44 |
+
"eslint-config",
|
| 45 |
+
"eslint-prettier",
|
| 46 |
+
"prettier"
|
| 47 |
+
],
|
| 48 |
+
"peerDependencies": {
|
| 49 |
+
"eslint": ">=7.0.0"
|
| 50 |
+
}
|
| 51 |
+
}
|
node_modules/eslint-config-prettier/prettier.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export const rules: Record<string, 0>;
|
node_modules/eslint-config-prettier/prettier.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
|
| 3 |
+
exports.rules = {
|
| 4 |
+
// These are safe to use as long as the `"prettier/prettier"` rule from
|
| 5 |
+
// eslint-plugin-prettier isn’t enabled.
|
| 6 |
+
// These are also included in `"plugin:prettier/recommended"`:
|
| 7 |
+
// https://github.com/prettier/eslint-plugin-prettier#recommended-configuration
|
| 8 |
+
"arrow-body-style": 0,
|
| 9 |
+
"prefer-arrow-callback": 0,
|
| 10 |
+
};
|
node_modules/eslint-plugin-prettier/LICENSE.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright © 2017 Andres Suarez and Teddy Katz
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person
|
| 6 |
+
obtaining a copy of this software and associated documentation
|
| 7 |
+
files (the “Software”), to deal in the Software without
|
| 8 |
+
restriction, including without limitation the rights to use,
|
| 9 |
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the
|
| 11 |
+
Software is furnished to do so, subject to the following
|
| 12 |
+
conditions:
|
| 13 |
+
|
| 14 |
+
The above copyright notice and this permission notice shall be
|
| 15 |
+
included in all copies or substantial portions of the Software.
|
| 16 |
+
|
| 17 |
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
| 18 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
| 19 |
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 20 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
| 21 |
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 22 |
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 23 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 24 |
+
OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/eslint-plugin-prettier/README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# eslint-plugin-prettier [](https://github.com/prettier/eslint-plugin-prettier/actions?query=workflow%3ACI+branch%3Amain)
|
| 2 |
+
|
| 3 |
+
Runs [Prettier](https://github.com/prettier/prettier) as an [ESLint](https://eslint.org) rule and reports differences as individual ESLint issues.
|
| 4 |
+
|
| 5 |
+
If your desired formatting does not match Prettier’s output, you should use a different tool such as [prettier-eslint](https://github.com/prettier/prettier-eslint) instead.
|
| 6 |
+
|
| 7 |
+
Please read [Integrating with linters](https://prettier.io/docs/en/integrating-with-linters.html) before installing.
|
| 8 |
+
|
| 9 |
+
## TOC <!-- omit in toc -->
|
| 10 |
+
|
| 11 |
+
- [Sample](#sample)
|
| 12 |
+
- [Installation](#installation)
|
| 13 |
+
- [Configuration (legacy: `.eslintrc*`)](#configuration-legacy-eslintrc)
|
| 14 |
+
- [Configuration (new: `eslint.config.js`)](#configuration-new-eslintconfigjs)
|
| 15 |
+
- [`Svelte` support](#svelte-support)
|
| 16 |
+
- [`arrow-body-style` and `prefer-arrow-callback` issue](#arrow-body-style-and-prefer-arrow-callback-issue)
|
| 17 |
+
- [Options](#options)
|
| 18 |
+
- [Sponsors](#sponsors)
|
| 19 |
+
- [Backers](#backers)
|
| 20 |
+
- [Contributing](#contributing)
|
| 21 |
+
- [Changelog](#changelog)
|
| 22 |
+
- [License](#license)
|
| 23 |
+
|
| 24 |
+
## Sample
|
| 25 |
+
|
| 26 |
+
```js
|
| 27 |
+
error: Insert `,` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:22:25:
|
| 28 |
+
20 | import {
|
| 29 |
+
21 | observeActiveEditorsDebounced,
|
| 30 |
+
> 22 | editorChangesDebounced
|
| 31 |
+
| ^
|
| 32 |
+
23 | } from './debounced';;
|
| 33 |
+
24 |
|
| 34 |
+
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:23:21:
|
| 38 |
+
21 | observeActiveEditorsDebounced,
|
| 39 |
+
22 | editorChangesDebounced
|
| 40 |
+
> 23 | } from './debounced';;
|
| 41 |
+
| ^
|
| 42 |
+
24 |
|
| 43 |
+
25 | import {observableFromSubscribeFunction} from '../commons-node/event';
|
| 44 |
+
26 | import {cacheWhileSubscribed} from '../commons-node/observable';
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
2 errors found.
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
> `./node_modules/.bin/eslint --format codeframe pkg/commons-atom/ActiveEditorRegistry.js` (code from [nuclide](https://github.com/facebook/nuclide)).
|
| 51 |
+
|
| 52 |
+
## Installation
|
| 53 |
+
|
| 54 |
+
```sh
|
| 55 |
+
npm install --save-dev eslint-plugin-prettier eslint-config-prettier
|
| 56 |
+
npm install --save-dev --save-exact prettier
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._** _You must install these yourself._
|
| 60 |
+
|
| 61 |
+
This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect potential bugs. If another active ESLint rule disagrees with `prettier` about how code should be formatted, it will be impossible to avoid lint errors. Our recommended configuration automatically enables [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) to disable all formatting-related ESLint rules.
|
| 62 |
+
|
| 63 |
+
## Configuration (legacy: `.eslintrc*`)
|
| 64 |
+
|
| 65 |
+
For [legacy configuration](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated), this plugin ships with a `plugin:prettier/recommended` config that sets up both `eslint-plugin-prettier` and [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) in one go.
|
| 66 |
+
|
| 67 |
+
Add `plugin:prettier/recommended` as the _last_ item in the extends array in your `.eslintrc*` config file, so that `eslint-config-prettier` has the opportunity to override other configs:
|
| 68 |
+
|
| 69 |
+
```json
|
| 70 |
+
{
|
| 71 |
+
"extends": ["plugin:prettier/recommended"]
|
| 72 |
+
}
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
This will:
|
| 76 |
+
|
| 77 |
+
- Enable the `prettier/prettier` rule.
|
| 78 |
+
- Disable the `arrow-body-style` and `prefer-arrow-callback` rules which are problematic with this plugin - see the below for why.
|
| 79 |
+
- Enable the `eslint-config-prettier` config which will turn off ESLint rules that conflict with Prettier.
|
| 80 |
+
|
| 81 |
+
## Configuration (new: `eslint.config.js`)
|
| 82 |
+
|
| 83 |
+
For [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new), this plugin ships with an `eslint-plugin-prettier/recommended` config that sets up both `eslint-plugin-prettier` and [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) in one go.
|
| 84 |
+
|
| 85 |
+
Import `eslint-plugin-prettier/recommended` and add it as the _last_ item in the configuration array in your `eslint.config.js` file so that `eslint-config-prettier` has the opportunity to override other configs:
|
| 86 |
+
|
| 87 |
+
```js
|
| 88 |
+
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
|
| 89 |
+
|
| 90 |
+
module.exports = [
|
| 91 |
+
// Any other config imports go at the top
|
| 92 |
+
eslintPluginPrettierRecommended,
|
| 93 |
+
];
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
This will:
|
| 97 |
+
|
| 98 |
+
- Enable the `prettier/prettier` rule.
|
| 99 |
+
- Disable the `arrow-body-style` and `prefer-arrow-callback` rules which are problematic with this plugin - see the below for why.
|
| 100 |
+
- Enable the `eslint-config-prettier` config which will turn off ESLint rules that conflict with Prettier.
|
| 101 |
+
|
| 102 |
+
## `Svelte` support
|
| 103 |
+
|
| 104 |
+
We recommend to use [`eslint-plugin-svelte`](https://github.com/ota-meshi/eslint-plugin-svelte) instead of [`eslint-plugin-svelte3`](https://github.com/sveltejs/eslint-plugin-svelte3) because `eslint-plugin-svelte` has a correct [`eslint-svelte-parser`](https://github.com/ota-meshi/svelte-eslint-parser) instead of hacking.
|
| 105 |
+
|
| 106 |
+
When use with `eslint-plugin-svelte3`, `eslint-plugin-prettier` will just ignore the text passed by `eslint-plugin-svelte3`, because the text has been modified.
|
| 107 |
+
|
| 108 |
+
If you still decide to use `eslint-plugin-svelte3`, you'll need to run `prettier --write *.svelte` manually.
|
| 109 |
+
|
| 110 |
+
## `arrow-body-style` and `prefer-arrow-callback` issue
|
| 111 |
+
|
| 112 |
+
If you use [arrow-body-style](https://eslint.org/docs/rules/arrow-body-style) or [prefer-arrow-callback](https://eslint.org/docs/rules/prefer-arrow-callback) together with the `prettier/prettier` rule from this plugin, you can in some cases end up with invalid code due to a bug in ESLint’s autofix – see [issue #65](https://github.com/prettier/eslint-plugin-prettier/issues/65).
|
| 113 |
+
|
| 114 |
+
For this reason, it’s recommended to turn off these rules. The `plugin:prettier/recommended` config does that for you.
|
| 115 |
+
|
| 116 |
+
You _can_ still use these rules together with this plugin if you want, because the bug does not occur _all the time._ But if you do, you need to keep in mind that you might end up with invalid code, where you manually have to insert a missing closing parenthesis to get going again.
|
| 117 |
+
|
| 118 |
+
If you’re fixing large of amounts of previously unformatted code, consider temporarily disabling the `prettier/prettier` rule and running `eslint --fix` and `prettier --write` separately.
|
| 119 |
+
|
| 120 |
+
## Options
|
| 121 |
+
|
| 122 |
+
> Note: While it is possible to pass options to Prettier via your ESLint configuration file, it is not recommended because editor extensions such as `prettier-atom` and `prettier-vscode` **will** read [`.prettierrc`](https://prettier.io/docs/en/configuration.html), but **won't** read settings from ESLint, which can lead to an inconsistent experience.
|
| 123 |
+
|
| 124 |
+
- The first option:
|
| 125 |
+
- An object representing [options](https://prettier.io/docs/en/options.html) that will be passed into prettier. Example:
|
| 126 |
+
|
| 127 |
+
```json
|
| 128 |
+
{
|
| 129 |
+
"prettier/prettier": [
|
| 130 |
+
"error",
|
| 131 |
+
{
|
| 132 |
+
"singleQuote": true,
|
| 133 |
+
"parser": "flow"
|
| 134 |
+
}
|
| 135 |
+
]
|
| 136 |
+
}
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
NB: This option will merge and override any config set with `.prettierrc` files
|
| 140 |
+
|
| 141 |
+
- The second option:
|
| 142 |
+
- An object with the following options
|
| 143 |
+
- `usePrettierrc`: Enables loading of the Prettier configuration file, (default: `true`). May be useful if you are using multiple tools that conflict with each other, or do not wish to mix your ESLint settings with your Prettier configuration. And also, it is possible to run prettier without loading the prettierrc config file [via the CLI's --no-config option](https://prettier.io/docs/en/cli.html#--no-config) or through the API by [calling prettier.format() without passing through the options generated by calling resolveConfig](https://prettier.io/docs/en/api.html#prettierresolveconfigfilepath--options).
|
| 144 |
+
|
| 145 |
+
```json
|
| 146 |
+
{
|
| 147 |
+
"prettier/prettier": [
|
| 148 |
+
"error",
|
| 149 |
+
{},
|
| 150 |
+
{
|
| 151 |
+
"usePrettierrc": false
|
| 152 |
+
}
|
| 153 |
+
]
|
| 154 |
+
}
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
- `fileInfoOptions`: Options that are passed to [prettier.getFileInfo](https://prettier.io/docs/en/api.html#prettiergetfileinfofilepath--options) to decide whether a file needs to be formatted. Can be used for example to opt-out from ignoring files located in `node_modules` directories.
|
| 158 |
+
|
| 159 |
+
```json
|
| 160 |
+
{
|
| 161 |
+
"prettier/prettier": [
|
| 162 |
+
"error",
|
| 163 |
+
{},
|
| 164 |
+
{
|
| 165 |
+
"fileInfoOptions": {
|
| 166 |
+
"withNodeModules": true
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
]
|
| 170 |
+
}
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
- The rule is auto fixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
|
| 174 |
+
|
| 175 |
+
---
|
| 176 |
+
|
| 177 |
+
## Sponsors
|
| 178 |
+
|
| 179 |
+
| @prettier/plugin-eslint | eslint-config-prettier | eslint-plugin-prettier | prettier-eslint | prettier-eslint-cli |
|
| 180 |
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 181 |
+
| [](https://opencollective.com/prettier-plugin-eslint) | [](https://opencollective.com/eslint-config-prettier) | [](https://opencollective.com/rxts) | [](https://opencollective.com/prettier-eslint) | [](https://opencollective.com/prettier-eslint-cli) |
|
| 182 |
+
|
| 183 |
+
## Backers
|
| 184 |
+
|
| 185 |
+
| @prettier/plugin-eslint | eslint-config-prettier | eslint-plugin-prettier | prettier-eslint | prettier-eslint-cli |
|
| 186 |
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| 187 |
+
| [](https://opencollective.com/prettier-plugin-eslint) | [](https://opencollective.com/eslint-config-prettier) | [](https://opencollective.com/rxts) | [](https://opencollective.com/prettier-eslint) | [](https://opencollective.com/prettier-eslint-cli) |
|
| 188 |
+
|
| 189 |
+
## Contributing
|
| 190 |
+
|
| 191 |
+
See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/main/CONTRIBUTING.md)
|
| 192 |
+
|
| 193 |
+
## Changelog
|
| 194 |
+
|
| 195 |
+
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
|
| 196 |
+
|
| 197 |
+
## License
|
| 198 |
+
|
| 199 |
+
[MIT](http://opensource.org/licenses/MIT)
|
node_modules/eslint-plugin-prettier/eslint-plugin-prettier.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { ESLint } from 'eslint';
|
| 2 |
+
|
| 3 |
+
declare const eslintPluginPrettier: ESLint.Plugin;
|
| 4 |
+
|
| 5 |
+
export = eslintPluginPrettier;
|
node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @file Runs `prettier` as an ESLint rule.
|
| 3 |
+
* @author Andres Suarez
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
// @ts-check
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @import {AST, ESLint, Linter, Rule, SourceCode} from 'eslint'
|
| 10 |
+
* @import {Position} from 'estree'
|
| 11 |
+
* @import {FileInfoOptions, Options as PrettierOptions} from 'prettier'
|
| 12 |
+
* @import {Difference} from 'prettier-linter-helpers'
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* @typedef {PrettierOptions & {
|
| 17 |
+
* onDiskFilepath: string;
|
| 18 |
+
* parserMeta?: ESLint.ObjectMetaProperties['meta'];
|
| 19 |
+
* parserPath?: string;
|
| 20 |
+
* usePrettierrc?: boolean;
|
| 21 |
+
* }} Options
|
| 22 |
+
*
|
| 23 |
+
*
|
| 24 |
+
* @typedef {(
|
| 25 |
+
* source: string,
|
| 26 |
+
* options: Options,
|
| 27 |
+
* fileInfoOptions: FileInfoOptions,
|
| 28 |
+
* ) => string} PrettierFormat
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
'use strict';
|
| 32 |
+
|
| 33 |
+
// ------------------------------------------------------------------------------
|
| 34 |
+
// Requirements
|
| 35 |
+
// ------------------------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
const {
|
| 38 |
+
showInvisibles,
|
| 39 |
+
generateDifferences,
|
| 40 |
+
} = require('prettier-linter-helpers');
|
| 41 |
+
const { name, version } = require('./package.json');
|
| 42 |
+
|
| 43 |
+
// ------------------------------------------------------------------------------
|
| 44 |
+
// Constants
|
| 45 |
+
// ------------------------------------------------------------------------------
|
| 46 |
+
|
| 47 |
+
const { INSERT, DELETE, REPLACE } = generateDifferences;
|
| 48 |
+
|
| 49 |
+
// ------------------------------------------------------------------------------
|
| 50 |
+
// Privates
|
| 51 |
+
// ------------------------------------------------------------------------------
|
| 52 |
+
|
| 53 |
+
// Lazily-loaded Prettier.
|
| 54 |
+
/** @type {PrettierFormat} */
|
| 55 |
+
let prettierFormat;
|
| 56 |
+
|
| 57 |
+
// ------------------------------------------------------------------------------
|
| 58 |
+
// Rule Definition
|
| 59 |
+
// ------------------------------------------------------------------------------
|
| 60 |
+
|
| 61 |
+
/** @type {WeakMap<SourceCode, number[]>} */
|
| 62 |
+
const lineIndexesCache = new WeakMap();
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Ponyfill `sourceCode.getLocFromIndex` when it's unavailable.
|
| 66 |
+
*
|
| 67 |
+
* See also `getLocFromIndex` in `@eslint/js`.
|
| 68 |
+
*
|
| 69 |
+
* @param {SourceCode} sourceCode
|
| 70 |
+
* @param {number} index
|
| 71 |
+
* @returns {Position}
|
| 72 |
+
*/
|
| 73 |
+
function getLocFromIndex(sourceCode, index) {
|
| 74 |
+
if (typeof sourceCode.getLocFromIndex === 'function') {
|
| 75 |
+
return sourceCode.getLocFromIndex(index);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
let lineIndexes = lineIndexesCache.get(sourceCode);
|
| 79 |
+
if (!lineIndexes) {
|
| 80 |
+
lineIndexes = [...sourceCode.text.matchAll(/\r?\n/g)].map(
|
| 81 |
+
match => match.index,
|
| 82 |
+
);
|
| 83 |
+
// first line in the file starts at byte offset 0
|
| 84 |
+
lineIndexes.unshift(0);
|
| 85 |
+
lineIndexesCache.set(sourceCode, lineIndexes);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
let line = 0;
|
| 89 |
+
while (line + 1 < lineIndexes.length && lineIndexes[line + 1] < index) {
|
| 90 |
+
line += 1;
|
| 91 |
+
}
|
| 92 |
+
const column = index - lineIndexes[line];
|
| 93 |
+
|
| 94 |
+
return { line: line + 1, column };
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Reports a difference.
|
| 99 |
+
*
|
| 100 |
+
* @param {Rule.RuleContext} context - The ESLint rule context.
|
| 101 |
+
* @param {Difference} difference - The difference object.
|
| 102 |
+
* @returns {void}
|
| 103 |
+
*/
|
| 104 |
+
function reportDifference(context, difference) {
|
| 105 |
+
const { operation, offset } = difference;
|
| 106 |
+
const insertText = 'insertText' in difference ? difference.insertText : '';
|
| 107 |
+
const deleteText = 'deleteText' in difference ? difference.deleteText : '';
|
| 108 |
+
/** @type {AST.Range} */
|
| 109 |
+
const range = [offset, offset + deleteText.length];
|
| 110 |
+
// `context.getSourceCode()` was deprecated in ESLint v8.40.0 and replaced
|
| 111 |
+
// with the `sourceCode` property.
|
| 112 |
+
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
|
| 113 |
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
| 114 |
+
|
| 115 |
+
const [start, end] = range.map(index => getLocFromIndex(sourceCode, index));
|
| 116 |
+
|
| 117 |
+
context.report({
|
| 118 |
+
messageId: operation,
|
| 119 |
+
data: {
|
| 120 |
+
deleteText: showInvisibles(deleteText),
|
| 121 |
+
insertText: showInvisibles(insertText),
|
| 122 |
+
},
|
| 123 |
+
loc: { start, end },
|
| 124 |
+
fix: fixer => fixer.replaceTextRange(range, insertText),
|
| 125 |
+
});
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
// ------------------------------------------------------------------------------
|
| 129 |
+
// Module Definition
|
| 130 |
+
// ------------------------------------------------------------------------------
|
| 131 |
+
|
| 132 |
+
/** @type {ESLint.Plugin} */
|
| 133 |
+
const eslintPluginPrettier = {
|
| 134 |
+
meta: { name, version },
|
| 135 |
+
configs: {
|
| 136 |
+
recommended: {
|
| 137 |
+
extends: ['prettier'],
|
| 138 |
+
plugins: ['prettier'],
|
| 139 |
+
rules: {
|
| 140 |
+
'prettier/prettier': 'error',
|
| 141 |
+
'arrow-body-style': 'off',
|
| 142 |
+
'prefer-arrow-callback': 'off',
|
| 143 |
+
},
|
| 144 |
+
},
|
| 145 |
+
},
|
| 146 |
+
rules: {
|
| 147 |
+
prettier: {
|
| 148 |
+
meta: {
|
| 149 |
+
docs: {
|
| 150 |
+
url: 'https://github.com/prettier/eslint-plugin-prettier#options',
|
| 151 |
+
},
|
| 152 |
+
type: 'layout',
|
| 153 |
+
fixable: 'code',
|
| 154 |
+
schema: [
|
| 155 |
+
// Prettier options:
|
| 156 |
+
{
|
| 157 |
+
type: 'object',
|
| 158 |
+
properties: {},
|
| 159 |
+
additionalProperties: true,
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
type: 'object',
|
| 163 |
+
properties: {
|
| 164 |
+
usePrettierrc: { type: 'boolean' },
|
| 165 |
+
fileInfoOptions: {
|
| 166 |
+
type: 'object',
|
| 167 |
+
properties: {},
|
| 168 |
+
additionalProperties: true,
|
| 169 |
+
},
|
| 170 |
+
},
|
| 171 |
+
additionalProperties: false,
|
| 172 |
+
},
|
| 173 |
+
],
|
| 174 |
+
messages: {
|
| 175 |
+
[INSERT]: 'Insert `{{ insertText }}`',
|
| 176 |
+
[DELETE]: 'Delete `{{ deleteText }}`',
|
| 177 |
+
[REPLACE]: 'Replace `{{ deleteText }}` with `{{ insertText }}`',
|
| 178 |
+
},
|
| 179 |
+
},
|
| 180 |
+
create(context) {
|
| 181 |
+
const options = /** @type {Options | undefined} */ (context.options[1]);
|
| 182 |
+
const usePrettierrc = !options || options.usePrettierrc !== false;
|
| 183 |
+
/** @type {FileInfoOptions} */
|
| 184 |
+
const fileInfoOptions = options?.fileInfoOptions || {};
|
| 185 |
+
|
| 186 |
+
// `context.getSourceCode()` was deprecated in ESLint v8.40.0 and replaced
|
| 187 |
+
// with the `sourceCode` property.
|
| 188 |
+
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
|
| 189 |
+
const sourceCode = /** @type {SourceCode} */ (
|
| 190 |
+
context.sourceCode ?? context.getSourceCode()
|
| 191 |
+
);
|
| 192 |
+
// `context.getFilename()` was deprecated in ESLint v8.40.0 and replaced
|
| 193 |
+
// with the `filename` property.
|
| 194 |
+
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
|
| 195 |
+
const filepath = context.filename ?? context.getFilename();
|
| 196 |
+
|
| 197 |
+
// Processors that extract content from a file, such as the markdown
|
| 198 |
+
// plugin extracting fenced code blocks may choose to specify virtual
|
| 199 |
+
// file paths. If this is the case then we need to resolve prettier
|
| 200 |
+
// config and file info using the on-disk path instead of the virtual
|
| 201 |
+
// path.
|
| 202 |
+
// `context.getPhysicalFilename()` was deprecated in ESLint v8.40.0 and replaced
|
| 203 |
+
// with the `physicalFilename` property.
|
| 204 |
+
// TODO: Only use property when our eslint peerDependency is >=8.40.0.
|
| 205 |
+
const onDiskFilepath =
|
| 206 |
+
context.physicalFilename ?? context.getPhysicalFilename();
|
| 207 |
+
const source = sourceCode.text;
|
| 208 |
+
|
| 209 |
+
return {
|
| 210 |
+
/** @param {unknown} node */
|
| 211 |
+
[sourceCode.ast.type](node) {
|
| 212 |
+
if (!prettierFormat) {
|
| 213 |
+
// Prettier is expensive to load, so only load it if needed.
|
| 214 |
+
prettierFormat = /** @type {PrettierFormat} */ (
|
| 215 |
+
require('synckit').createSyncFn(require.resolve('./worker.mjs'))
|
| 216 |
+
);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/** @type {PrettierOptions} */
|
| 220 |
+
const eslintPrettierOptions = context.options[0] || {};
|
| 221 |
+
|
| 222 |
+
const parser = /** @type {Linter.Parser | undefined} */ (
|
| 223 |
+
context.languageOptions?.parser
|
| 224 |
+
);
|
| 225 |
+
|
| 226 |
+
// prettier.format() may throw a SyntaxError if it cannot parse the
|
| 227 |
+
// source code it is given. Usually for JS files this isn't a
|
| 228 |
+
// problem as ESLint will report invalid syntax before trying to
|
| 229 |
+
// pass it to the prettier plugin. However this might be a problem
|
| 230 |
+
// for non-JS languages that are handled by a plugin. Notably Vue
|
| 231 |
+
// files throw an error if they contain unclosed elements, such as
|
| 232 |
+
// `<template><div></template>. In this case report an error at the
|
| 233 |
+
// point at which parsing failed.
|
| 234 |
+
/** @type {string} */
|
| 235 |
+
let prettierSource;
|
| 236 |
+
try {
|
| 237 |
+
prettierSource = prettierFormat(
|
| 238 |
+
source,
|
| 239 |
+
{
|
| 240 |
+
...eslintPrettierOptions,
|
| 241 |
+
filepath,
|
| 242 |
+
onDiskFilepath,
|
| 243 |
+
parserMeta:
|
| 244 |
+
parser &&
|
| 245 |
+
(parser.meta ?? {
|
| 246 |
+
name: parser.name,
|
| 247 |
+
version: parser.version,
|
| 248 |
+
}),
|
| 249 |
+
parserPath: context.parserPath,
|
| 250 |
+
usePrettierrc,
|
| 251 |
+
},
|
| 252 |
+
fileInfoOptions,
|
| 253 |
+
);
|
| 254 |
+
} catch (err) {
|
| 255 |
+
if (!(err instanceof SyntaxError)) {
|
| 256 |
+
throw err;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
let message = 'Parsing error: ' + err.message;
|
| 260 |
+
|
| 261 |
+
const error = /**
|
| 262 |
+
* @type {SyntaxError & {
|
| 263 |
+
* codeFrame: string;
|
| 264 |
+
* loc?: AST.SourceLocation;
|
| 265 |
+
* }}
|
| 266 |
+
*/ (err);
|
| 267 |
+
|
| 268 |
+
// Prettier's message contains a codeframe style preview of the
|
| 269 |
+
// invalid code and the line/column at which the error occurred.
|
| 270 |
+
// ESLint shows those pieces of information elsewhere already so
|
| 271 |
+
// remove them from the message
|
| 272 |
+
if (error.codeFrame) {
|
| 273 |
+
message = message.replace(`\n${error.codeFrame}`, '');
|
| 274 |
+
}
|
| 275 |
+
if (error.loc) {
|
| 276 |
+
message = message.replace(/ \(\d+:\d+\)$/, '');
|
| 277 |
+
context.report({ message, loc: error.loc });
|
| 278 |
+
} else {
|
| 279 |
+
context.report({ message, node });
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
return;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
if (prettierSource == null) {
|
| 286 |
+
return;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
if (source !== prettierSource) {
|
| 290 |
+
const differences = generateDifferences(source, prettierSource);
|
| 291 |
+
|
| 292 |
+
for (const difference of differences) {
|
| 293 |
+
reportDifference(
|
| 294 |
+
/** @type {Rule.RuleContext} */ (context),
|
| 295 |
+
difference,
|
| 296 |
+
);
|
| 297 |
+
}
|
| 298 |
+
}
|
| 299 |
+
},
|
| 300 |
+
};
|
| 301 |
+
},
|
| 302 |
+
},
|
| 303 |
+
},
|
| 304 |
+
};
|
| 305 |
+
|
| 306 |
+
module.exports = eslintPluginPrettier;
|
node_modules/eslint-plugin-prettier/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "eslint-plugin-prettier",
|
| 3 |
+
"version": "5.5.6",
|
| 4 |
+
"description": "Runs prettier as an eslint rule",
|
| 5 |
+
"repository": "https://github.com/prettier/eslint-plugin-prettier.git",
|
| 6 |
+
"homepage": "https://github.com/prettier/eslint-plugin-prettier#readme",
|
| 7 |
+
"author": "Teddy Katz",
|
| 8 |
+
"maintainers": [
|
| 9 |
+
"JounQin <admin@1stg.me> (https://github.com/JounQin)"
|
| 10 |
+
],
|
| 11 |
+
"funding": "https://opencollective.com/eslint-plugin-prettier",
|
| 12 |
+
"license": "MIT",
|
| 13 |
+
"engines": {
|
| 14 |
+
"node": "^14.18.0 || >=16.0.0"
|
| 15 |
+
},
|
| 16 |
+
"main": "eslint-plugin-prettier.js",
|
| 17 |
+
"types": "eslint-plugin-prettier.d.ts",
|
| 18 |
+
"exports": {
|
| 19 |
+
".": {
|
| 20 |
+
"types": "./eslint-plugin-prettier.d.ts",
|
| 21 |
+
"default": "./eslint-plugin-prettier.js"
|
| 22 |
+
},
|
| 23 |
+
"./recommended": {
|
| 24 |
+
"types": "./recommended.d.ts",
|
| 25 |
+
"default": "./recommended.js"
|
| 26 |
+
},
|
| 27 |
+
"./package.json": "./package.json"
|
| 28 |
+
},
|
| 29 |
+
"files": [
|
| 30 |
+
"eslint-plugin-prettier.d.ts",
|
| 31 |
+
"eslint-plugin-prettier.js",
|
| 32 |
+
"recommended.d.ts",
|
| 33 |
+
"recommended.js",
|
| 34 |
+
"worker.mjs"
|
| 35 |
+
],
|
| 36 |
+
"keywords": [
|
| 37 |
+
"eslint",
|
| 38 |
+
"eslintplugin",
|
| 39 |
+
"eslint-plugin",
|
| 40 |
+
"prettier"
|
| 41 |
+
],
|
| 42 |
+
"peerDependencies": {
|
| 43 |
+
"@types/eslint": ">=8.0.0",
|
| 44 |
+
"eslint": ">=8.0.0",
|
| 45 |
+
"eslint-config-prettier": ">= 7.0.0 <10.0.0 || >=10.1.0",
|
| 46 |
+
"prettier": ">=3.0.0"
|
| 47 |
+
},
|
| 48 |
+
"peerDependenciesMeta": {
|
| 49 |
+
"@types/eslint": {
|
| 50 |
+
"optional": true
|
| 51 |
+
},
|
| 52 |
+
"eslint-config-prettier": {
|
| 53 |
+
"optional": true
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
"dependencies": {
|
| 57 |
+
"prettier-linter-helpers": "^1.0.1",
|
| 58 |
+
"synckit": "^0.11.13"
|
| 59 |
+
}
|
| 60 |
+
}
|
node_modules/eslint-plugin-prettier/recommended.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Linter } from 'eslint';
|
| 2 |
+
|
| 3 |
+
// prettier-ignore
|
| 4 |
+
type IfEqual<A, B, X = A, Y = B> =
|
| 5 |
+
(<G>() => G extends A & G | G ? 1 : 2) extends
|
| 6 |
+
(<G>() => G extends B & G | G ? 1 : 2)
|
| 7 |
+
? X
|
| 8 |
+
: Y;
|
| 9 |
+
|
| 10 |
+
declare const recommendedConfig: IfEqual<Linter.Config, Linter.FlatConfig>;
|
| 11 |
+
|
| 12 |
+
export = recommendedConfig;
|
node_modules/eslint-plugin-prettier/recommended.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { rules: configPrettierRules } = require('eslint-config-prettier');
|
| 2 |
+
const {
|
| 3 |
+
rules: configPrettierOverridesRules,
|
| 4 |
+
} = require('eslint-config-prettier/prettier');
|
| 5 |
+
const eslintPluginPrettier = require('./eslint-plugin-prettier');
|
| 6 |
+
|
| 7 |
+
// Merge the contents of eslint-config-prettier into config
|
| 8 |
+
module.exports = {
|
| 9 |
+
name: 'eslint-plugin-prettier/recommended',
|
| 10 |
+
plugins: {
|
| 11 |
+
prettier: eslintPluginPrettier,
|
| 12 |
+
},
|
| 13 |
+
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @ts-check
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* @typedef {PrettierOptions & {
|
| 5 |
+
* onDiskFilepath: string;
|
| 6 |
+
* parserMeta?: ESLint.ObjectMetaProperties['meta'];
|
| 7 |
+
* parserPath?: string;
|
| 8 |
+
* usePrettierrc?: boolean;
|
| 9 |
+
* }} Options
|
| 10 |
+
* @import {FileInfoOptions, Options as PrettierOptions} from 'prettier'
|
| 11 |
+
* @import {ESLint} from 'eslint'
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
import prettier from 'prettier';
|
| 15 |
+
import { runAsWorker } from 'synckit';
|
| 16 |
+
|
| 17 |
+
runAsWorker(
|
| 18 |
+
/**
|
| 19 |
+
* @param {string} source - The source code to format.
|
| 20 |
+
* @param {Options} options - The prettier options.
|
| 21 |
+
* @param {FileInfoOptions} eslintFileInfoOptions - The file info options.
|
| 22 |
+
* @returns {Promise<string | undefined>} The formatted source code.
|
| 23 |
+
*/
|
| 24 |
+
async (
|
| 25 |
+
source,
|
| 26 |
+
{
|
| 27 |
+
filepath,
|
| 28 |
+
onDiskFilepath,
|
| 29 |
+
parserMeta,
|
| 30 |
+
parserPath,
|
| 31 |
+
usePrettierrc,
|
| 32 |
+
...eslintPrettierOptions
|
| 33 |
+
},
|
| 34 |
+
eslintFileInfoOptions,
|
| 35 |
+
) => {
|
| 36 |
+
const prettierRcOptions = usePrettierrc
|
| 37 |
+
? await prettier.resolveConfig(onDiskFilepath, {
|
| 38 |
+
editorconfig: true,
|
| 39 |
+
})
|
| 40 |
+
: null;
|
| 41 |
+
|
| 42 |
+
const { ignored, inferredParser } = await prettier.getFileInfo(
|
| 43 |
+
onDiskFilepath,
|
| 44 |
+
{
|
| 45 |
+
resolveConfig: false,
|
| 46 |
+
withNodeModules: false,
|
| 47 |
+
ignorePath: '.prettierignore',
|
| 48 |
+
...prettierRcOptions,
|
| 49 |
+
...eslintFileInfoOptions,
|
| 50 |
+
},
|
| 51 |
+
);
|
| 52 |
+
|
| 53 |
+
// Skip if file is ignored using a .prettierignore file
|
| 54 |
+
if (ignored) {
|
| 55 |
+
return;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
const initialOptions = { parser: inferredParser ?? 'babel' };
|
| 59 |
+
|
| 60 |
+
// ESLint supports processors that let you extract and lint JS
|
| 61 |
+
// fragments within a non-JS language. In the cases where prettier
|
| 62 |
+
// supports the same language as a processor, we want to process
|
| 63 |
+
// the provided source code as javascript (as ESLint provides the
|
| 64 |
+
// rules with fragments of JS) instead of guessing the parser
|
| 65 |
+
// based off the filename. Otherwise, for instance, on a .md file we
|
| 66 |
+
// end up trying to run prettier over a fragment of JS using the
|
| 67 |
+
// markdown parser, which throws an error.
|
| 68 |
+
// Processors may set virtual filenames for these extracted blocks.
|
| 69 |
+
// If they do so then we want to trust the file extension they
|
| 70 |
+
// provide, and no override is needed.
|
| 71 |
+
// If the processor does not set any virtual filename (signified by
|
| 72 |
+
// `filepath` and `onDiskFilepath` being equal) AND we can't
|
| 73 |
+
// infer the parser from the filename, either because no filename
|
| 74 |
+
// was provided or because there is no parser found for the
|
| 75 |
+
// filename, use javascript.
|
| 76 |
+
// This is added to the options first, so that
|
| 77 |
+
// prettierRcOptions and eslintPrettierOptions can still override
|
| 78 |
+
// the parser.
|
| 79 |
+
//
|
| 80 |
+
// `parserBlocklist` should contain the list of prettier parser
|
| 81 |
+
// names for file types where:
|
| 82 |
+
// * Prettier supports parsing the file type
|
| 83 |
+
// * There is an ESLint processor that extracts JavaScript snippets
|
| 84 |
+
// from the file type.
|
| 85 |
+
if (filepath === onDiskFilepath) {
|
| 86 |
+
// The following list means the plugin process source into js content
|
| 87 |
+
// but with same filename, so we need to change the parser to `babel`
|
| 88 |
+
// by default.
|
| 89 |
+
// Related ESLint plugins are:
|
| 90 |
+
// 1. `eslint-plugin-graphql` (replacement: `@graphql-eslint/eslint-plugin`)
|
| 91 |
+
// 2. `eslint-plugin-html`
|
| 92 |
+
// 3. `eslint-plugin-markdown@1` (replacement: `eslint-plugin-markdown@2+`)
|
| 93 |
+
// 4. `eslint-plugin-svelte3` (replacement: `eslint-plugin-svelte@2+`)
|
| 94 |
+
let inferParserToBabel = false;
|
| 95 |
+
|
| 96 |
+
switch (inferredParser) {
|
| 97 |
+
// it could be processed by `@graphql-eslint/eslint-plugin` or `eslint-plugin-graphql`
|
| 98 |
+
case 'graphql': {
|
| 99 |
+
if (
|
| 100 |
+
// for `eslint-plugin-graphql`, see https://github.com/apollographql/eslint-plugin-graphql/blob/64c524cd6607358803d5fcb7cead0a383a125ccb/src/index.js#L416
|
| 101 |
+
source.startsWith('ESLintPluginGraphQLFile`')
|
| 102 |
+
) {
|
| 103 |
+
inferParserToBabel = true;
|
| 104 |
+
}
|
| 105 |
+
break;
|
| 106 |
+
}
|
| 107 |
+
case 'html': {
|
| 108 |
+
// it could be processed by `eslint-plugin-html` or correctly parsed by `@html-eslint/parser`
|
| 109 |
+
if (
|
| 110 |
+
(typeof parserMeta !== 'undefined' &&
|
| 111 |
+
parserMeta.name !== '@html-eslint/parser') ||
|
| 112 |
+
(typeof parserPath === 'string' &&
|
| 113 |
+
!/([\\/])@html-eslint\1parser\1/.test(parserPath))
|
| 114 |
+
) {
|
| 115 |
+
inferParserToBabel = true;
|
| 116 |
+
}
|
| 117 |
+
break;
|
| 118 |
+
}
|
| 119 |
+
case 'markdown': {
|
| 120 |
+
// it could be processed by `eslint-plugin-markdown@1` or correctly parsed by `eslint-mdx`
|
| 121 |
+
if (
|
| 122 |
+
(typeof parserMeta !== 'undefined' &&
|
| 123 |
+
parserMeta.name !== 'eslint-mdx') ||
|
| 124 |
+
(typeof parserPath === 'string' &&
|
| 125 |
+
!/([\\/])eslint-mdx\1/.test(parserPath))
|
| 126 |
+
) {
|
| 127 |
+
inferParserToBabel = true;
|
| 128 |
+
}
|
| 129 |
+
break;
|
| 130 |
+
}
|
| 131 |
+
// it could be processed by `@ota-meshi/eslint-plugin-svelte`, `eslint-plugin-svelte` or `eslint-plugin-svelte3`
|
| 132 |
+
case 'svelte': {
|
| 133 |
+
// The `source` would be modified by `eslint-plugin-svelte3`
|
| 134 |
+
if (
|
| 135 |
+
typeof parserPath === 'string' &&
|
| 136 |
+
!/([\\/])svelte-eslint-parser\1/.test(parserPath)
|
| 137 |
+
) {
|
| 138 |
+
// We do not support `eslint-plugin-svelte3`,
|
| 139 |
+
// the users should run `prettier` on `.svelte` files manually
|
| 140 |
+
return;
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
if (inferParserToBabel) {
|
| 146 |
+
initialOptions.parser = 'babel';
|
| 147 |
+
}
|
| 148 |
+
} else {
|
| 149 |
+
// Similar to https://github.com/prettier/stylelint-prettier/pull/22
|
| 150 |
+
// In all of the following cases ESLint extracts a part of a file to
|
| 151 |
+
// be formatted and there exists a prettier parser for the whole file.
|
| 152 |
+
// If you're interested in prettier you'll want a fully formatted file so
|
| 153 |
+
// you're about to run prettier over the whole file anyway.
|
| 154 |
+
// Therefore running prettier over just the style section is wasteful, so
|
| 155 |
+
// skip it.
|
| 156 |
+
const parserBlocklist = [
|
| 157 |
+
'babel',
|
| 158 |
+
'babylon',
|
| 159 |
+
'flow',
|
| 160 |
+
'typescript',
|
| 161 |
+
'vue',
|
| 162 |
+
'markdown',
|
| 163 |
+
'html',
|
| 164 |
+
'mdx',
|
| 165 |
+
'angular',
|
| 166 |
+
'svelte',
|
| 167 |
+
'pug',
|
| 168 |
+
'oxc',
|
| 169 |
+
'oxc-ts',
|
| 170 |
+
'hermes',
|
| 171 |
+
];
|
| 172 |
+
if (parserBlocklist.includes(/** @type {string} */ (inferredParser))) {
|
| 173 |
+
return;
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
/** @type {PrettierOptions} */
|
| 178 |
+
const prettierOptions = {
|
| 179 |
+
...initialOptions,
|
| 180 |
+
...prettierRcOptions,
|
| 181 |
+
...eslintPrettierOptions,
|
| 182 |
+
filepath,
|
| 183 |
+
};
|
| 184 |
+
|
| 185 |
+
return prettier.format(source, prettierOptions);
|
| 186 |
+
},
|
| 187 |
+
);
|
node_modules/eslint-scope/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright JS Foundation and other contributors, https://js.foundation
|
| 2 |
+
Copyright (C) 2012-2013 Yusuke Suzuki (twitter: @Constellation) and other contributors.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
node_modules/eslint-scope/README.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[](https://www.npmjs.com/package/eslint-scope)
|
| 2 |
+
[](https://www.npmjs.com/package/eslint-scope)
|
| 3 |
+
[](https://github.com/eslint/js/actions)
|
| 4 |
+
|
| 5 |
+
# ESLint Scope
|
| 6 |
+
|
| 7 |
+
ESLint Scope is the [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm) scope analyzer used in ESLint. It is a fork of [escope](http://github.com/estools/escope).
|
| 8 |
+
|
| 9 |
+
## Install
|
| 10 |
+
|
| 11 |
+
```
|
| 12 |
+
npm i eslint-scope --save
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
## 📖 Usage
|
| 16 |
+
|
| 17 |
+
To use in an ESM file:
|
| 18 |
+
|
| 19 |
+
```js
|
| 20 |
+
import * as eslintScope from "eslint-scope";
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
To use in a CommonJS file:
|
| 24 |
+
|
| 25 |
+
```js
|
| 26 |
+
const eslintScope = require("eslint-scope");
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
In order to analyze scope, you'll need to have an [ESTree](https://github.com/estree/estree) compliant AST structure to run it on. The primary method is `eslintScope.analyze()`, which takes two arguments:
|
| 30 |
+
|
| 31 |
+
1. `ast` - the ESTree-compliant AST structure to analyze.
|
| 32 |
+
2. `options` (optional) - Options to adjust how the scope is analyzed, including:
|
| 33 |
+
|
| 34 |
+
- `ignoreEval` (default: `false`) - Set to `true` to ignore all `eval()` calls (which would normally create scopes).
|
| 35 |
+
- `nodejsScope` (default: `false`) - Set to `true` to create a top-level function scope needed for CommonJS evaluation.
|
| 36 |
+
- `impliedStrict` (default: `false`) - Set to `true` to evaluate the code in strict mode even outside of modules and without `"use strict"`.
|
| 37 |
+
- `ecmaVersion` (default: `5`) - The version of ECMAScript to use to evaluate the code.
|
| 38 |
+
- `sourceType` (default: `"script"`) - The type of JavaScript file to evaluate. Change to `"module"` for ECMAScript module code.
|
| 39 |
+
- `childVisitorKeys` (default: `null`) - An object with visitor key information (like [`eslint-visitor-keys`](https://github.com/eslint/js/tree/main/packages/eslint-visitor-keys)). Without this, `eslint-scope` finds child nodes to visit algorithmically. Providing this option is a performance enhancement.
|
| 40 |
+
- `fallback` (default: `"iteration"`) - The strategy to use when `childVisitorKeys` is not specified. May be a function.
|
| 41 |
+
- `optimistic` (default: `false`) - Set to `true` to enable optimistic scope analysis.
|
| 42 |
+
- `jsx` (default: `false`) - Enables the tracking of JSX components as variable references.
|
| 43 |
+
|
| 44 |
+
Example:
|
| 45 |
+
|
| 46 |
+
```js
|
| 47 |
+
import * as eslintScope from "eslint-scope";
|
| 48 |
+
import * as espree from "espree";
|
| 49 |
+
import estraverse from "estraverse";
|
| 50 |
+
|
| 51 |
+
const options = {
|
| 52 |
+
ecmaVersion: 2022,
|
| 53 |
+
sourceType: "module",
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
const ast = espree.parse(code, { range: true, ...options });
|
| 57 |
+
const scopeManager = eslintScope.analyze(ast, options);
|
| 58 |
+
|
| 59 |
+
const currentScope = scopeManager.acquire(ast); // global scope
|
| 60 |
+
|
| 61 |
+
estraverse.traverse(ast, {
|
| 62 |
+
enter(node, parent) {
|
| 63 |
+
// do stuff
|
| 64 |
+
|
| 65 |
+
if (/Function/.test(node.type)) {
|
| 66 |
+
currentScope = scopeManager.acquire(node); // get current function scope
|
| 67 |
+
}
|
| 68 |
+
},
|
| 69 |
+
leave(node, parent) {
|
| 70 |
+
if (/Function/.test(node.type)) {
|
| 71 |
+
currentScope = currentScope.upper; // set to parent scope
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// do stuff
|
| 75 |
+
},
|
| 76 |
+
});
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
## API
|
| 80 |
+
|
| 81 |
+
The following section describes the API for this package. You can also read [the docs](https://eslint.org/docs/latest/extend/scope-manager-interface).
|
| 82 |
+
|
| 83 |
+
### ScopeManager
|
| 84 |
+
|
| 85 |
+
The `ScopeManager` class is at the core of eslint-scope and is returned when you call `eslintScope.analyze()`. It manages all scopes in a given AST.
|
| 86 |
+
|
| 87 |
+
#### Properties
|
| 88 |
+
|
| 89 |
+
- `scopes` - An array of all scopes.
|
| 90 |
+
- `globalScope` - Reference to the global scope.
|
| 91 |
+
|
| 92 |
+
#### Methods
|
| 93 |
+
|
| 94 |
+
- **`addGlobals(names)`**
|
| 95 |
+
Adds variables to the global scope and resolves references to them.
|
| 96 |
+
- `names` - An array of strings, the names of variables to add to the global scope.
|
| 97 |
+
- Returns: `undefined`.
|
| 98 |
+
|
| 99 |
+
- **`acquire(node, inner)`**
|
| 100 |
+
Acquires the appropriate scope for a given node.
|
| 101 |
+
- `node` - The AST node to acquire the scope from.
|
| 102 |
+
- `inner` - Optional boolean. When `true`, returns the innermost scope, otherwise returns the outermost scope. Default is `false`.
|
| 103 |
+
- Returns: The acquired scope or `null` if no scope is found.
|
| 104 |
+
|
| 105 |
+
- **`acquireAll(node)` (Deprecated)**
|
| 106 |
+
Acquires all scopes for a given node.
|
| 107 |
+
- `node` - The AST node to acquire scopes from.
|
| 108 |
+
- Returns: An array of scopes or `undefined` if none are found.
|
| 109 |
+
|
| 110 |
+
- **`release(node, inner)`**
|
| 111 |
+
Returns the upper scope for a given node.
|
| 112 |
+
- `node` - The AST node to release.
|
| 113 |
+
- `inner` - Optional boolean. When `true`, returns the innermost upper scope, otherwise returns the outermost upper scope. Default is `false`.
|
| 114 |
+
- Returns: The upper scope or `null` if no upper scope exists.
|
| 115 |
+
|
| 116 |
+
- **`getDeclaredVariables(node)`**
|
| 117 |
+
Get variables that are declared by the node.
|
| 118 |
+
- `node` - The AST node to get declarations from.
|
| 119 |
+
- Returns: An array of variable objects declared by the node. If the node doesn't declare any variables, it returns an empty array.
|
| 120 |
+
|
| 121 |
+
- **`isGlobalReturn()`**
|
| 122 |
+
Determines if the global return statement should be allowed.
|
| 123 |
+
- Returns: `true` if the global return is enabled.
|
| 124 |
+
|
| 125 |
+
- **`isModule()` (Deprecated)**
|
| 126 |
+
Checks if the code should be handled as an ECMAScript module.
|
| 127 |
+
- Returns: `true` if the sourceType is "module".
|
| 128 |
+
|
| 129 |
+
- **`isImpliedStrict()` (Deprecated)**
|
| 130 |
+
Checks if implied strict mode is enabled.
|
| 131 |
+
- Returns: `true` if implied strict mode is enabled.
|
| 132 |
+
|
| 133 |
+
- **`isStrictModeSupported()` (Deprecated)**
|
| 134 |
+
Checks if strict mode is supported based on ECMAScript version.
|
| 135 |
+
- Returns: `true` if the ECMAScript version supports strict mode.
|
| 136 |
+
|
| 137 |
+
### Scope Objects
|
| 138 |
+
|
| 139 |
+
Scopes returned by the ScopeManager methods have the following properties:
|
| 140 |
+
|
| 141 |
+
- `type` - The type of scope (e.g., `"function"`, `"block"`, `"global"`).
|
| 142 |
+
- `isStrict` - `true` if this scope is in strict mode.
|
| 143 |
+
- `variables` - Array of variables declared in this scope.
|
| 144 |
+
- `set` - A Map of variable names to Variable objects for variables declared in this scope.
|
| 145 |
+
- `references` - Array of references in this scope.
|
| 146 |
+
- `through` - Array of references in this scope and its child scopes that aren't resolved in this scope or its child scopes.
|
| 147 |
+
- `functionExpressionScope` - `true` if this is a `"function-expression-name"` scope.
|
| 148 |
+
- `variableScope` - Reference to the closest variable scope.
|
| 149 |
+
- `upper` - Reference to the parent scope.
|
| 150 |
+
- `childScopes` - Array of child scopes.
|
| 151 |
+
- `block` - The AST node that created this scope.
|
| 152 |
+
|
| 153 |
+
### GlobalScope
|
| 154 |
+
|
| 155 |
+
The `GlobalScope` class is a specialized scope representing the global execution context. It extends the base `Scope` class with additional functionality for handling implicitly defined global variables.
|
| 156 |
+
|
| 157 |
+
#### Properties
|
| 158 |
+
|
| 159 |
+
- **`implicit`** - Tracks implicitly defined global variables (those used without declaration).
|
| 160 |
+
- `set` - A Map of variable names to Variable objects for implicitly defined globals.
|
| 161 |
+
- `variables` - Array of implicit global Variable objects.
|
| 162 |
+
- `left` - Array of References that need to be linked to the variable they refer to.
|
| 163 |
+
|
| 164 |
+
### Variable Objects
|
| 165 |
+
|
| 166 |
+
Each variable object has the following properties:
|
| 167 |
+
|
| 168 |
+
- `name` - The variable name.
|
| 169 |
+
- `identifiers` - Array of identifier nodes declaring this variable.
|
| 170 |
+
- `references` - Array of references to this variable.
|
| 171 |
+
- `defs` - Array of definition objects for this variable.
|
| 172 |
+
- `scope` - The scope object where this variable is defined.
|
| 173 |
+
|
| 174 |
+
## Contributing
|
| 175 |
+
|
| 176 |
+
Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/js/issues).
|
| 177 |
+
|
| 178 |
+
## Security Policy
|
| 179 |
+
|
| 180 |
+
We work hard to ensure that ESLint Scope is safe for everyone and that security issues are addressed quickly and responsibly. Read the full [security policy](https://github.com/eslint/.github/blob/master/SECURITY.md).
|
| 181 |
+
|
| 182 |
+
## Build Commands
|
| 183 |
+
|
| 184 |
+
- `npm test` - run all linting and tests
|
| 185 |
+
- `npm run lint` - run all linting
|
| 186 |
+
|
| 187 |
+
## License
|
| 188 |
+
|
| 189 |
+
ESLint Scope is licensed under a permissive BSD 2-clause license.
|
| 190 |
+
|
| 191 |
+
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
|
| 192 |
+
<!--sponsorsstart-->
|
| 193 |
+
|
| 194 |
+
## Sponsors
|
| 195 |
+
|
| 196 |
+
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
|
| 197 |
+
to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
| 198 |
+
|
| 199 |
+
<h3>Platinum Sponsors</h3>
|
| 200 |
+
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a></p><h3>Gold Sponsors</h3>
|
| 201 |
+
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a></p><h3>Silver Sponsors</h3>
|
| 202 |
+
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/d472863/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
| 203 |
+
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="https://depot.dev"><img src="https://images.opencollective.com/depot/39125a1/logo.png" alt="Depot" height="32"></a> <a href="https://www.n-ix.com/"><img src="https://images.opencollective.com/n-ix-ltd/575a7a5/logo.png" alt="N-iX Ltd" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
|
| 204 |
+
<h3>Technology Sponsors</h3>
|
| 205 |
+
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
| 206 |
+
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
| 207 |
+
<!--sponsorsend-->
|
node_modules/eslint-scope/lib/assert.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview Assertion utilities.
|
| 3 |
+
* @author Nicholas C. Zakas
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Throws an error if the given condition is not truthy.
|
| 8 |
+
* @param {boolean} condition The condition to check.
|
| 9 |
+
* @param {string} message The message to include with the error.
|
| 10 |
+
* @returns {void}
|
| 11 |
+
* @throws {Error} When the condition is not truthy.
|
| 12 |
+
*/
|
| 13 |
+
export function assert(condition, message = "Assertion failed.") {
|
| 14 |
+
if (!condition) {
|
| 15 |
+
throw new Error(message);
|
| 16 |
+
}
|
| 17 |
+
}
|
node_modules/eslint-scope/lib/definition.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import Variable from "./variable.js";
|
| 26 |
+
|
| 27 |
+
/** @import * as types from "eslint-scope" */
|
| 28 |
+
|
| 29 |
+
// Cannot implement `types.Definition` directly because it contains a union.
|
| 30 |
+
/**
|
| 31 |
+
* @constructor Definition
|
| 32 |
+
* @implements {Omit<types.Definition, never>}
|
| 33 |
+
*/
|
| 34 |
+
class Definition {
|
| 35 |
+
constructor(type, name, node, parent, index, kind) {
|
| 36 |
+
/**
|
| 37 |
+
* @member {string} Definition#type - type of the occurrence (e.g. "Parameter", "Variable", ...).
|
| 38 |
+
*/
|
| 39 |
+
this.type = type;
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* @member {espree.Identifier} Definition#name - the identifier AST node of the occurrence.
|
| 43 |
+
*/
|
| 44 |
+
this.name = name;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* @member {espree.Node} Definition#node - the enclosing node of the identifier.
|
| 48 |
+
*/
|
| 49 |
+
this.node = node;
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* @member {espree.Node?} Definition#parent - the enclosing statement node of the identifier.
|
| 53 |
+
*/
|
| 54 |
+
this.parent = parent;
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* @member {number?} Definition#index - the index in the declaration statement.
|
| 58 |
+
*/
|
| 59 |
+
this.index = index;
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* @member {string?} Definition#kind - the kind of the declaration statement.
|
| 63 |
+
*/
|
| 64 |
+
this.kind = kind;
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* @constructor ParameterDefinition
|
| 70 |
+
*/
|
| 71 |
+
class ParameterDefinition extends Definition {
|
| 72 |
+
constructor(name, node, index, rest) {
|
| 73 |
+
super(Variable.Parameter, name, node, null, index, null);
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Whether the parameter definition is a part of a rest parameter.
|
| 77 |
+
* @member {boolean} ParameterDefinition#rest
|
| 78 |
+
*/
|
| 79 |
+
this.rest = rest;
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
export { ParameterDefinition, Definition };
|
| 84 |
+
|
| 85 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/index.d.cts
ADDED
|
@@ -0,0 +1,1152 @@
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview This file contains the types for ESLint Scope.
|
| 3 |
+
* It was initially extracted from the DefinitelyTyped repository.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
/*
|
| 7 |
+
* MIT License
|
| 8 |
+
* Copyright (c) Microsoft Corporation.
|
| 9 |
+
*
|
| 10 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 11 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 12 |
+
* in the Software without restriction, including without limitation the rights
|
| 13 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 14 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 15 |
+
* furnished to do so, subject to the following conditions:
|
| 16 |
+
* The above copyright notice and this permission notice shall be included in all
|
| 17 |
+
* copies or substantial portions of the Software.
|
| 18 |
+
*
|
| 19 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 20 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 21 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 22 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 23 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 24 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 25 |
+
* SOFTWARE
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
//------------------------------------------------------------------------------
|
| 29 |
+
// Imports
|
| 30 |
+
//------------------------------------------------------------------------------
|
| 31 |
+
|
| 32 |
+
import type { Visitor, VisitorOptions } from "esrecurse";
|
| 33 |
+
import type * as ESTree from "estree";
|
| 34 |
+
|
| 35 |
+
//------------------------------------------------------------------------------
|
| 36 |
+
// Helpers
|
| 37 |
+
//------------------------------------------------------------------------------
|
| 38 |
+
|
| 39 |
+
interface JSXIdentifier extends ESTree.BaseNode {
|
| 40 |
+
type: "JSXIdentifier";
|
| 41 |
+
name: string;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
//------------------------------------------------------------------------------
|
| 45 |
+
// Exports
|
| 46 |
+
//------------------------------------------------------------------------------
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Options for scope analysis.
|
| 50 |
+
*/
|
| 51 |
+
export interface AnalyzeOptions {
|
| 52 |
+
/**
|
| 53 |
+
* Whether to ignore `eval()` calls, which normally create scopes.
|
| 54 |
+
* @default false
|
| 55 |
+
*/
|
| 56 |
+
ignoreEval?: boolean;
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Whether to create a top-level function scope for CommonJS evaluation.
|
| 60 |
+
* @default false
|
| 61 |
+
*/
|
| 62 |
+
nodejsScope?: boolean;
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Whether to evaluate code in strict mode even outside modules or without `"use strict"`.
|
| 66 |
+
* @default false
|
| 67 |
+
*/
|
| 68 |
+
impliedStrict?: boolean;
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* The ECMAScript version to use for evaluation (e.g., `5`, `2015`, `2022`).
|
| 72 |
+
* @default 5
|
| 73 |
+
*/
|
| 74 |
+
ecmaVersion?: number;
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* The type of JavaScript file to evaluate.
|
| 78 |
+
* @default "script"
|
| 79 |
+
*/
|
| 80 |
+
sourceType?: "script" | "module" | "commonjs";
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* Visitor key information for performance enhancement.
|
| 84 |
+
* @default null
|
| 85 |
+
*/
|
| 86 |
+
childVisitorKeys?: {
|
| 87 |
+
readonly [type: string]: ReadonlyArray<string>;
|
| 88 |
+
} | null;
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Strategy to use when `childVisitorKeys` is not specified.
|
| 92 |
+
* @default "iteration"
|
| 93 |
+
*/
|
| 94 |
+
fallback?: "iteration" | ((node: ESTree.Node) => string[]);
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Whether to enable optimistic scope analysis.
|
| 98 |
+
* @default false
|
| 99 |
+
*/
|
| 100 |
+
optimistic?: boolean;
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Enables the tracking of JSX components as variable references.
|
| 104 |
+
* @default false
|
| 105 |
+
*/
|
| 106 |
+
jsx?: boolean;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Callback function for pattern visitors.
|
| 111 |
+
*/
|
| 112 |
+
export type PatternVisitorCallback = (
|
| 113 |
+
pattern: ESTree.Identifier,
|
| 114 |
+
misc: {
|
| 115 |
+
topLevel: boolean;
|
| 116 |
+
rest: boolean;
|
| 117 |
+
assignments: ESTree.AssignmentPattern[];
|
| 118 |
+
},
|
| 119 |
+
) => void;
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* Manages the scope hierarchy of an AST.
|
| 123 |
+
*/
|
| 124 |
+
export class ScopeManager {
|
| 125 |
+
/**
|
| 126 |
+
* Creates a new `ScopeManager` instance.
|
| 127 |
+
* @param options Options for scope analysis.
|
| 128 |
+
*/
|
| 129 |
+
constructor(options: AnalyzeOptions);
|
| 130 |
+
|
| 131 |
+
/**
|
| 132 |
+
* The global scope, initially set to `null`.
|
| 133 |
+
*/
|
| 134 |
+
globalScope: GlobalScope | null;
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* All scopes in the analyzed program.
|
| 138 |
+
*/
|
| 139 |
+
scopes: Scope[];
|
| 140 |
+
|
| 141 |
+
/**
|
| 142 |
+
* Adds variables to the global scope and resolves references to them.
|
| 143 |
+
* @param names An array of strings, the names of variables to add to the global scope.
|
| 144 |
+
* @returns void
|
| 145 |
+
*/
|
| 146 |
+
addGlobals(names: ReadonlyArray<string>): void;
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Acquires the scope for a given node.
|
| 150 |
+
* @param node The AST node to get the scope for.
|
| 151 |
+
* @param inner Whether to get the innermost scope. (default: `false`)
|
| 152 |
+
* @returns The scope or null if not found.
|
| 153 |
+
*/
|
| 154 |
+
acquire(node: ESTree.Node, inner?: boolean): Scope | null;
|
| 155 |
+
|
| 156 |
+
/**
|
| 157 |
+
* acquire all scopes from node.
|
| 158 |
+
* @param node node for the acquired scope.
|
| 159 |
+
* @returns Scope array
|
| 160 |
+
* @deprecated
|
| 161 |
+
*/
|
| 162 |
+
acquireAll(node: ESTree.Node): Scope[] | null;
|
| 163 |
+
|
| 164 |
+
/**
|
| 165 |
+
* Releases a scope, moving to its parent.
|
| 166 |
+
* @param node The AST node to release the scope for.
|
| 167 |
+
* @param inner Whether to release the innermost scope. (default: `false`)
|
| 168 |
+
* @returns The parent scope or null if not found.
|
| 169 |
+
*/
|
| 170 |
+
release(node: ESTree.Node, inner?: boolean): Scope | null;
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* Gets all scopes for a given node, including parents.
|
| 174 |
+
* @param node The AST node to get scopes for.
|
| 175 |
+
* @param inner Whether to start from the innermost scope.
|
| 176 |
+
* @returns Array of scopes or empty array if none found.
|
| 177 |
+
*/
|
| 178 |
+
getDeclaredVariables(node: ESTree.Node): Variable[];
|
| 179 |
+
|
| 180 |
+
/**
|
| 181 |
+
* Determines if the global return statement should be allowed.
|
| 182 |
+
* @returns `true` if the global return is enabled.
|
| 183 |
+
*/
|
| 184 |
+
isGlobalReturn(): boolean;
|
| 185 |
+
|
| 186 |
+
/** @deprecated */
|
| 187 |
+
isModule(): boolean;
|
| 188 |
+
|
| 189 |
+
/** @deprecated */
|
| 190 |
+
isImpliedStrict(): boolean;
|
| 191 |
+
|
| 192 |
+
/** @deprecated */
|
| 193 |
+
isStrictModeSupported(): boolean;
|
| 194 |
+
|
| 195 |
+
/** @deprecated */
|
| 196 |
+
attach(): void;
|
| 197 |
+
|
| 198 |
+
/** @deprecated */
|
| 199 |
+
detach(): void;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
/**
|
| 203 |
+
* Base export class for all scopes.
|
| 204 |
+
*/
|
| 205 |
+
export class Scope<
|
| 206 |
+
TVariable extends Variable = Variable,
|
| 207 |
+
TReference extends Reference = Reference,
|
| 208 |
+
> {
|
| 209 |
+
/**
|
| 210 |
+
* Creates a new `Scope` instance.
|
| 211 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 212 |
+
* @param type The type of the scope.
|
| 213 |
+
* @param upperScope The parent scope, or null for the global scope.
|
| 214 |
+
* @param block The AST node that created this scope.
|
| 215 |
+
* @param isMethodDefinition Whether this scope is for a method definition.
|
| 216 |
+
*/
|
| 217 |
+
constructor(
|
| 218 |
+
scopeManager: ScopeManager,
|
| 219 |
+
type: typeof this.type,
|
| 220 |
+
upperScope: Scope | null,
|
| 221 |
+
block: ESTree.Node,
|
| 222 |
+
isMethodDefinition: boolean,
|
| 223 |
+
);
|
| 224 |
+
|
| 225 |
+
/**
|
| 226 |
+
* The type of the scope (e.g., 'global', 'function').
|
| 227 |
+
*/
|
| 228 |
+
type:
|
| 229 |
+
| "block"
|
| 230 |
+
| "catch"
|
| 231 |
+
| "class"
|
| 232 |
+
| "class-field-initializer"
|
| 233 |
+
| "class-static-block"
|
| 234 |
+
| "for"
|
| 235 |
+
| "function"
|
| 236 |
+
| "function-expression-name"
|
| 237 |
+
| "global"
|
| 238 |
+
| "module"
|
| 239 |
+
| "switch"
|
| 240 |
+
| "with";
|
| 241 |
+
|
| 242 |
+
/**
|
| 243 |
+
* Whether the scope is in strict mode.
|
| 244 |
+
*/
|
| 245 |
+
isStrict: boolean;
|
| 246 |
+
|
| 247 |
+
/**
|
| 248 |
+
* The parent scope, or null for the global scope.
|
| 249 |
+
*/
|
| 250 |
+
upper: Scope | null;
|
| 251 |
+
|
| 252 |
+
/**
|
| 253 |
+
* The scope where variables are declared (same as this for most scopes).
|
| 254 |
+
*/
|
| 255 |
+
variableScope: Scope;
|
| 256 |
+
|
| 257 |
+
/**
|
| 258 |
+
* Variables defined in this scope.
|
| 259 |
+
*/
|
| 260 |
+
variables: TVariable[];
|
| 261 |
+
|
| 262 |
+
/**
|
| 263 |
+
* References to variables in this scope.
|
| 264 |
+
*/
|
| 265 |
+
references: TReference[];
|
| 266 |
+
|
| 267 |
+
/**
|
| 268 |
+
* Child scopes.
|
| 269 |
+
*/
|
| 270 |
+
childScopes: Scope[];
|
| 271 |
+
|
| 272 |
+
/**
|
| 273 |
+
* The AST node that created this scope.
|
| 274 |
+
*/
|
| 275 |
+
block: ESTree.Node;
|
| 276 |
+
|
| 277 |
+
/**
|
| 278 |
+
* Whether this is a function expression scope.
|
| 279 |
+
*/
|
| 280 |
+
functionExpressionScope: boolean;
|
| 281 |
+
|
| 282 |
+
/**
|
| 283 |
+
* Map of variable names to variables.
|
| 284 |
+
*/
|
| 285 |
+
set: Map<string, TVariable>;
|
| 286 |
+
|
| 287 |
+
/**
|
| 288 |
+
* The tainted variables of this scope.
|
| 289 |
+
* @deprecated
|
| 290 |
+
*/
|
| 291 |
+
taints: Map<string, TVariable>;
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* References that pass through this scope to outer scopes.
|
| 295 |
+
*/
|
| 296 |
+
through: TReference[];
|
| 297 |
+
|
| 298 |
+
/**
|
| 299 |
+
* Dynamic flag for certain scope types.
|
| 300 |
+
* @deprecated
|
| 301 |
+
*/
|
| 302 |
+
dynamic: boolean;
|
| 303 |
+
|
| 304 |
+
/**
|
| 305 |
+
* Direct call to eval() flag.
|
| 306 |
+
* @deprecated
|
| 307 |
+
*/
|
| 308 |
+
directCallToEvalScope: boolean;
|
| 309 |
+
|
| 310 |
+
/**
|
| 311 |
+
* This scope flag.
|
| 312 |
+
* @deprecated
|
| 313 |
+
*/
|
| 314 |
+
thisFound: boolean;
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* Resolves a reference in this scope.
|
| 318 |
+
* @param ident An AST node to get their reference object.
|
| 319 |
+
* @deprecated
|
| 320 |
+
*/
|
| 321 |
+
resolve(ident: ESTree.Identifier): TReference | null;
|
| 322 |
+
|
| 323 |
+
/**
|
| 324 |
+
* Whether the reference is static.
|
| 325 |
+
* @deprecated
|
| 326 |
+
*/
|
| 327 |
+
isStatic(): boolean;
|
| 328 |
+
|
| 329 |
+
/**
|
| 330 |
+
* Returns whether this scope has materialized arguments.
|
| 331 |
+
* @deprecated
|
| 332 |
+
*/
|
| 333 |
+
isArgumentsMaterialized(): boolean;
|
| 334 |
+
|
| 335 |
+
/**
|
| 336 |
+
* Returns whether this scope has materialized `this` reference.
|
| 337 |
+
* @deprecated
|
| 338 |
+
*/
|
| 339 |
+
isThisMaterialized(): boolean;
|
| 340 |
+
|
| 341 |
+
/** @deprecated */
|
| 342 |
+
isUsedName(name: string): boolean;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
/**
|
| 346 |
+
* Global scope.
|
| 347 |
+
*/
|
| 348 |
+
export class GlobalScope extends Scope {
|
| 349 |
+
/**
|
| 350 |
+
* Creates a new GlobalScope instance.
|
| 351 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 352 |
+
* @param block The AST node that created this scope.
|
| 353 |
+
*/
|
| 354 |
+
constructor(scopeManager: ScopeManager, block: ESTree.Node);
|
| 355 |
+
|
| 356 |
+
type: "global";
|
| 357 |
+
|
| 358 |
+
functionExpressionScope: false;
|
| 359 |
+
|
| 360 |
+
isArgumentsMaterialized(): true;
|
| 361 |
+
|
| 362 |
+
isThisMaterialized(): true;
|
| 363 |
+
|
| 364 |
+
/**
|
| 365 |
+
* Implicit references (e.g., 'arguments' in functions).
|
| 366 |
+
*/
|
| 367 |
+
implicit: {
|
| 368 |
+
left: Reference[];
|
| 369 |
+
set: Map<string, Variable>;
|
| 370 |
+
variables: Variable[];
|
| 371 |
+
};
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
/**
|
| 375 |
+
* Module scope.
|
| 376 |
+
*/
|
| 377 |
+
export class ModuleScope extends Scope {
|
| 378 |
+
/**
|
| 379 |
+
* Creates a new ModuleScope instance.
|
| 380 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 381 |
+
* @param upperScope The parent scope.
|
| 382 |
+
* @param block The AST node that created this scope.
|
| 383 |
+
*/
|
| 384 |
+
constructor(
|
| 385 |
+
scopeManager: ScopeManager,
|
| 386 |
+
upperScope: Scope,
|
| 387 |
+
block: ESTree.Node,
|
| 388 |
+
);
|
| 389 |
+
|
| 390 |
+
type: "module";
|
| 391 |
+
|
| 392 |
+
functionExpressionScope: false;
|
| 393 |
+
|
| 394 |
+
isArgumentsMaterialized(): true;
|
| 395 |
+
|
| 396 |
+
isThisMaterialized(): true;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
/**
|
| 400 |
+
* Function expression name scope.
|
| 401 |
+
*/
|
| 402 |
+
export class FunctionExpressionNameScope extends Scope {
|
| 403 |
+
/**
|
| 404 |
+
* Creates a new FunctionExpressionNameScope instance.
|
| 405 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 406 |
+
* @param upperScope The parent scope.
|
| 407 |
+
* @param block The AST node that created this scope.
|
| 408 |
+
*/
|
| 409 |
+
constructor(
|
| 410 |
+
scopeManager: ScopeManager,
|
| 411 |
+
upperScope: Scope,
|
| 412 |
+
block: ESTree.Node,
|
| 413 |
+
);
|
| 414 |
+
|
| 415 |
+
type: "function-expression-name";
|
| 416 |
+
|
| 417 |
+
functionExpressionScope: true;
|
| 418 |
+
|
| 419 |
+
isArgumentsMaterialized(): true;
|
| 420 |
+
|
| 421 |
+
isThisMaterialized(): true;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
/**
|
| 425 |
+
* Catch scope.
|
| 426 |
+
*/
|
| 427 |
+
export class CatchScope extends Scope {
|
| 428 |
+
/**
|
| 429 |
+
* Creates a new CatchScope instance.
|
| 430 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 431 |
+
* @param upperScope The parent scope.
|
| 432 |
+
* @param block The AST node that created this scope.
|
| 433 |
+
*/
|
| 434 |
+
constructor(
|
| 435 |
+
scopeManager: ScopeManager,
|
| 436 |
+
upperScope: Scope,
|
| 437 |
+
block: ESTree.Node,
|
| 438 |
+
);
|
| 439 |
+
|
| 440 |
+
type: "catch";
|
| 441 |
+
|
| 442 |
+
functionExpressionScope: false;
|
| 443 |
+
|
| 444 |
+
isArgumentsMaterialized(): true;
|
| 445 |
+
|
| 446 |
+
isThisMaterialized(): true;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
/**
|
| 450 |
+
* With scope.
|
| 451 |
+
*/
|
| 452 |
+
export class WithScope extends Scope {
|
| 453 |
+
/**
|
| 454 |
+
* Creates a new WithScope instance.
|
| 455 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 456 |
+
* @param upperScope The parent scope.
|
| 457 |
+
* @param block The AST node that created this scope.
|
| 458 |
+
*/
|
| 459 |
+
constructor(
|
| 460 |
+
scopeManager: ScopeManager,
|
| 461 |
+
upperScope: Scope,
|
| 462 |
+
block: ESTree.Node,
|
| 463 |
+
);
|
| 464 |
+
|
| 465 |
+
type: "with";
|
| 466 |
+
|
| 467 |
+
functionExpressionScope: false;
|
| 468 |
+
|
| 469 |
+
isArgumentsMaterialized(): true;
|
| 470 |
+
|
| 471 |
+
isThisMaterialized(): true;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
/**
|
| 475 |
+
* Block scope.
|
| 476 |
+
*/
|
| 477 |
+
export class BlockScope extends Scope {
|
| 478 |
+
/**
|
| 479 |
+
* Creates a new BlockScope instance.
|
| 480 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 481 |
+
* @param upperScope The parent scope.
|
| 482 |
+
* @param block The AST node that created this scope.
|
| 483 |
+
*/
|
| 484 |
+
constructor(
|
| 485 |
+
scopeManager: ScopeManager,
|
| 486 |
+
upperScope: Scope,
|
| 487 |
+
block: ESTree.Node,
|
| 488 |
+
);
|
| 489 |
+
|
| 490 |
+
type: "block";
|
| 491 |
+
|
| 492 |
+
functionExpressionScope: false;
|
| 493 |
+
|
| 494 |
+
isArgumentsMaterialized(): true;
|
| 495 |
+
|
| 496 |
+
isThisMaterialized(): true;
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
/**
|
| 500 |
+
* Switch scope.
|
| 501 |
+
*/
|
| 502 |
+
export class SwitchScope extends Scope {
|
| 503 |
+
/**
|
| 504 |
+
* Creates a new SwitchScope instance.
|
| 505 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 506 |
+
* @param upperScope The parent scope.
|
| 507 |
+
* @param block The AST node that created this scope.
|
| 508 |
+
*/
|
| 509 |
+
constructor(
|
| 510 |
+
scopeManager: ScopeManager,
|
| 511 |
+
upperScope: Scope,
|
| 512 |
+
block: ESTree.Node,
|
| 513 |
+
);
|
| 514 |
+
|
| 515 |
+
type: "switch";
|
| 516 |
+
|
| 517 |
+
functionExpressionScope: false;
|
| 518 |
+
|
| 519 |
+
isArgumentsMaterialized(): true;
|
| 520 |
+
|
| 521 |
+
isThisMaterialized(): true;
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
/**
|
| 525 |
+
* Function scope.
|
| 526 |
+
*/
|
| 527 |
+
export class FunctionScope extends Scope {
|
| 528 |
+
/**
|
| 529 |
+
* Creates a new FunctionScope instance.
|
| 530 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 531 |
+
* @param upperScope The parent scope.
|
| 532 |
+
* @param block The AST node that created this scope.
|
| 533 |
+
* @param isMethodDefinition Whether this scope is for a method definition.
|
| 534 |
+
*/
|
| 535 |
+
constructor(
|
| 536 |
+
scopeManager: ScopeManager,
|
| 537 |
+
upperScope: Scope,
|
| 538 |
+
block: ESTree.Node,
|
| 539 |
+
isMethodDefinition: boolean,
|
| 540 |
+
);
|
| 541 |
+
|
| 542 |
+
type: "function";
|
| 543 |
+
|
| 544 |
+
functionExpressionScope: false;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
/**
|
| 548 |
+
* Scope of for, for-in, and for-of statements.
|
| 549 |
+
*/
|
| 550 |
+
export class ForScope extends Scope {
|
| 551 |
+
/**
|
| 552 |
+
* Creates a new ForScope instance.
|
| 553 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 554 |
+
* @param upperScope The parent scope.
|
| 555 |
+
* @param block The AST node that created this scope.
|
| 556 |
+
*/
|
| 557 |
+
constructor(
|
| 558 |
+
scopeManager: ScopeManager,
|
| 559 |
+
upperScope: Scope,
|
| 560 |
+
block: ESTree.Node,
|
| 561 |
+
);
|
| 562 |
+
|
| 563 |
+
type: "for";
|
| 564 |
+
|
| 565 |
+
functionExpressionScope: false;
|
| 566 |
+
|
| 567 |
+
isArgumentsMaterialized(): true;
|
| 568 |
+
|
| 569 |
+
isThisMaterialized(): true;
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
/**
|
| 573 |
+
* Class scope.
|
| 574 |
+
*/
|
| 575 |
+
export class ClassScope extends Scope {
|
| 576 |
+
/**
|
| 577 |
+
* Creates a new ClassScope instance.
|
| 578 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 579 |
+
* @param upperScope The parent scope.
|
| 580 |
+
* @param block The AST node that created this scope.
|
| 581 |
+
*/
|
| 582 |
+
constructor(
|
| 583 |
+
scopeManager: ScopeManager,
|
| 584 |
+
upperScope: Scope,
|
| 585 |
+
block: ESTree.Node,
|
| 586 |
+
);
|
| 587 |
+
|
| 588 |
+
type: "class";
|
| 589 |
+
|
| 590 |
+
functionExpressionScope: false;
|
| 591 |
+
|
| 592 |
+
isArgumentsMaterialized(): true;
|
| 593 |
+
|
| 594 |
+
isThisMaterialized(): true;
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
/**
|
| 598 |
+
* Class field initializer scope.
|
| 599 |
+
*/
|
| 600 |
+
export class ClassFieldInitializerScope extends Scope {
|
| 601 |
+
/**
|
| 602 |
+
* Creates a new ClassFieldInitializerScope instance.
|
| 603 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 604 |
+
* @param upperScope The parent scope.
|
| 605 |
+
* @param block The AST node that created this scope.
|
| 606 |
+
*/
|
| 607 |
+
constructor(
|
| 608 |
+
scopeManager: ScopeManager,
|
| 609 |
+
upperScope: Scope,
|
| 610 |
+
block: ESTree.Node,
|
| 611 |
+
);
|
| 612 |
+
|
| 613 |
+
type: "class-field-initializer";
|
| 614 |
+
|
| 615 |
+
functionExpressionScope: false;
|
| 616 |
+
|
| 617 |
+
isArgumentsMaterialized(): true;
|
| 618 |
+
|
| 619 |
+
isThisMaterialized(): true;
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
/**
|
| 623 |
+
* Class static block scope.
|
| 624 |
+
*/
|
| 625 |
+
export class ClassStaticBlockScope extends Scope {
|
| 626 |
+
/**
|
| 627 |
+
* Creates a new ClassStaticBlockScope instance.
|
| 628 |
+
* @param scopeManager The scope manager this scope belongs to.
|
| 629 |
+
* @param upperScope The parent scope.
|
| 630 |
+
* @param block The AST node that created this scope.
|
| 631 |
+
*/
|
| 632 |
+
constructor(
|
| 633 |
+
scopeManager: ScopeManager,
|
| 634 |
+
upperScope: Scope,
|
| 635 |
+
block: ESTree.Node,
|
| 636 |
+
);
|
| 637 |
+
|
| 638 |
+
type: "class-static-block";
|
| 639 |
+
|
| 640 |
+
functionExpressionScope: false;
|
| 641 |
+
|
| 642 |
+
isArgumentsMaterialized(): true;
|
| 643 |
+
|
| 644 |
+
isThisMaterialized(): true;
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
/**
|
| 648 |
+
* Represents a variable in a scope.
|
| 649 |
+
*/
|
| 650 |
+
export class Variable<TReference extends Reference = Reference> {
|
| 651 |
+
static readonly CatchClause: "CatchClause";
|
| 652 |
+
static readonly Parameter: "Parameter";
|
| 653 |
+
static readonly FunctionName: "FunctionName";
|
| 654 |
+
static readonly ClassName: "ClassName";
|
| 655 |
+
static readonly Variable: "Variable";
|
| 656 |
+
static readonly ImportBinding: "ImportBinding";
|
| 657 |
+
static readonly ImplicitGlobalVariable: "ImplicitGlobalVariable";
|
| 658 |
+
|
| 659 |
+
/**
|
| 660 |
+
* Creates a new Variable instance.
|
| 661 |
+
* @param name The name of the variable.
|
| 662 |
+
* @param scope The scope where the variable is defined.
|
| 663 |
+
*/
|
| 664 |
+
constructor(name: string, scope: Scope);
|
| 665 |
+
|
| 666 |
+
/**
|
| 667 |
+
* The name of the variable.
|
| 668 |
+
*/
|
| 669 |
+
name: string;
|
| 670 |
+
|
| 671 |
+
/**
|
| 672 |
+
* The scope where the variable is defined.
|
| 673 |
+
*/
|
| 674 |
+
scope: Scope;
|
| 675 |
+
|
| 676 |
+
/**
|
| 677 |
+
* Identifiers that declare this variable.
|
| 678 |
+
*/
|
| 679 |
+
identifiers: ESTree.Identifier[];
|
| 680 |
+
|
| 681 |
+
/**
|
| 682 |
+
* References to this variable.
|
| 683 |
+
*/
|
| 684 |
+
references: TReference[];
|
| 685 |
+
|
| 686 |
+
/**
|
| 687 |
+
* Definitions of this variable.
|
| 688 |
+
*/
|
| 689 |
+
defs: Definition[];
|
| 690 |
+
|
| 691 |
+
/**
|
| 692 |
+
* Whether the variable is tainted (e.g., potentially modified externally).
|
| 693 |
+
* @deprecated
|
| 694 |
+
*/
|
| 695 |
+
tainted: boolean;
|
| 696 |
+
|
| 697 |
+
/**
|
| 698 |
+
* Stack flag for certain variable types.
|
| 699 |
+
* @deprecated
|
| 700 |
+
*/
|
| 701 |
+
stack: boolean;
|
| 702 |
+
}
|
| 703 |
+
|
| 704 |
+
/**
|
| 705 |
+
* Represents a reference to a variable.
|
| 706 |
+
*/
|
| 707 |
+
export class Reference {
|
| 708 |
+
static readonly READ: 1;
|
| 709 |
+
static readonly WRITE: 2;
|
| 710 |
+
static readonly RW: 3;
|
| 711 |
+
|
| 712 |
+
/**
|
| 713 |
+
* Creates a new Reference instance.
|
| 714 |
+
* @param ident The identifier node of the reference.
|
| 715 |
+
* @param scope The scope where the reference occurs.
|
| 716 |
+
* @param flag The reference flag (read, write, or read-write).
|
| 717 |
+
* @param writeExpr The expression being written, if applicable.
|
| 718 |
+
* @param maybeImplicitGlobal Information about a possible global variable, if applicable.
|
| 719 |
+
* @param partial Whether this is a partial reference.
|
| 720 |
+
* @param init Whether this is an initialization reference.
|
| 721 |
+
*/
|
| 722 |
+
constructor(
|
| 723 |
+
ident: ESTree.Identifier | JSXIdentifier,
|
| 724 |
+
scope: Scope,
|
| 725 |
+
flag: number,
|
| 726 |
+
writeExpr: ESTree.Expression | null,
|
| 727 |
+
maybeImplicitGlobal: {
|
| 728 |
+
pattern: ESTree.Pattern;
|
| 729 |
+
node: ESTree.Node;
|
| 730 |
+
} | null,
|
| 731 |
+
partial: boolean,
|
| 732 |
+
init: boolean,
|
| 733 |
+
);
|
| 734 |
+
|
| 735 |
+
/**
|
| 736 |
+
* The identifier node of the reference.
|
| 737 |
+
*/
|
| 738 |
+
identifier: ESTree.Identifier | JSXIdentifier;
|
| 739 |
+
|
| 740 |
+
/**
|
| 741 |
+
* The variable being referenced, or null if unresolved.
|
| 742 |
+
*/
|
| 743 |
+
resolved: Variable | null;
|
| 744 |
+
|
| 745 |
+
/**
|
| 746 |
+
* Whether the reference is static.
|
| 747 |
+
* @deprecated
|
| 748 |
+
*/
|
| 749 |
+
isStatic(): boolean;
|
| 750 |
+
|
| 751 |
+
/**
|
| 752 |
+
* Whether this is a write operation.
|
| 753 |
+
*/
|
| 754 |
+
isWrite(): boolean;
|
| 755 |
+
|
| 756 |
+
/**
|
| 757 |
+
* Whether this is a read operation.
|
| 758 |
+
*/
|
| 759 |
+
isRead(): boolean;
|
| 760 |
+
|
| 761 |
+
/**
|
| 762 |
+
* The scope where the reference occurs.
|
| 763 |
+
*/
|
| 764 |
+
from: Scope;
|
| 765 |
+
|
| 766 |
+
/**
|
| 767 |
+
* Whether the reference comes from a dynamic scope (such as 'eval',
|
| 768 |
+
* 'with', etc.), and may be trapped by dynamic scopes.
|
| 769 |
+
* @deprecated
|
| 770 |
+
*/
|
| 771 |
+
tainted: boolean;
|
| 772 |
+
|
| 773 |
+
/**
|
| 774 |
+
* The expression being written, if applicable.
|
| 775 |
+
*/
|
| 776 |
+
writeExpr?: ESTree.Expression | null;
|
| 777 |
+
|
| 778 |
+
/**
|
| 779 |
+
* Whether this is a partial reference.
|
| 780 |
+
* @deprecated
|
| 781 |
+
*/
|
| 782 |
+
partial?: boolean;
|
| 783 |
+
|
| 784 |
+
/**
|
| 785 |
+
* Whether this is an initialization reference.
|
| 786 |
+
*/
|
| 787 |
+
init?: boolean;
|
| 788 |
+
|
| 789 |
+
/**
|
| 790 |
+
* Whether this reference is only read.
|
| 791 |
+
* @returns True if the reference is read-only.
|
| 792 |
+
*/
|
| 793 |
+
isReadOnly(): boolean;
|
| 794 |
+
|
| 795 |
+
/**
|
| 796 |
+
* Whether this reference is only written.
|
| 797 |
+
* @returns True if the reference is write-only.
|
| 798 |
+
*/
|
| 799 |
+
isWriteOnly(): boolean;
|
| 800 |
+
|
| 801 |
+
/**
|
| 802 |
+
* Whether this reference is read-write.
|
| 803 |
+
* @returns True if the reference is read-write.
|
| 804 |
+
*/
|
| 805 |
+
isReadWrite(): boolean;
|
| 806 |
+
|
| 807 |
+
/** @deprecated */
|
| 808 |
+
flag: number;
|
| 809 |
+
}
|
| 810 |
+
|
| 811 |
+
/**
|
| 812 |
+
* Represents a variable definition.
|
| 813 |
+
*/
|
| 814 |
+
export const Definition: {
|
| 815 |
+
/**
|
| 816 |
+
* Creates a new Definition instance.
|
| 817 |
+
* @param type The type of definition (e.g., 'Variable', 'Parameter').
|
| 818 |
+
* @param name The identifier node of the definition.
|
| 819 |
+
* @param node The AST node where the definition occurs.
|
| 820 |
+
* @param parent The parent node, if applicable.
|
| 821 |
+
* @param index The index of the definition in a pattern, if applicable.
|
| 822 |
+
* @param kind The kind of variable (e.g., 'var', 'let', 'const'), if applicable.
|
| 823 |
+
*/
|
| 824 |
+
new (
|
| 825 |
+
type: Definition["type"],
|
| 826 |
+
name: ESTree.Identifier,
|
| 827 |
+
node: Definition["node"],
|
| 828 |
+
parent: Definition["parent"],
|
| 829 |
+
index: number | null,
|
| 830 |
+
kind: string | null,
|
| 831 |
+
): Definition;
|
| 832 |
+
};
|
| 833 |
+
|
| 834 |
+
export type Definition = (
|
| 835 |
+
| { type: "CatchClause"; node: ESTree.CatchClause; parent: null }
|
| 836 |
+
| {
|
| 837 |
+
type: "ClassName";
|
| 838 |
+
node: ESTree.ClassDeclaration | ESTree.ClassExpression;
|
| 839 |
+
parent: null;
|
| 840 |
+
}
|
| 841 |
+
| {
|
| 842 |
+
type: "FunctionName";
|
| 843 |
+
node: ESTree.FunctionDeclaration | ESTree.FunctionExpression;
|
| 844 |
+
parent: null;
|
| 845 |
+
}
|
| 846 |
+
| {
|
| 847 |
+
type: "ImplicitGlobalVariable";
|
| 848 |
+
node:
|
| 849 |
+
| ESTree.AssignmentExpression
|
| 850 |
+
| ESTree.ForInStatement
|
| 851 |
+
| ESTree.ForOfStatement;
|
| 852 |
+
parent: null;
|
| 853 |
+
}
|
| 854 |
+
| {
|
| 855 |
+
type: "ImportBinding";
|
| 856 |
+
node:
|
| 857 |
+
| ESTree.ImportSpecifier
|
| 858 |
+
| ESTree.ImportDefaultSpecifier
|
| 859 |
+
| ESTree.ImportNamespaceSpecifier;
|
| 860 |
+
parent: ESTree.ImportDeclaration;
|
| 861 |
+
}
|
| 862 |
+
| {
|
| 863 |
+
type: "Parameter";
|
| 864 |
+
node:
|
| 865 |
+
| ESTree.FunctionDeclaration
|
| 866 |
+
| ESTree.FunctionExpression
|
| 867 |
+
| ESTree.ArrowFunctionExpression;
|
| 868 |
+
parent: null;
|
| 869 |
+
}
|
| 870 |
+
| {
|
| 871 |
+
type: "Variable";
|
| 872 |
+
node: ESTree.VariableDeclarator;
|
| 873 |
+
parent: ESTree.VariableDeclaration;
|
| 874 |
+
}
|
| 875 |
+
) & {
|
| 876 |
+
/**
|
| 877 |
+
* The identifier node of the definition.
|
| 878 |
+
*/
|
| 879 |
+
name: ESTree.Identifier;
|
| 880 |
+
|
| 881 |
+
/**
|
| 882 |
+
* The index of the definition in a pattern, if applicable.
|
| 883 |
+
* @deprecated
|
| 884 |
+
*/
|
| 885 |
+
index: number | null;
|
| 886 |
+
|
| 887 |
+
/**
|
| 888 |
+
* The kind of variable (e.g., 'var', 'let', 'const'), if applicable.
|
| 889 |
+
* @deprecated
|
| 890 |
+
*/
|
| 891 |
+
kind: string | null;
|
| 892 |
+
};
|
| 893 |
+
|
| 894 |
+
/**
|
| 895 |
+
* Visitor for destructuring patterns.
|
| 896 |
+
*/
|
| 897 |
+
export class PatternVisitor extends Visitor {
|
| 898 |
+
static isPattern(
|
| 899 |
+
node: ESTree.Node,
|
| 900 |
+
): node is
|
| 901 |
+
| ESTree.Identifier
|
| 902 |
+
| ESTree.ObjectPattern
|
| 903 |
+
| ESTree.ArrayPattern
|
| 904 |
+
| ESTree.SpreadElement
|
| 905 |
+
| ESTree.RestElement
|
| 906 |
+
| ESTree.AssignmentPattern;
|
| 907 |
+
|
| 908 |
+
constructor(
|
| 909 |
+
options: VisitorOptions | null | undefined,
|
| 910 |
+
rootPattern: ESTree.Pattern,
|
| 911 |
+
callback: PatternVisitorCallback,
|
| 912 |
+
);
|
| 913 |
+
|
| 914 |
+
rootPattern: ESTree.Pattern;
|
| 915 |
+
|
| 916 |
+
callback: PatternVisitorCallback;
|
| 917 |
+
|
| 918 |
+
assignments: Array<ESTree.AssignmentExpression | ESTree.AssignmentPattern>;
|
| 919 |
+
|
| 920 |
+
rightHandNodes: ESTree.Node[];
|
| 921 |
+
|
| 922 |
+
restElements: ESTree.RestElement[];
|
| 923 |
+
|
| 924 |
+
Identifier(pattern: ESTree.Identifier): void;
|
| 925 |
+
|
| 926 |
+
Property(pattern: ESTree.Property): void;
|
| 927 |
+
|
| 928 |
+
ArrayPattern(pattern: ESTree.ArrayPattern): void;
|
| 929 |
+
|
| 930 |
+
AssignmentPattern(pattern: ESTree.AssignmentPattern): void;
|
| 931 |
+
|
| 932 |
+
RestElement(pattern: ESTree.RestElement): void;
|
| 933 |
+
|
| 934 |
+
MemberExpression(pattern: ESTree.MemberExpression): void;
|
| 935 |
+
|
| 936 |
+
SpreadElement(pattern: ESTree.SpreadElement): void;
|
| 937 |
+
|
| 938 |
+
ArrayExpression(pattern: ESTree.ArrayExpression): void;
|
| 939 |
+
|
| 940 |
+
AssignmentExpression(pattern: ESTree.AssignmentExpression): void;
|
| 941 |
+
|
| 942 |
+
CallExpression(pattern: ESTree.CallExpression): void;
|
| 943 |
+
}
|
| 944 |
+
|
| 945 |
+
/**
|
| 946 |
+
* Visitor class for traversing AST nodes and creating variable references and bindings.
|
| 947 |
+
*/
|
| 948 |
+
export class Referencer extends Visitor {
|
| 949 |
+
/**
|
| 950 |
+
* Creates a new Referencer instance.
|
| 951 |
+
* @param options Options for scope analysis.
|
| 952 |
+
* @param scopeManager The scope manager to use.
|
| 953 |
+
*/
|
| 954 |
+
constructor(
|
| 955 |
+
options: VisitorOptions | null | undefined,
|
| 956 |
+
scopeManager: ScopeManager,
|
| 957 |
+
);
|
| 958 |
+
|
| 959 |
+
/**
|
| 960 |
+
* Options for scope analysis.
|
| 961 |
+
*/
|
| 962 |
+
options: VisitorOptions | null | undefined;
|
| 963 |
+
|
| 964 |
+
/**
|
| 965 |
+
* The scope manager being used.
|
| 966 |
+
*/
|
| 967 |
+
scopeManager: ScopeManager;
|
| 968 |
+
|
| 969 |
+
/**
|
| 970 |
+
* The parent node.
|
| 971 |
+
*/
|
| 972 |
+
parent: ESTree.Node | null;
|
| 973 |
+
|
| 974 |
+
/**
|
| 975 |
+
* Whether currently inside a method definition.
|
| 976 |
+
*/
|
| 977 |
+
isInnerMethodDefinition: boolean;
|
| 978 |
+
|
| 979 |
+
/**
|
| 980 |
+
* Gets the current scope.
|
| 981 |
+
* @returns The current scope.
|
| 982 |
+
*/
|
| 983 |
+
currentScope(): Scope;
|
| 984 |
+
|
| 985 |
+
/**
|
| 986 |
+
* Closes scopes up to the given node.
|
| 987 |
+
* @param node The AST node.
|
| 988 |
+
*/
|
| 989 |
+
close(node: ESTree.Node): void;
|
| 990 |
+
|
| 991 |
+
/**
|
| 992 |
+
* Pushes a new inner method definition state.
|
| 993 |
+
* @param isInnerMethodDefinition Whether inside a method definition.
|
| 994 |
+
* @returns The previous state.
|
| 995 |
+
*/
|
| 996 |
+
pushInnerMethodDefinition(isInnerMethodDefinition: boolean): boolean;
|
| 997 |
+
|
| 998 |
+
/**
|
| 999 |
+
* Pops the inner method definition state.
|
| 1000 |
+
* @param isInnerMethodDefinition The state to restore.
|
| 1001 |
+
*/
|
| 1002 |
+
popInnerMethodDefinition(isInnerMethodDefinition: boolean): void;
|
| 1003 |
+
|
| 1004 |
+
/**
|
| 1005 |
+
* References default values in patterns.
|
| 1006 |
+
* @param pattern The pattern.
|
| 1007 |
+
* @param assignments The assignments.
|
| 1008 |
+
* @param maybeImplicitGlobal Information about a possible implicit global.
|
| 1009 |
+
* @param init Whether this is an initialization.
|
| 1010 |
+
*/
|
| 1011 |
+
referencingDefaultValue(
|
| 1012 |
+
pattern: ESTree.Pattern,
|
| 1013 |
+
assignments: Array<
|
| 1014 |
+
ESTree.AssignmentExpression | ESTree.AssignmentPattern
|
| 1015 |
+
>,
|
| 1016 |
+
maybeImplicitGlobal: {
|
| 1017 |
+
pattern: ESTree.Pattern;
|
| 1018 |
+
node: ESTree.Node;
|
| 1019 |
+
} | null,
|
| 1020 |
+
init: boolean,
|
| 1021 |
+
): void;
|
| 1022 |
+
|
| 1023 |
+
/**
|
| 1024 |
+
* Visits a pattern node.
|
| 1025 |
+
* @param node The pattern node.
|
| 1026 |
+
* @param options Options or callback.
|
| 1027 |
+
* @param callback The callback function.
|
| 1028 |
+
*/
|
| 1029 |
+
visitPattern(
|
| 1030 |
+
node: ESTree.Pattern,
|
| 1031 |
+
options: { processRightHandNodes: boolean } | PatternVisitorCallback,
|
| 1032 |
+
callback?: PatternVisitorCallback,
|
| 1033 |
+
): void;
|
| 1034 |
+
|
| 1035 |
+
/**
|
| 1036 |
+
* Visits a function node.
|
| 1037 |
+
* @param node The function node.
|
| 1038 |
+
*/
|
| 1039 |
+
visitFunction(
|
| 1040 |
+
node:
|
| 1041 |
+
| ESTree.FunctionDeclaration
|
| 1042 |
+
| ESTree.FunctionExpression
|
| 1043 |
+
| ESTree.ArrowFunctionExpression,
|
| 1044 |
+
): void;
|
| 1045 |
+
|
| 1046 |
+
/**
|
| 1047 |
+
* Visits a class node.
|
| 1048 |
+
* @param node The class node.
|
| 1049 |
+
*/
|
| 1050 |
+
visitClass(node: ESTree.ClassDeclaration | ESTree.ClassExpression): void;
|
| 1051 |
+
|
| 1052 |
+
/**
|
| 1053 |
+
* Visits a property node.
|
| 1054 |
+
* @param node The property node.
|
| 1055 |
+
*/
|
| 1056 |
+
visitProperty(node: ESTree.Property | ESTree.MethodDefinition): void;
|
| 1057 |
+
|
| 1058 |
+
/**
|
| 1059 |
+
* Visits a for-in or for-of statement.
|
| 1060 |
+
* @param node The for-in or for-of node.
|
| 1061 |
+
*/
|
| 1062 |
+
visitForIn(node: ESTree.ForInStatement | ESTree.ForOfStatement): void;
|
| 1063 |
+
|
| 1064 |
+
/**
|
| 1065 |
+
* Visits a variable declaration.
|
| 1066 |
+
* @param variableTargetScope The scope where the variable should be defined.
|
| 1067 |
+
* @param type The variable type.
|
| 1068 |
+
* @param node The variable declaration node.
|
| 1069 |
+
* @param index The index of the declarator.
|
| 1070 |
+
*/
|
| 1071 |
+
visitVariableDeclaration(
|
| 1072 |
+
variableTargetScope: Scope,
|
| 1073 |
+
type: typeof Variable.Variable,
|
| 1074 |
+
node: ESTree.VariableDeclaration,
|
| 1075 |
+
index: number,
|
| 1076 |
+
): void;
|
| 1077 |
+
|
| 1078 |
+
/**
|
| 1079 |
+
* Visits an export declaration.
|
| 1080 |
+
* @param node The export declaration node.
|
| 1081 |
+
*/
|
| 1082 |
+
visitExportDeclaration(
|
| 1083 |
+
node:
|
| 1084 |
+
| ESTree.ExportAllDeclaration
|
| 1085 |
+
| ESTree.ExportDefaultDeclaration
|
| 1086 |
+
| ESTree.ExportNamedDeclaration,
|
| 1087 |
+
): void;
|
| 1088 |
+
|
| 1089 |
+
AssignmentExpression(node: ESTree.AssignmentExpression): void;
|
| 1090 |
+
CatchClause(node: ESTree.CatchClause): void;
|
| 1091 |
+
Program(node: ESTree.Program): void;
|
| 1092 |
+
Identifier(node: ESTree.Identifier): void;
|
| 1093 |
+
PrivateIdentifier(): void;
|
| 1094 |
+
UpdateExpression(node: ESTree.UpdateExpression): void;
|
| 1095 |
+
MemberExpression(node: ESTree.MemberExpression): void;
|
| 1096 |
+
Property(node: ESTree.Property): void;
|
| 1097 |
+
PropertyDefinition(node: ESTree.PropertyDefinition): void;
|
| 1098 |
+
StaticBlock(node: ESTree.StaticBlock): void;
|
| 1099 |
+
MethodDefinition(node: ESTree.MethodDefinition): void;
|
| 1100 |
+
BreakStatement(): void;
|
| 1101 |
+
ContinueStatement(): void;
|
| 1102 |
+
LabeledStatement(node: ESTree.LabeledStatement): void;
|
| 1103 |
+
ForStatement(node: ESTree.ForStatement): void;
|
| 1104 |
+
ClassExpression(node: ESTree.ClassExpression): void;
|
| 1105 |
+
ClassDeclaration(node: ESTree.ClassDeclaration): void;
|
| 1106 |
+
CallExpression(node: ESTree.CallExpression): void;
|
| 1107 |
+
BlockStatement(node: ESTree.BlockStatement): void;
|
| 1108 |
+
ThisExpression(): void;
|
| 1109 |
+
WithStatement(node: ESTree.WithStatement): void;
|
| 1110 |
+
VariableDeclaration(node: ESTree.VariableDeclaration): void;
|
| 1111 |
+
SwitchStatement(node: ESTree.SwitchStatement): void;
|
| 1112 |
+
FunctionDeclaration(node: ESTree.FunctionDeclaration): void;
|
| 1113 |
+
FunctionExpression(node: ESTree.FunctionExpression): void;
|
| 1114 |
+
ForOfStatement(node: ESTree.ForOfStatement): void;
|
| 1115 |
+
ForInStatement(node: ESTree.ForInStatement): void;
|
| 1116 |
+
ArrowFunctionExpression(node: ESTree.ArrowFunctionExpression): void;
|
| 1117 |
+
ImportDeclaration(node: ESTree.ImportDeclaration): void;
|
| 1118 |
+
ExportDeclaration(
|
| 1119 |
+
node:
|
| 1120 |
+
| ESTree.ExportAllDeclaration
|
| 1121 |
+
| ESTree.ExportDefaultDeclaration
|
| 1122 |
+
| ESTree.ExportNamedDeclaration,
|
| 1123 |
+
): void;
|
| 1124 |
+
ExportAllDeclaration(node: ESTree.ExportAllDeclaration): void;
|
| 1125 |
+
ExportDefaultDeclaration(node: ESTree.ExportDefaultDeclaration): void;
|
| 1126 |
+
ExportNamedDeclaration(node: ESTree.ExportNamedDeclaration): void;
|
| 1127 |
+
ExportSpecifier(node: ESTree.ExportSpecifier): void;
|
| 1128 |
+
MetaProperty(): void;
|
| 1129 |
+
JSXIdentifier(node: JSXIdentifier): void;
|
| 1130 |
+
JSXMemberExpression(node: any): void;
|
| 1131 |
+
JSXElement(node: any): void;
|
| 1132 |
+
JSXOpeningElement(node: any): void;
|
| 1133 |
+
JSXAttribute(node: any): void;
|
| 1134 |
+
JSXExpressionContainer(node: any): void;
|
| 1135 |
+
JSXNamespacedName(node: any): void;
|
| 1136 |
+
}
|
| 1137 |
+
|
| 1138 |
+
/**
|
| 1139 |
+
* Analyzes the scope of an AST.
|
| 1140 |
+
* @param ast The ESTree-compliant AST to analyze.
|
| 1141 |
+
* @param options Options for scope analysis.
|
| 1142 |
+
* @returns The scope manager for the analyzed AST.
|
| 1143 |
+
*/
|
| 1144 |
+
export function analyze(
|
| 1145 |
+
ast: ESTree.Program,
|
| 1146 |
+
options?: AnalyzeOptions,
|
| 1147 |
+
): ScopeManager;
|
| 1148 |
+
|
| 1149 |
+
/**
|
| 1150 |
+
* The version of ESLint Scope.
|
| 1151 |
+
*/
|
| 1152 |
+
export const version: string;
|
node_modules/eslint-scope/lib/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview ESLint Scope types in ESM format.
|
| 3 |
+
* @author Francesco Trotta
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
export * from "./index.cjs";
|
node_modules/eslint-scope/lib/index.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 3 |
+
Copyright (C) 2013 Alex Seville <hi@alexanderseville.com>
|
| 4 |
+
Copyright (C) 2014 Thiago de Arruda <tpadilha84@gmail.com>
|
| 5 |
+
|
| 6 |
+
Redistribution and use in source and binary forms, with or without
|
| 7 |
+
modification, are permitted provided that the following conditions are met:
|
| 8 |
+
|
| 9 |
+
* Redistributions of source code must retain the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer.
|
| 11 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 12 |
+
notice, this list of conditions and the following disclaimer in the
|
| 13 |
+
documentation and/or other materials provided with the distribution.
|
| 14 |
+
|
| 15 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 16 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 17 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 18 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 19 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 20 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 21 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 22 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 23 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 24 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Escope (<a href="http://github.com/estools/escope">escope</a>) is an <a
|
| 29 |
+
* href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript</a>
|
| 30 |
+
* scope analyzer extracted from the <a
|
| 31 |
+
* href="http://github.com/estools/esmangle">esmangle project</a/>.
|
| 32 |
+
* <p>
|
| 33 |
+
* <em>escope</em> finds lexical scopes in a source program, i.e. areas of that
|
| 34 |
+
* program where different occurrences of the same identifier refer to the same
|
| 35 |
+
* variable. With each scope the contained variables are collected, and each
|
| 36 |
+
* identifier reference in code is linked to its corresponding variable (if
|
| 37 |
+
* possible).
|
| 38 |
+
* <p>
|
| 39 |
+
* <em>escope</em> works on a syntax tree of the parsed source code which has
|
| 40 |
+
* to adhere to the <a
|
| 41 |
+
* href="https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API">
|
| 42 |
+
* Mozilla Parser API</a>. E.g. <a href="https://github.com/eslint/espree">espree</a> is a parser
|
| 43 |
+
* that produces such syntax trees.
|
| 44 |
+
* <p>
|
| 45 |
+
* The main interface is the {@link analyze} function.
|
| 46 |
+
* @module escope
|
| 47 |
+
*/
|
| 48 |
+
|
| 49 |
+
import { assert } from "./assert.js";
|
| 50 |
+
|
| 51 |
+
import ScopeManager from "./scope-manager.js";
|
| 52 |
+
import Referencer from "./referencer.js";
|
| 53 |
+
import Reference from "./reference.js";
|
| 54 |
+
import Variable from "./variable.js";
|
| 55 |
+
|
| 56 |
+
/** @import ESTree from "estree" */
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Set the default options
|
| 60 |
+
* @returns {Object} options
|
| 61 |
+
*/
|
| 62 |
+
function defaultOptions() {
|
| 63 |
+
return {
|
| 64 |
+
optimistic: false,
|
| 65 |
+
nodejsScope: false,
|
| 66 |
+
impliedStrict: false,
|
| 67 |
+
sourceType: "script", // one of ['script', 'module', 'commonjs']
|
| 68 |
+
ecmaVersion: 5,
|
| 69 |
+
childVisitorKeys: null,
|
| 70 |
+
fallback: "iteration",
|
| 71 |
+
};
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Preform deep update on option object
|
| 76 |
+
* @param {Record<string, unknown>} target Options
|
| 77 |
+
* @param {Record<string, unknown>} override Updates
|
| 78 |
+
* @returns {Record<string, unknown>} Updated options
|
| 79 |
+
*/
|
| 80 |
+
function updateDeeply(target, override) {
|
| 81 |
+
/**
|
| 82 |
+
* Is hash object
|
| 83 |
+
* @param {Object} value Test value
|
| 84 |
+
* @returns {value is Record<string, unknown>} Result
|
| 85 |
+
*/
|
| 86 |
+
function isHashObject(value) {
|
| 87 |
+
return (
|
| 88 |
+
typeof value === "object" &&
|
| 89 |
+
value instanceof Object &&
|
| 90 |
+
!(value instanceof Array) &&
|
| 91 |
+
!(value instanceof RegExp)
|
| 92 |
+
);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
for (const key in override) {
|
| 96 |
+
if (Object.hasOwn(override, key)) {
|
| 97 |
+
const val = override[key];
|
| 98 |
+
|
| 99 |
+
if (isHashObject(val)) {
|
| 100 |
+
if (isHashObject(target[key])) {
|
| 101 |
+
updateDeeply(target[key], val);
|
| 102 |
+
} else {
|
| 103 |
+
target[key] = updateDeeply({}, val);
|
| 104 |
+
}
|
| 105 |
+
} else {
|
| 106 |
+
target[key] = val;
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
return target;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Main interface function. Takes an Espree syntax tree and returns the
|
| 115 |
+
* analyzed scopes.
|
| 116 |
+
* @function analyze
|
| 117 |
+
* @param {ESTree.Program} tree Abstract Syntax Tree
|
| 118 |
+
* @param {Object} providedOptions Options that tailor the scope analysis
|
| 119 |
+
* @param {boolean} [providedOptions.optimistic=false] the optimistic flag
|
| 120 |
+
* @param {boolean} [providedOptions.ignoreEval=false] whether to check 'eval()' calls
|
| 121 |
+
* @param {boolean} [providedOptions.nodejsScope=false] whether the whole
|
| 122 |
+
* script is executed under node.js environment. When enabled, escope adds
|
| 123 |
+
* a function scope immediately following the global scope.
|
| 124 |
+
* @param {boolean} [providedOptions.impliedStrict=false] implied strict mode
|
| 125 |
+
* (if ecmaVersion >= 5).
|
| 126 |
+
* @param {string} [providedOptions.sourceType='script'] the source type of the script. one of 'script', 'module', and 'commonjs'
|
| 127 |
+
* @param {number} [providedOptions.ecmaVersion=5] which ECMAScript version is considered
|
| 128 |
+
* @param {boolean} [providedOptions.jsx=false] support JSX references
|
| 129 |
+
* @param {Object} [providedOptions.childVisitorKeys=null] Additional known visitor keys. See [esrecurse](https://github.com/estools/esrecurse)'s the `childVisitorKeys` option.
|
| 130 |
+
* @param {string} [providedOptions.fallback='iteration'] A kind of the fallback in order to encounter with unknown node. See [esrecurse](https://github.com/estools/esrecurse)'s the `fallback` option.
|
| 131 |
+
* @returns {ScopeManager} ScopeManager
|
| 132 |
+
*/
|
| 133 |
+
function analyze(tree, providedOptions) {
|
| 134 |
+
const options = updateDeeply(defaultOptions(), providedOptions);
|
| 135 |
+
const scopeManager = new ScopeManager(options);
|
| 136 |
+
const referencer = new Referencer(options, scopeManager);
|
| 137 |
+
|
| 138 |
+
referencer.visit(tree);
|
| 139 |
+
|
| 140 |
+
assert(
|
| 141 |
+
scopeManager.__currentScope === null,
|
| 142 |
+
"currentScope should be null.",
|
| 143 |
+
);
|
| 144 |
+
|
| 145 |
+
return scopeManager;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/** @name module:escope.version */
|
| 149 |
+
export const version = "9.1.2"; // x-release-please-version
|
| 150 |
+
|
| 151 |
+
export {
|
| 152 |
+
/** @name module:escope.Reference */
|
| 153 |
+
Reference,
|
| 154 |
+
|
| 155 |
+
/** @name module:escope.Variable */
|
| 156 |
+
Variable,
|
| 157 |
+
|
| 158 |
+
/** @name module:escope.ScopeManager */
|
| 159 |
+
ScopeManager,
|
| 160 |
+
|
| 161 |
+
/** @name module:escope.Referencer */
|
| 162 |
+
Referencer,
|
| 163 |
+
analyze,
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
/** @name module:escope.Definition */
|
| 167 |
+
export { Definition } from "./definition.js";
|
| 168 |
+
|
| 169 |
+
/** @name module:escope.PatternVisitor */
|
| 170 |
+
export { default as PatternVisitor } from "./pattern-visitor.js";
|
| 171 |
+
|
| 172 |
+
/** @name module:escope.Scope */
|
| 173 |
+
export { Scope } from "./scope.js";
|
| 174 |
+
|
| 175 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/pattern-visitor.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import estraverse from "estraverse";
|
| 26 |
+
import esrecurse from "esrecurse";
|
| 27 |
+
|
| 28 |
+
/** @import * as types from "eslint-scope" */
|
| 29 |
+
|
| 30 |
+
const { Syntax } = estraverse;
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* Get last array element
|
| 34 |
+
* @param {Array} xs array
|
| 35 |
+
* @returns {any} Last elment
|
| 36 |
+
*/
|
| 37 |
+
function getLast(xs) {
|
| 38 |
+
return xs.at(-1) || null;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Visitor for destructuring patterns.
|
| 43 |
+
* @implements {types.PatternVisitor}
|
| 44 |
+
*/
|
| 45 |
+
class PatternVisitor extends esrecurse.Visitor {
|
| 46 |
+
static isPattern(node) {
|
| 47 |
+
const nodeType = node.type;
|
| 48 |
+
|
| 49 |
+
return (
|
| 50 |
+
nodeType === Syntax.Identifier ||
|
| 51 |
+
nodeType === Syntax.ObjectPattern ||
|
| 52 |
+
nodeType === Syntax.ArrayPattern ||
|
| 53 |
+
nodeType === Syntax.SpreadElement ||
|
| 54 |
+
nodeType === Syntax.RestElement ||
|
| 55 |
+
nodeType === Syntax.AssignmentPattern
|
| 56 |
+
);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
constructor(options, rootPattern, callback) {
|
| 60 |
+
super(null, options);
|
| 61 |
+
this.rootPattern = rootPattern;
|
| 62 |
+
this.callback = callback;
|
| 63 |
+
this.assignments = [];
|
| 64 |
+
this.rightHandNodes = [];
|
| 65 |
+
this.restElements = [];
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
Identifier(pattern) {
|
| 69 |
+
const lastRestElement = getLast(this.restElements);
|
| 70 |
+
|
| 71 |
+
this.callback(pattern, {
|
| 72 |
+
topLevel: pattern === this.rootPattern,
|
| 73 |
+
rest:
|
| 74 |
+
lastRestElement !== null &&
|
| 75 |
+
lastRestElement !== void 0 &&
|
| 76 |
+
lastRestElement.argument === pattern,
|
| 77 |
+
assignments: this.assignments,
|
| 78 |
+
});
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
Property(property) {
|
| 82 |
+
// Computed property's key is a right hand node.
|
| 83 |
+
if (property.computed) {
|
| 84 |
+
this.rightHandNodes.push(property.key);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// If it's shorthand, its key is same as its value.
|
| 88 |
+
// If it's shorthand and has its default value, its key is same as its value.left (the value is AssignmentPattern).
|
| 89 |
+
// If it's not shorthand, the name of new variable is its value's.
|
| 90 |
+
this.visit(property.value);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
ArrayPattern(pattern) {
|
| 94 |
+
for (let i = 0, iz = pattern.elements.length; i < iz; ++i) {
|
| 95 |
+
const element = pattern.elements[i];
|
| 96 |
+
|
| 97 |
+
this.visit(element);
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
AssignmentPattern(pattern) {
|
| 102 |
+
this.assignments.push(pattern);
|
| 103 |
+
this.visit(pattern.left);
|
| 104 |
+
this.rightHandNodes.push(pattern.right);
|
| 105 |
+
this.assignments.pop();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
RestElement(pattern) {
|
| 109 |
+
this.restElements.push(pattern);
|
| 110 |
+
this.visit(pattern.argument);
|
| 111 |
+
this.restElements.pop();
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
MemberExpression(node) {
|
| 115 |
+
// Computed property's key is a right hand node.
|
| 116 |
+
if (node.computed) {
|
| 117 |
+
this.rightHandNodes.push(node.property);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// the object is only read, write to its property.
|
| 121 |
+
this.rightHandNodes.push(node.object);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
//
|
| 125 |
+
// ForInStatement.left and AssignmentExpression.left are LeftHandSideExpression.
|
| 126 |
+
// By spec, LeftHandSideExpression is Pattern or MemberExpression.
|
| 127 |
+
// (see also: https://github.com/estree/estree/pull/20#issuecomment-74584758)
|
| 128 |
+
// But espree 2.0 parses to ArrayExpression, ObjectExpression, etc...
|
| 129 |
+
//
|
| 130 |
+
|
| 131 |
+
SpreadElement(node) {
|
| 132 |
+
this.visit(node.argument);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
ArrayExpression(node) {
|
| 136 |
+
node.elements.forEach(this.visit, this);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
AssignmentExpression(node) {
|
| 140 |
+
this.assignments.push(node);
|
| 141 |
+
this.visit(node.left);
|
| 142 |
+
this.rightHandNodes.push(node.right);
|
| 143 |
+
this.assignments.pop();
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
CallExpression(node) {
|
| 147 |
+
// arguments are right hand nodes.
|
| 148 |
+
node.arguments.forEach(a => {
|
| 149 |
+
this.rightHandNodes.push(a);
|
| 150 |
+
});
|
| 151 |
+
this.visit(node.callee);
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
export default PatternVisitor;
|
| 156 |
+
|
| 157 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/reference.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
/** @import * as types from "eslint-scope" */
|
| 26 |
+
|
| 27 |
+
const READ = 0x1;
|
| 28 |
+
const WRITE = 0x2;
|
| 29 |
+
const RW = READ | WRITE;
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* A Reference represents a single occurrence of an identifier in code.
|
| 33 |
+
* @constructor Reference
|
| 34 |
+
* @implements {types.Reference}
|
| 35 |
+
*/
|
| 36 |
+
class Reference {
|
| 37 |
+
constructor(
|
| 38 |
+
ident,
|
| 39 |
+
scope,
|
| 40 |
+
flag,
|
| 41 |
+
writeExpr,
|
| 42 |
+
maybeImplicitGlobal,
|
| 43 |
+
partial,
|
| 44 |
+
init,
|
| 45 |
+
) {
|
| 46 |
+
/**
|
| 47 |
+
* Identifier syntax node.
|
| 48 |
+
* @member {espreeIdentifier} Reference#identifier
|
| 49 |
+
*/
|
| 50 |
+
this.identifier = ident;
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Reference to the enclosing Scope.
|
| 54 |
+
* @member {Scope} Reference#from
|
| 55 |
+
*/
|
| 56 |
+
this.from = scope;
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Whether the reference comes from a dynamic scope (such as 'eval',
|
| 60 |
+
* 'with', etc.), and may be trapped by dynamic scopes.
|
| 61 |
+
* @member {boolean} Reference#tainted
|
| 62 |
+
*/
|
| 63 |
+
this.tainted = false;
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* The variable this reference is resolved with.
|
| 67 |
+
* @member {Variable} Reference#resolved
|
| 68 |
+
*/
|
| 69 |
+
this.resolved = null;
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* The read-write mode of the reference. (Value is one of {@link
|
| 73 |
+
* Reference.READ}, {@link Reference.RW}, {@link Reference.WRITE}).
|
| 74 |
+
* @member {number} Reference#flag
|
| 75 |
+
*/
|
| 76 |
+
this.flag = flag;
|
| 77 |
+
if (this.isWrite()) {
|
| 78 |
+
/**
|
| 79 |
+
* If reference is writeable, this is the tree being written to it.
|
| 80 |
+
* @member {espreeNode} Reference#writeExpr
|
| 81 |
+
*/
|
| 82 |
+
this.writeExpr = writeExpr;
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Whether the Reference might refer to a partial value of writeExpr.
|
| 86 |
+
* @member {boolean} Reference#partial
|
| 87 |
+
*/
|
| 88 |
+
this.partial = partial;
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Whether the Reference is to write of initialization.
|
| 92 |
+
* @member {boolean} Reference#init
|
| 93 |
+
*/
|
| 94 |
+
this.init = init;
|
| 95 |
+
}
|
| 96 |
+
this.__maybeImplicitGlobal = maybeImplicitGlobal;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* Whether the reference is static.
|
| 101 |
+
* @function Reference#isStatic
|
| 102 |
+
* @returns {boolean} static
|
| 103 |
+
*/
|
| 104 |
+
isStatic() {
|
| 105 |
+
return (
|
| 106 |
+
!this.tainted && !!this.resolved && this.resolved.scope.isStatic()
|
| 107 |
+
);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/**
|
| 111 |
+
* Whether the reference is writeable.
|
| 112 |
+
* @function Reference#isWrite
|
| 113 |
+
* @returns {boolean} write
|
| 114 |
+
*/
|
| 115 |
+
isWrite() {
|
| 116 |
+
return !!(this.flag & Reference.WRITE);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/**
|
| 120 |
+
* Whether the reference is readable.
|
| 121 |
+
* @function Reference#isRead
|
| 122 |
+
* @returns {boolean} read
|
| 123 |
+
*/
|
| 124 |
+
isRead() {
|
| 125 |
+
return !!(this.flag & Reference.READ);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/**
|
| 129 |
+
* Whether the reference is read-only.
|
| 130 |
+
* @function Reference#isReadOnly
|
| 131 |
+
* @returns {boolean} read only
|
| 132 |
+
*/
|
| 133 |
+
isReadOnly() {
|
| 134 |
+
return this.flag === Reference.READ;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/**
|
| 138 |
+
* Whether the reference is write-only.
|
| 139 |
+
* @function Reference#isWriteOnly
|
| 140 |
+
* @returns {boolean} write only
|
| 141 |
+
*/
|
| 142 |
+
isWriteOnly() {
|
| 143 |
+
return this.flag === Reference.WRITE;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/**
|
| 147 |
+
* Whether the reference is read-write.
|
| 148 |
+
* @function Reference#isReadWrite
|
| 149 |
+
* @returns {boolean} read write
|
| 150 |
+
*/
|
| 151 |
+
isReadWrite() {
|
| 152 |
+
return this.flag === Reference.RW;
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
/**
|
| 157 |
+
* @constant Reference.READ
|
| 158 |
+
*/
|
| 159 |
+
Reference.READ = READ;
|
| 160 |
+
|
| 161 |
+
/**
|
| 162 |
+
* @constant Reference.WRITE
|
| 163 |
+
*/
|
| 164 |
+
Reference.WRITE = WRITE;
|
| 165 |
+
|
| 166 |
+
/**
|
| 167 |
+
* @constant Reference.RW
|
| 168 |
+
*/
|
| 169 |
+
Reference.RW = RW;
|
| 170 |
+
|
| 171 |
+
export default Reference;
|
| 172 |
+
|
| 173 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/referencer.js
ADDED
|
@@ -0,0 +1,817 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import estraverse from "estraverse";
|
| 26 |
+
import esrecurse from "esrecurse";
|
| 27 |
+
import Reference from "./reference.js";
|
| 28 |
+
import Variable from "./variable.js";
|
| 29 |
+
import PatternVisitor from "./pattern-visitor.js";
|
| 30 |
+
import { Definition, ParameterDefinition } from "./definition.js";
|
| 31 |
+
import { assert } from "./assert.js";
|
| 32 |
+
|
| 33 |
+
/** @import * as types from "eslint-scope" */
|
| 34 |
+
/** @import ESTree from "estree" */
|
| 35 |
+
|
| 36 |
+
const { Syntax } = estraverse;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Traverse identifier in pattern
|
| 40 |
+
* @param {Object} options options
|
| 41 |
+
* @param {ESTree.Pattern} rootPattern root pattern
|
| 42 |
+
* @param {?Referencer} referencer referencer
|
| 43 |
+
* @param {types.PatternVisitorCallback} callback callback
|
| 44 |
+
* @returns {void}
|
| 45 |
+
*/
|
| 46 |
+
function traverseIdentifierInPattern(
|
| 47 |
+
options,
|
| 48 |
+
rootPattern,
|
| 49 |
+
referencer,
|
| 50 |
+
callback,
|
| 51 |
+
) {
|
| 52 |
+
// Call the callback at left hand identifier nodes, and Collect right hand nodes.
|
| 53 |
+
const visitor = new PatternVisitor(options, rootPattern, callback);
|
| 54 |
+
|
| 55 |
+
visitor.visit(rootPattern);
|
| 56 |
+
|
| 57 |
+
// Process the right hand nodes recursively.
|
| 58 |
+
if (referencer !== null && referencer !== void 0) {
|
| 59 |
+
visitor.rightHandNodes.forEach(referencer.visit, referencer);
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Importing ImportDeclaration.
|
| 64 |
+
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation
|
| 65 |
+
// https://github.com/estree/estree/blob/master/es6.md#importdeclaration
|
| 66 |
+
// FIXME: Now, we don't create module environment, because the context is
|
| 67 |
+
// implementation dependent.
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Visitor for import specifiers.
|
| 71 |
+
*/
|
| 72 |
+
class Importer extends esrecurse.Visitor {
|
| 73 |
+
constructor(declaration, referencer) {
|
| 74 |
+
super(null, referencer.options);
|
| 75 |
+
this.declaration = declaration;
|
| 76 |
+
this.referencer = referencer;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
visitImport(id, specifier) {
|
| 80 |
+
this.referencer.visitPattern(id, pattern => {
|
| 81 |
+
this.referencer
|
| 82 |
+
.currentScope()
|
| 83 |
+
.__define(
|
| 84 |
+
pattern,
|
| 85 |
+
new Definition(
|
| 86 |
+
Variable.ImportBinding,
|
| 87 |
+
pattern,
|
| 88 |
+
specifier,
|
| 89 |
+
this.declaration,
|
| 90 |
+
null,
|
| 91 |
+
null,
|
| 92 |
+
),
|
| 93 |
+
);
|
| 94 |
+
});
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
ImportNamespaceSpecifier(node) {
|
| 98 |
+
const local = node.local || node.id;
|
| 99 |
+
|
| 100 |
+
if (local) {
|
| 101 |
+
this.visitImport(local, node);
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
ImportDefaultSpecifier(node) {
|
| 106 |
+
const local = node.local || node.id;
|
| 107 |
+
|
| 108 |
+
this.visitImport(local, node);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
ImportSpecifier(node) {
|
| 112 |
+
const local = node.local || node.id;
|
| 113 |
+
|
| 114 |
+
if (node.name) {
|
| 115 |
+
this.visitImport(node.name, node);
|
| 116 |
+
} else {
|
| 117 |
+
this.visitImport(local, node);
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/**
|
| 123 |
+
* Referencing variables and creating bindings.
|
| 124 |
+
* @implements {types.Referencer}
|
| 125 |
+
*/
|
| 126 |
+
class Referencer extends esrecurse.Visitor {
|
| 127 |
+
constructor(options, scopeManager) {
|
| 128 |
+
super(null, options);
|
| 129 |
+
this.options = options;
|
| 130 |
+
this.scopeManager = scopeManager;
|
| 131 |
+
this.parent = null;
|
| 132 |
+
this.isInnerMethodDefinition = false;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
currentScope() {
|
| 136 |
+
return this.scopeManager.__currentScope;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
close(node) {
|
| 140 |
+
while (this.currentScope() && node === this.currentScope().block) {
|
| 141 |
+
this.scopeManager.__currentScope = this.currentScope().__close(
|
| 142 |
+
this.scopeManager,
|
| 143 |
+
);
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
pushInnerMethodDefinition(isInnerMethodDefinition) {
|
| 148 |
+
const previous = this.isInnerMethodDefinition;
|
| 149 |
+
|
| 150 |
+
this.isInnerMethodDefinition = isInnerMethodDefinition;
|
| 151 |
+
return previous;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
popInnerMethodDefinition(isInnerMethodDefinition) {
|
| 155 |
+
this.isInnerMethodDefinition = isInnerMethodDefinition;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
referencingDefaultValue(pattern, assignments, maybeImplicitGlobal, init) {
|
| 159 |
+
const scope = this.currentScope();
|
| 160 |
+
|
| 161 |
+
assignments.forEach(assignment => {
|
| 162 |
+
scope.__referencing(
|
| 163 |
+
pattern,
|
| 164 |
+
Reference.WRITE,
|
| 165 |
+
assignment.right,
|
| 166 |
+
maybeImplicitGlobal,
|
| 167 |
+
pattern !== assignment.left,
|
| 168 |
+
init,
|
| 169 |
+
);
|
| 170 |
+
});
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
visitPattern(node, options, callback) {
|
| 174 |
+
let visitPatternOptions = options;
|
| 175 |
+
let visitPatternCallback = callback;
|
| 176 |
+
|
| 177 |
+
if (typeof options === "function") {
|
| 178 |
+
visitPatternCallback = options;
|
| 179 |
+
visitPatternOptions = { processRightHandNodes: false };
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
traverseIdentifierInPattern(
|
| 183 |
+
this.options,
|
| 184 |
+
node,
|
| 185 |
+
visitPatternOptions.processRightHandNodes ? this : null,
|
| 186 |
+
visitPatternCallback,
|
| 187 |
+
);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
visitFunction(node) {
|
| 191 |
+
let i, iz;
|
| 192 |
+
|
| 193 |
+
// FunctionDeclaration name is defined in upper scope
|
| 194 |
+
// NOTE: Not referring variableScope. It is intended.
|
| 195 |
+
// Since
|
| 196 |
+
// in ES5, FunctionDeclaration should be in FunctionBody.
|
| 197 |
+
// in ES6, FunctionDeclaration should be block scoped.
|
| 198 |
+
|
| 199 |
+
if (node.type === Syntax.FunctionDeclaration) {
|
| 200 |
+
// id is defined in upper scope
|
| 201 |
+
this.currentScope().__define(
|
| 202 |
+
node.id,
|
| 203 |
+
new Definition(
|
| 204 |
+
Variable.FunctionName,
|
| 205 |
+
node.id,
|
| 206 |
+
node,
|
| 207 |
+
null,
|
| 208 |
+
null,
|
| 209 |
+
null,
|
| 210 |
+
),
|
| 211 |
+
);
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
// FunctionExpression with name creates its special scope;
|
| 215 |
+
// FunctionExpressionNameScope.
|
| 216 |
+
if (node.type === Syntax.FunctionExpression && node.id) {
|
| 217 |
+
this.scopeManager.__nestFunctionExpressionNameScope(node);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
// Consider this function is in the MethodDefinition.
|
| 221 |
+
this.scopeManager.__nestFunctionScope(
|
| 222 |
+
node,
|
| 223 |
+
this.isInnerMethodDefinition,
|
| 224 |
+
);
|
| 225 |
+
|
| 226 |
+
const that = this;
|
| 227 |
+
|
| 228 |
+
/**
|
| 229 |
+
* Visit pattern callback
|
| 230 |
+
* @param {ESTree.Pattern} pattern pattern
|
| 231 |
+
* @param {Object} info info
|
| 232 |
+
* @returns {void}
|
| 233 |
+
*/
|
| 234 |
+
function visitPatternCallback(pattern, info) {
|
| 235 |
+
that.currentScope().__define(
|
| 236 |
+
pattern,
|
| 237 |
+
new ParameterDefinition(pattern, node, i, info.rest),
|
| 238 |
+
);
|
| 239 |
+
|
| 240 |
+
that.referencingDefaultValue(pattern, info.assignments, null, true);
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
// Process parameter declarations.
|
| 244 |
+
for (i = 0, iz = node.params.length; i < iz; ++i) {
|
| 245 |
+
this.visitPattern(
|
| 246 |
+
node.params[i],
|
| 247 |
+
{ processRightHandNodes: true },
|
| 248 |
+
visitPatternCallback,
|
| 249 |
+
);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
// if there's a rest argument, add that
|
| 253 |
+
if (node.rest) {
|
| 254 |
+
this.visitPattern(
|
| 255 |
+
{
|
| 256 |
+
type: "RestElement",
|
| 257 |
+
argument: node.rest,
|
| 258 |
+
},
|
| 259 |
+
pattern => {
|
| 260 |
+
this.currentScope().__define(
|
| 261 |
+
pattern,
|
| 262 |
+
new ParameterDefinition(
|
| 263 |
+
pattern,
|
| 264 |
+
node,
|
| 265 |
+
node.params.length,
|
| 266 |
+
true,
|
| 267 |
+
),
|
| 268 |
+
);
|
| 269 |
+
},
|
| 270 |
+
);
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
// In TypeScript there are a number of function-like constructs which have no body,
|
| 274 |
+
// so check it exists before traversing
|
| 275 |
+
if (node.body) {
|
| 276 |
+
// Skip BlockStatement to prevent creating BlockStatement scope.
|
| 277 |
+
if (node.body.type === Syntax.BlockStatement) {
|
| 278 |
+
this.visitChildren(node.body);
|
| 279 |
+
} else {
|
| 280 |
+
this.visit(node.body);
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
this.close(node);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
visitClass(node) {
|
| 288 |
+
if (node.type === Syntax.ClassDeclaration) {
|
| 289 |
+
this.currentScope().__define(
|
| 290 |
+
node.id,
|
| 291 |
+
new Definition(
|
| 292 |
+
Variable.ClassName,
|
| 293 |
+
node.id,
|
| 294 |
+
node,
|
| 295 |
+
null,
|
| 296 |
+
null,
|
| 297 |
+
null,
|
| 298 |
+
),
|
| 299 |
+
);
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
this.scopeManager.__nestClassScope(node);
|
| 303 |
+
|
| 304 |
+
if (node.id) {
|
| 305 |
+
this.currentScope().__define(
|
| 306 |
+
node.id,
|
| 307 |
+
new Definition(Variable.ClassName, node.id, node),
|
| 308 |
+
);
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
this.visit(node.superClass);
|
| 312 |
+
this.visit(node.body);
|
| 313 |
+
|
| 314 |
+
this.close(node);
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
visitProperty(node) {
|
| 318 |
+
let previous;
|
| 319 |
+
|
| 320 |
+
if (node.computed) {
|
| 321 |
+
this.visit(node.key);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
const isMethodDefinition = node.type === Syntax.MethodDefinition;
|
| 325 |
+
|
| 326 |
+
if (isMethodDefinition) {
|
| 327 |
+
previous = this.pushInnerMethodDefinition(true);
|
| 328 |
+
}
|
| 329 |
+
this.visit(node.value);
|
| 330 |
+
if (isMethodDefinition) {
|
| 331 |
+
this.popInnerMethodDefinition(previous);
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
visitForIn(node) {
|
| 336 |
+
if (
|
| 337 |
+
node.left.type === Syntax.VariableDeclaration &&
|
| 338 |
+
node.left.kind !== "var"
|
| 339 |
+
) {
|
| 340 |
+
this.scopeManager.__nestForScope(node);
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
if (node.left.type === Syntax.VariableDeclaration) {
|
| 344 |
+
this.visit(node.left);
|
| 345 |
+
this.visitPattern(node.left.declarations[0].id, pattern => {
|
| 346 |
+
this.currentScope().__referencing(
|
| 347 |
+
pattern,
|
| 348 |
+
Reference.WRITE,
|
| 349 |
+
node.right,
|
| 350 |
+
null,
|
| 351 |
+
true,
|
| 352 |
+
true,
|
| 353 |
+
);
|
| 354 |
+
});
|
| 355 |
+
} else {
|
| 356 |
+
this.visitPattern(
|
| 357 |
+
node.left,
|
| 358 |
+
{ processRightHandNodes: true },
|
| 359 |
+
(pattern, info) => {
|
| 360 |
+
let maybeImplicitGlobal = null;
|
| 361 |
+
|
| 362 |
+
if (!this.currentScope().isStrict) {
|
| 363 |
+
maybeImplicitGlobal = {
|
| 364 |
+
pattern,
|
| 365 |
+
node,
|
| 366 |
+
};
|
| 367 |
+
}
|
| 368 |
+
this.referencingDefaultValue(
|
| 369 |
+
pattern,
|
| 370 |
+
info.assignments,
|
| 371 |
+
maybeImplicitGlobal,
|
| 372 |
+
false,
|
| 373 |
+
);
|
| 374 |
+
this.currentScope().__referencing(
|
| 375 |
+
pattern,
|
| 376 |
+
Reference.WRITE,
|
| 377 |
+
node.right,
|
| 378 |
+
maybeImplicitGlobal,
|
| 379 |
+
true,
|
| 380 |
+
false,
|
| 381 |
+
);
|
| 382 |
+
},
|
| 383 |
+
);
|
| 384 |
+
}
|
| 385 |
+
this.visit(node.right);
|
| 386 |
+
this.visit(node.body);
|
| 387 |
+
|
| 388 |
+
this.close(node);
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
visitVariableDeclaration(variableTargetScope, type, node, index) {
|
| 392 |
+
const decl = node.declarations[index];
|
| 393 |
+
const init = decl.init;
|
| 394 |
+
|
| 395 |
+
this.visitPattern(
|
| 396 |
+
decl.id,
|
| 397 |
+
{ processRightHandNodes: true },
|
| 398 |
+
(pattern, info) => {
|
| 399 |
+
variableTargetScope.__define(
|
| 400 |
+
pattern,
|
| 401 |
+
new Definition(type, pattern, decl, node, index, node.kind),
|
| 402 |
+
);
|
| 403 |
+
|
| 404 |
+
this.referencingDefaultValue(
|
| 405 |
+
pattern,
|
| 406 |
+
info.assignments,
|
| 407 |
+
null,
|
| 408 |
+
true,
|
| 409 |
+
);
|
| 410 |
+
if (init) {
|
| 411 |
+
this.currentScope().__referencing(
|
| 412 |
+
pattern,
|
| 413 |
+
Reference.WRITE,
|
| 414 |
+
init,
|
| 415 |
+
null,
|
| 416 |
+
!info.topLevel,
|
| 417 |
+
true,
|
| 418 |
+
);
|
| 419 |
+
}
|
| 420 |
+
},
|
| 421 |
+
);
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
AssignmentExpression(node) {
|
| 425 |
+
if (PatternVisitor.isPattern(node.left)) {
|
| 426 |
+
if (node.operator === "=") {
|
| 427 |
+
this.visitPattern(
|
| 428 |
+
node.left,
|
| 429 |
+
{ processRightHandNodes: true },
|
| 430 |
+
(pattern, info) => {
|
| 431 |
+
let maybeImplicitGlobal = null;
|
| 432 |
+
|
| 433 |
+
if (!this.currentScope().isStrict) {
|
| 434 |
+
maybeImplicitGlobal = {
|
| 435 |
+
pattern,
|
| 436 |
+
node,
|
| 437 |
+
};
|
| 438 |
+
}
|
| 439 |
+
this.referencingDefaultValue(
|
| 440 |
+
pattern,
|
| 441 |
+
info.assignments,
|
| 442 |
+
maybeImplicitGlobal,
|
| 443 |
+
false,
|
| 444 |
+
);
|
| 445 |
+
this.currentScope().__referencing(
|
| 446 |
+
pattern,
|
| 447 |
+
Reference.WRITE,
|
| 448 |
+
node.right,
|
| 449 |
+
maybeImplicitGlobal,
|
| 450 |
+
!info.topLevel,
|
| 451 |
+
false,
|
| 452 |
+
);
|
| 453 |
+
},
|
| 454 |
+
);
|
| 455 |
+
} else {
|
| 456 |
+
this.currentScope().__referencing(
|
| 457 |
+
node.left,
|
| 458 |
+
Reference.RW,
|
| 459 |
+
node.right,
|
| 460 |
+
);
|
| 461 |
+
}
|
| 462 |
+
} else {
|
| 463 |
+
this.visit(node.left);
|
| 464 |
+
}
|
| 465 |
+
this.visit(node.right);
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
CatchClause(node) {
|
| 469 |
+
this.scopeManager.__nestCatchScope(node);
|
| 470 |
+
|
| 471 |
+
this.visitPattern(
|
| 472 |
+
node.param,
|
| 473 |
+
{ processRightHandNodes: true },
|
| 474 |
+
(pattern, info) => {
|
| 475 |
+
this.currentScope().__define(
|
| 476 |
+
pattern,
|
| 477 |
+
new Definition(
|
| 478 |
+
Variable.CatchClause,
|
| 479 |
+
pattern,
|
| 480 |
+
node,
|
| 481 |
+
null,
|
| 482 |
+
null,
|
| 483 |
+
null,
|
| 484 |
+
),
|
| 485 |
+
);
|
| 486 |
+
this.referencingDefaultValue(
|
| 487 |
+
pattern,
|
| 488 |
+
info.assignments,
|
| 489 |
+
null,
|
| 490 |
+
true,
|
| 491 |
+
);
|
| 492 |
+
},
|
| 493 |
+
);
|
| 494 |
+
this.visit(node.body);
|
| 495 |
+
|
| 496 |
+
this.close(node);
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
Program(node) {
|
| 500 |
+
this.scopeManager.__nestGlobalScope(node);
|
| 501 |
+
|
| 502 |
+
if (this.scopeManager.isGlobalReturn()) {
|
| 503 |
+
// Force strictness of GlobalScope to false when using node.js scope.
|
| 504 |
+
this.currentScope().isStrict = false;
|
| 505 |
+
this.scopeManager.__nestFunctionScope(node, false);
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
if (this.scopeManager.__isES6() && this.scopeManager.isModule()) {
|
| 509 |
+
this.scopeManager.__nestModuleScope(node);
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
if (
|
| 513 |
+
this.scopeManager.isStrictModeSupported() &&
|
| 514 |
+
this.scopeManager.isImpliedStrict()
|
| 515 |
+
) {
|
| 516 |
+
this.currentScope().isStrict = true;
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
this.visitChildren(node);
|
| 520 |
+
this.close(node);
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
Identifier(node) {
|
| 524 |
+
this.currentScope().__referencing(node);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
// eslint-disable-next-line class-methods-use-this -- Desired as instance method
|
| 528 |
+
PrivateIdentifier() {
|
| 529 |
+
// Do nothing.
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
UpdateExpression(node) {
|
| 533 |
+
if (PatternVisitor.isPattern(node.argument)) {
|
| 534 |
+
this.currentScope().__referencing(
|
| 535 |
+
node.argument,
|
| 536 |
+
Reference.RW,
|
| 537 |
+
null,
|
| 538 |
+
);
|
| 539 |
+
} else {
|
| 540 |
+
this.visitChildren(node);
|
| 541 |
+
}
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
MemberExpression(node) {
|
| 545 |
+
this.visit(node.object);
|
| 546 |
+
if (node.computed) {
|
| 547 |
+
this.visit(node.property);
|
| 548 |
+
}
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
Property(node) {
|
| 552 |
+
this.visitProperty(node);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
PropertyDefinition(node) {
|
| 556 |
+
const { computed, key, value } = node;
|
| 557 |
+
|
| 558 |
+
if (computed) {
|
| 559 |
+
this.visit(key);
|
| 560 |
+
}
|
| 561 |
+
if (value) {
|
| 562 |
+
this.scopeManager.__nestClassFieldInitializerScope(value);
|
| 563 |
+
this.visit(value);
|
| 564 |
+
this.close(value);
|
| 565 |
+
}
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
StaticBlock(node) {
|
| 569 |
+
this.scopeManager.__nestClassStaticBlockScope(node);
|
| 570 |
+
|
| 571 |
+
this.visitChildren(node);
|
| 572 |
+
|
| 573 |
+
this.close(node);
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
MethodDefinition(node) {
|
| 577 |
+
this.visitProperty(node);
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
BreakStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 581 |
+
|
| 582 |
+
ContinueStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 583 |
+
|
| 584 |
+
LabeledStatement(node) {
|
| 585 |
+
this.visit(node.body);
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
ForStatement(node) {
|
| 589 |
+
// Create ForStatement declaration.
|
| 590 |
+
// NOTE: In ES6, ForStatement dynamically generates
|
| 591 |
+
// per iteration environment. However, escope is
|
| 592 |
+
// a static analyzer, we only generate one scope for ForStatement.
|
| 593 |
+
if (
|
| 594 |
+
node.init &&
|
| 595 |
+
node.init.type === Syntax.VariableDeclaration &&
|
| 596 |
+
node.init.kind !== "var"
|
| 597 |
+
) {
|
| 598 |
+
this.scopeManager.__nestForScope(node);
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
this.visitChildren(node);
|
| 602 |
+
|
| 603 |
+
this.close(node);
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
ClassExpression(node) {
|
| 607 |
+
this.visitClass(node);
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
ClassDeclaration(node) {
|
| 611 |
+
this.visitClass(node);
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
CallExpression(node) {
|
| 615 |
+
// Check this is direct call to eval
|
| 616 |
+
if (
|
| 617 |
+
!this.scopeManager.__ignoreEval() &&
|
| 618 |
+
node.callee.type === Syntax.Identifier &&
|
| 619 |
+
node.callee.name === "eval"
|
| 620 |
+
) {
|
| 621 |
+
// NOTE: This should be `variableScope`. Since direct eval call always creates Lexical environment and
|
| 622 |
+
// let / const should be enclosed into it. Only VariableDeclaration affects on the caller's environment.
|
| 623 |
+
this.currentScope().variableScope.__detectEval();
|
| 624 |
+
}
|
| 625 |
+
this.visitChildren(node);
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
BlockStatement(node) {
|
| 629 |
+
if (this.scopeManager.__isES6()) {
|
| 630 |
+
this.scopeManager.__nestBlockScope(node);
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
this.visitChildren(node);
|
| 634 |
+
|
| 635 |
+
this.close(node);
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
ThisExpression() {
|
| 639 |
+
this.currentScope().variableScope.__detectThis();
|
| 640 |
+
}
|
| 641 |
+
|
| 642 |
+
WithStatement(node) {
|
| 643 |
+
this.visit(node.object);
|
| 644 |
+
|
| 645 |
+
// Then nest scope for WithStatement.
|
| 646 |
+
this.scopeManager.__nestWithScope(node);
|
| 647 |
+
|
| 648 |
+
this.visit(node.body);
|
| 649 |
+
|
| 650 |
+
this.close(node);
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
VariableDeclaration(node) {
|
| 654 |
+
const variableTargetScope =
|
| 655 |
+
node.kind === "var"
|
| 656 |
+
? this.currentScope().variableScope
|
| 657 |
+
: this.currentScope();
|
| 658 |
+
|
| 659 |
+
for (let i = 0, iz = node.declarations.length; i < iz; ++i) {
|
| 660 |
+
const decl = node.declarations[i];
|
| 661 |
+
|
| 662 |
+
this.visitVariableDeclaration(
|
| 663 |
+
variableTargetScope,
|
| 664 |
+
Variable.Variable,
|
| 665 |
+
node,
|
| 666 |
+
i,
|
| 667 |
+
);
|
| 668 |
+
if (decl.init) {
|
| 669 |
+
this.visit(decl.init);
|
| 670 |
+
}
|
| 671 |
+
}
|
| 672 |
+
}
|
| 673 |
+
|
| 674 |
+
// sec 13.11.8
|
| 675 |
+
SwitchStatement(node) {
|
| 676 |
+
this.visit(node.discriminant);
|
| 677 |
+
|
| 678 |
+
if (this.scopeManager.__isES6()) {
|
| 679 |
+
this.scopeManager.__nestSwitchScope(node);
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
for (let i = 0, iz = node.cases.length; i < iz; ++i) {
|
| 683 |
+
this.visit(node.cases[i]);
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
this.close(node);
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
FunctionDeclaration(node) {
|
| 690 |
+
this.visitFunction(node);
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
FunctionExpression(node) {
|
| 694 |
+
this.visitFunction(node);
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
ForOfStatement(node) {
|
| 698 |
+
this.visitForIn(node);
|
| 699 |
+
}
|
| 700 |
+
|
| 701 |
+
ForInStatement(node) {
|
| 702 |
+
this.visitForIn(node);
|
| 703 |
+
}
|
| 704 |
+
|
| 705 |
+
ArrowFunctionExpression(node) {
|
| 706 |
+
this.visitFunction(node);
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
ImportDeclaration(node) {
|
| 710 |
+
assert(
|
| 711 |
+
this.scopeManager.__isES6() && this.scopeManager.isModule(),
|
| 712 |
+
"ImportDeclaration should appear when the mode is ES6 and in the module context.",
|
| 713 |
+
);
|
| 714 |
+
|
| 715 |
+
const importer = new Importer(node, this);
|
| 716 |
+
|
| 717 |
+
importer.visit(node);
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
visitExportDeclaration(node) {
|
| 721 |
+
if (node.source) {
|
| 722 |
+
return;
|
| 723 |
+
}
|
| 724 |
+
if (node.declaration) {
|
| 725 |
+
this.visit(node.declaration);
|
| 726 |
+
return;
|
| 727 |
+
}
|
| 728 |
+
|
| 729 |
+
this.visitChildren(node);
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
// TODO: ExportDeclaration doesn't exist. for bc?
|
| 733 |
+
ExportDeclaration(node) {
|
| 734 |
+
this.visitExportDeclaration(node);
|
| 735 |
+
}
|
| 736 |
+
|
| 737 |
+
ExportAllDeclaration(node) {
|
| 738 |
+
this.visitExportDeclaration(node);
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
ExportDefaultDeclaration(node) {
|
| 742 |
+
this.visitExportDeclaration(node);
|
| 743 |
+
}
|
| 744 |
+
|
| 745 |
+
ExportNamedDeclaration(node) {
|
| 746 |
+
this.visitExportDeclaration(node);
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
ExportSpecifier(node) {
|
| 750 |
+
// TODO: `node.id` doesn't exist. for bc?
|
| 751 |
+
const local = node.id || node.local;
|
| 752 |
+
|
| 753 |
+
this.visit(local);
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
// eslint-disable-next-line class-methods-use-this -- Desired as instance method
|
| 757 |
+
MetaProperty() {
|
| 758 |
+
// do nothing.
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
JSXIdentifier(node) {
|
| 762 |
+
// Special case: "this" should not count as a reference
|
| 763 |
+
if (this.scopeManager.__isJSXEnabled() && node.name !== "this") {
|
| 764 |
+
this.currentScope().__referencing(node);
|
| 765 |
+
}
|
| 766 |
+
}
|
| 767 |
+
|
| 768 |
+
JSXMemberExpression(node) {
|
| 769 |
+
this.visit(node.object);
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
JSXElement(node) {
|
| 773 |
+
if (this.scopeManager.__isJSXEnabled()) {
|
| 774 |
+
this.visit(node.openingElement);
|
| 775 |
+
node.children.forEach(this.visit, this);
|
| 776 |
+
} else {
|
| 777 |
+
this.visitChildren(node);
|
| 778 |
+
}
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
JSXOpeningElement(node) {
|
| 782 |
+
if (this.scopeManager.__isJSXEnabled()) {
|
| 783 |
+
const nameNode = node.name;
|
| 784 |
+
const isComponentName =
|
| 785 |
+
nameNode.type === "JSXIdentifier" &&
|
| 786 |
+
nameNode.name[0].toUpperCase() === nameNode.name[0];
|
| 787 |
+
const isComponent =
|
| 788 |
+
isComponentName || nameNode.type === "JSXMemberExpression";
|
| 789 |
+
|
| 790 |
+
// we only want to visit JSXIdentifier nodes if they are capitalized
|
| 791 |
+
if (isComponent) {
|
| 792 |
+
this.visit(nameNode);
|
| 793 |
+
}
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
node.attributes.forEach(this.visit, this);
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
JSXAttribute(node) {
|
| 800 |
+
if (node.value) {
|
| 801 |
+
this.visit(node.value);
|
| 802 |
+
}
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
JSXExpressionContainer(node) {
|
| 806 |
+
this.visit(node.expression);
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
JSXNamespacedName(node) {
|
| 810 |
+
this.visit(node.namespace);
|
| 811 |
+
this.visit(node.name);
|
| 812 |
+
}
|
| 813 |
+
}
|
| 814 |
+
|
| 815 |
+
export default Referencer;
|
| 816 |
+
|
| 817 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/scope-manager.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import {
|
| 26 |
+
BlockScope,
|
| 27 |
+
CatchScope,
|
| 28 |
+
ClassFieldInitializerScope,
|
| 29 |
+
ClassStaticBlockScope,
|
| 30 |
+
ClassScope,
|
| 31 |
+
ForScope,
|
| 32 |
+
FunctionExpressionNameScope,
|
| 33 |
+
FunctionScope,
|
| 34 |
+
GlobalScope,
|
| 35 |
+
ModuleScope,
|
| 36 |
+
SwitchScope,
|
| 37 |
+
WithScope,
|
| 38 |
+
} from "./scope.js";
|
| 39 |
+
import { assert } from "./assert.js";
|
| 40 |
+
|
| 41 |
+
/** @import * as types from "eslint-scope" */
|
| 42 |
+
/** @import ESTree from "estree" */
|
| 43 |
+
/** @import { Scope } from "./scope.js" */
|
| 44 |
+
/** @import Variable from "./variable.js" */
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* @constructor ScopeManager
|
| 48 |
+
* @implements {types.ScopeManager}
|
| 49 |
+
*/
|
| 50 |
+
class ScopeManager {
|
| 51 |
+
constructor(options) {
|
| 52 |
+
this.scopes = [];
|
| 53 |
+
this.globalScope = null;
|
| 54 |
+
this.__nodeToScope = new WeakMap();
|
| 55 |
+
this.__currentScope = null;
|
| 56 |
+
this.__options = options;
|
| 57 |
+
this.__declaredVariables = new WeakMap();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
__isOptimistic() {
|
| 61 |
+
return this.__options.optimistic;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
__ignoreEval() {
|
| 65 |
+
return this.__options.ignoreEval;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
__isJSXEnabled() {
|
| 69 |
+
return this.__options.jsx === true;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
isGlobalReturn() {
|
| 73 |
+
return (
|
| 74 |
+
this.__options.nodejsScope ||
|
| 75 |
+
this.__options.sourceType === "commonjs"
|
| 76 |
+
);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
isModule() {
|
| 80 |
+
return this.__options.sourceType === "module";
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
isImpliedStrict() {
|
| 84 |
+
return !!this.__options.impliedStrict;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
isStrictModeSupported() {
|
| 88 |
+
return this.__options.ecmaVersion >= 5;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Returns appropriate scope for this node.
|
| 92 |
+
__get(node) {
|
| 93 |
+
return this.__nodeToScope.get(node);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Get variables that are declared by the node.
|
| 98 |
+
*
|
| 99 |
+
* "are declared by the node" means the node is same as `Variable.defs[].node` or `Variable.defs[].parent`.
|
| 100 |
+
* If the node declares nothing, this method returns an empty array.
|
| 101 |
+
* CAUTION: This API is experimental. See https://github.com/estools/escope/pull/69 for more details.
|
| 102 |
+
* @param {ESTree.Node} node a node to get.
|
| 103 |
+
* @returns {Variable[]} variables that declared by the node.
|
| 104 |
+
*/
|
| 105 |
+
getDeclaredVariables(node) {
|
| 106 |
+
return this.__declaredVariables.get(node) || [];
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* acquire scope from node.
|
| 111 |
+
* @function ScopeManager#acquire
|
| 112 |
+
* @param {ESTree.Node} node node for the acquired scope.
|
| 113 |
+
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
|
| 114 |
+
* @returns {Scope?} Scope from node
|
| 115 |
+
*/
|
| 116 |
+
acquire(node, inner) {
|
| 117 |
+
/**
|
| 118 |
+
* predicate
|
| 119 |
+
* @param {Scope} testScope scope to test
|
| 120 |
+
* @returns {boolean} predicate
|
| 121 |
+
*/
|
| 122 |
+
function predicate(testScope) {
|
| 123 |
+
if (
|
| 124 |
+
testScope.type === "function" &&
|
| 125 |
+
testScope.functionExpressionScope
|
| 126 |
+
) {
|
| 127 |
+
return false;
|
| 128 |
+
}
|
| 129 |
+
return true;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
const scopes = this.__get(node);
|
| 133 |
+
|
| 134 |
+
if (!scopes || scopes.length === 0) {
|
| 135 |
+
return null;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
// Heuristic selection from all scopes.
|
| 139 |
+
// If you would like to get all scopes, please use ScopeManager#acquireAll.
|
| 140 |
+
if (scopes.length === 1) {
|
| 141 |
+
return scopes[0];
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
if (inner) {
|
| 145 |
+
for (let i = scopes.length - 1; i >= 0; --i) {
|
| 146 |
+
const scope = scopes[i];
|
| 147 |
+
|
| 148 |
+
if (predicate(scope)) {
|
| 149 |
+
return scope;
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
} else {
|
| 153 |
+
for (let i = 0, iz = scopes.length; i < iz; ++i) {
|
| 154 |
+
const scope = scopes[i];
|
| 155 |
+
|
| 156 |
+
if (predicate(scope)) {
|
| 157 |
+
return scope;
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
return null;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/**
|
| 166 |
+
* acquire all scopes from node.
|
| 167 |
+
* @function ScopeManager#acquireAll
|
| 168 |
+
* @param {ESTree.Node} node node for the acquired scope.
|
| 169 |
+
* @returns {Scope[]?} Scope array
|
| 170 |
+
*/
|
| 171 |
+
acquireAll(node) {
|
| 172 |
+
return this.__get(node);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/**
|
| 176 |
+
* release the node.
|
| 177 |
+
* @function ScopeManager#release
|
| 178 |
+
* @param {ESTree.Node} node releasing node.
|
| 179 |
+
* @param {?boolean} [inner=false] look up the most inner scope, default value is false.
|
| 180 |
+
* @returns {Scope?} upper scope for the node.
|
| 181 |
+
*/
|
| 182 |
+
release(node, inner) {
|
| 183 |
+
const scopes = this.__get(node);
|
| 184 |
+
|
| 185 |
+
if (scopes && scopes.length) {
|
| 186 |
+
const scope = scopes[0].upper;
|
| 187 |
+
|
| 188 |
+
if (!scope) {
|
| 189 |
+
return null;
|
| 190 |
+
}
|
| 191 |
+
return this.acquire(scope.block, inner);
|
| 192 |
+
}
|
| 193 |
+
return null;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
* Add global variables and resolve their references.
|
| 198 |
+
* @function ScopeManager#addGlobals
|
| 199 |
+
* @param {string[]} names Names of global variables to add.
|
| 200 |
+
* @returns {void}
|
| 201 |
+
*/
|
| 202 |
+
addGlobals(names) {
|
| 203 |
+
// @ts-ignore -- globalScope must be set before this method is called.
|
| 204 |
+
this.globalScope.__addVariables(names);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
attach() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 208 |
+
|
| 209 |
+
detach() {} // eslint-disable-line class-methods-use-this -- Desired as instance method
|
| 210 |
+
|
| 211 |
+
__nestScope(scope) {
|
| 212 |
+
if (scope instanceof GlobalScope) {
|
| 213 |
+
assert(this.__currentScope === null);
|
| 214 |
+
this.globalScope = scope;
|
| 215 |
+
}
|
| 216 |
+
this.__currentScope = scope;
|
| 217 |
+
return scope;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
__nestGlobalScope(node) {
|
| 221 |
+
return this.__nestScope(new GlobalScope(this, node));
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
__nestBlockScope(node) {
|
| 225 |
+
return this.__nestScope(
|
| 226 |
+
new BlockScope(this, this.__currentScope, node),
|
| 227 |
+
);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
__nestFunctionScope(node, isMethodDefinition) {
|
| 231 |
+
return this.__nestScope(
|
| 232 |
+
new FunctionScope(
|
| 233 |
+
this,
|
| 234 |
+
this.__currentScope,
|
| 235 |
+
node,
|
| 236 |
+
isMethodDefinition,
|
| 237 |
+
),
|
| 238 |
+
);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
__nestForScope(node) {
|
| 242 |
+
return this.__nestScope(new ForScope(this, this.__currentScope, node));
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
__nestCatchScope(node) {
|
| 246 |
+
return this.__nestScope(
|
| 247 |
+
new CatchScope(this, this.__currentScope, node),
|
| 248 |
+
);
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
__nestWithScope(node) {
|
| 252 |
+
return this.__nestScope(new WithScope(this, this.__currentScope, node));
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
__nestClassScope(node) {
|
| 256 |
+
return this.__nestScope(
|
| 257 |
+
new ClassScope(this, this.__currentScope, node),
|
| 258 |
+
);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
__nestClassFieldInitializerScope(node) {
|
| 262 |
+
return this.__nestScope(
|
| 263 |
+
new ClassFieldInitializerScope(this, this.__currentScope, node),
|
| 264 |
+
);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
__nestClassStaticBlockScope(node) {
|
| 268 |
+
return this.__nestScope(
|
| 269 |
+
new ClassStaticBlockScope(this, this.__currentScope, node),
|
| 270 |
+
);
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
__nestSwitchScope(node) {
|
| 274 |
+
return this.__nestScope(
|
| 275 |
+
new SwitchScope(this, this.__currentScope, node),
|
| 276 |
+
);
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
__nestModuleScope(node) {
|
| 280 |
+
return this.__nestScope(
|
| 281 |
+
new ModuleScope(this, this.__currentScope, node),
|
| 282 |
+
);
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
__nestFunctionExpressionNameScope(node) {
|
| 286 |
+
return this.__nestScope(
|
| 287 |
+
new FunctionExpressionNameScope(this, this.__currentScope, node),
|
| 288 |
+
);
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
__isES6() {
|
| 292 |
+
return this.__options.ecmaVersion >= 6;
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
export default ScopeManager;
|
| 297 |
+
|
| 298 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/scope.js
ADDED
|
@@ -0,0 +1,852 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
import estraverse from "estraverse";
|
| 26 |
+
|
| 27 |
+
import Reference from "./reference.js";
|
| 28 |
+
import Variable from "./variable.js";
|
| 29 |
+
import { Definition } from "./definition.js";
|
| 30 |
+
import { assert } from "./assert.js";
|
| 31 |
+
|
| 32 |
+
/** @import * as types from "eslint-scope" */
|
| 33 |
+
/** @import ESTree from "estree" */
|
| 34 |
+
/** @import ScopeManager from "./scope-manager.js" */
|
| 35 |
+
/** @typedef {ESTree.Function | ESTree.Program | ESTree.StaticBlock} Block */
|
| 36 |
+
/** @typedef {{pattern: unknown, node: unknown}} MaybeImplicitGlobal */
|
| 37 |
+
|
| 38 |
+
const { Syntax } = estraverse;
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Test if scope is struct
|
| 42 |
+
* @param {Scope} scope scope
|
| 43 |
+
* @param {Block} block block
|
| 44 |
+
* @param {boolean} isMethodDefinition is method definition
|
| 45 |
+
* @returns {boolean} is strict scope
|
| 46 |
+
*/
|
| 47 |
+
function isStrictScope(scope, block, isMethodDefinition) {
|
| 48 |
+
let body;
|
| 49 |
+
|
| 50 |
+
// When upper scope is exists and strict, inner scope is also strict.
|
| 51 |
+
if (scope.upper && scope.upper.isStrict) {
|
| 52 |
+
return true;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
if (isMethodDefinition) {
|
| 56 |
+
return true;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (scope.type === "class" || scope.type === "module") {
|
| 60 |
+
return true;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
if (scope.type === "block" || scope.type === "switch") {
|
| 64 |
+
return false;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
if (scope.type === "function") {
|
| 68 |
+
if (
|
| 69 |
+
block.type === Syntax.ArrowFunctionExpression &&
|
| 70 |
+
// @ts-ignore -- when block is ArrowFunctionExpression
|
| 71 |
+
block.body.type !== Syntax.BlockStatement
|
| 72 |
+
) {
|
| 73 |
+
return false;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
if (block.type === Syntax.Program) {
|
| 77 |
+
body = block;
|
| 78 |
+
} else {
|
| 79 |
+
body = block.body;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
if (!body) {
|
| 83 |
+
return false;
|
| 84 |
+
}
|
| 85 |
+
} else if (scope.type === "global") {
|
| 86 |
+
body = block;
|
| 87 |
+
} else {
|
| 88 |
+
return false;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Search for a 'use strict' directive.
|
| 92 |
+
// @ts-ignore -- body is a function body
|
| 93 |
+
for (let i = 0, iz = body.body.length; i < iz; ++i) {
|
| 94 |
+
// @ts-ignore -- body is a function body
|
| 95 |
+
const stmt = body.body[i];
|
| 96 |
+
|
| 97 |
+
/*
|
| 98 |
+
* Check if the current statement is a directive.
|
| 99 |
+
* If it isn't, then we're past the directive prologue
|
| 100 |
+
* so stop the search because directives cannot
|
| 101 |
+
* appear after this point.
|
| 102 |
+
*
|
| 103 |
+
* Some parsers set `directive:null` on non-directive
|
| 104 |
+
* statements, so the `typeof` check is safer than
|
| 105 |
+
* checking for property existence.
|
| 106 |
+
*/
|
| 107 |
+
if (typeof stmt.directive !== "string") {
|
| 108 |
+
break;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
if (stmt.directive === "use strict") {
|
| 112 |
+
return true;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return false;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/**
|
| 120 |
+
* Register scope
|
| 121 |
+
* @param {ScopeManager} scopeManager scope manager
|
| 122 |
+
* @param {Scope} scope scope
|
| 123 |
+
* @returns {void}
|
| 124 |
+
*/
|
| 125 |
+
function registerScope(scopeManager, scope) {
|
| 126 |
+
scopeManager.scopes.push(scope);
|
| 127 |
+
|
| 128 |
+
const scopes = scopeManager.__nodeToScope.get(scope.block);
|
| 129 |
+
|
| 130 |
+
if (scopes) {
|
| 131 |
+
scopes.push(scope);
|
| 132 |
+
} else {
|
| 133 |
+
scopeManager.__nodeToScope.set(scope.block, [scope]);
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/**
|
| 138 |
+
* @constructor Scope
|
| 139 |
+
* @implements {types.Scope}
|
| 140 |
+
*/
|
| 141 |
+
class Scope {
|
| 142 |
+
constructor(scopeManager, type, upperScope, block, isMethodDefinition) {
|
| 143 |
+
/**
|
| 144 |
+
* One of "global", "module", "function", "function-expression-name", "block", "switch", "catch", "with", "for",
|
| 145 |
+
* "class", "class-field-initializer", "class-static-block".
|
| 146 |
+
* @member {string} Scope#type
|
| 147 |
+
*/
|
| 148 |
+
this.type = type;
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* The scoped {@link Variable}s of this scope, as <code>{ Variable.name
|
| 152 |
+
* : Variable }</code>.
|
| 153 |
+
* @member {Map} Scope#set
|
| 154 |
+
*/
|
| 155 |
+
this.set = new Map();
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* The tainted variables of this scope, as <code>{ Variable.name :
|
| 159 |
+
* boolean }</code>.
|
| 160 |
+
* @member {Map} Scope#taints
|
| 161 |
+
*/
|
| 162 |
+
this.taints = new Map();
|
| 163 |
+
|
| 164 |
+
/**
|
| 165 |
+
* Generally, through the lexical scoping of JS you can always know
|
| 166 |
+
* which variable an identifier in the source code refers to. There are
|
| 167 |
+
* a few exceptions to this rule. With 'global' and 'with' scopes you
|
| 168 |
+
* can only decide at runtime which variable a reference refers to.
|
| 169 |
+
* Moreover, if 'eval()' is used in a scope, it might introduce new
|
| 170 |
+
* bindings in this or its parent scopes.
|
| 171 |
+
* All those scopes are considered 'dynamic'.
|
| 172 |
+
* @member {boolean} Scope#dynamic
|
| 173 |
+
*/
|
| 174 |
+
this.dynamic = this.type === "global" || this.type === "with";
|
| 175 |
+
|
| 176 |
+
/**
|
| 177 |
+
* A reference to the scope-defining syntax node.
|
| 178 |
+
* @member {espree.Node} Scope#block
|
| 179 |
+
*/
|
| 180 |
+
this.block = block;
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* The {@link Reference|references} that are not resolved with this scope.
|
| 184 |
+
* @member {Reference[]} Scope#through
|
| 185 |
+
*/
|
| 186 |
+
this.through = [];
|
| 187 |
+
|
| 188 |
+
/**
|
| 189 |
+
* The scoped {@link Variable}s of this scope. In the case of a
|
| 190 |
+
* 'function' scope this includes the automatic argument <em>arguments</em> as
|
| 191 |
+
* its first element, as well as all further formal arguments.
|
| 192 |
+
* @member {Variable[]} Scope#variables
|
| 193 |
+
*/
|
| 194 |
+
this.variables = [];
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
* Any variable {@link Reference|reference} found in this scope. This
|
| 198 |
+
* includes occurrences of local variables as well as variables from
|
| 199 |
+
* parent scopes (including the global scope). For local variables
|
| 200 |
+
* this also includes defining occurrences (like in a 'var' statement).
|
| 201 |
+
* In a 'function' scope this does not include the occurrences of the
|
| 202 |
+
* formal parameter in the parameter list.
|
| 203 |
+
* @member {Reference[]} Scope#references
|
| 204 |
+
*/
|
| 205 |
+
this.references = [];
|
| 206 |
+
|
| 207 |
+
/**
|
| 208 |
+
* For 'global' and 'function' scopes, this is a self-reference. For
|
| 209 |
+
* other scope types this is the <em>variableScope</em> value of the
|
| 210 |
+
* parent scope.
|
| 211 |
+
* @member {Scope} Scope#variableScope
|
| 212 |
+
*/
|
| 213 |
+
this.variableScope =
|
| 214 |
+
this.type === "global" ||
|
| 215 |
+
this.type === "module" ||
|
| 216 |
+
this.type === "function" ||
|
| 217 |
+
this.type === "class-field-initializer" ||
|
| 218 |
+
this.type === "class-static-block"
|
| 219 |
+
? this
|
| 220 |
+
: upperScope.variableScope;
|
| 221 |
+
|
| 222 |
+
/**
|
| 223 |
+
* Whether this scope is created by a FunctionExpression.
|
| 224 |
+
* @member {boolean} Scope#functionExpressionScope
|
| 225 |
+
*/
|
| 226 |
+
this.functionExpressionScope = /** @type {any} */ (false);
|
| 227 |
+
|
| 228 |
+
/**
|
| 229 |
+
* Whether this is a scope that contains an 'eval()' invocation.
|
| 230 |
+
* @member {boolean} Scope#directCallToEvalScope
|
| 231 |
+
*/
|
| 232 |
+
this.directCallToEvalScope = false;
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* @member {boolean} Scope#thisFound
|
| 236 |
+
*/
|
| 237 |
+
this.thisFound = false;
|
| 238 |
+
|
| 239 |
+
/** @type {?Reference[]} */
|
| 240 |
+
this.__left = [];
|
| 241 |
+
|
| 242 |
+
/**
|
| 243 |
+
* Reference to the parent {@link Scope|scope}.
|
| 244 |
+
* @member {Scope} Scope#upper
|
| 245 |
+
*/
|
| 246 |
+
this.upper = upperScope;
|
| 247 |
+
|
| 248 |
+
/**
|
| 249 |
+
* Whether 'use strict' is in effect in this scope.
|
| 250 |
+
* @member {boolean} Scope#isStrict
|
| 251 |
+
*/
|
| 252 |
+
this.isStrict = scopeManager.isStrictModeSupported()
|
| 253 |
+
? isStrictScope(this, block, isMethodDefinition)
|
| 254 |
+
: false;
|
| 255 |
+
|
| 256 |
+
/**
|
| 257 |
+
* List of nested {@link Scope}s.
|
| 258 |
+
* @member {Scope[]} Scope#childScopes
|
| 259 |
+
*/
|
| 260 |
+
this.childScopes = [];
|
| 261 |
+
if (this.upper) {
|
| 262 |
+
this.upper.childScopes.push(this);
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
this.__declaredVariables = scopeManager.__declaredVariables;
|
| 266 |
+
|
| 267 |
+
registerScope(scopeManager, this);
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
__shouldStaticallyClose(scopeManager) {
|
| 271 |
+
return (
|
| 272 |
+
!this.dynamic ||
|
| 273 |
+
scopeManager.__isOptimistic() ||
|
| 274 |
+
this.type === "global"
|
| 275 |
+
);
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
__staticCloseRef(ref) {
|
| 279 |
+
if (!this.__resolve(ref)) {
|
| 280 |
+
this.__delegateToUpperScope(ref);
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
__dynamicCloseRef(ref) {
|
| 285 |
+
// notify all names are through to global
|
| 286 |
+
let current = this;
|
| 287 |
+
|
| 288 |
+
do {
|
| 289 |
+
current.through.push(ref);
|
| 290 |
+
current = current.upper;
|
| 291 |
+
} while (current);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
__close(scopeManager) {
|
| 295 |
+
let closeRef;
|
| 296 |
+
|
| 297 |
+
if (this.__shouldStaticallyClose(scopeManager)) {
|
| 298 |
+
closeRef = this.__staticCloseRef;
|
| 299 |
+
} else {
|
| 300 |
+
closeRef = this.__dynamicCloseRef;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// Try Resolving all references in this scope.
|
| 304 |
+
// @ts-ignore -- __left should be an array here
|
| 305 |
+
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
|
| 306 |
+
// @ts-ignore -- __left should be an array here
|
| 307 |
+
const ref = this.__left[i];
|
| 308 |
+
|
| 309 |
+
closeRef.call(this, ref);
|
| 310 |
+
}
|
| 311 |
+
this.__left = null;
|
| 312 |
+
|
| 313 |
+
return this.upper;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
// To override by function scopes.
|
| 317 |
+
// References in default parameters isn't resolved to variables which are in their function body.
|
| 318 |
+
// eslint-disable-next-line class-methods-use-this, no-unused-vars -- Desired as instance method with signature
|
| 319 |
+
__isValidResolution(ref, variable) {
|
| 320 |
+
return true;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
__resolve(ref) {
|
| 324 |
+
const name = ref.identifier.name;
|
| 325 |
+
|
| 326 |
+
if (!this.set.has(name)) {
|
| 327 |
+
return false;
|
| 328 |
+
}
|
| 329 |
+
const variable = this.set.get(name);
|
| 330 |
+
|
| 331 |
+
if (!this.__isValidResolution(ref, variable)) {
|
| 332 |
+
return false;
|
| 333 |
+
}
|
| 334 |
+
variable.references.push(ref);
|
| 335 |
+
variable.stack =
|
| 336 |
+
variable.stack && ref.from.variableScope === this.variableScope;
|
| 337 |
+
if (ref.tainted) {
|
| 338 |
+
variable.tainted = true;
|
| 339 |
+
this.taints.set(variable.name, true);
|
| 340 |
+
}
|
| 341 |
+
ref.resolved = variable;
|
| 342 |
+
|
| 343 |
+
return true;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
__delegateToUpperScope(ref) {
|
| 347 |
+
if (this.upper) {
|
| 348 |
+
this.upper.__left.push(ref);
|
| 349 |
+
}
|
| 350 |
+
this.through.push(ref);
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
__addDeclaredVariablesOfNode(variable, node) {
|
| 354 |
+
if (node === null || node === void 0) {
|
| 355 |
+
return;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
let variables = this.__declaredVariables.get(node);
|
| 359 |
+
|
| 360 |
+
if (variables === null || variables === void 0) {
|
| 361 |
+
variables = [];
|
| 362 |
+
this.__declaredVariables.set(node, variables);
|
| 363 |
+
}
|
| 364 |
+
if (!variables.includes(variable)) {
|
| 365 |
+
variables.push(variable);
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
__defineGeneric(name, set, variables, node, def) {
|
| 370 |
+
let variable;
|
| 371 |
+
|
| 372 |
+
variable = set.get(name);
|
| 373 |
+
if (!variable) {
|
| 374 |
+
variable = new Variable(name, this);
|
| 375 |
+
set.set(name, variable);
|
| 376 |
+
variables.push(variable);
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
if (def) {
|
| 380 |
+
variable.defs.push(def);
|
| 381 |
+
this.__addDeclaredVariablesOfNode(variable, def.node);
|
| 382 |
+
this.__addDeclaredVariablesOfNode(variable, def.parent);
|
| 383 |
+
}
|
| 384 |
+
if (node) {
|
| 385 |
+
variable.identifiers.push(node);
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
__define(node, def) {
|
| 390 |
+
if (node && node.type === Syntax.Identifier) {
|
| 391 |
+
this.__defineGeneric(
|
| 392 |
+
node.name,
|
| 393 |
+
this.set,
|
| 394 |
+
this.variables,
|
| 395 |
+
node,
|
| 396 |
+
def,
|
| 397 |
+
);
|
| 398 |
+
}
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
__referencing(node, assign, writeExpr, maybeImplicitGlobal, partial, init) {
|
| 402 |
+
// because Array element may be null
|
| 403 |
+
if (
|
| 404 |
+
!node ||
|
| 405 |
+
(node.type !== Syntax.Identifier && node.type !== "JSXIdentifier")
|
| 406 |
+
) {
|
| 407 |
+
return;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
// Specially handle like `this`.
|
| 411 |
+
if (node.name === "super") {
|
| 412 |
+
return;
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
const ref = new Reference(
|
| 416 |
+
node,
|
| 417 |
+
this,
|
| 418 |
+
assign || Reference.READ,
|
| 419 |
+
writeExpr,
|
| 420 |
+
maybeImplicitGlobal,
|
| 421 |
+
!!partial,
|
| 422 |
+
!!init,
|
| 423 |
+
);
|
| 424 |
+
|
| 425 |
+
this.references.push(ref);
|
| 426 |
+
|
| 427 |
+
// @ts-ignore -- __left should be an array here
|
| 428 |
+
this.__left.push(ref);
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
__detectEval() {
|
| 432 |
+
let current = this;
|
| 433 |
+
|
| 434 |
+
this.directCallToEvalScope = true;
|
| 435 |
+
do {
|
| 436 |
+
current.dynamic = true;
|
| 437 |
+
current = current.upper;
|
| 438 |
+
} while (current);
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
__detectThis() {
|
| 442 |
+
this.thisFound = true;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
__isClosed() {
|
| 446 |
+
return this.__left === null;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
/**
|
| 450 |
+
* returns resolved {Reference}
|
| 451 |
+
* @function Scope#resolve
|
| 452 |
+
* @param {ESTree.Identifier} ident identifier to be resolved.
|
| 453 |
+
* @returns {?Reference} reference
|
| 454 |
+
*/
|
| 455 |
+
resolve(ident) {
|
| 456 |
+
let ref, i, iz;
|
| 457 |
+
|
| 458 |
+
assert(this.__isClosed(), "Scope should be closed.");
|
| 459 |
+
assert(
|
| 460 |
+
ident.type === Syntax.Identifier,
|
| 461 |
+
"Target should be identifier.",
|
| 462 |
+
);
|
| 463 |
+
for (i = 0, iz = this.references.length; i < iz; ++i) {
|
| 464 |
+
ref = this.references[i];
|
| 465 |
+
if (ref.identifier === ident) {
|
| 466 |
+
return ref;
|
| 467 |
+
}
|
| 468 |
+
}
|
| 469 |
+
return null;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
/**
|
| 473 |
+
* returns this scope is static
|
| 474 |
+
* @function Scope#isStatic
|
| 475 |
+
* @returns {boolean} static
|
| 476 |
+
*/
|
| 477 |
+
isStatic() {
|
| 478 |
+
return !this.dynamic;
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
/**
|
| 482 |
+
* returns this scope has materialized arguments
|
| 483 |
+
* @function Scope#isArgumentsMaterialized
|
| 484 |
+
* @returns {any} arguments materialized
|
| 485 |
+
*/ // eslint-disable-next-line class-methods-use-this -- Desired as instance method
|
| 486 |
+
isArgumentsMaterialized() {
|
| 487 |
+
return true;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
/**
|
| 491 |
+
* returns this scope has materialized `this` reference
|
| 492 |
+
* @function Scope#isThisMaterialized
|
| 493 |
+
* @returns {any} this materialized
|
| 494 |
+
*/ // eslint-disable-next-line class-methods-use-this -- Desired as instance method
|
| 495 |
+
isThisMaterialized() {
|
| 496 |
+
return true;
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
isUsedName(name) {
|
| 500 |
+
if (this.set.has(name)) {
|
| 501 |
+
return true;
|
| 502 |
+
}
|
| 503 |
+
for (let i = 0, iz = this.through.length; i < iz; ++i) {
|
| 504 |
+
if (this.through[i].identifier.name === name) {
|
| 505 |
+
return true;
|
| 506 |
+
}
|
| 507 |
+
}
|
| 508 |
+
return false;
|
| 509 |
+
}
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
/**
|
| 513 |
+
* Global scope.
|
| 514 |
+
* @implements {types.GlobalScope}
|
| 515 |
+
*/
|
| 516 |
+
class GlobalScope extends Scope {
|
| 517 |
+
constructor(scopeManager, block) {
|
| 518 |
+
super(scopeManager, "global", null, block, false);
|
| 519 |
+
this.implicit = {
|
| 520 |
+
set: new Map(),
|
| 521 |
+
|
| 522 |
+
/** @type {Variable[]} */
|
| 523 |
+
variables: [],
|
| 524 |
+
|
| 525 |
+
/**
|
| 526 |
+
* List of {@link Reference}s that are left to be resolved (i.e. which
|
| 527 |
+
* need to be linked to the variable they refer to).
|
| 528 |
+
* @member {Reference[]} Scope#implicit#left
|
| 529 |
+
* @type {Reference[]}
|
| 530 |
+
*/
|
| 531 |
+
left: [],
|
| 532 |
+
};
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
__close(scopeManager) {
|
| 536 |
+
const implicit = [];
|
| 537 |
+
|
| 538 |
+
// @ts-ignore -- __left should be an array here
|
| 539 |
+
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
|
| 540 |
+
// @ts-ignore -- __left should be an array here
|
| 541 |
+
const ref = this.__left[i];
|
| 542 |
+
|
| 543 |
+
if (
|
| 544 |
+
ref.__maybeImplicitGlobal &&
|
| 545 |
+
!this.set.has(ref.identifier.name)
|
| 546 |
+
) {
|
| 547 |
+
implicit.push(ref.__maybeImplicitGlobal);
|
| 548 |
+
}
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
// create an implicit global variable from assignment expression
|
| 552 |
+
for (let i = 0, iz = implicit.length; i < iz; ++i) {
|
| 553 |
+
const info = implicit[i];
|
| 554 |
+
|
| 555 |
+
this.__defineImplicit(
|
| 556 |
+
info.pattern,
|
| 557 |
+
new Definition(
|
| 558 |
+
Variable.ImplicitGlobalVariable,
|
| 559 |
+
info.pattern,
|
| 560 |
+
info.node,
|
| 561 |
+
null,
|
| 562 |
+
null,
|
| 563 |
+
null,
|
| 564 |
+
),
|
| 565 |
+
);
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
super.__close(scopeManager);
|
| 569 |
+
|
| 570 |
+
this.implicit.left = [...this.through];
|
| 571 |
+
|
| 572 |
+
return null;
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
__defineImplicit(node, def) {
|
| 576 |
+
if (node && node.type === Syntax.Identifier) {
|
| 577 |
+
this.__defineGeneric(
|
| 578 |
+
node.name,
|
| 579 |
+
this.implicit.set,
|
| 580 |
+
this.implicit.variables,
|
| 581 |
+
node,
|
| 582 |
+
def,
|
| 583 |
+
);
|
| 584 |
+
}
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
__addVariables(names) {
|
| 588 |
+
for (const name of names) {
|
| 589 |
+
this.__defineGeneric(name, this.set, this.variables, null, null);
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
const namesSet = new Set(names);
|
| 593 |
+
|
| 594 |
+
this.through = this.through.filter(reference => {
|
| 595 |
+
const name = reference.identifier.name;
|
| 596 |
+
|
| 597 |
+
if (namesSet.has(name)) {
|
| 598 |
+
const variable = this.set.get(name);
|
| 599 |
+
|
| 600 |
+
reference.resolved = variable;
|
| 601 |
+
variable.references.push(reference);
|
| 602 |
+
|
| 603 |
+
return false;
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
return true;
|
| 607 |
+
});
|
| 608 |
+
|
| 609 |
+
this.implicit.variables = this.implicit.variables.filter(variable => {
|
| 610 |
+
const name = variable.name;
|
| 611 |
+
|
| 612 |
+
if (namesSet.has(name)) {
|
| 613 |
+
this.implicit.set.delete(name);
|
| 614 |
+
|
| 615 |
+
return false;
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
return true;
|
| 619 |
+
});
|
| 620 |
+
|
| 621 |
+
this.implicit.left = this.implicit.left.filter(
|
| 622 |
+
reference => !namesSet.has(reference.identifier.name),
|
| 623 |
+
);
|
| 624 |
+
}
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
/**
|
| 628 |
+
* Module scope.
|
| 629 |
+
* @implements {types.ModuleScope}
|
| 630 |
+
*/
|
| 631 |
+
class ModuleScope extends Scope {
|
| 632 |
+
constructor(scopeManager, upperScope, block) {
|
| 633 |
+
super(scopeManager, "module", upperScope, block, false);
|
| 634 |
+
}
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
/**
|
| 638 |
+
* Function expression name scope.
|
| 639 |
+
* @implements {types.FunctionExpressionNameScope}
|
| 640 |
+
*/
|
| 641 |
+
class FunctionExpressionNameScope extends Scope {
|
| 642 |
+
constructor(scopeManager, upperScope, block) {
|
| 643 |
+
super(
|
| 644 |
+
scopeManager,
|
| 645 |
+
"function-expression-name",
|
| 646 |
+
upperScope,
|
| 647 |
+
block,
|
| 648 |
+
false,
|
| 649 |
+
);
|
| 650 |
+
this.__define(
|
| 651 |
+
block.id,
|
| 652 |
+
new Definition(
|
| 653 |
+
Variable.FunctionName,
|
| 654 |
+
block.id,
|
| 655 |
+
block,
|
| 656 |
+
null,
|
| 657 |
+
null,
|
| 658 |
+
null,
|
| 659 |
+
),
|
| 660 |
+
);
|
| 661 |
+
this.functionExpressionScope = /** @type {const} */ (true);
|
| 662 |
+
}
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
/**
|
| 666 |
+
* Catch scope.
|
| 667 |
+
* @implements {types.CatchScope}
|
| 668 |
+
*/
|
| 669 |
+
class CatchScope extends Scope {
|
| 670 |
+
constructor(scopeManager, upperScope, block) {
|
| 671 |
+
super(scopeManager, "catch", upperScope, block, false);
|
| 672 |
+
}
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
/**
|
| 676 |
+
* With statement scope.
|
| 677 |
+
* @implements {types.WithScope}
|
| 678 |
+
*/
|
| 679 |
+
class WithScope extends Scope {
|
| 680 |
+
constructor(scopeManager, upperScope, block) {
|
| 681 |
+
super(scopeManager, "with", upperScope, block, false);
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
__close(scopeManager) {
|
| 685 |
+
if (this.__shouldStaticallyClose(scopeManager)) {
|
| 686 |
+
return super.__close(scopeManager);
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
// @ts-ignore -- __left should be an array here
|
| 690 |
+
for (let i = 0, iz = this.__left.length; i < iz; ++i) {
|
| 691 |
+
// @ts-ignore -- __left should be an array here
|
| 692 |
+
const ref = this.__left[i];
|
| 693 |
+
|
| 694 |
+
ref.tainted = true;
|
| 695 |
+
this.__delegateToUpperScope(ref);
|
| 696 |
+
}
|
| 697 |
+
this.__left = null;
|
| 698 |
+
|
| 699 |
+
return this.upper;
|
| 700 |
+
}
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
/**
|
| 704 |
+
* Block scope.
|
| 705 |
+
* @implements {types.BlockScope}
|
| 706 |
+
*/
|
| 707 |
+
class BlockScope extends Scope {
|
| 708 |
+
constructor(scopeManager, upperScope, block) {
|
| 709 |
+
super(scopeManager, "block", upperScope, block, false);
|
| 710 |
+
}
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
/**
|
| 714 |
+
* Switch scope.
|
| 715 |
+
* @implements {types.SwitchScope}
|
| 716 |
+
*/
|
| 717 |
+
class SwitchScope extends Scope {
|
| 718 |
+
constructor(scopeManager, upperScope, block) {
|
| 719 |
+
super(scopeManager, "switch", upperScope, block, false);
|
| 720 |
+
}
|
| 721 |
+
}
|
| 722 |
+
|
| 723 |
+
/**
|
| 724 |
+
* Function scope.
|
| 725 |
+
* @implements {types.FunctionScope}
|
| 726 |
+
*/
|
| 727 |
+
class FunctionScope extends Scope {
|
| 728 |
+
constructor(scopeManager, upperScope, block, isMethodDefinition) {
|
| 729 |
+
super(scopeManager, "function", upperScope, block, isMethodDefinition);
|
| 730 |
+
|
| 731 |
+
// section 9.2.13, FunctionDeclarationInstantiation.
|
| 732 |
+
// NOTE Arrow functions never have an arguments objects.
|
| 733 |
+
if (this.block.type !== Syntax.ArrowFunctionExpression) {
|
| 734 |
+
this.__defineArguments();
|
| 735 |
+
}
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
isArgumentsMaterialized() {
|
| 739 |
+
// TODO(Constellation)
|
| 740 |
+
// We can more aggressive on this condition like this.
|
| 741 |
+
//
|
| 742 |
+
// function t() {
|
| 743 |
+
// // arguments of t is always hidden.
|
| 744 |
+
// function arguments() {
|
| 745 |
+
// }
|
| 746 |
+
// }
|
| 747 |
+
if (this.block.type === Syntax.ArrowFunctionExpression) {
|
| 748 |
+
return false;
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
if (!this.isStatic()) {
|
| 752 |
+
return true;
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
const variable = this.set.get("arguments");
|
| 756 |
+
|
| 757 |
+
assert(variable, "Always have arguments variable.");
|
| 758 |
+
return variable.tainted || variable.references.length !== 0;
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
isThisMaterialized() {
|
| 762 |
+
if (!this.isStatic()) {
|
| 763 |
+
return true;
|
| 764 |
+
}
|
| 765 |
+
return this.thisFound;
|
| 766 |
+
}
|
| 767 |
+
|
| 768 |
+
__defineArguments() {
|
| 769 |
+
this.__defineGeneric("arguments", this.set, this.variables, null, null);
|
| 770 |
+
this.taints.set("arguments", true);
|
| 771 |
+
}
|
| 772 |
+
|
| 773 |
+
// References in default parameters isn't resolved to variables which are in their function body.
|
| 774 |
+
// const x = 1
|
| 775 |
+
// function f(a = x) { // This `x` is resolved to the `x` in the outer scope.
|
| 776 |
+
// const x = 2
|
| 777 |
+
// console.log(a)
|
| 778 |
+
// }
|
| 779 |
+
__isValidResolution(ref, variable) {
|
| 780 |
+
// If `options.nodejsScope` is true, `this.block` becomes a Program node.
|
| 781 |
+
if (this.block.type === "Program") {
|
| 782 |
+
return true;
|
| 783 |
+
}
|
| 784 |
+
|
| 785 |
+
const bodyStart = this.block.body.range[0];
|
| 786 |
+
|
| 787 |
+
// It's invalid resolution in the following case:
|
| 788 |
+
return !(
|
| 789 |
+
variable.scope === this &&
|
| 790 |
+
ref.identifier.range[0] < bodyStart && // the reference is in the parameter part.
|
| 791 |
+
variable.defs.every(d => d.name.range[0] >= bodyStart) // the variable is in the body.
|
| 792 |
+
);
|
| 793 |
+
}
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
/**
|
| 797 |
+
* Scope of for, for-in, and for-of statements.
|
| 798 |
+
* @implements {types.ForScope}
|
| 799 |
+
*/
|
| 800 |
+
class ForScope extends Scope {
|
| 801 |
+
constructor(scopeManager, upperScope, block) {
|
| 802 |
+
super(scopeManager, "for", upperScope, block, false);
|
| 803 |
+
}
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
/**
|
| 807 |
+
* Class scope.
|
| 808 |
+
* @implements {types.ClassScope}
|
| 809 |
+
*/
|
| 810 |
+
class ClassScope extends Scope {
|
| 811 |
+
constructor(scopeManager, upperScope, block) {
|
| 812 |
+
super(scopeManager, "class", upperScope, block, false);
|
| 813 |
+
}
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
/**
|
| 817 |
+
* Class field initializer scope.
|
| 818 |
+
* @implements {types.ClassFieldInitializerScope}
|
| 819 |
+
*/
|
| 820 |
+
class ClassFieldInitializerScope extends Scope {
|
| 821 |
+
constructor(scopeManager, upperScope, block) {
|
| 822 |
+
super(scopeManager, "class-field-initializer", upperScope, block, true);
|
| 823 |
+
}
|
| 824 |
+
}
|
| 825 |
+
|
| 826 |
+
/**
|
| 827 |
+
* Class static block scope.
|
| 828 |
+
* @implements {types.ClassStaticBlockScope}
|
| 829 |
+
*/
|
| 830 |
+
class ClassStaticBlockScope extends Scope {
|
| 831 |
+
constructor(scopeManager, upperScope, block) {
|
| 832 |
+
super(scopeManager, "class-static-block", upperScope, block, true);
|
| 833 |
+
}
|
| 834 |
+
}
|
| 835 |
+
|
| 836 |
+
export {
|
| 837 |
+
Scope,
|
| 838 |
+
GlobalScope,
|
| 839 |
+
ModuleScope,
|
| 840 |
+
FunctionExpressionNameScope,
|
| 841 |
+
CatchScope,
|
| 842 |
+
WithScope,
|
| 843 |
+
BlockScope,
|
| 844 |
+
SwitchScope,
|
| 845 |
+
FunctionScope,
|
| 846 |
+
ForScope,
|
| 847 |
+
ClassScope,
|
| 848 |
+
ClassFieldInitializerScope,
|
| 849 |
+
ClassStaticBlockScope,
|
| 850 |
+
};
|
| 851 |
+
|
| 852 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/lib/variable.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 17 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 22 |
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
/** @import * as types from "eslint-scope" */
|
| 26 |
+
/** @import Reference from "./reference.js" */
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* A Variable represents a locally scoped identifier. These include arguments to
|
| 30 |
+
* functions.
|
| 31 |
+
* @constructor Variable
|
| 32 |
+
* @implements {types.Variable}
|
| 33 |
+
*/
|
| 34 |
+
class Variable {
|
| 35 |
+
constructor(name, scope) {
|
| 36 |
+
/**
|
| 37 |
+
* The variable name, as given in the source code.
|
| 38 |
+
* @member {string} Variable#name
|
| 39 |
+
*/
|
| 40 |
+
this.name = name;
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* List of defining occurrences of this variable (like in 'var ...'
|
| 44 |
+
* statements or as parameter), as AST nodes.
|
| 45 |
+
* @member {espree.Identifier[]} Variable#identifiers
|
| 46 |
+
*/
|
| 47 |
+
this.identifiers = [];
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* List of {@link Reference|references} of this variable (excluding parameter entries)
|
| 51 |
+
* in its defining scope and all nested scopes. For defining
|
| 52 |
+
* occurrences only see {@link Variable#defs}.
|
| 53 |
+
* @member {Reference[]} Variable#references
|
| 54 |
+
*/
|
| 55 |
+
this.references = [];
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* List of defining occurrences of this variable (like in 'var ...'
|
| 59 |
+
* statements or as parameter), as custom objects.
|
| 60 |
+
* @member {Definition[]} Variable#defs
|
| 61 |
+
*/
|
| 62 |
+
this.defs = [];
|
| 63 |
+
|
| 64 |
+
this.tainted = false;
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Whether this is a stack variable.
|
| 68 |
+
* @member {boolean} Variable#stack
|
| 69 |
+
*/
|
| 70 |
+
this.stack = true;
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* Reference to the enclosing Scope.
|
| 74 |
+
* @member {Scope} Variable#scope
|
| 75 |
+
*/
|
| 76 |
+
this.scope = scope;
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
Variable.CatchClause = "CatchClause";
|
| 81 |
+
Variable.Parameter = "Parameter";
|
| 82 |
+
Variable.FunctionName = "FunctionName";
|
| 83 |
+
Variable.ClassName = "ClassName";
|
| 84 |
+
Variable.Variable = "Variable";
|
| 85 |
+
Variable.ImportBinding = "ImportBinding";
|
| 86 |
+
Variable.ImplicitGlobalVariable = "ImplicitGlobalVariable";
|
| 87 |
+
|
| 88 |
+
export default Variable;
|
| 89 |
+
|
| 90 |
+
/* vim: set sw=4 ts=4 et tw=80 : */
|
node_modules/eslint-scope/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "eslint-scope",
|
| 3 |
+
"description": "ECMAScript scope analyzer for ESLint",
|
| 4 |
+
"homepage": "https://github.com/eslint/js/blob/main/packages/eslint-scope/README.md",
|
| 5 |
+
"main": "./dist/eslint-scope.cjs",
|
| 6 |
+
"types": "./lib/index.d.cts",
|
| 7 |
+
"type": "module",
|
| 8 |
+
"exports": {
|
| 9 |
+
".": {
|
| 10 |
+
"import": {
|
| 11 |
+
"types": "./lib/index.d.ts",
|
| 12 |
+
"default": "./lib/index.js"
|
| 13 |
+
},
|
| 14 |
+
"require": {
|
| 15 |
+
"types": "./lib/index.d.cts",
|
| 16 |
+
"default": "./dist/eslint-scope.cjs"
|
| 17 |
+
}
|
| 18 |
+
},
|
| 19 |
+
"./package.json": "./package.json"
|
| 20 |
+
},
|
| 21 |
+
"version": "9.1.2",
|
| 22 |
+
"engines": {
|
| 23 |
+
"node": "^20.19.0 || ^22.13.0 || >=24"
|
| 24 |
+
},
|
| 25 |
+
"repository": {
|
| 26 |
+
"type": "git",
|
| 27 |
+
"url": "https://github.com/eslint/js.git",
|
| 28 |
+
"directory": "packages/eslint-scope"
|
| 29 |
+
},
|
| 30 |
+
"funding": "https://opencollective.com/eslint",
|
| 31 |
+
"keywords": [
|
| 32 |
+
"eslint"
|
| 33 |
+
],
|
| 34 |
+
"bugs": {
|
| 35 |
+
"url": "https://github.com/eslint/js/issues"
|
| 36 |
+
},
|
| 37 |
+
"license": "BSD-2-Clause",
|
| 38 |
+
"scripts": {
|
| 39 |
+
"build": "rollup -c",
|
| 40 |
+
"lint:types": "attw --pack",
|
| 41 |
+
"pretest": "npm run build",
|
| 42 |
+
"test": "node Makefile.js test && npm run test:types",
|
| 43 |
+
"test:types": "tsc -p tsconfig.json && tsc -p tests/types/tsconfig.json"
|
| 44 |
+
},
|
| 45 |
+
"files": [
|
| 46 |
+
"LICENSE",
|
| 47 |
+
"README.md",
|
| 48 |
+
"lib",
|
| 49 |
+
"dist/eslint-scope.cjs"
|
| 50 |
+
],
|
| 51 |
+
"dependencies": {
|
| 52 |
+
"@types/esrecurse": "^4.3.1",
|
| 53 |
+
"@types/estree": "^1.0.8",
|
| 54 |
+
"esrecurse": "^4.3.0",
|
| 55 |
+
"estraverse": "^5.2.0"
|
| 56 |
+
},
|
| 57 |
+
"devDependencies": {
|
| 58 |
+
"@typescript-eslint/parser": "^8.7.0",
|
| 59 |
+
"chai": "^6.0.0",
|
| 60 |
+
"eslint": ">=10.0.0-rc.0 <10.0.0 || ^10.0.0",
|
| 61 |
+
"eslint-visitor-keys": "^5.0.1",
|
| 62 |
+
"espree": "^11.2.0",
|
| 63 |
+
"npm-license": "^0.3.3",
|
| 64 |
+
"shelljs": "^0.8.5"
|
| 65 |
+
}
|
| 66 |
+
}
|
node_modules/eslint-visitor-keys/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright contributors
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
node_modules/eslint-visitor-keys/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# eslint-visitor-keys
|
| 2 |
+
|
| 3 |
+
[](https://www.npmjs.com/package/eslint-visitor-keys)
|
| 4 |
+
[](http://www.npmtrends.com/eslint-visitor-keys)
|
| 5 |
+
[](https://github.com/eslint/js/actions)
|
| 6 |
+
|
| 7 |
+
Constants and utilities about visitor keys to traverse AST.
|
| 8 |
+
|
| 9 |
+
## 💿 Installation
|
| 10 |
+
|
| 11 |
+
Use [npm] to install.
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
$ npm install eslint-visitor-keys
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
### Requirements
|
| 18 |
+
|
| 19 |
+
- [Node.js] `^20.19.0`, `^22.13.0`, or `>=24`
|
| 20 |
+
|
| 21 |
+
## 📖 Usage
|
| 22 |
+
|
| 23 |
+
To use in an ESM file:
|
| 24 |
+
|
| 25 |
+
```js
|
| 26 |
+
import * as evk from "eslint-visitor-keys";
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
To use in a CommonJS file:
|
| 30 |
+
|
| 31 |
+
```js
|
| 32 |
+
const evk = require("eslint-visitor-keys");
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### evk.KEYS
|
| 36 |
+
|
| 37 |
+
> type: `{ [type: string]: string[] | undefined }`
|
| 38 |
+
|
| 39 |
+
Visitor keys. This keys are frozen.
|
| 40 |
+
|
| 41 |
+
This is an object. Keys are the type of [ESTree] nodes. Their values are an array of property names which have child nodes.
|
| 42 |
+
|
| 43 |
+
For example:
|
| 44 |
+
|
| 45 |
+
```
|
| 46 |
+
console.log(evk.KEYS.AssignmentExpression) // → ["left", "right"]
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### evk.getKeys(node)
|
| 50 |
+
|
| 51 |
+
> type: `(node: object) => string[]`
|
| 52 |
+
|
| 53 |
+
Get the visitor keys of a given AST node.
|
| 54 |
+
|
| 55 |
+
This is similar to `Object.keys(node)` of ES Standard, but some keys are excluded: `parent`, `leadingComments`, `trailingComments`, and names which start with `_`.
|
| 56 |
+
|
| 57 |
+
This will be used to traverse unknown nodes.
|
| 58 |
+
|
| 59 |
+
For example:
|
| 60 |
+
|
| 61 |
+
```js
|
| 62 |
+
const node = {
|
| 63 |
+
type: "AssignmentExpression",
|
| 64 |
+
left: { type: "Identifier", name: "foo" },
|
| 65 |
+
right: { type: "Literal", value: 0 },
|
| 66 |
+
};
|
| 67 |
+
console.log(evk.getKeys(node)); // → ["type", "left", "right"]
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### evk.unionWith(additionalKeys)
|
| 71 |
+
|
| 72 |
+
> type: `(additionalKeys: object) => { [type: string]: string[] | undefined }`
|
| 73 |
+
|
| 74 |
+
Make the union set with `evk.KEYS` and the given keys.
|
| 75 |
+
|
| 76 |
+
- The order of keys is, `additionalKeys` is at first, then `evk.KEYS` is concatenated after that.
|
| 77 |
+
- It removes duplicated keys as keeping the first one.
|
| 78 |
+
|
| 79 |
+
For example:
|
| 80 |
+
|
| 81 |
+
```js
|
| 82 |
+
console.log(
|
| 83 |
+
evk.unionWith({
|
| 84 |
+
MethodDefinition: ["decorators"],
|
| 85 |
+
}),
|
| 86 |
+
); // → { ..., MethodDefinition: ["decorators", "key", "value"], ... }
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
## 📰 Change log
|
| 90 |
+
|
| 91 |
+
See [GitHub releases](https://github.com/eslint/js/releases).
|
| 92 |
+
|
| 93 |
+
## 🍻 Contributing
|
| 94 |
+
|
| 95 |
+
Welcome. See [ESLint contribution guidelines](https://eslint.org/docs/developer-guide/contributing/).
|
| 96 |
+
|
| 97 |
+
### Development commands
|
| 98 |
+
|
| 99 |
+
- `npm test` runs tests and measures code coverage.
|
| 100 |
+
- `npm run lint` checks source codes with ESLint.
|
| 101 |
+
- `npm run test:open-coverage` opens the code coverage report of the previous test with your default browser.
|
| 102 |
+
|
| 103 |
+
[npm]: https://www.npmjs.com/
|
| 104 |
+
[Node.js]: https://nodejs.org/
|
| 105 |
+
[ESTree]: https://github.com/estree/estree
|
| 106 |
+
|
| 107 |
+
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
|
| 108 |
+
<!--sponsorsstart-->
|
| 109 |
+
|
| 110 |
+
## Sponsors
|
| 111 |
+
|
| 112 |
+
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
|
| 113 |
+
to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
| 114 |
+
|
| 115 |
+
<h3>Platinum Sponsors</h3>
|
| 116 |
+
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a></p><h3>Gold Sponsors</h3>
|
| 117 |
+
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a></p><h3>Silver Sponsors</h3>
|
| 118 |
+
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/d472863/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
| 119 |
+
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="https://depot.dev"><img src="https://images.opencollective.com/depot/39125a1/logo.png" alt="Depot" height="32"></a> <a href="https://www.n-ix.com/"><img src="https://images.opencollective.com/n-ix-ltd/575a7a5/logo.png" alt="N-iX Ltd" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
|
| 120 |
+
<h3>Technology Sponsors</h3>
|
| 121 |
+
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
| 122 |
+
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
| 123 |
+
<!--sponsorsend-->
|
node_modules/eslint-visitor-keys/lib/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @author Toru Nagashima <https://github.com/mysticatea>
|
| 3 |
+
* See LICENSE file in root directory for full license.
|
| 4 |
+
*/
|
| 5 |
+
import KEYS from "./visitor-keys.js";
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* @typedef {import('./visitor-keys.js').VisitorKeys} VisitorKeys
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
// List to ignore keys.
|
| 12 |
+
const KEY_BLACKLIST = new Set([
|
| 13 |
+
"parent",
|
| 14 |
+
"leadingComments",
|
| 15 |
+
"trailingComments",
|
| 16 |
+
]);
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Check whether a given key should be used or not.
|
| 20 |
+
* @param {string} key The key to check.
|
| 21 |
+
* @returns {boolean} `true` if the key should be used.
|
| 22 |
+
*/
|
| 23 |
+
function filterKey(key) {
|
| 24 |
+
return !KEY_BLACKLIST.has(key) && key[0] !== "_";
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
|
| 28 |
+
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
|
| 29 |
+
*/
|
| 30 |
+
/**
|
| 31 |
+
* Get visitor keys of a given node.
|
| 32 |
+
* @param {Object} node The AST node to get keys.
|
| 33 |
+
* @returns {readonly string[]} Visitor keys of the node.
|
| 34 |
+
*/
|
| 35 |
+
export function getKeys(node) {
|
| 36 |
+
return Object.keys(node).filter(filterKey);
|
| 37 |
+
}
|
| 38 |
+
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly` */
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Make the union set with `KEYS` and given keys.
|
| 42 |
+
* @param {VisitorKeys} additionalKeys The additional keys.
|
| 43 |
+
* @returns {VisitorKeys} The union set.
|
| 44 |
+
*/
|
| 45 |
+
export function unionWith(additionalKeys) {
|
| 46 |
+
const retv =
|
| 47 |
+
/** @type {{ [type: string]: ReadonlyArray<string> }} */
|
| 48 |
+
(Object.assign({}, KEYS));
|
| 49 |
+
|
| 50 |
+
for (const type of Object.keys(additionalKeys)) {
|
| 51 |
+
if (Object.hasOwn(retv, type)) {
|
| 52 |
+
const keys = new Set(additionalKeys[type]);
|
| 53 |
+
|
| 54 |
+
for (const key of retv[type]) {
|
| 55 |
+
keys.add(key);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
retv[type] = Object.freeze(Array.from(keys));
|
| 59 |
+
} else {
|
| 60 |
+
retv[type] = Object.freeze(Array.from(additionalKeys[type]));
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
return Object.freeze(retv);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
export { KEYS };
|
node_modules/eslint-visitor-keys/lib/visitor-keys.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
|
| 2 |
+
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
|
| 3 |
+
*/
|
| 4 |
+
/**
|
| 5 |
+
* @typedef {{ readonly [type: string]: ReadonlyArray<string> }} VisitorKeys
|
| 6 |
+
*/
|
| 7 |
+
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly string[]`. TODO: check why */
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* @type {VisitorKeys}
|
| 11 |
+
*/
|
| 12 |
+
const KEYS = {
|
| 13 |
+
ArrayExpression: ["elements"],
|
| 14 |
+
ArrayPattern: ["elements"],
|
| 15 |
+
ArrowFunctionExpression: ["params", "body"],
|
| 16 |
+
AssignmentExpression: ["left", "right"],
|
| 17 |
+
AssignmentPattern: ["left", "right"],
|
| 18 |
+
AwaitExpression: ["argument"],
|
| 19 |
+
BinaryExpression: ["left", "right"],
|
| 20 |
+
BlockStatement: ["body"],
|
| 21 |
+
BreakStatement: ["label"],
|
| 22 |
+
CallExpression: ["callee", "arguments"],
|
| 23 |
+
CatchClause: ["param", "body"],
|
| 24 |
+
ChainExpression: ["expression"],
|
| 25 |
+
ClassBody: ["body"],
|
| 26 |
+
ClassDeclaration: ["id", "superClass", "body"],
|
| 27 |
+
ClassExpression: ["id", "superClass", "body"],
|
| 28 |
+
ConditionalExpression: ["test", "consequent", "alternate"],
|
| 29 |
+
ContinueStatement: ["label"],
|
| 30 |
+
DebuggerStatement: [],
|
| 31 |
+
DoWhileStatement: ["body", "test"],
|
| 32 |
+
EmptyStatement: [],
|
| 33 |
+
ExperimentalRestProperty: ["argument"],
|
| 34 |
+
ExperimentalSpreadProperty: ["argument"],
|
| 35 |
+
ExportAllDeclaration: ["exported", "source", "attributes"],
|
| 36 |
+
ExportDefaultDeclaration: ["declaration"],
|
| 37 |
+
ExportNamedDeclaration: [
|
| 38 |
+
"declaration",
|
| 39 |
+
"specifiers",
|
| 40 |
+
"source",
|
| 41 |
+
"attributes",
|
| 42 |
+
],
|
| 43 |
+
ExportSpecifier: ["local", "exported"],
|
| 44 |
+
ExpressionStatement: ["expression"],
|
| 45 |
+
ForInStatement: ["left", "right", "body"],
|
| 46 |
+
ForOfStatement: ["left", "right", "body"],
|
| 47 |
+
ForStatement: ["init", "test", "update", "body"],
|
| 48 |
+
FunctionDeclaration: ["id", "params", "body"],
|
| 49 |
+
FunctionExpression: ["id", "params", "body"],
|
| 50 |
+
Identifier: [],
|
| 51 |
+
IfStatement: ["test", "consequent", "alternate"],
|
| 52 |
+
ImportAttribute: ["key", "value"],
|
| 53 |
+
ImportDeclaration: ["specifiers", "source", "attributes"],
|
| 54 |
+
ImportDefaultSpecifier: ["local"],
|
| 55 |
+
ImportExpression: ["source", "options"],
|
| 56 |
+
ImportNamespaceSpecifier: ["local"],
|
| 57 |
+
ImportSpecifier: ["imported", "local"],
|
| 58 |
+
JSXAttribute: ["name", "value"],
|
| 59 |
+
JSXClosingElement: ["name"],
|
| 60 |
+
JSXClosingFragment: [],
|
| 61 |
+
JSXElement: ["openingElement", "children", "closingElement"],
|
| 62 |
+
JSXEmptyExpression: [],
|
| 63 |
+
JSXExpressionContainer: ["expression"],
|
| 64 |
+
JSXFragment: ["openingFragment", "children", "closingFragment"],
|
| 65 |
+
JSXIdentifier: [],
|
| 66 |
+
JSXMemberExpression: ["object", "property"],
|
| 67 |
+
JSXNamespacedName: ["namespace", "name"],
|
| 68 |
+
JSXOpeningElement: ["name", "attributes"],
|
| 69 |
+
JSXOpeningFragment: [],
|
| 70 |
+
JSXSpreadAttribute: ["argument"],
|
| 71 |
+
JSXSpreadChild: ["expression"],
|
| 72 |
+
JSXText: [],
|
| 73 |
+
LabeledStatement: ["label", "body"],
|
| 74 |
+
Literal: [],
|
| 75 |
+
LogicalExpression: ["left", "right"],
|
| 76 |
+
MemberExpression: ["object", "property"],
|
| 77 |
+
MetaProperty: ["meta", "property"],
|
| 78 |
+
MethodDefinition: ["key", "value"],
|
| 79 |
+
NewExpression: ["callee", "arguments"],
|
| 80 |
+
ObjectExpression: ["properties"],
|
| 81 |
+
ObjectPattern: ["properties"],
|
| 82 |
+
PrivateIdentifier: [],
|
| 83 |
+
Program: ["body"],
|
| 84 |
+
Property: ["key", "value"],
|
| 85 |
+
PropertyDefinition: ["key", "value"],
|
| 86 |
+
RestElement: ["argument"],
|
| 87 |
+
ReturnStatement: ["argument"],
|
| 88 |
+
SequenceExpression: ["expressions"],
|
| 89 |
+
SpreadElement: ["argument"],
|
| 90 |
+
StaticBlock: ["body"],
|
| 91 |
+
Super: [],
|
| 92 |
+
SwitchCase: ["test", "consequent"],
|
| 93 |
+
SwitchStatement: ["discriminant", "cases"],
|
| 94 |
+
TaggedTemplateExpression: ["tag", "quasi"],
|
| 95 |
+
TemplateElement: [],
|
| 96 |
+
TemplateLiteral: ["quasis", "expressions"],
|
| 97 |
+
ThisExpression: [],
|
| 98 |
+
ThrowStatement: ["argument"],
|
| 99 |
+
TryStatement: ["block", "handler", "finalizer"],
|
| 100 |
+
UnaryExpression: ["argument"],
|
| 101 |
+
UpdateExpression: ["argument"],
|
| 102 |
+
VariableDeclaration: ["declarations"],
|
| 103 |
+
VariableDeclarator: ["id", "init"],
|
| 104 |
+
WhileStatement: ["test", "body"],
|
| 105 |
+
WithStatement: ["object", "body"],
|
| 106 |
+
YieldExpression: ["argument"],
|
| 107 |
+
};
|
| 108 |
+
|
| 109 |
+
// Types.
|
| 110 |
+
const NODE_TYPES = Object.keys(KEYS);
|
| 111 |
+
|
| 112 |
+
// Freeze the keys.
|
| 113 |
+
for (const type of NODE_TYPES) {
|
| 114 |
+
Object.freeze(KEYS[type]);
|
| 115 |
+
}
|
| 116 |
+
Object.freeze(KEYS);
|
| 117 |
+
|
| 118 |
+
export default KEYS;
|
node_modules/eslint-visitor-keys/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "eslint-visitor-keys",
|
| 3 |
+
"version": "5.0.1",
|
| 4 |
+
"description": "Constants and utilities about visitor keys to traverse AST.",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"main": "dist/eslint-visitor-keys.cjs",
|
| 7 |
+
"types": "./dist/index.d.ts",
|
| 8 |
+
"exports": {
|
| 9 |
+
".": [
|
| 10 |
+
{
|
| 11 |
+
"import": "./lib/index.js",
|
| 12 |
+
"require": "./dist/eslint-visitor-keys.cjs"
|
| 13 |
+
},
|
| 14 |
+
"./dist/eslint-visitor-keys.cjs"
|
| 15 |
+
],
|
| 16 |
+
"./package.json": "./package.json"
|
| 17 |
+
},
|
| 18 |
+
"files": [
|
| 19 |
+
"dist/index.d.ts",
|
| 20 |
+
"dist/visitor-keys.d.ts",
|
| 21 |
+
"dist/eslint-visitor-keys.cjs",
|
| 22 |
+
"dist/eslint-visitor-keys.d.cts",
|
| 23 |
+
"lib"
|
| 24 |
+
],
|
| 25 |
+
"engines": {
|
| 26 |
+
"node": "^20.19.0 || ^22.13.0 || >=24"
|
| 27 |
+
},
|
| 28 |
+
"devDependencies": {
|
| 29 |
+
"rollup-plugin-dts": "^6.2.3",
|
| 30 |
+
"tsd": "^0.33.0"
|
| 31 |
+
},
|
| 32 |
+
"scripts": {
|
| 33 |
+
"build": "npm run build:cjs && npm run build:types",
|
| 34 |
+
"build:cjs": "rollup -c",
|
| 35 |
+
"build:debug": "npm run build:cjs -- -m && npm run build:types",
|
| 36 |
+
"build:types": "tsc -v && tsc",
|
| 37 |
+
"test": "mocha \"tests/**/*.test.cjs\" && mocha \"tests/**/*.test.js\" && npm run test:types",
|
| 38 |
+
"test:coverage": "c8 npm test",
|
| 39 |
+
"test:types": "tsd"
|
| 40 |
+
},
|
| 41 |
+
"repository": {
|
| 42 |
+
"type": "git",
|
| 43 |
+
"url": "https://github.com/eslint/js.git",
|
| 44 |
+
"directory": "packages/eslint-visitor-keys"
|
| 45 |
+
},
|
| 46 |
+
"funding": "https://opencollective.com/eslint",
|
| 47 |
+
"keywords": [
|
| 48 |
+
"eslint"
|
| 49 |
+
],
|
| 50 |
+
"author": "Toru Nagashima (https://github.com/mysticatea)",
|
| 51 |
+
"license": "Apache-2.0",
|
| 52 |
+
"bugs": {
|
| 53 |
+
"url": "https://github.com/eslint/js/issues"
|
| 54 |
+
},
|
| 55 |
+
"homepage": "https://github.com/eslint/js/blob/main/packages/eslint-visitor-keys/README.md",
|
| 56 |
+
"sideEffects": false
|
| 57 |
+
}
|
node_modules/eslint/lib/rules/space-in-parens.js
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ileoverview Disallows or enforces spaces inside of parentheses.
|
| 3 |
+
* @author Jonathan Rajavuori
|
| 4 |
+
* @deprecated in ESLint v8.53.0
|
| 5 |
+
*/
|
| 6 |
+
"use strict";
|
| 7 |
+
|
| 8 |
+
const astUtils = require("./utils/ast-utils");
|
| 9 |
+
|
| 10 |
+
//------------------------------------------------------------------------------
|
| 11 |
+
// Rule Definition
|
| 12 |
+
//------------------------------------------------------------------------------
|
| 13 |
+
|
| 14 |
+
/** @type {import('../types').Rule.RuleModule} */
|
| 15 |
+
module.exports = {
|
| 16 |
+
meta: {
|
| 17 |
+
deprecated: {
|
| 18 |
+
message: "Formatting rules are being moved out of ESLint core.",
|
| 19 |
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
| 20 |
+
deprecatedSince: "8.53.0",
|
| 21 |
+
availableUntil: "11.0.0",
|
| 22 |
+
replacedBy: [
|
| 23 |
+
{
|
| 24 |
+
message:
|
| 25 |
+
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
| 26 |
+
url: "https://eslint.style/guide/migration",
|
| 27 |
+
plugin: {
|
| 28 |
+
name: "@stylistic/eslint-plugin",
|
| 29 |
+
url: "https://eslint.style",
|
| 30 |
+
},
|
| 31 |
+
rule: {
|
| 32 |
+
name: "space-in-parens",
|
| 33 |
+
url: "https://eslint.style/rules/space-in-parens",
|
| 34 |
+
},
|
| 35 |
+
},
|
| 36 |
+
],
|
| 37 |
+
},
|
| 38 |
+
type: "layout",
|
| 39 |
+
|
| 40 |
+
docs: {
|
| 41 |
+
description: "Enforce consistent spacing inside parentheses",
|
| 42 |
+
recommended: false,
|
| 43 |
+
url: "https://eslint.org/docs/latest/rules/space-in-parens",
|
| 44 |
+
},
|
| 45 |
+
|
| 46 |
+
fixable: "whitespace",
|
| 47 |
+
|
| 48 |
+
schema: [
|
| 49 |
+
{
|
| 50 |
+
enum: ["always", "never"],
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
type: "object",
|
| 54 |
+
properties: {
|
| 55 |
+
exceptions: {
|
| 56 |
+
type: "array",
|
| 57 |
+
items: {
|
| 58 |
+
enum: ["{}", "[]", "()", "empty"],
|
| 59 |
+
},
|
| 60 |
+
uniqueItems: true,
|
| 61 |
+
},
|
| 62 |
+
},
|
| 63 |
+
additionalProperties: false,
|
| 64 |
+
},
|
| 65 |
+
],
|
| 66 |
+
|
| 67 |
+
messages: {
|
| 68 |
+
missingOpeningSpace: "There must be a space after this paren.",
|
| 69 |
+
missingClosingSpace: "There must be a space before this paren.",
|
| 70 |
+
rejectedOpeningSpace: "There should be no space after this paren.",
|
| 71 |
+
rejectedClosingSpace: "There should be no space before this paren.",
|
| 72 |
+
},
|
| 73 |
+
},
|
| 74 |
+
|
| 75 |
+
create(context) {
|
| 76 |
+
const ALWAYS = context.options[0] === "always",
|
| 77 |
+
exceptionsArrayOptions =
|
| 78 |
+
(context.options[1] && context.options[1].exceptions) || [],
|
| 79 |
+
options = {};
|
| 80 |
+
|
| 81 |
+
let exceptions;
|
| 82 |
+
|
| 83 |
+
if (exceptionsArrayOptions.length) {
|
| 84 |
+
options.braceException = exceptionsArrayOptions.includes("{}");
|
| 85 |
+
options.bracketException = exceptionsArrayOptions.includes("[]");
|
| 86 |
+
options.parenException = exceptionsArrayOptions.includes("()");
|
| 87 |
+
options.empty = exceptionsArrayOptions.includes("empty");
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Produces an object with the opener and closer exception values
|
| 92 |
+
* @returns {Object} `openers` and `closers` exception values
|
| 93 |
+
* @private
|
| 94 |
+
*/
|
| 95 |
+
function getExceptions() {
|
| 96 |
+
const openers = [],
|
| 97 |
+
closers = [];
|
| 98 |
+
|
| 99 |
+
if (options.braceException) {
|
| 100 |
+
openers.push("{");
|
| 101 |
+
closers.push("}");
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
if (options.bracketException) {
|
| 105 |
+
openers.push("[");
|
| 106 |
+
closers.push("]");
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
if (options.parenException) {
|
| 110 |
+
openers.push("(");
|
| 111 |
+
closers.push(")");
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
if (options.empty) {
|
| 115 |
+
openers.push(")");
|
| 116 |
+
closers.push("(");
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
return {
|
| 120 |
+
openers,
|
| 121 |
+
closers,
|
| 122 |
+
};
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
//--------------------------------------------------------------------------
|
| 126 |
+
// Helpers
|
| 127 |
+
//--------------------------------------------------------------------------
|
| 128 |
+
const sourceCode = context.sourceCode;
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Determines if a token is one of the exceptions for the opener paren
|
| 132 |
+
* @param {Object} token The token to check
|
| 133 |
+
* @returns {boolean} True if the token is one of the exceptions for the opener paren
|
| 134 |
+
*/
|
| 135 |
+
function isOpenerException(token) {
|
| 136 |
+
return exceptions.openers.includes(token.value);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* Determines if a token is one of the exceptions for the closer paren
|
| 141 |
+
* @param {Object} token The token to check
|
| 142 |
+
* @returns {boolean} True if the token is one of the exceptions for the closer paren
|
| 143 |
+
*/
|
| 144 |
+
function isCloserException(token) {
|
| 145 |
+
return exceptions.closers.includes(token.value);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Determines if an opening paren is immediately followed by a required space
|
| 150 |
+
* @param {Object} openingParenToken The paren token
|
| 151 |
+
* @param {Object} tokenAfterOpeningParen The token after it
|
| 152 |
+
* @returns {boolean} True if the opening paren is missing a required space
|
| 153 |
+
*/
|
| 154 |
+
function openerMissingSpace(openingParenToken, tokenAfterOpeningParen) {
|
| 155 |
+
if (
|
| 156 |
+
sourceCode.isSpaceBetween(
|
| 157 |
+
openingParenToken,
|
| 158 |
+
tokenAfterOpeningParen,
|
| 159 |
+
)
|
| 160 |
+
) {
|
| 161 |
+
return false;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
if (
|
| 165 |
+
!options.empty &&
|
| 166 |
+
astUtils.isClosingParenToken(tokenAfterOpeningParen)
|
| 167 |
+
) {
|
| 168 |
+
return false;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
if (ALWAYS) {
|
| 172 |
+
return !isOpenerException(tokenAfterOpeningParen);
|
| 173 |
+
}
|
| 174 |
+
return isOpenerException(tokenAfterOpeningParen);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
/**
|
| 178 |
+
* Determines if an opening paren is immediately followed by a disallowed space
|
| 179 |
+
* @param {Object} openingParenToken The paren token
|
| 180 |
+
* @param {Object} tokenAfterOpeningParen The token after it
|
| 181 |
+
* @returns {boolean} True if the opening paren has a disallowed space
|
| 182 |
+
*/
|
| 183 |
+
function openerRejectsSpace(openingParenToken, tokenAfterOpeningParen) {
|
| 184 |
+
if (
|
| 185 |
+
!astUtils.isTokenOnSameLine(
|
| 186 |
+
openingParenToken,
|
| 187 |
+
tokenAfterOpeningParen,
|
| 188 |
+
)
|
| 189 |
+
) {
|
| 190 |
+
return false;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
if (tokenAfterOpeningParen.type === "Line") {
|
| 194 |
+
return false;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
if (
|
| 198 |
+
!sourceCode.isSpaceBetween(
|
| 199 |
+
openingParenToken,
|
| 200 |
+
tokenAfterOpeningParen,
|
| 201 |
+
)
|
| 202 |
+
) {
|
| 203 |
+
return false;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
if (ALWAYS) {
|
| 207 |
+
return isOpenerException(tokenAfterOpeningParen);
|
| 208 |
+
}
|
| 209 |
+
return !isOpenerException(tokenAfterOpeningParen);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
/**
|
| 213 |
+
* Determines if a closing paren is immediately preceded by a required space
|
| 214 |
+
* @param {Object} tokenBeforeClosingParen The token before the paren
|
| 215 |
+
* @param {Object} closingParenToken The paren token
|
| 216 |
+
* @returns {boolean} True if the closing paren is missing a required space
|
| 217 |
+
*/
|
| 218 |
+
function closerMissingSpace(
|
| 219 |
+
tokenBeforeClosingParen,
|
| 220 |
+
closingParenToken,
|
| 221 |
+
) {
|
| 222 |
+
if (
|
| 223 |
+
sourceCode.isSpaceBetween(
|
| 224 |
+
tokenBeforeClosingParen,
|
| 225 |
+
closingParenToken,
|
| 226 |
+
)
|
| 227 |
+
) {
|
| 228 |
+
return false;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
if (
|
| 232 |
+
!options.empty &&
|
| 233 |
+
astUtils.isOpeningParenToken(tokenBeforeClosingParen)
|
| 234 |
+
) {
|
| 235 |
+
return false;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
if (ALWAYS) {
|
| 239 |
+
return !isCloserException(tokenBeforeClosingParen);
|
| 240 |
+
}
|
| 241 |
+
return isCloserException(tokenBeforeClosingParen);
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
/**
|
| 245 |
+
* Determines if a closer paren is immediately preceded by a disallowed space
|
| 246 |
+
* @param {Object} tokenBeforeClosingParen The token before the paren
|
| 247 |
+
* @param {Object} closingParenToken The paren token
|
| 248 |
+
* @returns {boolean} True if the closing paren has a disallowed space
|
| 249 |
+
*/
|
| 250 |
+
function closerRejectsSpace(
|
| 251 |
+
tokenBeforeClosingParen,
|
| 252 |
+
closingParenToken,
|
| 253 |
+
) {
|
| 254 |
+
if (
|
| 255 |
+
!astUtils.isTokenOnSameLine(
|
| 256 |
+
tokenBeforeClosingParen,
|
| 257 |
+
closingParenToken,
|
| 258 |
+
)
|
| 259 |
+
) {
|
| 260 |
+
return false;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
if (
|
| 264 |
+
!sourceCode.isSpaceBetween(
|
| 265 |
+
tokenBeforeClosingParen,
|
| 266 |
+
closingParenToken,
|
| 267 |
+
)
|
| 268 |
+
) {
|
| 269 |
+
return false;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
if (ALWAYS) {
|
| 273 |
+
return isCloserException(tokenBeforeClosingParen);
|
| 274 |
+
}
|
| 275 |
+
return !isCloserException(tokenBeforeClosingParen);
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
//--------------------------------------------------------------------------
|
| 279 |
+
// Public
|
| 280 |
+
//--------------------------------------------------------------------------
|
| 281 |
+
|
| 282 |
+
return {
|
| 283 |
+
Program: function checkParenSpaces(node) {
|
| 284 |
+
exceptions = getExceptions();
|
| 285 |
+
const tokens = sourceCode.tokensAndComments;
|
| 286 |
+
|
| 287 |
+
tokens.forEach((token, i) => {
|
| 288 |
+
const prevToken = tokens[i - 1];
|
| 289 |
+
const nextToken = tokens[i + 1];
|
| 290 |
+
|
| 291 |
+
// if token is not an opening or closing paren token, do nothing
|
| 292 |
+
if (
|
| 293 |
+
!astUtils.isOpeningParenToken(token) &&
|
| 294 |
+
!astUtils.isClosingParenToken(token)
|
| 295 |
+
) {
|
| 296 |
+
return;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
// if token is an opening paren and is not followed by a required space
|
| 300 |
+
if (
|
| 301 |
+
token.value === "(" &&
|
| 302 |
+
openerMissingSpace(token, nextToken)
|
| 303 |
+
) {
|
| 304 |
+
context.report({
|
| 305 |
+
node,
|
| 306 |
+
loc: token.loc,
|
| 307 |
+
messageId: "missingOpeningSpace",
|
| 308 |
+
fix(fixer) {
|
| 309 |
+
return fixer.insertTextAfter(token, " ");
|
| 310 |
+
},
|
| 311 |
+
});
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
// if token is an opening paren and is followed by a disallowed space
|
| 315 |
+
if (
|
| 316 |
+
token.value === "(" &&
|
| 317 |
+
openerRejectsSpace(token, nextToken)
|
| 318 |
+
) {
|
| 319 |
+
context.report({
|
| 320 |
+
node,
|
| 321 |
+
loc: {
|
| 322 |
+
start: token.loc.end,
|
| 323 |
+
end: nextToken.loc.start,
|
| 324 |
+
},
|
| 325 |
+
messageId: "rejectedOpeningSpace",
|
| 326 |
+
fix(fixer) {
|
| 327 |
+
return fixer.removeRange([
|
| 328 |
+
token.range[1],
|
| 329 |
+
nextToken.range[0],
|
| 330 |
+
]);
|
| 331 |
+
},
|
| 332 |
+
});
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
// if token is a closing paren and is not preceded by a required space
|
| 336 |
+
if (
|
| 337 |
+
token.value === ")" &&
|
| 338 |
+
closerMissingSpace(prevToken, token)
|
| 339 |
+
) {
|
| 340 |
+
context.report({
|
| 341 |
+
node,
|
| 342 |
+
loc: token.loc,
|
| 343 |
+
messageId: "missingClosingSpace",
|
| 344 |
+
fix(fixer) {
|
| 345 |
+
return fixer.insertTextBefore(token, " ");
|
| 346 |
+
},
|
| 347 |
+
});
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
// if token is a closing paren and is preceded by a disallowed space
|
| 351 |
+
if (
|
| 352 |
+
token.value === ")" &&
|
| 353 |
+
closerRejectsSpace(prevToken, token)
|
| 354 |
+
) {
|
| 355 |
+
context.report({
|
| 356 |
+
node,
|
| 357 |
+
loc: {
|
| 358 |
+
start: prevToken.loc.end,
|
| 359 |
+
end: token.loc.start,
|
| 360 |
+
},
|
| 361 |
+
messageId: "rejectedClosingSpace",
|
| 362 |
+
fix(fixer) {
|
| 363 |
+
return fixer.removeRange([
|
| 364 |
+
prevToken.range[1],
|
| 365 |
+
token.range[0],
|
| 366 |
+
]);
|
| 367 |
+
},
|
| 368 |
+
});
|
| 369 |
+
}
|
| 370 |
+
});
|
| 371 |
+
},
|
| 372 |
+
};
|
| 373 |
+
},
|
| 374 |
+
};
|
node_modules/eslint/lib/rules/space-infix-ops.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview Require spaces around infix operators
|
| 3 |
+
* @author Michael Ficarra
|
| 4 |
+
* @deprecated in ESLint v8.53.0
|
| 5 |
+
*/
|
| 6 |
+
"use strict";
|
| 7 |
+
|
| 8 |
+
const { isEqToken } = require("./utils/ast-utils");
|
| 9 |
+
|
| 10 |
+
//------------------------------------------------------------------------------
|
| 11 |
+
// Rule Definition
|
| 12 |
+
//------------------------------------------------------------------------------
|
| 13 |
+
|
| 14 |
+
/** @type {import('../types').Rule.RuleModule} */
|
| 15 |
+
module.exports = {
|
| 16 |
+
meta: {
|
| 17 |
+
deprecated: {
|
| 18 |
+
message: "Formatting rules are being moved out of ESLint core.",
|
| 19 |
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
| 20 |
+
deprecatedSince: "8.53.0",
|
| 21 |
+
availableUntil: "11.0.0",
|
| 22 |
+
replacedBy: [
|
| 23 |
+
{
|
| 24 |
+
message:
|
| 25 |
+
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
| 26 |
+
url: "https://eslint.style/guide/migration",
|
| 27 |
+
plugin: {
|
| 28 |
+
name: "@stylistic/eslint-plugin",
|
| 29 |
+
url: "https://eslint.style",
|
| 30 |
+
},
|
| 31 |
+
rule: {
|
| 32 |
+
name: "space-infix-ops",
|
| 33 |
+
url: "https://eslint.style/rules/space-infix-ops",
|
| 34 |
+
},
|
| 35 |
+
},
|
| 36 |
+
],
|
| 37 |
+
},
|
| 38 |
+
type: "layout",
|
| 39 |
+
|
| 40 |
+
docs: {
|
| 41 |
+
description: "Require spacing around infix operators",
|
| 42 |
+
recommended: false,
|
| 43 |
+
url: "https://eslint.org/docs/latest/rules/space-infix-ops",
|
| 44 |
+
},
|
| 45 |
+
|
| 46 |
+
fixable: "whitespace",
|
| 47 |
+
|
| 48 |
+
schema: [
|
| 49 |
+
{
|
| 50 |
+
type: "object",
|
| 51 |
+
properties: {
|
| 52 |
+
int32Hint: {
|
| 53 |
+
type: "boolean",
|
| 54 |
+
default: false,
|
| 55 |
+
},
|
| 56 |
+
},
|
| 57 |
+
additionalProperties: false,
|
| 58 |
+
},
|
| 59 |
+
],
|
| 60 |
+
|
| 61 |
+
messages: {
|
| 62 |
+
missingSpace: "Operator '{{operator}}' must be spaced.",
|
| 63 |
+
},
|
| 64 |
+
},
|
| 65 |
+
|
| 66 |
+
create(context) {
|
| 67 |
+
const int32Hint = context.options[0]
|
| 68 |
+
? context.options[0].int32Hint === true
|
| 69 |
+
: false;
|
| 70 |
+
const sourceCode = context.sourceCode;
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* Returns the first token which violates the rule
|
| 74 |
+
* @param {ASTNode} left The left node of the main node
|
| 75 |
+
* @param {ASTNode} right The right node of the main node
|
| 76 |
+
* @param {string} op The operator of the main node
|
| 77 |
+
* @returns {Object} The violator token or null
|
| 78 |
+
* @private
|
| 79 |
+
*/
|
| 80 |
+
function getFirstNonSpacedToken(left, right, op) {
|
| 81 |
+
const operator = sourceCode.getFirstTokenBetween(
|
| 82 |
+
left,
|
| 83 |
+
right,
|
| 84 |
+
token => token.value === op,
|
| 85 |
+
);
|
| 86 |
+
const prev = sourceCode.getTokenBefore(operator);
|
| 87 |
+
const next = sourceCode.getTokenAfter(operator);
|
| 88 |
+
|
| 89 |
+
if (
|
| 90 |
+
!sourceCode.isSpaceBetween(prev, operator) ||
|
| 91 |
+
!sourceCode.isSpaceBetween(operator, next)
|
| 92 |
+
) {
|
| 93 |
+
return operator;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
return null;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* Reports an AST node as a rule violation
|
| 101 |
+
* @param {ASTNode} mainNode The node to report
|
| 102 |
+
* @param {Object} culpritToken The token which has a problem
|
| 103 |
+
* @returns {void}
|
| 104 |
+
* @private
|
| 105 |
+
*/
|
| 106 |
+
function report(mainNode, culpritToken) {
|
| 107 |
+
context.report({
|
| 108 |
+
node: mainNode,
|
| 109 |
+
loc: culpritToken.loc,
|
| 110 |
+
messageId: "missingSpace",
|
| 111 |
+
data: {
|
| 112 |
+
operator: culpritToken.value,
|
| 113 |
+
},
|
| 114 |
+
fix(fixer) {
|
| 115 |
+
const previousToken =
|
| 116 |
+
sourceCode.getTokenBefore(culpritToken);
|
| 117 |
+
const afterToken = sourceCode.getTokenAfter(culpritToken);
|
| 118 |
+
let fixString = "";
|
| 119 |
+
|
| 120 |
+
if (culpritToken.range[0] - previousToken.range[1] === 0) {
|
| 121 |
+
fixString = " ";
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
fixString += culpritToken.value;
|
| 125 |
+
|
| 126 |
+
if (afterToken.range[0] - culpritToken.range[1] === 0) {
|
| 127 |
+
fixString += " ";
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
return fixer.replaceText(culpritToken, fixString);
|
| 131 |
+
},
|
| 132 |
+
});
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/**
|
| 136 |
+
* Check if the node is binary then report
|
| 137 |
+
* @param {ASTNode} node node to evaluate
|
| 138 |
+
* @returns {void}
|
| 139 |
+
* @private
|
| 140 |
+
*/
|
| 141 |
+
function checkBinary(node) {
|
| 142 |
+
const leftNode = node.left.typeAnnotation
|
| 143 |
+
? node.left.typeAnnotation
|
| 144 |
+
: node.left;
|
| 145 |
+
const rightNode = node.right;
|
| 146 |
+
|
| 147 |
+
// search for = in AssignmentPattern nodes
|
| 148 |
+
const operator = node.operator || "=";
|
| 149 |
+
|
| 150 |
+
const nonSpacedNode = getFirstNonSpacedToken(
|
| 151 |
+
leftNode,
|
| 152 |
+
rightNode,
|
| 153 |
+
operator,
|
| 154 |
+
);
|
| 155 |
+
|
| 156 |
+
if (nonSpacedNode) {
|
| 157 |
+
if (!(int32Hint && sourceCode.getText(node).endsWith("|0"))) {
|
| 158 |
+
report(node, nonSpacedNode);
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/**
|
| 164 |
+
* Check if the node is conditional
|
| 165 |
+
* @param {ASTNode} node node to evaluate
|
| 166 |
+
* @returns {void}
|
| 167 |
+
* @private
|
| 168 |
+
*/
|
| 169 |
+
function checkConditional(node) {
|
| 170 |
+
const nonSpacedConsequentNode = getFirstNonSpacedToken(
|
| 171 |
+
node.test,
|
| 172 |
+
node.consequent,
|
| 173 |
+
"?",
|
| 174 |
+
);
|
| 175 |
+
const nonSpacedAlternateNode = getFirstNonSpacedToken(
|
| 176 |
+
node.consequent,
|
| 177 |
+
node.alternate,
|
| 178 |
+
":",
|
| 179 |
+
);
|
| 180 |
+
|
| 181 |
+
if (nonSpacedConsequentNode) {
|
| 182 |
+
report(node, nonSpacedConsequentNode);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
if (nonSpacedAlternateNode) {
|
| 186 |
+
report(node, nonSpacedAlternateNode);
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/**
|
| 191 |
+
* Check if the node is a variable
|
| 192 |
+
* @param {ASTNode} node node to evaluate
|
| 193 |
+
* @returns {void}
|
| 194 |
+
* @private
|
| 195 |
+
*/
|
| 196 |
+
function checkVar(node) {
|
| 197 |
+
const leftNode = node.id.typeAnnotation
|
| 198 |
+
? node.id.typeAnnotation
|
| 199 |
+
: node.id;
|
| 200 |
+
const rightNode = node.init;
|
| 201 |
+
|
| 202 |
+
if (rightNode) {
|
| 203 |
+
const nonSpacedNode = getFirstNonSpacedToken(
|
| 204 |
+
leftNode,
|
| 205 |
+
rightNode,
|
| 206 |
+
"=",
|
| 207 |
+
);
|
| 208 |
+
|
| 209 |
+
if (nonSpacedNode) {
|
| 210 |
+
report(node, nonSpacedNode);
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
return {
|
| 216 |
+
AssignmentExpression: checkBinary,
|
| 217 |
+
AssignmentPattern: checkBinary,
|
| 218 |
+
BinaryExpression: checkBinary,
|
| 219 |
+
LogicalExpression: checkBinary,
|
| 220 |
+
ConditionalExpression: checkConditional,
|
| 221 |
+
VariableDeclarator: checkVar,
|
| 222 |
+
|
| 223 |
+
PropertyDefinition(node) {
|
| 224 |
+
if (!node.value) {
|
| 225 |
+
return;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
/*
|
| 229 |
+
* Because of computed properties and type annotations, some
|
| 230 |
+
* tokens may exist between `node.key` and `=`.
|
| 231 |
+
* Therefore, find the `=` from the right.
|
| 232 |
+
*/
|
| 233 |
+
const operatorToken = sourceCode.getTokenBefore(
|
| 234 |
+
node.value,
|
| 235 |
+
isEqToken,
|
| 236 |
+
);
|
| 237 |
+
const leftToken = sourceCode.getTokenBefore(operatorToken);
|
| 238 |
+
const rightToken = sourceCode.getTokenAfter(operatorToken);
|
| 239 |
+
|
| 240 |
+
if (
|
| 241 |
+
!sourceCode.isSpaceBetween(leftToken, operatorToken) ||
|
| 242 |
+
!sourceCode.isSpaceBetween(operatorToken, rightToken)
|
| 243 |
+
) {
|
| 244 |
+
report(node, operatorToken);
|
| 245 |
+
}
|
| 246 |
+
},
|
| 247 |
+
};
|
| 248 |
+
},
|
| 249 |
+
};
|
node_modules/eslint/lib/rules/space-unary-ops.js
ADDED
|
@@ -0,0 +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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview This rule should require or disallow spaces before or after unary operations.
|
| 3 |
+
* @author Marcin Kumorek
|
| 4 |
+
* @deprecated in ESLint v8.53.0
|
| 5 |
+
*/
|
| 6 |
+
"use strict";
|
| 7 |
+
|
| 8 |
+
//------------------------------------------------------------------------------
|
| 9 |
+
// Requirements
|
| 10 |
+
//------------------------------------------------------------------------------
|
| 11 |
+
|
| 12 |
+
const astUtils = require("./utils/ast-utils");
|
| 13 |
+
|
| 14 |
+
//------------------------------------------------------------------------------
|
| 15 |
+
// Rule Definition
|
| 16 |
+
//------------------------------------------------------------------------------
|
| 17 |
+
|
| 18 |
+
/** @type {import('../types').Rule.RuleModule} */
|
| 19 |
+
module.exports = {
|
| 20 |
+
meta: {
|
| 21 |
+
deprecated: {
|
| 22 |
+
message: "Formatting rules are being moved out of ESLint core.",
|
| 23 |
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
| 24 |
+
deprecatedSince: "8.53.0",
|
| 25 |
+
availableUntil: "11.0.0",
|
| 26 |
+
replacedBy: [
|
| 27 |
+
{
|
| 28 |
+
message:
|
| 29 |
+
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
| 30 |
+
url: "https://eslint.style/guide/migration",
|
| 31 |
+
plugin: {
|
| 32 |
+
name: "@stylistic/eslint-plugin",
|
| 33 |
+
url: "https://eslint.style",
|
| 34 |
+
},
|
| 35 |
+
rule: {
|
| 36 |
+
name: "space-unary-ops",
|
| 37 |
+
url: "https://eslint.style/rules/space-unary-ops",
|
| 38 |
+
},
|
| 39 |
+
},
|
| 40 |
+
],
|
| 41 |
+
},
|
| 42 |
+
type: "layout",
|
| 43 |
+
|
| 44 |
+
docs: {
|
| 45 |
+
description:
|
| 46 |
+
"Enforce consistent spacing before or after unary operators",
|
| 47 |
+
recommended: false,
|
| 48 |
+
url: "https://eslint.org/docs/latest/rules/space-unary-ops",
|
| 49 |
+
},
|
| 50 |
+
|
| 51 |
+
fixable: "whitespace",
|
| 52 |
+
|
| 53 |
+
schema: [
|
| 54 |
+
{
|
| 55 |
+
type: "object",
|
| 56 |
+
properties: {
|
| 57 |
+
words: {
|
| 58 |
+
type: "boolean",
|
| 59 |
+
default: true,
|
| 60 |
+
},
|
| 61 |
+
nonwords: {
|
| 62 |
+
type: "boolean",
|
| 63 |
+
default: false,
|
| 64 |
+
},
|
| 65 |
+
overrides: {
|
| 66 |
+
type: "object",
|
| 67 |
+
additionalProperties: {
|
| 68 |
+
type: "boolean",
|
| 69 |
+
},
|
| 70 |
+
},
|
| 71 |
+
},
|
| 72 |
+
additionalProperties: false,
|
| 73 |
+
},
|
| 74 |
+
],
|
| 75 |
+
messages: {
|
| 76 |
+
unexpectedBefore:
|
| 77 |
+
"Unexpected space before unary operator '{{operator}}'.",
|
| 78 |
+
unexpectedAfter:
|
| 79 |
+
"Unexpected space after unary operator '{{operator}}'.",
|
| 80 |
+
unexpectedAfterWord:
|
| 81 |
+
"Unexpected space after unary word operator '{{word}}'.",
|
| 82 |
+
wordOperator:
|
| 83 |
+
"Unary word operator '{{word}}' must be followed by whitespace.",
|
| 84 |
+
operator:
|
| 85 |
+
"Unary operator '{{operator}}' must be followed by whitespace.",
|
| 86 |
+
beforeUnaryExpressions:
|
| 87 |
+
"Space is required before unary expressions '{{token}}'.",
|
| 88 |
+
},
|
| 89 |
+
},
|
| 90 |
+
|
| 91 |
+
create(context) {
|
| 92 |
+
const options = context.options[0] || { words: true, nonwords: false };
|
| 93 |
+
|
| 94 |
+
const sourceCode = context.sourceCode;
|
| 95 |
+
|
| 96 |
+
//--------------------------------------------------------------------------
|
| 97 |
+
// Helpers
|
| 98 |
+
//--------------------------------------------------------------------------
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Check if the node is the first "!" in a "!!" convert to Boolean expression
|
| 102 |
+
* @param {ASTnode} node AST node
|
| 103 |
+
* @returns {boolean} Whether or not the node is first "!" in "!!"
|
| 104 |
+
*/
|
| 105 |
+
function isFirstBangInBangBangExpression(node) {
|
| 106 |
+
return (
|
| 107 |
+
node &&
|
| 108 |
+
node.type === "UnaryExpression" &&
|
| 109 |
+
node.argument.operator === "!" &&
|
| 110 |
+
node.argument &&
|
| 111 |
+
node.argument.type === "UnaryExpression" &&
|
| 112 |
+
node.argument.operator === "!"
|
| 113 |
+
);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Checks if an override exists for a given operator.
|
| 118 |
+
* @param {string} operator Operator
|
| 119 |
+
* @returns {boolean} Whether or not an override has been provided for the operator
|
| 120 |
+
*/
|
| 121 |
+
function overrideExistsForOperator(operator) {
|
| 122 |
+
return (
|
| 123 |
+
options.overrides && Object.hasOwn(options.overrides, operator)
|
| 124 |
+
);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Gets the value that the override was set to for this operator
|
| 129 |
+
* @param {string} operator Operator
|
| 130 |
+
* @returns {boolean} Whether or not an override enforces a space with this operator
|
| 131 |
+
*/
|
| 132 |
+
function overrideEnforcesSpaces(operator) {
|
| 133 |
+
return options.overrides[operator];
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* Verify Unary Word Operator has spaces after the word operator
|
| 138 |
+
* @param {ASTnode} node AST node
|
| 139 |
+
* @param {Object} firstToken first token from the AST node
|
| 140 |
+
* @param {Object} secondToken second token from the AST node
|
| 141 |
+
* @param {string} word The word to be used for reporting
|
| 142 |
+
* @returns {void}
|
| 143 |
+
*/
|
| 144 |
+
function verifyWordHasSpaces(node, firstToken, secondToken, word) {
|
| 145 |
+
if (secondToken.range[0] === firstToken.range[1]) {
|
| 146 |
+
context.report({
|
| 147 |
+
node,
|
| 148 |
+
messageId: "wordOperator",
|
| 149 |
+
data: {
|
| 150 |
+
word,
|
| 151 |
+
},
|
| 152 |
+
fix(fixer) {
|
| 153 |
+
return fixer.insertTextAfter(firstToken, " ");
|
| 154 |
+
},
|
| 155 |
+
});
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* Verify Unary Word Operator doesn't have spaces after the word operator
|
| 161 |
+
* @param {ASTnode} node AST node
|
| 162 |
+
* @param {Object} firstToken first token from the AST node
|
| 163 |
+
* @param {Object} secondToken second token from the AST node
|
| 164 |
+
* @param {string} word The word to be used for reporting
|
| 165 |
+
* @returns {void}
|
| 166 |
+
*/
|
| 167 |
+
function verifyWordDoesntHaveSpaces(
|
| 168 |
+
node,
|
| 169 |
+
firstToken,
|
| 170 |
+
secondToken,
|
| 171 |
+
word,
|
| 172 |
+
) {
|
| 173 |
+
if (astUtils.canTokensBeAdjacent(firstToken, secondToken)) {
|
| 174 |
+
if (secondToken.range[0] > firstToken.range[1]) {
|
| 175 |
+
context.report({
|
| 176 |
+
node,
|
| 177 |
+
messageId: "unexpectedAfterWord",
|
| 178 |
+
data: {
|
| 179 |
+
word,
|
| 180 |
+
},
|
| 181 |
+
fix(fixer) {
|
| 182 |
+
return fixer.removeRange([
|
| 183 |
+
firstToken.range[1],
|
| 184 |
+
secondToken.range[0],
|
| 185 |
+
]);
|
| 186 |
+
},
|
| 187 |
+
});
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/**
|
| 193 |
+
* Check Unary Word Operators for spaces after the word operator
|
| 194 |
+
* @param {ASTnode} node AST node
|
| 195 |
+
* @param {Object} firstToken first token from the AST node
|
| 196 |
+
* @param {Object} secondToken second token from the AST node
|
| 197 |
+
* @param {string} word The word to be used for reporting
|
| 198 |
+
* @returns {void}
|
| 199 |
+
*/
|
| 200 |
+
function checkUnaryWordOperatorForSpaces(
|
| 201 |
+
node,
|
| 202 |
+
firstToken,
|
| 203 |
+
secondToken,
|
| 204 |
+
word,
|
| 205 |
+
) {
|
| 206 |
+
if (overrideExistsForOperator(word)) {
|
| 207 |
+
if (overrideEnforcesSpaces(word)) {
|
| 208 |
+
verifyWordHasSpaces(node, firstToken, secondToken, word);
|
| 209 |
+
} else {
|
| 210 |
+
verifyWordDoesntHaveSpaces(
|
| 211 |
+
node,
|
| 212 |
+
firstToken,
|
| 213 |
+
secondToken,
|
| 214 |
+
word,
|
| 215 |
+
);
|
| 216 |
+
}
|
| 217 |
+
} else if (options.words) {
|
| 218 |
+
verifyWordHasSpaces(node, firstToken, secondToken, word);
|
| 219 |
+
} else {
|
| 220 |
+
verifyWordDoesntHaveSpaces(node, firstToken, secondToken, word);
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
/**
|
| 225 |
+
* Verifies YieldExpressions satisfy spacing requirements
|
| 226 |
+
* @param {ASTnode} node AST node
|
| 227 |
+
* @returns {void}
|
| 228 |
+
*/
|
| 229 |
+
function checkForSpacesAfterYield(node) {
|
| 230 |
+
const tokens = sourceCode.getFirstTokens(node, 3),
|
| 231 |
+
word = "yield";
|
| 232 |
+
|
| 233 |
+
if (!node.argument || node.delegate) {
|
| 234 |
+
return;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
checkUnaryWordOperatorForSpaces(node, tokens[0], tokens[1], word);
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/**
|
| 241 |
+
* Verifies AwaitExpressions satisfy spacing requirements
|
| 242 |
+
* @param {ASTNode} node AwaitExpression AST node
|
| 243 |
+
* @returns {void}
|
| 244 |
+
*/
|
| 245 |
+
function checkForSpacesAfterAwait(node) {
|
| 246 |
+
const tokens = sourceCode.getFirstTokens(node, 3);
|
| 247 |
+
|
| 248 |
+
checkUnaryWordOperatorForSpaces(
|
| 249 |
+
node,
|
| 250 |
+
tokens[0],
|
| 251 |
+
tokens[1],
|
| 252 |
+
"await",
|
| 253 |
+
);
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
/**
|
| 257 |
+
* Verifies UnaryExpression, UpdateExpression and NewExpression have spaces before or after the operator
|
| 258 |
+
* @param {ASTnode} node AST node
|
| 259 |
+
* @param {Object} firstToken First token in the expression
|
| 260 |
+
* @param {Object} secondToken Second token in the expression
|
| 261 |
+
* @returns {void}
|
| 262 |
+
*/
|
| 263 |
+
function verifyNonWordsHaveSpaces(node, firstToken, secondToken) {
|
| 264 |
+
if (node.prefix) {
|
| 265 |
+
if (isFirstBangInBangBangExpression(node)) {
|
| 266 |
+
return;
|
| 267 |
+
}
|
| 268 |
+
if (firstToken.range[1] === secondToken.range[0]) {
|
| 269 |
+
context.report({
|
| 270 |
+
node,
|
| 271 |
+
messageId: "operator",
|
| 272 |
+
data: {
|
| 273 |
+
operator: firstToken.value,
|
| 274 |
+
},
|
| 275 |
+
fix(fixer) {
|
| 276 |
+
return fixer.insertTextAfter(firstToken, " ");
|
| 277 |
+
},
|
| 278 |
+
});
|
| 279 |
+
}
|
| 280 |
+
} else {
|
| 281 |
+
if (firstToken.range[1] === secondToken.range[0]) {
|
| 282 |
+
context.report({
|
| 283 |
+
node,
|
| 284 |
+
messageId: "beforeUnaryExpressions",
|
| 285 |
+
data: {
|
| 286 |
+
token: secondToken.value,
|
| 287 |
+
},
|
| 288 |
+
fix(fixer) {
|
| 289 |
+
return fixer.insertTextBefore(secondToken, " ");
|
| 290 |
+
},
|
| 291 |
+
});
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
/**
|
| 297 |
+
* Verifies UnaryExpression, UpdateExpression and NewExpression don't have spaces before or after the operator
|
| 298 |
+
* @param {ASTnode} node AST node
|
| 299 |
+
* @param {Object} firstToken First token in the expression
|
| 300 |
+
* @param {Object} secondToken Second token in the expression
|
| 301 |
+
* @returns {void}
|
| 302 |
+
*/
|
| 303 |
+
function verifyNonWordsDontHaveSpaces(node, firstToken, secondToken) {
|
| 304 |
+
if (node.prefix) {
|
| 305 |
+
if (secondToken.range[0] > firstToken.range[1]) {
|
| 306 |
+
context.report({
|
| 307 |
+
node,
|
| 308 |
+
messageId: "unexpectedAfter",
|
| 309 |
+
data: {
|
| 310 |
+
operator: firstToken.value,
|
| 311 |
+
},
|
| 312 |
+
fix(fixer) {
|
| 313 |
+
if (
|
| 314 |
+
astUtils.canTokensBeAdjacent(
|
| 315 |
+
firstToken,
|
| 316 |
+
secondToken,
|
| 317 |
+
)
|
| 318 |
+
) {
|
| 319 |
+
return fixer.removeRange([
|
| 320 |
+
firstToken.range[1],
|
| 321 |
+
secondToken.range[0],
|
| 322 |
+
]);
|
| 323 |
+
}
|
| 324 |
+
return null;
|
| 325 |
+
},
|
| 326 |
+
});
|
| 327 |
+
}
|
| 328 |
+
} else {
|
| 329 |
+
if (secondToken.range[0] > firstToken.range[1]) {
|
| 330 |
+
context.report({
|
| 331 |
+
node,
|
| 332 |
+
messageId: "unexpectedBefore",
|
| 333 |
+
data: {
|
| 334 |
+
operator: secondToken.value,
|
| 335 |
+
},
|
| 336 |
+
fix(fixer) {
|
| 337 |
+
return fixer.removeRange([
|
| 338 |
+
firstToken.range[1],
|
| 339 |
+
secondToken.range[0],
|
| 340 |
+
]);
|
| 341 |
+
},
|
| 342 |
+
});
|
| 343 |
+
}
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
/**
|
| 348 |
+
* Verifies UnaryExpression, UpdateExpression and NewExpression satisfy spacing requirements
|
| 349 |
+
* @param {ASTnode} node AST node
|
| 350 |
+
* @returns {void}
|
| 351 |
+
*/
|
| 352 |
+
function checkForSpaces(node) {
|
| 353 |
+
const tokens =
|
| 354 |
+
node.type === "UpdateExpression" && !node.prefix
|
| 355 |
+
? sourceCode.getLastTokens(node, 2)
|
| 356 |
+
: sourceCode.getFirstTokens(node, 2);
|
| 357 |
+
const firstToken = tokens[0];
|
| 358 |
+
const secondToken = tokens[1];
|
| 359 |
+
|
| 360 |
+
if (
|
| 361 |
+
(node.type === "NewExpression" || node.prefix) &&
|
| 362 |
+
firstToken.type === "Keyword"
|
| 363 |
+
) {
|
| 364 |
+
checkUnaryWordOperatorForSpaces(
|
| 365 |
+
node,
|
| 366 |
+
firstToken,
|
| 367 |
+
secondToken,
|
| 368 |
+
firstToken.value,
|
| 369 |
+
);
|
| 370 |
+
return;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
const operator = node.prefix ? tokens[0].value : tokens[1].value;
|
| 374 |
+
|
| 375 |
+
if (overrideExistsForOperator(operator)) {
|
| 376 |
+
if (overrideEnforcesSpaces(operator)) {
|
| 377 |
+
verifyNonWordsHaveSpaces(node, firstToken, secondToken);
|
| 378 |
+
} else {
|
| 379 |
+
verifyNonWordsDontHaveSpaces(node, firstToken, secondToken);
|
| 380 |
+
}
|
| 381 |
+
} else if (options.nonwords) {
|
| 382 |
+
verifyNonWordsHaveSpaces(node, firstToken, secondToken);
|
| 383 |
+
} else {
|
| 384 |
+
verifyNonWordsDontHaveSpaces(node, firstToken, secondToken);
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
//--------------------------------------------------------------------------
|
| 389 |
+
// Public
|
| 390 |
+
//--------------------------------------------------------------------------
|
| 391 |
+
|
| 392 |
+
return {
|
| 393 |
+
UnaryExpression: checkForSpaces,
|
| 394 |
+
UpdateExpression: checkForSpaces,
|
| 395 |
+
NewExpression: checkForSpaces,
|
| 396 |
+
YieldExpression: checkForSpacesAfterYield,
|
| 397 |
+
AwaitExpression: checkForSpacesA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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview Source code for spaced-comments rule
|
| 3 |
+
* @author Gyandeep Singh
|
| 4 |
+
* @deprecated in ESLint v8.53.0
|
| 5 |
+
*/
|
| 6 |
+
"use strict";
|
| 7 |
+
|
| 8 |
+
const escapeRegExp = require("escape-string-regexp");
|
| 9 |
+
const astUtils = require("./utils/ast-utils");
|
| 10 |
+
|
| 11 |
+
//------------------------------------------------------------------------------
|
| 12 |
+
// Helpers
|
| 13 |
+
//------------------------------------------------------------------------------
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* Escapes the control characters of a given string.
|
| 17 |
+
* @param {string} s A string to escape.
|
| 18 |
+
* @returns {string} An escaped string.
|
| 19 |
+
*/
|
| 20 |
+
function escape(s) {
|
| 21 |
+
return `(?:${escapeRegExp(s)})`;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Escapes the control characters of a given string.
|
| 26 |
+
* And adds a repeat flag.
|
| 27 |
+
* @param {string} s A string to escape.
|
| 28 |
+
* @returns {string} An escaped string.
|
| 29 |
+
*/
|
| 30 |
+
function escapeAndRepeat(s) {
|
| 31 |
+
return `${escape(s)}+`;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Parses `markers` option.
|
| 36 |
+
* If markers don't include `"*"`, this adds `"*"` to allow JSDoc comments.
|
| 37 |
+
* @param {string[]} [markers] A marker list.
|
| 38 |
+
* @returns {string[]} A marker list.
|
| 39 |
+
*/
|
| 40 |
+
function parseMarkersOption(markers) {
|
| 41 |
+
// `*` is a marker for JSDoc comments.
|
| 42 |
+
if (!markers.includes("*")) {
|
| 43 |
+
return markers.concat("*");
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return markers;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Creates string pattern for exceptions.
|
| 51 |
+
* Generated pattern:
|
| 52 |
+
*
|
| 53 |
+
* 1. A space or an exception pattern sequence.
|
| 54 |
+
* @param {string[]} exceptions An exception pattern list.
|
| 55 |
+
* @returns {string} A regular expression string for exceptions.
|
| 56 |
+
*/
|
| 57 |
+
function createExceptionsPattern(exceptions) {
|
| 58 |
+
let pattern = "";
|
| 59 |
+
|
| 60 |
+
/*
|
| 61 |
+
* A space or an exception pattern sequence.
|
| 62 |
+
* [] ==> "\s"
|
| 63 |
+
* ["-"] ==> "(?:\s|\-+$)"
|
| 64 |
+
* ["-", "="] ==> "(?:\s|(?:\-+|=+)$)"
|
| 65 |
+
* ["-", "=", "--=="] ==> "(?:\s|(?:\-+|=+|(?:\-\-==)+)$)" ==> https://jex.im/regulex/#!embed=false&flags=&re=(%3F%3A%5Cs%7C(%3F%3A%5C-%2B%7C%3D%2B%7C(%3F%3A%5C-%5C-%3D%3D)%2B)%24)
|
| 66 |
+
*/
|
| 67 |
+
if (exceptions.length === 0) {
|
| 68 |
+
// a space.
|
| 69 |
+
pattern += "\\s";
|
| 70 |
+
} else {
|
| 71 |
+
// a space or...
|
| 72 |
+
pattern += "(?:\\s|";
|
| 73 |
+
|
| 74 |
+
if (exceptions.length === 1) {
|
| 75 |
+
// a sequence of the exception pattern.
|
| 76 |
+
pattern += escapeAndRepeat(exceptions[0]);
|
| 77 |
+
} else {
|
| 78 |
+
// a sequence of one of the exception patterns.
|
| 79 |
+
pattern += "(?:";
|
| 80 |
+
pattern += exceptions.map(escapeAndRepeat).join("|");
|
| 81 |
+
pattern += ")";
|
| 82 |
+
}
|
| 83 |
+
pattern += `(?:$|[${Array.from(astUtils.LINEBREAKS).join("")}]))`;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
return pattern;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* Creates RegExp object for `always` mode.
|
| 91 |
+
* Generated pattern for beginning of comment:
|
| 92 |
+
*
|
| 93 |
+
* 1. First, a marker or nothing.
|
| 94 |
+
* 2. Next, a space or an exception pattern sequence.
|
| 95 |
+
* @param {string[]} markers A marker list.
|
| 96 |
+
* @param {string[]} exceptions An exception pattern list.
|
| 97 |
+
* @returns {RegExp} A RegExp object for the beginning of a comment in `always` mode.
|
| 98 |
+
*/
|
| 99 |
+
function createAlwaysStylePattern(markers, exceptions) {
|
| 100 |
+
let pattern = "^";
|
| 101 |
+
|
| 102 |
+
/*
|
| 103 |
+
* A marker or nothing.
|
| 104 |
+
* ["*"] ==> "\*?"
|
| 105 |
+
* ["*", "!"] ==> "(?:\*|!)?"
|
| 106 |
+
* ["*", "/", "!<"] ==> "(?:\*|\/|(?:!<))?" ==> https://jex.im/regulex/#!embed=false&flags=&re=(%3F%3A%5C*%7C%5C%2F%7C(%3F%3A!%3C))%3F
|
| 107 |
+
*/
|
| 108 |
+
if (markers.length === 1) {
|
| 109 |
+
// the marker.
|
| 110 |
+
pattern += escape(markers[0]);
|
| 111 |
+
} else {
|
| 112 |
+
// one of markers.
|
| 113 |
+
pattern += "(?:";
|
| 114 |
+
pattern += markers.map(escape).join("|");
|
| 115 |
+
pattern += ")";
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
pattern += "?"; // or nothing.
|
| 119 |
+
pattern += createExceptionsPattern(exceptions);
|
| 120 |
+
|
| 121 |
+
return new RegExp(pattern, "u");
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Creates RegExp object for `never` mode.
|
| 126 |
+
* Generated pattern for beginning of comment:
|
| 127 |
+
*
|
| 128 |
+
* 1. First, a marker or nothing (captured).
|
| 129 |
+
* 2. Next, a space or a tab.
|
| 130 |
+
* @param {string[]} markers A marker list.
|
| 131 |
+
* @returns {RegExp} A RegExp object for `never` mode.
|
| 132 |
+
*/
|
| 133 |
+
function createNeverStylePattern(markers) {
|
| 134 |
+
const pattern = `^(${markers.map(escape).join("|")})?[ \t]+`;
|
| 135 |
+
|
| 136 |
+
return new RegExp(pattern, "u");
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
//------------------------------------------------------------------------------
|
| 140 |
+
// Rule Definition
|
| 141 |
+
//------------------------------------------------------------------------------
|
| 142 |
+
|
| 143 |
+
/** @type {import('../types').Rule.RuleModule} */
|
| 144 |
+
module.exports = {
|
| 145 |
+
meta: {
|
| 146 |
+
deprecated: {
|
| 147 |
+
message: "Formatting rules are being moved out of ESLint core.",
|
| 148 |
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
| 149 |
+
deprecatedSince: "8.53.0",
|
| 150 |
+
availableUntil: "11.0.0",
|
| 151 |
+
replacedBy: [
|
| 152 |
+
{
|
| 153 |
+
message:
|
| 154 |
+
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
| 155 |
+
url: "https://eslint.style/guide/migration",
|
| 156 |
+
plugin: {
|
| 157 |
+
name: "@stylistic/eslint-plugin",
|
| 158 |
+
url: "https://eslint.style",
|
| 159 |
+
},
|
| 160 |
+
rule: {
|
| 161 |
+
name: "spaced-comment",
|
| 162 |
+
url: "https://eslint.style/rules/spaced-comment",
|
| 163 |
+
},
|
| 164 |
+
},
|
| 165 |
+
],
|
| 166 |
+
},
|
| 167 |
+
type: "suggestion",
|
| 168 |
+
|
| 169 |
+
docs: {
|
| 170 |
+
description:
|
| 171 |
+
"Enforce consistent spacing after the `//` or `/*` in a comment",
|
| 172 |
+
recommended: false,
|
| 173 |
+
url: "https://eslint.org/docs/latest/rules/spaced-comment",
|
| 174 |
+
},
|
| 175 |
+
|
| 176 |
+
fixable: "whitespace",
|
| 177 |
+
|
| 178 |
+
schema: [
|
| 179 |
+
{
|
| 180 |
+
enum: ["always", "never"],
|
| 181 |
+
},
|
| 182 |
+
{
|
| 183 |
+
type: "object",
|
| 184 |
+
properties: {
|
| 185 |
+
exceptions: {
|
| 186 |
+
type: "array",
|
| 187 |
+
items: {
|
| 188 |
+
type: "string",
|
| 189 |
+
},
|
| 190 |
+
},
|
| 191 |
+
markers: {
|
| 192 |
+
type: "array",
|
| 193 |
+
items: {
|
| 194 |
+
type: "string",
|
| 195 |
+
},
|
| 196 |
+
},
|
| 197 |
+
line: {
|
| 198 |
+
type: "object",
|
| 199 |
+
properties: {
|
| 200 |
+
exceptions: {
|
| 201 |
+
type: "array",
|
| 202 |
+
items: {
|
| 203 |
+
type: "string",
|
| 204 |
+
},
|
| 205 |
+
},
|
| 206 |
+
markers: {
|
| 207 |
+
type: "array",
|
| 208 |
+
items: {
|
| 209 |
+
type: "string",
|
| 210 |
+
},
|
| 211 |
+
},
|
| 212 |
+
},
|
| 213 |
+
additionalProperties: false,
|
| 214 |
+
},
|
| 215 |
+
block: {
|
| 216 |
+
type: "object",
|
| 217 |
+
properties: {
|
| 218 |
+
exceptions: {
|
| 219 |
+
type: "array",
|
| 220 |
+
items: {
|
| 221 |
+
type: "string",
|
| 222 |
+
},
|
| 223 |
+
},
|
| 224 |
+
markers: {
|
| 225 |
+
type: "array",
|
| 226 |
+
items: {
|
| 227 |
+
type: "string",
|
| 228 |
+
},
|
| 229 |
+
},
|
| 230 |
+
balanced: {
|
| 231 |
+
type: "boolean",
|
| 232 |
+
default: false,
|
| 233 |
+
},
|
| 234 |
+
},
|
| 235 |
+
additionalProperties: false,
|
| 236 |
+
},
|
| 237 |
+
},
|
| 238 |
+
additionalProperties: false,
|
| 239 |
+
},
|
| 240 |
+
],
|
| 241 |
+
|
| 242 |
+
messages: {
|
| 243 |
+
unexpectedSpaceAfterMarker:
|
| 244 |
+
"Unexpected space or tab after marker ({{refChar}}) in comment.",
|
| 245 |
+
expectedExceptionAfter:
|
| 246 |
+
"Expected exception block, space or tab after '{{refChar}}' in comment.",
|
| 247 |
+
unexpectedSpaceBefore:
|
| 248 |
+
"Unexpected space or tab before '*/' in comment.",
|
| 249 |
+
unexpectedSpaceAfter:
|
| 250 |
+
"Unexpected space or tab after '{{refChar}}' in comment.",
|
| 251 |
+
expectedSpaceBefore:
|
| 252 |
+
"Expected space or tab before '*/' in comment.",
|
| 253 |
+
expectedSpaceAfter:
|
| 254 |
+
"Expected space or tab after '{{refChar}}' in comment.",
|
| 255 |
+
},
|
| 256 |
+
},
|
| 257 |
+
|
| 258 |
+
create(context) {
|
| 259 |
+
const sourceCode = context.sourceCode;
|
| 260 |
+
|
| 261 |
+
// Unless the first option is never, require a space
|
| 262 |
+
const requireSpace = context.options[0] !== "never";
|
| 263 |
+
|
| 264 |
+
/*
|
| 265 |
+
* Parse the second options.
|
| 266 |
+
* If markers don't include `"*"`, it's added automatically for JSDoc
|
| 267 |
+
* comments.
|
| 268 |
+
*/
|
| 269 |
+
const config = context.options[1] || {};
|
| 270 |
+
const balanced = config.block && config.block.balanced;
|
| 271 |
+
|
| 272 |
+
const styleRules = ["block", "line"].reduce((rule, type) => {
|
| 273 |
+
const markers = parseMarkersOption(
|
| 274 |
+
(config[type] && config[type].markers) || config.markers || [],
|
| 275 |
+
);
|
| 276 |
+
const exceptions =
|
| 277 |
+
(config[type] && config[type].exceptions) ||
|
| 278 |
+
config.exceptions ||
|
| 279 |
+
[];
|
| 280 |
+
const endNeverPattern = "[ \t]+$";
|
| 281 |
+
|
| 282 |
+
// Create RegExp object for valid patterns.
|
| 283 |
+
rule[type] = {
|
| 284 |
+
beginRegex: requireSpace
|
| 285 |
+
? createAlwaysStylePattern(markers, exceptions)
|
| 286 |
+
: createNeverStylePattern(markers),
|
| 287 |
+
endRegex:
|
| 288 |
+
balanced && requireSpace
|
| 289 |
+
? new RegExp(
|
| 290 |
+
`${createExceptionsPattern(exceptions)}$`,
|
| 291 |
+
"u",
|
| 292 |
+
)
|
| 293 |
+
: new RegExp(endNeverPattern, "u"),
|
| 294 |
+
hasExceptions: exceptions.length > 0,
|
| 295 |
+
captureMarker: new RegExp(
|
| 296 |
+
`^(${markers.map(escape).join("|")})`,
|
| 297 |
+
"u",
|
| 298 |
+
),
|
| 299 |
+
markers: new Set(markers),
|
| 300 |
+
};
|
| 301 |
+
|
| 302 |
+
return rule;
|
| 303 |
+
}, {});
|
| 304 |
+
|
| 305 |
+
/**
|
| 306 |
+
* Reports a beginning spacing error with an appropriate message.
|
| 307 |
+
* @param {ASTNode} node A comment node to check.
|
| 308 |
+
* @param {string} messageId An error message to report.
|
| 309 |
+
* @param {Array} match An array of match results for markers.
|
| 310 |
+
* @param {string} refChar Character used for reference in the error message.
|
| 311 |
+
* @returns {void}
|
| 312 |
+
*/
|
| 313 |
+
function reportBegin(node, messageId, match, refChar) {
|
| 314 |
+
const type = node.type.toLowerCase(),
|
| 315 |
+
commentIdentifier = type === "block" ? "/*" : "//";
|
| 316 |
+
|
| 317 |
+
context.report({
|
| 318 |
+
node,
|
| 319 |
+
fix(fixer) {
|
| 320 |
+
const start = node.range[0];
|
| 321 |
+
let end = start + 2;
|
| 322 |
+
|
| 323 |
+
if (requireSpace) {
|
| 324 |
+
if (match) {
|
| 325 |
+
end += match[0].length;
|
| 326 |
+
}
|
| 327 |
+
return fixer.insertTextAfterRange([start, end], " ");
|
| 328 |
+
}
|
| 329 |
+
end += match[0].length;
|
| 330 |
+
return fixer.replaceTextRange(
|
| 331 |
+
[start, end],
|
| 332 |
+
commentIdentifier + (match[1] ? match[1] : ""),
|
| 333 |
+
);
|
| 334 |
+
},
|
| 335 |
+
messageId,
|
| 336 |
+
data: { refChar },
|
| 337 |
+
});
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
/**
|
| 341 |
+
* Reports an ending spacing error with an appropriate message.
|
| 342 |
+
* @param {ASTNode} node A comment node to check.
|
| 343 |
+
* @param {string} messageId An error message to report.
|
| 344 |
+
* @param {string} match An array of the matched whitespace characters.
|
| 345 |
+
* @returns {void}
|
| 346 |
+
*/
|
| 347 |
+
function reportEnd(node, messageId, match) {
|
| 348 |
+
context.report({
|
| 349 |
+
node,
|
| 350 |
+
fix(fixer) {
|
| 351 |
+
if (requireSpace) {
|
| 352 |
+
return fixer.insertTextAfterRange(
|
| 353 |
+
[node.range[0], node.range[1] - 2],
|
| 354 |
+
" ",
|
| 355 |
+
);
|
| 356 |
+
}
|
| 357 |
+
const end = node.range[1] - 2,
|
| 358 |
+
start = end - match[0].length;
|
| 359 |
+
|
| 360 |
+
return fixer.replaceTextRange([start, end], "");
|
| 361 |
+
},
|
| 362 |
+
messageId,
|
| 363 |
+
});
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
/**
|
| 367 |
+
* Reports a given comment if it's invalid.
|
| 368 |
+
* @param {ASTNode} node a comment node to check.
|
| 369 |
+
* @returns {void}
|
| 370 |
+
*/
|
| 371 |
+
function checkCommentForSpace(node) {
|
| 372 |
+
const type = node.type.toLowerCase(),
|
| 373 |
+
rule = styleRules[type],
|
| 374 |
+
commentIdentifier = type === "block" ? "/*" : "//";
|
| 375 |
+
|
| 376 |
+
// Ignores empty comments and comments that consist only of a marker.
|
| 377 |
+
if (node.value.length === 0 || rule.markers.has(node.value)) {
|
| 378 |
+
return;
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
const beginMatch = rule.beginRegex.exec(node.value);
|
| 382 |
+
const endMatch = rule.endRegex.exec(node.value);
|
| 383 |
+
|
| 384 |
+
// Checks.
|
| 385 |
+
if (requireSpace) {
|
| 386 |
+
if (!beginMatch) {
|
| 387 |
+
const hasMarker = rule.captureMarker.exec(node.value);
|
| 388 |
+
const marker = hasMarker
|
| 389 |
+
? commentIdentifier + hasMarker[0]
|
| 390 |
+
: commentIdentifier;
|
| 391 |
+
|
| 392 |
+
if (rule.hasExceptions) {
|
| 393 |
+
reportBegin(
|
| 394 |
+
node,
|
| 395 |
+
"expectedExceptionAfter",
|
| 396 |
+
hasMarker,
|
| 397 |
+
marker,
|
| 398 |
+
);
|
| 399 |
+
} else {
|
| 400 |
+
reportBegin(
|
| 401 |
+
node,
|
| 402 |
+
"expectedSpaceAfter",
|
| 403 |
+
hasMarker,
|
| 404 |
+
marker,
|
| 405 |
+
);
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
if (balanced && type === "block" && !endMatch) {
|
| 410 |
+
reportEnd(node, "expectedSpaceBefore");
|
| 411 |
+
}
|
| 412 |
+
} else {
|
| 413 |
+
if (beginMatch) {
|
| 414 |
+
if (!beginMatch[1]) {
|
| 415 |
+
reportBegin(
|
| 416 |
+
node,
|
| 417 |
+
"unexpectedSpaceAfter",
|
| 418 |
+
beginMatch,
|
| 419 |
+
commentIdentifier,
|
| 420 |
+
);
|
| 421 |
+
} else {
|
| 422 |
+
reportBegin(
|
| 423 |
+
node,
|
| 424 |
+
"unexpectedSpaceAfterMarker",
|
| 425 |
+
beginMatch,
|
| 426 |
+
beginMatch[1],
|
| 427 |
+
);
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
if (balanced && type === "block" && endMatch) {
|
| 432 |
+
reportEnd(node, "unexpectedSpaceBefore", endMatch);
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
return {
|
| 438 |
+
Program() {
|
| 439 |
+
const comments = sourceCode.getAllComments();
|
| 440 |
+
|
| 441 |
+
comments
|
| 442 |
+
.filter(token => token.type !== "Shebang")
|
| 443 |
+
.forEach(checkCommentForSpace);
|
| 444 |
+
},
|
| 445 |
+
};
|
| 446 |
+
},
|
| 447 |
+
};
|
node_modules/eslint/lib/rules/strict.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview Rule to control usage of strict mode directives.
|
| 3 |
+
* @author Brandon Mills
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
"use strict";
|
| 7 |
+
|
| 8 |
+
//------------------------------------------------------------------------------
|
| 9 |
+
// Requirements
|
| 10 |
+
//------------------------------------------------------------------------------
|
| 11 |
+
|
| 12 |
+
const astUtils = require("./utils/ast-utils");
|
| 13 |
+
|
| 14 |
+
//------------------------------------------------------------------------------
|
| 15 |
+
// Helpers
|
| 16 |
+
//------------------------------------------------------------------------------
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Gets all of the Use Strict Directives in the Directive Prologue of a group of
|
| 20 |
+
* statements.
|
| 21 |
+
* @param {ASTNode[]} statements Statements in the program or function body.
|
| 22 |
+
* @returns {ASTNode[]} All of the Use Strict Directives.
|
| 23 |
+
*/
|
| 24 |
+
function getUseStrictDirectives(statements) {
|
| 25 |
+
const directives = [];
|
| 26 |
+
|
| 27 |
+
for (let i = 0; i < statements.length; i++) {
|
| 28 |
+
const statement = statements[i];
|
| 29 |
+
|
| 30 |
+
if (
|
| 31 |
+
statement.type === "ExpressionStatement" &&
|
| 32 |
+
statement.expression.type === "Literal" &&
|
| 33 |
+
statement.expression.value === "use strict"
|
| 34 |
+
) {
|
| 35 |
+
directives[i] = statement;
|
| 36 |
+
} else {
|
| 37 |
+
break;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
return directives;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Checks whether a given parameter is a simple parameter.
|
| 46 |
+
* @param {ASTNode} node A pattern node to check.
|
| 47 |
+
* @returns {boolean} `true` if the node is an Identifier node.
|
| 48 |
+
*/
|
| 49 |
+
function isSimpleParameter(node) {
|
| 50 |
+
return node.type === "Identifier";
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Checks whether a given parameter list is a simple parameter list.
|
| 55 |
+
* @param {ASTNode[]} params A parameter list to check.
|
| 56 |
+
* @returns {boolean} `true` if the every parameter is an Identifier node.
|
| 57 |
+
*/
|
| 58 |
+
function isSimpleParameterList(params) {
|
| 59 |
+
return params.every(isSimpleParameter);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
//------------------------------------------------------------------------------
|
| 63 |
+
// Rule Definition
|
| 64 |
+
//------------------------------------------------------------------------------
|
| 65 |
+
|
| 66 |
+
/** @type {import('../types').Rule.RuleModule} */
|
| 67 |
+
module.exports = {
|
| 68 |
+
meta: {
|
| 69 |
+
type: "suggestion",
|
| 70 |
+
|
| 71 |
+
defaultOptions: ["safe"],
|
| 72 |
+
|
| 73 |
+
docs: {
|
| 74 |
+
description: "Require or disallow strict mode directives",
|
| 75 |
+
recommended: false,
|
| 76 |
+
url: "https://eslint.org/docs/latest/rules/strict",
|
| 77 |
+
},
|
| 78 |
+
|
| 79 |
+
schema: [
|
| 80 |
+
{
|
| 81 |
+
enum: ["never", "global", "function", "safe"],
|
| 82 |
+
},
|
| 83 |
+
],
|
| 84 |
+
|
| 85 |
+
fixable: "code",
|
| 86 |
+
messages: {
|
| 87 |
+
function: "Use the function form of 'use strict'.",
|
| 88 |
+
global: "Use the global form of 'use strict'.",
|
| 89 |
+
multiple: "Multiple 'use strict' directives.",
|
| 90 |
+
never: "Strict mode is not permitted.",
|
| 91 |
+
unnecessary: "Unnecessary 'use strict' directive.",
|
| 92 |
+
module: "'use strict' is unnecessary inside of modules.",
|
| 93 |
+
implied:
|
| 94 |
+
"'use strict' is unnecessary when implied strict mode is enabled.",
|
| 95 |
+
unnecessaryInClasses:
|
| 96 |
+
"'use strict' is unnecessary inside of classes.",
|
| 97 |
+
nonSimpleParameterList:
|
| 98 |
+
"'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016.",
|
| 99 |
+
wrap: "Wrap {{name}} in a function with 'use strict' directive.",
|
| 100 |
+
},
|
| 101 |
+
},
|
| 102 |
+
|
| 103 |
+
create(context) {
|
| 104 |
+
const ecmaFeatures =
|
| 105 |
+
context.languageOptions.parserOptions.ecmaFeatures || {},
|
| 106 |
+
scopes = [],
|
| 107 |
+
classScopes = [];
|
| 108 |
+
let [mode] = context.options;
|
| 109 |
+
|
| 110 |
+
if (ecmaFeatures.impliedStrict) {
|
| 111 |
+
mode = "implied";
|
| 112 |
+
} else if (mode === "safe") {
|
| 113 |
+
mode =
|
| 114 |
+
ecmaFeatures.globalReturn ||
|
| 115 |
+
context.languageOptions.sourceType === "commonjs"
|
| 116 |
+
? "global"
|
| 117 |
+
: "function";
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* Determines whether a reported error should be fixed, depending on the error type.
|
| 122 |
+
* @param {string} errorType The type of error
|
| 123 |
+
* @returns {boolean} `true` if the reported error should be fixed
|
| 124 |
+
*/
|
| 125 |
+
function shouldFix(errorType) {
|
| 126 |
+
return (
|
| 127 |
+
errorType === "multiple" ||
|
| 128 |
+
errorType === "unnecessary" ||
|
| 129 |
+
errorType === "module" ||
|
| 130 |
+
errorType === "implied" ||
|
| 131 |
+
errorType === "unnecessaryInClasses"
|
| 132 |
+
);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/**
|
| 136 |
+
* Gets a fixer function to remove a given 'use strict' directive.
|
| 137 |
+
* @param {ASTNode} node The directive that should be removed
|
| 138 |
+
* @returns {Function} A fixer function
|
| 139 |
+
*/
|
| 140 |
+
function getFixFunction(node) {
|
| 141 |
+
return fixer => fixer.remove(node);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Report a slice of an array of nodes with a given message.
|
| 146 |
+
* @param {ASTNode[]} nodes Nodes.
|
| 147 |
+
* @param {string} start Index to start from.
|
| 148 |
+
* @param {string} end Index to end before.
|
| 149 |
+
* @param {string} messageId Message to display.
|
| 150 |
+
* @param {boolean} fix `true` if the directive should be fixed (i.e. removed)
|
| 151 |
+
* @returns {void}
|
| 152 |
+
*/
|
| 153 |
+
function reportSlice(nodes, start, end, messageId, fix) {
|
| 154 |
+
nodes.slice(start, end).forEach(node => {
|
| 155 |
+
context.report({
|
| 156 |
+
node,
|
| 157 |
+
messageId,
|
| 158 |
+
fix: fix ? getFixFunction(node) : null,
|
| 159 |
+
});
|
| 160 |
+
});
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/**
|
| 164 |
+
* Report all nodes in an array with a given message.
|
| 165 |
+
* @param {ASTNode[]} nodes Nodes.
|
| 166 |
+
* @param {string} messageId Message id to display.
|
| 167 |
+
* @param {boolean} fix `true` if the directive should be fixed (i.e. removed)
|
| 168 |
+
* @returns {void}
|
| 169 |
+
*/
|
| 170 |
+
function reportAll(nodes, messageId, fix) {
|
| 171 |
+
reportSlice(nodes, 0, nodes.length, messageId, fix);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/**
|
| 175 |
+
* Report all nodes in an array, except the first, with a given message.
|
| 176 |
+
* @param {ASTNode[]} nodes Nodes.
|
| 177 |
+
* @param {string} messageId Message id to display.
|
| 178 |
+
* @param {boolean} fix `true` if the directive should be fixed (i.e. removed)
|
| 179 |
+
* @returns {void}
|
| 180 |
+
*/
|
| 181 |
+
function reportAllExceptFirst(nodes, messageId, fix) {
|
| 182 |
+
reportSlice(nodes, 1, nodes.length, messageId, fix);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/**
|
| 186 |
+
* Entering a function in 'function' mode pushes a new nested scope onto the
|
| 187 |
+
* stack. The new scope is true if the nested function is strict mode code.
|
| 188 |
+
* @param {ASTNode} node The function declaration or expression.
|
| 189 |
+
* @param {ASTNode[]} useStrictDirectives The Use Strict Directives of the node.
|
| 190 |
+
* @returns {void}
|
| 191 |
+
*/
|
| 192 |
+
function enterFunctionInFunctionMode(node, useStrictDirectives) {
|
| 193 |
+
const isInClass = classScopes.length > 0,
|
| 194 |
+
isParentGlobal =
|
| 195 |
+
scopes.length === 0 && classScopes.length === 0,
|
| 196 |
+
isParentStrict = scopes.length > 0 && scopes.at(-1),
|
| 197 |
+
isStrict = useStrictDirectives.length > 0;
|
| 198 |
+
|
| 199 |
+
if (isStrict) {
|
| 200 |
+
if (!isSimpleParameterList(node.params)) {
|
| 201 |
+
context.report({
|
| 202 |
+
node: useStrictDirectives[0],
|
| 203 |
+
messageId: "nonSimpleParameterList",
|
| 204 |
+
});
|
| 205 |
+
} else if (isParentStrict) {
|
| 206 |
+
context.report({
|
| 207 |
+
node: useStrictDirectives[0],
|
| 208 |
+
messageId: "unnecessary",
|
| 209 |
+
fix: getFixFunction(useStrictDirectives[0]),
|
| 210 |
+
});
|
| 211 |
+
} else if (isInClass) {
|
| 212 |
+
context.report({
|
| 213 |
+
node: useStrictDirectives[0],
|
| 214 |
+
messageId: "unnecessaryInClasses",
|
| 215 |
+
fix: getFixFunction(useStrictDirectives[0]),
|
| 216 |
+
});
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
reportAllExceptFirst(useStrictDirectives, "multiple", true);
|
| 220 |
+
} else if (isParentGlobal) {
|
| 221 |
+
if (isSimpleParameterList(node.params)) {
|
| 222 |
+
context.report({ node, messageId: "function" });
|
| 223 |
+
} else {
|
| 224 |
+
context.report({
|
| 225 |
+
node,
|
| 226 |
+
messageId: "wrap",
|
| 227 |
+
data: { name: astUtils.getFunctionNameWithKind(node) },
|
| 228 |
+
});
|
| 229 |
+
}
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
scopes.push(isParentStrict || isStrict);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
/**
|
| 236 |
+
* Exiting a function in 'function' mode pops its scope off the stack.
|
| 237 |
+
* @returns {void}
|
| 238 |
+
*/
|
| 239 |
+
function exitFunctionInFunctionMode() {
|
| 240 |
+
scopes.pop();
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
/**
|
| 244 |
+
* Enter a function and either:
|
| 245 |
+
* - Push a new nested scope onto the stack (in 'function' mode).
|
| 246 |
+
* - Report all the Use Strict Directives (in the other modes).
|
| 247 |
+
* @param {ASTNode} node The function declaration or expression.
|
| 248 |
+
* @returns {void}
|
| 249 |
+
*/
|
| 250 |
+
function enterFunction(node) {
|
| 251 |
+
const isBlock = node.body.type === "BlockStatement",
|
| 252 |
+
useStrictDirectives = isBlock
|
| 253 |
+
? getUseStrictDirectives(node.body.body)
|
| 254 |
+
: [];
|
| 255 |
+
|
| 256 |
+
if (mode === "function") {
|
| 257 |
+
enterFunctionInFunctionMode(node, useStrictDirectives);
|
| 258 |
+
} else if (useStrictDirectives.length > 0) {
|
| 259 |
+
if (isSimpleParameterList(node.params)) {
|
| 260 |
+
reportAll(useStrictDirectives, mode, shouldFix(mode));
|
| 261 |
+
} else {
|
| 262 |
+
context.report({
|
| 263 |
+
node: useStrictDirectives[0],
|
| 264 |
+
messageId: "nonSimpleParameterList",
|
| 265 |
+
});
|
| 266 |
+
reportAllExceptFirst(useStrictDirectives, "multiple", true);
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
/** @type {import('../types').Rule.RuleListener} */
|
| 272 |
+
const rule = {
|
| 273 |
+
Program(node) {
|
| 274 |
+
const useStrictDirectives = getUseStrictDirectives(node.body);
|
| 275 |
+
|
| 276 |
+
if (node.sourceType === "module") {
|
| 277 |
+
mode = "module";
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
if (mode === "global") {
|
| 281 |
+
if (
|
| 282 |
+
node.body.length > 0 &&
|
| 283 |
+
useStrictDirectives.length === 0
|
| 284 |
+
) {
|
| 285 |
+
/*
|
| 286 |
+
* Report the range as v9 does
|
| 287 |
+
*/
|
| 288 |
+
context.report({
|
| 289 |
+
loc: {
|
| 290 |
+
start: node.body[0].loc.start,
|
| 291 |
+
end: node.body.at(-1).loc.end,
|
| 292 |
+
},
|
| 293 |
+
messageId: "global",
|
| 294 |
+
});
|
| 295 |
+
}
|
| 296 |
+
reportAllExceptFirst(useStrictDirectives, "multiple", true);
|
| 297 |
+
} else {
|
| 298 |
+
reportAll(useStrictDirectives, mode, shouldFix(mode));
|
| 299 |
+
}
|
| 300 |
+
},
|
| 301 |
+
FunctionDeclaration: enterFunction,
|
| 302 |
+
FunctionExpression: enterFunction,
|
| 303 |
+
ArrowFunctionExpression: enterFunction,
|
| 304 |
+
};
|
| 305 |
+
|
| 306 |
+
if (mode === "function") {
|
| 307 |
+
Object.assign(rule, {
|
| 308 |
+
// Inside of class bodies are always strict mode.
|
| 309 |
+
ClassBody() {
|
| 310 |
+
classScopes.push(true);
|
| 311 |
+
},
|
| 312 |
+
"ClassBody:exit"() {
|
| 313 |
+
classScopes.pop();
|
| 314 |
+
},
|
| 315 |
+
|
| 316 |
+
"FunctionDeclaration:exit": exitFunctionInFunctionMode,
|
| 317 |
+
"FunctionExpression:exit": exitFunctionInFunctionMode,
|
| 318 |
+
"ArrowFunctionExpression:exit": exitFunctionInFunctionMode,
|
| 319 |
+
});
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
return rule;
|
| 323 |
+
},
|
| 324 |
+
};
|
node_modules/eslint/lib/rules/switch-colon-spacing.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview Rule to enforce spacing around colons of switch statements.
|
| 3 |
+
* @author Toru Nagashima
|
| 4 |
+
* @deprecated in ESLint v8.53.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
"use strict";
|
| 8 |
+
|
| 9 |
+
//------------------------------------------------------------------------------
|
| 10 |
+
// Requirements
|
| 11 |
+
//------------------------------------------------------------------------------
|
| 12 |
+
|
| 13 |
+
const astUtils = require("./utils/ast-utils");
|
| 14 |
+
|
| 15 |
+
//------------------------------------------------------------------------------
|
| 16 |
+
// Rule Definition
|
| 17 |
+
//------------------------------------------------------------------------------
|
| 18 |
+
|
| 19 |
+
/** @type {import('../types').Rule.RuleModule} */
|
| 20 |
+
module.exports = {
|
| 21 |
+
meta: {
|
| 22 |
+
deprecated: {
|
| 23 |
+
message: "Formatting rules are being moved out of ESLint core.",
|
| 24 |
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
| 25 |
+
deprecatedSince: "8.53.0",
|
| 26 |
+
availableUntil: "11.0.0",
|
| 27 |
+
replacedBy: [
|
| 28 |
+
{
|
| 29 |
+
message:
|
| 30 |
+
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
| 31 |
+
url: "https://eslint.style/guide/migration",
|
| 32 |
+
plugin: {
|
| 33 |
+
name: "@stylistic/eslint-plugin",
|
| 34 |
+
url: "https://eslint.style",
|
| 35 |
+
},
|
| 36 |
+
rule: {
|
| 37 |
+
name: "switch-colon-spacing",
|
| 38 |
+
url: "https://eslint.style/rules/switch-colon-spacing",
|
| 39 |
+
},
|
| 40 |
+
},
|
| 41 |
+
],
|
| 42 |
+
},
|
| 43 |
+
type: "layout",
|
| 44 |
+
|
| 45 |
+
docs: {
|
| 46 |
+
description: "Enforce spacing around colons of switch statements",
|
| 47 |
+
recommended: false,
|
| 48 |
+
url: "https://eslint.org/docs/latest/rules/switch-colon-spacing",
|
| 49 |
+
},
|
| 50 |
+
|
| 51 |
+
schema: [
|
| 52 |
+
{
|
| 53 |
+
type: "object",
|
| 54 |
+
properties: {
|
| 55 |
+
before: { type: "boolean", default: false },
|
| 56 |
+
after: { type: "boolean", default: true },
|
| 57 |
+
},
|
| 58 |
+
additionalProperties: false,
|
| 59 |
+
},
|
| 60 |
+
],
|
| 61 |
+
fixable: "whitespace",
|
| 62 |
+
messages: {
|
| 63 |
+
expectedBefore: "Expected space(s) before this colon.",
|
| 64 |
+
expectedAfter: "Expected space(s) after this colon.",
|
| 65 |
+
unexpectedBefore: "Unexpected space(s) before this colon.",
|
| 66 |
+
unexpectedAfter: "Unexpected space(s) after this colon.",
|
| 67 |
+
},
|
| 68 |
+
},
|
| 69 |
+
|
| 70 |
+
create(context) {
|
| 71 |
+
const sourceCode = context.sourceCode;
|
| 72 |
+
const options = context.options[0] || {};
|
| 73 |
+
const beforeSpacing = options.before === true; // false by default
|
| 74 |
+
const afterSpacing = options.after !== false; // true by default
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Check whether the spacing between the given 2 tokens is valid or not.
|
| 78 |
+
* @param {Token} left The left token to check.
|
| 79 |
+
* @param {Token} right The right token to check.
|
| 80 |
+
* @param {boolean} expected The expected spacing to check. `true` if there should be a space.
|
| 81 |
+
* @returns {boolean} `true` if the spacing between the tokens is valid.
|
| 82 |
+
*/
|
| 83 |
+
function isValidSpacing(left, right, expected) {
|
| 84 |
+
return (
|
| 85 |
+
astUtils.isClosingBraceToken(right) ||
|
| 86 |
+
!astUtils.isTokenOnSameLine(left, right) ||
|
| 87 |
+
sourceCode.isSpaceBetween(left, right) === expected
|
| 88 |
+
);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* Check whether comments exist between the given 2 tokens.
|
| 93 |
+
* @param {Token} left The left token to check.
|
| 94 |
+
* @param {Token} right The right token to check.
|
| 95 |
+
* @returns {boolean} `true` if comments exist between the given 2 tokens.
|
| 96 |
+
*/
|
| 97 |
+
function commentsExistBetween(left, right) {
|
| 98 |
+
return (
|
| 99 |
+
sourceCode.getFirstTokenBetween(left, right, {
|
| 100 |
+
includeComments: true,
|
| 101 |
+
filter: astUtils.isCommentToken,
|
| 102 |
+
}) !== null
|
| 103 |
+
);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/**
|
| 107 |
+
* Fix the spacing between the given 2 tokens.
|
| 108 |
+
* @param {RuleFixer} fixer The fixer to fix.
|
| 109 |
+
* @param {Token} left The left token of fix range.
|
| 110 |
+
* @param {Token} right The right token of fix range.
|
| 111 |
+
* @param {boolean} spacing The spacing style. `true` if there should be a space.
|
| 112 |
+
* @returns {Fix|null} The fix object.
|
| 113 |
+
*/
|
| 114 |
+
function fix(fixer, left, right, spacing) {
|
| 115 |
+
if (commentsExistBetween(left, right)) {
|
| 116 |
+
return null;
|
| 117 |
+
}
|
| 118 |
+
if (spacing) {
|
| 119 |
+
return fixer.insertTextAfter(left, " ");
|
| 120 |
+
}
|
| 121 |
+
return fixer.removeRange([left.range[1], right.range[0]]);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
return {
|
| 125 |
+
SwitchCase(node) {
|
| 126 |
+
const colonToken = astUtils.getSwitchCaseColonToken(
|
| 127 |
+
node,
|
| 128 |
+
sourceCode,
|
| 129 |
+
);
|
| 130 |
+
const beforeToken = sourceCode.getTokenBefore(colonToken);
|
| 131 |
+
const afterToken = sourceCode.getTokenAfter(colonToken);
|
| 132 |
+
|
| 133 |
+
if (!isValidSpacing(beforeToken, colonToken, beforeSpacing)) {
|
| 134 |
+
context.report({
|
| 135 |
+
node,
|
| 136 |
+
loc: colonToken.loc,
|
| 137 |
+
messageId: beforeSpacing
|
| 138 |
+
? "expectedBefore"
|
| 139 |
+
: "unexpectedBefore",
|
| 140 |
+
fix: fixer =>
|
| 141 |
+
fix(fixer, beforeToken, colonToken, beforeSpacing),
|
| 142 |
+
});
|
| 143 |
+
}
|
| 144 |
+
if (!isValidSpacing(colonToken, afterToken, afterSpacing)) {
|
| 145 |
+
context.report({
|
| 146 |
+
node,
|
| 147 |
+
loc: colonToken.loc,
|
| 148 |
+
messageId: afterSpacing
|
| 149 |
+
? "expectedAfter"
|
| 150 |
+
: "unexpectedAfter",
|
| 151 |
+
fix: fixer =>
|
| 152 |
+
fix(fixer, colonToken, afterToken, afterSpacing),
|
| 153 |
+
});
|
| 154 |
+
}
|
| 155 |
+
},
|
| 156 |
+
};
|
| 157 |
+
},
|
| 158 |
+
};
|
node_modules/eslint/lib/rules/symbol-description.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview Rule to enforce description with the `Symbol` object
|
| 3 |
+
* @author Jarek Rencz
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
"use strict";
|
| 7 |
+
|
| 8 |
+
//------------------------------------------------------------------------------
|
| 9 |
+
// Requirements
|
| 10 |
+
//------------------------------------------------------------------------------
|
| 11 |
+
|
| 12 |
+
const astUtils = require("./utils/ast-utils");
|
| 13 |
+
|
| 14 |
+
//------------------------------------------------------------------------------
|
| 15 |
+
// Rule Definition
|
| 16 |
+
//------------------------------------------------------------------------------
|
| 17 |
+
|
| 18 |
+
/** @type {import('../types').Rule.RuleModule} */
|
| 19 |
+
module.exports = {
|
| 20 |
+
meta: {
|
| 21 |
+
type: "suggestion",
|
| 22 |
+
|
| 23 |
+
docs: {
|
| 24 |
+
description: "Require symbol descriptions",
|
| 25 |
+
recommended: false,
|
| 26 |
+
url: "https://eslint.org/docs/latest/rules/symbol-description",
|
| 27 |
+
},
|
| 28 |
+
fixable: null,
|
| 29 |
+
schema: [],
|
| 30 |
+
messages: {
|
| 31 |
+
expected: "Expected Symbol to have a description.",
|
| 32 |
+
},
|
| 33 |
+
},
|
| 34 |
+
|
| 35 |
+
create(context) {
|
| 36 |
+
const sourceCode = context.sourceCode;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Reports if node does not conform the rule in case rule is set to
|
| 40 |
+
* report missing description
|
| 41 |
+
* @param {ASTNode} node A CallExpression node to check.
|
| 42 |
+
* @returns {void}
|
| 43 |
+
*/
|
| 44 |
+
function checkArgument(node) {
|
| 45 |
+
if (node.arguments.length === 0) {
|
| 46 |
+
context.report({
|
| 47 |
+
node,
|
| 48 |
+
messageId: "expected",
|
| 49 |
+
});
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
return {
|
| 54 |
+
"Program:exit"(node) {
|
| 55 |
+
const scope = sourceCode.getScope(node);
|
| 56 |
+
const variable = astUtils.getVariableByName(scope, "Symbol");
|
| 57 |
+
|
| 58 |
+
if (variable && variable.defs.length === 0) {
|
| 59 |
+
variable.references.forEach(reference => {
|
| 60 |
+
const idNode = reference.identifier;
|
| 61 |
+
|
| 62 |
+
if (astUtils.isCallee(idNode)) {
|
| 63 |
+
checkArgument(idNode.parent);
|
| 64 |
+
}
|
| 65 |
+
});
|
| 66 |
+
}
|
| 67 |
+
},
|
| 68 |
+
};
|
| 69 |
+
},
|
| 70 |
+
};
|
node_modules/eslint/lib/rules/template-curly-spacing.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @fileoverview Rule to enforce spacing around embedded expressions of template strings
|
| 3 |
+
* @author Toru Nagashima
|
| 4 |
+
* @deprecated in ESLint v8.53.0
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
"use strict";
|
| 8 |
+
|
| 9 |
+
//------------------------------------------------------------------------------
|
| 10 |
+
// Requirements
|
| 11 |
+
//------------------------------------------------------------------------------
|
| 12 |
+
|
| 13 |
+
const astUtils = require("./utils/ast-utils");
|
| 14 |
+
|
| 15 |
+
//------------------------------------------------------------------------------
|
| 16 |
+
// Rule Definition
|
| 17 |
+
//------------------------------------------------------------------------------
|
| 18 |
+
|
| 19 |
+
/** @type {import('../types').Rule.RuleModule} */
|
| 20 |
+
module.exports = {
|
| 21 |
+
meta: {
|
| 22 |
+
deprecated: {
|
| 23 |
+
message: "Formatting rules are being moved out of ESLint core.",
|
| 24 |
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
| 25 |
+
deprecatedSince: "8.53.0",
|
| 26 |
+
availableUntil: "11.0.0",
|
| 27 |
+
replacedBy: [
|
| 28 |
+
{
|
| 29 |
+
message:
|
| 30 |
+
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
| 31 |
+
url: "https://eslint.style/guide/migration",
|
| 32 |
+
plugin: {
|
| 33 |
+
name: "@stylistic/eslint-plugin",
|
| 34 |
+
url: "https://eslint.style",
|
| 35 |
+
},
|
| 36 |
+
rule: {
|
| 37 |
+
name: "template-curly-spacing",
|
| 38 |
+
url: "https://eslint.style/rules/template-curly-spacing",
|
| 39 |
+
},
|
| 40 |
+
},
|
| 41 |
+
],
|
| 42 |
+
},
|
| 43 |
+
type: "layout",
|
| 44 |
+
|
| 45 |
+
docs: {
|
| 46 |
+
description:
|
| 47 |
+
"Require or disallow spacing around embedded expressions of template strings",
|
| 48 |
+
recommended: false,
|
| 49 |
+
url: "https://eslint.org/docs/latest/rules/template-curly-spacing",
|
| 50 |
+
},
|
| 51 |
+
|
| 52 |
+
fixable: "whitespace",
|
| 53 |
+
|
| 54 |
+
schema: [{ enum: ["always", "never"] }],
|
| 55 |
+
messages: {
|
| 56 |
+
expectedBefore: "Expected space(s) before '}'.",
|
| 57 |
+
expectedAfter: "Expected space(s) after '${'.",
|
| 58 |
+
unexpectedBefore: "Unexpected space(s) before '}'.",
|
| 59 |
+
unexpectedAfter: "Unexpected space(s) after '${'.",
|
| 60 |
+
},
|
| 61 |
+
},
|
| 62 |
+
|
| 63 |
+
create(context) {
|
| 64 |
+
const sourceCode = context.sourceCode;
|
| 65 |
+
const always = context.options[0] === "always";
|
| 66 |
+
|
| 67 |
+
/**
|
| 68 |
+
* Checks spacing before `}` of a given token.
|
| 69 |
+
* @param {Token} token A token to check. This is a Template token.
|
| 70 |
+
* @returns {void}
|
| 71 |
+
*/
|
| 72 |
+
function checkSpacingBefore(token) {
|
| 73 |
+
if (!token.value.startsWith("}")) {
|
| 74 |
+
return; // starts with a backtick, this is the first template element in the template literal
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
const prevToken = sourceCode.getTokenBefore(token, {
|
| 78 |
+
includeComments: true,
|
| 79 |
+
}),
|
| 80 |
+
hasSpace = sourceCode.isSpaceBetween(prevToken, token);
|
| 81 |
+
|
| 82 |
+
if (!astUtils.isTokenOnSameLine(prevToken, token)) {
|
| 83 |
+
return;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
if (always && !hasSpace) {
|
| 87 |
+
context.report({
|
| 88 |
+
loc: {
|
| 89 |
+
start: token.loc.start,
|
| 90 |
+
end: {
|
| 91 |
+
line: token.loc.start.line,
|
| 92 |
+
column: token.loc.start.column + 1,
|
| 93 |
+
},
|
| 94 |
+
},
|
| 95 |
+
messageId: "expectedBefore",
|
| 96 |
+
fix: fixer => fixer.insertTextBefore(token, " "),
|
| 97 |
+
});
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
if (!always && hasSpace) {
|
| 101 |
+
context.report({
|
| 102 |
+
loc: {
|
| 103 |
+
start: prevToken.loc.end,
|
| 104 |
+
end: token.loc.start,
|
| 105 |
+
},
|
| 106 |
+
messageId: "unexpectedBefore",
|
| 107 |
+
fix: fixer =>
|
| 108 |
+
fixer.removeRange([prevToken.range[1], token.range[0]]),
|
| 109 |
+
});
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Checks spacing after `${` of a given token.
|
| 115 |
+
* @param {Token} token A token to check. This is a Template token.
|
| 116 |
+
* @returns {void}
|
| 117 |
+
*/
|
| 118 |
+
function checkSpacingAfter(token) {
|
| 119 |
+
if (!token.value.endsWith("${")) {
|
| 120 |
+
return; // ends with a backtick, this is the last template element in the template literal
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
const nextToken = sourceCode.getTokenAfter(token, {
|
| 124 |
+
includeComments: true,
|
| 125 |
+
}),
|
| 126 |
+
hasSpace = sourceCode.isSpaceBetween(token, nextToken);
|
| 127 |
+
|
| 128 |
+
if (!astUtils.isTokenOnSameLine(token, nextToken)) {
|
| 129 |
+
return;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
if (always && !hasSpace) {
|
| 133 |
+
context.report({
|
| 134 |
+
loc: {
|
| 135 |
+
start: {
|
| 136 |
+
line: token.loc.end.line,
|
| 137 |
+
column: token.loc.end.column - 2,
|
| 138 |
+
},
|
| 139 |
+
end: token.loc.end,
|
| 140 |
+
},
|
| 141 |
+
messageId: "expectedAfter",
|
| 142 |
+
fix: fixer => fixer.insertTextAfter(token, " "),
|
| 143 |
+
});
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
if (!always && hasSpace) {
|
| 147 |
+
context.report({
|
| 148 |
+
loc: {
|
| 149 |
+
start: token.loc.end,
|
| 150 |
+
end: nextToken.loc.start,
|
| 151 |
+
},
|
| 152 |
+
messageId: "unexpectedAfter",
|
| 153 |
+
fix: fixer =>
|
| 154 |
+
fixer.removeRange([token.range[1], nextToken.range[0]]),
|
| 155 |
+
});
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
return {
|
| 160 |
+
TemplateElement(node) {
|
| 161 |
+
const token = sourceCode.getFirstToken(node);
|
| 162 |
+
|
| 163 |
+
checkSpacingBefore(token);
|
| 164 |
+
checkSpacingAfter(token);
|
| 165 |
+
},
|
| 166 |
+
};
|
| 167 |
+
},
|
| 168 |
+
};
|