mirror of
https://github.com/github/codeql-action.git
synced 2025-12-30 03:00:13 +08:00
Bump packages to fix linter
This commit is contained in:
2214
node_modules/eslint-plugin-github/node_modules/@typescript-eslint/eslint-plugin/CHANGELOG.md
generated
vendored
2214
node_modules/eslint-plugin-github/node_modules/@typescript-eslint/eslint-plugin/CHANGELOG.md
generated
vendored
File diff suppressed because it is too large
Load Diff
21
node_modules/eslint-plugin-github/node_modules/@typescript-eslint/eslint-plugin/LICENSE
generated
vendored
21
node_modules/eslint-plugin-github/node_modules/@typescript-eslint/eslint-plugin/LICENSE
generated
vendored
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 TypeScript ESLint and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
239
node_modules/eslint-plugin-github/node_modules/@typescript-eslint/eslint-plugin/README.md
generated
vendored
239
node_modules/eslint-plugin-github/node_modules/@typescript-eslint/eslint-plugin/README.md
generated
vendored
@@ -1,239 +0,0 @@
|
||||
<h1 align="center">ESLint Plugin TypeScript</h1>
|
||||
|
||||
<p align="center">An ESLint plugin which provides lint rules for TypeScript codebases.</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://github.com/typescript-eslint/typescript-eslint/workflows/CI/badge.svg" alt="CI" />
|
||||
<a href="https://www.npmjs.com/package/@typescript-eslint/eslint-plugin"><img src="https://img.shields.io/npm/v/@typescript-eslint/eslint-plugin.svg?style=flat-square" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/package/@typescript-eslint/eslint-plugin"><img src="https://img.shields.io/npm/dm/@typescript-eslint/eslint-plugin.svg?style=flat-square" alt="NPM Downloads" /></a>
|
||||
</p>
|
||||
|
||||
## Getting Started
|
||||
|
||||
- **[You can find our Getting Started docs here](../../docs/getting-started/linting/README.md)**
|
||||
- **[You can find our FAQ / Troubleshooting docs here](../../docs/getting-started/linting/FAQ.md)**
|
||||
|
||||
These docs walk you through setting up ESLint, this plugin, and our parser. If you know what you're doing and just want to quick start, read on...
|
||||
|
||||
## Quick-start
|
||||
|
||||
### Installation
|
||||
|
||||
Make sure you have TypeScript and [`@typescript-eslint/parser`](../parser) installed:
|
||||
|
||||
```bash
|
||||
$ yarn add -D typescript @typescript-eslint/parser
|
||||
$ npm i --save-dev typescript @typescript-eslint/parser
|
||||
```
|
||||
|
||||
Then install the plugin:
|
||||
|
||||
```bash
|
||||
$ yarn add -D @typescript-eslint/eslint-plugin
|
||||
$ npm i --save-dev @typescript-eslint/eslint-plugin
|
||||
```
|
||||
|
||||
It is important that you use the same version number for `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin`.
|
||||
|
||||
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `@typescript-eslint/eslint-plugin` globally.
|
||||
|
||||
### Usage
|
||||
|
||||
Add `@typescript-eslint/parser` to the `parser` field and `@typescript-eslint` to the plugins section of your `.eslintrc` configuration file, then configure the rules you want to use under the rules section.
|
||||
|
||||
```json
|
||||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"rules": {
|
||||
"@typescript-eslint/rule-name": "error"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can also enable all the recommended rules for our plugin. Add `plugin:@typescript-eslint/recommended` in extends:
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": ["plugin:@typescript-eslint/recommended"]
|
||||
}
|
||||
```
|
||||
|
||||
**Note: Make sure to use `eslint --ext .js,.ts` since by [default](https://eslint.org/docs/user-guide/command-line-interface#--ext) `eslint` will only search for `.js` files.**
|
||||
|
||||
### Recommended Configs
|
||||
|
||||
You can also use [`eslint:recommended`](https://eslint.org/docs/rules/) (the set of rules which are recommended for all projects by the ESLint Team) with this plugin:
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"]
|
||||
}
|
||||
```
|
||||
|
||||
As of version 2 of this plugin, _by design_, none of the rules in the main `recommended` config require type-checking in order to run. This means that they are more lightweight and faster to run.
|
||||
|
||||
Some highly valuable rules simply require type-checking in order to be implemented correctly, however, so we provide an additional config you can extend from called `recommended-requiring-type-checking`. You would apply this _in addition_ to the recommended configs previously mentioned, e.g.:
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Pro Tip: For larger codebases you may want to consider splitting our linting into two separate stages: 1. fast feedback rules which operate purely based on syntax (no type-checking), 2. rules which are based on semantics (type-checking).
|
||||
|
||||
**[You can read more about linting with type information here](../../docs/getting-started/linting/TYPED_LINTING.md)**
|
||||
|
||||
## Supported Rules
|
||||
|
||||
<!-- begin base rule list -->
|
||||
|
||||
**Key**: :white_check_mark: = recommended, :wrench: = fixable, :thought_balloon: = requires type information
|
||||
|
||||
| Name | Description | :white_check_mark: | :wrench: | :thought_balloon: |
|
||||
| ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------ | -------- | ----------------- |
|
||||
| [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Requires using either `T[]` or `Array<T>` for arrays | | :wrench: | |
|
||||
| [`@typescript-eslint/await-thenable`](./docs/rules/await-thenable.md) | Disallows awaiting a value that is not a Thenable | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/ban-ts-comment`](./docs/rules/ban-ts-comment.md) | Bans `@ts-<directive>` comments from being used or requires descriptions after directive | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/ban-tslint-comment`](./docs/rules/ban-tslint-comment.md) | Bans `// tslint:<rule-flag>` comments from being used | | :wrench: | |
|
||||
| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Bans specific types from being used | :white_check_mark: | :wrench: | |
|
||||
| [`@typescript-eslint/class-literal-property-style`](./docs/rules/class-literal-property-style.md) | Ensures that literals on classes are exposed in a consistent style | | :wrench: | |
|
||||
| [`@typescript-eslint/consistent-indexed-object-style`](./docs/rules/consistent-indexed-object-style.md) | Enforce or disallow the use of the record type | | :wrench: | |
|
||||
| [`@typescript-eslint/consistent-type-assertions`](./docs/rules/consistent-type-assertions.md) | Enforces consistent usage of type assertions | | | |
|
||||
| [`@typescript-eslint/consistent-type-definitions`](./docs/rules/consistent-type-definitions.md) | Consistent with type definition either `interface` or `type` | | :wrench: | |
|
||||
| [`@typescript-eslint/consistent-type-imports`](./docs/rules/consistent-type-imports.md) | Enforces consistent usage of type imports | | :wrench: | |
|
||||
| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | | | |
|
||||
| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods | | :wrench: | |
|
||||
| [`@typescript-eslint/explicit-module-boundary-types`](./docs/rules/explicit-module-boundary-types.md) | Require explicit return and argument types on exported functions' and classes' public class methods | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | | :wrench: | |
|
||||
| [`@typescript-eslint/member-ordering`](./docs/rules/member-ordering.md) | Require a consistent member declaration order | | | |
|
||||
| [`@typescript-eslint/method-signature-style`](./docs/rules/method-signature-style.md) | Enforces using a particular method signature syntax. | | :wrench: | |
|
||||
| [`@typescript-eslint/naming-convention`](./docs/rules/naming-convention.md) | Enforces naming conventions for everything across a codebase | | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-base-to-string`](./docs/rules/no-base-to-string.md) | Requires that `.toString()` is only called on objects which provide useful information when stringified | | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-confusing-non-null-assertion`](./docs/rules/no-confusing-non-null-assertion.md) | Disallow non-null assertion in locations that may be confusing | | :wrench: | |
|
||||
| [`@typescript-eslint/no-confusing-void-expression`](./docs/rules/no-confusing-void-expression.md) | Requires expressions of type void to appear in statement position | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-dynamic-delete`](./docs/rules/no-dynamic-delete.md) | Disallow the delete operator with computed key expressions | | :wrench: | |
|
||||
| [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces | :white_check_mark: | :wrench: | |
|
||||
| [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type | :white_check_mark: | :wrench: | |
|
||||
| [`@typescript-eslint/no-extra-non-null-assertion`](./docs/rules/no-extra-non-null-assertion.md) | Disallow extra non-null assertion | :white_check_mark: | :wrench: | |
|
||||
| [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Forbids the use of classes as namespaces | | | |
|
||||
| [`@typescript-eslint/no-floating-promises`](./docs/rules/no-floating-promises.md) | Requires Promise-like values to be handled appropriately | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-for-in-array`](./docs/rules/no-for-in-array.md) | Disallow iterating over an array with a for-in loop | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-implicit-any-catch`](./docs/rules/no-implicit-any-catch.md) | Disallow usage of the implicit `any` type in catch clauses | | :wrench: | |
|
||||
| [`@typescript-eslint/no-inferrable-types`](./docs/rules/no-inferrable-types.md) | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean | :white_check_mark: | :wrench: | |
|
||||
| [`@typescript-eslint/no-invalid-void-type`](./docs/rules/no-invalid-void-type.md) | Disallows usage of `void` type outside of generic or return types | | | |
|
||||
| [`@typescript-eslint/no-meaningless-void-operator`](./docs/rules/no-meaningless-void-operator.md) | Disallow the `void` operator except when used to discard a value | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-misused-new`](./docs/rules/no-misused-new.md) | Enforce valid definition of `new` and `constructor` | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/no-misused-promises`](./docs/rules/no-misused-promises.md) | Avoid using promises in places not designed to handle them | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-namespace`](./docs/rules/no-namespace.md) | Disallow the use of custom TypeScript modules and namespaces | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/no-non-null-asserted-nullish-coalescing`](./docs/rules/no-non-null-asserted-nullish-coalescing.md) | Disallows using a non-null assertion in the left operand of the nullish coalescing operator | | | |
|
||||
| [`@typescript-eslint/no-non-null-asserted-optional-chain`](./docs/rules/no-non-null-asserted-optional-chain.md) | Disallows using a non-null assertion after an optional chain expression | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/no-non-null-assertion`](./docs/rules/no-non-null-assertion.md) | Disallows non-null assertions using the `!` postfix operator | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/no-parameter-properties`](./docs/rules/no-parameter-properties.md) | Disallow the use of parameter properties in class constructors | | | |
|
||||
| [`@typescript-eslint/no-require-imports`](./docs/rules/no-require-imports.md) | Disallows invocation of `require()` | | | |
|
||||
| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases | | | |
|
||||
| [`@typescript-eslint/no-unnecessary-boolean-literal-compare`](./docs/rules/no-unnecessary-boolean-literal-compare.md) | Flags unnecessary equality comparisons against boolean literals | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unnecessary-condition`](./docs/rules/no-unnecessary-condition.md) | Prevents conditionals where the type is always truthy or always falsy | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unnecessary-qualifier`](./docs/rules/no-unnecessary-qualifier.md) | Warns when a namespace qualifier is unnecessary | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unnecessary-type-arguments`](./docs/rules/no-unnecessary-type-arguments.md) | Enforces that type arguments will not be used if not required | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unnecessary-type-assertion`](./docs/rules/no-unnecessary-type-assertion.md) | Warns if a type assertion does not change the type of an expression | :white_check_mark: | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unnecessary-type-constraint`](./docs/rules/no-unnecessary-type-constraint.md) | Disallows unnecessary constraints on generic types | | :wrench: | |
|
||||
| [`@typescript-eslint/no-unsafe-argument`](./docs/rules/no-unsafe-argument.md) | Disallows calling a function with an any type value | | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unsafe-assignment`](./docs/rules/no-unsafe-assignment.md) | Disallows assigning any to variables and properties | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unsafe-call`](./docs/rules/no-unsafe-call.md) | Disallows calling an any type value | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unsafe-member-access`](./docs/rules/no-unsafe-member-access.md) | Disallows member access on any typed variables | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unsafe-return`](./docs/rules/no-unsafe-return.md) | Disallows returning any from a function | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/non-nullable-type-assertion-style`](./docs/rules/non-nullable-type-assertion-style.md) | Prefers a non-null assertion over explicit type cast when possible | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/prefer-as-const`](./docs/rules/prefer-as-const.md) | Prefer usage of `as const` over literal type | :white_check_mark: | :wrench: | |
|
||||
| [`@typescript-eslint/prefer-enum-initializers`](./docs/rules/prefer-enum-initializers.md) | Prefer initializing each enums member value | | | |
|
||||
| [`@typescript-eslint/prefer-for-of`](./docs/rules/prefer-for-of.md) | Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated | | | |
|
||||
| [`@typescript-eslint/prefer-function-type`](./docs/rules/prefer-function-type.md) | Use function types instead of interfaces with call signatures | | :wrench: | |
|
||||
| [`@typescript-eslint/prefer-includes`](./docs/rules/prefer-includes.md) | Enforce `includes` method over `indexOf` method | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/prefer-literal-enum-member`](./docs/rules/prefer-literal-enum-member.md) | Require that all enum members be literal values to prevent unintended enum member name shadow issues | | | |
|
||||
| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules | :white_check_mark: | :wrench: | |
|
||||
| [`@typescript-eslint/prefer-nullish-coalescing`](./docs/rules/prefer-nullish-coalescing.md) | Enforce the usage of the nullish coalescing operator instead of logical chaining | | | :thought_balloon: |
|
||||
| [`@typescript-eslint/prefer-optional-chain`](./docs/rules/prefer-optional-chain.md) | Prefer using concise optional chain expressions instead of chained logical ands | | | |
|
||||
| [`@typescript-eslint/prefer-readonly`](./docs/rules/prefer-readonly.md) | Requires that private members are marked as `readonly` if they're never modified outside of the constructor | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/prefer-readonly-parameter-types`](./docs/rules/prefer-readonly-parameter-types.md) | Requires that function parameters are typed as readonly to prevent accidental mutation of inputs | | | :thought_balloon: |
|
||||
| [`@typescript-eslint/prefer-reduce-type-parameter`](./docs/rules/prefer-reduce-type-parameter.md) | Prefer using type parameter when calling `Array#reduce` instead of casting | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/prefer-regexp-exec`](./docs/rules/prefer-regexp-exec.md) | Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided | :white_check_mark: | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/prefer-return-this-type`](./docs/rules/prefer-return-this-type.md) | Enforce that `this` is used when only `this` type is returned | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/prefer-string-starts-ends-with`](./docs/rules/prefer-string-starts-ends-with.md) | Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/prefer-ts-expect-error`](./docs/rules/prefer-ts-expect-error.md) | Recommends using `@ts-expect-error` over `@ts-ignore` | | :wrench: | |
|
||||
| [`@typescript-eslint/promise-function-async`](./docs/rules/promise-function-async.md) | Requires any function or method that returns a Promise to be marked async | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/require-array-sort-compare`](./docs/rules/require-array-sort-compare.md) | Requires `Array#sort` calls to always provide a `compareFunction` | | | :thought_balloon: |
|
||||
| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/restrict-template-expressions`](./docs/rules/restrict-template-expressions.md) | Enforce template literal expressions to be of string type | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/sort-type-union-intersection-members`](./docs/rules/sort-type-union-intersection-members.md) | Enforces that members of a type union/intersection are sorted alphabetically | | :wrench: | |
|
||||
| [`@typescript-eslint/strict-boolean-expressions`](./docs/rules/strict-boolean-expressions.md) | Restricts the types allowed in boolean expressions | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/switch-exhaustiveness-check`](./docs/rules/switch-exhaustiveness-check.md) | Exhaustiveness checking in switch with union type | | | :thought_balloon: |
|
||||
| [`@typescript-eslint/triple-slash-reference`](./docs/rules/triple-slash-reference.md) | Sets preference level for triple slash directives versus ES6-style import declarations | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations | | :wrench: | |
|
||||
| [`@typescript-eslint/typedef`](./docs/rules/typedef.md) | Requires type annotations to exist | | | |
|
||||
| [`@typescript-eslint/unbound-method`](./docs/rules/unbound-method.md) | Enforces unbound methods are called with their expected scope | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/unified-signatures`](./docs/rules/unified-signatures.md) | Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter | | | |
|
||||
|
||||
<!-- end base rule list -->
|
||||
|
||||
### Extension Rules
|
||||
|
||||
In some cases, ESLint provides a rule itself, but it doesn't support TypeScript syntax; either it crashes, or it ignores the syntax, or it falsely reports against it.
|
||||
In these cases, we create what we call an extension rule; a rule within our plugin that has the same functionality, but also supports TypeScript.
|
||||
|
||||
<!-- begin extension rule list -->
|
||||
|
||||
**Key**: :white_check_mark: = recommended, :wrench: = fixable, :thought_balloon: = requires type information
|
||||
|
||||
| Name | Description | :white_check_mark: | :wrench: | :thought_balloon: |
|
||||
| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------ | -------- | ----------------- |
|
||||
| [`@typescript-eslint/brace-style`](./docs/rules/brace-style.md) | Enforce consistent brace style for blocks | | :wrench: | |
|
||||
| [`@typescript-eslint/comma-dangle`](./docs/rules/comma-dangle.md) | Require or disallow trailing comma | | :wrench: | |
|
||||
| [`@typescript-eslint/comma-spacing`](./docs/rules/comma-spacing.md) | Enforces consistent spacing before and after commas | | :wrench: | |
|
||||
| [`@typescript-eslint/default-param-last`](./docs/rules/default-param-last.md) | Enforce default parameters to be last | | | |
|
||||
| [`@typescript-eslint/dot-notation`](./docs/rules/dot-notation.md) | enforce dot notation whenever possible | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/func-call-spacing`](./docs/rules/func-call-spacing.md) | Require or disallow spacing between function identifiers and their invocations | | :wrench: | |
|
||||
| [`@typescript-eslint/indent`](./docs/rules/indent.md) | Enforce consistent indentation | | :wrench: | |
|
||||
| [`@typescript-eslint/init-declarations`](./docs/rules/init-declarations.md) | require or disallow initialization in variable declarations | | | |
|
||||
| [`@typescript-eslint/keyword-spacing`](./docs/rules/keyword-spacing.md) | Enforce consistent spacing before and after keywords | | :wrench: | |
|
||||
| [`@typescript-eslint/lines-between-class-members`](./docs/rules/lines-between-class-members.md) | Require or disallow an empty line between class members | | :wrench: | |
|
||||
| [`@typescript-eslint/no-array-constructor`](./docs/rules/no-array-constructor.md) | Disallow generic `Array` constructors | :white_check_mark: | :wrench: | |
|
||||
| [`@typescript-eslint/no-dupe-class-members`](./docs/rules/no-dupe-class-members.md) | Disallow duplicate class members | | | |
|
||||
| [`@typescript-eslint/no-duplicate-imports`](./docs/rules/no-duplicate-imports.md) | Disallow duplicate imports | | | |
|
||||
| [`@typescript-eslint/no-empty-function`](./docs/rules/no-empty-function.md) | Disallow empty functions | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/no-extra-parens`](./docs/rules/no-extra-parens.md) | Disallow unnecessary parentheses | | :wrench: | |
|
||||
| [`@typescript-eslint/no-extra-semi`](./docs/rules/no-extra-semi.md) | Disallow unnecessary semicolons | :white_check_mark: | :wrench: | |
|
||||
| [`@typescript-eslint/no-implied-eval`](./docs/rules/no-implied-eval.md) | Disallow the use of `eval()`-like methods | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-invalid-this`](./docs/rules/no-invalid-this.md) | Disallow `this` keywords outside of classes or class-like objects | | | |
|
||||
| [`@typescript-eslint/no-loop-func`](./docs/rules/no-loop-func.md) | Disallow function declarations that contain unsafe references inside loop statements | | | |
|
||||
| [`@typescript-eslint/no-loss-of-precision`](./docs/rules/no-loss-of-precision.md) | Disallow literal numbers that lose precision | | | |
|
||||
| [`@typescript-eslint/no-magic-numbers`](./docs/rules/no-magic-numbers.md) | Disallow magic numbers | | | |
|
||||
| [`@typescript-eslint/no-redeclare`](./docs/rules/no-redeclare.md) | Disallow variable redeclaration | | | |
|
||||
| [`@typescript-eslint/no-restricted-imports`](./docs/rules/no-restricted-imports.md) | Disallow specified modules when loaded by `import` | | | |
|
||||
| [`@typescript-eslint/no-shadow`](./docs/rules/no-shadow.md) | Disallow variable declarations from shadowing variables declared in the outer scope | | | |
|
||||
| [`@typescript-eslint/no-throw-literal`](./docs/rules/no-throw-literal.md) | Disallow throwing literals as exceptions | | | :thought_balloon: |
|
||||
| [`@typescript-eslint/no-unused-expressions`](./docs/rules/no-unused-expressions.md) | Disallow unused expressions | | | |
|
||||
| [`@typescript-eslint/no-unused-vars`](./docs/rules/no-unused-vars.md) | Disallow unused variables | :white_check_mark: | | |
|
||||
| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | | | |
|
||||
| [`@typescript-eslint/no-useless-constructor`](./docs/rules/no-useless-constructor.md) | Disallow unnecessary constructors | | | |
|
||||
| [`@typescript-eslint/object-curly-spacing`](./docs/rules/object-curly-spacing.md) | Enforce consistent spacing inside braces | | :wrench: | |
|
||||
| [`@typescript-eslint/padding-line-between-statements`](./docs/rules/padding-line-between-statements.md) | require or disallow padding lines between statements | | :wrench: | |
|
||||
| [`@typescript-eslint/quotes`](./docs/rules/quotes.md) | Enforce the consistent use of either backticks, double, or single quotes | | :wrench: | |
|
||||
| [`@typescript-eslint/require-await`](./docs/rules/require-await.md) | Disallow async functions which have no `await` expression | :white_check_mark: | | :thought_balloon: |
|
||||
| [`@typescript-eslint/return-await`](./docs/rules/return-await.md) | Enforces consistent returning of awaited values | | :wrench: | :thought_balloon: |
|
||||
| [`@typescript-eslint/semi`](./docs/rules/semi.md) | Require or disallow semicolons instead of ASI | | :wrench: | |
|
||||
| [`@typescript-eslint/space-before-function-paren`](./docs/rules/space-before-function-paren.md) | Enforces consistent spacing before function parenthesis | | :wrench: | |
|
||||
| [`@typescript-eslint/space-infix-ops`](./docs/rules/space-infix-ops.md) | This rule is aimed at ensuring there are spaces around infix operators. | | :wrench: | |
|
||||
|
||||
<!-- end extension rule list -->
|
||||
|
||||
## Contributing
|
||||
|
||||
[See the contributing guide here](../../CONTRIBUTING.md).
|
||||
@@ -1,167 +0,0 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// YOU CAN REGENERATE IT USING yarn generate:configs
|
||||
module.exports = {
|
||||
extends: ['./configs/base', './configs/eslint-recommended'],
|
||||
rules: {
|
||||
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
||||
'@typescript-eslint/array-type': 'error',
|
||||
'@typescript-eslint/await-thenable': 'error',
|
||||
'@typescript-eslint/ban-ts-comment': 'error',
|
||||
'@typescript-eslint/ban-tslint-comment': 'error',
|
||||
'@typescript-eslint/ban-types': 'error',
|
||||
'brace-style': 'off',
|
||||
'@typescript-eslint/brace-style': 'error',
|
||||
'@typescript-eslint/class-literal-property-style': 'error',
|
||||
'comma-dangle': 'off',
|
||||
'@typescript-eslint/comma-dangle': 'error',
|
||||
'comma-spacing': 'off',
|
||||
'@typescript-eslint/comma-spacing': 'error',
|
||||
'@typescript-eslint/consistent-indexed-object-style': 'error',
|
||||
'@typescript-eslint/consistent-type-assertions': 'error',
|
||||
'@typescript-eslint/consistent-type-definitions': 'error',
|
||||
'@typescript-eslint/consistent-type-imports': 'error',
|
||||
'default-param-last': 'off',
|
||||
'@typescript-eslint/default-param-last': 'error',
|
||||
'dot-notation': 'off',
|
||||
'@typescript-eslint/dot-notation': 'error',
|
||||
'@typescript-eslint/explicit-function-return-type': 'error',
|
||||
'@typescript-eslint/explicit-member-accessibility': 'error',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'error',
|
||||
'func-call-spacing': 'off',
|
||||
'@typescript-eslint/func-call-spacing': 'error',
|
||||
indent: 'off',
|
||||
'@typescript-eslint/indent': 'error',
|
||||
'init-declarations': 'off',
|
||||
'@typescript-eslint/init-declarations': 'error',
|
||||
'keyword-spacing': 'off',
|
||||
'@typescript-eslint/keyword-spacing': 'error',
|
||||
'lines-between-class-members': 'off',
|
||||
'@typescript-eslint/lines-between-class-members': 'error',
|
||||
'@typescript-eslint/member-delimiter-style': 'error',
|
||||
'@typescript-eslint/member-ordering': 'error',
|
||||
'@typescript-eslint/method-signature-style': 'error',
|
||||
'@typescript-eslint/naming-convention': 'error',
|
||||
'no-array-constructor': 'off',
|
||||
'@typescript-eslint/no-array-constructor': 'error',
|
||||
'@typescript-eslint/no-base-to-string': 'error',
|
||||
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
|
||||
'@typescript-eslint/no-confusing-void-expression': 'error',
|
||||
'no-dupe-class-members': 'off',
|
||||
'@typescript-eslint/no-dupe-class-members': 'error',
|
||||
'no-duplicate-imports': 'off',
|
||||
'@typescript-eslint/no-duplicate-imports': 'error',
|
||||
'@typescript-eslint/no-dynamic-delete': 'error',
|
||||
'no-empty-function': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'error',
|
||||
'@typescript-eslint/no-empty-interface': 'error',
|
||||
'@typescript-eslint/no-explicit-any': 'error',
|
||||
'@typescript-eslint/no-extra-non-null-assertion': 'error',
|
||||
'no-extra-parens': 'off',
|
||||
'@typescript-eslint/no-extra-parens': 'error',
|
||||
'no-extra-semi': 'off',
|
||||
'@typescript-eslint/no-extra-semi': 'error',
|
||||
'@typescript-eslint/no-extraneous-class': 'error',
|
||||
'@typescript-eslint/no-floating-promises': 'error',
|
||||
'@typescript-eslint/no-for-in-array': 'error',
|
||||
'@typescript-eslint/no-implicit-any-catch': 'error',
|
||||
'no-implied-eval': 'off',
|
||||
'@typescript-eslint/no-implied-eval': 'error',
|
||||
'@typescript-eslint/no-inferrable-types': 'error',
|
||||
'no-invalid-this': 'off',
|
||||
'@typescript-eslint/no-invalid-this': 'error',
|
||||
'@typescript-eslint/no-invalid-void-type': 'error',
|
||||
'no-loop-func': 'off',
|
||||
'@typescript-eslint/no-loop-func': 'error',
|
||||
'no-loss-of-precision': 'off',
|
||||
'@typescript-eslint/no-loss-of-precision': 'error',
|
||||
'no-magic-numbers': 'off',
|
||||
'@typescript-eslint/no-magic-numbers': 'error',
|
||||
'@typescript-eslint/no-meaningless-void-operator': 'error',
|
||||
'@typescript-eslint/no-misused-new': 'error',
|
||||
'@typescript-eslint/no-misused-promises': 'error',
|
||||
'@typescript-eslint/no-namespace': 'error',
|
||||
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
|
||||
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
|
||||
'@typescript-eslint/no-non-null-assertion': 'error',
|
||||
'@typescript-eslint/no-parameter-properties': 'error',
|
||||
'no-redeclare': 'off',
|
||||
'@typescript-eslint/no-redeclare': 'error',
|
||||
'@typescript-eslint/no-require-imports': 'error',
|
||||
'no-restricted-imports': 'off',
|
||||
'@typescript-eslint/no-restricted-imports': 'error',
|
||||
'no-shadow': 'off',
|
||||
'@typescript-eslint/no-shadow': 'error',
|
||||
'@typescript-eslint/no-this-alias': 'error',
|
||||
'no-throw-literal': 'off',
|
||||
'@typescript-eslint/no-throw-literal': 'error',
|
||||
'@typescript-eslint/no-type-alias': 'error',
|
||||
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
|
||||
'@typescript-eslint/no-unnecessary-condition': 'error',
|
||||
'@typescript-eslint/no-unnecessary-qualifier': 'error',
|
||||
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
|
||||
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
||||
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
|
||||
'@typescript-eslint/no-unsafe-argument': 'error',
|
||||
'@typescript-eslint/no-unsafe-assignment': 'error',
|
||||
'@typescript-eslint/no-unsafe-call': 'error',
|
||||
'@typescript-eslint/no-unsafe-member-access': 'error',
|
||||
'@typescript-eslint/no-unsafe-return': 'error',
|
||||
'no-unused-expressions': 'off',
|
||||
'@typescript-eslint/no-unused-expressions': 'error',
|
||||
'no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'error',
|
||||
'no-use-before-define': 'off',
|
||||
'@typescript-eslint/no-use-before-define': 'error',
|
||||
'no-useless-constructor': 'off',
|
||||
'@typescript-eslint/no-useless-constructor': 'error',
|
||||
'@typescript-eslint/no-var-requires': 'error',
|
||||
'@typescript-eslint/non-nullable-type-assertion-style': 'error',
|
||||
'object-curly-spacing': 'off',
|
||||
'@typescript-eslint/object-curly-spacing': 'error',
|
||||
'padding-line-between-statements': 'off',
|
||||
'@typescript-eslint/padding-line-between-statements': 'error',
|
||||
'@typescript-eslint/prefer-as-const': 'error',
|
||||
'@typescript-eslint/prefer-enum-initializers': 'error',
|
||||
'@typescript-eslint/prefer-for-of': 'error',
|
||||
'@typescript-eslint/prefer-function-type': 'error',
|
||||
'@typescript-eslint/prefer-includes': 'error',
|
||||
'@typescript-eslint/prefer-literal-enum-member': 'error',
|
||||
'@typescript-eslint/prefer-namespace-keyword': 'error',
|
||||
'@typescript-eslint/prefer-nullish-coalescing': 'error',
|
||||
'@typescript-eslint/prefer-optional-chain': 'error',
|
||||
'@typescript-eslint/prefer-readonly': 'error',
|
||||
'@typescript-eslint/prefer-readonly-parameter-types': 'error',
|
||||
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
|
||||
'@typescript-eslint/prefer-regexp-exec': 'error',
|
||||
'@typescript-eslint/prefer-return-this-type': 'error',
|
||||
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
|
||||
'@typescript-eslint/prefer-ts-expect-error': 'error',
|
||||
'@typescript-eslint/promise-function-async': 'error',
|
||||
quotes: 'off',
|
||||
'@typescript-eslint/quotes': 'error',
|
||||
'@typescript-eslint/require-array-sort-compare': 'error',
|
||||
'require-await': 'off',
|
||||
'@typescript-eslint/require-await': 'error',
|
||||
'@typescript-eslint/restrict-plus-operands': 'error',
|
||||
'@typescript-eslint/restrict-template-expressions': 'error',
|
||||
'no-return-await': 'off',
|
||||
'@typescript-eslint/return-await': 'error',
|
||||
semi: 'off',
|
||||
'@typescript-eslint/semi': 'error',
|
||||
'@typescript-eslint/sort-type-union-intersection-members': 'error',
|
||||
'space-before-function-paren': 'off',
|
||||
'@typescript-eslint/space-before-function-paren': 'error',
|
||||
'space-infix-ops': 'off',
|
||||
'@typescript-eslint/space-infix-ops': 'error',
|
||||
'@typescript-eslint/strict-boolean-expressions': 'error',
|
||||
'@typescript-eslint/switch-exhaustiveness-check': 'error',
|
||||
'@typescript-eslint/triple-slash-reference': 'error',
|
||||
'@typescript-eslint/type-annotation-spacing': 'error',
|
||||
'@typescript-eslint/typedef': 'error',
|
||||
'@typescript-eslint/unbound-method': 'error',
|
||||
'@typescript-eslint/unified-signatures': 'error',
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=all.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"all.js","sourceRoot":"","sources":["../../src/configs/all.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,gCAAgC;AAChC,oDAAoD;AAEpD,iBAAS;IACP,OAAO,EAAE,CAAC,gBAAgB,EAAE,8BAA8B,CAAC;IAC3D,KAAK,EAAE;QACL,iDAAiD,EAAE,OAAO;QAC1D,+BAA+B,EAAE,OAAO;QACxC,mCAAmC,EAAE,OAAO;QAC5C,mCAAmC,EAAE,OAAO;QAC5C,uCAAuC,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AiC,EAAE,OAAO;QAC1C,IAAI,EAAE,KAAK;QACX,yBAAyB,EAAE,OAAO;QAClC,yDAAyD,EAAE,OAAO;QAClE,6BAA6B,EAAE,KAAK;QACpC,gDAAgD,EAAE,OAAO;QACzD,iBAAiB,EAAE,KAAK;QACxB,oCAAoC,EAAE,OAAO;QAC7C,+CAA+C,EAAE,OAAO;QACxD,gDAAgD,EAAE,OAAO;QACzD,2CAA2C,EAAE,OAAO;QACpD,4CAA4C,EAAE,OAAO;QACrD,4BAA4B,EAAE,OAAO;QACrC,mCAAmC,EAAE,OAAO;QAC5C,uCAAuC,EAAE,OAAO;KACjD;CACF,CAAC"}
|
||||
@@ -1,10 +0,0 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// YOU CAN REGENERATE IT USING yarn generate:configs
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: { sourceType: 'module' },
|
||||
plugins: ['@typescript-eslint'],
|
||||
};
|
||||
//# sourceMappingURL=base.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/configs/base.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,gCAAgC;AAChC,oDAAoD;AAEpD,iBAAS;IACP,MAAM,EAAE,2BAA2B;IACnC,aAAa,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE;IACvC,OAAO,EAAE,CAAC,oBAAoB,CAAC;CAChC,CAAC"}
|
||||
@@ -1,32 +0,0 @@
|
||||
"use strict";
|
||||
module.exports = {
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
rules: {
|
||||
'constructor-super': 'off',
|
||||
'getter-return': 'off',
|
||||
'no-const-assign': 'off',
|
||||
'no-dupe-args': 'off',
|
||||
'no-dupe-class-members': 'off',
|
||||
'no-dupe-keys': 'off',
|
||||
'no-func-assign': 'off',
|
||||
'no-import-assign': 'off',
|
||||
'no-new-symbol': 'off',
|
||||
'no-obj-calls': 'off',
|
||||
'no-redeclare': 'off',
|
||||
'no-setter-return': 'off',
|
||||
'no-this-before-super': 'off',
|
||||
'no-undef': 'off',
|
||||
'no-unreachable': 'off',
|
||||
'no-unsafe-negation': 'off',
|
||||
'no-var': 'error',
|
||||
'prefer-const': 'error',
|
||||
'prefer-rest-params': 'error',
|
||||
'prefer-spread': 'error',
|
||||
'valid-typeof': 'off', // ts(2367)
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
//# sourceMappingURL=eslint-recommended.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"eslint-recommended.js","sourceRoot":"","sources":["../../src/configs/eslint-recommended.ts"],"names":[],"mappings":";AAKA,iBAAS;IACP,SAAS,EAAE;QACT;YACE,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;YACxB,KAAK,EAAE;gBACL,mBAAmB,EAAE,KAAK;gBAC1B,eAAe,EAAE,KAAK;gBACtB,iBAAiB,EAAE,KAAK;gBACxB,cAAc,EAAE,KAAK;gBACrB,uBAAuB,EAAE,KAAK;gBAC9B,cAAc,EAAE,KAAK;gBACrB,gBAAgB,EAAE,KAAK;gBACvB,kBAAkB,EAAE,KAAK;gBACzB,eAAe,EAAE,KAAK;gBACtB,cAAc,EAAE,KAAK;gBACrB,cAAc,EAAE,KAAK;gBACrB,kBAAkB,EAAE,KAAK;gBACzB,sBAAsB,EAAE,KAAK;gBAC7B,UAAU,EAAE,KAAK;gBACjB,gBAAgB,EAAE,KAAK;gBACvB,oBAAoB,EAAE,KAAK;gBAC3B,QAAQ,EAAE,OAAO;gBACjB,cAAc,EAAE,OAAO;gBACvB,oBAAoB,EAAE,OAAO;gBAC7B,eAAe,EAAE,OAAO;gBACxB,cAAc,EAAE,KAAK,EAAE,WAAW;aACnC;SACF;KACF;CACF,CAAC"}
|
||||
@@ -1,27 +0,0 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// YOU CAN REGENERATE IT USING yarn generate:configs
|
||||
module.exports = {
|
||||
extends: ['./configs/base', './configs/eslint-recommended'],
|
||||
rules: {
|
||||
'@typescript-eslint/await-thenable': 'error',
|
||||
'@typescript-eslint/no-floating-promises': 'error',
|
||||
'@typescript-eslint/no-for-in-array': 'error',
|
||||
'no-implied-eval': 'off',
|
||||
'@typescript-eslint/no-implied-eval': 'error',
|
||||
'@typescript-eslint/no-misused-promises': 'error',
|
||||
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
||||
'@typescript-eslint/no-unsafe-assignment': 'error',
|
||||
'@typescript-eslint/no-unsafe-call': 'error',
|
||||
'@typescript-eslint/no-unsafe-member-access': 'error',
|
||||
'@typescript-eslint/no-unsafe-return': 'error',
|
||||
'@typescript-eslint/prefer-regexp-exec': 'error',
|
||||
'require-await': 'off',
|
||||
'@typescript-eslint/require-await': 'error',
|
||||
'@typescript-eslint/restrict-plus-operands': 'error',
|
||||
'@typescript-eslint/restrict-template-expressions': 'error',
|
||||
'@typescript-eslint/unbound-method': 'error',
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=recommended-requiring-type-checking.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"recommended-requiring-type-checking.js","sourceRoot":"","sources":["../../src/configs/recommended-requiring-type-checking.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,gCAAgC;AAChC,oDAAoD;AAEpD,iBAAS;IACP,OAAO,EAAE,CAAC,gBAAgB,EAAE,8BAA8B,CAAC;IAC3D,KAAK,EAAE;QACL,mCAAmC,EAAE,OAAO;QAC5C,yCAAyC,EAAE,OAAO;QAClD,oCAAoC,EAAE,OAAO;QAC7C,iBAAiB,EAAE,KAAK;QACxB,oCAAoC,EAAE,OAAO;QAC7C,wCAAwC,EAAE,OAAO;QACjD,kDAAkD,EAAE,OAAO;QAC3D,yCAAyC,EAAE,OAAO;QAClD,mCAAmC,EAAE,OAAO;QAC5C,4CAA4C,EAAE,OAAO;QACrD,qCAAqC,EAAE,OAAO;QAC9C,uCAAuC,EAAE,OAAO;QAChD,eAAe,EAAE,KAAK;QACtB,kCAAkC,EAAE,OAAO;QAC3C,2CAA2C,EAAE,OAAO;QACpD,kDAAkD,EAAE,OAAO;QAC3D,mCAAmC,EAAE,OAAO;KAC7C;CACF,CAAC"}
|
||||
@@ -1,35 +0,0 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// YOU CAN REGENERATE IT USING yarn generate:configs
|
||||
module.exports = {
|
||||
extends: ['./configs/base', './configs/eslint-recommended'],
|
||||
rules: {
|
||||
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
||||
'@typescript-eslint/ban-ts-comment': 'error',
|
||||
'@typescript-eslint/ban-types': 'error',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'warn',
|
||||
'no-array-constructor': 'off',
|
||||
'@typescript-eslint/no-array-constructor': 'error',
|
||||
'no-empty-function': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'error',
|
||||
'@typescript-eslint/no-empty-interface': 'error',
|
||||
'@typescript-eslint/no-explicit-any': 'warn',
|
||||
'@typescript-eslint/no-extra-non-null-assertion': 'error',
|
||||
'no-extra-semi': 'off',
|
||||
'@typescript-eslint/no-extra-semi': 'error',
|
||||
'@typescript-eslint/no-inferrable-types': 'error',
|
||||
'@typescript-eslint/no-misused-new': 'error',
|
||||
'@typescript-eslint/no-namespace': 'error',
|
||||
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
|
||||
'@typescript-eslint/no-non-null-assertion': 'warn',
|
||||
'@typescript-eslint/no-this-alias': 'error',
|
||||
'no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'warn',
|
||||
'@typescript-eslint/no-var-requires': 'error',
|
||||
'@typescript-eslint/prefer-as-const': 'error',
|
||||
'@typescript-eslint/prefer-namespace-keyword': 'error',
|
||||
'@typescript-eslint/triple-slash-reference': 'error',
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=recommended.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,gCAAgC;AAChC,oDAAoD;AAEpD,iBAAS;IACP,OAAO,EAAE,CAAC,gBAAgB,EAAE,8BAA8B,CAAC;IAC3D,KAAK,EAAE;QACL,iDAAiD,EAAE,OAAO;QAC1D,mCAAmC,EAAE,OAAO;QAC5C,8BAA8B,EAAE,OAAO;QACvC,mDAAmD,EAAE,MAAM;QAC3D,sBAAsB,EAAE,KAAK;QAC7B,yCAAyC,EAAE,OAAO;QAClD,mBAAmB,EAAE,KAAK;QAC1B,sCAAsC,EAAE,OAAO;QAC/C,uCAAuC,EAAE,OAAO;QAChD,oCAAoC,EAAE,MAAM;QAC5C,gDAAgD,EAAE,OAAO;QACzD,eAAe,EAAE,KAAK;QACtB,kCAAkC,EAAE,OAAO;QAC3C,wCAAwC,EAAE,OAAO;QACjD,mCAAmC,EAAE,OAAO;QAC5C,iCAAiC,EAAE,OAAO;QAC1C,wDAAwD,EAAE,OAAO;QACjE,0CAA0C,EAAE,MAAM;QAClD,kCAAkC,EAAE,OAAO;QAC3C,gBAAgB,EAAE,KAAK;QACvB,mCAAmC,EAAE,MAAM;QAC3C,oCAAoC,EAAE,OAAO;QAC7C,oCAAoC,EAAE,OAAO;QAC7C,6CAA6C,EAAE,OAAO;QACtD,2CAA2C,EAAE,OAAO;KACrD;CACF,CAAC"}
|
||||
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const rules_1 = __importDefault(require("./rules"));
|
||||
const all_1 = __importDefault(require("./configs/all"));
|
||||
const base_1 = __importDefault(require("./configs/base"));
|
||||
const recommended_1 = __importDefault(require("./configs/recommended"));
|
||||
const recommended_requiring_type_checking_1 = __importDefault(require("./configs/recommended-requiring-type-checking"));
|
||||
const eslint_recommended_1 = __importDefault(require("./configs/eslint-recommended"));
|
||||
module.exports = {
|
||||
rules: rules_1.default,
|
||||
configs: {
|
||||
all: all_1.default,
|
||||
base: base_1.default,
|
||||
recommended: recommended_1.default,
|
||||
'eslint-recommended': eslint_recommended_1.default,
|
||||
'recommended-requiring-type-checking': recommended_requiring_type_checking_1.default,
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,oDAA4B;AAE5B,wDAAgC;AAChC,0DAAkC;AAClC,wEAAgD;AAChD,wHAA6F;AAC7F,sFAA6D;AAE7D,iBAAS;IACP,KAAK,EAAL,eAAK;IACL,OAAO,EAAE;QACP,GAAG,EAAH,aAAG;QACH,IAAI,EAAJ,cAAI;QACJ,WAAW,EAAX,qBAAW;QACX,oBAAoB,EAAE,4BAAiB;QACvC,qCAAqC,EAAE,6CAAgC;KACxE;CACF,CAAC"}
|
||||
@@ -1,159 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
exports.default = util.createRule({
|
||||
name: 'adjacent-overload-signatures',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Require that member overloads be consecutive',
|
||||
category: 'Best Practices',
|
||||
recommended: 'error',
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
adjacentSignature: "All '{{name}}' signatures should be adjacent.",
|
||||
},
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
/**
|
||||
* Gets the name and attribute of the member being processed.
|
||||
* @param member the member being processed.
|
||||
* @returns the name and attribute of the member or null if it's a member not relevant to the rule.
|
||||
*/
|
||||
function getMemberMethod(member) {
|
||||
var _a, _b;
|
||||
if (!member) {
|
||||
return null;
|
||||
}
|
||||
const isStatic = 'static' in member && !!member.static;
|
||||
switch (member.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.ExportDefaultDeclaration:
|
||||
case experimental_utils_1.AST_NODE_TYPES.ExportNamedDeclaration: {
|
||||
// export statements (e.g. export { a };)
|
||||
// have no declarations, so ignore them
|
||||
if (!member.declaration) {
|
||||
return null;
|
||||
}
|
||||
return getMemberMethod(member.declaration);
|
||||
}
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSDeclareFunction:
|
||||
case experimental_utils_1.AST_NODE_TYPES.FunctionDeclaration: {
|
||||
const name = (_b = (_a = member.id) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : null;
|
||||
if (name === null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
name,
|
||||
static: isStatic,
|
||||
callSignature: false,
|
||||
};
|
||||
}
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSMethodSignature:
|
||||
return {
|
||||
name: util.getNameFromMember(member, sourceCode),
|
||||
static: isStatic,
|
||||
callSignature: false,
|
||||
};
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
|
||||
return {
|
||||
name: 'call',
|
||||
static: isStatic,
|
||||
callSignature: true,
|
||||
};
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
|
||||
return {
|
||||
name: 'new',
|
||||
static: isStatic,
|
||||
callSignature: false,
|
||||
};
|
||||
case experimental_utils_1.AST_NODE_TYPES.MethodDefinition:
|
||||
return {
|
||||
name: util.getNameFromMember(member, sourceCode),
|
||||
static: isStatic,
|
||||
callSignature: false,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function isSameMethod(method1, method2) {
|
||||
return (!!method2 &&
|
||||
method1.name === method2.name &&
|
||||
method1.static === method2.static &&
|
||||
method1.callSignature === method2.callSignature);
|
||||
}
|
||||
function getMembers(node) {
|
||||
switch (node.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.ClassBody:
|
||||
case experimental_utils_1.AST_NODE_TYPES.Program:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSModuleBlock:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSInterfaceBody:
|
||||
return node.body;
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSTypeLiteral:
|
||||
return node.members;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check the body for overload methods.
|
||||
* @param {ASTNode} node the body to be inspected.
|
||||
*/
|
||||
function checkBodyForOverloadMethods(node) {
|
||||
const members = getMembers(node);
|
||||
if (members) {
|
||||
let lastMethod = null;
|
||||
const seenMethods = [];
|
||||
members.forEach(member => {
|
||||
const method = getMemberMethod(member);
|
||||
if (method === null) {
|
||||
lastMethod = null;
|
||||
return;
|
||||
}
|
||||
const index = seenMethods.findIndex(seenMethod => isSameMethod(method, seenMethod));
|
||||
if (index > -1 && !isSameMethod(method, lastMethod)) {
|
||||
context.report({
|
||||
node: member,
|
||||
messageId: 'adjacentSignature',
|
||||
data: {
|
||||
name: (method.static ? 'static ' : '') + method.name,
|
||||
},
|
||||
});
|
||||
}
|
||||
else if (index === -1) {
|
||||
seenMethods.push(method);
|
||||
}
|
||||
lastMethod = method;
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
ClassBody: checkBodyForOverloadMethods,
|
||||
Program: checkBodyForOverloadMethods,
|
||||
TSModuleBlock: checkBodyForOverloadMethods,
|
||||
TSTypeLiteral: checkBodyForOverloadMethods,
|
||||
TSInterfaceBody: checkBodyForOverloadMethods,
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=adjacent-overload-signatures.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"adjacent-overload-signatures.js","sourceRoot":"","sources":["../../src/rules/adjacent-overload-signatures.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8EAG+C;AAC/C,8CAAgC;AAahC,kBAAe,IAAI,CAAC,UAAU,CAAC;IAC7B,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,8CAA8C;YAC3D,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,OAAO;SACrB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,iBAAiB,EAAE,+CAA+C;SACnE;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAQ3C;;;;WAIG;QACH,SAAS,eAAe,CAAC,MAAqB;;YAC5C,IAAI,CAAC,MAAM,EAAE;gBACX,OAAO,IAAI,CAAC;aACb;YAED,MAAM,QAAQ,GAAG,QAAQ,IAAI,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,C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CAAC,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE;wBACnD,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,MAAM;4BACZ,SAAS,EAAE,mBAAmB;4BAC9B,IAAI,EAAE;gCACJ,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI;6BACrD;yBACF,CAAC,CAAC;qBACJ;yBAAM,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;wBACvB,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;qBAC1B;oBAED,UAAU,GAAG,MAAM,CAAC;gBACtB,CAAC,CAAC,CAAC;aACJ;QACH,CAAC;QAED,OAAO;YACL,SAAS,EAAE,2BAA2B;YACtC,OAAO,EAAE,2BAA2B;YACpC,aAAa,EAAE,2BAA2B;YAC1C,aAAa,EAAE,2BAA2B;YAC1C,eAAe,EAAE,2BAA2B;SAC7C,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,231 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
/**
|
||||
* Check whatever node can be considered as simple
|
||||
* @param node the node to be evaluated.
|
||||
*/
|
||||
function isSimpleType(node) {
|
||||
switch (node.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.Identifier:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSAnyKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSBooleanKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSNeverKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSNumberKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSObjectKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSStringKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSSymbolKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSUnknownKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSVoidKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSNullKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSArrayType:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSUndefinedKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSThisType:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSQualifiedName:
|
||||
return true;
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSTypeReference:
|
||||
if (node.typeName &&
|
||||
node.typeName.type === experimental_utils_1.AST_NODE_TYPES.Identifier &&
|
||||
node.typeName.name === 'Array') {
|
||||
if (!node.typeParameters) {
|
||||
return true;
|
||||
}
|
||||
if (node.typeParameters.params.length === 1) {
|
||||
return isSimpleType(node.typeParameters.params[0]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (node.typeParameters) {
|
||||
return false;
|
||||
}
|
||||
return isSimpleType(node.typeName);
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check if node needs parentheses
|
||||
* @param node the node to be evaluated.
|
||||
*/
|
||||
function typeNeedsParentheses(node) {
|
||||
switch (node.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSTypeReference:
|
||||
return typeNeedsParentheses(node.typeName);
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSUnionType:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSFunctionType:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSIntersectionType:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSTypeOperator:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSInferType:
|
||||
return true;
|
||||
case experimental_utils_1.AST_NODE_TYPES.Identifier:
|
||||
return node.name === 'ReadonlyArray';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const arrayOption = { enum: ['array', 'generic', 'array-simple'] };
|
||||
exports.default = util.createRule({
|
||||
name: 'array-type',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Requires using either `T[]` or `Array<T>` for arrays',
|
||||
category: 'Stylistic Issues',
|
||||
// too opinionated to be recommended
|
||||
recommended: false,
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
errorStringGeneric: "Array type using '{{type}}[]' is forbidden. Use 'Array<{{type}}>' instead.",
|
||||
errorStringGenericSimple: "Array type using '{{type}}[]' is forbidden for non-simple types. Use 'Array<{{type}}>' instead.",
|
||||
errorStringArray: "Array type using 'Array<{{type}}>' is forbidden. Use '{{type}}[]' instead.",
|
||||
errorStringArraySimple: "Array type using 'Array<{{type}}>' is forbidden for simple types. Use '{{type}}[]' instead.",
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
default: arrayOption,
|
||||
readonly: arrayOption,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
default: 'array',
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
var _a;
|
||||
const sourceCode = context.getSourceCode();
|
||||
const defaultOption = options.default;
|
||||
const readonlyOption = (_a = options.readonly) !== null && _a !== void 0 ? _a : defaultOption;
|
||||
/**
|
||||
* @param node the node to be evaluated.
|
||||
*/
|
||||
function getMessageType(node) {
|
||||
if (node) {
|
||||
if (node.type === experimental_utils_1.AST_NODE_TYPES.TSParenthesizedType) {
|
||||
return getMessageType(node.typeAnnotation);
|
||||
}
|
||||
if (isSimpleType(node)) {
|
||||
return sourceCode.getText(node);
|
||||
}
|
||||
}
|
||||
return 'T';
|
||||
}
|
||||
return {
|
||||
TSArrayType(node) {
|
||||
const isReadonly = node.parent &&
|
||||
node.parent.type === experimental_utils_1.AST_NODE_TYPES.TSTypeOperator &&
|
||||
node.parent.operator === 'readonly';
|
||||
const currentOption = isReadonly ? readonlyOption : defaultOption;
|
||||
if (currentOption === 'array' ||
|
||||
(currentOption === 'array-simple' && isSimpleType(node.elementType))) {
|
||||
return;
|
||||
}
|
||||
const messageId = currentOption === 'generic'
|
||||
? 'errorStringGeneric'
|
||||
: 'errorStringGenericSimple';
|
||||
const errorNode = isReadonly ? node.parent : node;
|
||||
context.report({
|
||||
node: errorNode,
|
||||
messageId,
|
||||
data: {
|
||||
type: getMessageType(node.elementType),
|
||||
},
|
||||
fix(fixer) {
|
||||
const typeNode = node.elementType.type === experimental_utils_1.AST_NODE_TYPES.TSParenthesizedType
|
||||
? node.elementType.typeAnnotation
|
||||
: node.elementType;
|
||||
const arrayType = isReadonly ? 'ReadonlyArray' : 'Array';
|
||||
return [
|
||||
fixer.replaceTextRange([errorNode.range[0], typeNode.range[0]], `${arrayType}<`),
|
||||
fixer.replaceTextRange([typeNode.range[1], errorNode.range[1]], '>'),
|
||||
];
|
||||
},
|
||||
});
|
||||
},
|
||||
TSTypeReference(node) {
|
||||
var _a, _b;
|
||||
if (node.typeName.type !== experimental_utils_1.AST_NODE_TYPES.Identifier ||
|
||||
!(node.typeName.name === 'Array' ||
|
||||
node.typeName.name === 'ReadonlyArray')) {
|
||||
return;
|
||||
}
|
||||
const isReadonlyArrayType = node.typeName.name === 'ReadonlyArray';
|
||||
const currentOption = isReadonlyArrayType
|
||||
? readonlyOption
|
||||
: defaultOption;
|
||||
if (currentOption === 'generic') {
|
||||
return;
|
||||
}
|
||||
const readonlyPrefix = isReadonlyArrayType ? 'readonly ' : '';
|
||||
const typeParams = (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.params;
|
||||
const messageId = currentOption === 'array'
|
||||
? 'errorStringArray'
|
||||
: 'errorStringArraySimple';
|
||||
if (!typeParams || typeParams.length === 0) {
|
||||
// Create an 'any' array
|
||||
context.report({
|
||||
node,
|
||||
messageId,
|
||||
data: {
|
||||
type: 'any',
|
||||
},
|
||||
fix(fixer) {
|
||||
return fixer.replaceText(node, `${readonlyPrefix}any[]`);
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (typeParams.length !== 1 ||
|
||||
(currentOption === 'array-simple' && !isSimpleType(typeParams[0]))) {
|
||||
return;
|
||||
}
|
||||
const type = typeParams[0];
|
||||
const typeParens = typeNeedsParentheses(type);
|
||||
const parentParens = readonlyPrefix && ((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === experimental_utils_1.AST_NODE_TYPES.TSArrayType;
|
||||
const start = `${parentParens ? '(' : ''}${readonlyPrefix}${typeParens ? '(' : ''}`;
|
||||
const end = `${typeParens ? ')' : ''}[]${parentParens ? ')' : ''}`;
|
||||
context.report({
|
||||
node,
|
||||
messageId,
|
||||
data: {
|
||||
type: getMessageType(type),
|
||||
},
|
||||
fix(fixer) {
|
||||
return [
|
||||
fixer.replaceTextRange([node.range[0], type.range[0]], start),
|
||||
fixer.replaceTextRange([type.range[1], node.range[1]], end),
|
||||
];
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=array-type.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,59 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tsutils = __importStar(require("tsutils"));
|
||||
const util = __importStar(require("../util"));
|
||||
exports.default = util.createRule({
|
||||
name: 'await-thenable',
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Disallows awaiting a value that is not a Thenable',
|
||||
category: 'Best Practices',
|
||||
recommended: 'error',
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
messages: {
|
||||
await: 'Unexpected `await` of a non-Promise (non-"Thenable") value.',
|
||||
},
|
||||
schema: [],
|
||||
type: 'problem',
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
const parserServices = util.getParserServices(context);
|
||||
const checker = parserServices.program.getTypeChecker();
|
||||
return {
|
||||
AwaitExpression(node) {
|
||||
const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node);
|
||||
const type = checker.getTypeAtLocation(originalNode.expression);
|
||||
if (!util.isTypeAnyType(type) &&
|
||||
!util.isTypeUnknownType(type) &&
|
||||
!tsutils.isThenableType(checker, originalNode.expression, type)) {
|
||||
context.report({
|
||||
messageId: 'await',
|
||||
node,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=await-thenable.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"await-thenable.js","sourceRoot":"","sources":["../../src/rules/await-thenable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AAEnC,8CAAgC;AAEhC,kBAAe,IAAI,CAAC,UAAU,CAAC;IAC7B,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EAAE,mDAAmD;YAChE,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,OAAO;YACpB,oBAAoB,EAAE,IAAI;SAC3B;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,6DAA6D;SACrE;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;KAChB;IACD,cAAc,EAAE,EAAE;IAElB,MAAM,CAAC,OAAO;QACZ,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACvD,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAExD,OAAO;YACL,eAAe,CAAC,IAAI;gBAClB,MAAM,YAAY,GAAG,cAAc,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACpE,MAAM,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;gBAEhE,IACE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;oBACzB,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;oBAC7B,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,EAC/D;oBACA,OAAO,CAAC,MAAM,CAAC;wBACb,SAAS,EAAE,OAAO;wBAClB,IAAI;qBACL,CAAC,CAAC;iBACJ;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,147 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultMinimumDescriptionLength = void 0;
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
exports.defaultMinimumDescriptionLength = 3;
|
||||
exports.default = util.createRule({
|
||||
name: 'ban-ts-comment',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Bans `@ts-<directive>` comments from being used or requires descriptions after directive',
|
||||
category: 'Best Practices',
|
||||
recommended: 'error',
|
||||
},
|
||||
messages: {
|
||||
tsDirectiveComment: 'Do not use "@ts-{{directive}}" because it alters compilation errors.',
|
||||
tsDirectiveCommentRequiresDescription: 'Include a description after the "@ts-{{directive}}" directive to explain why the @ts-{{directive}} is necessary. The description must be {{minimumDescriptionLength}} characters or longer.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
'ts-expect-error': {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
enum: ['allow-with-description'],
|
||||
},
|
||||
],
|
||||
},
|
||||
'ts-ignore': {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
enum: ['allow-with-description'],
|
||||
},
|
||||
],
|
||||
},
|
||||
'ts-nocheck': {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
enum: ['allow-with-description'],
|
||||
},
|
||||
],
|
||||
},
|
||||
'ts-check': {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
enum: ['allow-with-description'],
|
||||
},
|
||||
],
|
||||
},
|
||||
minimumDescriptionLength: {
|
||||
type: 'number',
|
||||
default: exports.defaultMinimumDescriptionLength,
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
'ts-expect-error': 'allow-with-description',
|
||||
'ts-ignore': true,
|
||||
'ts-nocheck': true,
|
||||
'ts-check': false,
|
||||
minimumDescriptionLength: exports.defaultMinimumDescriptionLength,
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
/*
|
||||
The regex used are taken from the ones used in the official TypeScript repo -
|
||||
https://github.com/microsoft/TypeScript/blob/master/src/compiler/scanner.ts#L281-L289
|
||||
*/
|
||||
const commentDirectiveRegExSingleLine = /^\/*\s*@ts-(expect-error|ignore|check|nocheck)(.*)/;
|
||||
const commentDirectiveRegExMultiLine = /^\s*(?:\/|\*)*\s*@ts-(expect-error|ignore|check|nocheck)(.*)/;
|
||||
const sourceCode = context.getSourceCode();
|
||||
return {
|
||||
Program() {
|
||||
const comments = sourceCode.getAllComments();
|
||||
comments.forEach(comment => {
|
||||
var _a;
|
||||
let regExp = commentDirectiveRegExSingleLine;
|
||||
if (comment.type !== experimental_utils_1.AST_TOKEN_TYPES.Line) {
|
||||
regExp = commentDirectiveRegExMultiLine;
|
||||
}
|
||||
const [, directive, description] = (_a = regExp.exec(comment.value)) !== null && _a !== void 0 ? _a : [];
|
||||
const fullDirective = `ts-${directive}`;
|
||||
const option = options[fullDirective];
|
||||
if (option === true) {
|
||||
context.report({
|
||||
data: { directive },
|
||||
node: comment,
|
||||
messageId: 'tsDirectiveComment',
|
||||
});
|
||||
}
|
||||
if (option === 'allow-with-description') {
|
||||
const { minimumDescriptionLength = exports.defaultMinimumDescriptionLength, } = options;
|
||||
if (description.trim().length < minimumDescriptionLength) {
|
||||
context.report({
|
||||
data: { directive, minimumDescriptionLength },
|
||||
node: comment,
|
||||
messageId: 'tsDirectiveCommentRequiresDescription',
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=ban-ts-comment.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"ban-ts-comment.js","sourceRoot":"","sources":["../../src/rules/ban-ts-comment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,8EAAwE;AACxE,8CAAgC;AAUnB,QAAA,+BAA+B,GAAG,CAAC,CAAC;AAMjD,kBAAe,IAAI,CAAC,UAAU,CAAwB;IACpD,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,0FAA0F;YAC5F,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,OAAO;SACrB;QACD,QAAQ,EAAE;YACR,kBAAkB,EAChB,sEAAsE;YACxE,qCAAqC,EACnC,6LAA6L;SAChM;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,iBA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CAAC,OAAO,CAAC,EAAE;;oBACzB,IAAI,MAAM,GAAG,+BAA+B,CAAC;oBAE7C,IAAI,OAAO,CAAC,IAAI,KAAK,oCAAe,CAAC,IAAI,EAAE;wBACzC,MAAM,GAAG,8BAA8B,CAAC;qBACzC;oBACD,MAAM,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,GAAG,MAAA,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,mCAAI,EAAE,CAAC;oBAEpE,MAAM,aAAa,GAAG,MAAM,SAAS,EAAmB,CAAC;oBAEzD,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;oBACtC,IAAI,MAAM,KAAK,IAAI,EAAE;wBACnB,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,EAAE,SAAS,EAAE;4BACnB,IAAI,EAAE,OAAO;4BACb,SAAS,EAAE,oBAAoB;yBAChC,CAAC,CAAC;qBACJ;oBAED,IAAI,MAAM,KAAK,wBAAwB,EAAE;wBACvC,MAAM,EACJ,wBAAwB,GAAG,uCAA+B,GAC3D,GAAG,OAAO,CAAC;wBACZ,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,wBAAwB,EAAE;4BACxD,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI,EAAE,EAAE,SAAS,EAAE,wBAAwB,EAAE;gCAC7C,IAAI,EAAE,OAAO;gCACb,SAAS,EAAE,uCAAuC;6BACnD,CAAC,CAAC;yBACJ;qBACF;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,75 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
// tslint regex
|
||||
// https://github.com/palantir/tslint/blob/95d9d958833fd9dc0002d18cbe34db20d0fbf437/src/enableDisableRules.ts#L32
|
||||
const ENABLE_DISABLE_REGEX = /^\s*tslint:(enable|disable)(?:-(line|next-line))?(:|\s|$)/;
|
||||
const toText = (text, type) => type === experimental_utils_1.AST_TOKEN_TYPES.Line
|
||||
? ['//', text.trim()].join(' ')
|
||||
: ['/*', text.trim(), '*/'].join(' ');
|
||||
exports.default = util.createRule({
|
||||
name: 'ban-tslint-comment',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Bans `// tslint:<rule-flag>` comments from being used',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
},
|
||||
messages: {
|
||||
commentDetected: 'tslint comment detected: "{{ text }}"',
|
||||
},
|
||||
schema: [],
|
||||
fixable: 'code',
|
||||
},
|
||||
defaultOptions: [],
|
||||
create: context => {
|
||||
const sourceCode = context.getSourceCode();
|
||||
return {
|
||||
Program() {
|
||||
const comments = sourceCode.getAllComments();
|
||||
comments.forEach(c => {
|
||||
if (ENABLE_DISABLE_REGEX.test(c.value)) {
|
||||
context.report({
|
||||
data: { text: toText(c.value, c.type) },
|
||||
node: c,
|
||||
messageId: 'commentDetected',
|
||||
fix(fixer) {
|
||||
const rangeStart = sourceCode.getIndexFromLoc({
|
||||
column: c.loc.start.column > 0 ? c.loc.start.column - 1 : 0,
|
||||
line: c.loc.start.line,
|
||||
});
|
||||
const rangeEnd = sourceCode.getIndexFromLoc({
|
||||
column: c.loc.end.column,
|
||||
line: c.loc.end.line,
|
||||
});
|
||||
return fixer.removeRange([rangeStart, rangeEnd + 1]);
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=ban-tslint-comment.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"ban-tslint-comment.js","sourceRoot":"","sources":["../../src/rules/ban-tslint-comment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8EAAwE;AACxE,8CAAgC;AAEhC,eAAe;AACf,iHAAiH;AACjH,MAAM,oBAAoB,GACxB,2DAA2D,CAAC;AAE9D,MAAM,MAAM,GAAG,CACb,IAAY,EACZ,IAAkD,EAC1C,EAAE,CACV,IAAI,KAAK,oCAAe,CAAC,IAAI;IAC3B,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;IAC/B,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE1C,kBAAe,IAAI,CAAC,UAAU,CAAC;IAC7B,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,uDAAuD;YACpE,QAAQ,EAAE,kBAAkB;YAC5B,WAAW,EAAE,KAAK;SACnB;QACD,QAAQ,EAAE;YACR,eAAe,EAAE,uCAAuC;SACzD;QACD,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,MAAM;KAChB;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@@ -1,198 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TYPE_KEYWORDS = void 0;
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
function removeSpaces(str) {
|
||||
return str.replace(/ /g, '');
|
||||
}
|
||||
function stringifyNode(node, sourceCode) {
|
||||
return removeSpaces(sourceCode.getText(node));
|
||||
}
|
||||
function getCustomMessage(bannedType) {
|
||||
if (bannedType === null) {
|
||||
return '';
|
||||
}
|
||||
if (typeof bannedType === 'string') {
|
||||
return ` ${bannedType}`;
|
||||
}
|
||||
if (bannedType.message) {
|
||||
return ` ${bannedType.message}`;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
const defaultTypes = {
|
||||
String: {
|
||||
message: 'Use string instead',
|
||||
fixWith: 'string',
|
||||
},
|
||||
Boolean: {
|
||||
message: 'Use boolean instead',
|
||||
fixWith: 'boolean',
|
||||
},
|
||||
Number: {
|
||||
message: 'Use number instead',
|
||||
fixWith: 'number',
|
||||
},
|
||||
Symbol: {
|
||||
message: 'Use symbol instead',
|
||||
fixWith: 'symbol',
|
||||
},
|
||||
Function: {
|
||||
message: [
|
||||
'The `Function` type accepts any function-like value.',
|
||||
'It provides no type safety when calling the function, which can be a common source of bugs.',
|
||||
'It also accepts things like class declarations, which will throw at runtime as they will not be called with `new`.',
|
||||
'If you are expecting the function to accept certain arguments, you should explicitly define the function shape.',
|
||||
].join('\n'),
|
||||
},
|
||||
// object typing
|
||||
Object: {
|
||||
message: [
|
||||
'The `Object` type actually means "any non-nullish value", so it is marginally better than `unknown`.',
|
||||
'- If you want a type meaning "any object", you probably want `Record<string, unknown>` instead.',
|
||||
'- If you want a type meaning "any value", you probably want `unknown` instead.',
|
||||
].join('\n'),
|
||||
},
|
||||
'{}': {
|
||||
message: [
|
||||
'`{}` actually means "any non-nullish value".',
|
||||
'- If you want a type meaning "any object", you probably want `Record<string, unknown>` instead.',
|
||||
'- If you want a type meaning "any value", you probably want `unknown` instead.',
|
||||
'- If you want a type meaning "empty object", you probably want `Record<string, never>` instead.',
|
||||
].join('\n'),
|
||||
},
|
||||
object: {
|
||||
message: [
|
||||
'The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)).',
|
||||
'Consider using `Record<string, unknown>` instead, as it allows you to more easily inspect and use the keys.',
|
||||
].join('\n'),
|
||||
},
|
||||
};
|
||||
exports.TYPE_KEYWORDS = {
|
||||
bigint: experimental_utils_1.AST_NODE_TYPES.TSBigIntKeyword,
|
||||
boolean: experimental_utils_1.AST_NODE_TYPES.TSBooleanKeyword,
|
||||
never: experimental_utils_1.AST_NODE_TYPES.TSNeverKeyword,
|
||||
null: experimental_utils_1.AST_NODE_TYPES.TSNullKeyword,
|
||||
number: experimental_utils_1.AST_NODE_TYPES.TSNumberKeyword,
|
||||
object: experimental_utils_1.AST_NODE_TYPES.TSObjectKeyword,
|
||||
string: experimental_utils_1.AST_NODE_TYPES.TSStringKeyword,
|
||||
symbol: experimental_utils_1.AST_NODE_TYPES.TSSymbolKeyword,
|
||||
undefined: experimental_utils_1.AST_NODE_TYPES.TSUndefinedKeyword,
|
||||
unknown: experimental_utils_1.AST_NODE_TYPES.TSUnknownKeyword,
|
||||
void: experimental_utils_1.AST_NODE_TYPES.TSVoidKeyword,
|
||||
};
|
||||
exports.default = util.createRule({
|
||||
name: 'ban-types',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Bans specific types from being used',
|
||||
category: 'Best Practices',
|
||||
recommended: 'error',
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
bannedTypeMessage: "Don't use `{{name}}` as a type.{{customMessage}}",
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
types: {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
oneOf: [
|
||||
{ type: 'null' },
|
||||
{ type: 'boolean' },
|
||||
{ type: 'string' },
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
message: { type: 'string' },
|
||||
fixWith: { type: 'string' },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
extendDefaults: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [{}],
|
||||
create(context, [options]) {
|
||||
var _a, _b;
|
||||
const extendDefaults = (_a = options.extendDefaults) !== null && _a !== void 0 ? _a : true;
|
||||
const customTypes = (_b = options.types) !== null && _b !== void 0 ? _b : {};
|
||||
const types = Object.assign({}, extendDefaults ? defaultTypes : {}, customTypes);
|
||||
const bannedTypes = new Map(Object.entries(types).map(([type, data]) => [removeSpaces(type), data]));
|
||||
function checkBannedTypes(typeNode, name = stringifyNode(typeNode, context.getSourceCode())) {
|
||||
const bannedType = bannedTypes.get(name);
|
||||
if (bannedType === undefined || bannedType === false) {
|
||||
return;
|
||||
}
|
||||
const customMessage = getCustomMessage(bannedType);
|
||||
const fixWith = bannedType && typeof bannedType === 'object' && bannedType.fixWith;
|
||||
context.report({
|
||||
node: typeNode,
|
||||
messageId: 'bannedTypeMessage',
|
||||
data: {
|
||||
name,
|
||||
customMessage,
|
||||
},
|
||||
fix: fixWith
|
||||
? (fixer) => fixer.replaceText(typeNode, fixWith)
|
||||
: null,
|
||||
});
|
||||
}
|
||||
const keywordSelectors = util.objectReduceKey(exports.TYPE_KEYWORDS, (acc, keyword) => {
|
||||
if (bannedTypes.has(keyword)) {
|
||||
acc[exports.TYPE_KEYWORDS[keyword]] = (node) => checkBannedTypes(node, keyword);
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
return Object.assign(Object.assign({}, keywordSelectors), { TSTypeLiteral(node) {
|
||||
if (node.members.length) {
|
||||
return;
|
||||
}
|
||||
checkBannedTypes(node);
|
||||
},
|
||||
TSTupleType(node) {
|
||||
if (node.elementTypes.length === 0) {
|
||||
checkBannedTypes(node);
|
||||
}
|
||||
},
|
||||
TSTypeReference(node) {
|
||||
checkBannedTypes(node.typeName);
|
||||
if (node.typeParameters) {
|
||||
checkBannedTypes(node);
|
||||
}
|
||||
} });
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=ban-types.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"ban-types.js","sourceRoot":"","sources":["../../src/rules/ban-types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,8EAI+C;AAC/C,8CAAgC;AAqBhC,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,aAAa,CACpB,IAAmB,EACnB,UAA+B;IAE/B,OAAO,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,gBAAgB,CACvB,UAAkE;IAElE,IAAI,UAAU,KAAK,IAAI,EAAE;QACvB,OAAO,EAAE,CAAC;K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EACb,CAAC,GAA0B,EAAE,OAAO,EAAE,EAAE;YACtC,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;gBAC5B,GAAG,CAAC,qBAAa,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,IAAmB,EAAQ,EAAE,CAC1D,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;aACnC;YAED,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAAE,CACH,CAAC;QAEF,uCACK,gBAAgB,KAEnB,aAAa,CAAC,IAAI;gBAChB,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;oBACvB,OAAO;iBACR;gBAED,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;YACD,WAAW,CAAC,IAAI;gBACd,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;oBAClC,gBAAgB,CAAC,IAAI,CAAC,CAAC;iBACxB;YACH,CAAC;YACD,eAAe,CAAC,IAAI;gBAClB,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAEhC,IAAI,IAAI,CAAC,cAAc,EAAE;oBACvB,gBAAgB,CAAC,IAAI,CAAC,CAAC;iBACxB;YACH,CAAC,IACD;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,94 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const brace_style_1 = __importDefault(require("eslint/lib/rules/brace-style"));
|
||||
const util_1 = require("../util");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'brace-style',
|
||||
meta: {
|
||||
type: 'layout',
|
||||
docs: {
|
||||
description: 'Enforce consistent brace style for blocks',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
messages: brace_style_1.default.meta.messages,
|
||||
fixable: brace_style_1.default.meta.fixable,
|
||||
schema: brace_style_1.default.meta.schema,
|
||||
},
|
||||
defaultOptions: ['1tbs'],
|
||||
create(context) {
|
||||
const [style, { allowSingleLine } = { allowSingleLine: false }] = context.options;
|
||||
const isAllmanStyle = style === 'allman';
|
||||
const sourceCode = context.getSourceCode();
|
||||
const rules = brace_style_1.default.create(context);
|
||||
/**
|
||||
* Checks a pair of curly brackets based on the user's config
|
||||
*/
|
||||
function validateCurlyPair(openingCurlyToken, closingCurlyToken) {
|
||||
if (allowSingleLine &&
|
||||
(0, util_1.isTokenOnSameLine)(openingCurlyToken, closingCurlyToken)) {
|
||||
return;
|
||||
}
|
||||
const tokenBeforeOpeningCurly = sourceCode.getTokenBefore(openingCurlyToken);
|
||||
const tokenBeforeClosingCurly = sourceCode.getTokenBefore(closingCurlyToken);
|
||||
const tokenAfterOpeningCurly = sourceCode.getTokenAfter(openingCurlyToken);
|
||||
if (!isAllmanStyle &&
|
||||
!(0, util_1.isTokenOnSameLine)(tokenBeforeOpeningCurly, openingCurlyToken)) {
|
||||
context.report({
|
||||
node: openingCurlyToken,
|
||||
messageId: 'nextLineOpen',
|
||||
fix: fixer => {
|
||||
const textRange = [
|
||||
tokenBeforeOpeningCurly.range[1],
|
||||
openingCurlyToken.range[0],
|
||||
];
|
||||
const textBetween = sourceCode.text.slice(textRange[0], textRange[1]);
|
||||
if (textBetween.trim()) {
|
||||
return null;
|
||||
}
|
||||
return fixer.replaceTextRange(textRange, ' ');
|
||||
},
|
||||
});
|
||||
}
|
||||
if (isAllmanStyle &&
|
||||
(0, util_1.isTokenOnSameLine)(tokenBeforeOpeningCurly, openingCurlyToken)) {
|
||||
context.report({
|
||||
node: openingCurlyToken,
|
||||
messageId: 'sameLineOpen',
|
||||
fix: fixer => fixer.insertTextBefore(openingCurlyToken, '\n'),
|
||||
});
|
||||
}
|
||||
if ((0, util_1.isTokenOnSameLine)(openingCurlyToken, tokenAfterOpeningCurly) &&
|
||||
tokenAfterOpeningCurly !== closingCurlyToken) {
|
||||
context.report({
|
||||
node: openingCurlyToken,
|
||||
messageId: 'blockSameLine',
|
||||
fix: fixer => fixer.insertTextAfter(openingCurlyToken, '\n'),
|
||||
});
|
||||
}
|
||||
if ((0, util_1.isTokenOnSameLine)(tokenBeforeClosingCurly, closingCurlyToken) &&
|
||||
tokenBeforeClosingCurly !== openingCurlyToken) {
|
||||
context.report({
|
||||
node: closingCurlyToken,
|
||||
messageId: 'singleLineClose',
|
||||
fix: fixer => fixer.insertTextBefore(closingCurlyToken, '\n'),
|
||||
});
|
||||
}
|
||||
}
|
||||
return Object.assign(Object.assign({}, rules), { 'TSInterfaceBody, TSModuleBlock'(node) {
|
||||
const openingCurly = sourceCode.getFirstToken(node);
|
||||
const closingCurly = sourceCode.getLastToken(node);
|
||||
validateCurlyPair(openingCurly, closingCurly);
|
||||
},
|
||||
TSEnumDeclaration(node) {
|
||||
const closingCurly = sourceCode.getLastToken(node);
|
||||
const openingCurly = sourceCode.getTokenBefore(node.members.length ? node.members[0] : closingCurly);
|
||||
validateCurlyPair(openingCurly, closingCurly);
|
||||
} });
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=brace-style.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"brace-style.js","sourceRoot":"","sources":["../../src/rules/brace-style.ts"],"names":[],"mappings":";;;;;AACA,+EAAoD;AACpD,kCAKiB;AAKjB,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,aAAa;IACnB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE;YACJ,WAAW,EAAE,2CAA2C;YACxD,QAAQ,EAAE,kBAAkB;YAC5B,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;SACtB;QACD,QAAQ,EAAE,qBAAQ,CAAC,IAAI,CAAC,QAAQ;QAChC,OAAO,EAAE,qBAAQ,CAAC,IAAI,CAAC,OAAO;QAC9B,MAAM,EAAE,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C,YAAY,CAAC,IAAI,CAAE,CAAC;gBAEpD,iBAAiB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;YAChD,CAAC;YACD,iBAAiB,CAAC,IAAI;gBACpB,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,CAAE,CAAC;gBACpD,MAAM,YAAY,GAAG,UAAU,CAAC,cAAc,CAC5C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CACpD,CAAC;gBAEH,iBAAiB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;YAChD,CAAC,IACD;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,114 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
const printNodeModifiers = (node, final) => {
|
||||
var _a;
|
||||
return `${(_a = node.accessibility) !== null && _a !== void 0 ? _a : ''}${node.static ? ' static' : ''} ${final} `.trimLeft();
|
||||
};
|
||||
const isSupportedLiteral = (node) => {
|
||||
if (node.type === experimental_utils_1.AST_NODE_TYPES.Literal) {
|
||||
return true;
|
||||
}
|
||||
if (node.type === experimental_utils_1.AST_NODE_TYPES.TaggedTemplateExpression ||
|
||||
node.type === experimental_utils_1.AST_NODE_TYPES.TemplateLiteral) {
|
||||
return ('quasi' in node ? node.quasi.quasis : node.quasis).length === 1;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
exports.default = util.createRule({
|
||||
name: 'class-literal-property-style',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Ensures that literals on classes are exposed in a consistent style',
|
||||
category: 'Best Practices',
|
||||
recommended: false,
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
preferFieldStyle: 'Literals should be exposed using readonly fields.',
|
||||
preferGetterStyle: 'Literals should be exposed using getters.',
|
||||
},
|
||||
schema: [{ enum: ['fields', 'getters'] }],
|
||||
},
|
||||
defaultOptions: ['fields'],
|
||||
create(context, [style]) {
|
||||
if (style === 'fields') {
|
||||
return {
|
||||
MethodDefinition(node) {
|
||||
if (node.kind !== 'get' ||
|
||||
!node.value.body ||
|
||||
!node.value.body.body.length) {
|
||||
return;
|
||||
}
|
||||
const [statement] = node.value.body.body;
|
||||
if (statement.type !== experimental_utils_1.AST_NODE_TYPES.ReturnStatement) {
|
||||
return;
|
||||
}
|
||||
const { argument } = statement;
|
||||
if (!argument || !isSupportedLiteral(argument)) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: node.key,
|
||||
messageId: 'preferFieldStyle',
|
||||
fix(fixer) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
const name = sourceCode.getText(node.key);
|
||||
let text = '';
|
||||
text += printNodeModifiers(node, 'readonly');
|
||||
text += node.computed ? `[${name}]` : name;
|
||||
text += ` = ${sourceCode.getText(argument)};`;
|
||||
return fixer.replaceText(node, text);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
ClassProperty(node) {
|
||||
if (!node.readonly || node.declare) {
|
||||
return;
|
||||
}
|
||||
const { value } = node;
|
||||
if (!value || !isSupportedLiteral(value)) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: node.key,
|
||||
messageId: 'preferGetterStyle',
|
||||
fix(fixer) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
const name = sourceCode.getText(node.key);
|
||||
let text = '';
|
||||
text += printNodeModifiers(node, 'get');
|
||||
text += node.computed ? `[${name}]` : name;
|
||||
text += `() { return ${sourceCode.getText(value)}; }`;
|
||||
return fixer.replaceText(node, text);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=class-literal-property-style.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"class-literal-property-style.js","sourceRoot":"","sources":["../../src/rules/class-literal-property-style.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8EAG+C;AAC/C,8CAAgC;AAUhC,MAAM,kBAAkB,GAAG,CACzB,IAAuB,EACvB,KAAyB,EACjB,EAAE;;IACV,OAAA,GAAG,MAAA,IAAI,CAAC,aAAa,mCAAI,EAAE,GACzB,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAC5B,IAAI,KAAK,GAAG,CAAC,QAAQ,EAAE,CAAA;CAAA,CAAC;AAE1B,MAAM,kBAAkB,GAAG,CACzB,IAAmB,EACiB,EAAE;IACtC,IAAI,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,OAAO,EAAE;QACxC,OAAO,IAAI,CAAC;KACb;IAED,IACE,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,wBAAwB;QACrD,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,eAAe,EAC5C;QACA,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CA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K,CAAC,CAAC;wBACxC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;wBAC3C,IAAI,IAAI,eAAe,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;wBAEtD,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBACvC,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,177 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const util = __importStar(require("../util"));
|
||||
const comma_dangle_1 = __importDefault(require("eslint/lib/rules/comma-dangle"));
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const OPTION_VALUE_SCHEME = [
|
||||
'always-multiline',
|
||||
'always',
|
||||
'never',
|
||||
'only-multiline',
|
||||
];
|
||||
const DEFAULT_OPTION_VALUE = 'never';
|
||||
function normalizeOptions(options) {
|
||||
var _a, _b, _c;
|
||||
if (typeof options === 'string') {
|
||||
return {
|
||||
enums: options,
|
||||
generics: options,
|
||||
tuples: options,
|
||||
};
|
||||
}
|
||||
return {
|
||||
enums: (_a = options.enums) !== null && _a !== void 0 ? _a : DEFAULT_OPTION_VALUE,
|
||||
generics: (_b = options.generics) !== null && _b !== void 0 ? _b : DEFAULT_OPTION_VALUE,
|
||||
tuples: (_c = options.tuples) !== null && _c !== void 0 ? _c : DEFAULT_OPTION_VALUE,
|
||||
};
|
||||
}
|
||||
exports.default = util.createRule({
|
||||
name: 'comma-dangle',
|
||||
meta: {
|
||||
type: 'layout',
|
||||
docs: {
|
||||
description: 'Require or disallow trailing comma',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
schema: {
|
||||
definitions: {
|
||||
value: {
|
||||
enum: OPTION_VALUE_SCHEME,
|
||||
},
|
||||
valueWithIgnore: {
|
||||
enum: [...OPTION_VALUE_SCHEME, 'ignore'],
|
||||
},
|
||||
},
|
||||
type: 'array',
|
||||
items: [
|
||||
{
|
||||
oneOf: [
|
||||
{
|
||||
$ref: '#/definitions/value',
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
arrays: { $ref: '#/definitions/valueWithIgnore' },
|
||||
objects: { $ref: '#/definitions/valueWithIgnore' },
|
||||
imports: { $ref: '#/definitions/valueWithIgnore' },
|
||||
exports: { $ref: '#/definitions/valueWithIgnore' },
|
||||
functions: { $ref: '#/definitions/valueWithIgnore' },
|
||||
enums: { $ref: '#/definitions/valueWithIgnore' },
|
||||
generics: { $ref: '#/definitions/valueWithIgnore' },
|
||||
tuples: { $ref: '#/definitions/valueWithIgnore' },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: comma_dangle_1.default.meta.messages,
|
||||
},
|
||||
defaultOptions: ['never'],
|
||||
create(context, [options]) {
|
||||
const rules = comma_dangle_1.default.create(context);
|
||||
const sourceCode = context.getSourceCode();
|
||||
const normalizedOptions = normalizeOptions(options);
|
||||
const predicate = {
|
||||
always: forceComma,
|
||||
'always-multiline': forceCommaIfMultiline,
|
||||
'only-multiline': allowCommaIfMultiline,
|
||||
never: forbidComma,
|
||||
ignore: () => { },
|
||||
};
|
||||
function last(nodes) {
|
||||
var _a;
|
||||
return (_a = nodes[nodes.length - 1]) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
function getLastItem(node) {
|
||||
switch (node.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSEnumDeclaration:
|
||||
return last(node.members);
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSTypeParameterDeclaration:
|
||||
return last(node.params);
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSTupleType:
|
||||
return last(node.elementTypes);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function getTrailingToken(node) {
|
||||
const last = getLastItem(node);
|
||||
const trailing = last && sourceCode.getTokenAfter(last);
|
||||
return trailing;
|
||||
}
|
||||
function isMultiline(node) {
|
||||
const last = getLastItem(node);
|
||||
const lastToken = sourceCode.getLastToken(node);
|
||||
return (last === null || last === void 0 ? void 0 : last.loc.end.line) !== (lastToken === null || lastToken === void 0 ? void 0 : lastToken.loc.end.line);
|
||||
}
|
||||
function forbidComma(node) {
|
||||
const last = getLastItem(node);
|
||||
const trailing = getTrailingToken(node);
|
||||
if (last && trailing && util.isCommaToken(trailing)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpected',
|
||||
fix(fixer) {
|
||||
return fixer.remove(trailing);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
function forceComma(node) {
|
||||
const last = getLastItem(node);
|
||||
const trailing = getTrailingToken(node);
|
||||
if (last && trailing && !util.isCommaToken(trailing)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'missing',
|
||||
fix(fixer) {
|
||||
return fixer.insertTextAfter(last, ',');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
function allowCommaIfMultiline(node) {
|
||||
if (!isMultiline(node)) {
|
||||
forbidComma(node);
|
||||
}
|
||||
}
|
||||
function forceCommaIfMultiline(node) {
|
||||
if (isMultiline(node)) {
|
||||
forceComma(node);
|
||||
}
|
||||
else {
|
||||
forbidComma(node);
|
||||
}
|
||||
}
|
||||
return Object.assign(Object.assign({}, rules), { TSEnumDeclaration: predicate[normalizedOptions.enums], TSTypeParameterDeclaration: predicate[normalizedOptions.generics], TSTupleType: predicate[normalizedOptions.tuples] });
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=comma-dangle.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"comma-dangle.js","sourceRoot":"","sources":["../../src/rules/comma-dangle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAgC;AAChC,iFAAqD;AACrD,8EAG+C;AAU/C,MAAM,mBAAmB,GAAG;IAC1B,kBAAkB;IAClB,QAAQ;IACR,OAAO;IACP,gBAAgB;CACjB,CAAC;AAEF,MAAM,oBAAoB,GAAG,OAAO,CAAC;AAErC,SAAS,gBAAgB,CAAC,OAAe;;IACvC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO;YACL,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,OAAO;YACjB,MAAM,EAAE,OAAO;SAChB,CAAC;KACH;IACD,OAAO;QACL,KAAK,EAAE,MAAA,OAAO,CAAC,KAAK,mCAAI,oBAAoB;QAC5C,QAAQ,EAAE,MAAA,OAAO,CAAC,QAAQ,mCAAI,oBAAoB;QAClD,MAAM,EAAE,MAAA,OAAO,CAAC,MAAM,mCAAI,oBAAoB;KAC/C,CAAC;AACJ,CAAC;AAED,kBAAe,IAAI,CAAC,UAAU,CAAs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AAC;aAClB;iBAAM;gBACL,WAAW,CAAC,IAAI,CAAC,CAAC;aACnB;QACH,CAAC;QAED,uCACK,KAAK,KACR,iBAAiB,EAAE,SAAS,CAAC,iBAAiB,CAAC,KAAK,CAAC,EACrD,0BAA0B,EAAE,SAAS,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EACjE,WAAW,EAAE,SAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAChD;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,144 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util_1 = require("../util");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'comma-spacing',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforces consistent spacing before and after commas',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
fixable: 'whitespace',
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
before: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
after: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
messages: {
|
||||
unexpected: `There should be no space {{loc}} ','.`,
|
||||
missing: `A space is required {{loc}} ','.`,
|
||||
},
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
before: false,
|
||||
after: true,
|
||||
},
|
||||
],
|
||||
create(context, [{ before: spaceBefore, after: spaceAfter }]) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
const tokensAndComments = sourceCode.tokensAndComments;
|
||||
const ignoredTokens = new Set();
|
||||
/**
|
||||
* Adds null elements of the ArrayExpression or ArrayPattern node to the ignore list
|
||||
* @param node node to evaluate
|
||||
*/
|
||||
function addNullElementsToIgnoreList(node) {
|
||||
let previousToken = sourceCode.getFirstToken(node);
|
||||
for (const element of node.elements) {
|
||||
let token;
|
||||
if (element === null) {
|
||||
token = sourceCode.getTokenAfter(previousToken);
|
||||
if (token && (0, util_1.isCommaToken)(token)) {
|
||||
ignoredTokens.add(token);
|
||||
}
|
||||
}
|
||||
else {
|
||||
token = sourceCode.getTokenAfter(element);
|
||||
}
|
||||
previousToken = token;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds type parameters trailing comma token to the ignore list
|
||||
* @param node node to evaluate
|
||||
*/
|
||||
function addTypeParametersTrailingCommaToIgnoreList(node) {
|
||||
const paramLength = node.params.length;
|
||||
if (paramLength) {
|
||||
const param = node.params[paramLength - 1];
|
||||
const afterToken = sourceCode.getTokenAfter(param);
|
||||
if (afterToken && (0, util_1.isCommaToken)(afterToken)) {
|
||||
ignoredTokens.add(afterToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Validates the spacing around a comma token.
|
||||
* @param commaToken The token representing the comma
|
||||
* @param prevToken The last token before the comma
|
||||
* @param nextToken The first token after the comma
|
||||
*/
|
||||
function validateCommaSpacing(commaToken, prevToken, nextToken) {
|
||||
if (prevToken &&
|
||||
(0, util_1.isTokenOnSameLine)(prevToken, commaToken) &&
|
||||
spaceBefore !== sourceCode.isSpaceBetweenTokens(prevToken, commaToken)) {
|
||||
context.report({
|
||||
node: commaToken,
|
||||
data: {
|
||||
loc: 'before',
|
||||
},
|
||||
messageId: spaceBefore ? 'missing' : 'unexpected',
|
||||
fix: fixer => spaceBefore
|
||||
? fixer.insertTextBefore(commaToken, ' ')
|
||||
: fixer.replaceTextRange([prevToken.range[1], commaToken.range[0]], ''),
|
||||
});
|
||||
}
|
||||
if (nextToken && (0, util_1.isClosingParenToken)(nextToken)) {
|
||||
return;
|
||||
}
|
||||
if (!spaceAfter && nextToken && nextToken.type === experimental_utils_1.AST_TOKEN_TYPES.Line) {
|
||||
return;
|
||||
}
|
||||
if (nextToken &&
|
||||
(0, util_1.isTokenOnSameLine)(commaToken, nextToken) &&
|
||||
spaceAfter !== sourceCode.isSpaceBetweenTokens(commaToken, nextToken)) {
|
||||
context.report({
|
||||
node: commaToken,
|
||||
data: {
|
||||
loc: 'after',
|
||||
},
|
||||
messageId: spaceAfter ? 'missing' : 'unexpected',
|
||||
fix: fixer => spaceAfter
|
||||
? fixer.insertTextAfter(commaToken, ' ')
|
||||
: fixer.replaceTextRange([commaToken.range[1], nextToken.range[0]], ''),
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
TSTypeParameterDeclaration: addTypeParametersTrailingCommaToIgnoreList,
|
||||
ArrayExpression: addNullElementsToIgnoreList,
|
||||
ArrayPattern: addNullElementsToIgnoreList,
|
||||
'Program:exit'() {
|
||||
tokensAndComments.forEach((token, i) => {
|
||||
if (!(0, util_1.isCommaToken)(token)) {
|
||||
return;
|
||||
}
|
||||
const prevToken = tokensAndComments[i - 1];
|
||||
const nextToken = tokensAndComments[i + 1];
|
||||
validateCommaSpacing(token, (0, util_1.isCommaToken)(prevToken) || ignoredTokens.has(token)
|
||||
? null
|
||||
: prevToken, (0, util_1.isCommaToken)(nextToken) || ignoredTokens.has(token)
|
||||
? null
|
||||
: nextToken);
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=comma-spacing.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"comma-spacing.js","sourceRoot":"","sources":["../../src/rules/comma-spacing.ts"],"names":[],"mappings":";;AAAA,8EAG+C;AAC/C,kCAKiB;AAUjB,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,qDAAqD;YAClE,QAAQ,EAAE,kBAAkB;YAC5B,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;SACtB;QACD,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE;YACN;g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aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;wBACjD,CAAC,CAAC,IAAI;wBACN,CAAC,CAAC,SAAS,CACd,CAAC;gBACJ,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,109 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const util_1 = require("../util");
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'consistent-indexed-object-style',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforce or disallow the use of the record type',
|
||||
category: 'Stylistic Issues',
|
||||
// too opinionated to be recommended
|
||||
recommended: false,
|
||||
},
|
||||
messages: {
|
||||
preferRecord: 'A record is preferred over an index signature.',
|
||||
preferIndexSignature: 'An index signature is preferred over a record.',
|
||||
},
|
||||
fixable: 'code',
|
||||
schema: [
|
||||
{
|
||||
enum: ['record', 'index-signature'],
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: ['record'],
|
||||
create(context) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
if (context.options[0] === 'index-signature') {
|
||||
return {
|
||||
TSTypeReference(node) {
|
||||
var _a;
|
||||
const typeName = node.typeName;
|
||||
if (typeName.type !== experimental_utils_1.AST_NODE_TYPES.Identifier) {
|
||||
return;
|
||||
}
|
||||
if (typeName.name !== 'Record') {
|
||||
return;
|
||||
}
|
||||
const params = (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.params;
|
||||
if ((params === null || params === void 0 ? void 0 : params.length) !== 2) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'preferIndexSignature',
|
||||
fix(fixer) {
|
||||
const key = sourceCode.getText(params[0]);
|
||||
const type = sourceCode.getText(params[1]);
|
||||
return fixer.replaceText(node, `{ [key: ${key}]: ${type} }`);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
function checkMembers(members, node, prefix, postfix, safeFix = true) {
|
||||
if (members.length !== 1) {
|
||||
return;
|
||||
}
|
||||
const [member] = members;
|
||||
if (member.type !== experimental_utils_1.AST_NODE_TYPES.TSIndexSignature) {
|
||||
return;
|
||||
}
|
||||
const [parameter] = member.parameters;
|
||||
if (!parameter) {
|
||||
return;
|
||||
}
|
||||
if (parameter.type !== experimental_utils_1.AST_NODE_TYPES.Identifier) {
|
||||
return;
|
||||
}
|
||||
const keyType = parameter.typeAnnotation;
|
||||
if (!keyType) {
|
||||
return;
|
||||
}
|
||||
const valueType = member.typeAnnotation;
|
||||
if (!valueType) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'preferRecord',
|
||||
fix: safeFix
|
||||
? (fixer) => {
|
||||
const key = sourceCode.getText(keyType.typeAnnotation);
|
||||
const value = sourceCode.getText(valueType.typeAnnotation);
|
||||
const record = member.readonly
|
||||
? `Readonly<Record<${key}, ${value}>>`
|
||||
: `Record<${key}, ${value}>`;
|
||||
return fixer.replaceText(node, `${prefix}${record}${postfix}`);
|
||||
}
|
||||
: null,
|
||||
});
|
||||
}
|
||||
return {
|
||||
TSTypeLiteral(node) {
|
||||
checkMembers(node.members, node, '', '');
|
||||
},
|
||||
TSInterfaceDeclaration(node) {
|
||||
var _a, _b, _c, _d;
|
||||
let genericTypes = '';
|
||||
if (((_b = (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.params) !== null && _b !== void 0 ? _b : []).length > 0) {
|
||||
genericTypes = `<${(_c = node.typeParameters) === null || _c === void 0 ? void 0 : _c.params.map(p => p.name.name).join(', ')}>`;
|
||||
}
|
||||
checkMembers(node.body.body, node, `type ${node.id.name}${genericTypes} = `, ';', !((_d = node.extends) === null || _d === void 0 ? void 0 : _d.length));
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=consistent-indexed-object-style.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"consistent-indexed-object-style.js","sourceRoot":"","sources":["../../src/rules/consistent-indexed-object-style.ts"],"names":[],"mappings":";;AAAA,kCAAqC;AACrC,8EAI+C;AAK/C,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,iCAAiC;IACvC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,gDAAgD;YAC7D,QAAQ,EAAE,kBAAkB;YAC5B,oCAAoC;YACpC,WAAW,EAAE,KAAK;SACnB;QACD,QAAQ,EAAE;YACR,YAAY,EAAE,gDAAgD;YAC9D,oBAAoB,EAAE,gDAAgD;SACvE;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,CAAC,QAAQ,EAAE,iBAAiB,CAAC;aACpC;SACF;KACF;IACD,cAAc,EAAE,CAAC,QAAQ,CAAC;IAC1B,MAAM,CAAC,OAAO;QACZ,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAE3C,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAE;YAC5C,OAAO;gBACL,eAAe,CAAC,IAAI;;oBAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;oBAC/B,IAAI,QAAQ,CAAC,IAAI,KAAK,mCAAc,CAAC,UAAU,EAAE;wBAC/C,OAAO;qBACR;oBACD,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE;wBAC9B,OAAO;qBACR;oBAED,MAAM,MAAM,GAAG,MAAA,IAAI,CAAC,cAAc,0CAAE,MAAM,CAAC;oBAC3C,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,MAAK,CAAC,EAAE;wBACxB,OAAO;qBACR;oBAED,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,SAAS,EAAE,sBAAsB;wBACjC,GAAG,CAA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k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const util = __importStar(require("../util"));
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
exports.default = util.createRule({
|
||||
name: 'consistent-type-assertions',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Enforces consistent usage of type assertions',
|
||||
recommended: false,
|
||||
},
|
||||
messages: {
|
||||
as: "Use 'as {{cast}}' instead of '<{{cast}}>'.",
|
||||
'angle-bracket': "Use '<{{cast}}>' instead of 'as {{cast}}'.",
|
||||
never: 'Do not use any type assertions.',
|
||||
unexpectedObjectTypeAssertion: 'Always prefer const x: T = { ... }.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
oneOf: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
assertionStyle: {
|
||||
enum: ['never'],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
required: ['assertionStyle'],
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
assertionStyle: {
|
||||
enum: ['as', 'angle-bracket'],
|
||||
},
|
||||
objectLiteralTypeAssertions: {
|
||||
enum: ['allow', 'allow-as-parameter', 'never'],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
required: ['assertionStyle'],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
assertionStyle: 'as',
|
||||
objectLiteralTypeAssertions: 'allow',
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
function isConst(node) {
|
||||
if (node.type !== experimental_utils_1.AST_NODE_TYPES.TSTypeReference) {
|
||||
return false;
|
||||
}
|
||||
return (node.typeName.type === experimental_utils_1.AST_NODE_TYPES.Identifier &&
|
||||
node.typeName.name === 'const');
|
||||
}
|
||||
function reportIncorrectAssertionType(node) {
|
||||
// If this node is `as const`, then don't report an error.
|
||||
if (isConst(node.typeAnnotation)) {
|
||||
return;
|
||||
}
|
||||
const messageId = options.assertionStyle;
|
||||
context.report({
|
||||
node,
|
||||
messageId,
|
||||
data: messageId !== 'never'
|
||||
? { cast: sourceCode.getText(node.typeAnnotation) }
|
||||
: {},
|
||||
});
|
||||
}
|
||||
function checkType(node) {
|
||||
switch (node.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSAnyKeyword:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSUnknownKeyword:
|
||||
return false;
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSTypeReference:
|
||||
return (
|
||||
// Ignore `as const` and `<const>`
|
||||
!isConst(node) ||
|
||||
// Allow qualified names which have dots between identifiers, `Foo.Bar`
|
||||
node.typeName.type === experimental_utils_1.AST_NODE_TYPES.TSQualifiedName);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function checkExpression(node) {
|
||||
if (options.assertionStyle === 'never' ||
|
||||
options.objectLiteralTypeAssertions === 'allow' ||
|
||||
node.expression.type !== experimental_utils_1.AST_NODE_TYPES.ObjectExpression) {
|
||||
return;
|
||||
}
|
||||
if (options.objectLiteralTypeAssertions === 'allow-as-parameter' &&
|
||||
node.parent &&
|
||||
(node.parent.type === experimental_utils_1.AST_NODE_TYPES.NewExpression ||
|
||||
node.parent.type === experimental_utils_1.AST_NODE_TYPES.CallExpression ||
|
||||
node.parent.type === experimental_utils_1.AST_NODE_TYPES.ThrowStatement ||
|
||||
node.parent.type === experimental_utils_1.AST_NODE_TYPES.AssignmentPattern ||
|
||||
node.parent.type === experimental_utils_1.AST_NODE_TYPES.JSXExpressionContainer)) {
|
||||
return;
|
||||
}
|
||||
if (checkType(node.typeAnnotation) &&
|
||||
node.expression.type === experimental_utils_1.AST_NODE_TYPES.ObjectExpression) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpectedObjectTypeAssertion',
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
TSTypeAssertion(node) {
|
||||
if (options.assertionStyle !== 'angle-bracket') {
|
||||
reportIncorrectAssertionType(node);
|
||||
return;
|
||||
}
|
||||
checkExpression(node);
|
||||
},
|
||||
TSAsExpression(node) {
|
||||
if (options.assertionStyle !== 'as') {
|
||||
reportIncorrectAssertionType(node);
|
||||
return;
|
||||
}
|
||||
checkExpression(node);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=consistent-type-assertions.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"consistent-type-assertions.js","sourceRoot":"","sources":["../../src/rules/consistent-type-assertions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8CAAgC;AAChC,8EAG+C;AAkB/C,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,8CAA8C;YAC3D,WAAW,EAAE,KAAK;SACnB;QACD,QAAQ,EAAE;YACR,EAAE,EAAE,4CAA4C;YAChD,eAAe,EAAE,4CAA4C;YAC7D,KAAK,EAAE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gBACA,OAAO;aACR;YAED,IACE,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC;gBAC9B,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,mCAAc,CAAC,gBAAgB,EACxD;gBACA,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAE,+BAA+B;iBAC3C,CAAC,CAAC;aACJ;QACH,CAAC;QAED,OAAO;YACL,eAAe,CAAC,IAAI;gBAClB,IAAI,OAAO,CAAC,cAAc,KAAK,eAAe,EAAE;oBAC9C,4BAA4B,CAAC,IAAI,CAAC,CAAC;oBACnC,OAAO;iBACR;gBAED,eAAe,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;YACD,cAAc,CAAC,IAAI;gBACjB,IAAI,OAAO,CAAC,cAAc,KAAK,IAAI,EAAE;oBACnC,4BAA4B,CAAC,IAAI,CAAC,CAAC;oBACnC,OAAO;iBACR;gBAED,eAAe,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,123 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
exports.default = util.createRule({
|
||||
name: 'consistent-type-definitions',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Consistent with type definition either `interface` or `type`',
|
||||
category: 'Stylistic Issues',
|
||||
// too opinionated to be recommended
|
||||
recommended: false,
|
||||
},
|
||||
messages: {
|
||||
interfaceOverType: 'Use an `interface` instead of a `type`.',
|
||||
typeOverInterface: 'Use a `type` instead of an `interface`.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
enum: ['interface', 'type'],
|
||||
},
|
||||
],
|
||||
fixable: 'code',
|
||||
},
|
||||
defaultOptions: ['interface'],
|
||||
create(context, [option]) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
/**
|
||||
* Iterates from the highest parent to the currently traversed node
|
||||
* to determine whether any node in tree is globally declared module declaration
|
||||
*/
|
||||
function isCurrentlyTraversedNodeWithinModuleDeclaration() {
|
||||
return context
|
||||
.getAncestors()
|
||||
.some(node => node.type === experimental_utils_1.AST_NODE_TYPES.TSModuleDeclaration &&
|
||||
node.declare &&
|
||||
node.global);
|
||||
}
|
||||
return {
|
||||
"TSTypeAliasDeclaration[typeAnnotation.type='TSTypeLiteral']"(node) {
|
||||
if (option === 'interface') {
|
||||
context.report({
|
||||
node: node.id,
|
||||
messageId: 'interfaceOverType',
|
||||
fix(fixer) {
|
||||
var _a;
|
||||
const typeNode = (_a = node.typeParameters) !== null && _a !== void 0 ? _a : node.id;
|
||||
const fixes = [];
|
||||
const firstToken = sourceCode.getFirstToken(node);
|
||||
if (firstToken) {
|
||||
fixes.push(fixer.replaceText(firstToken, 'interface'));
|
||||
fixes.push(fixer.replaceTextRange([typeNode.range[1], node.typeAnnotation.range[0]], ' '));
|
||||
}
|
||||
const afterToken = sourceCode.getTokenAfter(node.typeAnnotation);
|
||||
if (afterToken &&
|
||||
afterToken.type === experimental_utils_1.AST_TOKEN_TYPES.Punctuator &&
|
||||
afterToken.value === ';') {
|
||||
fixes.push(fixer.remove(afterToken));
|
||||
}
|
||||
return fixes;
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
TSInterfaceDeclaration(node) {
|
||||
if (option === 'type') {
|
||||
context.report({
|
||||
node: node.id,
|
||||
messageId: 'typeOverInterface',
|
||||
/**
|
||||
* remove automatically fix when the interface is within a declare global
|
||||
* @see {@link https://github.com/typescript-eslint/typescript-eslint/issues/2707}
|
||||
*/
|
||||
fix: isCurrentlyTraversedNodeWithinModuleDeclaration()
|
||||
? null
|
||||
: (fixer) => {
|
||||
var _a, _b;
|
||||
const typeNode = (_a = node.typeParameters) !== null && _a !== void 0 ? _a : node.id;
|
||||
const fixes = [];
|
||||
const firstToken = sourceCode.getFirstToken(node);
|
||||
if (firstToken) {
|
||||
fixes.push(fixer.replaceText(firstToken, 'type'));
|
||||
fixes.push(fixer.replaceTextRange([typeNode.range[1], node.body.range[0]], ' = '));
|
||||
}
|
||||
if (node.extends) {
|
||||
node.extends.forEach(heritage => {
|
||||
const typeIdentifier = sourceCode.getText(heritage);
|
||||
fixes.push(fixer.insertTextAfter(node.body, ` & ${typeIdentifier}`));
|
||||
});
|
||||
}
|
||||
if (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) ===
|
||||
experimental_utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
||||
fixes.push(fixer.removeRange([node.parent.range[0], node.range[0]]), fixer.insertTextAfter(node.body, `\nexport default ${node.id.name}`));
|
||||
}
|
||||
return fixes;
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=consistent-type-definitions.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"consistent-type-definitions.js","sourceRoot":"","sources":["../../src/rules/consistent-type-definitions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;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,IAAI,CACR,KAAK,CAAC,gBAAgB,CACpB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACvC,KAAK,CACN,CACF,CAAC;iCACH;gCAED,IAAI,IAAI,CAAC,OAAO,EAAE;oCAChB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;wCAC9B,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;wCACpD,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,eAAe,CACnB,IAAI,CAAC,IAAI,EACT,MAAM,cAAc,EAAE,CACvB,CACF,CAAC;oCACJ,CAAC,CAAC,CAAC;iCACJ;gCAED,IACE,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI;oCACjB,mCAAc,CAAC,wBAAwB,EACvC;oCACA,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EACxD,KAAK,CAAC,eAAe,CACnB,IAAI,CAAC,IAAI,EACT,oBAAoB,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CACnC,CACF,CAAC;iCACH;gCAED,OAAO,KAAK,CAAC;4BACf,CAAC;qBACN,CAAC,CAAC;iBACJ;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,556 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
function isImportToken(token) {
|
||||
return token.type === experimental_utils_1.AST_TOKEN_TYPES.Keyword && token.value === 'import';
|
||||
}
|
||||
function isTypeToken(token) {
|
||||
return token.type === experimental_utils_1.AST_TOKEN_TYPES.Identifier && token.value === 'type';
|
||||
}
|
||||
exports.default = util.createRule({
|
||||
name: 'consistent-type-imports',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforces consistent usage of type imports',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
},
|
||||
messages: {
|
||||
typeOverValue: 'All imports in the declaration are only used as types. Use `import type`.',
|
||||
someImportsAreOnlyTypes: 'Imports {{typeImports}} are only used as types.',
|
||||
aImportIsOnlyTypes: 'Import {{typeImports}} is only used as types.',
|
||||
someImportsInDecoMeta: 'Type imports {{typeImports}} are used by decorator metadata.',
|
||||
aImportInDecoMeta: 'Type import {{typeImports}} is used by decorator metadata.',
|
||||
valueOverType: 'Use an `import` instead of an `import type`.',
|
||||
noImportTypeAnnotations: '`import()` type annotations are forbidden.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
prefer: {
|
||||
enum: ['type-imports', 'no-type-imports'],
|
||||
},
|
||||
disallowTypeAnnotations: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
fixable: 'code',
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
prefer: 'type-imports',
|
||||
disallowTypeAnnotations: true,
|
||||
},
|
||||
],
|
||||
create(context, [option]) {
|
||||
var _a;
|
||||
const prefer = (_a = option.prefer) !== null && _a !== void 0 ? _a : 'type-imports';
|
||||
const disallowTypeAnnotations = option.disallowTypeAnnotations !== false;
|
||||
const sourceCode = context.getSourceCode();
|
||||
const sourceImportsMap = {};
|
||||
return Object.assign(Object.assign({}, (prefer === 'type-imports'
|
||||
? {
|
||||
// prefer type imports
|
||||
ImportDeclaration(node) {
|
||||
var _a;
|
||||
const source = node.source.value;
|
||||
const sourceImports = (_a = sourceImportsMap[source]) !== null && _a !== void 0 ? _a : (sourceImportsMap[source] = {
|
||||
source,
|
||||
reportValueImports: [],
|
||||
typeOnlyNamedImport: null,
|
||||
valueOnlyNamedImport: null,
|
||||
});
|
||||
if (node.importKind === 'type') {
|
||||
if (!sourceImports.typeOnlyNamedImport &&
|
||||
node.specifiers.every(specifier => specifier.type === experimental_utils_1.AST_NODE_TYPES.ImportSpecifier)) {
|
||||
sourceImports.typeOnlyNamedImport = node;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!sourceImports.valueOnlyNamedImport &&
|
||||
node.specifiers.every(specifier => specifier.type === experimental_utils_1.AST_NODE_TYPES.ImportSpecifier)) {
|
||||
sourceImports.valueOnlyNamedImport = node;
|
||||
}
|
||||
}
|
||||
const typeSpecifiers = [];
|
||||
const valueSpecifiers = [];
|
||||
const unusedSpecifiers = [];
|
||||
for (const specifier of node.specifiers) {
|
||||
const [variable] = context.getDeclaredVariables(specifier);
|
||||
if (variable.references.length === 0) {
|
||||
unusedSpecifiers.push(specifier);
|
||||
}
|
||||
else {
|
||||
const onlyHasTypeReferences = variable.references.every(ref => {
|
||||
var _a, _b;
|
||||
/**
|
||||
* keep origin import kind when export
|
||||
* export { Type }
|
||||
* export default Type;
|
||||
*/
|
||||
if (((_a = ref.identifier.parent) === null || _a === void 0 ? void 0 : _a.type) ===
|
||||
experimental_utils_1.AST_NODE_TYPES.ExportSpecifier ||
|
||||
((_b = ref.identifier.parent) === null || _b === void 0 ? void 0 : _b.type) ===
|
||||
experimental_utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
||||
if (ref.isValueReference && ref.isTypeReference) {
|
||||
return node.importKind === 'type';
|
||||
}
|
||||
}
|
||||
if (ref.isValueReference) {
|
||||
let parent = ref.identifier.parent;
|
||||
let child = ref.identifier;
|
||||
while (parent) {
|
||||
switch (parent.type) {
|
||||
// CASE 1:
|
||||
// `type T = typeof foo` will create a value reference because "foo" must be a value type
|
||||
// however this value reference is safe to use with type-only imports
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSTypeQuery:
|
||||
return true;
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSQualifiedName:
|
||||
// TSTypeQuery must have a TSESTree.EntityName as its child, so we can filter here and break early
|
||||
if (parent.left !== child) {
|
||||
return false;
|
||||
}
|
||||
child = parent;
|
||||
parent = parent.parent;
|
||||
continue;
|
||||
// END CASE 1
|
||||
//////////////
|
||||
// CASE 2:
|
||||
// `type T = { [foo]: string }` will create a value reference because "foo" must be a value type
|
||||
// however this value reference is safe to use with type-only imports.
|
||||
// Also this is represented as a non-type AST - hence it uses MemberExpression
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSPropertySignature:
|
||||
return parent.key === child;
|
||||
case experimental_utils_1.AST_NODE_TYPES.MemberExpression:
|
||||
if (parent.object !== child) {
|
||||
return false;
|
||||
}
|
||||
child = parent;
|
||||
parent = parent.parent;
|
||||
continue;
|
||||
// END CASE 2
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ref.isTypeReference;
|
||||
});
|
||||
if (onlyHasTypeReferences) {
|
||||
typeSpecifiers.push(specifier);
|
||||
}
|
||||
else {
|
||||
valueSpecifiers.push(specifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((node.importKind === 'value' && typeSpecifiers.length) ||
|
||||
(node.importKind === 'type' && valueSpecifiers.length)) {
|
||||
sourceImports.reportValueImports.push({
|
||||
node,
|
||||
typeSpecifiers,
|
||||
valueSpecifiers,
|
||||
unusedSpecifiers,
|
||||
});
|
||||
}
|
||||
},
|
||||
'Program:exit'() {
|
||||
for (const sourceImports of Object.values(sourceImportsMap)) {
|
||||
if (sourceImports.reportValueImports.length === 0) {
|
||||
continue;
|
||||
}
|
||||
for (const report of sourceImports.reportValueImports) {
|
||||
if (report.valueSpecifiers.length === 0 &&
|
||||
report.unusedSpecifiers.length === 0) {
|
||||
// import is all type-only, convert the entire import to `import type`
|
||||
context.report({
|
||||
node: report.node,
|
||||
messageId: 'typeOverValue',
|
||||
*fix(fixer) {
|
||||
yield* fixToTypeImport(fixer, report, sourceImports);
|
||||
},
|
||||
});
|
||||
}
|
||||
else {
|
||||
const isTypeImport = report.node.importKind === 'type';
|
||||
// we have a mixed type/value import, so we need to split them out into multiple exports
|
||||
const importNames = (isTypeImport
|
||||
? report.valueSpecifiers
|
||||
: report.typeSpecifiers).map(specifier => `"${specifier.local.name}"`);
|
||||
const message = (() => {
|
||||
if (importNames.length === 1) {
|
||||
const typeImports = importNames[0];
|
||||
if (isTypeImport) {
|
||||
return {
|
||||
messageId: 'aImportInDecoMeta',
|
||||
data: { typeImports },
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
messageId: 'aImportIsOnlyTypes',
|
||||
data: { typeImports },
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
const typeImports = [
|
||||
importNames.slice(0, -1).join(', '),
|
||||
importNames.slice(-1)[0],
|
||||
].join(' and ');
|
||||
if (isTypeImport) {
|
||||
return {
|
||||
messageId: 'someImportsInDecoMeta',
|
||||
data: { typeImports },
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
messageId: 'someImportsAreOnlyTypes',
|
||||
data: { typeImports },
|
||||
};
|
||||
}
|
||||
}
|
||||
})();
|
||||
context.report(Object.assign(Object.assign({ node: report.node }, message), { *fix(fixer) {
|
||||
if (isTypeImport) {
|
||||
yield* fixToValueImportInDecoMeta(fixer, report, sourceImports);
|
||||
}
|
||||
else {
|
||||
yield* fixToTypeImport(fixer, report, sourceImports);
|
||||
}
|
||||
} }));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
: {
|
||||
// prefer no type imports
|
||||
'ImportDeclaration[importKind = "type"]'(node) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'valueOverType',
|
||||
fix(fixer) {
|
||||
return fixToValueImport(fixer, node);
|
||||
},
|
||||
});
|
||||
},
|
||||
})), (disallowTypeAnnotations
|
||||
? {
|
||||
// disallow `import()` type
|
||||
TSImportType(node) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'noImportTypeAnnotations',
|
||||
});
|
||||
},
|
||||
}
|
||||
: {}));
|
||||
function classifySpecifier(node) {
|
||||
var _a;
|
||||
const defaultSpecifier = node.specifiers[0].type === experimental_utils_1.AST_NODE_TYPES.ImportDefaultSpecifier
|
||||
? node.specifiers[0]
|
||||
: null;
|
||||
const namespaceSpecifier = (_a = node.specifiers.find((specifier) => specifier.type === experimental_utils_1.AST_NODE_TYPES.ImportNamespaceSpecifier)) !== null && _a !== void 0 ? _a : null;
|
||||
const namedSpecifiers = node.specifiers.filter((specifier) => specifier.type === experimental_utils_1.AST_NODE_TYPES.ImportSpecifier);
|
||||
return {
|
||||
defaultSpecifier,
|
||||
namespaceSpecifier,
|
||||
namedSpecifiers,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Returns information for fixing named specifiers.
|
||||
*/
|
||||
function getFixesNamedSpecifiers(fixer, node, typeNamedSpecifiers, allNamedSpecifiers) {
|
||||
if (allNamedSpecifiers.length === 0) {
|
||||
return {
|
||||
typeNamedSpecifiersText: '',
|
||||
removeTypeNamedSpecifiers: [],
|
||||
};
|
||||
}
|
||||
const typeNamedSpecifiersTexts = [];
|
||||
const removeTypeNamedSpecifiers = [];
|
||||
if (typeNamedSpecifiers.length === allNamedSpecifiers.length) {
|
||||
// e.g.
|
||||
// import Foo, {Type1, Type2} from 'foo'
|
||||
// import DefType, {Type1, Type2} from 'foo'
|
||||
const openingBraceToken = util.nullThrows(sourceCode.getTokenBefore(typeNamedSpecifiers[0], util.isOpeningBraceToken), util.NullThrowsReasons.MissingToken('{', node.type));
|
||||
const commaToken = util.nullThrows(sourceCode.getTokenBefore(openingBraceToken, util.isCommaToken), util.NullThrowsReasons.MissingToken(',', node.type));
|
||||
const closingBraceToken = util.nullThrows(sourceCode.getFirstTokenBetween(openingBraceToken, node.source, util.isClosingBraceToken), util.NullThrowsReasons.MissingToken('}', node.type));
|
||||
// import DefType, {...} from 'foo'
|
||||
// ^^^^^^^ remove
|
||||
removeTypeNamedSpecifiers.push(fixer.removeRange([commaToken.range[0], closingBraceToken.range[1]]));
|
||||
typeNamedSpecifiersTexts.push(sourceCode.text.slice(openingBraceToken.range[1], closingBraceToken.range[0]));
|
||||
}
|
||||
else {
|
||||
const typeNamedSpecifierGroups = [];
|
||||
let group = [];
|
||||
for (const namedSpecifier of allNamedSpecifiers) {
|
||||
if (typeNamedSpecifiers.includes(namedSpecifier)) {
|
||||
group.push(namedSpecifier);
|
||||
}
|
||||
else if (group.length) {
|
||||
typeNamedSpecifierGroups.push(group);
|
||||
group = [];
|
||||
}
|
||||
}
|
||||
if (group.length) {
|
||||
typeNamedSpecifierGroups.push(group);
|
||||
}
|
||||
for (const namedSpecifiers of typeNamedSpecifierGroups) {
|
||||
const { removeRange, textRange } = getNamedSpecifierRanges(namedSpecifiers, allNamedSpecifiers);
|
||||
removeTypeNamedSpecifiers.push(fixer.removeRange(removeRange));
|
||||
typeNamedSpecifiersTexts.push(sourceCode.text.slice(...textRange));
|
||||
}
|
||||
}
|
||||
return {
|
||||
typeNamedSpecifiersText: typeNamedSpecifiersTexts.join(','),
|
||||
removeTypeNamedSpecifiers,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Returns ranges for fixing named specifier.
|
||||
*/
|
||||
function getNamedSpecifierRanges(namedSpecifierGroup, allNamedSpecifiers) {
|
||||
const first = namedSpecifierGroup[0];
|
||||
const last = namedSpecifierGroup[namedSpecifierGroup.length - 1];
|
||||
const removeRange = [first.range[0], last.range[1]];
|
||||
const textRange = [...removeRange];
|
||||
const before = sourceCode.getTokenBefore(first);
|
||||
textRange[0] = before.range[1];
|
||||
if (util.isCommaToken(before)) {
|
||||
removeRange[0] = before.range[0];
|
||||
}
|
||||
else {
|
||||
removeRange[0] = before.range[1];
|
||||
}
|
||||
const isFirst = allNamedSpecifiers[0] === first;
|
||||
const isLast = allNamedSpecifiers[allNamedSpecifiers.length - 1] === last;
|
||||
const after = sourceCode.getTokenAfter(last);
|
||||
textRange[1] = after.range[0];
|
||||
if (isFirst || isLast) {
|
||||
if (util.isCommaToken(after)) {
|
||||
removeRange[1] = after.range[1];
|
||||
}
|
||||
}
|
||||
return {
|
||||
textRange,
|
||||
removeRange,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* insert specifiers to named import node.
|
||||
* e.g.
|
||||
* import type { Already, Type1, Type2 } from 'foo'
|
||||
* ^^^^^^^^^^^^^ insert
|
||||
*/
|
||||
function insertToNamedImport(fixer, target, insertText) {
|
||||
const closingBraceToken = util.nullThrows(sourceCode.getFirstTokenBetween(sourceCode.getFirstToken(target), target.source, util.isClosingBraceToken), util.NullThrowsReasons.MissingToken('}', target.type));
|
||||
const before = sourceCode.getTokenBefore(closingBraceToken);
|
||||
if (!util.isCommaToken(before) && !util.isOpeningBraceToken(before)) {
|
||||
insertText = ',' + insertText;
|
||||
}
|
||||
return fixer.insertTextBefore(closingBraceToken, insertText);
|
||||
}
|
||||
function* fixToTypeImport(fixer, report, sourceImports) {
|
||||
const { node } = report;
|
||||
const { defaultSpecifier, namespaceSpecifier, namedSpecifiers } = classifySpecifier(node);
|
||||
if (namespaceSpecifier && !defaultSpecifier) {
|
||||
// e.g.
|
||||
// import * as types from 'foo'
|
||||
yield* fixToTypeImportByInsertType(fixer, node, false);
|
||||
return;
|
||||
}
|
||||
else if (defaultSpecifier) {
|
||||
if (report.typeSpecifiers.includes(defaultSpecifier) &&
|
||||
namedSpecifiers.length === 0 &&
|
||||
!namespaceSpecifier) {
|
||||
// e.g.
|
||||
// import Type from 'foo'
|
||||
yield* fixToTypeImportByInsertType(fixer, node, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (namedSpecifiers.every(specifier => report.typeSpecifiers.includes(specifier)) &&
|
||||
!namespaceSpecifier) {
|
||||
// e.g.
|
||||
// import {Type1, Type2} from 'foo'
|
||||
yield* fixToTypeImportByInsertType(fixer, node, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const typeNamedSpecifiers = namedSpecifiers.filter(specifier => report.typeSpecifiers.includes(specifier));
|
||||
const fixesNamedSpecifiers = getFixesNamedSpecifiers(fixer, node, typeNamedSpecifiers, namedSpecifiers);
|
||||
const afterFixes = [];
|
||||
if (typeNamedSpecifiers.length) {
|
||||
if (sourceImports.typeOnlyNamedImport) {
|
||||
const insertTypeNamedSpecifiers = insertToNamedImport(fixer, sourceImports.typeOnlyNamedImport, fixesNamedSpecifiers.typeNamedSpecifiersText);
|
||||
if (sourceImports.typeOnlyNamedImport.range[1] <= node.range[0]) {
|
||||
yield insertTypeNamedSpecifiers;
|
||||
}
|
||||
else {
|
||||
afterFixes.push(insertTypeNamedSpecifiers);
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield fixer.insertTextBefore(node, `import type {${fixesNamedSpecifiers.typeNamedSpecifiersText}} from ${sourceCode.getText(node.source)};\n`);
|
||||
}
|
||||
}
|
||||
const fixesRemoveTypeNamespaceSpecifier = [];
|
||||
if (namespaceSpecifier &&
|
||||
report.typeSpecifiers.includes(namespaceSpecifier)) {
|
||||
// e.g.
|
||||
// import Foo, * as Type from 'foo'
|
||||
// import DefType, * as Type from 'foo'
|
||||
// import DefType, * as Type from 'foo'
|
||||
const commaToken = util.nullThrows(sourceCode.getTokenBefore(namespaceSpecifier, util.isCommaToken), util.NullThrowsReasons.MissingToken(',', node.type));
|
||||
// import Def, * as Ns from 'foo'
|
||||
// ^^^^^^^^^ remove
|
||||
fixesRemoveTypeNamespaceSpecifier.push(fixer.removeRange([commaToken.range[0], namespaceSpecifier.range[1]]));
|
||||
// import type * as Ns from 'foo'
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ insert
|
||||
yield fixer.insertTextBefore(node, `import type ${sourceCode.getText(namespaceSpecifier)} from ${sourceCode.getText(node.source)};\n`);
|
||||
}
|
||||
if (defaultSpecifier &&
|
||||
report.typeSpecifiers.includes(defaultSpecifier)) {
|
||||
if (report.typeSpecifiers.length === node.specifiers.length) {
|
||||
const importToken = util.nullThrows(sourceCode.getFirstToken(node, isImportToken), util.NullThrowsReasons.MissingToken('import', node.type));
|
||||
// import type Type from 'foo'
|
||||
// ^^^^ insert
|
||||
yield fixer.insertTextAfter(importToken, ' type');
|
||||
}
|
||||
else {
|
||||
const commaToken = util.nullThrows(sourceCode.getTokenAfter(defaultSpecifier, util.isCommaToken), util.NullThrowsReasons.MissingToken(',', defaultSpecifier.type));
|
||||
// import Type , {...} from 'foo'
|
||||
// ^^^^^ pick
|
||||
const defaultText = sourceCode.text
|
||||
.slice(defaultSpecifier.range[0], commaToken.range[0])
|
||||
.trim();
|
||||
yield fixer.insertTextBefore(node, `import type ${defaultText} from ${sourceCode.getText(node.source)};\n`);
|
||||
const afterToken = util.nullThrows(sourceCode.getTokenAfter(commaToken, { includeComments: true }), util.NullThrowsReasons.MissingToken('any token', node.type));
|
||||
// import Type , {...} from 'foo'
|
||||
// ^^^^^^^ remove
|
||||
yield fixer.removeRange([
|
||||
defaultSpecifier.range[0],
|
||||
afterToken.range[0],
|
||||
]);
|
||||
}
|
||||
}
|
||||
yield* fixesNamedSpecifiers.removeTypeNamedSpecifiers;
|
||||
yield* fixesRemoveTypeNamespaceSpecifier;
|
||||
yield* afterFixes;
|
||||
}
|
||||
function* fixToTypeImportByInsertType(fixer, node, isDefaultImport) {
|
||||
// import type Foo from 'foo'
|
||||
// ^^^^^ insert
|
||||
const importToken = util.nullThrows(sourceCode.getFirstToken(node, isImportToken), util.NullThrowsReasons.MissingToken('import', node.type));
|
||||
yield fixer.insertTextAfter(importToken, ' type');
|
||||
if (isDefaultImport) {
|
||||
// Has default import
|
||||
const openingBraceToken = sourceCode.getFirstTokenBetween(importToken, node.source, util.isOpeningBraceToken);
|
||||
if (openingBraceToken) {
|
||||
// Only braces. e.g. import Foo, {} from 'foo'
|
||||
const commaToken = util.nullThrows(sourceCode.getTokenBefore(openingBraceToken, util.isCommaToken), util.NullThrowsReasons.MissingToken(',', node.type));
|
||||
const closingBraceToken = util.nullThrows(sourceCode.getFirstTokenBetween(openingBraceToken, node.source, util.isClosingBraceToken), util.NullThrowsReasons.MissingToken('}', node.type));
|
||||
// import type Foo, {} from 'foo'
|
||||
// ^^ remove
|
||||
yield fixer.removeRange([
|
||||
commaToken.range[0],
|
||||
closingBraceToken.range[1],
|
||||
]);
|
||||
const specifiersText = sourceCode.text.slice(commaToken.range[1], closingBraceToken.range[1]);
|
||||
if (node.specifiers.length > 1) {
|
||||
// import type Foo from 'foo'
|
||||
// import type {...} from 'foo' // <- insert
|
||||
yield fixer.insertTextAfter(node, `\nimport type${specifiersText} from ${sourceCode.getText(node.source)};`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function* fixToValueImportInDecoMeta(fixer, report, sourceImports) {
|
||||
const { node } = report;
|
||||
const { defaultSpecifier, namespaceSpecifier, namedSpecifiers } = classifySpecifier(node);
|
||||
if (namespaceSpecifier) {
|
||||
// e.g.
|
||||
// import type * as types from 'foo'
|
||||
yield* fixToValueImport(fixer, node);
|
||||
return;
|
||||
}
|
||||
else if (defaultSpecifier) {
|
||||
if (report.valueSpecifiers.includes(defaultSpecifier) &&
|
||||
namedSpecifiers.length === 0) {
|
||||
// e.g.
|
||||
// import type Type from 'foo'
|
||||
yield* fixToValueImport(fixer, node);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (namedSpecifiers.every(specifier => report.valueSpecifiers.includes(specifier))) {
|
||||
// e.g.
|
||||
// import type {Type1, Type2} from 'foo'
|
||||
yield* fixToValueImport(fixer, node);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const valueNamedSpecifiers = namedSpecifiers.filter(specifier => report.valueSpecifiers.includes(specifier));
|
||||
const fixesNamedSpecifiers = getFixesNamedSpecifiers(fixer, node, valueNamedSpecifiers, namedSpecifiers);
|
||||
const afterFixes = [];
|
||||
if (valueNamedSpecifiers.length) {
|
||||
if (sourceImports.valueOnlyNamedImport) {
|
||||
const insertTypeNamedSpecifiers = insertToNamedImport(fixer, sourceImports.valueOnlyNamedImport, fixesNamedSpecifiers.typeNamedSpecifiersText);
|
||||
if (sourceImports.valueOnlyNamedImport.range[1] <= node.range[0]) {
|
||||
yield insertTypeNamedSpecifiers;
|
||||
}
|
||||
else {
|
||||
afterFixes.push(insertTypeNamedSpecifiers);
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield fixer.insertTextBefore(node, `import {${fixesNamedSpecifiers.typeNamedSpecifiersText}} from ${sourceCode.getText(node.source)};\n`);
|
||||
}
|
||||
}
|
||||
yield* fixesNamedSpecifiers.removeTypeNamedSpecifiers;
|
||||
yield* afterFixes;
|
||||
}
|
||||
function* fixToValueImport(fixer, node) {
|
||||
var _a, _b;
|
||||
// import type Foo from 'foo'
|
||||
// ^^^^ remove
|
||||
const importToken = util.nullThrows(sourceCode.getFirstToken(node, isImportToken), util.NullThrowsReasons.MissingToken('import', node.type));
|
||||
const typeToken = util.nullThrows(sourceCode.getFirstTokenBetween(importToken, (_b = (_a = node.specifiers[0]) === null || _a === void 0 ? void 0 : _a.local) !== null && _b !== void 0 ? _b : node.source, isTypeToken), util.NullThrowsReasons.MissingToken('type', node.type));
|
||||
const afterToken = util.nullThrows(sourceCode.getTokenAfter(typeToken, { includeComments: true }), util.NullThrowsReasons.MissingToken('any token', node.type));
|
||||
yield fixer.removeRange([typeToken.range[0], afterToken.range[0]]);
|
||||
}
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=consistent-type-imports.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,65 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const util_1 = require("../util");
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'default-param-last',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforce default parameters to be last',
|
||||
category: 'Best Practices',
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
shouldBeLast: 'Default parameters should be last.',
|
||||
},
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
/**
|
||||
* checks if node is optional parameter
|
||||
* @param node the node to be evaluated
|
||||
* @private
|
||||
*/
|
||||
function isOptionalParam(node) {
|
||||
return 'optional' in node && node.optional === true;
|
||||
}
|
||||
/**
|
||||
* checks if node is plain parameter
|
||||
* @param node the node to be evaluated
|
||||
* @private
|
||||
*/
|
||||
function isPlainParam(node) {
|
||||
return !(node.type === experimental_utils_1.AST_NODE_TYPES.AssignmentPattern ||
|
||||
node.type === experimental_utils_1.AST_NODE_TYPES.RestElement ||
|
||||
isOptionalParam(node));
|
||||
}
|
||||
function checkDefaultParamLast(node) {
|
||||
let hasSeenPlainParam = false;
|
||||
for (let i = node.params.length - 1; i >= 0; i--) {
|
||||
const current = node.params[i];
|
||||
const param = current.type === experimental_utils_1.AST_NODE_TYPES.TSParameterProperty
|
||||
? current.parameter
|
||||
: current;
|
||||
if (isPlainParam(param)) {
|
||||
hasSeenPlainParam = true;
|
||||
continue;
|
||||
}
|
||||
if (hasSeenPlainParam &&
|
||||
(isOptionalParam(param) ||
|
||||
param.type === experimental_utils_1.AST_NODE_TYPES.AssignmentPattern)) {
|
||||
context.report({ node: current, messageId: 'shouldBeLast' });
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
ArrowFunctionExpression: checkDefaultParamLast,
|
||||
FunctionDeclaration: checkDefaultParamLast,
|
||||
FunctionExpression: checkDefaultParamLast,
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=default-param-last.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"default-param-last.js","sourceRoot":"","sources":["../../src/rules/default-param-last.ts"],"names":[],"mappings":";;AAAA,kCAAqC;AACrC,8EAG+C;AAE/C,kBAAe,IAAA,iBAAU,EAAC;IACxB,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,uCAAuC;YACpD,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;SACtB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,YAAY,EAAE,oCAAoC;SACnD;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ;;;;WAIG;QACH,SAAS,eAAe,CAAC,IAAwB;YAC/C,OAAO,UAAU,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC;QACtD,CAAC;QAED;;;;WAIG;QACH,SAAS,YAAY,CAAC,IAAwB;YAC5C,OAAO,CAAC,CACN,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,iBAAiB;gBAC9C,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,WAAW;gBACxC,eAAe,CAAC,IAAI,CAAC,CACtB,CAAC;QACJ,CAAC;QAED,SAAS,qBAAqB,CAC5B,IAG+B;YAE/B,IAAI,iBAAiB,GAAG,KAAK,CAAC;YAC9B,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;gBAChD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC/B,MAAM,KAAK,GACT,OAAO,CAAC,IAAI,KAAK,mCAAc,CAAC,mBAAmB;oBACjD,CAAC,CAAC,OAAO,CAAC,SAAS;oBACnB,CAAC,CAAC,OAAO,CAAC;gBAEd,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;oBACvB,iBAAiB,GAAG,IAAI,CAAC;oBACzB,SAAS;iBACV;gBAED,IACE,iBAAiB;oBACjB,CAAC,eAAe,CAAC,KAAK,CAAC;wBACrB,KAAK,CAAC,IAAI,KAAK,mCAAc,CAAC,iBAAiB,CAAC,EAClD;oBACA,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,CAAC;iBAC9D;aACF;QACH,CAAC;QAED,OAAO;YACL,uBAAuB,EAAE,qBAAqB;YAC9C,mBAAmB,EAAE,qBAAqB;YAC1C,kBAAkB,EAAE,qBAAqB;SAC1C,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,123 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const ts = __importStar(require("typescript"));
|
||||
const tsutils = __importStar(require("tsutils"));
|
||||
const dot_notation_1 = __importDefault(require("eslint/lib/rules/dot-notation"));
|
||||
const util_1 = require("../util");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'dot-notation',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'enforce dot notation whenever possible',
|
||||
category: 'Best Practices',
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
allowKeywords: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
allowPattern: {
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
allowPrivateClassPropertyAccess: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
allowProtectedClassPropertyAccess: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
allowIndexSignaturePropertyAccess: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
fixable: dot_notation_1.default.meta.fixable,
|
||||
messages: dot_notation_1.default.meta.messages,
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
allowPrivateClassPropertyAccess: false,
|
||||
allowProtectedClassPropertyAccess: false,
|
||||
allowIndexSignaturePropertyAccess: false,
|
||||
allowKeywords: true,
|
||||
allowPattern: '',
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
var _a;
|
||||
const rules = dot_notation_1.default.create(context);
|
||||
const { program, esTreeNodeToTSNodeMap } = (0, util_1.getParserServices)(context);
|
||||
const typeChecker = program.getTypeChecker();
|
||||
const allowPrivateClassPropertyAccess = options.allowPrivateClassPropertyAccess;
|
||||
const allowProtectedClassPropertyAccess = options.allowProtectedClassPropertyAccess;
|
||||
const allowIndexSignaturePropertyAccess = ((_a = options.allowIndexSignaturePropertyAccess) !== null && _a !== void 0 ? _a : false) ||
|
||||
tsutils.isCompilerOptionEnabled(program.getCompilerOptions(),
|
||||
// @ts-expect-error - TS is refining the type to never for some reason
|
||||
'noPropertyAccessFromIndexSignature');
|
||||
return {
|
||||
MemberExpression(node) {
|
||||
var _a, _b, _c;
|
||||
if ((allowPrivateClassPropertyAccess ||
|
||||
allowProtectedClassPropertyAccess ||
|
||||
allowIndexSignaturePropertyAccess) &&
|
||||
node.computed) {
|
||||
// for perf reasons - only fetch symbols if we have to
|
||||
const propertySymbol = typeChecker.getSymbolAtLocation(esTreeNodeToTSNodeMap.get(node.property));
|
||||
const modifierKind = (_c = (_b = (_a = propertySymbol === null || propertySymbol === void 0 ? void 0 : propertySymbol.getDeclarations()) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.modifiers) === null || _c === void 0 ? void 0 : _c[0].kind;
|
||||
if ((allowPrivateClassPropertyAccess &&
|
||||
modifierKind == ts.SyntaxKind.PrivateKeyword) ||
|
||||
(allowProtectedClassPropertyAccess &&
|
||||
modifierKind == ts.SyntaxKind.ProtectedKeyword)) {
|
||||
return;
|
||||
}
|
||||
if (propertySymbol === undefined &&
|
||||
allowIndexSignaturePropertyAccess) {
|
||||
const objectType = typeChecker.getTypeAtLocation(esTreeNodeToTSNodeMap.get(node.object));
|
||||
const indexType = objectType
|
||||
.getNonNullableType()
|
||||
.getStringIndexType();
|
||||
if (indexType != undefined) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
rules.MemberExpression(node);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=dot-notation.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"dot-notation.js","sourceRoot":"","sources":["../../src/rules/dot-notation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AACjC,iDAAmC;AACnC,iFAAqD;AACrD,kCAKiB;AAKjB,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,wCAAwC;YACrD,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;YACrB,oBAAoB,EAAE,IAAI;SAC3B;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,aAAa,EAAE;wBACb,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,IAAI;qBACd;oBACD,YAAY,EAAE;wBACZ,IAAI,EAAE,QAAQ;wBACd,OAAO,EAAE,EAAE;qBACZ;oBACD,+BAA+B,EAAE;wBAC/B,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,KAAK;qBACf;oBACD,iCAAiC,EAAE;wBACjC,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,KAAK;qBACf;oBACD,iCAAiC,EAAE;wBACjC,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,KAAK;qBACf;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,OAAO,EAAE,sBAAQ,CAAC,IAAI,CAAC,OAAO;QAC9B,QAAQ,EAAE,sBAAQ,CAAC,IAAI,CAAC,QAAQ;KACjC;IACD,cAAc,EAAE;QACd;YACE,+BAA+B,EAAE,KAAK;YACtC,iCAAiC,EAAE,KAAK;YACxC,iCAAiC,EAAE,KAAK;YACxC,aAAa,EAAE,IAAI;YACnB,YAAY,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EACjC;wBACA,MAAM,UAAU,GAAG,WAAW,CAAC,iBAAiB,CAC9C,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CACvC,CAAC;wBACF,MAAM,SAAS,GAAG,UAAU;6BACzB,kBAAkB,EAAE;6BACpB,kBAAkB,EAAE,CAAC;wBACxB,IAAI,SAAS,IAAI,SAAS,EAAE;4BAC1B,OAAO;yBACR;qBACF;iBACF;gBACD,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,97 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
const explicitReturnTypeUtils_1 = require("../util/explicitReturnTypeUtils");
|
||||
exports.default = util.createRule({
|
||||
name: 'explicit-function-return-type',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Require explicit return types on functions and class methods',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
},
|
||||
messages: {
|
||||
missingReturnType: 'Missing return type on function.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
allowExpressions: {
|
||||
type: 'boolean',
|
||||
},
|
||||
allowTypedFunctionExpressions: {
|
||||
type: 'boolean',
|
||||
},
|
||||
allowHigherOrderFunctions: {
|
||||
type: 'boolean',
|
||||
},
|
||||
allowDirectConstAssertionInArrowFunctions: {
|
||||
type: 'boolean',
|
||||
},
|
||||
allowConciseArrowFunctionExpressionsStartingWithVoid: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
allowExpressions: false,
|
||||
allowTypedFunctionExpressions: true,
|
||||
allowHigherOrderFunctions: true,
|
||||
allowDirectConstAssertionInArrowFunctions: true,
|
||||
allowConciseArrowFunctionExpressionsStartingWithVoid: false,
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
return {
|
||||
'ArrowFunctionExpression, FunctionExpression'(node) {
|
||||
if (options.allowConciseArrowFunctionExpressionsStartingWithVoid &&
|
||||
node.type === experimental_utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
|
||||
node.expression &&
|
||||
node.body.type === experimental_utils_1.AST_NODE_TYPES.UnaryExpression &&
|
||||
node.body.operator === 'void') {
|
||||
return;
|
||||
}
|
||||
(0, explicitReturnTypeUtils_1.checkFunctionExpressionReturnType)(node, options, sourceCode, loc => context.report({
|
||||
node,
|
||||
loc,
|
||||
messageId: 'missingReturnType',
|
||||
}));
|
||||
},
|
||||
FunctionDeclaration(node) {
|
||||
(0, explicitReturnTypeUtils_1.checkFunctionReturnType)(node, options, sourceCode, loc => context.report({
|
||||
node,
|
||||
loc,
|
||||
messageId: 'missingReturnType',
|
||||
}));
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=explicit-function-return-type.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"explicit-function-return-type.js","sourceRoot":"","sources":["../../src/rules/explicit-function-return-type.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8EAG+C;AAC/C,8CAAgC;AAChC,6EAGyC;AAazC,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,+BAA+B;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,8DAA8D;YAChE,QAAQ,EAAE,kBAAkB;YAC5B,WAAW,EAAE,KAAK;SACnB;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,kCAAkC;SACtD;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,gBAAgB,EAAE;wBAChB,IAAI,EAAE,SAAS;qBAChB;oBACD,6BAA6B,EAAE;wBAC7B,IAAI,EAAE,SAAS;qBAChB;oBACD,yBAAyB,EAAE;wBACzB,IAAI,EAAE,SAAS;qBAChB;oBACD,yCAAyC,EAAE;wBACzC,IAAI,EAAE,SAAS;qBAChB;oBACD,oDAAoD,EAAE;wBACpD,IAAI,EAAE,SAAS;qBAChB;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;KACF;IACD,cAAc,EAAE;QACd;YACE,gBAAgB,EAAE,KAAK;YACvB,6BAA6B,EAAE,IAAI;YACnC,yBAAyB,EAAE,IAAI;YAC/B,yCAAyC,EAAE,IAAI;YAC/C,oDAAoD,EAAE,KAAK;SAC5D;KACF;IACD,MAAM,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC;QACvB,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAE3C,OAAO;YACL,6CAA6C,CAC3C,IAAoE;gBAEpE,IACE,OAAO,CAAC,oDAAoD;oBAC5D,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,uBAAuB;oBACpD,IAAI,CAAC,UAAU;oBACf,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,eAAe;oBACjD,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,MAAM,EAC7B;oBACA,OAAO;iBACR;gBAED,IAAA,2DAAiC,EAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,CACjE,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,GAAG;oBACH,SAAS,EAAE,mBAAmB;iBAC/B,CAAC,CACH,CAAC;YACJ,CAAC;YACD,mBAAmB,CAAC,IAAI;gBACtB,IAAA,iDAAuB,EAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,CACvD,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,GAAG;oBACH,SAAS,EAAE,mBAAmB;iBAC/B,CAAC,CACH,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,209 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
const accessibilityLevel = { enum: ['explicit', 'no-public', 'off'] };
|
||||
exports.default = util.createRule({
|
||||
name: 'explicit-member-accessibility',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Require explicit accessibility modifiers on class properties and methods',
|
||||
category: 'Stylistic Issues',
|
||||
// too opinionated to be recommended
|
||||
recommended: false,
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
missingAccessibility: 'Missing accessibility modifier on {{type}} {{name}}.',
|
||||
unwantedPublicAccessibility: 'Public accessibility modifier on {{type}} {{name}}.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
accessibility: accessibilityLevel,
|
||||
overrides: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
accessors: accessibilityLevel,
|
||||
constructors: accessibilityLevel,
|
||||
methods: accessibilityLevel,
|
||||
properties: accessibilityLevel,
|
||||
parameterProperties: accessibilityLevel,
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
ignoredMethodNames: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [{ accessibility: 'explicit' }],
|
||||
create(context, [option]) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h;
|
||||
const sourceCode = context.getSourceCode();
|
||||
const baseCheck = (_a = option.accessibility) !== null && _a !== void 0 ? _a : 'explicit';
|
||||
const overrides = (_b = option.overrides) !== null && _b !== void 0 ? _b : {};
|
||||
const ctorCheck = (_c = overrides.constructors) !== null && _c !== void 0 ? _c : baseCheck;
|
||||
const accessorCheck = (_d = overrides.accessors) !== null && _d !== void 0 ? _d : baseCheck;
|
||||
const methodCheck = (_e = overrides.methods) !== null && _e !== void 0 ? _e : baseCheck;
|
||||
const propCheck = (_f = overrides.properties) !== null && _f !== void 0 ? _f : baseCheck;
|
||||
const paramPropCheck = (_g = overrides.parameterProperties) !== null && _g !== void 0 ? _g : baseCheck;
|
||||
const ignoredMethodNames = new Set((_h = option.ignoredMethodNames) !== null && _h !== void 0 ? _h : []);
|
||||
/**
|
||||
* Generates the report for rule violations
|
||||
*/
|
||||
function reportIssue(messageId, nodeType, node, nodeName, fix = null) {
|
||||
context.report({
|
||||
node: node,
|
||||
messageId: messageId,
|
||||
data: {
|
||||
type: nodeType,
|
||||
name: nodeName,
|
||||
},
|
||||
fix: fix,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Checks if a method declaration has an accessibility modifier.
|
||||
* @param methodDefinition The node representing a MethodDefinition.
|
||||
*/
|
||||
function checkMethodAccessibilityModifier(methodDefinition) {
|
||||
let nodeType = 'method definition';
|
||||
let check = baseCheck;
|
||||
switch (methodDefinition.kind) {
|
||||
case 'method':
|
||||
check = methodCheck;
|
||||
break;
|
||||
case 'constructor':
|
||||
check = ctorCheck;
|
||||
break;
|
||||
case 'get':
|
||||
case 'set':
|
||||
check = accessorCheck;
|
||||
nodeType = `${methodDefinition.kind} property accessor`;
|
||||
break;
|
||||
}
|
||||
const methodName = util.getNameFromMember(methodDefinition, sourceCode);
|
||||
if (check === 'off' || ignoredMethodNames.has(methodName)) {
|
||||
return;
|
||||
}
|
||||
if (check === 'no-public' &&
|
||||
methodDefinition.accessibility === 'public') {
|
||||
reportIssue('unwantedPublicAccessibility', nodeType, methodDefinition, methodName, getUnwantedPublicAccessibilityFixer(methodDefinition));
|
||||
}
|
||||
else if (check === 'explicit' && !methodDefinition.accessibility) {
|
||||
reportIssue('missingAccessibility', nodeType, methodDefinition, methodName);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a fixer that removes a "public" keyword with following spaces
|
||||
*/
|
||||
function getUnwantedPublicAccessibilityFixer(node) {
|
||||
return function (fixer) {
|
||||
const tokens = sourceCode.getTokens(node);
|
||||
let rangeToRemove;
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
const token = tokens[i];
|
||||
if (token.type === experimental_utils_1.AST_TOKEN_TYPES.Keyword &&
|
||||
token.value === 'public') {
|
||||
const commensAfterPublicKeyword = sourceCode.getCommentsAfter(token);
|
||||
if (commensAfterPublicKeyword.length) {
|
||||
// public /* Hi there! */ static foo()
|
||||
// ^^^^^^^
|
||||
rangeToRemove = [
|
||||
token.range[0],
|
||||
commensAfterPublicKeyword[0].range[0],
|
||||
];
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// public static foo()
|
||||
// ^^^^^^^
|
||||
rangeToRemove = [token.range[0], tokens[i + 1].range[0]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fixer.removeRange(rangeToRemove);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Checks if property has an accessibility modifier.
|
||||
* @param classProperty The node representing a ClassProperty.
|
||||
*/
|
||||
function checkPropertyAccessibilityModifier(classProperty) {
|
||||
const nodeType = 'class property';
|
||||
const propertyName = util.getNameFromMember(classProperty, sourceCode);
|
||||
if (propCheck === 'no-public' &&
|
||||
classProperty.accessibility === 'public') {
|
||||
reportIssue('unwantedPublicAccessibility', nodeType, classProperty, propertyName, getUnwantedPublicAccessibilityFixer(classProperty));
|
||||
}
|
||||
else if (propCheck === 'explicit' && !classProperty.accessibility) {
|
||||
reportIssue('missingAccessibility', nodeType, classProperty, propertyName);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks that the parameter property has the desired accessibility modifiers set.
|
||||
* @param node The node representing a Parameter Property
|
||||
*/
|
||||
function checkParameterPropertyAccessibilityModifier(node) {
|
||||
const nodeType = 'parameter property';
|
||||
// HAS to be an identifier or assignment or TSC will throw
|
||||
if (node.parameter.type !== experimental_utils_1.AST_NODE_TYPES.Identifier &&
|
||||
node.parameter.type !== experimental_utils_1.AST_NODE_TYPES.AssignmentPattern) {
|
||||
return;
|
||||
}
|
||||
const nodeName = node.parameter.type === experimental_utils_1.AST_NODE_TYPES.Identifier
|
||||
? node.parameter.name
|
||||
: // has to be an Identifier or TSC will throw an error
|
||||
node.parameter.left.name;
|
||||
switch (paramPropCheck) {
|
||||
case 'explicit': {
|
||||
if (!node.accessibility) {
|
||||
reportIssue('missingAccessibility', nodeType, node, nodeName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'no-public': {
|
||||
if (node.accessibility === 'public' && node.readonly) {
|
||||
reportIssue('unwantedPublicAccessibility', nodeType, node, nodeName, getUnwantedPublicAccessibilityFixer(node));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
TSParameterProperty: checkParameterPropertyAccessibilityModifier,
|
||||
ClassProperty: checkPropertyAccessibilityModifier,
|
||||
MethodDefinition: checkMethodAccessibilityModifier,
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=explicit-member-accessibility.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"explicit-member-accessibility.js","sourceRoot":"","sources":["../../src/rules/explicit-member-accessibility.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8EAK+C;AAC/C,8CAAgC;AAuBhC,MAAM,kBAAkB,GAAG,EAAE,IAAI,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC;AAEtE,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,+BAA+B;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,0EAA0E;YAC5E,QAAQ,EAAE,kBAAkB;YAC5B,oCAAoC;YACpC,WAAW,EAAE,KAAK;SACnB;QACD,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE;YACR,oBAAoB,EAClB,sDAAsD;YACxD,2BAA2B,EACzB,qDAAqD;SACxD;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,Q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L,mBAAmB,EAAE,2CAA2C;YAChE,aAAa,EAAE,kCAAkC;YACjD,gBAAgB,EAAE,gCAAgC;SACnD,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,420 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const scope_manager_1 = require("@typescript-eslint/scope-manager");
|
||||
const util = __importStar(require("../util"));
|
||||
const explicitReturnTypeUtils_1 = require("../util/explicitReturnTypeUtils");
|
||||
exports.default = util.createRule({
|
||||
name: 'explicit-module-boundary-types',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: "Require explicit return and argument types on exported functions' and classes' public class methods",
|
||||
category: 'Stylistic Issues',
|
||||
recommended: 'warn',
|
||||
},
|
||||
messages: {
|
||||
missingReturnType: 'Missing return type on function.',
|
||||
missingArgType: "Argument '{{name}}' should be typed.",
|
||||
missingArgTypeUnnamed: '{{type}} argument should be typed.',
|
||||
anyTypedArg: "Argument '{{name}}' should be typed with a non-any type.",
|
||||
anyTypedArgUnnamed: '{{type}} argument should be typed with a non-any type.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
allowArgumentsExplicitlyTypedAsAny: {
|
||||
type: 'boolean',
|
||||
},
|
||||
allowDirectConstAssertionInArrowFunctions: {
|
||||
type: 'boolean',
|
||||
},
|
||||
allowedNames: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
allowHigherOrderFunctions: {
|
||||
type: 'boolean',
|
||||
},
|
||||
allowTypedFunctionExpressions: {
|
||||
type: 'boolean',
|
||||
},
|
||||
// DEPRECATED - To be removed in next major
|
||||
shouldTrackReferences: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
allowArgumentsExplicitlyTypedAsAny: false,
|
||||
allowDirectConstAssertionInArrowFunctions: true,
|
||||
allowedNames: [],
|
||||
allowHigherOrderFunctions: true,
|
||||
allowTypedFunctionExpressions: true,
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
// tracks all of the functions we've already checked
|
||||
const checkedFunctions = new Set();
|
||||
// tracks functions that were found whilst traversing
|
||||
const foundFunctions = [];
|
||||
// all nodes visited, avoids infinite recursion for cyclic references
|
||||
// (such as class member referring to itself)
|
||||
const alreadyVisited = new Set();
|
||||
/*
|
||||
# How the rule works:
|
||||
|
||||
As the rule traverses the AST, it immediately checks every single function that it finds is exported.
|
||||
"exported" means that it is either directly exported, or that its name is exported.
|
||||
|
||||
It also collects a list of every single function it finds on the way, but does not check them.
|
||||
After it's finished traversing the AST, it then iterates through the list of found functions, and checks to see if
|
||||
any of them are part of a higher-order function
|
||||
*/
|
||||
return {
|
||||
ExportDefaultDeclaration(node) {
|
||||
checkNode(node.declaration);
|
||||
},
|
||||
'ExportNamedDeclaration:not([source])'(node) {
|
||||
if (node.declaration) {
|
||||
checkNode(node.declaration);
|
||||
}
|
||||
else {
|
||||
for (const specifier of node.specifiers) {
|
||||
followReference(specifier.local);
|
||||
}
|
||||
}
|
||||
},
|
||||
TSExportAssignment(node) {
|
||||
checkNode(node.expression);
|
||||
},
|
||||
'ArrowFunctionExpression, FunctionDeclaration, FunctionExpression'(node) {
|
||||
foundFunctions.push(node);
|
||||
},
|
||||
'Program:exit'() {
|
||||
for (const func of foundFunctions) {
|
||||
if (isExportedHigherOrderFunction(func)) {
|
||||
checkNode(func);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
function checkParameters(node) {
|
||||
function checkParameter(param) {
|
||||
function report(namedMessageId, unnamedMessageId) {
|
||||
if (param.type === experimental_utils_1.AST_NODE_TYPES.Identifier) {
|
||||
context.report({
|
||||
node: param,
|
||||
messageId: namedMessageId,
|
||||
data: { name: param.name },
|
||||
});
|
||||
}
|
||||
else if (param.type === experimental_utils_1.AST_NODE_TYPES.ArrayPattern) {
|
||||
context.report({
|
||||
node: param,
|
||||
messageId: unnamedMessageId,
|
||||
data: { type: 'Array pattern' },
|
||||
});
|
||||
}
|
||||
else if (param.type === experimental_utils_1.AST_NODE_TYPES.ObjectPattern) {
|
||||
context.report({
|
||||
node: param,
|
||||
messageId: unnamedMessageId,
|
||||
data: { type: 'Object pattern' },
|
||||
});
|
||||
}
|
||||
else if (param.type === experimental_utils_1.AST_NODE_TYPES.RestElement) {
|
||||
if (param.argument.type === experimental_utils_1.AST_NODE_TYPES.Identifier) {
|
||||
context.report({
|
||||
node: param,
|
||||
messageId: namedMessageId,
|
||||
data: { name: param.argument.name },
|
||||
});
|
||||
}
|
||||
else {
|
||||
context.report({
|
||||
node: param,
|
||||
messageId: unnamedMessageId,
|
||||
data: { type: 'Rest' },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (param.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.ArrayPattern:
|
||||
case experimental_utils_1.AST_NODE_TYPES.Identifier:
|
||||
case experimental_utils_1.AST_NODE_TYPES.ObjectPattern:
|
||||
case experimental_utils_1.AST_NODE_TYPES.RestElement:
|
||||
if (!param.typeAnnotation) {
|
||||
report('missingArgType', 'missingArgTypeUnnamed');
|
||||
}
|
||||
else if (options.allowArgumentsExplicitlyTypedAsAny !== true &&
|
||||
param.typeAnnotation.typeAnnotation.type ===
|
||||
experimental_utils_1.AST_NODE_TYPES.TSAnyKeyword) {
|
||||
report('anyTypedArg', 'anyTypedArgUnnamed');
|
||||
}
|
||||
return;
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSParameterProperty:
|
||||
return checkParameter(param.parameter);
|
||||
case experimental_utils_1.AST_NODE_TYPES.AssignmentPattern: // ignored as it has a type via its assignment
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (const arg of node.params) {
|
||||
checkParameter(arg);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks if a function name is allowed and should not be checked.
|
||||
*/
|
||||
function isAllowedName(node) {
|
||||
var _a;
|
||||
if (!node || !options.allowedNames || !options.allowedNames.length) {
|
||||
return false;
|
||||
}
|
||||
if (node.type === experimental_utils_1.AST_NODE_TYPES.VariableDeclarator ||
|
||||
node.type === experimental_utils_1.AST_NODE_TYPES.FunctionDeclaration) {
|
||||
return (((_a = node.id) === null || _a === void 0 ? void 0 : _a.type) === experimental_utils_1.AST_NODE_TYPES.Identifier &&
|
||||
options.allowedNames.includes(node.id.name));
|
||||
}
|
||||
else if (node.type === experimental_utils_1.AST_NODE_TYPES.MethodDefinition ||
|
||||
node.type === experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition ||
|
||||
(node.type === experimental_utils_1.AST_NODE_TYPES.Property && node.method)) {
|
||||
if (node.key.type === experimental_utils_1.AST_NODE_TYPES.Literal &&
|
||||
typeof node.key.value === 'string') {
|
||||
return options.allowedNames.includes(node.key.value);
|
||||
}
|
||||
if (node.key.type === experimental_utils_1.AST_NODE_TYPES.TemplateLiteral &&
|
||||
node.key.expressions.length === 0) {
|
||||
return options.allowedNames.includes(node.key.quasis[0].value.raw);
|
||||
}
|
||||
if (!node.computed && node.key.type === experimental_utils_1.AST_NODE_TYPES.Identifier) {
|
||||
return options.allowedNames.includes(node.key.name);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isExportedHigherOrderFunction(node) {
|
||||
var _a;
|
||||
let current = node.parent;
|
||||
while (current) {
|
||||
if (current.type === experimental_utils_1.AST_NODE_TYPES.ReturnStatement) {
|
||||
// the parent of a return will always be a block statement, so we can skip over it
|
||||
current = (_a = current.parent) === null || _a === void 0 ? void 0 : _a.parent;
|
||||
continue;
|
||||
}
|
||||
if (!util.isFunction(current) ||
|
||||
!(0, explicitReturnTypeUtils_1.doesImmediatelyReturnFunctionExpression)(current)) {
|
||||
return false;
|
||||
}
|
||||
if (checkedFunctions.has(current)) {
|
||||
return true;
|
||||
}
|
||||
current = current.parent;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function followReference(node) {
|
||||
const scope = context.getScope();
|
||||
const variable = scope.set.get(node.name);
|
||||
/* istanbul ignore if */ if (!variable) {
|
||||
return;
|
||||
}
|
||||
// check all of the definitions
|
||||
for (const definition of variable.defs) {
|
||||
// cases we don't care about in this rule
|
||||
if ([
|
||||
scope_manager_1.DefinitionType.ImplicitGlobalVariable,
|
||||
scope_manager_1.DefinitionType.ImportBinding,
|
||||
scope_manager_1.DefinitionType.CatchClause,
|
||||
scope_manager_1.DefinitionType.Parameter,
|
||||
].includes(definition.type)) {
|
||||
continue;
|
||||
}
|
||||
checkNode(definition.node);
|
||||
}
|
||||
// follow references to find writes to the variable
|
||||
for (const reference of variable.references) {
|
||||
if (
|
||||
// we don't want to check the initialization ref, as this is handled by the declaration check
|
||||
!reference.init &&
|
||||
reference.writeExpr) {
|
||||
checkNode(reference.writeExpr);
|
||||
}
|
||||
}
|
||||
}
|
||||
function checkNode(node) {
|
||||
if (node == null || alreadyVisited.has(node)) {
|
||||
return;
|
||||
}
|
||||
alreadyVisited.add(node);
|
||||
switch (node.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.ArrowFunctionExpression:
|
||||
case experimental_utils_1.AST_NODE_TYPES.FunctionExpression:
|
||||
return checkFunctionExpression(node);
|
||||
case experimental_utils_1.AST_NODE_TYPES.ArrayExpression:
|
||||
for (const element of node.elements) {
|
||||
checkNode(element);
|
||||
}
|
||||
return;
|
||||
case experimental_utils_1.AST_NODE_TYPES.ClassProperty:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSAbstractClassProperty:
|
||||
if (node.accessibility === 'private') {
|
||||
return;
|
||||
}
|
||||
return checkNode(node.value);
|
||||
case experimental_utils_1.AST_NODE_TYPES.ClassDeclaration:
|
||||
case experimental_utils_1.AST_NODE_TYPES.ClassExpression:
|
||||
for (const element of node.body.body) {
|
||||
checkNode(element);
|
||||
}
|
||||
return;
|
||||
case experimental_utils_1.AST_NODE_TYPES.FunctionDeclaration:
|
||||
return checkFunction(node);
|
||||
case experimental_utils_1.AST_NODE_TYPES.MethodDefinition:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition:
|
||||
if (node.accessibility === 'private') {
|
||||
return;
|
||||
}
|
||||
return checkNode(node.value);
|
||||
case experimental_utils_1.AST_NODE_TYPES.Identifier:
|
||||
return followReference(node);
|
||||
case experimental_utils_1.AST_NODE_TYPES.ObjectExpression:
|
||||
for (const property of node.properties) {
|
||||
checkNode(property);
|
||||
}
|
||||
return;
|
||||
case experimental_utils_1.AST_NODE_TYPES.Property:
|
||||
return checkNode(node.value);
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression:
|
||||
return checkEmptyBodyFunctionExpression(node);
|
||||
case experimental_utils_1.AST_NODE_TYPES.VariableDeclaration:
|
||||
for (const declaration of node.declarations) {
|
||||
checkNode(declaration);
|
||||
}
|
||||
return;
|
||||
case experimental_utils_1.AST_NODE_TYPES.VariableDeclarator:
|
||||
return checkNode(node.init);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check whether any ancestor of the provided function has a valid return type.
|
||||
* This function assumes that the function either:
|
||||
* - belongs to an exported function chain validated by isExportedHigherOrderFunction
|
||||
* - is directly exported itself
|
||||
*/
|
||||
function ancestorHasReturnType(node) {
|
||||
let ancestor = node.parent;
|
||||
if ((ancestor === null || ancestor === void 0 ? void 0 : ancestor.type) === experimental_utils_1.AST_NODE_TYPES.Property) {
|
||||
ancestor = ancestor.value;
|
||||
}
|
||||
// if the ancestor is not a return, then this function was not returned at all, so we can exit early
|
||||
const isReturnStatement = (ancestor === null || ancestor === void 0 ? void 0 : ancestor.type) === experimental_utils_1.AST_NODE_TYPES.ReturnStatement;
|
||||
const isBodylessArrow = (ancestor === null || ancestor === void 0 ? void 0 : ancestor.type) === experimental_utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
|
||||
ancestor.body.type !== experimental_utils_1.AST_NODE_TYPES.BlockStatement;
|
||||
if (!isReturnStatement && !isBodylessArrow) {
|
||||
return false;
|
||||
}
|
||||
while (ancestor) {
|
||||
switch (ancestor.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.ArrowFunctionExpression:
|
||||
case experimental_utils_1.AST_NODE_TYPES.FunctionExpression:
|
||||
case experimental_utils_1.AST_NODE_TYPES.FunctionDeclaration:
|
||||
if (ancestor.returnType) {
|
||||
return true;
|
||||
}
|
||||
// assume
|
||||
break;
|
||||
// const x: Foo = () => {};
|
||||
// Assume that a typed variable types the function expression
|
||||
case experimental_utils_1.AST_NODE_TYPES.VariableDeclarator:
|
||||
if (ancestor.id.typeAnnotation) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
ancestor = ancestor.parent;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function checkEmptyBodyFunctionExpression(node) {
|
||||
var _a, _b, _c;
|
||||
const isConstructor = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === experimental_utils_1.AST_NODE_TYPES.MethodDefinition &&
|
||||
node.parent.kind === 'constructor';
|
||||
const isSetAccessor = (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition ||
|
||||
((_c = node.parent) === null || _c === void 0 ? void 0 : _c.type) === experimental_utils_1.AST_NODE_TYPES.MethodDefinition) &&
|
||||
node.parent.kind === 'set';
|
||||
if (!isConstructor && !isSetAccessor && !node.returnType) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'missingReturnType',
|
||||
});
|
||||
}
|
||||
checkParameters(node);
|
||||
}
|
||||
function checkFunctionExpression(node) {
|
||||
if (checkedFunctions.has(node)) {
|
||||
return;
|
||||
}
|
||||
checkedFunctions.add(node);
|
||||
if (isAllowedName(node.parent) ||
|
||||
(0, explicitReturnTypeUtils_1.isTypedFunctionExpression)(node, options) ||
|
||||
ancestorHasReturnType(node)) {
|
||||
return;
|
||||
}
|
||||
(0, explicitReturnTypeUtils_1.checkFunctionExpressionReturnType)(node, options, sourceCode, loc => {
|
||||
context.report({
|
||||
node,
|
||||
loc,
|
||||
messageId: 'missingReturnType',
|
||||
});
|
||||
});
|
||||
checkParameters(node);
|
||||
}
|
||||
function checkFunction(node) {
|
||||
if (checkedFunctions.has(node)) {
|
||||
return;
|
||||
}
|
||||
checkedFunctions.add(node);
|
||||
if (isAllowedName(node) || ancestorHasReturnType(node)) {
|
||||
return;
|
||||
}
|
||||
(0, explicitReturnTypeUtils_1.checkFunctionReturnType)(node, options, sourceCode, loc => {
|
||||
context.report({
|
||||
node,
|
||||
loc,
|
||||
messageId: 'missingReturnType',
|
||||
});
|
||||
});
|
||||
checkParameters(node);
|
||||
}
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=explicit-module-boundary-types.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,165 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const util = __importStar(require("../util"));
|
||||
exports.default = util.createRule({
|
||||
name: 'func-call-spacing',
|
||||
meta: {
|
||||
type: 'layout',
|
||||
docs: {
|
||||
description: 'Require or disallow spacing between function identifiers and their invocations',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
fixable: 'whitespace',
|
||||
schema: {
|
||||
anyOf: [
|
||||
{
|
||||
type: 'array',
|
||||
items: [
|
||||
{
|
||||
enum: ['never'],
|
||||
},
|
||||
],
|
||||
minItems: 0,
|
||||
maxItems: 1,
|
||||
},
|
||||
{
|
||||
type: 'array',
|
||||
items: [
|
||||
{
|
||||
enum: ['always'],
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
allowNewlines: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
minItems: 0,
|
||||
maxItems: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
messages: {
|
||||
unexpectedWhitespace: 'Unexpected whitespace between function name and paren.',
|
||||
unexpectedNewline: 'Unexpected newline between function name and paren.',
|
||||
missing: 'Missing space between function name and paren.',
|
||||
},
|
||||
},
|
||||
defaultOptions: ['never', {}],
|
||||
create(context, [option, config]) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
const text = sourceCode.getText();
|
||||
/**
|
||||
* Check if open space is present in a function name
|
||||
* @param {ASTNode} node node to evaluate
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
function checkSpacing(node) {
|
||||
var _a;
|
||||
const isOptionalCall = util.isOptionalCallExpression(node);
|
||||
const closingParenToken = sourceCode.getLastToken(node);
|
||||
const lastCalleeTokenWithoutPossibleParens = sourceCode.getLastToken((_a = node.typeParameters) !== null && _a !== void 0 ? _a : node.callee);
|
||||
const openingParenToken = sourceCode.getFirstTokenBetween(lastCalleeTokenWithoutPossibleParens, closingParenToken, util.isOpeningParenToken);
|
||||
if (!openingParenToken || openingParenToken.range[1] >= node.range[1]) {
|
||||
// new expression with no parens...
|
||||
return;
|
||||
}
|
||||
const lastCalleeToken = sourceCode.getTokenBefore(openingParenToken, util.isNotOptionalChainPunctuator);
|
||||
const textBetweenTokens = text
|
||||
.slice(lastCalleeToken.range[1], openingParenToken.range[0])
|
||||
.replace(/\/\*.*?\*\//gu, '');
|
||||
const hasWhitespace = /\s/u.test(textBetweenTokens);
|
||||
const hasNewline = hasWhitespace && util.LINEBREAK_MATCHER.test(textBetweenTokens);
|
||||
if (option === 'never') {
|
||||
if (hasWhitespace) {
|
||||
return context.report({
|
||||
node,
|
||||
loc: lastCalleeToken.loc.start,
|
||||
messageId: 'unexpectedWhitespace',
|
||||
fix(fixer) {
|
||||
/*
|
||||
* Only autofix if there is no newline
|
||||
* https://github.com/eslint/eslint/issues/7787
|
||||
*/
|
||||
if (!hasNewline &&
|
||||
// don't fix optional calls
|
||||
!isOptionalCall) {
|
||||
return fixer.removeRange([
|
||||
lastCalleeToken.range[1],
|
||||
openingParenToken.range[0],
|
||||
]);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (isOptionalCall) {
|
||||
// disallow:
|
||||
// foo?. ();
|
||||
// foo ?.();
|
||||
// foo ?. ();
|
||||
if (hasWhitespace || hasNewline) {
|
||||
context.report({
|
||||
node,
|
||||
loc: lastCalleeToken.loc.start,
|
||||
messageId: 'unexpectedWhitespace',
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!hasWhitespace) {
|
||||
context.report({
|
||||
node,
|
||||
loc: lastCalleeToken.loc.start,
|
||||
messageId: 'missing',
|
||||
fix(fixer) {
|
||||
return fixer.insertTextBefore(openingParenToken, ' ');
|
||||
},
|
||||
});
|
||||
}
|
||||
else if (!config.allowNewlines && hasNewline) {
|
||||
context.report({
|
||||
node,
|
||||
loc: lastCalleeToken.loc.start,
|
||||
messageId: 'unexpectedNewline',
|
||||
fix(fixer) {
|
||||
return fixer.replaceTextRange([lastCalleeToken.range[1], openingParenToken.range[0]], ' ');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
CallExpression: checkSpacing,
|
||||
NewExpression: checkSpacing,
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=func-call-spacing.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"func-call-spacing.js","sourceRoot":"","sources":["../../src/rules/func-call-spacing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,8CAAgC;AAahC,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE;YACJ,WAAW,EACT,gFAAgF;YAClF,QAAQ,EAAE,kBAAkB;YAC5B,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;SACtB;QACD,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE;YACN,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,OAAO;oBACb,KAAK,EAAE;wBACL;4BACE,IAAI,EAAE,CAAC,OAAO,CAAC;yBAChB;qBACF;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qBAClC,CAAC,CAAC;iBACJ;aACF;iBAAM;gBACL,IAAI,CAAC,aAAa,EAAE;oBAClB,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK;wBAC9B,SAAS,EAAE,SAAS;wBACpB,GAAG,CAAC,KAAK;4BACP,OAAO,KAAK,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;wBACxD,CAAC;qBACF,CAAC,CAAC;iBACJ;qBAAM,IAAI,CAAC,MAAO,CAAC,aAAa,IAAI,UAAU,EAAE;oBAC/C,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK;wBAC9B,SAAS,EAAE,mBAAmB;wBAC9B,GAAG,CAAC,KAAK;4BACP,OAAO,KAAK,CAAC,gBAAgB,CAC3B,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACtD,GAAG,CACJ,CAAC;wBACJ,CAAC;qBACF,CAAC,CAAC;iBACJ;aACF;QACH,CAAC;QAED,OAAO;YACL,cAAc,EAAE,YAAY;YAC5B,aAAa,EAAE,YAAY;SAC5B,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,55 +0,0 @@
|
||||
"use strict";
|
||||
// The following code is adapted from the the code in eslint.
|
||||
// License: https://github.com/eslint/eslint/blob/48700fc8408f394887cdedd071b22b757700fdcb/LICENSE
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BinarySearchTree = void 0;
|
||||
const functional_red_black_tree_1 = __importDefault(require("functional-red-black-tree"));
|
||||
/**
|
||||
* A mutable balanced binary search tree that stores (key, value) pairs. The keys are numeric, and must be unique.
|
||||
* This is intended to be a generic wrapper around a balanced binary search tree library, so that the underlying implementation
|
||||
* can easily be swapped out.
|
||||
*/
|
||||
class BinarySearchTree {
|
||||
constructor() {
|
||||
this.rbTree = (0, functional_red_black_tree_1.default)();
|
||||
}
|
||||
/**
|
||||
* Inserts an entry into the tree.
|
||||
*/
|
||||
insert(key, value) {
|
||||
const iterator = this.rbTree.find(key);
|
||||
if (iterator.valid) {
|
||||
this.rbTree = iterator.update(value);
|
||||
}
|
||||
else {
|
||||
this.rbTree = this.rbTree.insert(key, value);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Finds the entry with the largest key less than or equal to the provided key
|
||||
* @returns The found entry, or null if no such entry exists.
|
||||
*/
|
||||
findLe(key) {
|
||||
const iterator = this.rbTree.le(key);
|
||||
return { key: iterator.key, value: iterator.value };
|
||||
}
|
||||
/**
|
||||
* Deletes all of the keys in the interval [start, end)
|
||||
*/
|
||||
deleteRange(start, end) {
|
||||
// Exit without traversing the tree if the range has zero size.
|
||||
if (start === end) {
|
||||
return;
|
||||
}
|
||||
const iterator = this.rbTree.ge(start);
|
||||
while (iterator.valid && iterator.key < end) {
|
||||
this.rbTree = this.rbTree.remove(iterator.key);
|
||||
iterator.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.BinarySearchTree = BinarySearchTree;
|
||||
//# sourceMappingURL=BinarySearchTree.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"BinarySearchTree.js","sourceRoot":"","sources":["../../../src/rules/indent-new-do-not-use/BinarySearchTree.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,kGAAkG;;;;;;AAGlG,0FAAmD;AAQnD;;;;GAIG;AACH,MAAa,gBAAgB;IAA7B;QACU,WAAM,GAAG,IAAA,mCAAU,GAAa,CAAC;IAwC3C,CAAC;IAtCC;;OAEG;IACI,MAAM,CAAC,GAAW,EAAE,KAAgB;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEvC,IAAI,QAAQ,CAAC,KAAK,EAAE;YAClB,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACtC;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;SAC9C;IACH,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,GAAW;QACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QAErC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;IACtD,CAAC;IAED;;OAEG;IACI,WAAW,CAAC,KAAa,EAAE,GAAW;QAC3C,+DAA+D;QAC/D,IAAI,KAAK,KAAK,GAAG,EAAE;YACjB,OAAO;SACR;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;QAEvC,OAAO,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,GAAG,GAAG,GAAG,EAAE;YAC3C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC/C,QAAQ,CAAC,IAAI,EAAE,CAAC;SACjB;IACH,CAAC;CACF;AAzCD,4CAyCC"}
|
||||
@@ -1,221 +0,0 @@
|
||||
"use strict";
|
||||
// The following code is adapted from the the code in eslint.
|
||||
// License: https://github.com/eslint/eslint/blob/48700fc8408f394887cdedd071b22b757700fdcb/LICENSE
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OffsetStorage = void 0;
|
||||
const BinarySearchTree_1 = require("./BinarySearchTree");
|
||||
/**
|
||||
* A class to store information on desired offsets of tokens from each other
|
||||
*/
|
||||
class OffsetStorage {
|
||||
/**
|
||||
* @param tokenInfo a TokenInfo instance
|
||||
* @param indentSize The desired size of each indentation level
|
||||
* @param indentType The indentation character
|
||||
*/
|
||||
constructor(tokenInfo, indentSize, indentType) {
|
||||
this.tokenInfo = tokenInfo;
|
||||
this.indentSize = indentSize;
|
||||
this.indentType = indentType;
|
||||
this.tree = new BinarySearchTree_1.BinarySearchTree();
|
||||
this.tree.insert(0, { offset: 0, from: null, force: false });
|
||||
this.lockedFirstTokens = new WeakMap();
|
||||
this.desiredIndentCache = new WeakMap();
|
||||
this.ignoredTokens = new WeakSet();
|
||||
}
|
||||
getOffsetDescriptor(token) {
|
||||
return this.tree.findLe(token.range[0]).value;
|
||||
}
|
||||
/**
|
||||
* Sets the offset column of token B to match the offset column of token A.
|
||||
* **WARNING**: This matches a *column*, even if baseToken is not the first token on its line. In
|
||||
* most cases, `setDesiredOffset` should be used instead.
|
||||
* @param baseToken The first token
|
||||
* @param offsetToken The second token, whose offset should be matched to the first token
|
||||
*/
|
||||
matchOffsetOf(baseToken, offsetToken) {
|
||||
/*
|
||||
* lockedFirstTokens is a map from a token whose indentation is controlled by the "first" option to
|
||||
* the token that it depends on. For example, with the `ArrayExpression: first` option, the first
|
||||
* token of each element in the array after the first will be mapped to the first token of the first
|
||||
* element. The desired indentation of each of these tokens is computed based on the desired indentation
|
||||
* of the "first" element, rather than through the normal offset mechanism.
|
||||
*/
|
||||
this.lockedFirstTokens.set(offsetToken, baseToken);
|
||||
}
|
||||
/**
|
||||
* Sets the desired offset of a token.
|
||||
*
|
||||
* This uses a line-based offset collapsing behavior to handle tokens on the same line.
|
||||
* For example, consider the following two cases:
|
||||
*
|
||||
* (
|
||||
* [
|
||||
* bar
|
||||
* ]
|
||||
* )
|
||||
*
|
||||
* ([
|
||||
* bar
|
||||
* ])
|
||||
*
|
||||
* Based on the first case, it's clear that the `bar` token needs to have an offset of 1 indent level (4 spaces) from
|
||||
* the `[` token, and the `[` token has to have an offset of 1 indent level from the `(` token. Since the `(` token is
|
||||
* the first on its line (with an indent of 0 spaces), the `bar` token needs to be offset by 2 indent levels (8 spaces)
|
||||
* from the start of its line.
|
||||
*
|
||||
* However, in the second case `bar` should only be indented by 4 spaces. This is because the offset of 1 indent level
|
||||
* between the `(` and the `[` tokens gets "collapsed" because the two tokens are on the same line. As a result, the
|
||||
* `(` token is mapped to the `[` token with an offset of 0, and the rule correctly decides that `bar` should be indented
|
||||
* by 1 indent level from the start of the line.
|
||||
*
|
||||
* This is useful because rule listeners can usually just call `setDesiredOffset` for all the tokens in the node,
|
||||
* without needing to check which lines those tokens are on.
|
||||
*
|
||||
* Note that since collapsing only occurs when two tokens are on the same line, there are a few cases where non-intuitive
|
||||
* behavior can occur. For example, consider the following cases:
|
||||
*
|
||||
* foo(
|
||||
* ).
|
||||
* bar(
|
||||
* baz
|
||||
* )
|
||||
*
|
||||
* foo(
|
||||
* ).bar(
|
||||
* baz
|
||||
* )
|
||||
*
|
||||
* Based on the first example, it would seem that `bar` should be offset by 1 indent level from `foo`, and `baz`
|
||||
* should be offset by 1 indent level from `bar`. However, this is not correct, because it would result in `baz`
|
||||
* being indented by 2 indent levels in the second case (since `foo`, `bar`, and `baz` are all on separate lines, no
|
||||
* collapsing would occur).
|
||||
*
|
||||
* Instead, the correct way would be to offset `baz` by 1 level from `bar`, offset `bar` by 1 level from the `)`, and
|
||||
* offset the `)` by 0 levels from `foo`. This ensures that the offset between `bar` and the `)` are correctly collapsed
|
||||
* in the second case.
|
||||
*
|
||||
* @param token The token
|
||||
* @param fromToken The token that `token` should be offset from
|
||||
* @param offset The desired indent level
|
||||
*/
|
||||
setDesiredOffset(token, fromToken, offset) {
|
||||
this.setDesiredOffsets(token.range, fromToken, offset);
|
||||
}
|
||||
/**
|
||||
* Sets the desired offset of all tokens in a range
|
||||
* It's common for node listeners in this file to need to apply the same offset to a large, contiguous range of tokens.
|
||||
* Moreover, the offset of any given token is usually updated multiple times (roughly once for each node that contains
|
||||
* it). This means that the offset of each token is updated O(AST depth) times.
|
||||
* It would not be performant to store and update the offsets for each token independently, because the rule would end
|
||||
* up having a time complexity of O(number of tokens * AST depth), which is quite slow for large files.
|
||||
*
|
||||
* Instead, the offset tree is represented as a collection of contiguous offset ranges in a file. For example, the following
|
||||
* list could represent the state of the offset tree at a given point:
|
||||
*
|
||||
* * Tokens starting in the interval [0, 15) are aligned with the beginning of the file
|
||||
* * Tokens starting in the interval [15, 30) are offset by 1 indent level from the `bar` token
|
||||
* * Tokens starting in the interval [30, 43) are offset by 1 indent level from the `foo` token
|
||||
* * Tokens starting in the interval [43, 820) are offset by 2 indent levels from the `bar` token
|
||||
* * Tokens starting in the interval [820, ∞) are offset by 1 indent level from the `baz` token
|
||||
*
|
||||
* The `setDesiredOffsets` methods inserts ranges like the ones above. The third line above would be inserted by using:
|
||||
* `setDesiredOffsets([30, 43], fooToken, 1);`
|
||||
*
|
||||
* @param range A [start, end] pair. All tokens with range[0] <= token.start < range[1] will have the offset applied.
|
||||
* @param fromToken The token that this is offset from
|
||||
* @param offset The desired indent level
|
||||
* @param force `true` if this offset should not use the normal collapsing behavior. This should almost always be false.
|
||||
*/
|
||||
setDesiredOffsets(range, fromToken, offset = 0, force = false) {
|
||||
/*
|
||||
* Offset ranges are stored as a collection of nodes, where each node maps a numeric key to an offset
|
||||
* descriptor. The tree for the example above would have the following nodes:
|
||||
*
|
||||
* * key: 0, value: { offset: 0, from: null }
|
||||
* * key: 15, value: { offset: 1, from: barToken }
|
||||
* * key: 30, value: { offset: 1, from: fooToken }
|
||||
* * key: 43, value: { offset: 2, from: barToken }
|
||||
* * key: 820, value: { offset: 1, from: bazToken }
|
||||
*
|
||||
* To find the offset descriptor for any given token, one needs to find the node with the largest key
|
||||
* which is <= token.start. To make this operation fast, the nodes are stored in a balanced binary
|
||||
* search tree indexed by key.
|
||||
*/
|
||||
const descriptorToInsert = { offset, from: fromToken, force };
|
||||
const descriptorAfterRange = this.tree.findLe(range[1]).value;
|
||||
const fromTokenIsInRange = fromToken &&
|
||||
fromToken.range[0] >= range[0] &&
|
||||
fromToken.range[1] <= range[1];
|
||||
// this has to be before the delete + insert below or else you'll get into a cycle
|
||||
const fromTokenDescriptor = fromTokenIsInRange
|
||||
? this.getOffsetDescriptor(fromToken)
|
||||
: null;
|
||||
// First, remove any existing nodes in the range from the tree.
|
||||
this.tree.deleteRange(range[0] + 1, range[1]);
|
||||
// Insert a new node into the tree for this range
|
||||
this.tree.insert(range[0], descriptorToInsert);
|
||||
/*
|
||||
* To avoid circular offset dependencies, keep the `fromToken` token mapped to whatever it was mapped to previously,
|
||||
* even if it's in the current range.
|
||||
*/
|
||||
if (fromTokenIsInRange) {
|
||||
this.tree.insert(fromToken.range[0], fromTokenDescriptor);
|
||||
this.tree.insert(fromToken.range[1], descriptorToInsert);
|
||||
}
|
||||
/*
|
||||
* To avoid modifying the offset of tokens after the range, insert another node to keep the offset of the following
|
||||
* tokens the same as it was before.
|
||||
*/
|
||||
this.tree.insert(range[1], descriptorAfterRange);
|
||||
}
|
||||
/**
|
||||
* Gets the desired indent of a token
|
||||
* @returns The desired indent of the token
|
||||
*/
|
||||
getDesiredIndent(token) {
|
||||
if (!this.desiredIndentCache.has(token)) {
|
||||
if (this.ignoredTokens.has(token)) {
|
||||
/*
|
||||
* If the token is ignored, use the actual indent of the token as the desired indent.
|
||||
* This ensures that no errors are reported for this token.
|
||||
*/
|
||||
this.desiredIndentCache.set(token, this.tokenInfo.getTokenIndent(token));
|
||||
}
|
||||
else if (this.lockedFirstTokens.has(token)) {
|
||||
const firstToken = this.lockedFirstTokens.get(token);
|
||||
this.desiredIndentCache.set(token,
|
||||
// (indentation for the first element's line)
|
||||
this.getDesiredIndent(this.tokenInfo.getFirstTokenOfLine(firstToken)) +
|
||||
// (space between the start of the first element's line and the first element)
|
||||
this.indentType.repeat(firstToken.loc.start.column -
|
||||
this.tokenInfo.getFirstTokenOfLine(firstToken).loc.start.column));
|
||||
}
|
||||
else {
|
||||
const offsetInfo = this.getOffsetDescriptor(token);
|
||||
const offset = offsetInfo.from &&
|
||||
offsetInfo.from.loc.start.line === token.loc.start.line &&
|
||||
!/^\s*?\n/u.test(token.value) &&
|
||||
!offsetInfo.force
|
||||
? 0
|
||||
: offsetInfo.offset * this.indentSize;
|
||||
this.desiredIndentCache.set(token, (offsetInfo.from ? this.getDesiredIndent(offsetInfo.from) : '') +
|
||||
this.indentType.repeat(offset));
|
||||
}
|
||||
}
|
||||
return this.desiredIndentCache.get(token);
|
||||
}
|
||||
/**
|
||||
* Ignores a token, preventing it from being reported.
|
||||
*/
|
||||
ignoreToken(token) {
|
||||
if (this.tokenInfo.isFirstTokenOfLine(token)) {
|
||||
this.ignoredTokens.add(token);
|
||||
}
|
||||
}
|
||||
getFirstDependency(token) {
|
||||
return this.getOffsetDescriptor(token).from;
|
||||
}
|
||||
}
|
||||
exports.OffsetStorage = OffsetStorage;
|
||||
//# sourceMappingURL=OffsetStorage.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"OffsetStorage.js","sourceRoot":"","sources":["../../../src/rules/indent-new-do-not-use/OffsetStorage.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,kGAAkG;;;AAGlG,yDAAiE;AAGjE;;GAEG;AACH,MAAa,aAAa;IAQxB;;;;OAIG;IACH,YAAY,SAAoB,EAAE,UAAkB,EAAE,UAAkB;QACtE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7B,IAAI,CAAC,IAAI,GAAG,IAAI,mCAAgB,EAAE,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAE7D,IAAI,CAAC,iBAAiB,GAAG,IAAI,OAAO,EAAE,CAAC;QACvC,IAAI,CAAC,kBAAkB,GA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ACH,CAAC;IAUD,kBAAkB,CAAC,KAAqB;QACtC,OAAO,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;IAC9C,CAAC;CACF;AA5QD,sCA4QC"}
|
||||
@@ -1,49 +0,0 @@
|
||||
"use strict";
|
||||
// The following code is adapted from the the code in eslint.
|
||||
// License: https://github.com/eslint/eslint/blob/48700fc8408f394887cdedd071b22b757700fdcb/LICENSE
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TokenInfo = void 0;
|
||||
/**
|
||||
* A helper class to get token-based info related to indentation
|
||||
*/
|
||||
class TokenInfo {
|
||||
constructor(sourceCode) {
|
||||
this.sourceCode = sourceCode;
|
||||
this.firstTokensByLineNumber = sourceCode.tokensAndComments.reduce((map, token) => {
|
||||
if (!map.has(token.loc.start.line)) {
|
||||
map.set(token.loc.start.line, token);
|
||||
}
|
||||
if (!map.has(token.loc.end.line) &&
|
||||
sourceCode.text
|
||||
.slice(token.range[1] - token.loc.end.column, token.range[1])
|
||||
.trim()) {
|
||||
map.set(token.loc.end.line, token);
|
||||
}
|
||||
return map;
|
||||
}, new Map());
|
||||
}
|
||||
/**
|
||||
* Gets the first token on a given token's line
|
||||
* @returns The first token on the given line
|
||||
*/
|
||||
getFirstTokenOfLine(token) {
|
||||
return this.firstTokensByLineNumber.get(token.loc.start.line);
|
||||
}
|
||||
/**
|
||||
* Determines whether a token is the first token in its line
|
||||
* @returns `true` if the token is the first on its line
|
||||
*/
|
||||
isFirstTokenOfLine(token) {
|
||||
return this.getFirstTokenOfLine(token) === token;
|
||||
}
|
||||
/**
|
||||
* Get the actual indent of a token
|
||||
* @param token Token to examine. This should be the first token on its line.
|
||||
* @returns The indentation characters that precede the token
|
||||
*/
|
||||
getTokenIndent(token) {
|
||||
return this.sourceCode.text.slice(token.range[0] - token.loc.start.column, token.range[0]);
|
||||
}
|
||||
}
|
||||
exports.TokenInfo = TokenInfo;
|
||||
//# sourceMappingURL=TokenInfo.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,OAAO,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAC,KAAqB;QACzC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAC/B,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EACvC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CACf,CAAC;IACJ,CAAC;CACF;AAtDD,8BAsDC"}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -1,412 +0,0 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Note this file is rather type-unsafe in its current state.
|
||||
* This is due to some really funky type conversions between different node types.
|
||||
* This is done intentionally based on the internal implementation of the base indent rule.
|
||||
*/
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment */
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _a;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const indent_1 = __importDefault(require("eslint/lib/rules/indent"));
|
||||
const util = __importStar(require("../util"));
|
||||
const KNOWN_NODES = new Set([
|
||||
// Class properties aren't yet supported by eslint...
|
||||
experimental_utils_1.AST_NODE_TYPES.ClassProperty,
|
||||
// ts keywords
|
||||
experimental_utils_1.AST_NODE_TYPES.TSAbstractKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSAnyKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSBooleanKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSNeverKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSNumberKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSStringKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSSymbolKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSUndefinedKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSUnknownKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSVoidKeyword,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSNullKeyword,
|
||||
// ts specific nodes we want to support
|
||||
experimental_utils_1.AST_NODE_TYPES.TSAbstractClassProperty,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSArrayType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSAsExpression,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSConditionalType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSConstructorType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSDeclareFunction,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSEnumDeclaration,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSEnumMember,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSExportAssignment,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSExternalModuleReference,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSFunctionType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSImportType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSIndexedAccessType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSIndexSignature,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSInferType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSInterfaceBody,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSInterfaceDeclaration,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSInterfaceHeritage,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSIntersectionType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSImportEqualsDeclaration,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSLiteralType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSMappedType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSMethodSignature,
|
||||
'TSMinusToken',
|
||||
experimental_utils_1.AST_NODE_TYPES.TSModuleBlock,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSModuleDeclaration,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSNonNullExpression,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSParameterProperty,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSParenthesizedType,
|
||||
'TSPlusToken',
|
||||
experimental_utils_1.AST_NODE_TYPES.TSPropertySignature,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSQualifiedName,
|
||||
'TSQuestionToken',
|
||||
experimental_utils_1.AST_NODE_TYPES.TSRestType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSThisType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSTupleType,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSTypeAnnotation,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSTypeLiteral,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSTypeOperator,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSTypeParameter,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSTypeParameterDeclaration,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSTypeParameterInstantiation,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSTypeReference,
|
||||
experimental_utils_1.AST_NODE_TYPES.TSUnionType,
|
||||
experimental_utils_1.AST_NODE_TYPES.Decorator,
|
||||
]);
|
||||
exports.default = util.createRule({
|
||||
name: 'indent',
|
||||
meta: {
|
||||
type: 'layout',
|
||||
docs: {
|
||||
description: 'Enforce consistent indentation',
|
||||
category: 'Stylistic Issues',
|
||||
// too opinionated to be recommended
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
fixable: 'whitespace',
|
||||
schema: indent_1.default.meta.schema,
|
||||
messages: (_a = indent_1.default.meta.messages) !== null && _a !== void 0 ? _a : {
|
||||
wrongIndentation: 'Expected indentation of {{expected}} but found {{actual}}.',
|
||||
},
|
||||
},
|
||||
defaultOptions: [
|
||||
// typescript docs and playground use 4 space indent
|
||||
4,
|
||||
{
|
||||
// typescript docs indent the case from the switch
|
||||
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-8.html#example-4
|
||||
SwitchCase: 1,
|
||||
flatTernaryExpressions: false,
|
||||
ignoredNodes: [],
|
||||
},
|
||||
],
|
||||
create(context, optionsWithDefaults) {
|
||||
// because we extend the base rule, have to update opts on the context
|
||||
// the context defines options as readonly though...
|
||||
const contextWithDefaults = Object.create(context, {
|
||||
options: {
|
||||
writable: false,
|
||||
configurable: false,
|
||||
value: optionsWithDefaults,
|
||||
},
|
||||
});
|
||||
const rules = indent_1.default.create(contextWithDefaults);
|
||||
/**
|
||||
* Converts from a TSPropertySignature to a Property
|
||||
* @param node a TSPropertySignature node
|
||||
* @param [type] the type to give the new node
|
||||
* @returns a Property node
|
||||
*/
|
||||
function TSPropertySignatureToProperty(node, type = experimental_utils_1.AST_NODE_TYPES.Property) {
|
||||
const base = {
|
||||
// indent doesn't actually use these
|
||||
key: null,
|
||||
value: null,
|
||||
// Property flags
|
||||
computed: false,
|
||||
method: false,
|
||||
kind: 'init',
|
||||
// this will stop eslint from interrogating the type literal
|
||||
shorthand: true,
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
};
|
||||
if (type === experimental_utils_1.AST_NODE_TYPES.Property) {
|
||||
return Object.assign({ type }, base);
|
||||
}
|
||||
else {
|
||||
return Object.assign({ type, static: false, readonly: false, declare: false }, base);
|
||||
}
|
||||
}
|
||||
return Object.assign({}, rules, {
|
||||
// overwrite the base rule here so we can use our KNOWN_NODES list instead
|
||||
'*:exit'(node) {
|
||||
// For nodes we care about, skip the default handling, because it just marks the node as ignored...
|
||||
if (!KNOWN_NODES.has(node.type)) {
|
||||
rules['*:exit'](node);
|
||||
}
|
||||
},
|
||||
VariableDeclaration(node) {
|
||||
// https://github.com/typescript-eslint/typescript-eslint/issues/441
|
||||
if (node.declarations.length === 0) {
|
||||
return;
|
||||
}
|
||||
return rules.VariableDeclaration(node);
|
||||
},
|
||||
TSAsExpression(node) {
|
||||
// transform it to a BinaryExpression
|
||||
return rules['BinaryExpression, LogicalExpression']({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.BinaryExpression,
|
||||
operator: 'as',
|
||||
left: node.expression,
|
||||
// the first typeAnnotation includes the as token
|
||||
right: node.typeAnnotation,
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
TSConditionalType(node) {
|
||||
// transform it to a ConditionalExpression
|
||||
return rules.ConditionalExpression({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.ConditionalExpression,
|
||||
test: {
|
||||
type: experimental_utils_1.AST_NODE_TYPES.BinaryExpression,
|
||||
operator: 'extends',
|
||||
left: node.checkType,
|
||||
right: node.extendsType,
|
||||
// location data
|
||||
range: [node.checkType.range[0], node.extendsType.range[1]],
|
||||
loc: {
|
||||
start: node.checkType.loc.start,
|
||||
end: node.extendsType.loc.end,
|
||||
},
|
||||
},
|
||||
consequent: node.trueType,
|
||||
alternate: node.falseType,
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
'TSEnumDeclaration, TSTypeLiteral'(node) {
|
||||
// transform it to an ObjectExpression
|
||||
return rules['ObjectExpression, ObjectPattern']({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.ObjectExpression,
|
||||
properties: node.members.map(member => TSPropertySignatureToProperty(member)),
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
TSImportEqualsDeclaration(node) {
|
||||
// transform it to an VariableDeclaration
|
||||
// use VariableDeclaration instead of ImportDeclaration because it's essentially the same thing
|
||||
const { id, moduleReference } = node;
|
||||
return rules.VariableDeclaration({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.VariableDeclaration,
|
||||
kind: 'const',
|
||||
declarations: [
|
||||
{
|
||||
type: experimental_utils_1.AST_NODE_TYPES.VariableDeclarator,
|
||||
range: [id.range[0], moduleReference.range[1]],
|
||||
loc: {
|
||||
start: id.loc.start,
|
||||
end: moduleReference.loc.end,
|
||||
},
|
||||
id: id,
|
||||
init: {
|
||||
type: experimental_utils_1.AST_NODE_TYPES.CallExpression,
|
||||
callee: {
|
||||
type: experimental_utils_1.AST_NODE_TYPES.Identifier,
|
||||
name: 'require',
|
||||
range: [
|
||||
moduleReference.range[0],
|
||||
moduleReference.range[0] + 'require'.length,
|
||||
],
|
||||
loc: {
|
||||
start: moduleReference.loc.start,
|
||||
end: {
|
||||
line: moduleReference.loc.end.line,
|
||||
column: moduleReference.loc.start.line + 'require'.length,
|
||||
},
|
||||
},
|
||||
},
|
||||
arguments: 'expression' in moduleReference
|
||||
? [moduleReference.expression]
|
||||
: [],
|
||||
// location data
|
||||
range: moduleReference.range,
|
||||
loc: moduleReference.loc,
|
||||
},
|
||||
},
|
||||
],
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
TSIndexedAccessType(node) {
|
||||
// convert to a MemberExpression
|
||||
return rules['MemberExpression, JSXMemberExpression, MetaProperty']({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.MemberExpression,
|
||||
object: node.objectType,
|
||||
property: node.indexType,
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
optional: false,
|
||||
computed: true,
|
||||
});
|
||||
},
|
||||
TSInterfaceBody(node) {
|
||||
// transform it to an ClassBody
|
||||
return rules['BlockStatement, ClassBody']({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.ClassBody,
|
||||
body: node.body.map(p => TSPropertySignatureToProperty(p, experimental_utils_1.AST_NODE_TYPES.ClassProperty)),
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
'TSInterfaceDeclaration[extends.length > 0]'(node) {
|
||||
// transform it to a ClassDeclaration
|
||||
return rules['ClassDeclaration[superClass], ClassExpression[superClass]']({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.ClassDeclaration,
|
||||
body: node.body,
|
||||
id: null,
|
||||
// TODO: This is invalid, there can be more than one extends in interface
|
||||
superClass: node.extends[0].expression,
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
TSMappedType(node) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
const squareBracketStart = sourceCode.getTokenBefore(node.typeParameter);
|
||||
// transform it to an ObjectExpression
|
||||
return rules['ObjectExpression, ObjectPattern']({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.ObjectExpression,
|
||||
properties: [
|
||||
{
|
||||
type: experimental_utils_1.AST_NODE_TYPES.Property,
|
||||
key: node.typeParameter,
|
||||
value: node.typeAnnotation,
|
||||
// location data
|
||||
range: [
|
||||
squareBracketStart.range[0],
|
||||
node.typeAnnotation
|
||||
? node.typeAnnotation.range[1]
|
||||
: squareBracketStart.range[0],
|
||||
],
|
||||
loc: {
|
||||
start: squareBracketStart.loc.start,
|
||||
end: node.typeAnnotation
|
||||
? node.typeAnnotation.loc.end
|
||||
: squareBracketStart.loc.end,
|
||||
},
|
||||
kind: 'init',
|
||||
computed: false,
|
||||
method: false,
|
||||
shorthand: false,
|
||||
},
|
||||
],
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
TSModuleBlock(node) {
|
||||
// transform it to a BlockStatement
|
||||
return rules['BlockStatement, ClassBody']({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.BlockStatement,
|
||||
body: node.body,
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
TSQualifiedName(node) {
|
||||
return rules['MemberExpression, JSXMemberExpression, MetaProperty']({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.MemberExpression,
|
||||
object: node.left,
|
||||
property: node.right,
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
optional: false,
|
||||
computed: false,
|
||||
});
|
||||
},
|
||||
TSTupleType(node) {
|
||||
// transform it to an ArrayExpression
|
||||
return rules['ArrayExpression, ArrayPattern']({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.ArrayExpression,
|
||||
elements: node.elementTypes,
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
TSTypeParameterDeclaration(node) {
|
||||
if (!node.params.length) {
|
||||
return;
|
||||
}
|
||||
const [name, ...attributes] = node.params;
|
||||
// JSX is about the closest we can get because the angle brackets
|
||||
// it's not perfect but it works!
|
||||
return rules.JSXOpeningElement({
|
||||
type: experimental_utils_1.AST_NODE_TYPES.JSXOpeningElement,
|
||||
selfClosing: false,
|
||||
name: name,
|
||||
attributes: attributes,
|
||||
// location data
|
||||
parent: node.parent,
|
||||
range: node.range,
|
||||
loc: node.loc,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=indent.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,250 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const adjacent_overload_signatures_1 = __importDefault(require("./adjacent-overload-signatures"));
|
||||
const array_type_1 = __importDefault(require("./array-type"));
|
||||
const await_thenable_1 = __importDefault(require("./await-thenable"));
|
||||
const ban_ts_comment_1 = __importDefault(require("./ban-ts-comment"));
|
||||
const ban_tslint_comment_1 = __importDefault(require("./ban-tslint-comment"));
|
||||
const ban_types_1 = __importDefault(require("./ban-types"));
|
||||
const brace_style_1 = __importDefault(require("./brace-style"));
|
||||
const class_literal_property_style_1 = __importDefault(require("./class-literal-property-style"));
|
||||
const comma_dangle_1 = __importDefault(require("./comma-dangle"));
|
||||
const comma_spacing_1 = __importDefault(require("./comma-spacing"));
|
||||
const consistent_indexed_object_style_1 = __importDefault(require("./consistent-indexed-object-style"));
|
||||
const consistent_type_assertions_1 = __importDefault(require("./consistent-type-assertions"));
|
||||
const consistent_type_definitions_1 = __importDefault(require("./consistent-type-definitions"));
|
||||
const consistent_type_imports_1 = __importDefault(require("./consistent-type-imports"));
|
||||
const default_param_last_1 = __importDefault(require("./default-param-last"));
|
||||
const dot_notation_1 = __importDefault(require("./dot-notation"));
|
||||
const explicit_function_return_type_1 = __importDefault(require("./explicit-function-return-type"));
|
||||
const explicit_member_accessibility_1 = __importDefault(require("./explicit-member-accessibility"));
|
||||
const explicit_module_boundary_types_1 = __importDefault(require("./explicit-module-boundary-types"));
|
||||
const func_call_spacing_1 = __importDefault(require("./func-call-spacing"));
|
||||
const indent_1 = __importDefault(require("./indent"));
|
||||
const init_declarations_1 = __importDefault(require("./init-declarations"));
|
||||
const keyword_spacing_1 = __importDefault(require("./keyword-spacing"));
|
||||
const lines_between_class_members_1 = __importDefault(require("./lines-between-class-members"));
|
||||
const member_delimiter_style_1 = __importDefault(require("./member-delimiter-style"));
|
||||
const member_ordering_1 = __importDefault(require("./member-ordering"));
|
||||
const method_signature_style_1 = __importDefault(require("./method-signature-style"));
|
||||
const naming_convention_1 = __importDefault(require("./naming-convention"));
|
||||
const no_array_constructor_1 = __importDefault(require("./no-array-constructor"));
|
||||
const no_base_to_string_1 = __importDefault(require("./no-base-to-string"));
|
||||
const no_confusing_non_null_assertion_1 = __importDefault(require("./no-confusing-non-null-assertion"));
|
||||
const no_confusing_void_expression_1 = __importDefault(require("./no-confusing-void-expression"));
|
||||
const no_dupe_class_members_1 = __importDefault(require("./no-dupe-class-members"));
|
||||
const no_duplicate_imports_1 = __importDefault(require("./no-duplicate-imports"));
|
||||
const no_dynamic_delete_1 = __importDefault(require("./no-dynamic-delete"));
|
||||
const no_empty_function_1 = __importDefault(require("./no-empty-function"));
|
||||
const no_empty_interface_1 = __importDefault(require("./no-empty-interface"));
|
||||
const no_explicit_any_1 = __importDefault(require("./no-explicit-any"));
|
||||
const no_extra_non_null_assertion_1 = __importDefault(require("./no-extra-non-null-assertion"));
|
||||
const no_extra_parens_1 = __importDefault(require("./no-extra-parens"));
|
||||
const no_extra_semi_1 = __importDefault(require("./no-extra-semi"));
|
||||
const no_extraneous_class_1 = __importDefault(require("./no-extraneous-class"));
|
||||
const no_floating_promises_1 = __importDefault(require("./no-floating-promises"));
|
||||
const no_for_in_array_1 = __importDefault(require("./no-for-in-array"));
|
||||
const no_implicit_any_catch_1 = __importDefault(require("./no-implicit-any-catch"));
|
||||
const no_implied_eval_1 = __importDefault(require("./no-implied-eval"));
|
||||
const no_inferrable_types_1 = __importDefault(require("./no-inferrable-types"));
|
||||
const no_invalid_this_1 = __importDefault(require("./no-invalid-this"));
|
||||
const no_invalid_void_type_1 = __importDefault(require("./no-invalid-void-type"));
|
||||
const no_loop_func_1 = __importDefault(require("./no-loop-func"));
|
||||
const no_loss_of_precision_1 = __importDefault(require("./no-loss-of-precision"));
|
||||
const no_magic_numbers_1 = __importDefault(require("./no-magic-numbers"));
|
||||
const no_meaningless_void_operator_1 = __importDefault(require("./no-meaningless-void-operator"));
|
||||
const no_misused_new_1 = __importDefault(require("./no-misused-new"));
|
||||
const no_misused_promises_1 = __importDefault(require("./no-misused-promises"));
|
||||
const no_namespace_1 = __importDefault(require("./no-namespace"));
|
||||
const no_non_null_asserted_nullish_coalescing_1 = __importDefault(require("./no-non-null-asserted-nullish-coalescing"));
|
||||
const no_non_null_asserted_optional_chain_1 = __importDefault(require("./no-non-null-asserted-optional-chain"));
|
||||
const no_non_null_assertion_1 = __importDefault(require("./no-non-null-assertion"));
|
||||
const no_parameter_properties_1 = __importDefault(require("./no-parameter-properties"));
|
||||
const no_redeclare_1 = __importDefault(require("./no-redeclare"));
|
||||
const no_require_imports_1 = __importDefault(require("./no-require-imports"));
|
||||
const no_restricted_imports_1 = __importDefault(require("./no-restricted-imports"));
|
||||
const no_shadow_1 = __importDefault(require("./no-shadow"));
|
||||
const no_this_alias_1 = __importDefault(require("./no-this-alias"));
|
||||
const no_throw_literal_1 = __importDefault(require("./no-throw-literal"));
|
||||
const no_type_alias_1 = __importDefault(require("./no-type-alias"));
|
||||
const no_unnecessary_boolean_literal_compare_1 = __importDefault(require("./no-unnecessary-boolean-literal-compare"));
|
||||
const no_unnecessary_condition_1 = __importDefault(require("./no-unnecessary-condition"));
|
||||
const no_unnecessary_qualifier_1 = __importDefault(require("./no-unnecessary-qualifier"));
|
||||
const no_unnecessary_type_arguments_1 = __importDefault(require("./no-unnecessary-type-arguments"));
|
||||
const no_unnecessary_type_assertion_1 = __importDefault(require("./no-unnecessary-type-assertion"));
|
||||
const no_unnecessary_type_constraint_1 = __importDefault(require("./no-unnecessary-type-constraint"));
|
||||
const no_unsafe_argument_1 = __importDefault(require("./no-unsafe-argument"));
|
||||
const no_unsafe_assignment_1 = __importDefault(require("./no-unsafe-assignment"));
|
||||
const no_unsafe_call_1 = __importDefault(require("./no-unsafe-call"));
|
||||
const no_unsafe_member_access_1 = __importDefault(require("./no-unsafe-member-access"));
|
||||
const no_unsafe_return_1 = __importDefault(require("./no-unsafe-return"));
|
||||
const no_unused_expressions_1 = __importDefault(require("./no-unused-expressions"));
|
||||
const no_unused_vars_1 = __importDefault(require("./no-unused-vars"));
|
||||
const no_unused_vars_experimental_1 = __importDefault(require("./no-unused-vars-experimental"));
|
||||
const no_use_before_define_1 = __importDefault(require("./no-use-before-define"));
|
||||
const no_useless_constructor_1 = __importDefault(require("./no-useless-constructor"));
|
||||
const no_var_requires_1 = __importDefault(require("./no-var-requires"));
|
||||
const non_nullable_type_assertion_style_1 = __importDefault(require("./non-nullable-type-assertion-style"));
|
||||
const object_curly_spacing_1 = __importDefault(require("./object-curly-spacing"));
|
||||
const padding_line_between_statements_1 = __importDefault(require("./padding-line-between-statements"));
|
||||
const prefer_as_const_1 = __importDefault(require("./prefer-as-const"));
|
||||
const prefer_enum_initializers_1 = __importDefault(require("./prefer-enum-initializers"));
|
||||
const prefer_for_of_1 = __importDefault(require("./prefer-for-of"));
|
||||
const prefer_function_type_1 = __importDefault(require("./prefer-function-type"));
|
||||
const prefer_includes_1 = __importDefault(require("./prefer-includes"));
|
||||
const prefer_literal_enum_member_1 = __importDefault(require("./prefer-literal-enum-member"));
|
||||
const prefer_namespace_keyword_1 = __importDefault(require("./prefer-namespace-keyword"));
|
||||
const prefer_nullish_coalescing_1 = __importDefault(require("./prefer-nullish-coalescing"));
|
||||
const prefer_optional_chain_1 = __importDefault(require("./prefer-optional-chain"));
|
||||
const prefer_readonly_1 = __importDefault(require("./prefer-readonly"));
|
||||
const prefer_readonly_parameter_types_1 = __importDefault(require("./prefer-readonly-parameter-types"));
|
||||
const prefer_reduce_type_parameter_1 = __importDefault(require("./prefer-reduce-type-parameter"));
|
||||
const prefer_regexp_exec_1 = __importDefault(require("./prefer-regexp-exec"));
|
||||
const prefer_return_this_type_1 = __importDefault(require("./prefer-return-this-type"));
|
||||
const prefer_string_starts_ends_with_1 = __importDefault(require("./prefer-string-starts-ends-with"));
|
||||
const prefer_ts_expect_error_1 = __importDefault(require("./prefer-ts-expect-error"));
|
||||
const promise_function_async_1 = __importDefault(require("./promise-function-async"));
|
||||
const quotes_1 = __importDefault(require("./quotes"));
|
||||
const require_array_sort_compare_1 = __importDefault(require("./require-array-sort-compare"));
|
||||
const require_await_1 = __importDefault(require("./require-await"));
|
||||
const restrict_plus_operands_1 = __importDefault(require("./restrict-plus-operands"));
|
||||
const restrict_template_expressions_1 = __importDefault(require("./restrict-template-expressions"));
|
||||
const return_await_1 = __importDefault(require("./return-await"));
|
||||
const semi_1 = __importDefault(require("./semi"));
|
||||
const sort_type_union_intersection_members_1 = __importDefault(require("./sort-type-union-intersection-members"));
|
||||
const space_before_function_paren_1 = __importDefault(require("./space-before-function-paren"));
|
||||
const space_infix_ops_1 = __importDefault(require("./space-infix-ops"));
|
||||
const strict_boolean_expressions_1 = __importDefault(require("./strict-boolean-expressions"));
|
||||
const switch_exhaustiveness_check_1 = __importDefault(require("./switch-exhaustiveness-check"));
|
||||
const triple_slash_reference_1 = __importDefault(require("./triple-slash-reference"));
|
||||
const type_annotation_spacing_1 = __importDefault(require("./type-annotation-spacing"));
|
||||
const typedef_1 = __importDefault(require("./typedef"));
|
||||
const unbound_method_1 = __importDefault(require("./unbound-method"));
|
||||
const unified_signatures_1 = __importDefault(require("./unified-signatures"));
|
||||
exports.default = {
|
||||
'adjacent-overload-signatures': adjacent_overload_signatures_1.default,
|
||||
'array-type': array_type_1.default,
|
||||
'await-thenable': await_thenable_1.default,
|
||||
'ban-ts-comment': ban_ts_comment_1.default,
|
||||
'ban-tslint-comment': ban_tslint_comment_1.default,
|
||||
'ban-types': ban_types_1.default,
|
||||
'brace-style': brace_style_1.default,
|
||||
'class-literal-property-style': class_literal_property_style_1.default,
|
||||
'comma-dangle': comma_dangle_1.default,
|
||||
'comma-spacing': comma_spacing_1.default,
|
||||
'consistent-indexed-object-style': consistent_indexed_object_style_1.default,
|
||||
'consistent-type-assertions': consistent_type_assertions_1.default,
|
||||
'consistent-type-definitions': consistent_type_definitions_1.default,
|
||||
'consistent-type-imports': consistent_type_imports_1.default,
|
||||
'default-param-last': default_param_last_1.default,
|
||||
'dot-notation': dot_notation_1.default,
|
||||
'explicit-function-return-type': explicit_function_return_type_1.default,
|
||||
'explicit-member-accessibility': explicit_member_accessibility_1.default,
|
||||
'explicit-module-boundary-types': explicit_module_boundary_types_1.default,
|
||||
'func-call-spacing': func_call_spacing_1.default,
|
||||
indent: indent_1.default,
|
||||
'init-declarations': init_declarations_1.default,
|
||||
'keyword-spacing': keyword_spacing_1.default,
|
||||
'lines-between-class-members': lines_between_class_members_1.default,
|
||||
'member-delimiter-style': member_delimiter_style_1.default,
|
||||
'member-ordering': member_ordering_1.default,
|
||||
'method-signature-style': method_signature_style_1.default,
|
||||
'naming-convention': naming_convention_1.default,
|
||||
'no-array-constructor': no_array_constructor_1.default,
|
||||
'no-base-to-string': no_base_to_string_1.default,
|
||||
'no-confusing-non-null-assertion': no_confusing_non_null_assertion_1.default,
|
||||
'no-confusing-void-expression': no_confusing_void_expression_1.default,
|
||||
'no-dupe-class-members': no_dupe_class_members_1.default,
|
||||
'no-duplicate-imports': no_duplicate_imports_1.default,
|
||||
'no-dynamic-delete': no_dynamic_delete_1.default,
|
||||
'no-empty-function': no_empty_function_1.default,
|
||||
'no-empty-interface': no_empty_interface_1.default,
|
||||
'no-explicit-any': no_explicit_any_1.default,
|
||||
'no-extra-non-null-assertion': no_extra_non_null_assertion_1.default,
|
||||
'no-extra-parens': no_extra_parens_1.default,
|
||||
'no-extra-semi': no_extra_semi_1.default,
|
||||
'no-extraneous-class': no_extraneous_class_1.default,
|
||||
'no-floating-promises': no_floating_promises_1.default,
|
||||
'no-for-in-array': no_for_in_array_1.default,
|
||||
'no-implicit-any-catch': no_implicit_any_catch_1.default,
|
||||
'no-implied-eval': no_implied_eval_1.default,
|
||||
'no-inferrable-types': no_inferrable_types_1.default,
|
||||
'no-invalid-this': no_invalid_this_1.default,
|
||||
'no-invalid-void-type': no_invalid_void_type_1.default,
|
||||
'no-loop-func': no_loop_func_1.default,
|
||||
'no-loss-of-precision': no_loss_of_precision_1.default,
|
||||
'no-magic-numbers': no_magic_numbers_1.default,
|
||||
'no-meaningless-void-operator': no_meaningless_void_operator_1.default,
|
||||
'no-misused-new': no_misused_new_1.default,
|
||||
'no-misused-promises': no_misused_promises_1.default,
|
||||
'no-namespace': no_namespace_1.default,
|
||||
'no-non-null-asserted-nullish-coalescing': no_non_null_asserted_nullish_coalescing_1.default,
|
||||
'no-non-null-asserted-optional-chain': no_non_null_asserted_optional_chain_1.default,
|
||||
'no-non-null-assertion': no_non_null_assertion_1.default,
|
||||
'no-parameter-properties': no_parameter_properties_1.default,
|
||||
'no-redeclare': no_redeclare_1.default,
|
||||
'no-require-imports': no_require_imports_1.default,
|
||||
'no-restricted-imports': no_restricted_imports_1.default,
|
||||
'no-shadow': no_shadow_1.default,
|
||||
'no-this-alias': no_this_alias_1.default,
|
||||
'no-throw-literal': no_throw_literal_1.default,
|
||||
'no-type-alias': no_type_alias_1.default,
|
||||
'no-unnecessary-boolean-literal-compare': no_unnecessary_boolean_literal_compare_1.default,
|
||||
'no-unnecessary-condition': no_unnecessary_condition_1.default,
|
||||
'no-unnecessary-qualifier': no_unnecessary_qualifier_1.default,
|
||||
'no-unnecessary-type-arguments': no_unnecessary_type_arguments_1.default,
|
||||
'no-unnecessary-type-assertion': no_unnecessary_type_assertion_1.default,
|
||||
'no-unnecessary-type-constraint': no_unnecessary_type_constraint_1.default,
|
||||
'no-unsafe-argument': no_unsafe_argument_1.default,
|
||||
'no-unsafe-assignment': no_unsafe_assignment_1.default,
|
||||
'no-unsafe-call': no_unsafe_call_1.default,
|
||||
'no-unsafe-member-access': no_unsafe_member_access_1.default,
|
||||
'no-unsafe-return': no_unsafe_return_1.default,
|
||||
'no-unused-expressions': no_unused_expressions_1.default,
|
||||
'no-unused-vars': no_unused_vars_1.default,
|
||||
'no-unused-vars-experimental': no_unused_vars_experimental_1.default,
|
||||
'no-use-before-define': no_use_before_define_1.default,
|
||||
'no-useless-constructor': no_useless_constructor_1.default,
|
||||
'no-var-requires': no_var_requires_1.default,
|
||||
'non-nullable-type-assertion-style': non_nullable_type_assertion_style_1.default,
|
||||
'object-curly-spacing': object_curly_spacing_1.default,
|
||||
'padding-line-between-statements': padding_line_between_statements_1.default,
|
||||
'prefer-as-const': prefer_as_const_1.default,
|
||||
'prefer-enum-initializers': prefer_enum_initializers_1.default,
|
||||
'prefer-for-of': prefer_for_of_1.default,
|
||||
'prefer-function-type': prefer_function_type_1.default,
|
||||
'prefer-includes': prefer_includes_1.default,
|
||||
'prefer-literal-enum-member': prefer_literal_enum_member_1.default,
|
||||
'prefer-namespace-keyword': prefer_namespace_keyword_1.default,
|
||||
'prefer-nullish-coalescing': prefer_nullish_coalescing_1.default,
|
||||
'prefer-optional-chain': prefer_optional_chain_1.default,
|
||||
'prefer-readonly': prefer_readonly_1.default,
|
||||
'prefer-readonly-parameter-types': prefer_readonly_parameter_types_1.default,
|
||||
'prefer-reduce-type-parameter': prefer_reduce_type_parameter_1.default,
|
||||
'prefer-regexp-exec': prefer_regexp_exec_1.default,
|
||||
'prefer-return-this-type': prefer_return_this_type_1.default,
|
||||
'prefer-string-starts-ends-with': prefer_string_starts_ends_with_1.default,
|
||||
'prefer-ts-expect-error': prefer_ts_expect_error_1.default,
|
||||
'promise-function-async': promise_function_async_1.default,
|
||||
quotes: quotes_1.default,
|
||||
'require-array-sort-compare': require_array_sort_compare_1.default,
|
||||
'require-await': require_await_1.default,
|
||||
'restrict-plus-operands': restrict_plus_operands_1.default,
|
||||
'restrict-template-expressions': restrict_template_expressions_1.default,
|
||||
'return-await': return_await_1.default,
|
||||
semi: semi_1.default,
|
||||
'sort-type-union-intersection-members': sort_type_union_intersection_members_1.default,
|
||||
'space-before-function-paren': space_before_function_paren_1.default,
|
||||
'space-infix-ops': space_infix_ops_1.default,
|
||||
'strict-boolean-expressions': strict_boolean_expressions_1.default,
|
||||
'switch-exhaustiveness-check': switch_exhaustiveness_check_1.default,
|
||||
'triple-slash-reference': triple_slash_reference_1.default,
|
||||
'type-annotation-spacing': type_annotation_spacing_1.default,
|
||||
typedef: typedef_1.default,
|
||||
'unbound-method': unbound_method_1.default,
|
||||
'unified-signatures': unified_signatures_1.default,
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":";;;;;AAAA,kGAAwE;AACxE,8DAAqC;AACrC,sEAA6C;AAC7C,sEAA4C;AAC5C,8EAAoD;AACpD,4DAAmC;AACnC,gEAAuC;AACvC,kGAAuE;AACvE,kEAAyC;AACzC,oEAA2C;AAC3C,wGAA6E;AAC7E,8FAAoE;AACpE,gGAAsE;AACtE,wFAA8D;AAC9D,8EAAoD;AACpD,kEAAyC;AACzC,oGAAyE;AACzE,oGAA0E;AAC1E,sGAA2E;AAC3E,4EAAkD;AAClD,sDAA8B;AAC9B,4EAAmD;AACnD,wEAA+C;AAC/C,gGAAqE;AACrE,sFAA4D;AAC5D,wEAA+C;AAC/C,sFAA4D;AAC5D,4EAAmD;AACnD,kFAAwD;AACxD,4EAAiD;AACjD,wGAAsF;AACtF,kGAAuE;AACvE,oFAAyD;AACzD,kFAAwD;AACxD,4EAAkD;AAClD,4EAAkD;AAClD,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AE,2CAA6B;IAClE,sBAAsB,EAAE,8BAAkB;IAC1C,iCAAiC,EAAE,yCAA4B;IAC/D,iBAAiB,EAAE,yBAAa;IAChC,0BAA0B,EAAE,kCAAsB;IAClD,eAAe,EAAE,uBAAW;IAC5B,sBAAsB,EAAE,8BAAkB;IAC1C,iBAAiB,EAAE,yBAAc;IACjC,4BAA4B,EAAE,oCAAuB;IACrD,0BAA0B,EAAE,kCAAsB;IAClD,2BAA2B,EAAE,mCAAuB;IACpD,uBAAuB,EAAE,+BAAmB;IAC5C,iBAAiB,EAAE,yBAAc;IACjC,iCAAiC,EAAE,yCAA4B;IAC/D,8BAA8B,EAAE,sCAAyB;IACzD,oBAAoB,EAAE,4BAAgB;IACtC,yBAAyB,EAAE,iCAAoB;IAC/C,gCAAgC,EAAE,wCAA0B;IAC5D,wBAAwB,EAAE,gCAAmB;IAC7C,wBAAwB,EAAE,gCAAoB;IAC9C,MAAM,EAAE,gBAAM;IACd,4BAA4B,EAAE,oCAAuB;IACrD,eAAe,EAAE,uBAAY;IAC7B,wBAAwB,EAAE,gCAAoB;IAC9C,+BAA+B,EAAE,uCAA2B;IAC5D,cAAc,EAAE,sBAAW;IAC3B,IAAI,EAAE,cAAI;IACV,sCAAsC,EAAE,8CAAgC;IACxE,6BAA6B,EAAE,qCAAwB;IACvD,iBAAiB,EAAE,yBAAa;IAChC,4BAA4B,EAAE,oCAAwB;IACtD,6BAA6B,EAAE,qCAAyB;IACxD,wBAAwB,EAAE,gCAAoB;IAC9C,yBAAyB,EAAE,iCAAqB;IAChD,OAAO,EAAE,iBAAO;IAChB,gBAAgB,EAAE,wBAAa;IAC/B,oBAAoB,EAAE,4BAAiB;CACxC,CAAC"}
|
||||
@@ -1,48 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _a;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const init_declarations_1 = __importDefault(require("eslint/lib/rules/init-declarations"));
|
||||
const util_1 = require("../util");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'init-declarations',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'require or disallow initialization in variable declarations',
|
||||
category: 'Variables',
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
schema: init_declarations_1.default.meta.schema,
|
||||
messages: (_a = init_declarations_1.default.meta.messages) !== null && _a !== void 0 ? _a : {
|
||||
initialized: "Variable '{{idName}}' should be initialized on declaration.",
|
||||
notInitialized: "Variable '{{idName}}' should not be initialized on declaration.",
|
||||
},
|
||||
},
|
||||
defaultOptions: ['always'],
|
||||
create(context) {
|
||||
const rules = init_declarations_1.default.create(context);
|
||||
const mode = context.options[0] || 'always';
|
||||
return {
|
||||
'VariableDeclaration:exit'(node) {
|
||||
var _a, _b, _c;
|
||||
if (mode === 'always') {
|
||||
if (node.declare) {
|
||||
return;
|
||||
}
|
||||
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === experimental_utils_1.AST_NODE_TYPES.TSModuleBlock &&
|
||||
((_b = node.parent.parent) === null || _b === void 0 ? void 0 : _b.type) === experimental_utils_1.AST_NODE_TYPES.TSModuleDeclaration &&
|
||||
((_c = node.parent.parent) === null || _c === void 0 ? void 0 : _c.declare)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
rules['VariableDeclaration:exit'](node);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=init-declarations.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"init-declarations.js","sourceRoot":"","sources":["../../src/rules/init-declarations.ts"],"names":[],"mappings":";;;;;;AAAA,8EAG+C;AAC/C,2FAA0D;AAC1D,kCAIiB;AAKjB,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,6DAA6D;YAC/D,QAAQ,EAAE,WAAW;YACrB,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;SACtB;QACD,MAAM,EAAE,2BAAQ,CAAC,IAAI,CAAC,MAAM;QAC5B,QAAQ,EAAE,MAAA,2BAAQ,CAAC,IAAI,CAAC,QAAQ,mCAAI;YAClC,WAAW,EACT,6DAA6D;YAC/D,cAAc,EACZ,iEAAiE;SACpE;KACF;IACD,cAAc,EAAE,CAAC,QAAQ,CAAC;IAC1B,MAAM,CAAC,OAAO;QACZ,MAAM,KAAK,GAAG,2BAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC;QAE5C,OAAO;YACL,0BAA0B,CAAC,IAAkC;;gBAC3D,IAAI,IAAI,KAAK,QAAQ,EAAE;oBACrB,IAAI,IAAI,CAAC,OAAO,EAAE;wBAChB,OAAO;qBACR;oBACD,IACE,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI,MAAK,mCAAc,CAAC,aAAa;wBAClD,CAAA,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,IAAI,MAAK,mCAAc,CAAC,mBAAmB;yBAC/D,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,0CAAE,OAAO,CAAA,EAC3B;wBACA,OAAO;qBACR;iBACF;gBAED,KAAK,CAAC,0BAA0B,CAAC,CAAC,IAAI,CAAC,CAAC;YAC1C,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,67 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _a;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const keyword_spacing_1 = __importDefault(require("eslint/lib/rules/keyword-spacing"));
|
||||
const util = __importStar(require("../util"));
|
||||
exports.default = util.createRule({
|
||||
name: 'keyword-spacing',
|
||||
meta: {
|
||||
type: 'layout',
|
||||
docs: {
|
||||
description: 'Enforce consistent spacing before and after keywords',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
fixable: 'whitespace',
|
||||
schema: keyword_spacing_1.default.meta.schema,
|
||||
messages: (_a = keyword_spacing_1.default.meta.messages) !== null && _a !== void 0 ? _a : {
|
||||
expectedBefore: 'Expected space(s) before "{{value}}".',
|
||||
expectedAfter: 'Expected space(s) after "{{value}}".',
|
||||
unexpectedBefore: 'Unexpected space(s) before "{{value}}".',
|
||||
unexpectedAfter: 'Unexpected space(s) after "{{value}}".',
|
||||
},
|
||||
},
|
||||
defaultOptions: [{}],
|
||||
create(context) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
const baseRules = keyword_spacing_1.default.create(context);
|
||||
return Object.assign(Object.assign({}, baseRules), { TSAsExpression(node) {
|
||||
const asToken = util.nullThrows(sourceCode.getTokenAfter(node.expression, token => token.value === 'as'), util.NullThrowsReasons.MissingToken('as', node.type));
|
||||
const oldTokenType = asToken.type;
|
||||
// as is a contextual keyword, so it's always reported as an Identifier
|
||||
// the rule looks for keyword tokens, so we temporarily override it
|
||||
// we mutate it at the token level because the rule calls sourceCode.getFirstToken,
|
||||
// so mutating a copy would not change the underlying copy returned by that method
|
||||
asToken.type = experimental_utils_1.AST_TOKEN_TYPES.Keyword;
|
||||
// use this selector just because it is just a call to `checkSpacingAroundFirstToken`
|
||||
baseRules.DebuggerStatement(asToken);
|
||||
// make sure to reset the type afterward so we don't permanently mutate the AST
|
||||
asToken.type = oldTokenType;
|
||||
} });
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=keyword-spacing.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"keyword-spacing.js","sourceRoot":"","sources":["../../src/rules/keyword-spacing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8EAAwE;AACxE,uFAAwD;AACxD,8CAAgC;AAKhC,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE;YACJ,WAAW,EAAE,sDAAsD;YACnE,QAAQ,EAAE,kBAAkB;YAC5B,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;SACtB;QACD,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,yBAAQ,CAAC,IAAI,CAAC,MAAM;QAC5B,QAAQ,EAAE,MAAA,yBAAQ,CAAC,IAAI,CAAC,QAAQ,mCAAI;YAClC,cAAc,EAAE,uCAAuC;YACvD,aAAa,EAAE,sCAAsC;YACrD,gBAAgB,EAAE,yCAAyC;YAC3D,eAAe,EAAE,wCAAwC;SAC1D;KACF;IACD,cAAc,EAAE,CAAC,EAAE,CAAC;IAEpB,MAAM,CAAC,OAAO;QACZ,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,yBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3C,uCACK,SAAS,KACZ,cAAc,CAAC,IAAI;gBACjB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAC7B,UAAU,CAAC,aAAa,CACtB,IAAI,CAAC,UAAU,EACf,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,CAC9B,EACD,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CACrD,CAAC;gBACF,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;gBAClC,uEAAuE;gBACvE,mEAAmE;gBACnE,mFAAmF;gBACnF,kFAAkF;gBAClF,OAAO,CAAC,IAAI,GAAG,oCAAe,CAAC,OAAO,CAAC;gBAEvC,qFAAqF;gBACrF,SAAS,CAAC,iBAAiB,CAAC,OAAgB,CAAC,CAAC;gBAE9C,+EAA+E;gBAC/E,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC;YAC9B,CAAC,IACD;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,80 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _a;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const lines_between_class_members_1 = __importDefault(require("eslint/lib/rules/lines-between-class-members"));
|
||||
const util = __importStar(require("../util"));
|
||||
const schema = util.deepMerge(Object.assign({}, lines_between_class_members_1.default.meta.schema), {
|
||||
1: {
|
||||
exceptAfterOverload: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
exports.default = util.createRule({
|
||||
name: 'lines-between-class-members',
|
||||
meta: {
|
||||
type: 'layout',
|
||||
docs: {
|
||||
description: 'Require or disallow an empty line between class members',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
fixable: 'whitespace',
|
||||
schema,
|
||||
messages: (_a = lines_between_class_members_1.default.meta.messages) !== null && _a !== void 0 ? _a : {
|
||||
never: 'Unexpected blank line between class members.',
|
||||
always: 'Expected blank line between class members.',
|
||||
},
|
||||
},
|
||||
defaultOptions: [
|
||||
'always',
|
||||
{
|
||||
exceptAfterOverload: true,
|
||||
exceptAfterSingleLine: false,
|
||||
},
|
||||
],
|
||||
create(context, options) {
|
||||
var _a;
|
||||
const rules = lines_between_class_members_1.default.create(context);
|
||||
const exceptAfterOverload = ((_a = options[1]) === null || _a === void 0 ? void 0 : _a.exceptAfterOverload) && options[0] === 'always';
|
||||
function isOverload(node) {
|
||||
return ((node.type === experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition ||
|
||||
node.type === experimental_utils_1.AST_NODE_TYPES.MethodDefinition) &&
|
||||
node.value.type === experimental_utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression);
|
||||
}
|
||||
return {
|
||||
ClassBody(node) {
|
||||
const body = exceptAfterOverload
|
||||
? node.body.filter(node => !isOverload(node))
|
||||
: node.body;
|
||||
rules.ClassBody(Object.assign(Object.assign({}, node), { body }));
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=lines-between-class-members.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"lines-between-class-members.js","sourceRoot":"","sources":["../../src/rules/lines-between-class-members.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8EAG+C;AAC/C,+GAAoE;AACpE,8CAAgC;AAKhC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,mBACtB,qCAAQ,CAAC,IAAI,CAAC,MAAM,GACzB;IACE,CAAC,EAAE;QACD,mBAAmB,EAAE;YACnB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,IAAI;SACd;KACF;CACF,CACF,CAAC;AAEF,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,6BAA6B;IACnC,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE;YACJ,WAAW,EAAE,yDAAyD;YACtE,QAAQ,EAAE,kBAAkB;YAC5B,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;SACtB;QACD,OAAO,EAAE,YAAY;QACrB,MAAM;QACN,QAAQ,EAAE,MAAA,qCAAQ,CAAC,IAAI,CAAC,QAAQ,mCAAI;YAClC,KAAK,EAAE,8CAA8C;YACrD,MAAM,EAAE,4CAA4C;SACrD;KACF;IACD,cAAc,EAAE;QACd,QAAQ;QACR;YACE,mBAAmB,EAAE,IAAI;YACzB,qBAAqB,EAAE,KAAK;SAC7B;KACF;IACD,MAAM,CAAC,OAAO,EAAE,OAAO;;QACrB,MAAM,KAAK,GAAG,qCAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,mBAAmB,GACvB,CAAA,MAAA,OAAO,CAAC,CAAC,CAAC,0CAAE,mBAAmB,KAAI,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;QAE7D,SAAS,UAAU,CAAC,IAAmB;YACrC,OAAO,CACL,CAAC,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,0BAA0B;gBACtD,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,gBAAgB,CAAC;gBAChD,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,mCAAc,CAAC,6BAA6B,CACjE,CAAC;QACJ,CAAC;QAED,OAAO;YACL,SAAS,CAAC,IAAI;gBACZ,MAAM,IAAI,GAAG,mBAAmB;oBAC9B,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;oBAC7C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;gBAEd,KAAK,CAAC,SAAS,iCAAM,IAAI,KAAE,IAAI,IAAG,CAAC;YACrC,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,243 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
const definition = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
multiline: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
delimiter: { enum: ['none', 'semi', 'comma'] },
|
||||
requireLast: { type: 'boolean' },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
singleline: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
// note can't have "none" for single line delimiter as it's invalid syntax
|
||||
delimiter: { enum: ['semi', 'comma'] },
|
||||
requireLast: { type: 'boolean' },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
};
|
||||
const isLastTokenEndOfLine = (token, line) => {
|
||||
const positionInLine = line.indexOf(token);
|
||||
return positionInLine === line.length - 1;
|
||||
};
|
||||
const makeFixFunction = ({ optsNone, optsSemi, lastToken, missingDelimiter, lastTokenLine, isSingleLine, }) => {
|
||||
// if removing is the action but last token is not the end of the line
|
||||
if (optsNone &&
|
||||
!isLastTokenEndOfLine(lastToken.value, lastTokenLine) &&
|
||||
!isSingleLine) {
|
||||
return null;
|
||||
}
|
||||
return (fixer) => {
|
||||
if (optsNone) {
|
||||
// remove the unneeded token
|
||||
return fixer.remove(lastToken);
|
||||
}
|
||||
const token = optsSemi ? ';' : ',';
|
||||
if (missingDelimiter) {
|
||||
// add the missing delimiter
|
||||
return fixer.insertTextAfter(lastToken, token);
|
||||
}
|
||||
// correct the current delimiter
|
||||
return fixer.replaceText(lastToken, token);
|
||||
};
|
||||
};
|
||||
exports.default = util.createRule({
|
||||
name: 'member-delimiter-style',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Require a specific member delimiter style for interfaces and type literals',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
unexpectedComma: 'Unexpected separator (,).',
|
||||
unexpectedSemi: 'Unexpected separator (;).',
|
||||
expectedComma: 'Expected a comma.',
|
||||
expectedSemi: 'Expected a semicolon.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: Object.assign({}, definition.properties, {
|
||||
overrides: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
interface: definition,
|
||||
typeLiteral: definition,
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
multilineDetection: {
|
||||
enum: ['brackets', 'last-member'],
|
||||
},
|
||||
}),
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
multiline: {
|
||||
delimiter: 'semi',
|
||||
requireLast: true,
|
||||
},
|
||||
singleline: {
|
||||
delimiter: 'semi',
|
||||
requireLast: false,
|
||||
},
|
||||
multilineDetection: 'brackets',
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
var _a;
|
||||
const sourceCode = context.getSourceCode();
|
||||
// use the base options as the defaults for the cases
|
||||
const baseOptions = options;
|
||||
const overrides = (_a = baseOptions.overrides) !== null && _a !== void 0 ? _a : {};
|
||||
const interfaceOptions = util.deepMerge(baseOptions, overrides.interface);
|
||||
const typeLiteralOptions = util.deepMerge(baseOptions, overrides.typeLiteral);
|
||||
/**
|
||||
* Check the last token in the given member.
|
||||
* @param member the member to be evaluated.
|
||||
* @param opts the options to be validated.
|
||||
* @param isLast a flag indicating `member` is the last in the interface or type literal.
|
||||
*/
|
||||
function checkLastToken(member, opts, isLast) {
|
||||
/**
|
||||
* Resolves the boolean value for the given setting enum value
|
||||
* @param type the option name
|
||||
*/
|
||||
function getOption(type) {
|
||||
if (isLast && !opts.requireLast) {
|
||||
// only turn the option on if its expecting no delimiter for the last member
|
||||
return type === 'none';
|
||||
}
|
||||
return opts.delimiter === type;
|
||||
}
|
||||
let messageId = null;
|
||||
let missingDelimiter = false;
|
||||
const lastToken = sourceCode.getLastToken(member, {
|
||||
includeComments: false,
|
||||
});
|
||||
if (!lastToken) {
|
||||
return;
|
||||
}
|
||||
const sourceCodeLines = sourceCode.getLines();
|
||||
const lastTokenLine = sourceCodeLines[(lastToken === null || lastToken === void 0 ? void 0 : lastToken.loc.start.line) - 1];
|
||||
const optsSemi = getOption('semi');
|
||||
const optsComma = getOption('comma');
|
||||
const optsNone = getOption('none');
|
||||
if (lastToken.value === ';') {
|
||||
if (optsComma) {
|
||||
messageId = 'expectedComma';
|
||||
}
|
||||
else if (optsNone) {
|
||||
missingDelimiter = true;
|
||||
messageId = 'unexpectedSemi';
|
||||
}
|
||||
}
|
||||
else if (lastToken.value === ',') {
|
||||
if (optsSemi) {
|
||||
messageId = 'expectedSemi';
|
||||
}
|
||||
else if (optsNone) {
|
||||
missingDelimiter = true;
|
||||
messageId = 'unexpectedComma';
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (optsSemi) {
|
||||
missingDelimiter = true;
|
||||
messageId = 'expectedSemi';
|
||||
}
|
||||
else if (optsComma) {
|
||||
missingDelimiter = true;
|
||||
messageId = 'expectedComma';
|
||||
}
|
||||
}
|
||||
if (messageId) {
|
||||
context.report({
|
||||
node: lastToken,
|
||||
loc: {
|
||||
start: {
|
||||
line: lastToken.loc.end.line,
|
||||
column: lastToken.loc.end.column,
|
||||
},
|
||||
end: {
|
||||
line: lastToken.loc.end.line,
|
||||
column: lastToken.loc.end.column,
|
||||
},
|
||||
},
|
||||
messageId,
|
||||
fix: makeFixFunction({
|
||||
optsNone,
|
||||
optsSemi,
|
||||
lastToken,
|
||||
missingDelimiter,
|
||||
lastTokenLine,
|
||||
isSingleLine: opts.type === 'single-line',
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check the member separator being used matches the delimiter.
|
||||
* @param {ASTNode} node the node to be evaluated.
|
||||
*/
|
||||
function checkMemberSeparatorStyle(node) {
|
||||
const members = node.type === experimental_utils_1.AST_NODE_TYPES.TSInterfaceBody ? node.body : node.members;
|
||||
let isSingleLine = node.loc.start.line === node.loc.end.line;
|
||||
if (options.multilineDetection === 'last-member' &&
|
||||
!isSingleLine &&
|
||||
members.length > 0) {
|
||||
const lastMember = members[members.length - 1];
|
||||
if (lastMember.loc.end.line === node.loc.end.line) {
|
||||
isSingleLine = true;
|
||||
}
|
||||
}
|
||||
const typeOpts = node.type === experimental_utils_1.AST_NODE_TYPES.TSInterfaceBody
|
||||
? interfaceOptions
|
||||
: typeLiteralOptions;
|
||||
const opts = isSingleLine
|
||||
? Object.assign(Object.assign({}, typeOpts.singleline), { type: 'single-line' }) : Object.assign(Object.assign({}, typeOpts.multiline), { type: 'multi-line' });
|
||||
members.forEach((member, index) => {
|
||||
checkLastToken(member, opts !== null && opts !== void 0 ? opts : {}, index === members.length - 1);
|
||||
});
|
||||
}
|
||||
return {
|
||||
TSInterfaceBody: checkMemberSeparatorStyle,
|
||||
TSTypeLiteral: checkMemberSeparatorStyle,
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=member-delimiter-style.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,478 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultOrder = void 0;
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
const neverConfig = {
|
||||
type: 'string',
|
||||
enum: ['never'],
|
||||
};
|
||||
const arrayConfig = (memberTypes) => ({
|
||||
type: 'array',
|
||||
items: {
|
||||
enum: memberTypes,
|
||||
},
|
||||
});
|
||||
const objectConfig = (memberTypes) => ({
|
||||
type: 'object',
|
||||
properties: {
|
||||
memberTypes: {
|
||||
oneOf: [arrayConfig(memberTypes), neverConfig],
|
||||
},
|
||||
order: {
|
||||
type: 'string',
|
||||
enum: ['alphabetically', 'as-written'],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
});
|
||||
exports.defaultOrder = [
|
||||
// Index signature
|
||||
'signature',
|
||||
'call-signature',
|
||||
// Fields
|
||||
'public-static-field',
|
||||
'protected-static-field',
|
||||
'private-static-field',
|
||||
'public-decorated-field',
|
||||
'protected-decorated-field',
|
||||
'private-decorated-field',
|
||||
'public-instance-field',
|
||||
'protected-instance-field',
|
||||
'private-instance-field',
|
||||
'public-abstract-field',
|
||||
'protected-abstract-field',
|
||||
'private-abstract-field',
|
||||
'public-field',
|
||||
'protected-field',
|
||||
'private-field',
|
||||
'static-field',
|
||||
'instance-field',
|
||||
'abstract-field',
|
||||
'decorated-field',
|
||||
'field',
|
||||
// Constructors
|
||||
'public-constructor',
|
||||
'protected-constructor',
|
||||
'private-constructor',
|
||||
'constructor',
|
||||
// Methods
|
||||
'public-static-method',
|
||||
'protected-static-method',
|
||||
'private-static-method',
|
||||
'public-decorated-method',
|
||||
'protected-decorated-method',
|
||||
'private-decorated-method',
|
||||
'public-instance-method',
|
||||
'protected-instance-method',
|
||||
'private-instance-method',
|
||||
'public-abstract-method',
|
||||
'protected-abstract-method',
|
||||
'private-abstract-method',
|
||||
'public-method',
|
||||
'protected-method',
|
||||
'private-method',
|
||||
'static-method',
|
||||
'instance-method',
|
||||
'abstract-method',
|
||||
'decorated-method',
|
||||
'method',
|
||||
];
|
||||
const allMemberTypes = [
|
||||
'signature',
|
||||
'field',
|
||||
'method',
|
||||
'call-signature',
|
||||
'constructor',
|
||||
].reduce((all, type) => {
|
||||
all.push(type);
|
||||
['public', 'protected', 'private'].forEach(accessibility => {
|
||||
if (type !== 'signature') {
|
||||
all.push(`${accessibility}-${type}`); // e.g. `public-field`
|
||||
}
|
||||
// Only class instance fields and methods can have decorators attached to them
|
||||
if (type === 'field' || type === 'method') {
|
||||
const decoratedMemberType = `${accessibility}-decorated-${type}`;
|
||||
const decoratedMemberTypeNoAccessibility = `decorated-${type}`;
|
||||
if (!all.includes(decoratedMemberType)) {
|
||||
all.push(decoratedMemberType);
|
||||
}
|
||||
if (!all.includes(decoratedMemberTypeNoAccessibility)) {
|
||||
all.push(decoratedMemberTypeNoAccessibility);
|
||||
}
|
||||
}
|
||||
if (type !== 'constructor' && type !== 'signature') {
|
||||
// There is no `static-constructor` or `instance-constructor` or `abstract-constructor`
|
||||
['static', 'instance', 'abstract'].forEach(scope => {
|
||||
if (!all.includes(`${scope}-${type}`)) {
|
||||
all.push(`${scope}-${type}`);
|
||||
}
|
||||
all.push(`${accessibility}-${scope}-${type}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
return all;
|
||||
}, []);
|
||||
const functionExpressions = [
|
||||
experimental_utils_1.AST_NODE_TYPES.FunctionExpression,
|
||||
experimental_utils_1.AST_NODE_TYPES.ArrowFunctionExpression,
|
||||
];
|
||||
/**
|
||||
* Gets the node type.
|
||||
*
|
||||
* @param node the node to be evaluated.
|
||||
*/
|
||||
function getNodeType(node) {
|
||||
switch (node.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition:
|
||||
case experimental_utils_1.AST_NODE_TYPES.MethodDefinition:
|
||||
return node.kind;
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSMethodSignature:
|
||||
return 'method';
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
|
||||
return 'call-signature';
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
|
||||
return 'constructor';
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSAbstractClassProperty:
|
||||
case experimental_utils_1.AST_NODE_TYPES.ClassProperty:
|
||||
return node.value && functionExpressions.includes(node.value.type)
|
||||
? 'method'
|
||||
: 'field';
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSPropertySignature:
|
||||
return 'field';
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSIndexSignature:
|
||||
return 'signature';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets the member name based on the member type.
|
||||
*
|
||||
* @param node the node to be evaluated.
|
||||
* @param sourceCode
|
||||
*/
|
||||
function getMemberName(node, sourceCode) {
|
||||
switch (node.type) {
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSPropertySignature:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSMethodSignature:
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSAbstractClassProperty:
|
||||
case experimental_utils_1.AST_NODE_TYPES.ClassProperty:
|
||||
return util.getNameFromMember(node, sourceCode);
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition:
|
||||
case experimental_utils_1.AST_NODE_TYPES.MethodDefinition:
|
||||
return node.kind === 'constructor'
|
||||
? 'constructor'
|
||||
: util.getNameFromMember(node, sourceCode);
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
|
||||
return 'new';
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
|
||||
return 'call';
|
||||
case experimental_utils_1.AST_NODE_TYPES.TSIndexSignature:
|
||||
return util.getNameFromIndexSignature(node);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets the calculated rank using the provided method definition.
|
||||
* The algorithm is as follows:
|
||||
* - Get the rank based on the accessibility-scope-type name, e.g. public-instance-field
|
||||
* - If there is no order for accessibility-scope-type, then strip out the accessibility.
|
||||
* - If there is no order for scope-type, then strip out the scope.
|
||||
* - If there is no order for type, then return -1
|
||||
* @param memberGroups the valid names to be validated.
|
||||
* @param orderConfig the current order to be validated.
|
||||
*
|
||||
* @return Index of the matching member type in the order configuration.
|
||||
*/
|
||||
function getRankOrder(memberGroups, orderConfig) {
|
||||
let rank = -1;
|
||||
const stack = memberGroups.slice(); // Get a copy of the member groups
|
||||
while (stack.length > 0 && rank === -1) {
|
||||
rank = orderConfig.indexOf(stack.shift());
|
||||
}
|
||||
return rank;
|
||||
}
|
||||
/**
|
||||
* Gets the rank of the node given the order.
|
||||
* @param node the node to be evaluated.
|
||||
* @param orderConfig the current order to be validated.
|
||||
* @param supportsModifiers a flag indicating whether the type supports modifiers (scope or accessibility) or not.
|
||||
*/
|
||||
function getRank(node, orderConfig, supportsModifiers) {
|
||||
const type = getNodeType(node);
|
||||
if (type === null) {
|
||||
// shouldn't happen but just in case, put it on the end
|
||||
return orderConfig.length - 1;
|
||||
}
|
||||
const abstract = node.type === experimental_utils_1.AST_NODE_TYPES.TSAbstractClassProperty ||
|
||||
node.type === experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition;
|
||||
const scope = 'static' in node && node.static
|
||||
? 'static'
|
||||
: abstract
|
||||
? 'abstract'
|
||||
: 'instance';
|
||||
const accessibility = 'accessibility' in node && node.accessibility
|
||||
? node.accessibility
|
||||
: 'public';
|
||||
// Collect all existing member groups (e.g. 'public-instance-field', 'instance-field', 'public-field', 'constructor' etc.)
|
||||
const memberGroups = [];
|
||||
if (supportsModifiers) {
|
||||
const decorated = 'decorators' in node && node.decorators.length > 0;
|
||||
if (decorated && (type === 'field' || type === 'method')) {
|
||||
memberGroups.push(`${accessibility}-decorated-${type}`);
|
||||
memberGroups.push(`decorated-${type}`);
|
||||
}
|
||||
if (type !== 'constructor') {
|
||||
// Constructors have no scope
|
||||
memberGroups.push(`${accessibility}-${scope}-${type}`);
|
||||
memberGroups.push(`${scope}-${type}`);
|
||||
}
|
||||
memberGroups.push(`${accessibility}-${type}`);
|
||||
}
|
||||
memberGroups.push(type);
|
||||
return getRankOrder(memberGroups, orderConfig);
|
||||
}
|
||||
/**
|
||||
* Gets the lowest possible rank higher than target.
|
||||
* e.g. given the following order:
|
||||
* ...
|
||||
* public-static-method
|
||||
* protected-static-method
|
||||
* private-static-method
|
||||
* public-instance-method
|
||||
* protected-instance-method
|
||||
* private-instance-method
|
||||
* ...
|
||||
* and considering that a public-instance-method has already been declared, so ranks contains
|
||||
* public-instance-method, then the lowest possible rank for public-static-method is
|
||||
* public-instance-method.
|
||||
* @param ranks the existing ranks in the object.
|
||||
* @param target the target rank.
|
||||
* @param order the current order to be validated.
|
||||
* @returns the name of the lowest possible rank without dashes (-).
|
||||
*/
|
||||
function getLowestRank(ranks, target, order) {
|
||||
let lowest = ranks[ranks.length - 1];
|
||||
ranks.forEach(rank => {
|
||||
if (rank > target) {
|
||||
lowest = Math.min(lowest, rank);
|
||||
}
|
||||
});
|
||||
return order[lowest].replace(/-/g, ' ');
|
||||
}
|
||||
exports.default = util.createRule({
|
||||
name: 'member-ordering',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Require a consistent member declaration order',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: false,
|
||||
},
|
||||
messages: {
|
||||
incorrectOrder: 'Member "{{member}}" should be declared before member "{{beforeMember}}".',
|
||||
incorrectGroupOrder: 'Member {{name}} should be declared before all {{rank}} definitions.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
default: {
|
||||
oneOf: [
|
||||
neverConfig,
|
||||
arrayConfig(allMemberTypes),
|
||||
objectConfig(allMemberTypes),
|
||||
],
|
||||
},
|
||||
classes: {
|
||||
oneOf: [
|
||||
neverConfig,
|
||||
arrayConfig(allMemberTypes),
|
||||
objectConfig(allMemberTypes),
|
||||
],
|
||||
},
|
||||
classExpressions: {
|
||||
oneOf: [
|
||||
neverConfig,
|
||||
arrayConfig(allMemberTypes),
|
||||
objectConfig(allMemberTypes),
|
||||
],
|
||||
},
|
||||
interfaces: {
|
||||
oneOf: [
|
||||
neverConfig,
|
||||
arrayConfig(['signature', 'field', 'method', 'constructor']),
|
||||
objectConfig(['signature', 'field', 'method', 'constructor']),
|
||||
],
|
||||
},
|
||||
typeLiterals: {
|
||||
oneOf: [
|
||||
neverConfig,
|
||||
arrayConfig(['signature', 'field', 'method', 'constructor']),
|
||||
objectConfig(['signature', 'field', 'method', 'constructor']),
|
||||
],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
default: exports.defaultOrder,
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
/**
|
||||
* Checks if the member groups are correctly sorted.
|
||||
*
|
||||
* @param members Members to be validated.
|
||||
* @param groupOrder Group order to be validated.
|
||||
* @param supportsModifiers A flag indicating whether the type supports modifiers (scope or accessibility) or not.
|
||||
*
|
||||
* @return Array of member groups or null if one of the groups is not correctly sorted.
|
||||
*/
|
||||
function checkGroupSort(members, groupOrder, supportsModifiers) {
|
||||
const previousRanks = [];
|
||||
const memberGroups = [];
|
||||
let isCorrectlySorted = true;
|
||||
// Find first member which isn't correctly sorted
|
||||
members.forEach(member => {
|
||||
const rank = getRank(member, groupOrder, supportsModifiers);
|
||||
const name = getMemberName(member, context.getSourceCode());
|
||||
const rankLastMember = previousRanks[previousRanks.length - 1];
|
||||
if (rank === -1) {
|
||||
return;
|
||||
}
|
||||
// Works for 1st item because x < undefined === false for any x (typeof string)
|
||||
if (rank < rankLastMember) {
|
||||
context.report({
|
||||
node: member,
|
||||
messageId: 'incorrectGroupOrder',
|
||||
data: {
|
||||
name,
|
||||
rank: getLowestRank(previousRanks, rank, groupOrder),
|
||||
},
|
||||
});
|
||||
isCorrectlySorted = false;
|
||||
}
|
||||
else if (rank === rankLastMember) {
|
||||
// Same member group --> Push to existing member group array
|
||||
memberGroups[memberGroups.length - 1].push(member);
|
||||
}
|
||||
else {
|
||||
// New member group --> Create new member group array
|
||||
previousRanks.push(rank);
|
||||
memberGroups.push([member]);
|
||||
}
|
||||
});
|
||||
return isCorrectlySorted ? memberGroups : null;
|
||||
}
|
||||
/**
|
||||
* Checks if the members are alphabetically sorted.
|
||||
*
|
||||
* @param members Members to be validated.
|
||||
*
|
||||
* @return True if all members are correctly sorted.
|
||||
*/
|
||||
function checkAlphaSort(members) {
|
||||
let previousName = '';
|
||||
let isCorrectlySorted = true;
|
||||
// Find first member which isn't correctly sorted
|
||||
members.forEach(member => {
|
||||
const name = getMemberName(member, context.getSourceCode());
|
||||
// Note: Not all members have names
|
||||
if (name) {
|
||||
if (name < previousName) {
|
||||
context.report({
|
||||
node: member,
|
||||
messageId: 'incorrectOrder',
|
||||
data: {
|
||||
member: name,
|
||||
beforeMember: previousName,
|
||||
},
|
||||
});
|
||||
isCorrectlySorted = false;
|
||||
}
|
||||
previousName = name;
|
||||
}
|
||||
});
|
||||
return isCorrectlySorted;
|
||||
}
|
||||
/**
|
||||
* Validates if all members are correctly sorted.
|
||||
*
|
||||
* @param members Members to be validated.
|
||||
* @param orderConfig Order config to be validated.
|
||||
* @param supportsModifiers A flag indicating whether the type supports modifiers (scope or accessibility) or not.
|
||||
*/
|
||||
function validateMembersOrder(members, orderConfig, supportsModifiers) {
|
||||
if (orderConfig === 'never') {
|
||||
return;
|
||||
}
|
||||
// Standardize config
|
||||
let order = null;
|
||||
let memberTypes;
|
||||
if (Array.isArray(orderConfig)) {
|
||||
memberTypes = orderConfig;
|
||||
}
|
||||
else {
|
||||
order = orderConfig.order;
|
||||
memberTypes = orderConfig.memberTypes;
|
||||
}
|
||||
// Check order
|
||||
if (Array.isArray(memberTypes)) {
|
||||
const grouped = checkGroupSort(members, memberTypes, supportsModifiers);
|
||||
if (grouped === null) {
|
||||
return;
|
||||
}
|
||||
if (order === 'alphabetically') {
|
||||
grouped.some(groupMember => !checkAlphaSort(groupMember));
|
||||
}
|
||||
}
|
||||
else if (order === 'alphabetically') {
|
||||
checkAlphaSort(members);
|
||||
}
|
||||
}
|
||||
return {
|
||||
ClassDeclaration(node) {
|
||||
var _a;
|
||||
validateMembersOrder(node.body.body, (_a = options.classes) !== null && _a !== void 0 ? _a : options.default, true);
|
||||
},
|
||||
ClassExpression(node) {
|
||||
var _a;
|
||||
validateMembersOrder(node.body.body, (_a = options.classExpressions) !== null && _a !== void 0 ? _a : options.default, true);
|
||||
},
|
||||
TSInterfaceDeclaration(node) {
|
||||
var _a;
|
||||
validateMembersOrder(node.body.body, (_a = options.interfaces) !== null && _a !== void 0 ? _a : options.default, false);
|
||||
},
|
||||
TSTypeLiteral(node) {
|
||||
var _a;
|
||||
validateMembersOrder(node.members, (_a = options.typeLiterals) !== null && _a !== void 0 ? _a : options.default, false);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=member-ordering.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,200 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
exports.default = util.createRule({
|
||||
name: 'method-signature-style',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforces using a particular method signature syntax.',
|
||||
category: 'Best Practices',
|
||||
recommended: false,
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
errorMethod: 'Shorthand method signature is forbidden. Use a function property instead.',
|
||||
errorProperty: 'Function property signature is forbidden. Use a method shorthand instead.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
enum: ['property', 'method'],
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: ['property'],
|
||||
create(context, [mode]) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
function getMethodKey(node) {
|
||||
let key = sourceCode.getText(node.key);
|
||||
if (node.computed) {
|
||||
key = `[${key}]`;
|
||||
}
|
||||
if (node.optional) {
|
||||
key = `${key}?`;
|
||||
}
|
||||
if (node.readonly) {
|
||||
key = `readonly ${key}`;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
function getMethodParams(node) {
|
||||
let params = '()';
|
||||
if (node.params.length > 0) {
|
||||
const openingParen = util.nullThrows(sourceCode.getTokenBefore(node.params[0], util.isOpeningParenToken), 'Missing opening paren before first parameter');
|
||||
const closingParen = util.nullThrows(sourceCode.getTokenAfter(node.params[node.params.length - 1], util.isClosingParenToken), 'Missing closing paren after last parameter');
|
||||
params = sourceCode.text.substring(openingParen.range[0], closingParen.range[1]);
|
||||
}
|
||||
if (node.typeParameters != null) {
|
||||
const typeParams = sourceCode.getText(node.typeParameters);
|
||||
params = `${typeParams}${params}`;
|
||||
}
|
||||
return params;
|
||||
}
|
||||
function getMethodReturnType(node) {
|
||||
return node.returnType == null
|
||||
? // if the method has no return type, it implicitly has an `any` return type
|
||||
// we just make it explicit here so we can do the fix
|
||||
'any'
|
||||
: sourceCode.getText(node.returnType.typeAnnotation);
|
||||
}
|
||||
function getDelimiter(node) {
|
||||
const lastToken = sourceCode.getLastToken(node);
|
||||
if (lastToken &&
|
||||
(util.isSemicolonToken(lastToken) || util.isCommaToken(lastToken))) {
|
||||
return lastToken.value;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
function isNodeParentModuleDeclaration(node) {
|
||||
if (!node.parent) {
|
||||
return false;
|
||||
}
|
||||
if (node.parent.type === experimental_utils_1.AST_NODE_TYPES.TSModuleDeclaration) {
|
||||
return true;
|
||||
}
|
||||
if (node.parent.type === experimental_utils_1.AST_NODE_TYPES.Program) {
|
||||
return false;
|
||||
}
|
||||
return isNodeParentModuleDeclaration(node.parent);
|
||||
}
|
||||
return {
|
||||
TSMethodSignature(methodNode) {
|
||||
if (mode === 'method') {
|
||||
return;
|
||||
}
|
||||
const parent = methodNode.parent;
|
||||
const members = (parent === null || parent === void 0 ? void 0 : parent.type) === experimental_utils_1.AST_NODE_TYPES.TSInterfaceBody
|
||||
? parent.body
|
||||
: (parent === null || parent === void 0 ? void 0 : parent.type) === experimental_utils_1.AST_NODE_TYPES.TSTypeLiteral
|
||||
? parent.members
|
||||
: [];
|
||||
const duplicatedKeyMethodNodes = members.filter((element) => element.type === experimental_utils_1.AST_NODE_TYPES.TSMethodSignature &&
|
||||
element !== methodNode &&
|
||||
getMethodKey(element) === getMethodKey(methodNode));
|
||||
const isParentModule = isNodeParentModuleDeclaration(methodNode);
|
||||
if (duplicatedKeyMethodNodes.length > 0) {
|
||||
if (isParentModule) {
|
||||
context.report({
|
||||
node: methodNode,
|
||||
messageId: 'errorMethod',
|
||||
});
|
||||
}
|
||||
else {
|
||||
context.report({
|
||||
node: methodNode,
|
||||
messageId: 'errorMethod',
|
||||
*fix(fixer) {
|
||||
const methodNodes = [
|
||||
methodNode,
|
||||
...duplicatedKeyMethodNodes,
|
||||
].sort((a, b) => (a.range[0] < b.range[0] ? -1 : 1));
|
||||
const typeString = methodNodes
|
||||
.map(node => {
|
||||
const params = getMethodParams(node);
|
||||
const returnType = getMethodReturnType(node);
|
||||
return `(${params} => ${returnType})`;
|
||||
})
|
||||
.join(' & ');
|
||||
const key = getMethodKey(methodNode);
|
||||
const delimiter = getDelimiter(methodNode);
|
||||
yield fixer.replaceText(methodNode, `${key}: ${typeString}${delimiter}`);
|
||||
for (const node of duplicatedKeyMethodNodes) {
|
||||
const lastToken = sourceCode.getLastToken(node);
|
||||
if (lastToken) {
|
||||
const nextToken = sourceCode.getTokenAfter(lastToken);
|
||||
if (nextToken) {
|
||||
yield fixer.remove(node);
|
||||
yield fixer.replaceTextRange([lastToken.range[1], nextToken.range[0]], '');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (isParentModule) {
|
||||
context.report({
|
||||
node: methodNode,
|
||||
messageId: 'errorMethod',
|
||||
});
|
||||
}
|
||||
else {
|
||||
context.report({
|
||||
node: methodNode,
|
||||
messageId: 'errorMethod',
|
||||
fix: fixer => {
|
||||
const key = getMethodKey(methodNode);
|
||||
const params = getMethodParams(methodNode);
|
||||
const returnType = getMethodReturnType(methodNode);
|
||||
const delimiter = getDelimiter(methodNode);
|
||||
return fixer.replaceText(methodNode, `${key}: ${params} => ${returnType}${delimiter}`);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
TSPropertySignature(propertyNode) {
|
||||
var _a;
|
||||
const typeNode = (_a = propertyNode.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation;
|
||||
if ((typeNode === null || typeNode === void 0 ? void 0 : typeNode.type) !== experimental_utils_1.AST_NODE_TYPES.TSFunctionType) {
|
||||
return;
|
||||
}
|
||||
if (mode === 'property') {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: propertyNode,
|
||||
messageId: 'errorProperty',
|
||||
fix: fixer => {
|
||||
const key = getMethodKey(propertyNode);
|
||||
const params = getMethodParams(typeNode);
|
||||
const returnType = getMethodReturnType(typeNode);
|
||||
const delimiter = getDelimiter(propertyNode);
|
||||
return fixer.replaceText(propertyNode, `${key}${params}: ${returnType}${delimiter}`);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=method-signature-style.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,94 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UnderscoreOptions = exports.TypeModifiers = exports.Selectors = exports.PredefinedFormats = exports.Modifiers = exports.MetaSelectors = void 0;
|
||||
var PredefinedFormats;
|
||||
(function (PredefinedFormats) {
|
||||
PredefinedFormats[PredefinedFormats["camelCase"] = 1] = "camelCase";
|
||||
PredefinedFormats[PredefinedFormats["strictCamelCase"] = 2] = "strictCamelCase";
|
||||
PredefinedFormats[PredefinedFormats["PascalCase"] = 3] = "PascalCase";
|
||||
PredefinedFormats[PredefinedFormats["StrictPascalCase"] = 4] = "StrictPascalCase";
|
||||
PredefinedFormats[PredefinedFormats["snake_case"] = 5] = "snake_case";
|
||||
PredefinedFormats[PredefinedFormats["UPPER_CASE"] = 6] = "UPPER_CASE";
|
||||
})(PredefinedFormats || (PredefinedFormats = {}));
|
||||
exports.PredefinedFormats = PredefinedFormats;
|
||||
var UnderscoreOptions;
|
||||
(function (UnderscoreOptions) {
|
||||
UnderscoreOptions[UnderscoreOptions["forbid"] = 1] = "forbid";
|
||||
UnderscoreOptions[UnderscoreOptions["allow"] = 2] = "allow";
|
||||
UnderscoreOptions[UnderscoreOptions["require"] = 3] = "require";
|
||||
// special cases as it's common practice to use double underscore
|
||||
UnderscoreOptions[UnderscoreOptions["requireDouble"] = 4] = "requireDouble";
|
||||
UnderscoreOptions[UnderscoreOptions["allowDouble"] = 5] = "allowDouble";
|
||||
UnderscoreOptions[UnderscoreOptions["allowSingleOrDouble"] = 6] = "allowSingleOrDouble";
|
||||
})(UnderscoreOptions || (UnderscoreOptions = {}));
|
||||
exports.UnderscoreOptions = UnderscoreOptions;
|
||||
var Selectors;
|
||||
(function (Selectors) {
|
||||
// variableLike
|
||||
Selectors[Selectors["variable"] = 1] = "variable";
|
||||
Selectors[Selectors["function"] = 2] = "function";
|
||||
Selectors[Selectors["parameter"] = 4] = "parameter";
|
||||
// memberLike
|
||||
Selectors[Selectors["parameterProperty"] = 8] = "parameterProperty";
|
||||
Selectors[Selectors["accessor"] = 16] = "accessor";
|
||||
Selectors[Selectors["enumMember"] = 32] = "enumMember";
|
||||
Selectors[Selectors["classMethod"] = 64] = "classMethod";
|
||||
Selectors[Selectors["objectLiteralMethod"] = 128] = "objectLiteralMethod";
|
||||
Selectors[Selectors["typeMethod"] = 256] = "typeMethod";
|
||||
Selectors[Selectors["classProperty"] = 512] = "classProperty";
|
||||
Selectors[Selectors["objectLiteralProperty"] = 1024] = "objectLiteralProperty";
|
||||
Selectors[Selectors["typeProperty"] = 2048] = "typeProperty";
|
||||
// typeLike
|
||||
Selectors[Selectors["class"] = 4096] = "class";
|
||||
Selectors[Selectors["interface"] = 8192] = "interface";
|
||||
Selectors[Selectors["typeAlias"] = 16384] = "typeAlias";
|
||||
Selectors[Selectors["enum"] = 32768] = "enum";
|
||||
Selectors[Selectors["typeParameter"] = 131072] = "typeParameter";
|
||||
})(Selectors || (Selectors = {}));
|
||||
exports.Selectors = Selectors;
|
||||
var MetaSelectors;
|
||||
(function (MetaSelectors) {
|
||||
MetaSelectors[MetaSelectors["default"] = -1] = "default";
|
||||
MetaSelectors[MetaSelectors["variableLike"] = 7] = "variableLike";
|
||||
MetaSelectors[MetaSelectors["memberLike"] = 4088] = "memberLike";
|
||||
MetaSelectors[MetaSelectors["typeLike"] = 192512] = "typeLike";
|
||||
MetaSelectors[MetaSelectors["method"] = 448] = "method";
|
||||
MetaSelectors[MetaSelectors["property"] = 3584] = "property";
|
||||
})(MetaSelectors || (MetaSelectors = {}));
|
||||
exports.MetaSelectors = MetaSelectors;
|
||||
var Modifiers;
|
||||
(function (Modifiers) {
|
||||
// const variable
|
||||
Modifiers[Modifiers["const"] = 1] = "const";
|
||||
// readonly members
|
||||
Modifiers[Modifiers["readonly"] = 2] = "readonly";
|
||||
// static members
|
||||
Modifiers[Modifiers["static"] = 4] = "static";
|
||||
// member accessibility
|
||||
Modifiers[Modifiers["public"] = 8] = "public";
|
||||
Modifiers[Modifiers["protected"] = 16] = "protected";
|
||||
Modifiers[Modifiers["private"] = 32] = "private";
|
||||
Modifiers[Modifiers["abstract"] = 64] = "abstract";
|
||||
// destructured variable
|
||||
Modifiers[Modifiers["destructured"] = 128] = "destructured";
|
||||
// variables declared in the top-level scope
|
||||
Modifiers[Modifiers["global"] = 256] = "global";
|
||||
// things that are exported
|
||||
Modifiers[Modifiers["exported"] = 512] = "exported";
|
||||
// things that are unused
|
||||
Modifiers[Modifiers["unused"] = 1024] = "unused";
|
||||
// properties that require quoting
|
||||
Modifiers[Modifiers["requiresQuotes"] = 2048] = "requiresQuotes";
|
||||
// make sure TypeModifiers starts at Modifiers + 1 or else sorting won't work
|
||||
})(Modifiers || (Modifiers = {}));
|
||||
exports.Modifiers = Modifiers;
|
||||
var TypeModifiers;
|
||||
(function (TypeModifiers) {
|
||||
TypeModifiers[TypeModifiers["boolean"] = 4096] = "boolean";
|
||||
TypeModifiers[TypeModifiers["string"] = 8192] = "string";
|
||||
TypeModifiers[TypeModifiers["number"] = 16384] = "number";
|
||||
TypeModifiers[TypeModifiers["function"] = 32768] = "function";
|
||||
TypeModifiers[TypeModifiers["array"] = 65536] = "array";
|
||||
})(TypeModifiers || (TypeModifiers = {}));
|
||||
exports.TypeModifiers = TypeModifiers;
|
||||
//# sourceMappingURL=enums.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3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AAK,SAwBJ;AAxBD,WAAK,SAAS;IACZ,iBAAiB;IACjB,2CAAc,CAAA;IACd,mBAAmB;IACnB,iDAAiB,CAAA;IACjB,iBAAiB;IACjB,6CAAe,CAAA;IACf,uBAAuB;IACvB,6CAAe,CAAA;IACf,oDAAkB,CAAA;IAClB,gDAAgB,CAAA;IAChB,kDAAiB,CAAA;IACjB,wBAAwB;IACxB,2DAAqB,CAAA;IACrB,4CAA4C;IAC5C,+CAAe,CAAA;IACf,2BAA2B;IAC3B,mDAAiB,CAAA;IACjB,yBAAyB;IACzB,gDAAgB,CAAA;IAChB,kCAAkC;IAClC,gEAAwB,CAAA;IAExB,6EAA6E;AAC/E,CAAC,EAxBI,SAAS,KAAT,SAAS,QAwBb;AAgBC,8BAAS;AAbX,IAAK,aAMJ;AAND,WAAK,aAAa;IAChB,0DAAiB,CAAA;IACjB,wDAAgB,CAAA;IAChB,yDAAgB,CAAA;IAChB,6DAAkB,CAAA;IAClB,uDAAe,CAAA;AACjB,CAAC,EANI,aAAa,KAAb,aAAa,QAMjB;AAaC,sCAAa"}
|
||||
@@ -1,91 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PredefinedFormatToCheckFunction = void 0;
|
||||
const enums_1 = require("./enums");
|
||||
/*
|
||||
These format functions are taken from `tslint-consistent-codestyle/naming-convention`:
|
||||
https://github.com/ajafff/tslint-consistent-codestyle/blob/ab156cc8881bcc401236d999f4ce034b59039e81/rules/namingConventionRule.ts#L603-L645
|
||||
|
||||
The licence for the code can be viewed here:
|
||||
https://github.com/ajafff/tslint-consistent-codestyle/blob/ab156cc8881bcc401236d999f4ce034b59039e81/LICENSE
|
||||
*/
|
||||
/*
|
||||
Why not regex here? Because it's actually really, really difficult to create a regex to handle
|
||||
all of the unicode cases, and we have many non-english users that use non-english characters.
|
||||
https://gist.github.com/mathiasbynens/6334847
|
||||
*/
|
||||
function isPascalCase(name) {
|
||||
return (name.length === 0 ||
|
||||
(name[0] === name[0].toUpperCase() && !name.includes('_')));
|
||||
}
|
||||
function isStrictPascalCase(name) {
|
||||
return (name.length === 0 ||
|
||||
(name[0] === name[0].toUpperCase() && hasStrictCamelHumps(name, true)));
|
||||
}
|
||||
function isCamelCase(name) {
|
||||
return (name.length === 0 ||
|
||||
(name[0] === name[0].toLowerCase() && !name.includes('_')));
|
||||
}
|
||||
function isStrictCamelCase(name) {
|
||||
return (name.length === 0 ||
|
||||
(name[0] === name[0].toLowerCase() && hasStrictCamelHumps(name, false)));
|
||||
}
|
||||
function hasStrictCamelHumps(name, isUpper) {
|
||||
function isUppercaseChar(char) {
|
||||
return char === char.toUpperCase() && char !== char.toLowerCase();
|
||||
}
|
||||
if (name.startsWith('_')) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 1; i < name.length; ++i) {
|
||||
if (name[i] === '_') {
|
||||
return false;
|
||||
}
|
||||
if (isUpper === isUppercaseChar(name[i])) {
|
||||
if (isUpper) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
isUpper = !isUpper;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function isSnakeCase(name) {
|
||||
return (name.length === 0 ||
|
||||
(name === name.toLowerCase() && validateUnderscores(name)));
|
||||
}
|
||||
function isUpperCase(name) {
|
||||
return (name.length === 0 ||
|
||||
(name === name.toUpperCase() && validateUnderscores(name)));
|
||||
}
|
||||
/** Check for leading trailing and adjacent underscores */
|
||||
function validateUnderscores(name) {
|
||||
if (name.startsWith('_')) {
|
||||
return false;
|
||||
}
|
||||
let wasUnderscore = false;
|
||||
for (let i = 1; i < name.length; ++i) {
|
||||
if (name[i] === '_') {
|
||||
if (wasUnderscore) {
|
||||
return false;
|
||||
}
|
||||
wasUnderscore = true;
|
||||
}
|
||||
else {
|
||||
wasUnderscore = false;
|
||||
}
|
||||
}
|
||||
return !wasUnderscore;
|
||||
}
|
||||
const PredefinedFormatToCheckFunction = {
|
||||
[enums_1.PredefinedFormats.PascalCase]: isPascalCase,
|
||||
[enums_1.PredefinedFormats.StrictPascalCase]: isStrictPascalCase,
|
||||
[enums_1.PredefinedFormats.camelCase]: isCamelCase,
|
||||
[enums_1.PredefinedFormats.strictCamelCase]: isStrictCamelCase,
|
||||
[enums_1.PredefinedFormats.UPPER_CASE]: isUpperCase,
|
||||
[enums_1.PredefinedFormats.snake_case]: isSnakeCase,
|
||||
};
|
||||
exports.PredefinedFormatToCheckFunction = PredefinedFormatToCheckFunction;
|
||||
//# sourceMappingURL=format.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/rules/naming-convention-utils/format.ts"],"names":[],"mappings":";;;AAAA,mCAA4C;AAE5C;;;;;;EAME;AAEF;;;;EAIE;AAEF,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,CAAC;QACjB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAC3D,CAAC;AACJ,CAAC;AACD,SAAS,kBAAkB,CAAC,IAAY;IACtC,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,CAAC;QACjB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,CAAC;QACjB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAC3D,CAAC;AACJ,CAAC;AACD,SAAS,iBAAiB,CAAC,IAAY;IACrC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AC;AAED,0DAA0D;AAC1D,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IACD,IAAI,aAAa,GAAG,KAAK,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACpC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YACnB,IAAI,aAAa,EAAE;gBACjB,OAAO,KAAK,CAAC;aACd;YACD,aAAa,GAAG,IAAI,CAAC;SACtB;aAAM;YACL,aAAa,GAAG,KAAK,CAAC;SACvB;KACF;IACD,OAAO,CAAC,aAAa,CAAC;AACxB,CAAC;AAED,MAAM,+BAA+B,GAEjC;IACF,CAAC,yBAAiB,CAAC,UAAU,CAAC,EAAE,YAAY;IAC5C,CAAC,yBAAiB,CAAC,gBAAgB,CAAC,EAAE,kBAAkB;IACxD,CAAC,yBAAiB,CAAC,SAAS,CAAC,EAAE,WAAW;IAC1C,CAAC,yBAAiB,CAAC,eAAe,CAAC,EAAE,iBAAiB;IACtD,CAAC,yBAAiB,CAAC,UAAU,CAAC,EAAE,WAAW;IAC3C,CAAC,yBAAiB,CAAC,UAAU,CAAC,EAAE,WAAW;CAC5C,CAAC;AAEO,0EAA+B"}
|
||||
@@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseOptions = exports.selectorTypeToMessageString = exports.SCHEMA = exports.Modifiers = void 0;
|
||||
var enums_1 = require("./enums");
|
||||
Object.defineProperty(exports, "Modifiers", { enumerable: true, get: function () { return enums_1.Modifiers; } });
|
||||
var schema_1 = require("./schema");
|
||||
Object.defineProperty(exports, "SCHEMA", { enumerable: true, get: function () { return schema_1.SCHEMA; } });
|
||||
var shared_1 = require("./shared");
|
||||
Object.defineProperty(exports, "selectorTypeToMessageString", { enumerable: true, get: function () { return shared_1.selectorTypeToMessageString; } });
|
||||
var parse_options_1 = require("./parse-options");
|
||||
Object.defineProperty(exports, "parseOptions", { enumerable: true, get: function () { return parse_options_1.parseOptions; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rules/naming-convention-utils/index.ts"],"names":[],"mappings":";;;AAAA,iCAAoC;AAA3B,kGAAA,SAAS,OAAA;AAGlB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,mCAAuD;AAA9C,qHAAA,2BAA2B,OAAA;AACpC,iDAA+C;AAAtC,6GAAA,YAAY,OAAA"}
|
||||
@@ -1,90 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseOptions = void 0;
|
||||
const util = __importStar(require("../../util"));
|
||||
const enums_1 = require("./enums");
|
||||
const shared_1 = require("./shared");
|
||||
const validator_1 = require("./validator");
|
||||
function normalizeOption(option) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
let weight = 0;
|
||||
(_a = option.modifiers) === null || _a === void 0 ? void 0 : _a.forEach(mod => {
|
||||
weight |= enums_1.Modifiers[mod];
|
||||
});
|
||||
(_b = option.types) === null || _b === void 0 ? void 0 : _b.forEach(mod => {
|
||||
weight |= enums_1.TypeModifiers[mod];
|
||||
});
|
||||
// give selectors with a filter the _highest_ priority
|
||||
if (option.filter) {
|
||||
weight |= 1 << 30;
|
||||
}
|
||||
const normalizedOption = {
|
||||
// format options
|
||||
format: option.format ? option.format.map(f => enums_1.PredefinedFormats[f]) : null,
|
||||
custom: option.custom
|
||||
? {
|
||||
regex: new RegExp(option.custom.regex, 'u'),
|
||||
match: option.custom.match,
|
||||
}
|
||||
: null,
|
||||
leadingUnderscore: option.leadingUnderscore !== undefined
|
||||
? enums_1.UnderscoreOptions[option.leadingUnderscore]
|
||||
: null,
|
||||
trailingUnderscore: option.trailingUnderscore !== undefined
|
||||
? enums_1.UnderscoreOptions[option.trailingUnderscore]
|
||||
: null,
|
||||
prefix: option.prefix && option.prefix.length > 0 ? option.prefix : null,
|
||||
suffix: option.suffix && option.suffix.length > 0 ? option.suffix : null,
|
||||
modifiers: (_d = (_c = option.modifiers) === null || _c === void 0 ? void 0 : _c.map(m => enums_1.Modifiers[m])) !== null && _d !== void 0 ? _d : null,
|
||||
types: (_f = (_e = option.types) === null || _e === void 0 ? void 0 : _e.map(m => enums_1.TypeModifiers[m])) !== null && _f !== void 0 ? _f : null,
|
||||
filter: option.filter !== undefined
|
||||
? typeof option.filter === 'string'
|
||||
? {
|
||||
regex: new RegExp(option.filter, 'u'),
|
||||
match: true,
|
||||
}
|
||||
: {
|
||||
regex: new RegExp(option.filter.regex, 'u'),
|
||||
match: option.filter.match,
|
||||
}
|
||||
: null,
|
||||
// calculated ordering weight based on modifiers
|
||||
modifierWeight: weight,
|
||||
};
|
||||
const selectors = Array.isArray(option.selector)
|
||||
? option.selector
|
||||
: [option.selector];
|
||||
return selectors.map(selector => (Object.assign({ selector: (0, shared_1.isMetaSelector)(selector)
|
||||
? enums_1.MetaSelectors[selector]
|
||||
: enums_1.Selectors[selector] }, normalizedOption)));
|
||||
}
|
||||
function parseOptions(context) {
|
||||
const normalizedOptions = context.options
|
||||
.map(opt => normalizeOption(opt))
|
||||
.reduce((acc, val) => acc.concat(val), []);
|
||||
return util.getEnumNames(enums_1.Selectors).reduce((acc, k) => {
|
||||
acc[k] = (0, validator_1.createValidator)(k, context, normalizedOptions);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
exports.parseOptions = parseOptions;
|
||||
//# sourceMappingURL=parse-options.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"parse-options.js","sourceRoot":"","sources":["../../../src/rules/naming-convention-utils/parse-options.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,mCAOiB;AACjB,qCAA0C;AAO1C,2CAA8C;AAE9C,SAAS,eAAe,CAAC,MAAgB;;IACvC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAA,MAAM,CAAC,SAAS,0CAAE,OAAO,CAAC,GAAG,CAAC,EAAE;QAC9B,MAAM,IAAI,iBAAS,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,MAAA,MAAM,CAAC,KAAK,0CAAE,OAAO,CAAC,GAAG,CAAC,EAAE;QAC1B,MAAM,IAAI,qBAAa,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,sDAAsD;IACtD,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;KACnB;IAED,MAAM,gBAAgB,GAAG;QACvB,iBAAiB;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,yBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;QAC3E,MA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AAEQ,oCAAY"}
|
||||
@@ -1,259 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SCHEMA = void 0;
|
||||
const enums_1 = require("./enums");
|
||||
const util = __importStar(require("../../util"));
|
||||
const UNDERSCORE_SCHEMA = {
|
||||
type: 'string',
|
||||
enum: util.getEnumNames(enums_1.UnderscoreOptions),
|
||||
};
|
||||
const PREFIX_SUFFIX_SCHEMA = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
minLength: 1,
|
||||
},
|
||||
additionalItems: false,
|
||||
};
|
||||
const MATCH_REGEX_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
match: { type: 'boolean' },
|
||||
regex: { type: 'string' },
|
||||
},
|
||||
required: ['match', 'regex'],
|
||||
};
|
||||
const FORMAT_OPTIONS_PROPERTIES = {
|
||||
format: {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
enum: util.getEnumNames(enums_1.PredefinedFormats),
|
||||
},
|
||||
additionalItems: false,
|
||||
},
|
||||
{
|
||||
type: 'null',
|
||||
},
|
||||
],
|
||||
},
|
||||
custom: MATCH_REGEX_SCHEMA,
|
||||
leadingUnderscore: UNDERSCORE_SCHEMA,
|
||||
trailingUnderscore: UNDERSCORE_SCHEMA,
|
||||
prefix: PREFIX_SUFFIX_SCHEMA,
|
||||
suffix: PREFIX_SUFFIX_SCHEMA,
|
||||
failureMessage: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
function selectorSchema(selectorString, allowType, modifiers) {
|
||||
const selector = {
|
||||
filter: {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'string',
|
||||
minLength: 1,
|
||||
},
|
||||
MATCH_REGEX_SCHEMA,
|
||||
],
|
||||
},
|
||||
selector: {
|
||||
type: 'string',
|
||||
enum: [selectorString],
|
||||
},
|
||||
};
|
||||
if (modifiers && modifiers.length > 0) {
|
||||
selector.modifiers = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
enum: modifiers,
|
||||
},
|
||||
additionalItems: false,
|
||||
};
|
||||
}
|
||||
if (allowType) {
|
||||
selector.types = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
enum: util.getEnumNames(enums_1.TypeModifiers),
|
||||
},
|
||||
additionalItems: false,
|
||||
};
|
||||
}
|
||||
return [
|
||||
{
|
||||
type: 'object',
|
||||
properties: Object.assign(Object.assign({}, FORMAT_OPTIONS_PROPERTIES), selector),
|
||||
required: ['selector', 'format'],
|
||||
additionalProperties: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
function selectorsSchema() {
|
||||
return {
|
||||
type: 'object',
|
||||
properties: Object.assign(Object.assign({}, FORMAT_OPTIONS_PROPERTIES), {
|
||||
filter: {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'string',
|
||||
minLength: 1,
|
||||
},
|
||||
MATCH_REGEX_SCHEMA,
|
||||
],
|
||||
},
|
||||
selector: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
enum: [
|
||||
...util.getEnumNames(enums_1.MetaSelectors),
|
||||
...util.getEnumNames(enums_1.Selectors),
|
||||
],
|
||||
},
|
||||
additionalItems: false,
|
||||
},
|
||||
modifiers: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
enum: util.getEnumNames(enums_1.Modifiers),
|
||||
},
|
||||
additionalItems: false,
|
||||
},
|
||||
types: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
enum: util.getEnumNames(enums_1.TypeModifiers),
|
||||
},
|
||||
additionalItems: false,
|
||||
},
|
||||
}),
|
||||
required: ['selector', 'format'],
|
||||
additionalProperties: false,
|
||||
};
|
||||
}
|
||||
const SCHEMA = {
|
||||
type: 'array',
|
||||
items: {
|
||||
oneOf: [
|
||||
selectorsSchema(),
|
||||
...selectorSchema('default', false, util.getEnumNames(enums_1.Modifiers)),
|
||||
...selectorSchema('variableLike', false, ['unused']),
|
||||
...selectorSchema('variable', true, [
|
||||
'const',
|
||||
'destructured',
|
||||
'exported',
|
||||
'global',
|
||||
'unused',
|
||||
]),
|
||||
...selectorSchema('function', false, ['exported', 'global', 'unused']),
|
||||
...selectorSchema('parameter', true, ['destructured', 'unused']),
|
||||
...selectorSchema('memberLike', false, [
|
||||
'abstract',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'readonly',
|
||||
'requiresQuotes',
|
||||
'static',
|
||||
]),
|
||||
...selectorSchema('classProperty', true, [
|
||||
'abstract',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'readonly',
|
||||
'requiresQuotes',
|
||||
'static',
|
||||
]),
|
||||
...selectorSchema('objectLiteralProperty', true, [
|
||||
'public',
|
||||
'requiresQuotes',
|
||||
]),
|
||||
...selectorSchema('typeProperty', true, [
|
||||
'public',
|
||||
'readonly',
|
||||
'requiresQuotes',
|
||||
]),
|
||||
...selectorSchema('parameterProperty', true, [
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'readonly',
|
||||
]),
|
||||
...selectorSchema('property', true, [
|
||||
'abstract',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'readonly',
|
||||
'requiresQuotes',
|
||||
'static',
|
||||
]),
|
||||
...selectorSchema('classMethod', false, [
|
||||
'abstract',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'requiresQuotes',
|
||||
'static',
|
||||
]),
|
||||
...selectorSchema('objectLiteralMethod', false, [
|
||||
'public',
|
||||
'requiresQuotes',
|
||||
]),
|
||||
...selectorSchema('typeMethod', false, ['public', 'requiresQuotes']),
|
||||
...selectorSchema('method', false, [
|
||||
'abstract',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'requiresQuotes',
|
||||
'static',
|
||||
]),
|
||||
...selectorSchema('accessor', true, [
|
||||
'abstract',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'requiresQuotes',
|
||||
'static',
|
||||
]),
|
||||
...selectorSchema('enumMember', false, ['requiresQuotes']),
|
||||
...selectorSchema('typeLike', false, ['abstract', 'exported', 'unused']),
|
||||
...selectorSchema('class', false, ['abstract', 'exported', 'unused']),
|
||||
...selectorSchema('interface', false, ['exported', 'unused']),
|
||||
...selectorSchema('typeAlias', false, ['exported', 'unused']),
|
||||
...selectorSchema('enum', false, ['exported', 'unused']),
|
||||
...selectorSchema('typeParameter', false, ['unused']),
|
||||
],
|
||||
},
|
||||
additionalItems: false,
|
||||
};
|
||||
exports.SCHEMA = SCHEMA;
|
||||
//# sourceMappingURL=schema.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/rules/naming-convention-utils/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,mCASiB;AACjB,iDAAmC;AAEnC,MAAM,iBAAiB,GAA2B;IAChD,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,yBAAiB,CAAC;CAC3C,CAAC;AACF,MAA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AAK,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YAC7D,GAAG,cAAc,CAAC,WAAW,EAAE,KAAK,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YAC7D,GAAG,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACxD,GAAG,cAAc,CAAC,eAAe,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC;SACtD;KACF;IACD,eAAe,EAAE,KAAK;CACvB,CAAC;AAEO,wBAAM"}
|
||||
@@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isMethodOrPropertySelector = exports.isMetaSelector = exports.selectorTypeToMessageString = void 0;
|
||||
const enums_1 = require("./enums");
|
||||
function selectorTypeToMessageString(selectorType) {
|
||||
const notCamelCase = selectorType.replace(/([A-Z])/g, ' $1');
|
||||
return notCamelCase.charAt(0).toUpperCase() + notCamelCase.slice(1);
|
||||
}
|
||||
exports.selectorTypeToMessageString = selectorTypeToMessageString;
|
||||
function isMetaSelector(selector) {
|
||||
return selector in enums_1.MetaSelectors;
|
||||
}
|
||||
exports.isMetaSelector = isMetaSelector;
|
||||
function isMethodOrPropertySelector(selector) {
|
||||
return (selector === enums_1.MetaSelectors.method || selector === enums_1.MetaSelectors.property);
|
||||
}
|
||||
exports.isMethodOrPropertySelector = isMethodOrPropertySelector;
|
||||
//# sourceMappingURL=shared.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/rules/naming-convention-utils/shared.ts"],"names":[],"mappings":";;;AAAA,mCAMiB;AAEjB,SAAS,2BAA2B,CAAC,YAA6B;IAChE,MAAM,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC7D,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC;AAiBC,kEAA2B;AAf7B,SAAS,cAAc,CACrB,QAAsE;IAEtE,OAAO,QAAQ,IAAI,qBAAa,CAAC;AACnC,CAAC;AAYC,wCAAc;AAVhB,SAAS,0BAA0B,CACjC,QAAsE;IAEtE,OAAO,CACL,QAAQ,KAAK,qBAAa,CAAC,MAAM,IAAI,QAAQ,KAAK,qBAAa,CAAC,QAAQ,CACzE,CAAC;AACJ,CAAC;AAKC,gEAA0B"}
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/rules/naming-convention-utils/types.ts"],"names":[],"mappings":""}
|
||||
@@ -1,368 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createValidator = void 0;
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const enums_1 = require("./enums");
|
||||
const format_1 = require("./format");
|
||||
const shared_1 = require("./shared");
|
||||
const util = __importStar(require("../../util"));
|
||||
function createValidator(type, context, allConfigs) {
|
||||
// make sure the "highest priority" configs are checked first
|
||||
const selectorType = enums_1.Selectors[type];
|
||||
const configs = allConfigs
|
||||
// gather all of the applicable selectors
|
||||
.filter(c => (c.selector & selectorType) !== 0 ||
|
||||
c.selector === enums_1.MetaSelectors.default)
|
||||
.sort((a, b) => {
|
||||
if (a.selector === b.selector) {
|
||||
// in the event of the same selector, order by modifier weight
|
||||
// sort descending - the type modifiers are "more important"
|
||||
return b.modifierWeight - a.modifierWeight;
|
||||
}
|
||||
const aIsMeta = (0, shared_1.isMetaSelector)(a.selector);
|
||||
const bIsMeta = (0, shared_1.isMetaSelector)(b.selector);
|
||||
// non-meta selectors should go ahead of meta selectors
|
||||
if (aIsMeta && !bIsMeta) {
|
||||
return 1;
|
||||
}
|
||||
if (!aIsMeta && bIsMeta) {
|
||||
return -1;
|
||||
}
|
||||
const aIsMethodOrProperty = (0, shared_1.isMethodOrPropertySelector)(a.selector);
|
||||
const bIsMethodOrProperty = (0, shared_1.isMethodOrPropertySelector)(b.selector);
|
||||
// for backward compatibility, method and property have higher precedence than other meta selectors
|
||||
if (aIsMethodOrProperty && !bIsMethodOrProperty) {
|
||||
return -1;
|
||||
}
|
||||
if (!aIsMethodOrProperty && bIsMethodOrProperty) {
|
||||
return 1;
|
||||
}
|
||||
// both aren't meta selectors
|
||||
// sort descending - the meta selectors are "least important"
|
||||
return b.selector - a.selector;
|
||||
});
|
||||
return (node, modifiers = new Set()) => {
|
||||
var _a, _b, _c;
|
||||
const originalName = node.type === experimental_utils_1.AST_NODE_TYPES.Identifier ? node.name : `${node.value}`;
|
||||
// return will break the loop and stop checking configs
|
||||
// it is only used when the name is known to have failed or succeeded a config.
|
||||
for (const config of configs) {
|
||||
if (((_a = config.filter) === null || _a === void 0 ? void 0 : _a.regex.test(originalName)) !== ((_b = config.filter) === null || _b === void 0 ? void 0 : _b.match)) {
|
||||
// name does not match the filter
|
||||
continue;
|
||||
}
|
||||
if ((_c = config.modifiers) === null || _c === void 0 ? void 0 : _c.some(modifier => !modifiers.has(modifier))) {
|
||||
// does not have the required modifiers
|
||||
continue;
|
||||
}
|
||||
if (!isCorrectType(node, config, context, selectorType)) {
|
||||
// is not the correct type
|
||||
continue;
|
||||
}
|
||||
let name = originalName;
|
||||
name = validateUnderscore('leading', config, name, node, originalName);
|
||||
if (name === null) {
|
||||
// fail
|
||||
return;
|
||||
}
|
||||
name = validateUnderscore('trailing', config, name, node, originalName);
|
||||
if (name === null) {
|
||||
// fail
|
||||
return;
|
||||
}
|
||||
name = validateAffix('prefix', config, name, node, originalName);
|
||||
if (name === null) {
|
||||
// fail
|
||||
return;
|
||||
}
|
||||
name = validateAffix('suffix', config, name, node, originalName);
|
||||
if (name === null) {
|
||||
// fail
|
||||
return;
|
||||
}
|
||||
if (!validateCustom(config, name, node, originalName)) {
|
||||
// fail
|
||||
return;
|
||||
}
|
||||
if (!validatePredefinedFormat(config, name, node, originalName)) {
|
||||
// fail
|
||||
return;
|
||||
}
|
||||
// it's valid for this config, so we don't need to check any more configs
|
||||
return;
|
||||
}
|
||||
};
|
||||
// centralizes the logic for formatting the report data
|
||||
function formatReportData({ affixes, formats, originalName, processedName, position, custom, count, }) {
|
||||
var _a;
|
||||
return {
|
||||
type: (0, shared_1.selectorTypeToMessageString)(type),
|
||||
name: originalName,
|
||||
processedName,
|
||||
position,
|
||||
count,
|
||||
affixes: affixes === null || affixes === void 0 ? void 0 : affixes.join(', '),
|
||||
formats: formats === null || formats === void 0 ? void 0 : formats.map(f => enums_1.PredefinedFormats[f]).join(', '),
|
||||
regex: (_a = custom === null || custom === void 0 ? void 0 : custom.regex) === null || _a === void 0 ? void 0 : _a.toString(),
|
||||
regexMatch: (custom === null || custom === void 0 ? void 0 : custom.match) === true
|
||||
? 'match'
|
||||
: (custom === null || custom === void 0 ? void 0 : custom.match) === false
|
||||
? 'not match'
|
||||
: null,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @returns the name with the underscore removed, if it is valid according to the specified underscore option, null otherwise
|
||||
*/
|
||||
function validateUnderscore(position, config, name, node, originalName) {
|
||||
const option = position === 'leading'
|
||||
? config.leadingUnderscore
|
||||
: config.trailingUnderscore;
|
||||
if (!option) {
|
||||
return name;
|
||||
}
|
||||
const hasSingleUnderscore = position === 'leading'
|
||||
? () => name.startsWith('_')
|
||||
: () => name.endsWith('_');
|
||||
const trimSingleUnderscore = position === 'leading'
|
||||
? () => name.slice(1)
|
||||
: () => name.slice(0, -1);
|
||||
const hasDoubleUnderscore = position === 'leading'
|
||||
? () => name.startsWith('__')
|
||||
: () => name.endsWith('__');
|
||||
const trimDoubleUnderscore = position === 'leading'
|
||||
? () => name.slice(2)
|
||||
: () => name.slice(0, -2);
|
||||
switch (option) {
|
||||
// ALLOW - no conditions as the user doesn't care if it's there or not
|
||||
case enums_1.UnderscoreOptions.allow: {
|
||||
if (hasSingleUnderscore()) {
|
||||
return trimSingleUnderscore();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
case enums_1.UnderscoreOptions.allowDouble: {
|
||||
if (hasDoubleUnderscore()) {
|
||||
return trimDoubleUnderscore();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
case enums_1.UnderscoreOptions.allowSingleOrDouble: {
|
||||
if (hasDoubleUnderscore()) {
|
||||
return trimDoubleUnderscore();
|
||||
}
|
||||
if (hasSingleUnderscore()) {
|
||||
return trimSingleUnderscore();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
// FORBID
|
||||
case enums_1.UnderscoreOptions.forbid: {
|
||||
if (hasSingleUnderscore()) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpectedUnderscore',
|
||||
data: formatReportData({
|
||||
originalName,
|
||||
position,
|
||||
count: 'one',
|
||||
}),
|
||||
});
|
||||
return null;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
// REQUIRE
|
||||
case enums_1.UnderscoreOptions.require: {
|
||||
if (!hasSingleUnderscore()) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'missingUnderscore',
|
||||
data: formatReportData({
|
||||
originalName,
|
||||
position,
|
||||
count: 'one',
|
||||
}),
|
||||
});
|
||||
return null;
|
||||
}
|
||||
return trimSingleUnderscore();
|
||||
}
|
||||
case enums_1.UnderscoreOptions.requireDouble: {
|
||||
if (!hasDoubleUnderscore()) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'missingUnderscore',
|
||||
data: formatReportData({
|
||||
originalName,
|
||||
position,
|
||||
count: 'two',
|
||||
}),
|
||||
});
|
||||
return null;
|
||||
}
|
||||
return trimDoubleUnderscore();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @returns the name with the affix removed, if it is valid according to the specified affix option, null otherwise
|
||||
*/
|
||||
function validateAffix(position, config, name, node, originalName) {
|
||||
const affixes = config[position];
|
||||
if (!affixes || affixes.length === 0) {
|
||||
return name;
|
||||
}
|
||||
for (const affix of affixes) {
|
||||
const hasAffix = position === 'prefix' ? name.startsWith(affix) : name.endsWith(affix);
|
||||
const trimAffix = position === 'prefix'
|
||||
? () => name.slice(affix.length)
|
||||
: () => name.slice(0, -affix.length);
|
||||
if (hasAffix) {
|
||||
// matches, so trim it and return
|
||||
return trimAffix();
|
||||
}
|
||||
}
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'missingAffix',
|
||||
data: formatReportData({
|
||||
originalName,
|
||||
position,
|
||||
affixes,
|
||||
}),
|
||||
});
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @returns true if the name is valid according to the `regex` option, false otherwise
|
||||
*/
|
||||
function validateCustom(config, name, node, originalName) {
|
||||
const custom = config.custom;
|
||||
if (!custom) {
|
||||
return true;
|
||||
}
|
||||
const result = custom.regex.test(name);
|
||||
if (custom.match && result) {
|
||||
return true;
|
||||
}
|
||||
if (!custom.match && !result) {
|
||||
return true;
|
||||
}
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'satisfyCustom',
|
||||
data: formatReportData({
|
||||
originalName,
|
||||
custom,
|
||||
}),
|
||||
});
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @returns true if the name is valid according to the `format` option, false otherwise
|
||||
*/
|
||||
function validatePredefinedFormat(config, name, node, originalName) {
|
||||
const formats = config.format;
|
||||
if (formats === null || formats.length === 0) {
|
||||
return true;
|
||||
}
|
||||
for (const format of formats) {
|
||||
const checker = format_1.PredefinedFormatToCheckFunction[format];
|
||||
if (checker(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
context.report({
|
||||
node,
|
||||
messageId: originalName === name
|
||||
? 'doesNotMatchFormat'
|
||||
: 'doesNotMatchFormatTrimmed',
|
||||
data: formatReportData({
|
||||
originalName,
|
||||
processedName: name,
|
||||
formats,
|
||||
}),
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.createValidator = createValidator;
|
||||
const SelectorsAllowedToHaveTypes = enums_1.Selectors.variable |
|
||||
enums_1.Selectors.parameter |
|
||||
enums_1.Selectors.classProperty |
|
||||
enums_1.Selectors.objectLiteralProperty |
|
||||
enums_1.Selectors.typeProperty |
|
||||
enums_1.Selectors.parameterProperty |
|
||||
enums_1.Selectors.accessor;
|
||||
function isCorrectType(node, config, context, selector) {
|
||||
if (config.types === null) {
|
||||
return true;
|
||||
}
|
||||
if ((SelectorsAllowedToHaveTypes & selector) === 0) {
|
||||
return true;
|
||||
}
|
||||
const { esTreeNodeToTSNodeMap, program } = util.getParserServices(context);
|
||||
const checker = program.getTypeChecker();
|
||||
const tsNode = esTreeNodeToTSNodeMap.get(node);
|
||||
const type = checker
|
||||
.getTypeAtLocation(tsNode)
|
||||
// remove null and undefined from the type, as we don't care about it here
|
||||
.getNonNullableType();
|
||||
for (const allowedType of config.types) {
|
||||
switch (allowedType) {
|
||||
case enums_1.TypeModifiers.array:
|
||||
if (isAllTypesMatch(type, t => checker.isArrayType(t) || checker.isTupleType(t))) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case enums_1.TypeModifiers.function:
|
||||
if (isAllTypesMatch(type, t => t.getCallSignatures().length > 0)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case enums_1.TypeModifiers.boolean:
|
||||
case enums_1.TypeModifiers.number:
|
||||
case enums_1.TypeModifiers.string: {
|
||||
const typeString = checker.typeToString(
|
||||
// this will resolve things like true => boolean, 'a' => string and 1 => number
|
||||
checker.getWidenedType(checker.getBaseTypeOfLiteralType(type)));
|
||||
const allowedTypeString = enums_1.TypeModifiers[allowedType];
|
||||
if (typeString === allowedTypeString) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @returns `true` if the type (or all union types) in the given type return true for the callback
|
||||
*/
|
||||
function isAllTypesMatch(type, cb) {
|
||||
if (type.isUnion()) {
|
||||
return type.types.every(t => cb(t));
|
||||
}
|
||||
return cb(type);
|
||||
}
|
||||
//# sourceMappingURL=validator.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,428 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const scope_manager_1 = require("@typescript-eslint/scope-manager");
|
||||
const util = __importStar(require("../util"));
|
||||
const naming_convention_utils_1 = require("./naming-convention-utils");
|
||||
// This essentially mirrors ESLint's `camelcase` rule
|
||||
// note that that rule ignores leading and trailing underscores and only checks those in the middle of a variable name
|
||||
const defaultCamelCaseAllTheThingsConfig = [
|
||||
{
|
||||
selector: 'default',
|
||||
format: ['camelCase'],
|
||||
leadingUnderscore: 'allow',
|
||||
trailingUnderscore: 'allow',
|
||||
},
|
||||
{
|
||||
selector: 'variable',
|
||||
format: ['camelCase', 'UPPER_CASE'],
|
||||
leadingUnderscore: 'allow',
|
||||
trailingUnderscore: 'allow',
|
||||
},
|
||||
{
|
||||
selector: 'typeLike',
|
||||
format: ['PascalCase'],
|
||||
},
|
||||
];
|
||||
exports.default = util.createRule({
|
||||
name: 'naming-convention',
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Variables',
|
||||
description: 'Enforces naming conventions for everything across a codebase',
|
||||
recommended: false,
|
||||
// technically only requires type checking if the user uses "type" modifiers
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
type: 'suggestion',
|
||||
messages: {
|
||||
unexpectedUnderscore: '{{type}} name `{{name}}` must not have a {{position}} underscore.',
|
||||
missingUnderscore: '{{type}} name `{{name}}` must have {{count}} {{position}} underscore(s).',
|
||||
missingAffix: '{{type}} name `{{name}}` must have one of the following {{position}}es: {{affixes}}',
|
||||
satisfyCustom: '{{type}} name `{{name}}` must {{regexMatch}} the RegExp: {{regex}}',
|
||||
doesNotMatchFormat: '{{type}} name `{{name}}` must match one of the following formats: {{formats}}',
|
||||
doesNotMatchFormatTrimmed: '{{type}} name `{{name}}` trimmed as `{{processedName}}` must match one of the following formats: {{formats}}',
|
||||
},
|
||||
schema: naming_convention_utils_1.SCHEMA,
|
||||
},
|
||||
defaultOptions: defaultCamelCaseAllTheThingsConfig,
|
||||
create(contextWithoutDefaults) {
|
||||
const context = contextWithoutDefaults.options &&
|
||||
contextWithoutDefaults.options.length > 0
|
||||
? contextWithoutDefaults
|
||||
: // only apply the defaults when the user provides no config
|
||||
Object.setPrototypeOf({
|
||||
options: defaultCamelCaseAllTheThingsConfig,
|
||||
}, contextWithoutDefaults);
|
||||
const validators = (0, naming_convention_utils_1.parseOptions)(context);
|
||||
// getParserServices(context, false) -- dirty hack to work around the docs checker test...
|
||||
const compilerOptions = util
|
||||
.getParserServices(context, true)
|
||||
.program.getCompilerOptions();
|
||||
function handleMember(validator, node, modifiers) {
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
const key = node.key;
|
||||
if (requiresQuoting(key, compilerOptions.target)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.requiresQuotes);
|
||||
}
|
||||
validator(key, modifiers);
|
||||
}
|
||||
function getMemberModifiers(node) {
|
||||
const modifiers = new Set();
|
||||
if (node.accessibility) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers[node.accessibility]);
|
||||
}
|
||||
else {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.public);
|
||||
}
|
||||
if (node.static) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.static);
|
||||
}
|
||||
if ('readonly' in node && node.readonly) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.readonly);
|
||||
}
|
||||
if (node.type === experimental_utils_1.AST_NODE_TYPES.TSAbstractClassProperty ||
|
||||
node.type === experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.abstract);
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
const unusedVariables = util.collectUnusedVariables(context);
|
||||
function isUnused(name, initialScope = context.getScope()) {
|
||||
var _a;
|
||||
let variable = null;
|
||||
let scope = initialScope;
|
||||
while (scope) {
|
||||
variable = (_a = scope.set.get(name)) !== null && _a !== void 0 ? _a : null;
|
||||
if (variable) {
|
||||
break;
|
||||
}
|
||||
scope = scope.upper;
|
||||
}
|
||||
if (!variable) {
|
||||
return false;
|
||||
}
|
||||
return unusedVariables.has(variable);
|
||||
}
|
||||
function isDestructured(id) {
|
||||
var _a, _b, _c;
|
||||
return (
|
||||
// `const { x }`
|
||||
// does not match `const { x: y }`
|
||||
(((_a = id.parent) === null || _a === void 0 ? void 0 : _a.type) === experimental_utils_1.AST_NODE_TYPES.Property && id.parent.shorthand) ||
|
||||
// `const { x = 2 }`
|
||||
// does not match const `{ x: y = 2 }`
|
||||
(((_b = id.parent) === null || _b === void 0 ? void 0 : _b.type) === experimental_utils_1.AST_NODE_TYPES.AssignmentPattern &&
|
||||
((_c = id.parent.parent) === null || _c === void 0 ? void 0 : _c.type) === experimental_utils_1.AST_NODE_TYPES.Property &&
|
||||
id.parent.parent.shorthand));
|
||||
}
|
||||
return {
|
||||
// #region variable
|
||||
VariableDeclarator(node) {
|
||||
const validator = validators.variable;
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
const identifiers = getIdentifiersFromPattern(node.id);
|
||||
const baseModifiers = new Set();
|
||||
const parent = node.parent;
|
||||
if ((parent === null || parent === void 0 ? void 0 : parent.type) === experimental_utils_1.AST_NODE_TYPES.VariableDeclaration) {
|
||||
if (parent.kind === 'const') {
|
||||
baseModifiers.add(naming_convention_utils_1.Modifiers.const);
|
||||
}
|
||||
if (isGlobal(context.getScope())) {
|
||||
baseModifiers.add(naming_convention_utils_1.Modifiers.global);
|
||||
}
|
||||
}
|
||||
identifiers.forEach(id => {
|
||||
const modifiers = new Set(baseModifiers);
|
||||
if (isDestructured(id)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.destructured);
|
||||
}
|
||||
if (isExported(parent, id.name, context.getScope())) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(id.name)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(id, modifiers);
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
// #region function
|
||||
'FunctionDeclaration, TSDeclareFunction, FunctionExpression'(node) {
|
||||
const validator = validators.function;
|
||||
if (!validator || node.id === null) {
|
||||
return;
|
||||
}
|
||||
const modifiers = new Set();
|
||||
// functions create their own nested scope
|
||||
const scope = context.getScope().upper;
|
||||
if (isGlobal(scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.global);
|
||||
}
|
||||
if (isExported(node, node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(node.id, modifiers);
|
||||
},
|
||||
// #endregion function
|
||||
// #region parameter
|
||||
'FunctionDeclaration, TSDeclareFunction, TSEmptyBodyFunctionExpression, FunctionExpression, ArrowFunctionExpression'(node) {
|
||||
const validator = validators.parameter;
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
node.params.forEach(param => {
|
||||
if (param.type === experimental_utils_1.AST_NODE_TYPES.TSParameterProperty) {
|
||||
return;
|
||||
}
|
||||
const identifiers = getIdentifiersFromPattern(param);
|
||||
identifiers.forEach(i => {
|
||||
const modifiers = new Set();
|
||||
if (isDestructured(i)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.destructured);
|
||||
}
|
||||
if (isUnused(i.name)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(i, modifiers);
|
||||
});
|
||||
});
|
||||
},
|
||||
// #endregion parameter
|
||||
// #region parameterProperty
|
||||
TSParameterProperty(node) {
|
||||
const validator = validators.parameterProperty;
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
const modifiers = getMemberModifiers(node);
|
||||
const identifiers = getIdentifiersFromPattern(node.parameter);
|
||||
identifiers.forEach(i => {
|
||||
validator(i, modifiers);
|
||||
});
|
||||
},
|
||||
// #endregion parameterProperty
|
||||
// #region property
|
||||
':not(ObjectPattern) > Property[computed = false][kind = "init"][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]'(node) {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
handleMember(validators.objectLiteralProperty, node, modifiers);
|
||||
},
|
||||
':matches(ClassProperty, TSAbstractClassProperty)[computed = false][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]'(node) {
|
||||
const modifiers = getMemberModifiers(node);
|
||||
handleMember(validators.classProperty, node, modifiers);
|
||||
},
|
||||
'TSPropertySignature[computed = false]'(node) {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
if (node.readonly) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.readonly);
|
||||
}
|
||||
handleMember(validators.typeProperty, node, modifiers);
|
||||
},
|
||||
// #endregion property
|
||||
// #region method
|
||||
[[
|
||||
'Property[computed = false][kind = "init"][value.type = "ArrowFunctionExpression"]',
|
||||
'Property[computed = false][kind = "init"][value.type = "FunctionExpression"]',
|
||||
'Property[computed = false][kind = "init"][value.type = "TSEmptyBodyFunctionExpression"]',
|
||||
].join(', ')](node) {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
handleMember(validators.objectLiteralMethod, node, modifiers);
|
||||
},
|
||||
[[
|
||||
':matches(ClassProperty, TSAbstractClassProperty)[computed = false][value.type = "ArrowFunctionExpression"]',
|
||||
':matches(ClassProperty, TSAbstractClassProperty)[computed = false][value.type = "FunctionExpression"]',
|
||||
':matches(ClassProperty, TSAbstractClassProperty)[computed = false][value.type = "TSEmptyBodyFunctionExpression"]',
|
||||
':matches(MethodDefinition, TSAbstractMethodDefinition)[computed = false][kind = "method"]',
|
||||
].join(', ')](node) {
|
||||
const modifiers = getMemberModifiers(node);
|
||||
handleMember(validators.classMethod, node, modifiers);
|
||||
},
|
||||
'TSMethodSignature[computed = false]'(node) {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
handleMember(validators.typeMethod, node, modifiers);
|
||||
},
|
||||
// #endregion method
|
||||
// #region accessor
|
||||
'Property[computed = false]:matches([kind = "get"], [kind = "set"])'(node) {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
handleMember(validators.accessor, node, modifiers);
|
||||
},
|
||||
'MethodDefinition[computed = false]:matches([kind = "get"], [kind = "set"])'(node) {
|
||||
const modifiers = getMemberModifiers(node);
|
||||
handleMember(validators.accessor, node, modifiers);
|
||||
},
|
||||
// #endregion accessor
|
||||
// #region enumMember
|
||||
// computed is optional, so can't do [computed = false]
|
||||
'TSEnumMember[computed != true]'(node) {
|
||||
const validator = validators.enumMember;
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
const id = node.id;
|
||||
const modifiers = new Set();
|
||||
if (requiresQuoting(id, compilerOptions.target)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.requiresQuotes);
|
||||
}
|
||||
validator(id, modifiers);
|
||||
},
|
||||
// #endregion enumMember
|
||||
// #region class
|
||||
'ClassDeclaration, ClassExpression'(node) {
|
||||
const validator = validators.class;
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
const id = node.id;
|
||||
if (id === null) {
|
||||
return;
|
||||
}
|
||||
const modifiers = new Set();
|
||||
// classes create their own nested scope
|
||||
const scope = context.getScope().upper;
|
||||
if (node.abstract) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.abstract);
|
||||
}
|
||||
if (isExported(node, id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(id, modifiers);
|
||||
},
|
||||
// #endregion class
|
||||
// #region interface
|
||||
TSInterfaceDeclaration(node) {
|
||||
const validator = validators.interface;
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
const modifiers = new Set();
|
||||
const scope = context.getScope();
|
||||
if (isExported(node, node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(node.id, modifiers);
|
||||
},
|
||||
// #endregion interface
|
||||
// #region typeAlias
|
||||
TSTypeAliasDeclaration(node) {
|
||||
const validator = validators.typeAlias;
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
const modifiers = new Set();
|
||||
const scope = context.getScope();
|
||||
if (isExported(node, node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(node.id, modifiers);
|
||||
},
|
||||
// #endregion typeAlias
|
||||
// #region enum
|
||||
TSEnumDeclaration(node) {
|
||||
const validator = validators.enum;
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
const modifiers = new Set();
|
||||
// enums create their own nested scope
|
||||
const scope = context.getScope().upper;
|
||||
if (isExported(node, node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(node.id, modifiers);
|
||||
},
|
||||
// #endregion enum
|
||||
// #region typeParameter
|
||||
'TSTypeParameterDeclaration > TSTypeParameter'(node) {
|
||||
const validator = validators.typeParameter;
|
||||
if (!validator) {
|
||||
return;
|
||||
}
|
||||
const modifiers = new Set();
|
||||
const scope = context.getScope();
|
||||
if (isUnused(node.name.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(node.name, modifiers);
|
||||
},
|
||||
// #endregion typeParameter
|
||||
};
|
||||
},
|
||||
});
|
||||
function getIdentifiersFromPattern(pattern) {
|
||||
const identifiers = [];
|
||||
const visitor = new scope_manager_1.PatternVisitor({}, pattern, id => identifiers.push(id));
|
||||
visitor.visit(pattern);
|
||||
return identifiers;
|
||||
}
|
||||
function isExported(node, name, scope) {
|
||||
var _a, _b;
|
||||
if (((_a = node === null || node === void 0 ? void 0 : node.parent) === null || _a === void 0 ? void 0 : _a.type) === experimental_utils_1.AST_NODE_TYPES.ExportDefaultDeclaration ||
|
||||
((_b = node === null || node === void 0 ? void 0 : node.parent) === null || _b === void 0 ? void 0 : _b.type) === experimental_utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
|
||||
return true;
|
||||
}
|
||||
if (scope == null) {
|
||||
return false;
|
||||
}
|
||||
const variable = scope.set.get(name);
|
||||
if (variable) {
|
||||
for (const ref of variable.references) {
|
||||
const refParent = ref.identifier.parent;
|
||||
if ((refParent === null || refParent === void 0 ? void 0 : refParent.type) === experimental_utils_1.AST_NODE_TYPES.ExportDefaultDeclaration ||
|
||||
(refParent === null || refParent === void 0 ? void 0 : refParent.type) === experimental_utils_1.AST_NODE_TYPES.ExportSpecifier) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isGlobal(scope) {
|
||||
if (scope == null) {
|
||||
return false;
|
||||
}
|
||||
return (scope.type === experimental_utils_1.TSESLint.Scope.ScopeType.global ||
|
||||
scope.type === experimental_utils_1.TSESLint.Scope.ScopeType.module);
|
||||
}
|
||||
function requiresQuoting(node, target) {
|
||||
const name = node.type === experimental_utils_1.AST_NODE_TYPES.Identifier ? node.name : `${node.value}`;
|
||||
return util.requiresQuoting(name, target);
|
||||
}
|
||||
//# sourceMappingURL=naming-convention.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,72 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const util = __importStar(require("../util"));
|
||||
exports.default = util.createRule({
|
||||
name: 'no-array-constructor',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Disallow generic `Array` constructors',
|
||||
category: 'Stylistic Issues',
|
||||
recommended: 'error',
|
||||
extendsBaseRule: true,
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
useLiteral: 'The array literal notation [] is preferable.',
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
/**
|
||||
* Disallow construction of dense arrays using the Array constructor
|
||||
* @param node node to evaluate
|
||||
*/
|
||||
function check(node) {
|
||||
if (node.arguments.length !== 1 &&
|
||||
node.callee.type === experimental_utils_1.AST_NODE_TYPES.Identifier &&
|
||||
node.callee.name === 'Array' &&
|
||||
!node.typeParameters &&
|
||||
!util.isOptionalCallExpression(node)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'useLiteral',
|
||||
fix(fixer) {
|
||||
if (node.arguments.length === 0) {
|
||||
return fixer.replaceText(node, '[]');
|
||||
}
|
||||
const fullText = context.getSourceCode().getText(node);
|
||||
const preambleLength = node.callee.range[1] - node.range[0];
|
||||
return fixer.replaceText(node, `[${fullText.slice(preambleLength + 1, -1)}]`);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
CallExpression: check,
|
||||
NewExpression: check,
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=no-array-constructor.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"no-array-constructor.js","sourceRoot":"","sources":["../../src/rules/no-array-constructor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8EAG+C;AAC/C,8CAAgC;AAEhC,kBAAe,IAAI,CAAC,UAAU,CAAC;IAC7B,IAAI,EAAE,sBAAsB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,uCAAuC;YACpD,QAAQ,EAAE,kBAAkB;YAC5B,WAAW,EAAE,OAAO;YACpB,eAAe,EAAE,IAAI;SACtB;QACD,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE;YACR,UAAU,EAAE,8CAA8C;SAC3D;QACD,MAAM,EAAE,EAAE;KACX;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ;;;WAGG;QACH,SAAS,KAAK,CACZ,IAAsD;YAEtD,IACE,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;gBAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,mCAAc,CAAC,UAAU;gBAC9C,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO;gBAC5B,CAAC,IAAI,CAAC,cAAc;gBACpB,CAAC,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,EACpC;gBACA,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAE,YAAY;oBACvB,GAAG,CAAC,KAAK;wBACP,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;4BAC/B,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;yBACtC;wBACD,MAAM,QAAQ,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;wBACvD,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;wBAE5D,OAAO,KAAK,CAAC,WAAW,CACtB,IAAI,EACJ,IAAI,QAAQ,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAC9C,CAAC;oBACJ,CAAC;iBACF,CAAC,CAAC;aACJ;QACH,CAAC;QAED,OAAO;YACL,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,KAAK;SACrB,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
||||
@@ -1,161 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
const ts = __importStar(require("typescript"));
|
||||
const util = __importStar(require("../util"));
|
||||
var Usefulness;
|
||||
(function (Usefulness) {
|
||||
Usefulness[Usefulness["Always"] = 0] = "Always";
|
||||
Usefulness["Never"] = "will";
|
||||
Usefulness["Sometimes"] = "may";
|
||||
})(Usefulness || (Usefulness = {}));
|
||||
exports.default = util.createRule({
|
||||
name: 'no-base-to-string',
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Requires that `.toString()` is only called on objects which provide useful information when stringified',
|
||||
category: 'Best Practices',
|
||||
recommended: false,
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
messages: {
|
||||
baseToString: "'{{name}} {{certainty}} evaluate to '[object Object]' when stringified.",
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
ignoredTypeNames: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
type: 'suggestion',
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
ignoredTypeNames: ['RegExp'],
|
||||
},
|
||||
],
|
||||
create(context, [option]) {
|
||||
var _a;
|
||||
const parserServices = util.getParserServices(context);
|
||||
const typeChecker = parserServices.program.getTypeChecker();
|
||||
const ignoredTypeNames = (_a = option.ignoredTypeNames) !== null && _a !== void 0 ? _a : [];
|
||||
function checkExpression(node, type) {
|
||||
if (node.type === experimental_utils_1.AST_NODE_TYPES.Literal) {
|
||||
return;
|
||||
}
|
||||
const certainty = collectToStringCertainty(type !== null && type !== void 0 ? type : typeChecker.getTypeAtLocation(parserServices.esTreeNodeToTSNodeMap.get(node)));
|
||||
if (certainty === Usefulness.Always) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
data: {
|
||||
certainty,
|
||||
name: context.getSourceCode().getText(node),
|
||||
},
|
||||
messageId: 'baseToString',
|
||||
node,
|
||||
});
|
||||
}
|
||||
function collectToStringCertainty(type) {
|
||||
const toString = typeChecker.getPropertyOfType(type, 'toString');
|
||||
const declarations = toString === null || toString === void 0 ? void 0 : toString.getDeclarations();
|
||||
if (!toString || !declarations || declarations.length === 0) {
|
||||
return Usefulness.Always;
|
||||
}
|
||||
// Patch for old version TypeScript, the Boolean type definition missing toString()
|
||||
if (type.flags & ts.TypeFlags.Boolean ||
|
||||
type.flags & ts.TypeFlags.BooleanLiteral) {
|
||||
return Usefulness.Always;
|
||||
}
|
||||
if (ignoredTypeNames.includes(util.getTypeName(typeChecker, type))) {
|
||||
return Usefulness.Always;
|
||||
}
|
||||
if (declarations.every(({ parent }) => !ts.isInterfaceDeclaration(parent) || parent.name.text !== 'Object')) {
|
||||
return Usefulness.Always;
|
||||
}
|
||||
if (type.isIntersection()) {
|
||||
for (const subType of type.types) {
|
||||
const subtypeUsefulness = collectToStringCertainty(subType);
|
||||
if (subtypeUsefulness === Usefulness.Always) {
|
||||
return Usefulness.Always;
|
||||
}
|
||||
}
|
||||
return Usefulness.Never;
|
||||
}
|
||||
if (!type.isUnion()) {
|
||||
return Usefulness.Never;
|
||||
}
|
||||
let allSubtypesUseful = true;
|
||||
let someSubtypeUseful = false;
|
||||
for (const subType of type.types) {
|
||||
const subtypeUsefulness = collectToStringCertainty(subType);
|
||||
if (subtypeUsefulness !== Usefulness.Always && allSubtypesUseful) {
|
||||
allSubtypesUseful = false;
|
||||
}
|
||||
if (subtypeUsefulness !== Usefulness.Never && !someSubtypeUseful) {
|
||||
someSubtypeUseful = true;
|
||||
}
|
||||
}
|
||||
if (allSubtypesUseful && someSubtypeUseful) {
|
||||
return Usefulness.Always;
|
||||
}
|
||||
if (someSubtypeUseful) {
|
||||
return Usefulness.Sometimes;
|
||||
}
|
||||
return Usefulness.Never;
|
||||
}
|
||||
return {
|
||||
'AssignmentExpression[operator = "+="], BinaryExpression[operator = "+"]'(node) {
|
||||
const leftType = typeChecker.getTypeAtLocation(parserServices.esTreeNodeToTSNodeMap.get(node.left));
|
||||
const rightType = typeChecker.getTypeAtLocation(parserServices.esTreeNodeToTSNodeMap.get(node.right));
|
||||
if (util.getTypeName(typeChecker, leftType) === 'string') {
|
||||
checkExpression(node.right, rightType);
|
||||
}
|
||||
else if (util.getTypeName(typeChecker, rightType) === 'string') {
|
||||
checkExpression(node.left, leftType);
|
||||
}
|
||||
},
|
||||
'CallExpression > MemberExpression.callee > Identifier[name = "toString"].property'(node) {
|
||||
const memberExpr = node.parent;
|
||||
checkExpression(memberExpr.object);
|
||||
},
|
||||
TemplateLiteral(node) {
|
||||
if (node.parent &&
|
||||
node.parent.type === experimental_utils_1.AST_NODE_TYPES.TaggedTemplateExpression) {
|
||||
return;
|
||||
}
|
||||
for (const expression of node.expressions) {
|
||||
checkExpression(expression);
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=no-base-to-string.js.map
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user