Upgrade TypeScript to 9.2.0

This commit is contained in:
Henry Mercer 2023-01-18 20:00:33 +00:00
parent 40a75182e7
commit 5f644f971e
2873 changed files with 320828 additions and 210965 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 TypeScript ESLint and other contributors
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

View file

@ -1,234 +1,10 @@
<h1 align="center">ESLint Plugin TypeScript</h1>
# `@typescript-eslint/eslint-plugin`
<p align="center">An ESLint plugin which provides lint rules for TypeScript codebases.</p>
An ESLint plugin which provides lint rules for TypeScript codebases.
<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>
[![NPM Version](https://img.shields.io/npm/v/@typescript-eslint/eslint-plugin.svg?style=flat-square)](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)
[![NPM Downloads](https://img.shields.io/npm/dm/@typescript-eslint/eslint-plugin.svg?style=flat-square)](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)
## Getting Started
👉 See **https://typescript-eslint.io/architecture/utils** for our Getting Started docs.
- **[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-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-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 an 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-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-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/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).
> See https://typescript-eslint.io for general documentation on typescript-eslint, the tooling that allows you to run ESLint and Prettier on TypeScript code.

View file

@ -18,9 +18,11 @@ module.exports = {
'@typescript-eslint/comma-dangle': 'error',
'comma-spacing': 'off',
'@typescript-eslint/comma-spacing': 'error',
'@typescript-eslint/consistent-generic-constructors': 'error',
'@typescript-eslint/consistent-indexed-object-style': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'default-param-last': 'off',
'@typescript-eslint/default-param-last': 'error',
@ -50,8 +52,8 @@ module.exports = {
'@typescript-eslint/no-confusing-void-expression': 'error',
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': 'error',
'@typescript-eslint/no-duplicate-enum-values': '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',
@ -65,7 +67,6 @@ module.exports = {
'@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',
@ -78,15 +79,20 @@ module.exports = {
'@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',
'@typescript-eslint/parameter-properties': 'error',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'error',
'@typescript-eslint/no-redundant-type-constituents': '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',
@ -102,6 +108,7 @@ module.exports = {
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'no-unused-expressions': 'off',
@ -112,10 +119,13 @@ module.exports = {
'@typescript-eslint/no-use-before-define': 'error',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-useless-empty-export': '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',
@ -129,6 +139,7 @@ module.exports = {
'@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',
@ -143,7 +154,9 @@ module.exports = {
'@typescript-eslint/return-await': 'error',
semi: 'off',
'@typescript-eslint/semi': 'error',
'@typescript-eslint/sort-type-union-intersection-members': 'error',
'@typescript-eslint/sort-type-constituents': 'error',
'space-before-blocks': 'off',
'@typescript-eslint/space-before-blocks': 'error',
'space-before-function-paren': 'off',
'@typescript-eslint/space-before-function-paren': 'error',
'space-infix-ops': 'off',

View file

@ -1 +1 @@
{"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,EAAE,OAAO;QAChD,8BAA8B,EAAE,OAAO;QACvC,aAAa,EAAE,KAAK;QACpB,gCAAgC,EAAE,OAAO;QACzC,iDAAiD,EAAE,OAAO;QAC1D,cAAc,EAAE,KAAK;QACrB,iCAAiC,EAAE,OAAO;QAC1C,eAAe,EAAE,KAAK;QACtB,kCAAkC,EAAE,OAAO;QAC3C,oDAAoD,EAAE,OAAO;QAC7D,+CAA+C,EAAE,OAAO;QACxD,gDAAgD,EAAE,OAAO;QACzD,4CAA4C,EAAE,OAAO;QACrD,oBAAoB,EAAE,KAAK;QAC3B,uCAAuC,EAAE,OAAO;QAChD,cA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OAAO;QACpD,2CAA2C,EAAE,OAAO;QACpD,MAAM,EAAE,KAAK;QACb,2BAA2B,EAAE,OAAO;QACpC,+CAA+C,EAAE,OAAO;QACxD,eAAe,EAAE,KAAK;QACtB,kCAAkC,EAAE,OAAO;QAC3C,2CAA2C,EAAE,OAAO;QACpD,kDAAkD,EAAE,OAAO;QAC3D,iBAAiB,EAAE,KAAK;QACxB,iCAAiC,EAAE,OAAO;QAC1C,IAAI,EAAE,KAAK;QACX,yBAAyB,EAAE,OAAO;QAClC,2CAA2C,EAAE,OAAO;QACpD,qBAAqB,EAAE,KAAK;QAC5B,wCAAwC,EAAE,OAAO;QACjD,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"}

View file

@ -2,7 +2,7 @@
module.exports = {
overrides: [
{
files: ['*.ts', '*.tsx'],
files: ['*.ts', '*.tsx', '*.mts', '*.cts'],
rules: {
'constructor-super': 'off',
'getter-return': 'off',

View file

@ -1 +1 @@
{"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"}
{"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,EAAE,OAAO,EAAE,OAAO,CAAC;YAC1C,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"}

View file

@ -12,11 +12,11 @@ module.exports = {
'@typescript-eslint/no-implied-eval': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': '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',
'@typescript-eslint/prefer-regexp-exec': 'error',
'require-await': 'off',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',

View file

@ -1 +1 @@
{"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"}
{"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,uCAAuC,EAAE,OAAO;QAChD,yCAAyC,EAAE,OAAO;QAClD,mCAAmC,EAAE,OAAO;QAC5C,4CAA4C,EAAE,OAAO;QACrD,qCAAqC,EAAE,OAAO;QAC9C,eAAe,EAAE,KAAK;QACtB,kCAAkC,EAAE,OAAO;QAC3C,2CAA2C,EAAE,OAAO;QACpD,kDAAkD,EAAE,OAAO;QAC3D,mCAAmC,EAAE,OAAO;KAC7C;CACF,CAAC"}

View file

@ -8,7 +8,6 @@ module.exports = {
'@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',
@ -19,11 +18,14 @@ module.exports = {
'no-extra-semi': 'off',
'@typescript-eslint/no-extra-semi': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'no-loss-of-precision': 'off',
'@typescript-eslint/no-loss-of-precision': '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',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-var-requires': 'error',

View file

@ -1 +1 @@
{"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,gCA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AAM;QAC5C,gDAAgD,EAAE,OAAO;QACzD,eAAe,EAAE,KAAK;QACtB,kCAAkC,EAAE,OAAO;QAC3C,wCAAwC,EAAE,OAAO;QACjD,sBAAsB,EAAE,KAAK;QAC7B,yCAAyC,EAAE,OAAO;QAClD,mCAAmC,EAAE,OAAO;QAC5C,iCAAiC,EAAE,OAAO;QAC1C,wDAAwD,EAAE,OAAO;QACjE,0CAA0C,EAAE,MAAM;QAClD,kCAAkC,EAAE,OAAO;QAC3C,mDAAmD,EAAE,OAAO;QAC5D,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"}

View file

@ -0,0 +1,47 @@
"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/array-type': 'warn',
'@typescript-eslint/ban-tslint-comment': 'warn',
'@typescript-eslint/class-literal-property-style': 'warn',
'@typescript-eslint/consistent-indexed-object-style': 'warn',
'@typescript-eslint/consistent-generic-constructors': 'warn',
'@typescript-eslint/consistent-type-assertions': 'warn',
'@typescript-eslint/consistent-type-definitions': 'warn',
'dot-notation': 'off',
'@typescript-eslint/dot-notation': 'warn',
'@typescript-eslint/no-base-to-string': 'warn',
'@typescript-eslint/no-confusing-non-null-assertion': 'warn',
'@typescript-eslint/no-duplicate-enum-values': 'warn',
'@typescript-eslint/no-dynamic-delete': 'warn',
'@typescript-eslint/no-extraneous-class': 'warn',
'@typescript-eslint/no-invalid-void-type': 'warn',
'@typescript-eslint/no-meaningless-void-operator': 'warn',
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'warn',
'no-throw-literal': 'off',
'@typescript-eslint/no-throw-literal': 'warn',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn',
'@typescript-eslint/no-unnecessary-condition': 'warn',
'@typescript-eslint/no-unnecessary-type-arguments': 'warn',
'@typescript-eslint/no-unsafe-declaration-merging': 'warn',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'warn',
'@typescript-eslint/non-nullable-type-assertion-style': 'warn',
'@typescript-eslint/prefer-for-of': 'warn',
'@typescript-eslint/prefer-function-type': 'warn',
'@typescript-eslint/prefer-includes': 'warn',
'@typescript-eslint/prefer-literal-enum-member': 'warn',
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
'@typescript-eslint/prefer-optional-chain': 'warn',
'@typescript-eslint/prefer-reduce-type-parameter': 'warn',
'@typescript-eslint/prefer-return-this-type': 'warn',
'@typescript-eslint/prefer-string-starts-ends-with': 'warn',
'@typescript-eslint/prefer-ts-expect-error': 'warn',
'@typescript-eslint/unified-signatures': 'warn',
},
};
//# sourceMappingURL=strict.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"strict.js","sourceRoot":"","sources":["../../src/configs/strict.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,gCAAgC;AAChC,oDAAoD;AAEpD,iBAAS;IACP,OAAO,EAAE,CAAC,gBAAgB,EAAE,8BAA8B,CAAC;IAC3D,KAAK,EAAE;QACL,+BAA+B,EAAE,MAAM;QACvC,uCAAuC,EAAE,MAAM;QAC/C,iDAAiD,EAAE,MAAM;QACzD,oDAAoD,EAAE,MAAM;QAC5D,oDAAoD,EAAE,MAAM;QAC5D,+CAA+C,EAAE,MAAM;QACvD,gDAAgD,EAAE,MAAM;QACxD,cAAc,EAAE,KAAK;QACrB,iCAAiC,EAAE,MAAM;QACzC,sCAAsC,EAAE,MAAM;QAC9C,oDAAoD,EAAE,MAAM;QAC5D,6CAA6C,EAAE,MAAM;QACrD,sCAAsC,EAAE,MAAM;QAC9C,wCAAwC,EAAE,MAAM;QAChD,yCAAyC,EAAE,MAAM;QACjD,iDAAiD,EAAE,MAAM;QACzD,4DAA4D,EAAE,MAAM;QACpE,kBAAkB,EAAE,KAAK;QACzB,qCAAqC,EAAE,MAAM;QAC7C,2DAA2D,EAAE,MAAM;QACnE,6CAA6C,EAAE,MAAM;QACrD,kDAAkD,EAAE,MAAM;QAC1D,kDAAkD,EAAE,MAAM;QAC1D,wBAAwB,EAAE,KAAK;QAC/B,2CAA2C,EAAE,MAAM;QACnD,sDAAsD,EAAE,MAAM;QAC9D,kCAAkC,EAAE,MAAM;QAC1C,yCAAyC,EAAE,MAAM;QACjD,oCAAoC,EAAE,MAAM;QAC5C,+CAA+C,EAAE,MAAM;QACvD,8CAA8C,EAAE,MAAM;QACtD,0CAA0C,EAAE,MAAM;QAClD,iDAAiD,EAAE,MAAM;QACzD,4CAA4C,EAAE,MAAM;QACpD,mDAAmD,EAAE,MAAM;QAC3D,2CAA2C,EAAE,MAAM;QACnD,uCAAuC,EAAE,MAAM;KAChD;CACF,CAAC"}

View file

@ -2,12 +2,13 @@
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 eslint_recommended_1 = __importDefault(require("./configs/eslint-recommended"));
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"));
const strict_1 = __importDefault(require("./configs/strict"));
const rules_1 = __importDefault(require("./rules"));
module.exports = {
rules: rules_1.default,
configs: {
@ -16,6 +17,7 @@ module.exports = {
recommended: recommended_1.default,
'eslint-recommended': eslint_recommended_1.default,
'recommended-requiring-type-checking': recommended_requiring_type_checking_1.default,
strict: strict_1.default,
},
};
//# sourceMappingURL=index.js.map

View file

@ -1 +1 @@
{"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"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,wDAAgC;AAChC,0DAAkC;AAClC,sFAA6D;AAC7D,wEAAgD;AAChD,wHAA6F;AAC7F,8DAAsC;AACtC,oDAA4B;AAE5B,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;QACvE,MAAM,EAAN,gBAAM;KACP;CACF,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,20 +23,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/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',
description: 'Require that function overload signatures be consecutive',
recommended: 'error',
},
schema: [],
messages: {
adjacentSignature: "All '{{name}}' signatures should be adjacent.",
adjacentSignature: 'All {{name}} signatures should be adjacent.',
},
},
defaultOptions: [],
@ -50,8 +53,8 @@ exports.default = util.createRule({
}
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: {
case utils_1.AST_NODE_TYPES.ExportDefaultDeclaration:
case utils_1.AST_NODE_TYPES.ExportNamedDeclaration: {
// export statements (e.g. export { a };)
// have no declarations, so ignore them
if (!member.declaration) {
@ -59,8 +62,8 @@ exports.default = util.createRule({
}
return getMemberMethod(member.declaration);
}
case experimental_utils_1.AST_NODE_TYPES.TSDeclareFunction:
case experimental_utils_1.AST_NODE_TYPES.FunctionDeclaration: {
case utils_1.AST_NODE_TYPES.TSDeclareFunction:
case 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;
@ -69,32 +72,27 @@ exports.default = util.createRule({
name,
static: isStatic,
callSignature: false,
type: util.MemberNameType.Normal,
};
}
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:
case utils_1.AST_NODE_TYPES.TSMethodSignature:
return Object.assign(Object.assign({}, util.getNameFromMember(member, sourceCode)), { static: isStatic, callSignature: false });
case utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
return {
name: 'call',
static: isStatic,
callSignature: true,
type: util.MemberNameType.Normal,
};
case experimental_utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
case utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
return {
name: 'new',
static: isStatic,
callSignature: false,
type: util.MemberNameType.Normal,
};
case experimental_utils_1.AST_NODE_TYPES.MethodDefinition:
return {
name: util.getNameFromMember(member, sourceCode),
static: isStatic,
callSignature: false,
};
case utils_1.AST_NODE_TYPES.MethodDefinition:
return Object.assign(Object.assign({}, util.getNameFromMember(member, sourceCode)), { static: isStatic, callSignature: false });
}
return null;
}
@ -102,16 +100,18 @@ exports.default = util.createRule({
return (!!method2 &&
method1.name === method2.name &&
method1.static === method2.static &&
method1.callSignature === method2.callSignature);
method1.callSignature === method2.callSignature &&
method1.type === method2.type);
}
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:
case utils_1.AST_NODE_TYPES.ClassBody:
case utils_1.AST_NODE_TYPES.Program:
case utils_1.AST_NODE_TYPES.TSModuleBlock:
case utils_1.AST_NODE_TYPES.TSInterfaceBody:
case utils_1.AST_NODE_TYPES.BlockStatement:
return node.body;
case experimental_utils_1.AST_NODE_TYPES.TSTypeLiteral:
case utils_1.AST_NODE_TYPES.TSTypeLiteral:
return node.members;
}
}
@ -136,7 +136,7 @@ exports.default = util.createRule({
node: member,
messageId: 'adjacentSignature',
data: {
name: (method.static ? 'static ' : '') + method.name,
name: `${method.static ? 'static ' : ''}${method.name}`,
},
});
}
@ -153,6 +153,7 @@ exports.default = util.createRule({
TSModuleBlock: checkBodyForOverloadMethods,
TSTypeLiteral: checkBodyForOverloadMethods,
TSInterfaceBody: checkBodyForOverloadMethods,
BlockStatement: checkBodyForOverloadMethods,
};
},
});

View file

@ -1 +1 @@
{"version":3,"file":"adjacent-overload-signatures.js","sourceRoot":"","sources":["../../src/rules/adjacent-overload-signatures.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8EAG+C;AAC/C,8CAAg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;CACF,CAAC,CAAC"}
{"version":3,"file":"adjacent-overload-signatures.js","sourceRoot":"","sources":["../../src/rules/adjacent-overload-signatures.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAA0D;AAE1D,8CAAgC;AAchC,kBAAe,IAAI,CAAC,UAAU,CAAC;IAC7B,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,0DAA0D;YACvE,WAAW,EAAE,OAAO;SACrB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,iBAAiB,EAAE,6CAA6C;SACjE;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAS3C;;;;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,CAAC;YAEvD,QAAQ,MAAM,CAAC,IAAI,EAAE;gBACnB,KAAK,sBAAc,CAAC,wBAAwB,CAAC;gBAC7C,KAAK,sBAAc,CAAC,sBAAsB,CAAC,CAAC;oBAC1C,yCAAyC;oBACzC,uCAAuC;oBACvC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;wBACvB,OAAO,IAAI,CAAC;qBACb;oBAED,OAAO,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;iBAC5C;gBACD,KAAK,sBAAc,CAAC,iBAAiB,CAAC;gBACtC,KAAK,sBAAc,CAAC,mBAAmB,CAAC,CAAC;oBACvC,MAAM,IAAI,GAAG,MAAA,MAAA,MAAM,CAAC,EAAE,0CAAE,IAAI,mCAAI,IAAI,CAAC;oBACrC,IAAI,IAAI,KAAK,IAAI,EAAE;wBAC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AAC,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;YAC5C,cAAc,EAAE,2BAA2B;SAC5C,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
/**
* Check whatever node can be considered as simple
@ -27,25 +31,26 @@ const util = __importStar(require("../util"));
*/
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:
case utils_1.AST_NODE_TYPES.Identifier:
case utils_1.AST_NODE_TYPES.TSAnyKeyword:
case utils_1.AST_NODE_TYPES.TSBooleanKeyword:
case utils_1.AST_NODE_TYPES.TSNeverKeyword:
case utils_1.AST_NODE_TYPES.TSNumberKeyword:
case utils_1.AST_NODE_TYPES.TSBigIntKeyword:
case utils_1.AST_NODE_TYPES.TSObjectKeyword:
case utils_1.AST_NODE_TYPES.TSStringKeyword:
case utils_1.AST_NODE_TYPES.TSSymbolKeyword:
case utils_1.AST_NODE_TYPES.TSUnknownKeyword:
case utils_1.AST_NODE_TYPES.TSVoidKeyword:
case utils_1.AST_NODE_TYPES.TSNullKeyword:
case utils_1.AST_NODE_TYPES.TSArrayType:
case utils_1.AST_NODE_TYPES.TSUndefinedKeyword:
case utils_1.AST_NODE_TYPES.TSThisType:
case utils_1.AST_NODE_TYPES.TSQualifiedName:
return true;
case experimental_utils_1.AST_NODE_TYPES.TSTypeReference:
case utils_1.AST_NODE_TYPES.TSTypeReference:
if (node.typeName &&
node.typeName.type === experimental_utils_1.AST_NODE_TYPES.Identifier &&
node.typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
node.typeName.name === 'Array') {
if (!node.typeParameters) {
return true;
@ -71,47 +76,59 @@ function isSimpleType(node) {
*/
function typeNeedsParentheses(node) {
switch (node.type) {
case experimental_utils_1.AST_NODE_TYPES.TSTypeReference:
case 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:
case utils_1.AST_NODE_TYPES.TSUnionType:
case utils_1.AST_NODE_TYPES.TSFunctionType:
case utils_1.AST_NODE_TYPES.TSIntersectionType:
case utils_1.AST_NODE_TYPES.TSTypeOperator:
case utils_1.AST_NODE_TYPES.TSInferType:
case utils_1.AST_NODE_TYPES.TSConstructorType:
return true;
case experimental_utils_1.AST_NODE_TYPES.Identifier:
case 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,
description: 'Require consistently using either `T[]` or `Array<T>` for arrays',
recommended: 'strict',
},
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.",
errorStringGeneric: "Array type using '{{readonlyPrefix}}{{type}}[]' is forbidden. Use '{{className}}<{{type}}>' instead.",
errorStringArray: "Array type using '{{className}}<{{type}}>' is forbidden. Use '{{readonlyPrefix}}{{type}}[]' instead.",
errorStringArraySimple: "Array type using '{{className}}<{{type}}>' is forbidden for simple types. Use '{{readonlyPrefix}}{{type}}[]' instead.",
errorStringGenericSimple: "Array type using '{{readonlyPrefix}}{{type}}[]' is forbidden for non-simple types. Use '{{className}}<{{type}}>' instead.",
},
schema: [
{
type: 'object',
properties: {
default: arrayOption,
readonly: arrayOption,
schema: {
$defs: {
arrayOption: {
enum: ['array', 'generic', 'array-simple'],
},
},
],
prefixItems: [
{
properties: {
default: {
$ref: '#/$defs/arrayOption',
description: 'The array type expected for mutable cases...',
},
readonly: {
$ref: '#/$defs/arrayOption',
description: 'The array type expected for readonly cases. If omitted, the value for `default` will be used.',
},
},
type: 'object',
},
],
type: 'array',
},
},
defaultOptions: [
{
@ -127,20 +144,15 @@ exports.default = util.createRule({
* @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);
}
if (node && 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.type === utils_1.AST_NODE_TYPES.TSTypeOperator &&
node.parent.operator === 'readonly';
const currentOption = isReadonly ? readonlyOption : defaultOption;
if (currentOption === 'array' ||
@ -155,12 +167,12 @@ exports.default = util.createRule({
node: errorNode,
messageId,
data: {
className: isReadonly ? 'ReadonlyArray' : 'Array',
readonlyPrefix: isReadonly ? 'readonly ' : '',
type: getMessageType(node.elementType),
},
fix(fixer) {
const typeNode = node.elementType.type === experimental_utils_1.AST_NODE_TYPES.TSParenthesizedType
? node.elementType.typeAnnotation
: node.elementType;
const typeNode = node.elementType;
const arrayType = isReadonly ? 'ReadonlyArray' : 'Array';
return [
fixer.replaceTextRange([errorNode.range[0], typeNode.range[0]], `${arrayType}<`),
@ -171,7 +183,7 @@ exports.default = util.createRule({
},
TSTypeReference(node) {
var _a, _b;
if (node.typeName.type !== experimental_utils_1.AST_NODE_TYPES.Identifier ||
if (node.typeName.type !== utils_1.AST_NODE_TYPES.Identifier ||
!(node.typeName.name === 'Array' ||
node.typeName.name === 'ReadonlyArray')) {
return;
@ -194,6 +206,8 @@ exports.default = util.createRule({
node,
messageId,
data: {
className: isReadonlyArrayType ? 'ReadonlyArray' : 'Array',
readonlyPrefix,
type: 'any',
},
fix(fixer) {
@ -208,13 +222,17 @@ exports.default = util.createRule({
}
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 parentParens = readonlyPrefix &&
((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.TSArrayType &&
!util.isParenthesized(node.parent.elementType, sourceCode);
const start = `${parentParens ? '(' : ''}${readonlyPrefix}${typeParens ? '(' : ''}`;
const end = `${typeParens ? ')' : ''}[]${parentParens ? ')' : ''}`;
context.report({
node,
messageId,
data: {
className: isReadonlyArrayType ? 'ReadonlyArray' : 'Array',
readonlyPrefix,
type: getMessageType(type),
},
fix(fixer) {

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -25,8 +29,7 @@ exports.default = util.createRule({
name: 'await-thenable',
meta: {
docs: {
description: 'Disallows awaiting a value that is not a Thenable',
category: 'Best Practices',
description: 'Disallow awaiting a value that is not a Thenable',
recommended: 'error',
requiresTypeChecking: true,
},

View file

@ -1 +1 @@
{"version":3,"file":"await-thenable.js","sourceRoot":"","sources":["../../src/rules/await-thenable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;A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U,CAAC;IAC7B,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EAAE,kDAAkD;YAC/D,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"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -20,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultMinimumDescriptionLength = void 0;
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
exports.defaultMinimumDescriptionLength = 3;
exports.default = util.createRule({
@ -28,70 +32,53 @@ exports.default = util.createRule({
meta: {
type: 'problem',
docs: {
description: 'Bans `@ts-<directive>` comments from being used or requires descriptions after directive',
category: 'Best Practices',
description: 'Disallow `@ts-<directive>` comments or require descriptions after directives',
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.',
tsDirectiveCommentDescriptionNotMatchPattern: 'The description for the "@ts-{{directive}}" directive must match the {{format}} format.',
},
schema: [
{
type: 'object',
properties: {
'ts-expect-error': {
oneOf: [
{
type: 'boolean',
default: true,
schema: {
$defs: {
directiveConfigSchema: {
oneOf: [
{
type: 'boolean',
default: true,
},
{
enum: ['allow-with-description'],
},
{
type: 'object',
properties: {
descriptionFormat: { type: 'string' },
},
{
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,
},
],
prefixItems: [
{
properties: {
'ts-expect-error': {
$ref: '#/$defs/directiveConfigSchema',
},
'ts-ignore': { $ref: '#/$defs/directiveConfigSchema' },
'ts-nocheck': { $ref: '#/$defs/directiveConfigSchema' },
'ts-check': { $ref: '#/$defs/directiveConfigSchema' },
minimumDescriptionLength: {
type: 'number',
default: exports.defaultMinimumDescriptionLength,
},
},
additionalProperties: false,
},
],
type: 'array',
},
},
defaultOptions: [
{
@ -105,21 +92,35 @@ exports.default = util.createRule({
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
https://github.com/microsoft/TypeScript/blob/408c760fae66080104bc85c449282c2d207dfe8e/src/compiler/scanner.ts#L288-L296
*/
const commentDirectiveRegExSingleLine = /^\/*\s*@ts-(expect-error|ignore|check|nocheck)(.*)/;
const commentDirectiveRegExMultiLine = /^\s*(?:\/|\*)*\s*@ts-(expect-error|ignore|check|nocheck)(.*)/;
const commentDirectiveRegExSingleLine = /^\/*\s*@ts-(?<directive>expect-error|ignore|check|nocheck)(?<description>.*)/;
const commentDirectiveRegExMultiLine = /^\s*(?:\/|\*)*\s*@ts-(?<directive>expect-error|ignore|check|nocheck)(?<description>.*)/;
const sourceCode = context.getSourceCode();
const descriptionFormats = new Map();
for (const directive of [
'ts-expect-error',
'ts-ignore',
'ts-nocheck',
'ts-check',
]) {
const option = options[directive];
if (typeof option === 'object' && option.descriptionFormat) {
descriptionFormats.set(directive, new RegExp(option.descriptionFormat));
}
}
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 regExp = comment.type === utils_1.AST_TOKEN_TYPES.Line
? commentDirectiveRegExSingleLine
: commentDirectiveRegExMultiLine;
const match = regExp.exec(comment.value);
if (!match) {
return;
}
const [, directive, description] = (_a = regExp.exec(comment.value)) !== null && _a !== void 0 ? _a : [];
const { directive, description } = match.groups;
const fullDirective = `ts-${directive}`;
const option = options[fullDirective];
if (option === true) {
@ -129,8 +130,10 @@ exports.default = util.createRule({
messageId: 'tsDirectiveComment',
});
}
if (option === 'allow-with-description') {
if (option === 'allow-with-description' ||
(typeof option === 'object' && option.descriptionFormat)) {
const { minimumDescriptionLength = exports.defaultMinimumDescriptionLength, } = options;
const format = descriptionFormats.get(fullDirective);
if (description.trim().length < minimumDescriptionLength) {
context.report({
data: { directive, minimumDescriptionLength },
@ -138,6 +141,13 @@ exports.default = util.createRule({
messageId: 'tsDirectiveCommentRequiresDescription',
});
}
else if (format && !format.test(description)) {
context.report({
data: { directive, format: format.source },
node: comment,
messageId: 'tsDirectiveCommentDescriptionNotMatchPattern',
});
}
}
});
},

View file

@ -1 +1 @@
{"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,iBAAiB,EAAE;wBACjB,KAAK,EAAE;4BACL;gCACE,IAAI,EAAE,SAAS;gCACf,OAAO,EAAE,IAAI;6BACd;4BACD;gCACE,IAAI,EAAE,CAAC,wBAAwB,CAAC;6BACjC;yBACF;qBACF;oBACD,WAAW,EAAE;wBACX,KAAK,EAAE;4BACL;gCACE,IAAI,EAAE,SA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AG,CAAC,aAAa,CAAC,CAAC;wBACrD,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;6BAAM,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;4BAC9C,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;gCAC1C,IAAI,EAAE,OAAO;gCACb,SAAS,EAAE,8CAA8C;6BAC1D,CAAC,CAAC;yBACJ;qBACF;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,12 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/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
const toText = (text, type) => type === utils_1.AST_TOKEN_TYPES.Line
? ['//', text.trim()].join(' ')
: ['/*', text.trim(), '*/'].join(' ');
exports.default = util.createRule({
@ -32,9 +36,8 @@ exports.default = util.createRule({
meta: {
type: 'suggestion',
docs: {
description: 'Bans `// tslint:<rule-flag>` comments from being used',
category: 'Stylistic Issues',
recommended: false,
description: 'Disallow `// tslint:<rule-flag>` comments',
recommended: 'strict',
},
messages: {
commentDetected: 'tslint comment detected: "{{ text }}"',

View file

@ -1 +1 @@
{"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;IACD,cAAc,EAAE,EAAE;IAClB,M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AE,CAAC;4BACP,SAAS,EAAE,iBAAiB;4BAC5B,GAAG,CAAC,KAAK;gCACP,MAAM,UAAU,GAAG,UAAU,CAAC,eAAe,CAAC;oCAC5C,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;oCAC3D,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI;iCACvB,CAAC,CAAC;gCACH,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC;oCAC1C,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM;oCACxB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;iCACrB,CAAC,CAAC;gCACH,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,UAAU,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC;4BACvD,CAAC;yBACF,CAAC,CAAC;qBACJ;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -20,10 +24,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TYPE_KEYWORDS = void 0;
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
function removeSpaces(str) {
return str.replace(/ /g, '');
return str.replace(/\s/g, '');
}
function stringifyNode(node, sourceCode) {
return removeSpaces(sourceCode.getText(node));
@ -57,6 +61,10 @@ const defaultTypes = {
message: 'Use symbol instead',
fixWith: 'symbol',
},
BigInt: {
message: 'Use bigint instead',
fixWith: 'bigint',
},
Function: {
message: [
'The `Function` type accepts any function-like value.',
@ -69,45 +77,38 @@ const defaultTypes = {
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 object", you probably want `object` 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 object", you probably want `object` 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,
bigint: utils_1.AST_NODE_TYPES.TSBigIntKeyword,
boolean: utils_1.AST_NODE_TYPES.TSBooleanKeyword,
never: utils_1.AST_NODE_TYPES.TSNeverKeyword,
null: utils_1.AST_NODE_TYPES.TSNullKeyword,
number: utils_1.AST_NODE_TYPES.TSNumberKeyword,
object: utils_1.AST_NODE_TYPES.TSObjectKeyword,
string: utils_1.AST_NODE_TYPES.TSStringKeyword,
symbol: utils_1.AST_NODE_TYPES.TSSymbolKeyword,
undefined: utils_1.AST_NODE_TYPES.TSUndefinedKeyword,
unknown: utils_1.AST_NODE_TYPES.TSUnknownKeyword,
void: 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',
description: 'Disallow certain types',
recommended: 'error',
},
fixable: 'code',

View file

@ -1 +1 @@
{"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;KACX;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAClC,OAAO,IAAI,UAAU,EAAE,CAAC;KACzB;IAED,IAAI,UAAU,CAAC,OAAO,EAAE;QACtB,OAAO,IAAI,UAAU,CAAC,OAAO,EAAE,C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,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"}

View file

@ -1,43 +1,43 @@
"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 = util_1.createRule({
const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('brace-style');
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,
messages: baseRule.meta.messages,
fixable: baseRule.meta.fixable,
hasSuggestions: baseRule.meta.hasSuggestions,
schema: baseRule.meta.schema,
},
defaultOptions: ['1tbs'],
create(context) {
const [style, { allowSingleLine } = { allowSingleLine: false }] = context.options;
const [style, { allowSingleLine } = { allowSingleLine: false }] =
// eslint-disable-next-line no-restricted-syntax -- Use raw options for extended rules.
context.options;
const isAllmanStyle = style === 'allman';
const sourceCode = context.getSourceCode();
const rules = brace_style_1.default.create(context);
const rules = baseRule.create(context);
/**
* Checks a pair of curly brackets based on the user's config
*/
function validateCurlyPair(openingCurlyToken, closingCurlyToken) {
if (allowSingleLine &&
util_1.isTokenOnSameLine(openingCurlyToken, closingCurlyToken)) {
(0, util_1.isTokenOnSameLine)(openingCurlyToken, closingCurlyToken)) {
return;
}
const tokenBeforeOpeningCurly = sourceCode.getTokenBefore(openingCurlyToken);
const tokenBeforeClosingCurly = sourceCode.getTokenBefore(closingCurlyToken);
const tokenAfterOpeningCurly = sourceCode.getTokenAfter(openingCurlyToken);
if (!isAllmanStyle &&
!util_1.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurlyToken)) {
!(0, util_1.isTokenOnSameLine)(tokenBeforeOpeningCurly, openingCurlyToken)) {
context.report({
node: openingCurlyToken,
messageId: 'nextLineOpen',
@ -55,14 +55,14 @@ exports.default = util_1.createRule({
});
}
if (isAllmanStyle &&
util_1.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurlyToken)) {
(0, util_1.isTokenOnSameLine)(tokenBeforeOpeningCurly, openingCurlyToken)) {
context.report({
node: openingCurlyToken,
messageId: 'sameLineOpen',
fix: fixer => fixer.insertTextBefore(openingCurlyToken, '\n'),
});
}
if (util_1.isTokenOnSameLine(openingCurlyToken, tokenAfterOpeningCurly) &&
if ((0, util_1.isTokenOnSameLine)(openingCurlyToken, tokenAfterOpeningCurly) &&
tokenAfterOpeningCurly !== closingCurlyToken) {
context.report({
node: openingCurlyToken,
@ -70,7 +70,7 @@ exports.default = util_1.createRule({
fix: fixer => fixer.insertTextAfter(openingCurlyToken, '\n'),
});
}
if (util_1.isTokenOnSameLine(tokenBeforeClosingCurly, closingCurlyToken) &&
if ((0, util_1.isTokenOnSameLine)(tokenBeforeClosingCurly, closingCurlyToken) &&
tokenBeforeClosingCurly !== openingCurlyToken) {
context.report({
node: closingCurlyToken,

View file

@ -1 +1 @@
{"version":3,"file":"brace-style.js","sourceRoot":"","sources":["../../src/rules/brace-style.ts"],"names":[],"mappings":";;;;;AACA,+EAAoD;AACpD,kCAKiB;AAKjB,kBAAe,iBAAU,CAAsB;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,qBAAQ,CAAC,IAAI,CAAC,MAAM;KAC7B;IACD,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,MAAM,CAAC,OAAO;QACZ,MAAM,CAAC,KAAK,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,GAC7D,OAAO,CAAC,OAAO,CAAC;QAElB,MAAM,aAAa,GAAG,KAAK,KAAK,QAAQ,CAAC;QACzC,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,qBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEvC;;WAEG;QACH,SAAS,iBAAiB,CACxB,iBAAiC,EACjC,iBAAiC;YAEjC,IACE,eAAe;gBACf,wBAAiB,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,EACvD;gBACA,OAAO;aACR;YAED,MAAM,uBAAuB,GAC3B,UAAU,CAAC,cAAc,CAAC,iBAAiB,CAAE,CAAC;YAChD,MAAM,uBAAuB,GAC3B,UAAU,CAAC,cAAc,CAAC,iBAAiB,CAAE,CAAC;YAChD,M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AC5B,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,IAAI,CAAC;iBAC9D,CAAC,CAAC;aACJ;QACH,CAAC;QAED,uCACK,KAAK,KACR,gCAAgC,CAC9B,IAAuD;gBAEvD,MAAM,YAAY,GAAG,UAAU,CAAC,aAAa,CAAC,IAAI,CAAE,CAAC;gBACrD,MAAM,YAAY,GAAG,UAAU,CAAC,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"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,18 +23,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/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();
return `${(_a = node.accessibility) !== null && _a !== void 0 ? _a : ''}${node.static ? ' static' : ''} ${final} `.trimStart();
};
const isSupportedLiteral = (node) => {
if (node.type === experimental_utils_1.AST_NODE_TYPES.Literal) {
if (node.type === 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) {
if (node.type === utils_1.AST_NODE_TYPES.TaggedTemplateExpression ||
node.type === utils_1.AST_NODE_TYPES.TemplateLiteral) {
return ('quasi' in node ? node.quasi.quasis : node.quasis).length === 1;
}
return false;
@ -40,9 +44,8 @@ exports.default = util.createRule({
meta: {
type: 'problem',
docs: {
description: 'Ensures that literals on classes are exposed in a consistent style',
category: 'Best Practices',
recommended: false,
description: 'Enforce that literals on classes are exposed in a consistent style',
recommended: 'strict',
},
fixable: 'code',
messages: {
@ -53,40 +56,37 @@ exports.default = util.createRule({
},
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) {
return Object.assign(Object.assign({}, (style === 'fields' && {
MethodDefinition(node) {
if (node.kind !== 'get' ||
!node.value.body ||
!node.value.body.body.length) {
return;
}
const [statement] = node.value.body.body;
if (statement.type !== 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);
},
});
},
})), (style === 'getters' && {
PropertyDefinition(node) {
if (!node.readonly || node.declare) {
return;
}
@ -108,7 +108,7 @@ exports.default = util.createRule({
},
});
},
};
}));
},
});
//# sourceMappingURL=class-literal-property-style.js.map

View file

@ -1 +1 @@
{"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,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,C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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"}
{"version":3,"file":"class-literal-property-style.js","sourceRoot":"","sources":["../../src/rules/class-literal-property-style.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAA0D;AAE1D,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,SAAS,EAAE,CAAA;CAAA,CAAC;AAE3B,MAAM,kBAAkB,GAAG,CACzB,IAAmB,EACiB,EAAE;IACtC,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,OAAO,EAAE;QACxC,OAAO,IAAI,CAAC;KACb;IAED,IACE,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,wBAAwB;QACrD,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,eAAe,EAC5C;QACA,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;KACzE;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QAC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ACvC,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAC,EACF;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -18,13 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
__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 utils_1 = require("@typescript-eslint/utils");
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 getESLintCoreRule_1 = require("../util/getESLintCoreRule");
const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('comma-dangle');
const OPTION_VALUE_SCHEME = [
'always-multiline',
'always',
@ -52,13 +54,12 @@ exports.default = util.createRule({
meta: {
type: 'layout',
docs: {
description: 'Require or disallow trailing comma',
category: 'Stylistic Issues',
description: 'Require or disallow trailing commas',
recommended: false,
extendsBaseRule: true,
},
schema: {
definitions: {
$defs: {
value: {
enum: OPTION_VALUE_SCHEME,
},
@ -71,32 +72,34 @@ exports.default = util.createRule({
{
oneOf: [
{
$ref: '#/definitions/value',
$ref: '#/$defs/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' },
arrays: { $ref: '#/$defs/valueWithIgnore' },
objects: { $ref: '#/$defs/valueWithIgnore' },
imports: { $ref: '#/$defs/valueWithIgnore' },
exports: { $ref: '#/$defs/valueWithIgnore' },
functions: { $ref: '#/$defs/valueWithIgnore' },
enums: { $ref: '#/$defs/valueWithIgnore' },
generics: { $ref: '#/$defs/valueWithIgnore' },
tuples: { $ref: '#/$defs/valueWithIgnore' },
},
additionalProperties: false,
},
],
},
],
additionalProperties: false,
},
fixable: 'code',
messages: comma_dangle_1.default.meta.messages,
hasSuggestions: baseRule.meta.hasSuggestions,
messages: baseRule.meta.messages,
},
defaultOptions: ['never'],
create(context, [options]) {
const rules = comma_dangle_1.default.create(context);
const rules = baseRule.create(context);
const sourceCode = context.getSourceCode();
const normalizedOptions = normalizeOptions(options);
const predicate = {
@ -112,11 +115,11 @@ exports.default = util.createRule({
}
function getLastItem(node) {
switch (node.type) {
case experimental_utils_1.AST_NODE_TYPES.TSEnumDeclaration:
case utils_1.AST_NODE_TYPES.TSEnumDeclaration:
return last(node.members);
case experimental_utils_1.AST_NODE_TYPES.TSTypeParameterDeclaration:
case utils_1.AST_NODE_TYPES.TSTypeParameterDeclaration:
return last(node.params);
case experimental_utils_1.AST_NODE_TYPES.TSTupleType:
case utils_1.AST_NODE_TYPES.TSTupleType:
return last(node.elementTypes);
default:
return null;

View file

@ -1 +1 @@
{"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,o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AC,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;oBAC1C,CAAC;iBACF,CAAC,CAAC;aACJ;QACH,CAAC;QAED,SAAS,qBAAqB,CAAC,IAAmB;YAChD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;gBACtB,WAAW,CAAC,IAAI,CAAC,CAAC;aACnB;QACH,CAAC;QAED,SAAS,qBAAqB,CAAC,IAAmB;YAChD,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE;gBACrB,UAAU,CAAC,IAAI,CAAC,CAAC;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"}

View file

@ -1,14 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util_1 = require("../util");
exports.default = util_1.createRule({
exports.default = (0, util_1.createRule)({
name: 'comma-spacing',
meta: {
type: 'suggestion',
type: 'layout',
docs: {
description: 'Enforces consistent spacing before and after commas',
category: 'Stylistic Issues',
description: 'Enforce consistent spacing before and after commas',
recommended: false,
extendsBaseRule: true,
},
@ -54,7 +53,7 @@ exports.default = util_1.createRule({
let token;
if (element === null) {
token = sourceCode.getTokenAfter(previousToken);
if (token && util_1.isCommaToken(token)) {
if (token && (0, util_1.isCommaToken)(token)) {
ignoredTokens.add(token);
}
}
@ -73,7 +72,7 @@ exports.default = util_1.createRule({
if (paramLength) {
const param = node.params[paramLength - 1];
const afterToken = sourceCode.getTokenAfter(param);
if (afterToken && util_1.isCommaToken(afterToken)) {
if (afterToken && (0, util_1.isCommaToken)(afterToken)) {
ignoredTokens.add(afterToken);
}
}
@ -86,7 +85,8 @@ exports.default = util_1.createRule({
*/
function validateCommaSpacing(commaToken, prevToken, nextToken) {
if (prevToken &&
util_1.isTokenOnSameLine(prevToken, commaToken) &&
(0, util_1.isTokenOnSameLine)(prevToken, commaToken) &&
// eslint-disable-next-line deprecation/deprecation -- TODO - switch once our min ESLint version is 6.7.0
spaceBefore !== sourceCode.isSpaceBetweenTokens(prevToken, commaToken)) {
context.report({
node: commaToken,
@ -99,14 +99,15 @@ exports.default = util_1.createRule({
: fixer.replaceTextRange([prevToken.range[1], commaToken.range[0]], ''),
});
}
if (nextToken && util_1.isClosingParenToken(nextToken)) {
if (nextToken && (0, util_1.isClosingParenToken)(nextToken)) {
return;
}
if (!spaceAfter && nextToken && nextToken.type === experimental_utils_1.AST_TOKEN_TYPES.Line) {
if (!spaceAfter && nextToken && nextToken.type === utils_1.AST_TOKEN_TYPES.Line) {
return;
}
if (nextToken &&
util_1.isTokenOnSameLine(commaToken, nextToken) &&
(0, util_1.isTokenOnSameLine)(commaToken, nextToken) &&
// eslint-disable-next-line deprecation/deprecation -- TODO - switch once our min ESLint version is 6.7.0
spaceAfter !== sourceCode.isSpaceBetweenTokens(commaToken, nextToken)) {
context.report({
node: commaToken,
@ -126,14 +127,14 @@ exports.default = util_1.createRule({
ArrayPattern: addNullElementsToIgnoreList,
'Program:exit'() {
tokensAndComments.forEach((token, i) => {
if (!util_1.isCommaToken(token)) {
if (!(0, util_1.isCommaToken)(token)) {
return;
}
const prevToken = tokensAndComments[i - 1];
const nextToken = tokensAndComments[i + 1];
validateCommaSpacing(token, util_1.isCommaToken(prevToken) || ignoredTokens.has(token)
validateCommaSpacing(token, (0, util_1.isCommaToken)(prevToken) || ignoredTokens.has(token)
? null
: prevToken, util_1.isCommaToken(nextToken) || ignoredTokens.has(token)
: prevToken, (nextToken && (0, util_1.isCommaToken)(nextToken)) || ignoredTokens.has(token)
? null
: nextToken);
});

View file

@ -1 +1 @@
{"version":3,"file":"comma-spacing.js","sourceRoot":"","sources":["../../src/rules/comma-spacing.ts"],"names":[],"mappings":";;AAAA,8EAG+C;AAC/C,kCAKiB;AAUjB,kBAAe,iBAAU,CAAsB;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;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,MAAM,EAAE;wBACN,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,KAAK;qBACf;oBACD,KAAK,EAAE;wBACL,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,IAAI;qBACd;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,UAAU,EAAE,uCAAuC;YACnD,OAAO,EAAE,kCAAkC;SAC5C;KACF;IACD,cAAc,EAAE;QACd;YACE,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,IAAI;SACZ;KACF;IACD,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;QAC1D,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC3C,MAAM,iBAAiB,GAAG,UAAU,CAAC,iBAAiB,CAAC;QACvD,MAAM,aAAa,GAAG,IAAI,GAAG,EAA4B,CAAC;QAE1D;;;WAGG;QACH,SAAS,2BAA2B,CAClC,IAAsD;YAEtD,IAAI,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YACnD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACnC,IAAI,KAA4B,CAA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BACxB,OAAO;qBACR;oBAED,MAAM,SAAS,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBAC3C,MAAM,SAAS,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBAE3C,oBAAoB,CAClB,KAAK,EACL,mBAAY,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;wBACjD,CAAC,CAAC,IAAI;wBACN,CAAC,CAAC,SAAS,EACb,mBAAY,CAAC,SAAS,CAAC,IAAI,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"}
{"version":3,"file":"comma-spacing.js","sourceRoot":"","sources":["../../src/rules/comma-spacing.ts"],"names":[],"mappings":";;AACA,oDAA2D;AAE3D,kCAKiB;AAUjB,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE;YACJ,WAAW,EAAE,oDAAoD;YACjE,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;SACtB;QACD,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,MAAM,EAAE;wBACN,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,KAAK;qBACf;oBACD,KAAK,EAAE;wBACL,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,IAAI;qBACd;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,UAAU,EAAE,uCAAuC;YACnD,OAAO,EAAE,kCAAkC;SAC5C;KACF;IACD,cAAc,EAAE;QACd;YACE,MAAM,EAAE,KAAK;YACb,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AC,YAAY;oBAChD,GAAG,EAAE,KAAK,CAAC,EAAE,CACX,UAAU;wBACR,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC;wBACxC,CAAC,CAAC,KAAK,CAAC,gBAAgB,CACpB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACzC,EAAE,CACH;iBACR,CAAC,CAAC;aACJ;QACH,CAAC;QAED,OAAO;YACL,0BAA0B,EAAE,0CAA0C;YACtE,eAAe,EAAE,2BAA2B;YAC5C,YAAY,EAAE,2BAA2B;YAEzC,cAAc;gBACZ,iBAAiB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;oBACrC,IAAI,CAAC,IAAA,mBAAY,EAAC,KAAK,CAAC,EAAE;wBACxB,OAAO;qBACR;oBAED,MAAM,SAAS,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBAC3C,MAAM,SAAS,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBAE3C,oBAAoB,CAClB,KAAK,EACL,IAAA,mBAAY,EAAC,SAAS,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;wBACjD,CAAC,CAAC,IAAI;wBACN,CAAC,CAAC,SAAS,EACb,CAAC,SAAS,IAAI,IAAA,mBAAY,EAAC,SAAS,CAAC,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC;wBAChE,CAAC,CAAC,IAAI;wBACN,CAAC,CAAC,SAAS,CACd,CAAC;gBACJ,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -0,0 +1,100 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@typescript-eslint/utils");
const util_1 = require("../util");
exports.default = (0, util_1.createRule)({
name: 'consistent-generic-constructors',
meta: {
type: 'suggestion',
docs: {
description: 'Enforce specifying generic type arguments on type annotation or constructor name of a constructor call',
recommended: 'strict',
},
messages: {
preferTypeAnnotation: 'The generic type arguments should be specified as part of the type annotation.',
preferConstructor: 'The generic type arguments should be specified as part of the constructor type arguments.',
},
fixable: 'code',
schema: [
{
enum: ['type-annotation', 'constructor'],
},
],
},
defaultOptions: ['constructor'],
create(context, [mode]) {
const sourceCode = context.getSourceCode();
return {
'VariableDeclarator,PropertyDefinition'(node) {
var _a, _b;
const lhs = (_a = (node.type === utils_1.AST_NODE_TYPES.VariableDeclarator ? node.id : node).typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation;
const rhs = node.type === utils_1.AST_NODE_TYPES.VariableDeclarator
? node.init
: node.value;
if (!rhs ||
rhs.type !== utils_1.AST_NODE_TYPES.NewExpression ||
rhs.callee.type !== utils_1.AST_NODE_TYPES.Identifier) {
return;
}
if (lhs &&
(lhs.type !== utils_1.AST_NODE_TYPES.TSTypeReference ||
lhs.typeName.type !== utils_1.AST_NODE_TYPES.Identifier ||
lhs.typeName.name !== rhs.callee.name)) {
return;
}
if (mode === 'type-annotation') {
if (!lhs && rhs.typeParameters) {
const { typeParameters, callee } = rhs;
const typeAnnotation = sourceCode.getText(callee) + sourceCode.getText(typeParameters);
context.report({
node,
messageId: 'preferTypeAnnotation',
fix(fixer) {
function getIDToAttachAnnotation() {
if (node.type === utils_1.AST_NODE_TYPES.VariableDeclarator) {
return node.id;
}
if (!node.computed) {
return node.key;
}
// If the property's computed, we have to attach the
// annotation after the square bracket, not the enclosed expression
return sourceCode.getTokenAfter(node.key);
}
return [
fixer.remove(typeParameters),
fixer.insertTextAfter(getIDToAttachAnnotation(), ': ' + typeAnnotation),
];
},
});
}
return;
}
if (mode === 'constructor') {
if ((lhs === null || lhs === void 0 ? void 0 : lhs.typeParameters) && !rhs.typeParameters) {
const hasParens = ((_b = sourceCode.getTokenAfter(rhs.callee)) === null || _b === void 0 ? void 0 : _b.value) === '(';
const extraComments = new Set(sourceCode.getCommentsInside(lhs.parent));
sourceCode
.getCommentsInside(lhs.typeParameters)
.forEach(c => extraComments.delete(c));
context.report({
node,
messageId: 'preferConstructor',
*fix(fixer) {
yield fixer.remove(lhs.parent);
for (const comment of extraComments) {
yield fixer.insertTextAfter(rhs.callee, sourceCode.getText(comment));
}
yield fixer.insertTextAfter(rhs.callee, sourceCode.getText(lhs.typeParameters));
if (!hasParens) {
yield fixer.insertTextAfter(rhs.callee, '()');
}
},
});
}
}
},
};
},
});
//# sourceMappingURL=consistent-generic-constructors.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"consistent-generic-constructors.js","sourceRoot":"","sources":["../../src/rules/consistent-generic-constructors.ts"],"names":[],"mappings":";;AACA,oDAA0D;AAE1D,kCAAqC;AAKrC,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,iCAAiC;IACvC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,wGAAwG;YAC1G,WAAW,EAAE,QAAQ;SACtB;QACD,QAAQ,EAAE;YACR,oBAAoB,EAClB,gFAAgF;YAClF,iBAAiB,EACf,2FAA2F;SAC9F;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,CAAC,iBAAiB,EAAE,aAAa,CAAC;aACzC;SACF;KACF;IACD,cAAc,EAAE,CAAC,aAAa,CAAC;IAC/B,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;QACpB,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC3C,OAAO;YACL,uCAAuC,CACrC,IAA+D;;gBAE/D,MAAM,GAAG,GAAG,MAAA,CACV,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CACjE,CAAC,cAAc,0CAAE,cAAc,CAAC;gBACj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AC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;iCAC/C;4BACH,CAAC;yBACF,CAAC,CAAC;qBACJ;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,19 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@typescript-eslint/utils");
const util_1 = require("../util");
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
exports.default = util_1.createRule({
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,
description: 'Require or disallow the `Record` type',
recommended: 'strict',
},
messages: {
preferRecord: 'A record is preferred over an index signature',
preferRecord: 'A record is preferred over an index signature.',
preferIndexSignature: 'An index signature is preferred over a record.',
},
fixable: 'code',
@ -24,48 +22,21 @@ exports.default = util_1.createRule({
],
},
defaultOptions: ['record'],
create(context) {
create(context, [mode]) {
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) {
function checkMembers(members, node, parentId, prefix, postfix, safeFix = true) {
if (members.length !== 1) {
return;
}
const [member] = members;
if (member.type !== experimental_utils_1.AST_NODE_TYPES.TSIndexSignature) {
if (member.type !== utils_1.AST_NODE_TYPES.TSIndexSignature) {
return;
}
const [parameter] = member.parameters;
if (!parameter) {
return;
}
if (parameter.type !== experimental_utils_1.AST_NODE_TYPES.Identifier) {
if (parameter.type !== utils_1.AST_NODE_TYPES.Identifier) {
return;
}
const keyType = parameter.typeAnnotation;
@ -76,6 +47,18 @@ exports.default = util_1.createRule({
if (!valueType) {
return;
}
if (parentId) {
const scope = context.getScope();
const superVar = utils_1.ASTUtils.findVariable(scope, parentId.name);
if (superVar) {
const isCircular = superVar.references.some(item => item.isTypeReference &&
node.range[0] <= item.identifier.range[0] &&
node.range[1] >= item.identifier.range[1]);
if (isCircular) {
return;
}
}
}
context.report({
node,
messageId: 'preferRecord',
@ -91,19 +74,53 @@ exports.default = util_1.createRule({
: null,
});
}
return {
return Object.assign(Object.assign({}, (mode === 'index-signature' && {
TSTypeReference(node) {
var _a;
const typeName = node.typeName;
if (typeName.type !== 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} }`);
},
});
},
})), (mode === 'record' && {
TSTypeLiteral(node) {
checkMembers(node.members, node, '', '');
const parent = findParentDeclaration(node);
checkMembers(node.members, node, parent === null || parent === void 0 ? void 0 : parent.id, '', '');
},
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(', ')}>`;
genericTypes = `<${(_c = node.typeParameters) === null || _c === void 0 ? void 0 : _c.params.map(p => sourceCode.getText(p)).join(', ')}>`;
}
checkMembers(node.body.body, node, `type ${node.id.name}${genericTypes} = `, ';', !((_d = node.extends) === null || _d === void 0 ? void 0 : _d.length));
checkMembers(node.body.body, node, node.id, `type ${node.id.name}${genericTypes} = `, ';', !((_d = node.extends) === null || _d === void 0 ? void 0 : _d.length));
},
};
}));
},
});
function findParentDeclaration(node) {
if (node.parent && node.parent.type !== utils_1.AST_NODE_TYPES.TSTypeAnnotation) {
if (node.parent.type === utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration) {
return node.parent;
}
return findParentDeclaration(node.parent);
}
return undefined;
}
//# sourceMappingURL=consistent-indexed-object-style.js.map

View file

@ -1 +1 @@
{"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,iBAAU,CAAsB;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,+CAA+C;YAC7D,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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,YAAY,CACV,IAAI,CAAC,IAAI,CAAC,IAAI,EACd,IAAI,EACJ,QAAQ,IAAI,CAAC,EAAE,CAAC,IAAI,GAAG,YAAY,KAAK,EACxC,GAAG,EACH,CAAC,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM,CAAA,CACtB,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
{"version":3,"file":"consistent-indexed-object-style.js","sourceRoot":"","sources":["../../src/rules/consistent-indexed-object-style.ts"],"names":[],"mappings":";;AACA,oDAAoE;AAEpE,kCAAqC;AAKrC,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,iCAAiC;IACvC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,uCAAuC;YACpD,WAAW,EAAE,QAAQ;SACtB;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,EAAE,CAAC,IAAI,CAAC;QACpB,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAE3C,SAAS,YAAY,CACnB,OAA+B,EAC/B,IAA8D,EAC9D,QAAyC,EACzC,MAAc,EACd,OAAe,EACf,OAAO,GAAG,IAAI;YAEd,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;gBACxB,OAAO;aACR;YACD,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;YAEzB,IAAI,MAAM,CAAC,IAAI,KAAK,sBAAc,CAAC,gBAAgB,EAAE;gBACnD,OAAO;aACR;YAED,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,UA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Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,16 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@typescript-eslint/utils");
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,
description: 'Enforce consistent usage of type assertions',
recommended: 'strict',
},
messages: {
as: "Use 'as {{cast}}' instead of '<{{cast}}>'.",
@ -75,18 +78,18 @@ exports.default = util.createRule({
create(context, [options]) {
const sourceCode = context.getSourceCode();
function isConst(node) {
if (node.type !== experimental_utils_1.AST_NODE_TYPES.TSTypeReference) {
if (node.type !== utils_1.AST_NODE_TYPES.TSTypeReference) {
return false;
}
return (node.typeName.type === experimental_utils_1.AST_NODE_TYPES.Identifier &&
return (node.typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
node.typeName.name === 'const');
}
function reportIncorrectAssertionType(node) {
const messageId = options.assertionStyle;
// If this node is `as const`, then don't report an error.
if (isConst(node.typeAnnotation)) {
if (isConst(node.typeAnnotation) && messageId === 'never') {
return;
}
const messageId = options.assertionStyle;
context.report({
node,
messageId,
@ -97,15 +100,15 @@ exports.default = util.createRule({
}
function checkType(node) {
switch (node.type) {
case experimental_utils_1.AST_NODE_TYPES.TSAnyKeyword:
case experimental_utils_1.AST_NODE_TYPES.TSUnknownKeyword:
case utils_1.AST_NODE_TYPES.TSAnyKeyword:
case utils_1.AST_NODE_TYPES.TSUnknownKeyword:
return false;
case experimental_utils_1.AST_NODE_TYPES.TSTypeReference:
case 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);
node.typeName.type === utils_1.AST_NODE_TYPES.TSQualifiedName);
default:
return true;
}
@ -113,20 +116,20 @@ exports.default = util.createRule({
function checkExpression(node) {
if (options.assertionStyle === 'never' ||
options.objectLiteralTypeAssertions === 'allow' ||
node.expression.type !== experimental_utils_1.AST_NODE_TYPES.ObjectExpression) {
node.expression.type !== 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)) {
(node.parent.type === utils_1.AST_NODE_TYPES.NewExpression ||
node.parent.type === utils_1.AST_NODE_TYPES.CallExpression ||
node.parent.type === utils_1.AST_NODE_TYPES.ThrowStatement ||
node.parent.type === utils_1.AST_NODE_TYPES.AssignmentPattern ||
node.parent.type === utils_1.AST_NODE_TYPES.JSXExpressionContainer)) {
return;
}
if (checkType(node.typeAnnotation) &&
node.expression.type === experimental_utils_1.AST_NODE_TYPES.ObjectExpression) {
node.expression.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
context.report({
node,
messageId: 'unexpectedObjectTypeAssertion',

View file

@ -1 +1 @@
{"version":3,"file":"consistent-type-assertions.js","sourceRoot":"","sources":["../../src/rules/consistent-type-assertions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8CA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AI,CAAC,MAAM,CAAC,IAAI,KAAK,mCAAc,CAAC,aAAa;oBAChD,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,mCAAc,CAAC,cAAc;oBAClD,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,mCAAc,CAAC,cAAc;oBAClD,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,mCAAc,CAAC,iBAAiB;oBACrD,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,mCAAc,CAAC,sBAAsB,CAAC,EAC7D;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"}
{"version":3,"file":"consistent-type-assertions.js","sourceRoot":"","sources":["../../src/rules/consistent-type-assertions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAA0D;AAE1D,8CAAgC;AAkBhC,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IA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CAAC,IAAI,KAAK,sBAAc,CAAC,cAAc;oBAClD,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,sBAAc,CAAC,iBAAiB;oBACrD,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,sBAAc,CAAC,sBAAsB,CAAC,EAC7D;gBACA,OAAO;aACR;YAED,IACE,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC;gBAC9B,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,sBAAc,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"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,17 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/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,
description: 'Enforce type definitions to consistently use either `interface` or `type`',
recommended: 'strict',
},
messages: {
interfaceOverType: 'Use an `interface` instead of a `type`.',
@ -52,68 +54,69 @@ exports.default = util.createRule({
function isCurrentlyTraversedNodeWithinModuleDeclaration() {
return context
.getAncestors()
.some(node => node.type === experimental_utils_1.AST_NODE_TYPES.TSModuleDeclaration &&
.some(node => node.type === utils_1.AST_NODE_TYPES.TSModuleDeclaration &&
node.declare &&
node.global);
}
return {
return Object.assign(Object.assign({}, (option === 'interface' && {
"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;
},
});
}
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.getTokenBefore(node.id);
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 === utils_1.AST_TOKEN_TYPES.Punctuator &&
afterToken.value === ';') {
fixes.push(fixer.remove(afterToken));
}
return fixes;
},
});
},
})), (option === 'type' && {
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;
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}`));
});
}
return fixes;
},
});
}
const fix = isCurrentlyTraversedNodeWithinModuleDeclaration()
? null
: (fixer) => {
var _a, _b;
const typeNode = (_a = node.typeParameters) !== null && _a !== void 0 ? _a : node.id;
const fixes = [];
const firstToken = sourceCode.getTokenBefore(node.id);
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) === 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;
};
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,
});
},
};
}));
},
});
//# sourceMappingURL=consistent-type-definitions.js.map

View file

@ -1 +1 @@
{"version":3,"file":"consistent-type-definitions.js","sourceRoot":"","sources":["../../src/rules/consistent-type-definitions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8EAK+C;AAC/C,8CAAgC;AAEhC,kBAAe,IAAI,CAAC,UAAU,CAAC;IAC7B,IAAI,EAAE,6BAA6B;IACnC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,8DAA8D;YAChE,QAAQ,EAAE,kBAAkB;YAC5B,oCAAoC;YACpC,WAAW,EAAE,KAAK;SACnB;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,yCAAyC;YAC5D,iBAAiB,EAAE,yCAAyC;SAC7D;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC;aAC5B;SACF;QACD,OAAO,EAAE,MAAM;KAChB;IACD,cAAc,EAAE,CAAC,WAAW,CAAC;IAC7B,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC;QACtB,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAE3C;;;WAGG;QACH,SAAS,+CAA+C;YACtD,OAAO,OAAO;iBACX,YAAY,EAAE;iBACd,IAAI,CACH,IAAI,CAAC,EAAE,CACL,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,mBAAmB;gBAChD,IAAI,CAAC,OAAO;gBACZ,IAAI,CAAC,MAAM,CACd,CAAC;QACN,CAAC;QAED,OAAO;YACL,6DAA6D,CAC3D,IAAqC;gBAErC,IAAI,MAAM,KAAK,WAAW,EAAE;oBAC1B,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,IAAI,CAAC,EAAE;wBACb,SAAS,EAAE,mBAAmB;wBAC9B,GAAG,CAAC,KAAK;;4BACP,MAAM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gCAErC,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;gCAClD,IAAI,UAAU,EAAE;oCACd,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;oCAClD,KAAK,CAAC,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,OAAO,KAAK,CAAC;4BACf,CAAC;qBACN,CAAC,CAAC;iBACJ;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
{"version":3,"file":"consistent-type-definitions.js","sourceRoot":"","sources":["../../src/rules/consistent-type-definitions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAA2E;AAE3E,8CAAgC;AAEhC,kBAAe,IAAI,CAAC,UAAU,CAAC;IAC7B,IAAI,EAAE,6BAA6B;IACnC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,2EAA2E;YAC7E,WAAW,EAAE,QAAQ;SACtB;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,yCAAyC;YAC5D,iBAAiB,EAAE,yCAAyC;SAC7D;QACD,MAAM,EAAE;YACN;g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D,CAAC;4BACJ,CAAC,CAAC,CAAC;yBACJ;wBAED,IACE,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI,MAAK,sBAAc,CAAC,wBAAwB,EAC7D;4BACA,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;yBACH;wBAED,OAAO,KAAK,CAAC;oBACf,CAAC,CAAC;gBACN,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,EAAE,IAAI,CAAC,EAAE;oBACb,SAAS,EAAE,mBAAmB;oBAC9B;;;uBAGG;oBACH,GAAG;iBACJ,CAAC,CAAC;YACL,CAAC;SACF,CAAC,EACF;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -0,0 +1,266 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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 utils_1 = require("@typescript-eslint/utils");
const typescript_1 = require("typescript");
const util = __importStar(require("../util"));
exports.default = util.createRule({
name: 'consistent-type-exports',
meta: {
type: 'suggestion',
docs: {
description: 'Enforce consistent usage of type exports',
recommended: false,
requiresTypeChecking: true,
},
messages: {
typeOverValue: 'All exports in the declaration are only used as types. Use `export type`.',
singleExportIsType: 'Type export {{exportNames}} is not a value and should be exported using `export type`.',
multipleExportsAreTypes: 'Type exports {{exportNames}} are not values and should be exported using `export type`.',
},
schema: [
{
type: 'object',
properties: {
fixMixedExportsWithInlineTypeSpecifier: {
type: 'boolean',
},
},
additionalProperties: false,
},
],
fixable: 'code',
},
defaultOptions: [
{
fixMixedExportsWithInlineTypeSpecifier: false,
},
],
create(context, [{ fixMixedExportsWithInlineTypeSpecifier }]) {
const sourceCode = context.getSourceCode();
const sourceExportsMap = {};
const parserServices = util.getParserServices(context);
return {
ExportNamedDeclaration(node) {
var _a;
// Coerce the source into a string for use as a lookup entry.
const source = (_a = getSourceFromExport(node)) !== null && _a !== void 0 ? _a : 'undefined';
const sourceExports = (sourceExportsMap[source] || (sourceExportsMap[source] = {
source,
reportValueExports: [],
typeOnlyNamedExport: null,
valueOnlyNamedExport: null,
}));
// Cache the first encountered exports for the package. We will need to come
// back to these later when fixing the problems.
if (node.exportKind === 'type') {
if (sourceExports.typeOnlyNamedExport == null) {
// The export is a type export
sourceExports.typeOnlyNamedExport = node;
}
}
else if (sourceExports.valueOnlyNamedExport == null) {
// The export is a value export
sourceExports.valueOnlyNamedExport = node;
}
// Next for the current export, we will separate type/value specifiers.
const typeBasedSpecifiers = [];
const inlineTypeSpecifiers = [];
const valueSpecifiers = [];
// Note: it is valid to export values as types. We will avoid reporting errors
// when this is encountered.
if (node.exportKind !== 'type') {
for (const specifier of node.specifiers) {
if (specifier.exportKind === 'type') {
inlineTypeSpecifiers.push(specifier);
continue;
}
const isTypeBased = isSpecifierTypeBased(parserServices, specifier);
if (isTypeBased === true) {
typeBasedSpecifiers.push(specifier);
}
else if (isTypeBased === false) {
// When isTypeBased is undefined, we should avoid reporting them.
valueSpecifiers.push(specifier);
}
}
}
if ((node.exportKind === 'value' && typeBasedSpecifiers.length) ||
(node.exportKind === 'type' && valueSpecifiers.length)) {
sourceExports.reportValueExports.push({
node,
typeBasedSpecifiers,
valueSpecifiers,
inlineTypeSpecifiers,
});
}
},
'Program:exit'() {
for (const sourceExports of Object.values(sourceExportsMap)) {
// If this export has no issues, move on.
if (sourceExports.reportValueExports.length === 0) {
continue;
}
for (const report of sourceExports.reportValueExports) {
if (report.valueSpecifiers.length === 0) {
// Export is all type-only with no type specifiers; convert the entire export to `export type`.
context.report({
node: report.node,
messageId: 'typeOverValue',
*fix(fixer) {
yield* fixExportInsertType(fixer, sourceCode, report.node);
},
});
continue;
}
// We have both type and value violations.
const allExportNames = report.typeBasedSpecifiers.map(specifier => `${specifier.local.name}`);
if (allExportNames.length === 1) {
const exportNames = allExportNames[0];
context.report({
node: report.node,
messageId: 'singleExportIsType',
data: { exportNames },
*fix(fixer) {
if (fixMixedExportsWithInlineTypeSpecifier) {
yield* fixAddTypeSpecifierToNamedExports(fixer, report);
}
else {
yield* fixSeparateNamedExports(fixer, sourceCode, report);
}
},
});
}
else {
const exportNames = util.formatWordList(allExportNames);
context.report({
node: report.node,
messageId: 'multipleExportsAreTypes',
data: { exportNames },
*fix(fixer) {
if (fixMixedExportsWithInlineTypeSpecifier) {
yield* fixAddTypeSpecifierToNamedExports(fixer, report);
}
else {
yield* fixSeparateNamedExports(fixer, sourceCode, report);
}
},
});
}
}
}
},
};
},
});
/**
* Helper for identifying if an export specifier resolves to a
* JavaScript value or a TypeScript type.
*
* @returns True/false if is a type or not, or undefined if the specifier
* can't be resolved.
*/
function isSpecifierTypeBased(parserServices, specifier) {
const checker = parserServices.program.getTypeChecker();
const node = parserServices.esTreeNodeToTSNodeMap.get(specifier.exported);
const symbol = checker.getSymbolAtLocation(node);
const aliasedSymbol = checker.getAliasedSymbol(symbol);
if (!aliasedSymbol || aliasedSymbol.escapedName === 'unknown') {
return undefined;
}
return !(aliasedSymbol.flags & typescript_1.SymbolFlags.Value);
}
/**
* Inserts "type" into an export.
*
* Example:
*
* export type { Foo } from 'foo';
* ^^^^
*/
function* fixExportInsertType(fixer, sourceCode, node) {
const exportToken = util.nullThrows(sourceCode.getFirstToken(node), util.NullThrowsReasons.MissingToken('export', node.type));
yield fixer.insertTextAfter(exportToken, ' type');
for (const specifier of node.specifiers) {
if (specifier.exportKind === 'type') {
const kindToken = util.nullThrows(sourceCode.getFirstToken(specifier), util.NullThrowsReasons.MissingToken('export', specifier.type));
const firstTokenAfter = util.nullThrows(sourceCode.getTokenAfter(kindToken, {
includeComments: true,
}), 'Missing token following the export kind.');
yield fixer.removeRange([kindToken.range[0], firstTokenAfter.range[0]]);
}
}
}
/**
* Separates the exports which mismatch the kind of export the given
* node represents. For example, a type export's named specifiers which
* represent values will be inserted in a separate `export` statement.
*/
function* fixSeparateNamedExports(fixer, sourceCode, report) {
const { node, typeBasedSpecifiers, inlineTypeSpecifiers, valueSpecifiers } = report;
const typeSpecifiers = typeBasedSpecifiers.concat(inlineTypeSpecifiers);
const source = getSourceFromExport(node);
const specifierNames = typeSpecifiers.map(getSpecifierText).join(', ');
const exportToken = util.nullThrows(sourceCode.getFirstToken(node), util.NullThrowsReasons.MissingToken('export', node.type));
// Filter the bad exports from the current line.
const filteredSpecifierNames = valueSpecifiers
.map(getSpecifierText)
.join(', ');
const openToken = util.nullThrows(sourceCode.getFirstToken(node, util.isOpeningBraceToken), util.NullThrowsReasons.MissingToken('{', node.type));
const closeToken = util.nullThrows(sourceCode.getLastToken(node, util.isClosingBraceToken), util.NullThrowsReasons.MissingToken('}', node.type));
// Remove exports from the current line which we're going to re-insert.
yield fixer.replaceTextRange([openToken.range[1], closeToken.range[0]], ` ${filteredSpecifierNames} `);
// Insert the bad exports into a new export line above.
yield fixer.insertTextBefore(exportToken, `export type { ${specifierNames} }${source ? ` from '${source}'` : ''};\n`);
}
function* fixAddTypeSpecifierToNamedExports(fixer, report) {
if (report.node.exportKind === 'type') {
return;
}
for (const specifier of report.typeBasedSpecifiers) {
yield fixer.insertTextBefore(specifier, 'type ');
}
}
/**
* Returns the source of the export, or undefined if the named export has no source.
*/
function getSourceFromExport(node) {
var _a;
if (((_a = node.source) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.Literal &&
typeof node.source.value === 'string') {
return node.source.value;
}
return undefined;
}
/**
* Returns the specifier text for the export. If it is aliased, we take care to return
* the proper formatting.
*/
function getSpecifierText(specifier) {
return `${specifier.local.name}${specifier.exported.name !== specifier.local.name
? ` as ${specifier.exported.name}`
: ''}`;
}
//# sourceMappingURL=consistent-type-exports.js.map

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,29 +23,28 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
function isImportToken(token) {
return token.type === experimental_utils_1.AST_TOKEN_TYPES.Keyword && token.value === 'import';
return token.type === 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';
return token.type === 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',
description: 'Enforce consistent usage of type imports',
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',
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.',
},
@ -55,6 +58,9 @@ exports.default = util.createRule({
disallowTypeAnnotations: {
type: 'boolean',
},
fixStyle: {
enum: ['separate-type-imports', 'inline-type-imports'],
},
},
additionalProperties: false,
},
@ -65,12 +71,14 @@ exports.default = util.createRule({
{
prefer: 'type-imports',
disallowTypeAnnotations: true,
fixStyle: 'separate-type-imports',
},
],
create(context, [option]) {
var _a;
var _a, _b;
const prefer = (_a = option.prefer) !== null && _a !== void 0 ? _a : 'type-imports';
const disallowTypeAnnotations = option.disallowTypeAnnotations !== false;
const fixStyle = (_b = option.fixStyle) !== null && _b !== void 0 ? _b : 'separate-type-imports';
const sourceCode = context.getSourceCode();
const sourceImportsMap = {};
return Object.assign(Object.assign({}, (prefer === 'type-imports'
@ -79,28 +87,42 @@ exports.default = util.createRule({
ImportDeclaration(node) {
var _a;
const source = node.source.value;
// sourceImports is the object containing all the specifics for a particular import source, type or value
const sourceImports = (_a = sourceImportsMap[source]) !== null && _a !== void 0 ? _a : (sourceImportsMap[source] = {
source,
reportValueImports: [],
typeOnlyNamedImport: null,
valueOnlyNamedImport: null,
valueImport: null, // if only value imports
});
if (node.importKind === 'type') {
if (!sourceImports.typeOnlyNamedImport &&
node.specifiers.every(specifier => specifier.type === experimental_utils_1.AST_NODE_TYPES.ImportSpecifier)) {
node.specifiers.every(specifier => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier)) {
// definitely import type { TypeX }
sourceImports.typeOnlyNamedImport = node;
}
}
else {
if (!sourceImports.valueOnlyNamedImport &&
node.specifiers.every(specifier => specifier.type === experimental_utils_1.AST_NODE_TYPES.ImportSpecifier)) {
node.specifiers.every(specifier => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier)) {
sourceImports.valueOnlyNamedImport = node;
sourceImports.valueImport = node;
}
else if (!sourceImports.valueImport &&
node.specifiers.some(specifier => specifier.type === utils_1.AST_NODE_TYPES.ImportDefaultSpecifier)) {
sourceImports.valueImport = node;
}
}
const typeSpecifiers = [];
const inlineTypeSpecifiers = [];
const valueSpecifiers = [];
const unusedSpecifiers = [];
for (const specifier of node.specifiers) {
if (specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier &&
specifier.importKind === 'type') {
inlineTypeSpecifiers.push(specifier);
continue;
}
const [variable] = context.getDeclaredVariables(specifier);
if (variable.references.length === 0) {
unusedSpecifiers.push(specifier);
@ -114,9 +136,9 @@ exports.default = util.createRule({
* export default Type;
*/
if (((_a = ref.identifier.parent) === null || _a === void 0 ? void 0 : _a.type) ===
experimental_utils_1.AST_NODE_TYPES.ExportSpecifier ||
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) {
utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
if (ref.isValueReference && ref.isTypeReference) {
return node.importKind === 'type';
}
@ -129,9 +151,9 @@ exports.default = util.createRule({
// 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:
case utils_1.AST_NODE_TYPES.TSTypeQuery:
return true;
case experimental_utils_1.AST_NODE_TYPES.TSQualifiedName:
case 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;
@ -145,9 +167,9 @@ exports.default = util.createRule({
// `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:
case utils_1.AST_NODE_TYPES.TSPropertySignature:
return parent.key === child;
case experimental_utils_1.AST_NODE_TYPES.MemberExpression:
case utils_1.AST_NODE_TYPES.MemberExpression:
if (parent.object !== child) {
return false;
}
@ -177,35 +199,38 @@ exports.default = util.createRule({
typeSpecifiers,
valueSpecifiers,
unusedSpecifiers,
inlineTypeSpecifiers,
});
}
},
'Program:exit'() {
for (const sourceImports of Object.values(sourceImportsMap)) {
if (sourceImports.reportValueImports.length === 0) {
// nothing to fix. value specifiers and type specifiers are correctly written
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`
report.unusedSpecifiers.length === 0 &&
report.node.importKind !== 'type') {
context.report({
node: report.node,
messageId: 'typeOverValue',
*fix(fixer) {
yield* fixToTypeImport(fixer, report, sourceImports);
yield* fixToTypeImportDeclaration(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
// we have a mixed type/value import or just value imports, so we need to split them out into multiple imports if separate-type-imports is configured
const importNames = (isTypeImport
? report.valueSpecifiers
: report.typeSpecifiers).map(specifier => `"${specifier.local.name}"`);
? report.valueSpecifiers // import type { A } from 'roo'; // WHERE A is used in value position
: report.typeSpecifiers) // import { A, B } from 'roo'; // WHERE A is used in type position and B is in value position
.map(specifier => `"${specifier.local.name}"`);
const message = (() => {
const typeImports = util.formatWordList(importNames);
if (importNames.length === 1) {
const typeImports = importNames[0];
if (isTypeImport) {
return {
messageId: 'aImportInDecoMeta',
@ -220,30 +245,28 @@ exports.default = util.createRule({
}
}
else {
const typeImports = [
importNames.slice(0, -1).join(', '),
importNames.slice(-1)[0],
].join(' and ');
if (isTypeImport) {
return {
messageId: 'someImportsInDecoMeta',
data: { typeImports },
data: { typeImports }, // typeImports are all the value specifiers that are in the type position
};
}
else {
return {
messageId: 'someImportsAreOnlyTypes',
data: { typeImports },
data: { typeImports }, // typeImports are all the type specifiers in the value position
};
}
}
})();
context.report(Object.assign(Object.assign({ node: report.node }, message), { *fix(fixer) {
if (isTypeImport) {
yield* fixToValueImportInDecoMeta(fixer, report, sourceImports);
// take all the valueSpecifiers and put them on a new line
yield* fixToValueImportDeclaration(fixer, report, sourceImports);
}
else {
yield* fixToTypeImport(fixer, report, sourceImports);
// take all the typeSpecifiers and put them on a new line
yield* fixToTypeImportDeclaration(fixer, report, sourceImports);
}
} }));
}
@ -258,7 +281,16 @@ exports.default = util.createRule({
node,
messageId: 'valueOverType',
fix(fixer) {
return fixToValueImport(fixer, node);
return fixRemoveTypeSpecifierFromImportDeclaration(fixer, node);
},
});
},
'ImportSpecifier[importKind = "type"]'(node) {
context.report({
node,
messageId: 'valueOverType',
fix(fixer) {
return fixRemoveTypeSpecifierFromImportSpecifier(fixer, node);
},
});
},
@ -275,11 +307,11 @@ exports.default = util.createRule({
: {}));
function classifySpecifier(node) {
var _a;
const defaultSpecifier = node.specifiers[0].type === experimental_utils_1.AST_NODE_TYPES.ImportDefaultSpecifier
const defaultSpecifier = node.specifiers[0].type === 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);
const namespaceSpecifier = (_a = node.specifiers.find((specifier) => specifier.type === utils_1.AST_NODE_TYPES.ImportNamespaceSpecifier)) !== null && _a !== void 0 ? _a : null;
const namedSpecifiers = node.specifiers.filter((specifier) => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier);
return {
defaultSpecifier,
namespaceSpecifier,
@ -287,9 +319,9 @@ exports.default = util.createRule({
};
}
/**
* Returns information for fixing named specifiers.
* Returns information for fixing named specifiers, type or value
*/
function getFixesNamedSpecifiers(fixer, node, typeNamedSpecifiers, allNamedSpecifiers) {
function getFixesNamedSpecifiers(fixer, node, subsetNamedSpecifiers, allNamedSpecifiers) {
if (allNamedSpecifiers.length === 0) {
return {
typeNamedSpecifiersText: '',
@ -298,11 +330,10 @@ exports.default = util.createRule({
}
const typeNamedSpecifiersTexts = [];
const removeTypeNamedSpecifiers = [];
if (typeNamedSpecifiers.length === allNamedSpecifiers.length) {
// e.g.
if (subsetNamedSpecifiers.length === allNamedSpecifiers.length) {
// 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 openingBraceToken = util.nullThrows(sourceCode.getTokenBefore(subsetNamedSpecifiers[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'
@ -311,21 +342,21 @@ exports.default = util.createRule({
typeNamedSpecifiersTexts.push(sourceCode.text.slice(openingBraceToken.range[1], closingBraceToken.range[0]));
}
else {
const typeNamedSpecifierGroups = [];
const namedSpecifierGroups = [];
let group = [];
for (const namedSpecifier of allNamedSpecifiers) {
if (typeNamedSpecifiers.includes(namedSpecifier)) {
if (subsetNamedSpecifiers.includes(namedSpecifier)) {
group.push(namedSpecifier);
}
else if (group.length) {
typeNamedSpecifierGroups.push(group);
namedSpecifierGroups.push(group);
group = [];
}
}
if (group.length) {
typeNamedSpecifierGroups.push(group);
namedSpecifierGroups.push(group);
}
for (const namedSpecifiers of typeNamedSpecifierGroups) {
for (const namedSpecifiers of namedSpecifierGroups) {
const { removeRange, textRange } = getNamedSpecifierRanges(namedSpecifiers, allNamedSpecifiers);
removeTypeNamedSpecifiers.push(fixer.removeRange(removeRange));
typeNamedSpecifiersTexts.push(sourceCode.text.slice(...textRange));
@ -372,39 +403,78 @@ exports.default = util.createRule({
* import type { Already, Type1, Type2 } from 'foo'
* ^^^^^^^^^^^^^ insert
*/
function insertToNamedImport(fixer, target, insertText) {
function fixInsertNamedSpecifiersInNamedSpecifierList(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;
insertText = `,${insertText}`;
}
return fixer.insertTextBefore(closingBraceToken, insertText);
}
function* fixToTypeImport(fixer, report, sourceImports) {
/**
* insert type keyword to named import node.
* e.g.
* import ADefault, { Already, type Type1, type Type2 } from 'foo'
* ^^^^ insert
*/
function* fixInsertTypeKeywordInNamedSpecifierList(fixer, typeSpecifiers) {
for (const spec of typeSpecifiers) {
const insertText = sourceCode.text.slice(...spec.range);
yield fixer.replaceTextRange(spec.range, `type ${insertText}`);
}
}
function* fixInlineTypeImportDeclaration(fixer, report, sourceImports) {
const { node } = report;
// For a value import, will only add an inline type to named specifiers
const { namedSpecifiers } = classifySpecifier(node);
const typeNamedSpecifiers = namedSpecifiers.filter(specifier => report.typeSpecifiers.includes(specifier));
if (sourceImports.valueImport) {
// add import named type specifiers to its value import
// import ValueA, { type A }
// ^^^^ insert
const { namedSpecifiers: valueImportNamedSpecifiers } = classifySpecifier(sourceImports.valueImport);
if (sourceImports.valueOnlyNamedImport ||
valueImportNamedSpecifiers.length) {
yield* fixInsertTypeKeywordInNamedSpecifierList(fixer, typeNamedSpecifiers);
}
}
}
function* fixToTypeImportDeclaration(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);
yield* fixInsertTypeSpecifierForImportDeclaration(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);
yield* fixInsertTypeSpecifierForImportDeclaration(fixer, node, true);
return;
}
else if (fixStyle === 'inline-type-imports' &&
!report.typeSpecifiers.includes(defaultSpecifier) &&
namedSpecifiers.length > 0 &&
!namespaceSpecifier) {
// if there is a default specifier but it isn't a type specifier, then just add the inline type modifier to the named specifiers
// import AValue, {BValue, Type1, Type2} from 'foo'
yield* fixInlineTypeImportDeclaration(fixer, report, sourceImports);
return;
}
}
else {
if (namedSpecifiers.every(specifier => report.typeSpecifiers.includes(specifier)) &&
!namespaceSpecifier) {
// e.g.
else if (!namespaceSpecifier) {
if (fixStyle === 'inline-type-imports' &&
namedSpecifiers.some(specifier => report.typeSpecifiers.includes(specifier))) {
// import {AValue, Type1, Type2} from 'foo'
yield* fixInlineTypeImportDeclaration(fixer, report, sourceImports);
return;
}
else if (namedSpecifiers.every(specifier => report.typeSpecifiers.includes(specifier))) {
// import {Type1, Type2} from 'foo'
yield* fixToTypeImportByInsertType(fixer, node, false);
yield* fixInsertTypeSpecifierForImportDeclaration(fixer, node, false);
return;
}
}
@ -413,7 +483,7 @@ exports.default = util.createRule({
const afterFixes = [];
if (typeNamedSpecifiers.length) {
if (sourceImports.typeOnlyNamedImport) {
const insertTypeNamedSpecifiers = insertToNamedImport(fixer, sourceImports.typeOnlyNamedImport, fixesNamedSpecifiers.typeNamedSpecifiersText);
const insertTypeNamedSpecifiers = fixInsertNamedSpecifiersInNamedSpecifierList(fixer, sourceImports.typeOnlyNamedImport, fixesNamedSpecifiers.typeNamedSpecifiersText);
if (sourceImports.typeOnlyNamedImport.range[1] <= node.range[0]) {
yield insertTypeNamedSpecifiers;
}
@ -422,13 +492,23 @@ exports.default = util.createRule({
}
}
else {
yield fixer.insertTextBefore(node, `import type {${fixesNamedSpecifiers.typeNamedSpecifiersText}} from ${sourceCode.getText(node.source)};\n`);
// The import is both default and named. Insert named on new line because can't mix default type import and named type imports
if (fixStyle === 'inline-type-imports') {
yield fixer.insertTextBefore(node, `import {${typeNamedSpecifiers
.map(spec => {
const insertText = sourceCode.text.slice(...spec.range);
return `type ${insertText}`;
})
.join(', ')}} from ${sourceCode.getText(node.source)};\n`);
}
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'
@ -469,7 +549,7 @@ exports.default = util.createRule({
yield* fixesRemoveTypeNamespaceSpecifier;
yield* afterFixes;
}
function* fixToTypeImportByInsertType(fixer, node, isDefaultImport) {
function* fixInsertTypeSpecifierForImportDeclaration(fixer, node, isDefaultImport) {
// import type Foo from 'foo'
// ^^^^^ insert
const importToken = util.nullThrows(sourceCode.getFirstToken(node, isImportToken), util.NullThrowsReasons.MissingToken('import', node.type));
@ -489,45 +569,50 @@ exports.default = util.createRule({
]);
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)};`);
}
}
}
// make sure we don't do anything like `import type {type T} from 'foo';`
for (const specifier of node.specifiers) {
if (specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier &&
specifier.importKind === 'type') {
yield* fixRemoveTypeSpecifierFromImportSpecifier(fixer, specifier);
}
}
}
function* fixToValueImportInDecoMeta(fixer, report, sourceImports) {
function* fixToValueImportDeclaration(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);
yield* fixRemoveTypeSpecifierFromImportDeclaration(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);
yield* fixRemoveTypeSpecifierFromImportDeclaration(fixer, node);
return;
}
}
else {
if (namedSpecifiers.every(specifier => report.valueSpecifiers.includes(specifier))) {
// e.g.
// import type {Type1, Type2} from 'foo'
yield* fixToValueImport(fixer, node);
yield* fixRemoveTypeSpecifierFromImportDeclaration(fixer, node);
return;
}
}
// we have some valueSpecifiers intermixed in types that need to be put on their own line
// import type { Type1, A } from 'foo'
// import type { A } from 'foo'
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);
const insertTypeNamedSpecifiers = fixInsertNamedSpecifiersInNamedSpecifierList(fixer, sourceImports.valueOnlyNamedImport, fixesNamedSpecifiers.typeNamedSpecifiersText);
if (sourceImports.valueOnlyNamedImport.range[1] <= node.range[0]) {
yield insertTypeNamedSpecifiers;
}
@ -536,13 +621,15 @@ exports.default = util.createRule({
}
}
else {
// some are types.
// Add new value import and later remove those value specifiers from import type
yield fixer.insertTextBefore(node, `import {${fixesNamedSpecifiers.typeNamedSpecifiersText}} from ${sourceCode.getText(node.source)};\n`);
}
}
yield* fixesNamedSpecifiers.removeTypeNamedSpecifiers;
yield* afterFixes;
}
function* fixToValueImport(fixer, node) {
function* fixRemoveTypeSpecifierFromImportDeclaration(fixer, node) {
var _a, _b;
// import type Foo from 'foo'
// ^^^^ remove
@ -551,6 +638,13 @@ exports.default = util.createRule({
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]]);
}
function* fixRemoveTypeSpecifierFromImportSpecifier(fixer, node) {
// import { type Foo } from 'foo'
// ^^^^ remove
const typeToken = util.nullThrows(sourceCode.getFirstToken(node, 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

View file

@ -1,14 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@typescript-eslint/utils");
const util_1 = require("../util");
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
exports.default = util_1.createRule({
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,
},
@ -33,15 +32,15 @@ exports.default = util_1.createRule({
* @private
*/
function isPlainParam(node) {
return !(node.type === experimental_utils_1.AST_NODE_TYPES.AssignmentPattern ||
node.type === experimental_utils_1.AST_NODE_TYPES.RestElement ||
return !(node.type === utils_1.AST_NODE_TYPES.AssignmentPattern ||
node.type === 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
const param = current.type === utils_1.AST_NODE_TYPES.TSParameterProperty
? current.parameter
: current;
if (isPlainParam(param)) {
@ -50,7 +49,7 @@ exports.default = util_1.createRule({
}
if (hasSeenPlainParam &&
(isOptionalParam(param) ||
param.type === experimental_utils_1.AST_NODE_TYPES.AssignmentPattern)) {
param.type === utils_1.AST_NODE_TYPES.AssignmentPattern)) {
context.report({ node: current, messageId: 'shouldBeLast' });
}
}

View file

@ -1 +1 @@
{"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,iBAAU,CAAC;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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,CAAC;wBACrB,KAAK,CAAC,IAAI,KAAK,sBAAc,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"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -18,22 +22,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
__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 ts = __importStar(require("typescript"));
const util_1 = require("../util");
exports.default = util_1.createRule({
const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('dot-notation');
exports.default = (0, util_1.createRule)({
name: 'dot-notation',
meta: {
type: 'suggestion',
docs: {
description: 'enforce dot notation whenever possible',
category: 'Best Practices',
recommended: false,
description: 'Enforce dot notation whenever possible',
recommended: 'strict',
extendsBaseRule: true,
requiresTypeChecking: true,
},
@ -65,8 +66,9 @@ exports.default = util_1.createRule({
additionalProperties: false,
},
],
fixable: dot_notation_1.default.meta.fixable,
messages: dot_notation_1.default.meta.messages,
fixable: baseRule.meta.fixable,
hasSuggestions: baseRule.meta.hasSuggestions,
messages: baseRule.meta.messages,
},
defaultOptions: [
{
@ -79,8 +81,8 @@ exports.default = util_1.createRule({
],
create(context, [options]) {
var _a;
const rules = dot_notation_1.default.create(context);
const { program, esTreeNodeToTSNodeMap } = util_1.getParserServices(context);
const rules = baseRule.create(context);
const { program, esTreeNodeToTSNodeMap } = (0, util_1.getParserServices)(context);
const typeChecker = program.getTypeChecker();
const allowPrivateClassPropertyAccess = options.allowPrivateClassPropertyAccess;
const allowProtectedClassPropertyAccess = options.allowProtectedClassPropertyAccess;
@ -90,25 +92,27 @@ exports.default = util_1.createRule({
'noPropertyAccessFromIndexSignature');
return {
MemberExpression(node) {
var _a, _b, _c;
var _a, _b;
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;
const modifierKind = (_b = (0, util_1.getModifiers)((_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[0].kind;
if ((allowPrivateClassPropertyAccess &&
modifierKind == ts.SyntaxKind.PrivateKeyword) ||
modifierKind === ts.SyntaxKind.PrivateKeyword) ||
(allowProtectedClassPropertyAccess &&
modifierKind == ts.SyntaxKind.ProtectedKeyword)) {
modifierKind === ts.SyntaxKind.ProtectedKeyword)) {
return;
}
if (propertySymbol === undefined &&
allowIndexSignaturePropertyAccess) {
const objectType = typeChecker.getTypeAtLocation(esTreeNodeToTSNodeMap.get(node.object));
const indexType = typeChecker.getIndexTypeOfType(objectType, ts.IndexKind.String);
if (indexType != undefined) {
const indexType = objectType
.getNonNullableType()
.getStringIndexType();
if (indexType !== undefined) {
return;
}
}

View file

@ -1 +1 @@
{"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,iBAAU,CAAsB;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,c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b;oBACA,sDAAsD;oBACtD,MAAM,cAAc,GAAG,WAAW,CAAC,mBAAmB,CACpD,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CACzC,CAAC;oBACF,MAAM,YAAY,GAAG,MAAA,IAAA,mBAAY,EAC/B,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,eAAe,EAAE,0CAAG,CAAC,CAAC,CACvC,0CAAG,CAAC,EAAE,IAAI,CAAC;oBACZ,IACE,CAAC,+BAA+B;wBAC9B,YAAY,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC;wBAChD,CAAC,iCAAiC;4BAChC,YAAY,KAAK,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAClD;wBACA,OAAO;qBACR;oBACD,IACE,cAAc,KAAK,SAAS;wBAC5B,iCAAiC,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,KAAK,SAAS,EAAE;4BAC3B,OAAO;yBACR;qBACF;iBACF;gBACD,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
const explicitReturnTypeUtils_1 = require("../util/explicitReturnTypeUtils");
exports.default = util.createRule({
@ -28,7 +32,6 @@ exports.default = util.createRule({
type: 'problem',
docs: {
description: 'Require explicit return types on functions and class methods',
category: 'Stylistic Issues',
recommended: false,
},
messages: {
@ -38,20 +41,32 @@ exports.default = util.createRule({
{
type: 'object',
properties: {
allowExpressions: {
allowConciseArrowFunctionExpressionsStartingWithVoid: {
description: 'Whether to allow arrow functions that start with the `void` keyword.',
type: 'boolean',
},
allowTypedFunctionExpressions: {
allowExpressions: {
description: 'Whether to ignore function expressions (functions which are not part of a declaration).',
type: 'boolean',
},
allowHigherOrderFunctions: {
description: 'Whether to ignore functions immediately returning another function expression.',
type: 'boolean',
},
allowTypedFunctionExpressions: {
description: 'Whether to ignore type annotations on the variable of function expressions.',
type: 'boolean',
},
allowDirectConstAssertionInArrowFunctions: {
description: 'Whether to ignore arrow functions immediately returning a `as const` value.',
type: 'boolean',
},
allowConciseArrowFunctionExpressionsStartingWithVoid: {
type: 'boolean',
allowedNames: {
description: 'An array of function/method names that will not have their arguments or return values checked.',
items: {
type: 'string',
},
type: 'array',
},
},
additionalProperties: false,
@ -65,27 +80,85 @@ exports.default = util.createRule({
allowHigherOrderFunctions: true,
allowDirectConstAssertionInArrowFunctions: true,
allowConciseArrowFunctionExpressionsStartingWithVoid: false,
allowedNames: [],
},
],
create(context, [options]) {
const sourceCode = context.getSourceCode();
function isAllowedName(node) {
var _a, _b;
if (!((_a = options.allowedNames) === null || _a === void 0 ? void 0 : _a.length)) {
return false;
}
if (node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression ||
node.type === utils_1.AST_NODE_TYPES.FunctionExpression) {
const parent = node.parent;
let funcName;
if ((_b = node.id) === null || _b === void 0 ? void 0 : _b.name) {
funcName = node.id.name;
}
else if (parent) {
switch (parent.type) {
case utils_1.AST_NODE_TYPES.VariableDeclarator: {
if (parent.id.type === utils_1.AST_NODE_TYPES.Identifier) {
funcName = parent.id.name;
}
break;
}
case utils_1.AST_NODE_TYPES.MethodDefinition:
case utils_1.AST_NODE_TYPES.PropertyDefinition:
case utils_1.AST_NODE_TYPES.Property: {
if (parent.key.type === utils_1.AST_NODE_TYPES.Identifier &&
parent.computed === false) {
funcName = parent.key.name;
}
break;
}
}
}
if (!!funcName && !!options.allowedNames.includes(funcName)) {
return true;
}
}
if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration &&
node.id &&
node.id.type === utils_1.AST_NODE_TYPES.Identifier &&
!!options.allowedNames.includes(node.id.name)) {
return true;
}
return false;
}
return {
'ArrowFunctionExpression, FunctionExpression'(node) {
if (options.allowConciseArrowFunctionExpressionsStartingWithVoid &&
node.type === experimental_utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
node.expression &&
node.body.type === experimental_utils_1.AST_NODE_TYPES.UnaryExpression &&
node.body.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
node.body.operator === 'void') {
return;
}
explicitReturnTypeUtils_1.checkFunctionExpressionReturnType(node, options, sourceCode, loc => context.report({
if (isAllowedName(node)) {
return;
}
if (options.allowTypedFunctionExpressions &&
((0, explicitReturnTypeUtils_1.isValidFunctionExpressionReturnType)(node, options) ||
(0, explicitReturnTypeUtils_1.ancestorHasReturnType)(node))) {
return;
}
(0, explicitReturnTypeUtils_1.checkFunctionReturnType)(node, options, sourceCode, loc => context.report({
node,
loc,
messageId: 'missingReturnType',
}));
},
FunctionDeclaration(node) {
explicitReturnTypeUtils_1.checkFunctionReturnType(node, options, sourceCode, loc => context.report({
if (isAllowedName(node)) {
return;
}
if (options.allowTypedFunctionExpressions && node.returnType) {
return;
}
(0, explicitReturnTypeUtils_1.checkFunctionReturnType)(node, options, sourceCode, loc => context.report({
node,
loc,
messageId: 'missingReturnType',

View file

@ -1 +1 @@
{"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,2DAAiC,CAAC,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,iDAAuB,CAAC,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"}
{"version":3,"file":"explicit-function-return-type.js","sourceRoot":"","sources":["../../src/rules/explicit-function-return-type.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAA0D;AAE1D,8CAAgC;AAChC,6EAIyC;AAczC,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,WAAW,EAAE,KAAK;SACnB;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,kCAAkC;SACtD;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,oDAAoD,EAAE;wBACpD,WAAW,EACT,sEAAsE;wBACxE,IAAI,EAAE,SAAS;qBAChB;oBACD,gBAAgB,EAAE;wBAChB,WAAW,EACT,yFAAyF;wBAC3F,IAAI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AI,CAAC,QAAQ,KAAK,MAAM,EAC7B;oBACA,OAAO;iBACR;gBAED,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE;oBACvB,OAAO;iBACR;gBAED,IACE,OAAO,CAAC,6BAA6B;oBACrC,CAAC,IAAA,6DAAmC,EAAC,IAAI,EAAE,OAAO,CAAC;wBACjD,IAAA,+CAAqB,EAAC,IAAI,CAAC,CAAC,EAC9B;oBACA,OAAO;iBACR;gBAED,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;YACD,mBAAmB,CAAC,IAAI;gBACtB,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE;oBACvB,OAAO;iBACR;gBACD,IAAI,OAAO,CAAC,6BAA6B,IAAI,IAAI,CAAC,UAAU,EAAE;oBAC5D,OAAO;iBACR;gBAED,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"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,16 +23,31 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
const accessibilityLevel = { enum: ['explicit', 'no-public', 'off'] };
const accessibilityLevel = {
oneOf: [
{
const: 'explicit',
description: 'Always require an accessor.',
},
{
const: 'no-public',
description: 'Require an accessor except when public.',
},
{
const: 'off',
description: 'Never check whether there is an accessor.',
},
],
};
exports.default = util.createRule({
name: 'explicit-member-accessibility',
meta: {
hasSuggestions: true,
type: 'problem',
docs: {
description: 'Require explicit accessibility modifiers on class properties and methods',
category: 'Stylistic Issues',
// too opinionated to be recommended
recommended: false,
},
@ -36,33 +55,42 @@ exports.default = util.createRule({
messages: {
missingAccessibility: 'Missing accessibility modifier on {{type}} {{name}}.',
unwantedPublicAccessibility: 'Public accessibility modifier on {{type}} {{name}}.',
addExplicitAccessibility: "Add '{{ type }}' accessibility modifier",
},
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,
schema: {
$defs: {
accessibilityLevel,
},
],
prefixItems: [
{
type: 'object',
properties: {
accessibility: { $ref: '#/$defs/accessibilityLevel' },
overrides: {
type: 'object',
properties: {
accessors: { $ref: '#/$defs/accessibilityLevel' },
constructors: { $ref: '#/$defs/accessibilityLevel' },
methods: { $ref: '#/$defs/accessibilityLevel' },
properties: { $ref: '#/$defs/accessibilityLevel' },
parameterProperties: {
$ref: '#/$defs/accessibilityLevel',
},
},
additionalProperties: false,
},
ignoredMethodNames: {
type: 'array',
items: {
type: 'string',
},
},
},
additionalProperties: false,
},
],
type: 'array',
},
},
defaultOptions: [{ accessibility: 'explicit' }],
create(context, [option]) {
@ -76,25 +104,14 @@ exports.default = util.createRule({
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) {
if (methodDefinition.key.type === utils_1.AST_NODE_TYPES.PrivateIdentifier) {
return;
}
let nodeType = 'method definition';
let check = baseCheck;
switch (methodDefinition.kind) {
@ -110,16 +127,32 @@ exports.default = util.createRule({
nodeType = `${methodDefinition.kind} property accessor`;
break;
}
const methodName = util.getNameFromMember(methodDefinition, sourceCode);
const { name: 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));
context.report({
node: methodDefinition,
messageId: 'unwantedPublicAccessibility',
data: {
type: nodeType,
name: methodName,
},
fix: getUnwantedPublicAccessibilityFixer(methodDefinition),
});
}
else if (check === 'explicit' && !methodDefinition.accessibility) {
reportIssue('missingAccessibility', nodeType, methodDefinition, methodName);
context.report({
node: methodDefinition,
messageId: 'missingAccessibility',
data: {
type: nodeType,
name: methodName,
},
suggest: getMissingAccessibilitySuggestions(methodDefinition),
});
}
}
/**
@ -131,7 +164,7 @@ exports.default = util.createRule({
let rangeToRemove;
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
if (token.type === experimental_utils_1.AST_TOKEN_TYPES.Keyword &&
if (token.type === utils_1.AST_TOKEN_TYPES.Keyword &&
token.value === 'public') {
const commensAfterPublicKeyword = sourceCode.getCommentsAfter(token);
if (commensAfterPublicKeyword.length) {
@ -155,18 +188,69 @@ exports.default = util.createRule({
};
}
/**
* Checks if property has an accessibility modifier.
* @param classProperty The node representing a ClassProperty.
* Creates a fixer that adds a "public" keyword with following spaces
*/
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));
function getMissingAccessibilitySuggestions(node) {
function fix(accessibility, fixer) {
var _a;
if ((_a = node === null || node === void 0 ? void 0 : node.decorators) === null || _a === void 0 ? void 0 : _a.length) {
const lastDecorator = node.decorators[node.decorators.length - 1];
const nextToken = sourceCode.getTokenAfter(lastDecorator);
return fixer.insertTextBefore(nextToken, `${accessibility} `);
}
return fixer.insertTextBefore(node, `${accessibility} `);
}
else if (propCheck === 'explicit' && !classProperty.accessibility) {
reportIssue('missingAccessibility', nodeType, classProperty, propertyName);
return [
{
messageId: 'addExplicitAccessibility',
data: { type: 'public' },
fix: fixer => fix('public', fixer),
},
{
messageId: 'addExplicitAccessibility',
data: { type: 'private' },
fix: fixer => fix('private', fixer),
},
{
messageId: 'addExplicitAccessibility',
data: { type: 'protected' },
fix: fixer => fix('protected', fixer),
},
];
}
/**
* Checks if property has an accessibility modifier.
* @param propertyDefinition The node representing a PropertyDefinition.
*/
function checkPropertyAccessibilityModifier(propertyDefinition) {
if (propertyDefinition.key.type === utils_1.AST_NODE_TYPES.PrivateIdentifier) {
return;
}
const nodeType = 'class property';
const { name: propertyName } = util.getNameFromMember(propertyDefinition, sourceCode);
if (propCheck === 'no-public' &&
propertyDefinition.accessibility === 'public') {
context.report({
node: propertyDefinition,
messageId: 'unwantedPublicAccessibility',
data: {
type: nodeType,
name: propertyName,
},
fix: getUnwantedPublicAccessibilityFixer(propertyDefinition),
});
}
else if (propCheck === 'explicit' &&
!propertyDefinition.accessibility) {
context.report({
node: propertyDefinition,
messageId: 'missingAccessibility',
data: {
type: nodeType,
name: propertyName,
},
suggest: getMissingAccessibilitySuggestions(propertyDefinition),
});
}
}
/**
@ -176,33 +260,49 @@ exports.default = util.createRule({
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) {
if (node.parameter.type !== utils_1.AST_NODE_TYPES.Identifier &&
node.parameter.type !== utils_1.AST_NODE_TYPES.AssignmentPattern) {
return;
}
const nodeName = node.parameter.type === experimental_utils_1.AST_NODE_TYPES.Identifier
const nodeName = node.parameter.type === 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);
context.report({
node,
messageId: 'missingAccessibility',
data: {
type: nodeType,
name: nodeName,
},
suggest: getMissingAccessibilitySuggestions(node),
});
}
break;
}
case 'no-public': {
if (node.accessibility === 'public' && node.readonly) {
reportIssue('unwantedPublicAccessibility', nodeType, node, nodeName, getUnwantedPublicAccessibilityFixer(node));
context.report({
node,
messageId: 'unwantedPublicAccessibility',
data: {
type: nodeType,
name: nodeName,
},
fix: getUnwantedPublicAccessibilityFixer(node),
});
}
break;
}
}
}
return {
'MethodDefinition, TSAbstractMethodDefinition': checkMethodAccessibilityModifier,
'PropertyDefinition, TSAbstractPropertyDefinition': checkPropertyAccessibilityModifier,
TSParameterProperty: checkParameterPropertyAccessibilityModifier,
ClassProperty: checkPropertyAccessibilityModifier,
MethodDefinition: checkMethodAccessibilityModifier,
};
},
});

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (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 utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
const explicitReturnTypeUtils_1 = require("../util/explicitReturnTypeUtils");
exports.default = util.createRule({
@ -28,8 +33,7 @@ exports.default = util.createRule({
type: 'problem',
docs: {
description: "Require explicit return and argument types on exported functions' and classes' public class methods",
category: 'Stylistic Issues',
recommended: 'warn',
recommended: false,
},
messages: {
missingReturnType: 'Missing return type on function.',
@ -43,21 +47,32 @@ exports.default = util.createRule({
type: 'object',
properties: {
allowArgumentsExplicitlyTypedAsAny: {
description: 'Whether to ignore arguments that are explicitly typed as `any`.',
type: 'boolean',
},
allowDirectConstAssertionInArrowFunctions: {
description: [
'Whether to ignore return type annotations on body-less arrow functions that return an `as const` type assertion.',
'You must still type the parameters of the function.',
].join('\n'),
type: 'boolean',
},
allowedNames: {
type: 'array',
description: 'An array of function/method names that will not have their arguments or return values checked.',
items: {
type: 'string',
},
type: 'array',
},
allowHigherOrderFunctions: {
description: [
'Whether to ignore return type annotations on functions immediately returning another function expression.',
'You must still type the parameters of the function.',
].join('\n'),
type: 'boolean',
},
allowTypedFunctionExpressions: {
description: 'Whether to ignore type annotations on the variable of a function expresion.',
type: 'boolean',
},
// DEPRECATED - To be removed in next major
@ -128,29 +143,29 @@ exports.default = util.createRule({
function checkParameters(node) {
function checkParameter(param) {
function report(namedMessageId, unnamedMessageId) {
if (param.type === experimental_utils_1.AST_NODE_TYPES.Identifier) {
if (param.type === 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) {
else if (param.type === 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) {
else if (param.type === 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) {
else if (param.type === utils_1.AST_NODE_TYPES.RestElement) {
if (param.argument.type === utils_1.AST_NODE_TYPES.Identifier) {
context.report({
node: param,
messageId: namedMessageId,
@ -167,22 +182,22 @@ exports.default = util.createRule({
}
}
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:
case utils_1.AST_NODE_TYPES.ArrayPattern:
case utils_1.AST_NODE_TYPES.Identifier:
case utils_1.AST_NODE_TYPES.ObjectPattern:
case 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) {
utils_1.AST_NODE_TYPES.TSAnyKeyword) {
report('anyTypedArg', 'anyTypedArgUnnamed');
}
return;
case experimental_utils_1.AST_NODE_TYPES.TSParameterProperty:
case 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
case utils_1.AST_NODE_TYPES.AssignmentPattern: // ignored as it has a type via its assignment
return;
}
}
@ -198,23 +213,24 @@ exports.default = util.createRule({
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 &&
if (node.type === utils_1.AST_NODE_TYPES.VariableDeclarator ||
node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration) {
return (((_a = node.id) === null || _a === void 0 ? void 0 : _a.type) === 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 &&
else if (node.type === utils_1.AST_NODE_TYPES.MethodDefinition ||
node.type === utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition ||
(node.type === utils_1.AST_NODE_TYPES.Property && node.method) ||
node.type === utils_1.AST_NODE_TYPES.PropertyDefinition) {
if (node.key.type === 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 &&
if (node.key.type === 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) {
if (!node.computed && node.key.type === utils_1.AST_NODE_TYPES.Identifier) {
return options.allowedNames.includes(node.key.name);
}
}
@ -224,13 +240,13 @@ exports.default = util.createRule({
var _a;
let current = node.parent;
while (current) {
if (current.type === experimental_utils_1.AST_NODE_TYPES.ReturnStatement) {
if (current.type === 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) ||
!explicitReturnTypeUtils_1.doesImmediatelyReturnFunctionExpression(current)) {
!(0, explicitReturnTypeUtils_1.doesImmediatelyReturnFunctionExpression)(current)) {
return false;
}
if (checkedFunctions.has(current)) {
@ -249,11 +265,12 @@ exports.default = util.createRule({
// check all of the definitions
for (const definition of variable.defs) {
// cases we don't care about in this rule
if (definition.type === 'ImplicitGlobalVariable' ||
definition.type === 'ImportBinding' ||
// eslint-disable-next-line @typescript-eslint/internal/prefer-ast-types-enum
definition.type === 'CatchClause' ||
definition.type === 'Parameter') {
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);
@ -274,100 +291,61 @@ exports.default = util.createRule({
}
alreadyVisited.add(node);
switch (node.type) {
case experimental_utils_1.AST_NODE_TYPES.ArrowFunctionExpression:
case experimental_utils_1.AST_NODE_TYPES.FunctionExpression:
case utils_1.AST_NODE_TYPES.ArrowFunctionExpression:
case utils_1.AST_NODE_TYPES.FunctionExpression:
return checkFunctionExpression(node);
case experimental_utils_1.AST_NODE_TYPES.ArrayExpression:
case 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') {
case utils_1.AST_NODE_TYPES.PropertyDefinition:
if (node.accessibility === 'private' ||
node.key.type === utils_1.AST_NODE_TYPES.PrivateIdentifier) {
return;
}
return checkNode(node.value);
case experimental_utils_1.AST_NODE_TYPES.ClassDeclaration:
case experimental_utils_1.AST_NODE_TYPES.ClassExpression:
case utils_1.AST_NODE_TYPES.ClassDeclaration:
case utils_1.AST_NODE_TYPES.ClassExpression:
for (const element of node.body.body) {
checkNode(element);
}
return;
case experimental_utils_1.AST_NODE_TYPES.FunctionDeclaration:
case 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') {
case utils_1.AST_NODE_TYPES.MethodDefinition:
case utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition:
if (node.accessibility === 'private' ||
node.key.type === utils_1.AST_NODE_TYPES.PrivateIdentifier) {
return;
}
return checkNode(node.value);
case experimental_utils_1.AST_NODE_TYPES.Identifier:
case utils_1.AST_NODE_TYPES.Identifier:
return followReference(node);
case experimental_utils_1.AST_NODE_TYPES.ObjectExpression:
case utils_1.AST_NODE_TYPES.ObjectExpression:
for (const property of node.properties) {
checkNode(property);
}
return;
case experimental_utils_1.AST_NODE_TYPES.Property:
case utils_1.AST_NODE_TYPES.Property:
return checkNode(node.value);
case experimental_utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression:
case utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression:
return checkEmptyBodyFunctionExpression(node);
case experimental_utils_1.AST_NODE_TYPES.VariableDeclaration:
case utils_1.AST_NODE_TYPES.VariableDeclaration:
for (const declaration of node.declarations) {
checkNode(declaration);
}
return;
case experimental_utils_1.AST_NODE_TYPES.VariableDeclarator:
case 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 &&
const isConstructor = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 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) &&
const isSetAccessor = (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition ||
((_c = node.parent) === null || _c === void 0 ? void 0 : _c.type) === utils_1.AST_NODE_TYPES.MethodDefinition) &&
node.parent.kind === 'set';
if (!isConstructor && !isSetAccessor && !node.returnType) {
context.report({
@ -383,11 +361,11 @@ exports.default = util.createRule({
}
checkedFunctions.add(node);
if (isAllowedName(node.parent) ||
explicitReturnTypeUtils_1.isTypedFunctionExpression(node, options) ||
ancestorHasReturnType(node)) {
(0, explicitReturnTypeUtils_1.isTypedFunctionExpression)(node, options) ||
(0, explicitReturnTypeUtils_1.ancestorHasReturnType)(node)) {
return;
}
explicitReturnTypeUtils_1.checkFunctionExpressionReturnType(node, options, sourceCode, loc => {
(0, explicitReturnTypeUtils_1.checkFunctionExpressionReturnType)(node, options, sourceCode, loc => {
context.report({
node,
loc,
@ -401,10 +379,10 @@ exports.default = util.createRule({
return;
}
checkedFunctions.add(node);
if (isAllowedName(node) || ancestorHasReturnType(node)) {
if (isAllowedName(node) || (0, explicitReturnTypeUtils_1.ancestorHasReturnType)(node)) {
return;
}
explicitReturnTypeUtils_1.checkFunctionReturnType(node, options, sourceCode, loc => {
(0, explicitReturnTypeUtils_1.checkFunctionReturnType)(node, options, sourceCode, loc => {
context.report({
node,
loc,

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -26,7 +30,6 @@ exports.default = util.createRule({
type: 'layout',
docs: {
description: 'Require or disallow spacing between function identifiers and their invocations',
category: 'Stylistic Issues',
recommended: false,
extendsBaseRule: true,
},

View file

@ -1 +1 @@
{"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;oBACD,QAAQ,EAAE,CAAC;oBACX,QAAQ,EAAE,CAAC;iBACZ;gBACD;oBACE,IAAI,EAAE,OAAO;oBACb,KAAK,EAAE;wBACL;4BACE,IAAI,EAAE,CAAC,QAAQ,CAAC;yBACjB;wBACD;4BACE,IAAI,EAAE,QAAQ;4BACd,UAAU,EAAE;gCACV,aAAa,EAAE;oCACb,IAAI,EAAE,SAAS;iCAChB;6BACF;4BACD,oBAAoB,EAAE,KAAK;yBAC5B;qBACF;oBACD,QAAQ,EAAE,CAAC;oBACX,QAAQ,EAAE,CAAC;iBACZ;aACF;SACF;QAED,QAAQ,EAAE;YACR,oBAAoB,EAClB,wDAAwD;YAC1D,iBAAiB,EAAE,qDAAqD;YACxE,OAAO,EAAE,gDAAgD;SAC1D;KACF;IACD,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;IAC7B,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;QAC9B,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;QAElC;;;;;WAKG;QACH,SA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QACH,CAAC;QAED,OAAO;YACL,cAAc,EAAE,YAAY;YAC5B,aAAa,EAAE,YAAY;SAC5B,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
{"version":3,"file":"func-call-spacing.js","sourceRoot":"","sources":["../../src/rules/func-call-spacing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAEA,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,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;oBACD,QAAQ,EAAE,CAAC;oBACX,QAAQ,EAAE,CAAC;iBACZ;gBACD;oBACE,IAAI,EAAE,OAAO;oBACb,KAAK,EAAE;wBACL;4BACE,IAAI,EAAE,CAAC,QAAQ,CAAC;yBACjB;wBACD;4BACE,IAAI,EAAE,QAAQ;4BACd,UAAU,EAAE;gCACV,aAAa,EAAE;oCACb,IAAI,EAAE,SAAS;iCAChB;6BACF;4BACD,oBAAoB,EAAE,KAAK;yBAC5B;qBACF;oBACD,QAAQ,EAAE,CAAC;oBACX,QAAQ,EAAE,CAAC;iBACZ;aACF;SACF;QAED,QAAQ,EAAE;YACR,oBAAoB,EAClB,wDAAwD;YAC1D,iBAAiB,EAAE,qDAAqD;YACxE,OAAO,EAAE,gDAAgD;SAC1D;KACF;IACD,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;IAC7B,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;QAC9B,MAAM,UAAU,GAAG,OAAO,CAAC,aAA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K,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"}

View file

@ -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 = 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

View file

@ -1 +0,0 @@
{"version":3,"file":"BinarySearchTree.js","sourceRoot":"","sources":["../../../src/rules/indent-new-do-not-use/BinarySearchTree.ts"],"names":[],"mappings":";AAAA,6DAA6D;A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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

View file

@ -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,IAA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AAI,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;YAC5C,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC/B;IACH,CAAC;IAUD,kBAAkB,CAAC,KAAqB;QACtC,OAAO,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;IAC9C,CAAC;CACF;AA5QD,sCA4QC"}

View file

@ -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.js.map

View file

@ -1 +0,0 @@
{"version":3,"file":"TokenInfo.js","sourceRoot":"","sources":["../../../src/rules/indent-new-do-not-use/TokenInfo.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,kGAAkG;;;AAIlG;;GAEG;AACH,MAA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AAK,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

View file

@ -7,7 +7,11 @@
/* 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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -24,79 +28,75 @@ var __importStar = (this && this.__importStar) || function (mod) {
__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 utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('indent');
const KNOWN_NODES = new Set([
// Class properties aren't yet supported by eslint...
experimental_utils_1.AST_NODE_TYPES.ClassProperty,
utils_1.AST_NODE_TYPES.PropertyDefinition,
// 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,
utils_1.AST_NODE_TYPES.TSAbstractKeyword,
utils_1.AST_NODE_TYPES.TSAnyKeyword,
utils_1.AST_NODE_TYPES.TSBooleanKeyword,
utils_1.AST_NODE_TYPES.TSNeverKeyword,
utils_1.AST_NODE_TYPES.TSNumberKeyword,
utils_1.AST_NODE_TYPES.TSStringKeyword,
utils_1.AST_NODE_TYPES.TSSymbolKeyword,
utils_1.AST_NODE_TYPES.TSUndefinedKeyword,
utils_1.AST_NODE_TYPES.TSUnknownKeyword,
utils_1.AST_NODE_TYPES.TSVoidKeyword,
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,
utils_1.AST_NODE_TYPES.TSAbstractPropertyDefinition,
utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition,
utils_1.AST_NODE_TYPES.TSArrayType,
utils_1.AST_NODE_TYPES.TSAsExpression,
utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration,
utils_1.AST_NODE_TYPES.TSConditionalType,
utils_1.AST_NODE_TYPES.TSConstructorType,
utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration,
utils_1.AST_NODE_TYPES.TSDeclareFunction,
utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
utils_1.AST_NODE_TYPES.TSEnumDeclaration,
utils_1.AST_NODE_TYPES.TSEnumMember,
utils_1.AST_NODE_TYPES.TSExportAssignment,
utils_1.AST_NODE_TYPES.TSExternalModuleReference,
utils_1.AST_NODE_TYPES.TSFunctionType,
utils_1.AST_NODE_TYPES.TSImportType,
utils_1.AST_NODE_TYPES.TSIndexedAccessType,
utils_1.AST_NODE_TYPES.TSIndexSignature,
utils_1.AST_NODE_TYPES.TSInferType,
utils_1.AST_NODE_TYPES.TSInterfaceBody,
utils_1.AST_NODE_TYPES.TSInterfaceDeclaration,
utils_1.AST_NODE_TYPES.TSInterfaceHeritage,
utils_1.AST_NODE_TYPES.TSIntersectionType,
utils_1.AST_NODE_TYPES.TSImportEqualsDeclaration,
utils_1.AST_NODE_TYPES.TSLiteralType,
utils_1.AST_NODE_TYPES.TSMappedType,
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,
utils_1.AST_NODE_TYPES.TSModuleBlock,
utils_1.AST_NODE_TYPES.TSModuleDeclaration,
utils_1.AST_NODE_TYPES.TSNonNullExpression,
utils_1.AST_NODE_TYPES.TSParameterProperty,
'TSPlusToken',
experimental_utils_1.AST_NODE_TYPES.TSPropertySignature,
experimental_utils_1.AST_NODE_TYPES.TSQualifiedName,
utils_1.AST_NODE_TYPES.TSPropertySignature,
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,
utils_1.AST_NODE_TYPES.TSRestType,
utils_1.AST_NODE_TYPES.TSThisType,
utils_1.AST_NODE_TYPES.TSTupleType,
utils_1.AST_NODE_TYPES.TSTypeAnnotation,
utils_1.AST_NODE_TYPES.TSTypeLiteral,
utils_1.AST_NODE_TYPES.TSTypeOperator,
utils_1.AST_NODE_TYPES.TSTypeParameter,
utils_1.AST_NODE_TYPES.TSTypeParameterDeclaration,
utils_1.AST_NODE_TYPES.TSTypeParameterInstantiation,
utils_1.AST_NODE_TYPES.TSTypeReference,
utils_1.AST_NODE_TYPES.TSUnionType,
utils_1.AST_NODE_TYPES.Decorator,
]);
exports.default = util.createRule({
name: 'indent',
@ -104,16 +104,14 @@ exports.default = util.createRule({
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}}.',
},
hasSuggestions: baseRule.meta.hasSuggestions,
schema: baseRule.meta.schema,
messages: baseRule.meta.messages,
},
defaultOptions: [
// typescript docs and playground use 4 space indent
@ -136,14 +134,14 @@ exports.default = util.createRule({
value: optionsWithDefaults,
},
});
const rules = indent_1.default.create(contextWithDefaults);
const rules = baseRule.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) {
function TSPropertySignatureToProperty(node, type = utils_1.AST_NODE_TYPES.Property) {
const base = {
// indent doesn't actually use these
key: null,
@ -159,7 +157,7 @@ exports.default = util.createRule({
range: node.range,
loc: node.loc,
};
if (type === experimental_utils_1.AST_NODE_TYPES.Property) {
if (type === utils_1.AST_NODE_TYPES.Property) {
return Object.assign({ type }, base);
}
else {
@ -184,7 +182,7 @@ exports.default = util.createRule({
TSAsExpression(node) {
// transform it to a BinaryExpression
return rules['BinaryExpression, LogicalExpression']({
type: experimental_utils_1.AST_NODE_TYPES.BinaryExpression,
type: utils_1.AST_NODE_TYPES.BinaryExpression,
operator: 'as',
left: node.expression,
// the first typeAnnotation includes the as token
@ -198,9 +196,9 @@ exports.default = util.createRule({
TSConditionalType(node) {
// transform it to a ConditionalExpression
return rules.ConditionalExpression({
type: experimental_utils_1.AST_NODE_TYPES.ConditionalExpression,
type: utils_1.AST_NODE_TYPES.ConditionalExpression,
test: {
type: experimental_utils_1.AST_NODE_TYPES.BinaryExpression,
type: utils_1.AST_NODE_TYPES.BinaryExpression,
operator: 'extends',
left: node.checkType,
right: node.extendsType,
@ -222,7 +220,7 @@ exports.default = util.createRule({
'TSEnumDeclaration, TSTypeLiteral'(node) {
// transform it to an ObjectExpression
return rules['ObjectExpression, ObjectPattern']({
type: experimental_utils_1.AST_NODE_TYPES.ObjectExpression,
type: utils_1.AST_NODE_TYPES.ObjectExpression,
properties: node.members.map(member => TSPropertySignatureToProperty(member)),
// location data
parent: node.parent,
@ -235,11 +233,11 @@ exports.default = util.createRule({
// 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,
type: utils_1.AST_NODE_TYPES.VariableDeclaration,
kind: 'const',
declarations: [
{
type: experimental_utils_1.AST_NODE_TYPES.VariableDeclarator,
type: utils_1.AST_NODE_TYPES.VariableDeclarator,
range: [id.range[0], moduleReference.range[1]],
loc: {
start: id.loc.start,
@ -247,9 +245,9 @@ exports.default = util.createRule({
},
id: id,
init: {
type: experimental_utils_1.AST_NODE_TYPES.CallExpression,
type: utils_1.AST_NODE_TYPES.CallExpression,
callee: {
type: experimental_utils_1.AST_NODE_TYPES.Identifier,
type: utils_1.AST_NODE_TYPES.Identifier,
name: 'require',
range: [
moduleReference.range[0],
@ -281,7 +279,7 @@ exports.default = util.createRule({
TSIndexedAccessType(node) {
// convert to a MemberExpression
return rules['MemberExpression, JSXMemberExpression, MetaProperty']({
type: experimental_utils_1.AST_NODE_TYPES.MemberExpression,
type: utils_1.AST_NODE_TYPES.MemberExpression,
object: node.objectType,
property: node.indexType,
// location data
@ -295,8 +293,8 @@ exports.default = util.createRule({
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)),
type: utils_1.AST_NODE_TYPES.ClassBody,
body: node.body.map(p => TSPropertySignatureToProperty(p, utils_1.AST_NODE_TYPES.PropertyDefinition)),
// location data
parent: node.parent,
range: node.range,
@ -306,7 +304,7 @@ exports.default = util.createRule({
'TSInterfaceDeclaration[extends.length > 0]'(node) {
// transform it to a ClassDeclaration
return rules['ClassDeclaration[superClass], ClassExpression[superClass]']({
type: experimental_utils_1.AST_NODE_TYPES.ClassDeclaration,
type: utils_1.AST_NODE_TYPES.ClassDeclaration,
body: node.body,
id: null,
// TODO: This is invalid, there can be more than one extends in interface
@ -322,10 +320,10 @@ exports.default = util.createRule({
const squareBracketStart = sourceCode.getTokenBefore(node.typeParameter);
// transform it to an ObjectExpression
return rules['ObjectExpression, ObjectPattern']({
type: experimental_utils_1.AST_NODE_TYPES.ObjectExpression,
type: utils_1.AST_NODE_TYPES.ObjectExpression,
properties: [
{
type: experimental_utils_1.AST_NODE_TYPES.Property,
type: utils_1.AST_NODE_TYPES.Property,
key: node.typeParameter,
value: node.typeAnnotation,
// location data
@ -356,7 +354,7 @@ exports.default = util.createRule({
TSModuleBlock(node) {
// transform it to a BlockStatement
return rules['BlockStatement, ClassBody']({
type: experimental_utils_1.AST_NODE_TYPES.BlockStatement,
type: utils_1.AST_NODE_TYPES.BlockStatement,
body: node.body,
// location data
parent: node.parent,
@ -366,7 +364,7 @@ exports.default = util.createRule({
},
TSQualifiedName(node) {
return rules['MemberExpression, JSXMemberExpression, MetaProperty']({
type: experimental_utils_1.AST_NODE_TYPES.MemberExpression,
type: utils_1.AST_NODE_TYPES.MemberExpression,
object: node.left,
property: node.right,
// location data
@ -380,7 +378,7 @@ exports.default = util.createRule({
TSTupleType(node) {
// transform it to an ArrayExpression
return rules['ArrayExpression, ArrayPattern']({
type: experimental_utils_1.AST_NODE_TYPES.ArrayExpression,
type: utils_1.AST_NODE_TYPES.ArrayExpression,
elements: node.elementTypes,
// location data
parent: node.parent,
@ -396,7 +394,7 @@ exports.default = util.createRule({
// 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,
type: utils_1.AST_NODE_TYPES.JSXOpeningElement,
selfClosing: false,
name: name,
attributes: attributes,

File diff suppressed because one or more lines are too long

View file

@ -13,9 +13,11 @@ 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_generic_constructors_1 = __importDefault(require("./consistent-generic-constructors"));
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_exports_1 = __importDefault(require("./consistent-type-exports"));
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"));
@ -36,6 +38,7 @@ 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_enum_values_1 = __importDefault(require("./no-duplicate-enum-values"));
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"));
@ -55,14 +58,18 @@ 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_redundant_type_constituents_1 = __importDefault(require("./no-redundant-type-constituents"));
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"));
@ -76,16 +83,19 @@ const no_unnecessary_type_constraint_1 = __importDefault(require("./no-unnecessa
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_declaration_merging_1 = __importDefault(require("./no-unsafe-declaration-merging"));
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_useless_empty_export_1 = __importDefault(require("./no-useless-empty-export"));
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 parameter_properties_1 = __importDefault(require("./parameter-properties"));
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"));
@ -99,6 +109,7 @@ 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"));
@ -109,7 +120,9 @@ const restrict_plus_operands_1 = __importDefault(require("./restrict-plus-operan
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_constituents_1 = __importDefault(require("./sort-type-constituents"));
const sort_type_union_intersection_members_1 = __importDefault(require("./sort-type-union-intersection-members"));
const space_before_blocks_1 = __importDefault(require("./space-before-blocks"));
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"));
@ -130,9 +143,11 @@ exports.default = {
'class-literal-property-style': class_literal_property_style_1.default,
'comma-dangle': comma_dangle_1.default,
'comma-spacing': comma_spacing_1.default,
'consistent-generic-constructors': consistent_generic_constructors_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-exports': consistent_type_exports_1.default,
'consistent-type-imports': consistent_type_imports_1.default,
'default-param-last': default_param_last_1.default,
'dot-notation': dot_notation_1.default,
@ -153,6 +168,7 @@ exports.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-enum-values': no_duplicate_enum_values_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,
@ -172,14 +188,18 @@ exports.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-redundant-type-constituents': no_redundant_type_constituents_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,
@ -193,16 +213,19 @@ exports.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-declaration-merging': no_unsafe_declaration_merging_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-useless-empty-export': no_useless_empty_export_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,
'parameter-properties': parameter_properties_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,
@ -216,6 +239,7 @@ exports.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,
@ -226,7 +250,9 @@ exports.default = {
'restrict-template-expressions': restrict_template_expressions_1.default,
'return-await': return_await_1.default,
semi: semi_1.default,
'sort-type-constituents': sort_type_constituents_1.default,
'sort-type-union-intersection-members': sort_type_union_intersection_members_1.default,
'space-before-blocks': space_before_blocks_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,

View file

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":";;;;;AAAA,kGAAwE;AACxE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AyB,EAAE,iCAAqB;IAChD,OAAO,EAAE,iBAAO;IAChB,gBAAgB,EAAE,wBAAa;IAC/B,oBAAoB,EAAE,4BAAiB;CACxC,CAAC"}
{"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,wGAA8E;AAC9E,wGAA6E;AAC7E,8FAAoE;AACpE,gGAAsE;AACtE,wFAA8D;AAC9D,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,0FAA+D;AAC/D,kFAAwD;AACxD,4EAAkD;AAClD,4EAAkD;AAClD,8EAAoD;AACpD,wEAA8C;AAC9C,gGAAoE;AACpE,wEAA8C;AAC9C,oEAA0C;AAC1C,gFAAsD;AACtD,kFAAwD;AACxD,wEAA6C;AAC7C,oFAAyD;AACzD,wEAA8C;AAC9C,gFAAsD;AACtD,wEAA8C;AAC9C,kFAAuD;AACvD,kEAAwC;AACxC,kFAAuD;AACvD,0EAAgD;AAChD,kGAAuE;AACvE,sEAA4C;AAC5C,gFAAsD;AACtD,kEAAyC;AACzC,wHAA2F;AAC3F,gHAAmF;AACnF,oFAAyD;AACzD,wFAA8D;AAC9D,kEAAyC;AACzC,sGAA2E;AAC3E,8EAAoD;AACpD,oFAA0D;AAC1D,4DAAmC;AACnC,oEAA0C;AAC1C,0EAAgD;AAChD,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AAc;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,wBAAwB,EAAE,gCAAoB;IAC9C,sCAAsC,EAAE,8CAAgC;IACxE,qBAAqB,EAAE,6BAAiB;IACxC,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"}

View file

@ -1,48 +1,49 @@
"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 utils_1 = require("@typescript-eslint/utils");
const util_1 = require("../util");
exports.default = util_1.createRule({
const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('init-declarations');
exports.default = (0, util_1.createRule)({
name: 'init-declarations',
meta: {
type: 'suggestion',
docs: {
description: 'require or disallow initialization in variable declarations',
category: 'Variables',
description: 'Require or disallow initialization in variable declarations',
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.",
},
hasSuggestions: baseRule.meta.hasSuggestions,
schema: baseRule.meta.schema,
messages: baseRule.meta.messages,
},
defaultOptions: ['always'],
create(context) {
const rules = init_declarations_1.default.create(context);
const mode = context.options[0] || 'always';
create(context, [mode]) {
const rules = baseRule.create(context);
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)) {
if (isAncestorNamespaceDeclared(node)) {
return;
}
}
rules['VariableDeclaration:exit'](node);
},
};
function isAncestorNamespaceDeclared(node) {
let ancestor = node.parent;
while (ancestor) {
if (ancestor.type === utils_1.AST_NODE_TYPES.TSModuleDeclaration &&
ancestor.declare) {
return true;
}
ancestor = ancestor.parent;
}
return false;
}
},
});
//# sourceMappingURL=init-declarations.js.map

View file

@ -1 +1 @@
{"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,iBAAU,CAAsB;IAC7C,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB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,EAAsB;IAC7C,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,6DAA6D;YAC/D,WAAW,EAAE,KAAK;YAClB,eAAe,EAAE,IAAI;SACtB;QACD,cAAc,EAAE,QAAQ,CAAC,IAAI,CAAC,cAAc;QAC5C,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;QAC5B,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ;KACjC;IACD,cAAc,EAAE,CAAC,QAAQ,CAAC;IAC1B,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;QACpB,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEvC,OAAO;YACL,0BAA0B,CAAC,IAAkC;gBAC3D,IAAI,IAAI,KAAK,QAAQ,EAAE;oBACrB,IAAI,IAAI,CAAC,OAAO,EAAE;wBAChB,OAAO;qBACR;oBACD,IAAI,2BAA2B,CAAC,IAAI,CAAC,EAAE;wBACrC,OAAO;qBACR;iBACF;gBAED,KAAK,CAAC,0BAA0B,CAAC,CAAC,IAAI,CAAC,CAAC;YAC1C,CAAC;SACF,CAAC;QAEF,SAAS,2BAA2B,CAClC,IAAkC;YAElC,IAAI,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;YAE3B,OAAO,QAAQ,EAAE;gBACf,IACE,QAAQ,CAAC,IAAI,KAAK,sBAAc,CAAC,mBAAmB;oBACpD,QAAQ,CAAC,OAAO,EAChB;oBACA,OAAO,IAAI,CAAC;iBACb;gBAED,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC;aAC5B;YAED,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -18,37 +22,45 @@ var __importStar = (this && this.__importStar) || function (mod) {
__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 utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('keyword-spacing');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const baseSchema = Array.isArray(baseRule.meta.schema)
? baseRule.meta.schema[0]
: baseRule.meta.schema;
const schema = util.deepMerge(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- https://github.com/microsoft/TypeScript/issues/17002
baseSchema, {
properties: {
overrides: {
properties: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
type: baseSchema.properties.overrides.properties.import,
},
},
},
});
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}}".',
},
hasSuggestions: baseRule.meta.hasSuggestions,
schema: [schema],
messages: baseRule.meta.messages,
},
defaultOptions: [{}],
create(context) {
create(context, [{ after, overrides }]) {
const sourceCode = context.getSourceCode();
const baseRules = keyword_spacing_1.default.create(context);
const baseRules = baseRule.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;
@ -56,11 +68,46 @@ exports.default = util.createRule({
// 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;
asToken.type = 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;
},
'ImportDeclaration[importKind=type]'(node) {
var _a, _b, _c, _d;
const { type: typeOptionOverride = {} } = overrides !== null && overrides !== void 0 ? overrides : {};
const typeToken = sourceCode.getFirstToken(node, { skip: 1 });
const punctuatorToken = sourceCode.getTokenAfter(typeToken);
if (((_b = (_a = node.specifiers) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.ImportDefaultSpecifier) {
return;
}
const spacesBetweenTypeAndPunctuator = punctuatorToken.range[0] - typeToken.range[1];
if (((_c = typeOptionOverride.after) !== null && _c !== void 0 ? _c : after) === true &&
spacesBetweenTypeAndPunctuator === 0) {
context.report({
loc: typeToken.loc,
messageId: 'expectedAfter',
data: { value: 'type' },
fix(fixer) {
return fixer.insertTextAfter(typeToken, ' ');
},
});
}
if (((_d = typeOptionOverride.after) !== null && _d !== void 0 ? _d : after) === false &&
spacesBetweenTypeAndPunctuator > 0) {
context.report({
loc: typeToken.loc,
messageId: 'unexpectedAfter',
data: { value: 'type' },
fix(fixer) {
return fixer.removeRange([
typeToken.range[1],
typeToken.range[1] + spacesBetweenTypeAndPunctuator,
]);
},
});
}
} });
},
});

View file

@ -1 +1 @@
{"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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C,CAAC;iBACJ;YACH,CAAC,IACD;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -18,15 +22,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
__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 utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
const schema = util.deepMerge(Object.assign({}, lines_between_class_members_1.default.meta.schema), {
const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('lines-between-class-members');
const schema = util.deepMerge(Object.assign({}, baseRule.meta.schema), {
1: {
exceptAfterOverload: {
type: 'boolean',
@ -40,16 +41,13 @@ exports.default = util.createRule({
type: 'layout',
docs: {
description: 'Require or disallow an empty line between class members',
category: 'Stylistic Issues',
recommended: false,
extendsBaseRule: true,
},
fixable: 'whitespace',
hasSuggestions: baseRule.meta.hasSuggestions,
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.',
},
messages: baseRule.meta.messages,
},
defaultOptions: [
'always',
@ -58,13 +56,13 @@ exports.default = util.createRule({
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';
create(context, [firstOption, secondOption]) {
const rules = baseRule.create(context);
const exceptAfterOverload = (secondOption === null || secondOption === void 0 ? void 0 : secondOption.exceptAfterOverload) && firstOption === 'always';
function isOverload(node) {
return (node.type === experimental_utils_1.AST_NODE_TYPES.MethodDefinition &&
node.value.type === experimental_utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression);
return ((node.type === utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition ||
node.type === utils_1.AST_NODE_TYPES.MethodDefinition) &&
node.value.type === utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression);
}
return {
ClassBody(node) {

View file

@ -1 +1 @@
{"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,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,gBAAgB;gBAC7C,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"}
{"version":3,"file":"lines-between-class-members.js","sourceRoot":"","sources":["../../src/rules/lines-between-class-members.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAA0D;AAE1D,8CAAgC;AAChC,iEAA8D;AAE9D,MAAM,QAAQ,GAAG,IAAA,qCAAiB,EAAC,6BAA6B,CAAC,CAAC;AAKlE,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,mBACtB,QAAQ,CAAC,IAAI,CAAC,MAAM,GACzB;IACE,CAAC,EAAE;QACD,m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C,IAAI,CAAC;gBAEd,KAAK,CAAC,SAAS,iCAAM,IAAI,KAAE,IAAI,IAAG,CAAC;YACrC,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
const definition = {
type: 'object',
@ -45,13 +49,24 @@ const definition = {
additionalProperties: false,
};
const isLastTokenEndOfLine = (token, line) => {
const positionInLine = line.indexOf(token);
const positionInLine = token.loc.start.column;
return positionInLine === line.length - 1;
};
const makeFixFunction = ({ optsNone, optsSemi, lastToken, missingDelimiter, lastTokenLine, isSingleLine, }) => {
const isCommentsEndOfLine = (token, comments, line) => {
if (!comments) {
return false;
}
if (comments.loc.end.line > token.loc.end.line) {
return true;
}
const positionInLine = comments.loc.end.column;
return positionInLine === line.length;
};
const makeFixFunction = ({ optsNone, optsSemi, lastToken, commentsAfterLastToken, missingDelimiter, lastTokenLine, isSingleLine, }) => {
// if removing is the action but last token is not the end of the line
if (optsNone &&
!isLastTokenEndOfLine(lastToken.value, lastTokenLine) &&
!isLastTokenEndOfLine(lastToken, lastTokenLine) &&
!isCommentsEndOfLine(lastToken, commentsAfterLastToken, lastTokenLine) &&
!isSingleLine) {
return null;
}
@ -72,13 +87,12 @@ const makeFixFunction = ({ optsNone, optsSemi, lastToken, missingDelimiter, last
exports.default = util.createRule({
name: 'member-delimiter-style',
meta: {
type: 'suggestion',
type: 'layout',
docs: {
description: 'Require a specific member delimiter style for interfaces and type literals',
category: 'Stylistic Issues',
recommended: false,
},
fixable: 'code',
fixable: 'whitespace',
messages: {
unexpectedComma: 'Unexpected separator (,).',
unexpectedSemi: 'Unexpected separator (;).',
@ -152,6 +166,9 @@ exports.default = util.createRule({
if (!lastToken) {
return;
}
const commentsAfterLastToken = sourceCode
.getCommentsAfter(lastToken)
.pop();
const sourceCodeLines = sourceCode.getLines();
const lastTokenLine = sourceCodeLines[(lastToken === null || lastToken === void 0 ? void 0 : lastToken.loc.start.line) - 1];
const optsSemi = getOption('semi');
@ -203,6 +220,7 @@ exports.default = util.createRule({
optsNone,
optsSemi,
lastToken,
commentsAfterLastToken,
missingDelimiter,
lastTokenLine,
isSingleLine: opts.type === 'single-line',
@ -215,7 +233,7 @@ exports.default = util.createRule({
* @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;
const members = node.type === 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 &&
@ -225,7 +243,7 @@ exports.default = util.createRule({
isSingleLine = true;
}
}
const typeOpts = node.type === experimental_utils_1.AST_NODE_TYPES.TSInterfaceBody
const typeOpts = node.type === utils_1.AST_NODE_TYPES.TSInterfaceBody
? interfaceOptions
: typeLiteralOptions;
const opts = isSingleLine

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -18,9 +22,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
__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 });
exports.defaultOrder = void 0;
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const natural_compare_lite_1 = __importDefault(require("natural-compare-lite"));
const util = __importStar(require("../util"));
const neverConfig = {
type: 'string',
@ -29,7 +37,17 @@ const neverConfig = {
const arrayConfig = (memberTypes) => ({
type: 'array',
items: {
enum: memberTypes,
oneOf: [
{
enum: memberTypes,
},
{
type: 'array',
items: {
enum: memberTypes,
},
},
],
},
});
const objectConfig = (memberTypes) => ({
@ -40,7 +58,17 @@ const objectConfig = (memberTypes) => ({
},
order: {
type: 'string',
enum: ['alphabetically', 'as-written'],
enum: [
'alphabetically',
'alphabetically-case-insensitive',
'as-written',
'natural',
'natural-case-insensitive',
],
},
optionalityOrder: {
type: 'string',
enum: ['optional-first', 'required-first'],
},
},
additionalProperties: false,
@ -53,88 +81,152 @@ exports.defaultOrder = [
'public-static-field',
'protected-static-field',
'private-static-field',
'#private-static-field',
'public-decorated-field',
'protected-decorated-field',
'private-decorated-field',
'public-instance-field',
'protected-instance-field',
'private-instance-field',
'#private-instance-field',
'public-abstract-field',
'protected-abstract-field',
'private-abstract-field',
'public-field',
'protected-field',
'private-field',
'#private-field',
'static-field',
'instance-field',
'abstract-field',
'decorated-field',
'field',
// Static initialization
'static-initialization',
// Constructors
'public-constructor',
'protected-constructor',
'private-constructor',
'constructor',
// Getters
'public-static-get',
'protected-static-get',
'private-static-get',
'#private-static-get',
'public-decorated-get',
'protected-decorated-get',
'private-decorated-get',
'public-instance-get',
'protected-instance-get',
'private-instance-get',
'#private-instance-get',
'public-abstract-get',
'protected-abstract-get',
'public-get',
'protected-get',
'private-get',
'#private-get',
'static-get',
'instance-get',
'abstract-get',
'decorated-get',
'get',
// Setters
'public-static-set',
'protected-static-set',
'private-static-set',
'#private-static-set',
'public-decorated-set',
'protected-decorated-set',
'private-decorated-set',
'public-instance-set',
'protected-instance-set',
'private-instance-set',
'#private-instance-set',
'public-abstract-set',
'protected-abstract-set',
'public-set',
'protected-set',
'private-set',
'#private-set',
'static-set',
'instance-set',
'abstract-set',
'decorated-set',
'set',
// Methods
'public-static-method',
'protected-static-method',
'private-static-method',
'#private-static-method',
'public-decorated-method',
'protected-decorated-method',
'private-decorated-method',
'public-instance-method',
'protected-instance-method',
'private-instance-method',
'#private-instance-method',
'public-abstract-method',
'protected-abstract-method',
'private-abstract-method',
'public-method',
'protected-method',
'private-method',
'#private-method',
'static-method',
'instance-method',
'abstract-method',
'decorated-method',
'method',
];
const allMemberTypes = [
const allMemberTypes = Array.from([
'signature',
'field',
'method',
'call-signature',
'constructor',
'get',
'set',
'static-initialization',
].reduce((all, type) => {
all.push(type);
['public', 'protected', 'private'].forEach(accessibility => {
if (type !== 'signature') {
all.push(`${accessibility}-${type}`); // e.g. `public-field`
all.add(type);
['public', 'protected', 'private', '#private'].forEach(accessibility => {
if (type !== 'signature' &&
type !== 'static-initialization' &&
type !== 'call-signature' &&
!(type === 'constructor' && accessibility === '#private')) {
all.add(`${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);
}
// Only class instance fields, methods, get and set can have decorators attached to them
if (accessibility !== '#private' &&
(type === 'field' ||
type === 'method' ||
type === 'get' ||
type === 'set')) {
all.add(`${accessibility}-decorated-${type}`);
all.add(`decorated-${type}`);
}
if (type !== 'constructor' && type !== 'signature') {
if (type !== 'constructor' &&
type !== 'signature' &&
type !== 'call-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}`);
});
if (accessibility === '#private' || accessibility === 'private') {
['static', 'instance'].forEach(scope => {
all.add(`${scope}-${type}`);
all.add(`${accessibility}-${scope}-${type}`);
});
}
else {
['static', 'instance', 'abstract'].forEach(scope => {
all.add(`${scope}-${type}`);
all.add(`${accessibility}-${scope}-${type}`);
});
}
}
});
return all;
}, []);
}, new Set()));
const functionExpressions = [
experimental_utils_1.AST_NODE_TYPES.FunctionExpression,
experimental_utils_1.AST_NODE_TYPES.ArrowFunctionExpression,
utils_1.AST_NODE_TYPES.FunctionExpression,
utils_1.AST_NODE_TYPES.ArrowFunctionExpression,
];
/**
* Gets the node type.
@ -143,28 +235,44 @@ const functionExpressions = [
*/
function getNodeType(node) {
switch (node.type) {
case experimental_utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition:
case experimental_utils_1.AST_NODE_TYPES.MethodDefinition:
case utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition:
case utils_1.AST_NODE_TYPES.MethodDefinition:
return node.kind;
case experimental_utils_1.AST_NODE_TYPES.TSMethodSignature:
case utils_1.AST_NODE_TYPES.TSMethodSignature:
return 'method';
case experimental_utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
case utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
return 'call-signature';
case experimental_utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
case utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
return 'constructor';
case experimental_utils_1.AST_NODE_TYPES.TSAbstractClassProperty:
case experimental_utils_1.AST_NODE_TYPES.ClassProperty:
case utils_1.AST_NODE_TYPES.TSAbstractPropertyDefinition:
return 'field';
case utils_1.AST_NODE_TYPES.PropertyDefinition:
return node.value && functionExpressions.includes(node.value.type)
? 'method'
: 'field';
case experimental_utils_1.AST_NODE_TYPES.TSPropertySignature:
case utils_1.AST_NODE_TYPES.TSPropertySignature:
return 'field';
case experimental_utils_1.AST_NODE_TYPES.TSIndexSignature:
case utils_1.AST_NODE_TYPES.TSIndexSignature:
return 'signature';
case utils_1.AST_NODE_TYPES.StaticBlock:
return 'static-initialization';
default:
return null;
}
}
/**
* Gets the raw string value of a member's name
*/
function getMemberRawName(member, sourceCode) {
const { name, type } = util.getNameFromMember(member, sourceCode);
if (type === util.MemberNameType.Quoted) {
return name.slice(1, -1);
}
if (type === util.MemberNameType.Private) {
return name.slice(1);
}
return name;
}
/**
* Gets the member name based on the member type.
*
@ -173,26 +281,47 @@ function getNodeType(node) {
*/
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:
case utils_1.AST_NODE_TYPES.TSPropertySignature:
case utils_1.AST_NODE_TYPES.TSMethodSignature:
case utils_1.AST_NODE_TYPES.TSAbstractPropertyDefinition:
case utils_1.AST_NODE_TYPES.PropertyDefinition:
return getMemberRawName(node, sourceCode);
case utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition:
case utils_1.AST_NODE_TYPES.MethodDefinition:
return node.kind === 'constructor'
? 'constructor'
: util.getNameFromMember(node, sourceCode);
case experimental_utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
: getMemberRawName(node, sourceCode);
case utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration:
return 'new';
case experimental_utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
case utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
return 'call';
case experimental_utils_1.AST_NODE_TYPES.TSIndexSignature:
case utils_1.AST_NODE_TYPES.TSIndexSignature:
return util.getNameFromIndexSignature(node);
case utils_1.AST_NODE_TYPES.StaticBlock:
return 'static block';
default:
return null;
}
}
/**
* Returns true if the member is optional based on the member type.
*
* @param node the node to be evaluated.
*
* @returns Whether the member is optional, or false if it cannot be optional at all.
*/
function isMemberOptional(node) {
switch (node.type) {
case utils_1.AST_NODE_TYPES.TSPropertySignature:
case utils_1.AST_NODE_TYPES.TSMethodSignature:
case utils_1.AST_NODE_TYPES.TSAbstractPropertyDefinition:
case utils_1.AST_NODE_TYPES.PropertyDefinition:
case utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition:
case utils_1.AST_NODE_TYPES.MethodDefinition:
return !!node.optional;
}
return false;
}
/**
* Gets the calculated rank using the provided method definition.
* The algorithm is as follows:
@ -209,10 +338,23 @@ 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());
const memberGroup = stack.shift();
rank = orderConfig.findIndex(memberType => Array.isArray(memberType)
? memberType.includes(memberGroup)
: memberType === memberGroup);
}
return rank;
}
function getAccessibility(node) {
var _a;
if ('accessibility' in node && node.accessibility) {
return node.accessibility;
}
if ('key' in node && ((_a = node.key) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.PrivateIdentifier) {
return '#private';
}
return 'public';
}
/**
* Gets the rank of the node given the order.
* @param node the node to be evaluated.
@ -225,36 +367,42 @@ function getRank(node, orderConfig, supportsModifiers) {
// 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 abstract = node.type === utils_1.AST_NODE_TYPES.TSAbstractPropertyDefinition ||
node.type === 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 accessibility = getAccessibility(node);
// Collect all existing member groups that apply to this node...
// (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')) {
if (decorated &&
(type === 'field' ||
type === 'method' ||
type === 'get' ||
type === 'set')) {
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}`);
if (type !== 'signature' && type !== 'static-initialization') {
if (type !== 'constructor') {
// Constructors have no scope
memberGroups.push(`${accessibility}-${scope}-${type}`);
memberGroups.push(`${scope}-${type}`);
}
memberGroups.push(`${accessibility}-${type}`);
}
memberGroups.push(`${accessibility}-${type}`);
}
memberGroups.push(type);
// ...then get the rank order for those member groups based on the node
return getRankOrder(memberGroups, orderConfig);
}
/**
* Gets the lowest possible rank higher than target.
* Gets the lowest possible rank(s) higher than target.
* e.g. given the following order:
* ...
* public-static-method
@ -267,10 +415,11 @@ function getRank(node, orderConfig, supportsModifiers) {
* 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.
* If a lowest possible rank is a member group, a comma separated list of ranks is returned.
* @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 (-).
* @returns the name(s) of the lowest possible rank without dashes (-).
*/
function getLowestRank(ranks, target, order) {
let lowest = ranks[ranks.length - 1];
@ -279,7 +428,9 @@ function getLowestRank(ranks, target, order) {
lowest = Math.min(lowest, rank);
}
});
return order[lowest].replace(/-/g, ' ');
const lowestRank = order[lowest];
const lowestRanks = Array.isArray(lowestRank) ? lowestRank : [lowestRank];
return lowestRanks.map(rank => rank.replace(/-/g, ' ')).join(', ');
}
exports.default = util.createRule({
name: 'member-ordering',
@ -287,12 +438,12 @@ exports.default = util.createRule({
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}}".',
incorrectOrder: 'Member {{member}} should be declared before member {{beforeMember}}.',
incorrectGroupOrder: 'Member {{name}} should be declared before all {{rank}} definitions.',
incorrectRequiredMembersOrder: `Member {{member}} should be declared after all {{optionalOrRequired}} members.`,
},
schema: [
{
@ -393,10 +544,11 @@ exports.default = util.createRule({
* Checks if the members are alphabetically sorted.
*
* @param members Members to be validated.
* @param caseSensitive indicates if the alpha ordering is case sensitive or not.
*
* @return True if all members are correctly sorted.
*/
function checkAlphaSort(members) {
function checkAlphaSort(members, order) {
let previousName = '';
let isCorrectlySorted = true;
// Find first member which isn't correctly sorted
@ -404,7 +556,7 @@ exports.default = util.createRule({
const name = getMemberName(member, context.getSourceCode());
// Note: Not all members have names
if (name) {
if (name < previousName) {
if (naturalOutOfOrder(name, previousName, order)) {
context.report({
node: member,
messageId: 'incorrectOrder',
@ -420,6 +572,54 @@ exports.default = util.createRule({
});
return isCorrectlySorted;
}
function naturalOutOfOrder(name, previousName, order) {
switch (order) {
case 'alphabetically':
return name < previousName;
case 'alphabetically-case-insensitive':
return name.toLowerCase() < previousName.toLowerCase();
case 'natural':
return (0, natural_compare_lite_1.default)(name, previousName) !== 1;
case 'natural-case-insensitive':
return ((0, natural_compare_lite_1.default)(name.toLowerCase(), previousName.toLowerCase()) !== 1);
}
}
/**
* Checks if the order of optional and required members is correct based
* on the given 'required' parameter.
*
* @param members Members to be validated.
* @param optionalityOrder Where to place optional members, if not intermixed.
*
* @return True if all required and optional members are correctly sorted.
*/
function checkRequiredOrder(members, optionalityOrder) {
const switchIndex = members.findIndex((member, i) => i && isMemberOptional(member) !== isMemberOptional(members[i - 1]));
const report = (member) => context.report({
messageId: 'incorrectRequiredMembersOrder',
loc: member.loc,
data: {
member: getMemberName(member, context.getSourceCode()),
optionalOrRequired: optionalityOrder === 'required-first' ? 'required' : 'optional',
},
});
// if the optionality of the first item is correct (based on optionalityOrder)
// then the first 0 inclusive to switchIndex exclusive members all
// have the correct optionality
if (isMemberOptional(members[0]) !==
(optionalityOrder === 'optional-first')) {
report(members[0]);
return false;
}
for (let i = switchIndex + 1; i < members.length; i++) {
if (isMemberOptional(members[i]) !==
isMemberOptional(members[switchIndex])) {
report(members[switchIndex]);
return false;
}
}
return true;
}
/**
* Validates if all members are correctly sorted.
*
@ -432,27 +632,46 @@ exports.default = util.createRule({
return;
}
// Standardize config
let order = null;
let order;
let memberTypes;
let optionalityOrder;
// returns true if everything is good and false if an error was reported
const checkOrder = (memberSet) => {
const hasAlphaSort = !!(order && order !== 'as-written');
// Check order
if (Array.isArray(memberTypes)) {
const grouped = checkGroupSort(memberSet, memberTypes, supportsModifiers);
if (grouped === null) {
return false;
}
if (hasAlphaSort) {
return !grouped.some(groupMember => !checkAlphaSort(groupMember, order));
}
}
else if (hasAlphaSort) {
return checkAlphaSort(memberSet, order);
}
return true;
};
if (Array.isArray(orderConfig)) {
memberTypes = orderConfig;
}
else {
order = orderConfig.order;
memberTypes = orderConfig.memberTypes;
optionalityOrder = orderConfig.optionalityOrder;
}
// Check order
if (Array.isArray(memberTypes)) {
const grouped = checkGroupSort(members, memberTypes, supportsModifiers);
if (grouped === null) {
if (!optionalityOrder) {
checkOrder(members);
return;
}
const switchIndex = members.findIndex((member, i) => i && isMemberOptional(member) !== isMemberOptional(members[i - 1]));
if (switchIndex !== -1) {
if (!checkRequiredOrder(members, optionalityOrder)) {
return;
}
if (order === 'alphabetically') {
grouped.some(groupMember => !checkAlphaSort(groupMember));
}
}
else if (order === 'alphabetically') {
checkAlphaSort(members);
checkOrder(members.slice(0, switchIndex));
checkOrder(members.slice(switchIndex));
}
}
return {

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,15 +23,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/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',
description: 'Enforce using a particular method signature syntax',
recommended: false,
},
fixable: 'code',
@ -89,26 +92,26 @@ exports.default = util.createRule({
if (!node.parent) {
return false;
}
if (node.parent.type === experimental_utils_1.AST_NODE_TYPES.TSModuleDeclaration) {
if (node.parent.type === utils_1.AST_NODE_TYPES.TSModuleDeclaration) {
return true;
}
if (node.parent.type === experimental_utils_1.AST_NODE_TYPES.Program) {
if (node.parent.type === utils_1.AST_NODE_TYPES.Program) {
return false;
}
return isNodeParentModuleDeclaration(node.parent);
}
return {
return Object.assign(Object.assign({}, (mode === 'property' && {
TSMethodSignature(methodNode) {
if (mode === 'method') {
if (methodNode.kind !== 'method') {
return;
}
const parent = methodNode.parent;
const members = (parent === null || parent === void 0 ? void 0 : parent.type) === experimental_utils_1.AST_NODE_TYPES.TSInterfaceBody
const members = (parent === null || parent === void 0 ? void 0 : parent.type) === 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 === null || parent === void 0 ? void 0 : parent.type) === utils_1.AST_NODE_TYPES.TSTypeLiteral
? parent.members
: [];
const duplicatedKeyMethodNodes = members.filter((element) => element.type === experimental_utils_1.AST_NODE_TYPES.TSMethodSignature &&
const duplicatedKeyMethodNodes = members.filter((element) => element.type === utils_1.AST_NODE_TYPES.TSMethodSignature &&
element !== methodNode &&
getMethodKey(element) === getMethodKey(methodNode));
const isParentModule = isNodeParentModuleDeclaration(methodNode);
@ -173,13 +176,11 @@ exports.default = util.createRule({
});
}
},
})), (mode === 'method' && {
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') {
if ((typeNode === null || typeNode === void 0 ? void 0 : typeNode.type) !== utils_1.AST_NODE_TYPES.TSFunctionType) {
return;
}
context.report({
@ -194,7 +195,7 @@ exports.default = util.createRule({
},
});
},
};
}));
},
});
//# sourceMappingURL=method-signature-style.js.map

File diff suppressed because one or more lines are too long

View file

@ -79,6 +79,10 @@ var Modifiers;
Modifiers[Modifiers["unused"] = 1024] = "unused";
// properties that require quoting
Modifiers[Modifiers["requiresQuotes"] = 2048] = "requiresQuotes";
// class members that are overridden
Modifiers[Modifiers["override"] = 4096] = "override";
// class methods, object function properties, or functions that are async via the `async` keyword
Modifiers[Modifiers["async"] = 8192] = "async";
// make sure TypeModifiers starts at Modifiers + 1 or else sorting won't work
})(Modifiers || (Modifiers = {}));
exports.Modifiers = Modifiers;

View file

@ -1 +1 @@
{"version":3,"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K,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"}
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../../../src/rules/naming-convention-utils/enums.ts"],"names":[],"mappings":";;;AAAA,IAAK,iBAOJ;AAPD,WAAK,iBAAiB;IACpB,mEAAa,CAAA;IACb,+EAAe,CAAA;IACf,qEAAU,CAAA;IACV,iFAAgB,CAAA;IAChB,qEAAU,CAAA;IACV,qEAAU,CAAA;AACZ,CAAC,EAPI,iBAAiB,KAAjB,iBAAiB,QAOrB;AAyHC,8CAAiB;AAtHnB,IAAK,iBASJ;AATD,WAAK,iBAAiB;IACpB,6DAAU,CAAA;IACV,2DAAK,CAAA;IACL,+DAAO,CAAA;IAEP,iEAAiE;IACjE,2EAAa,CAAA;IACb,uEAAW,CAAA;IACX,uFAAmB,CAAA;AACrB,CAAC,EATI,iBAAiB,KAAjB,iBAAiB,QASrB;AAmHC,8CAAiB;AAhHnB,IAAK,SAuBJ;AAvBD,WAAK,SA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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"}

View file

@ -6,7 +6,7 @@ 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:
The license for the code can be viewed here:
https://github.com/ajafff/tslint-consistent-codestyle/blob/ab156cc8881bcc401236d999f4ce034b59039e81/LICENSE
*/
/*

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -73,7 +77,7 @@ function normalizeOption(option) {
const selectors = Array.isArray(option.selector)
? option.selector
: [option.selector];
return selectors.map(selector => (Object.assign({ selector: shared_1.isMetaSelector(selector)
return selectors.map(selector => (Object.assign({ selector: (0, shared_1.isMetaSelector)(selector)
? enums_1.MetaSelectors[selector]
: enums_1.Selectors[selector] }, normalizedOption)));
}
@ -82,7 +86,7 @@ function parseOptions(context) {
.map(opt => normalizeOption(opt))
.reduce((acc, val) => acc.concat(val), []);
return util.getEnumNames(enums_1.Selectors).reduce((acc, k) => {
acc[k] = validator_1.createValidator(k, context, normalizedOptions);
acc[k] = (0, validator_1.createValidator)(k, context, normalizedOptions);
return acc;
}, {});
}

View file

@ -1 +1 @@
{"version":3,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AAC,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;SAChC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,OAAO,IAAI,CAAC,YAAY,CAAC,iBAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QACpD,GAAG,CAAC,CAAC,CAAC,GAAG,IAAA,2BAAe,EAAC,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;QACxD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAmB,CAAC,CAAC;AAC1B,CAAC;AAEQ,oCAAY"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -20,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SCHEMA = void 0;
const enums_1 = require("./enums");
const util = __importStar(require("../../util"));
const enums_1 = require("./enums");
const UNDERSCORE_SCHEMA = {
type: 'string',
enum: util.getEnumNames(enums_1.UnderscoreOptions),
@ -163,15 +167,21 @@ const SCHEMA = {
oneOf: [
selectorsSchema(),
...selectorSchema('default', false, util.getEnumNames(enums_1.Modifiers)),
...selectorSchema('variableLike', false, ['unused']),
...selectorSchema('variableLike', false, ['unused', 'async']),
...selectorSchema('variable', true, [
'const',
'destructured',
'exported',
'global',
'unused',
'async',
]),
...selectorSchema('function', false, [
'exported',
'global',
'unused',
'async',
]),
...selectorSchema('function', false, ['exported', 'global', 'unused']),
...selectorSchema('parameter', true, ['destructured', 'unused']),
...selectorSchema('memberLike', false, [
'abstract',
@ -181,6 +191,8 @@ const SCHEMA = {
'readonly',
'requiresQuotes',
'static',
'override',
'async',
]),
...selectorSchema('classProperty', true, [
'abstract',
@ -190,6 +202,7 @@ const SCHEMA = {
'readonly',
'requiresQuotes',
'static',
'override',
]),
...selectorSchema('objectLiteralProperty', true, [
'public',
@ -214,6 +227,8 @@ const SCHEMA = {
'readonly',
'requiresQuotes',
'static',
'override',
'async',
]),
...selectorSchema('classMethod', false, [
'abstract',
@ -222,10 +237,13 @@ const SCHEMA = {
'public',
'requiresQuotes',
'static',
'override',
'async',
]),
...selectorSchema('objectLiteralMethod', false, [
'public',
'requiresQuotes',
'async',
]),
...selectorSchema('typeMethod', false, ['public', 'requiresQuotes']),
...selectorSchema('method', false, [
@ -235,6 +253,8 @@ const SCHEMA = {
'public',
'requiresQuotes',
'static',
'override',
'async',
]),
...selectorSchema('accessor', true, [
'abstract',
@ -243,6 +263,7 @@ const SCHEMA = {
'public',
'requiresQuotes',
'static',
'override',
]),
...selectorSchema('enumMember', false, ['requiresQuotes']),
...selectorSchema('typeLike', false, ['abstract', 'exported', 'unused']),

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
{"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"}
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/rules/naming-convention-utils/shared.ts"],"names":[],"mappings":";;;AAMA,mCAAwC;AAExC,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"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -20,11 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createValidator = void 0;
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../../util"));
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];
@ -38,8 +42,8 @@ function createValidator(type, context, allConfigs) {
// sort descending - the type modifiers are "more important"
return b.modifierWeight - a.modifierWeight;
}
const aIsMeta = shared_1.isMetaSelector(a.selector);
const bIsMeta = shared_1.isMetaSelector(b.selector);
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;
@ -47,8 +51,8 @@ function createValidator(type, context, allConfigs) {
if (!aIsMeta && bIsMeta) {
return -1;
}
const aIsMethodOrProperty = shared_1.isMethodOrPropertySelector(a.selector);
const bIsMethodOrProperty = shared_1.isMethodOrPropertySelector(b.selector);
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;
@ -62,7 +66,10 @@ function createValidator(type, context, allConfigs) {
});
return (node, modifiers = new Set()) => {
var _a, _b, _c;
const originalName = node.type === experimental_utils_1.AST_NODE_TYPES.Identifier ? node.name : `${node.value}`;
const originalName = node.type === utils_1.AST_NODE_TYPES.Identifier ||
node.type === utils_1.AST_NODE_TYPES.PrivateIdentifier
? 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) {
@ -103,7 +110,7 @@ function createValidator(type, context, allConfigs) {
// fail
return;
}
if (!validatePredefinedFormat(config, name, node, originalName)) {
if (!validatePredefinedFormat(config, name, node, originalName, modifiers)) {
// fail
return;
}
@ -115,7 +122,7 @@ function createValidator(type, context, allConfigs) {
function formatReportData({ affixes, formats, originalName, processedName, position, custom, count, }) {
var _a;
return {
type: shared_1.selectorTypeToMessageString(type),
type: (0, shared_1.selectorTypeToMessageString)(type),
name: originalName,
processedName,
position,
@ -281,15 +288,17 @@ function createValidator(type, context, allConfigs) {
/**
* @returns true if the name is valid according to the `format` option, false otherwise
*/
function validatePredefinedFormat(config, name, node, originalName) {
function validatePredefinedFormat(config, name, node, originalName, modifiers) {
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;
if (!modifiers.has(enums_1.Modifiers.requiresQuotes)) {
for (const format of formats) {
const checker = format_1.PredefinedFormatToCheckFunction[format];
if (checker(name)) {
return true;
}
}
}
context.report({

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (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 utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
const naming_convention_utils_1 = require("./naming-convention-utils");
// This essentially mirrors ESLint's `camelcase` rule
@ -47,8 +51,7 @@ exports.default = util.createRule({
name: 'naming-convention',
meta: {
docs: {
category: 'Variables',
description: 'Enforces naming conventions for everything across a codebase',
description: 'Enforce naming conventions for everything across a codebase',
recommended: false,
// technically only requires type checking if the user uses "type" modifiers
requiresTypeChecking: true,
@ -73,7 +76,7 @@ exports.default = util.createRule({
Object.setPrototypeOf({
options: defaultCamelCaseAllTheThingsConfig,
}, contextWithoutDefaults);
const validators = naming_convention_utils_1.parseOptions(context);
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)
@ -102,8 +105,11 @@ exports.default = util.createRule({
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) {
if ('override' in node && node.override) {
modifiers.add(naming_convention_utils_1.Modifiers.override);
}
if (node.type === utils_1.AST_NODE_TYPES.TSAbstractPropertyDefinition ||
node.type === utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition) {
modifiers.add(naming_convention_utils_1.Modifiers.abstract);
}
return modifiers;
@ -130,13 +136,27 @@ exports.default = util.createRule({
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) ||
(((_a = id.parent) === null || _a === void 0 ? void 0 : _a.type) === 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 &&
(((_b = id.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.AssignmentPattern &&
((_c = id.parent.parent) === null || _c === void 0 ? void 0 : _c.type) === utils_1.AST_NODE_TYPES.Property &&
id.parent.parent.shorthand));
}
function isAsyncMemberOrProperty(propertyOrMemberNode) {
return Boolean('value' in propertyOrMemberNode &&
propertyOrMemberNode.value &&
'async' in propertyOrMemberNode.value &&
propertyOrMemberNode.value.async);
}
function isAsyncVariableIdentifier(id) {
return Boolean(id.parent &&
(('async' in id.parent && id.parent.async) ||
('init' in id.parent &&
id.parent.init &&
'async' in id.parent.init &&
id.parent.init.async)));
}
return {
// #region variable
VariableDeclarator(node) {
@ -147,7 +167,7 @@ exports.default = util.createRule({
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 === null || parent === void 0 ? void 0 : parent.type) === utils_1.AST_NODE_TYPES.VariableDeclaration) {
if (parent.kind === 'const') {
baseModifiers.add(naming_convention_utils_1.Modifiers.const);
}
@ -166,6 +186,9 @@ exports.default = util.createRule({
if (isUnused(id.name)) {
modifiers.add(naming_convention_utils_1.Modifiers.unused);
}
if (isAsyncVariableIdentifier(id)) {
modifiers.add(naming_convention_utils_1.Modifiers.async);
}
validator(id, modifiers);
});
},
@ -188,6 +211,9 @@ exports.default = util.createRule({
if (isUnused(node.id.name, scope)) {
modifiers.add(naming_convention_utils_1.Modifiers.unused);
}
if (node.async) {
modifiers.add(naming_convention_utils_1.Modifiers.async);
}
validator(node.id, modifiers);
},
// #endregion function
@ -198,7 +224,7 @@ exports.default = util.createRule({
return;
}
node.params.forEach(param => {
if (param.type === experimental_utils_1.AST_NODE_TYPES.TSParameterProperty) {
if (param.type === utils_1.AST_NODE_TYPES.TSParameterProperty) {
return;
}
const identifiers = getIdentifiersFromPattern(param);
@ -233,7 +259,7 @@ exports.default = util.createRule({
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) {
':matches(PropertyDefinition, TSAbstractPropertyDefinition)[computed = false][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]'(node) {
const modifiers = getMemberModifiers(node);
handleMember(validators.classProperty, node, modifiers);
},
@ -252,15 +278,21 @@ exports.default = util.createRule({
'Property[computed = false][kind = "init"][value.type = "TSEmptyBodyFunctionExpression"]',
].join(', ')](node) {
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
if (isAsyncMemberOrProperty(node)) {
modifiers.add(naming_convention_utils_1.Modifiers.async);
}
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(PropertyDefinition, TSAbstractPropertyDefinition)[computed = false][value.type = "ArrowFunctionExpression"]',
':matches(PropertyDefinition, TSAbstractPropertyDefinition)[computed = false][value.type = "FunctionExpression"]',
':matches(PropertyDefinition, TSAbstractPropertyDefinition)[computed = false][value.type = "TSEmptyBodyFunctionExpression"]',
':matches(MethodDefinition, TSAbstractMethodDefinition)[computed = false][kind = "method"]',
].join(', ')](node) {
const modifiers = getMemberModifiers(node);
if (isAsyncMemberOrProperty(node)) {
modifiers.add(naming_convention_utils_1.Modifiers.async);
}
handleMember(validators.classMethod, node, modifiers);
},
'TSMethodSignature[computed = false]'(node) {
@ -395,8 +427,8 @@ function getIdentifiersFromPattern(pattern) {
}
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) {
if (((_a = node === null || node === void 0 ? void 0 : node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration ||
((_b = node === null || node === void 0 ? void 0 : node.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
return true;
}
if (scope == null) {
@ -406,8 +438,8 @@ function isExported(node, name, scope) {
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) {
if ((refParent === null || refParent === void 0 ? void 0 : refParent.type) === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration ||
(refParent === null || refParent === void 0 ? void 0 : refParent.type) === utils_1.AST_NODE_TYPES.ExportSpecifier) {
return true;
}
}
@ -418,11 +450,14 @@ 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);
return (scope.type === utils_1.TSESLint.Scope.ScopeType.global ||
scope.type === 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}`;
const name = node.type === utils_1.AST_NODE_TYPES.Identifier ||
node.type === utils_1.AST_NODE_TYPES.PrivateIdentifier
? 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

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
exports.default = util.createRule({
name: 'no-array-constructor',
@ -27,7 +31,6 @@ exports.default = util.createRule({
type: 'suggestion',
docs: {
description: 'Disallow generic `Array` constructors',
category: 'Stylistic Issues',
recommended: 'error',
extendsBaseRule: true,
},
@ -45,7 +48,7 @@ exports.default = util.createRule({
*/
function check(node) {
if (node.arguments.length !== 1 &&
node.callee.type === experimental_utils_1.AST_NODE_TYPES.Identifier &&
node.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
node.callee.name === 'Array' &&
!node.typeParameters &&
!util.isOptionalCallExpression(node)) {

View file

@ -1 +1 @@
{"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,MA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C;QAED,OAAO;YACL,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,KAAK;SACrB,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const ts = __importStar(require("typescript"));
const util = __importStar(require("../util"));
var Usefulness;
@ -32,13 +36,12 @@ 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,
description: 'Require `.toString()` to only be called on objects which provide useful information when stringified',
recommended: 'strict',
requiresTypeChecking: true,
},
messages: {
baseToString: "'{{name}} {{certainty}} evaluate to '[object Object]' when stringified.",
baseToString: "'{{name}}' {{certainty}} evaluate to '[object Object]' when stringified.",
},
schema: [
{
@ -58,7 +61,7 @@ exports.default = util.createRule({
},
defaultOptions: [
{
ignoredTypeNames: ['RegExp'],
ignoredTypeNames: ['Error', 'RegExp', 'URL', 'URLSearchParams'],
},
],
create(context, [option]) {
@ -67,7 +70,7 @@ exports.default = util.createRule({
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) {
if (node.type === utils_1.AST_NODE_TYPES.Literal) {
return;
}
const certainty = collectToStringCertainty(type !== null && type !== void 0 ? type : typeChecker.getTypeAtLocation(parserServices.esTreeNodeToTSNodeMap.get(node)));
@ -138,7 +141,8 @@ exports.default = util.createRule({
if (util.getTypeName(typeChecker, leftType) === 'string') {
checkExpression(node.right, rightType);
}
else if (util.getTypeName(typeChecker, rightType) === 'string') {
else if (util.getTypeName(typeChecker, rightType) === 'string' &&
node.left.type !== utils_1.AST_NODE_TYPES.PrivateIdentifier) {
checkExpression(node.left, leftType);
}
},
@ -148,7 +152,7 @@ exports.default = util.createRule({
},
TemplateLiteral(node) {
if (node.parent &&
node.parent.type === experimental_utils_1.AST_NODE_TYPES.TaggedTemplateExpression) {
node.parent.type === utils_1.AST_NODE_TYPES.TaggedTemplateExpression) {
return;
}
for (const expression of node.expressions) {

View file

@ -1 +1 @@
{"version":3,"file":"no-base-to-string.js","sourceRoot":"","sources":["../../src/rules/no-base-to-string.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,8EAG+C;AAC/C,+CAAiC;AAEjC,8CAAgC;AAEhC,IAAK,UAIJ;AAJD,WAAK,UAAU;IACb,+CAAM,CAAA;IACN,4BAAc,CAAA;IACd,+BAAiB,CAAA;AACnB,CAAC,EAJI,UAAU,KAAV,UAAU,QAId;AASD,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EACT,yGAAyG;YAC3G,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,KAAK;YAClB,oBAAoB,EAAE,IAAI;SAC3B;QACD,QAAQ,EAAE;YACR,YAAY,EACV,yEAAyE;SAC5E;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,gBAAgB,EAAE;wBAChB,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE;4BACL,IAAI,EAAE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,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,mCAAc,CAAC,wBAAwB,EAC5D;oBACA,OAAO;iBACR;gBACD,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE;oBACzC,eAAe,CAAC,UAAU,CAAC,CAAC;iBAC7B;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
{"version":3,"file":"no-base-to-string.js","sourceRoot":"","sources":["../../src/rules/no-base-to-string.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAA0D;AAC1D,+CAAiC;AAEjC,8CAAgC;AAEhC,IAAK,UAIJ;AAJD,WAAK,UAAU;IACb,+CAAM,CAAA;IACN,4BAAc,CAAA;IACd,+BAAiB,CAAA;AACnB,CAAC,EAJI,UAAU,KAAV,UAAU,QAId;AASD,kBAAe,IAAI,CAAC,UAAU,CAAsB;IAClD,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EACT,sGAAsG;YACxG,WAAW,EAAE,QAAQ;YACrB,oBAAoB,EAAE,IAAI;SAC3B;QACD,QAAQ,EAAE;YACR,YAAY,EACV,0EAA0E;SAC7E;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,gBAAgB,EAAE;wBAChB,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE;4BACL,IAAI,EAAE,QAAQ;yBACf;qBACF;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,IAAI,EAAE,YAAY;KACnB;IACD,cAAc,EAAE;QACd;YACE,gBAAgB,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,iBAAiB,CAAC;SAChE;KACF;IACD,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC;;QACtB,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACvD,MAAM,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C"}

View file

@ -1,7 +1,11 @@
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
exports.default = util.createRule({
name: 'no-confusing-non-null-assertion',
@ -27,16 +31,16 @@ exports.default = util.createRule({
type: 'problem',
docs: {
description: 'Disallow non-null assertion in locations that may be confusing',
category: 'Stylistic Issues',
recommended: false,
recommended: 'strict',
},
fixable: 'code',
hasSuggestions: true,
messages: {
confusingEqual: 'Confusing combinations of non-null assertion and equal test like "a! == b", which looks very similar to not equal "a !== b"',
confusingAssign: 'Confusing combinations of non-null assertion and equal test like "a! = b", which looks very similar to not equal "a != b"',
notNeedInEqualTest: 'Unnecessary non-null assertion (!) in equal test',
notNeedInAssign: 'Unnecessary non-null assertion (!) in assignment left hand',
wrapUpLeft: 'Wrap up left hand to avoid putting non-null assertion "!" and "=" together',
confusingEqual: 'Confusing combinations of non-null assertion and equal test like "a! == b", which looks very similar to not equal "a !== b".',
confusingAssign: 'Confusing combinations of non-null assertion and equal test like "a! = b", which looks very similar to not equal "a != b".',
notNeedInEqualTest: 'Unnecessary non-null assertion (!) in equal test.',
notNeedInAssign: 'Unnecessary non-null assertion (!) in assignment left hand.',
wrapUpLeft: 'Wrap up left hand to avoid putting non-null assertion "!" and "=" together.',
},
schema: [],
},
@ -46,7 +50,7 @@ exports.default = util.createRule({
return {
'BinaryExpression, AssignmentExpression'(node) {
function isLeftHandPrimaryExpression(node) {
return node.type === experimental_utils_1.AST_NODE_TYPES.TSNonNullExpression;
return node.type === utils_1.AST_NODE_TYPES.TSNonNullExpression;
}
if (node.operator === '==' ||
node.operator === '===' ||
@ -54,7 +58,7 @@ exports.default = util.createRule({
const isAssign = node.operator === '=';
const leftHandFinalToken = sourceCode.getLastToken(node.left);
const tokenAfterLeft = sourceCode.getTokenAfter(node.left);
if ((leftHandFinalToken === null || leftHandFinalToken === void 0 ? void 0 : leftHandFinalToken.type) === experimental_utils_1.AST_TOKEN_TYPES.Punctuator &&
if ((leftHandFinalToken === null || leftHandFinalToken === void 0 ? void 0 : leftHandFinalToken.type) === utils_1.AST_TOKEN_TYPES.Punctuator &&
(leftHandFinalToken === null || leftHandFinalToken === void 0 ? void 0 : leftHandFinalToken.value) === '!' &&
(tokenAfterLeft === null || tokenAfterLeft === void 0 ? void 0 : tokenAfterLeft.value) !== ')') {
if (isLeftHandPrimaryExpression(node.left)) {

Some files were not shown because too many files have changed in this diff Show more