Skip to content

Commit

Permalink
Merge branch 'main' into patch-50
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Feb 23, 2022
2 parents 2b78b3c + 0c63f26 commit 4dc75d3
Show file tree
Hide file tree
Showing 45 changed files with 1,222 additions and 581 deletions.
1 change: 0 additions & 1 deletion .github/workflows/update-sponsors.yml
@@ -1,7 +1,6 @@
name: Update Sponsors Data

on:
branch: main
schedule:
- cron: "0 0 * * *"

Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,35 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [5.12.1](https://github.com/typescript-eslint/typescript-eslint/compare/v5.12.0...v5.12.1) (2022-02-21)


### Bug Fixes

* **eslint-plugin:** [no-unnecessary-type-arguments] fix comparison of types ([#4555](https://github.com/typescript-eslint/typescript-eslint/issues/4555)) ([fc3936e](https://github.com/typescript-eslint/typescript-eslint/commit/fc3936e99712374a707ce9e0101bc641807b9ea6))





# [5.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.11.0...v5.12.0) (2022-02-14)


### Bug Fixes

* **eslint-plugin:** [init-declarations] fix nested namespace ([#4544](https://github.com/typescript-eslint/typescript-eslint/issues/4544)) ([fe910e6](https://github.com/typescript-eslint/typescript-eslint/commit/fe910e61ca4bb42be3be9acb8ddcec73206754c2))
* **eslint-plugin:** [no-unnecessary-type-arguments] Use Symbol to check if it's the same type ([#4543](https://github.com/typescript-eslint/typescript-eslint/issues/4543)) ([5b7d8df](https://github.com/typescript-eslint/typescript-eslint/commit/5b7d8df149be6554c863cdd5b73c0b0b0a7960db))
* support nested object deconstructuring with type annotation ([#4548](https://github.com/typescript-eslint/typescript-eslint/issues/4548)) ([4da9278](https://github.com/typescript-eslint/typescript-eslint/commit/4da9278c80706f420d4c15a71c11c7b11d935643))


### Features

* add checking property definition for allowNames option ([#4542](https://github.com/typescript-eslint/typescript-eslint/issues/4542)) ([e32bef6](https://github.com/typescript-eslint/typescript-eslint/commit/e32bef6f6b74228c95e54a5cba1cde53d5e40623))





# [5.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.10.2...v5.11.0) (2022-02-07)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
@@ -1,5 +1,5 @@
{
"version": "5.11.0",
"version": "5.12.1",
"npmClient": "yarn",
"useWorkspaces": true,
"stream": true
Expand Down
16 changes: 16 additions & 0 deletions packages/ast-spec/CHANGELOG.md
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [5.12.1](https://github.com/typescript-eslint/typescript-eslint/compare/v5.12.0...v5.12.1) (2022-02-21)

**Note:** Version bump only for package @typescript-eslint/ast-spec





# [5.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.11.0...v5.12.0) (2022-02-14)

**Note:** Version bump only for package @typescript-eslint/ast-spec





# [5.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.10.2...v5.11.0) (2022-02-07)

**Note:** Version bump only for package @typescript-eslint/ast-spec
Expand Down
2 changes: 1 addition & 1 deletion packages/ast-spec/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/ast-spec",
"version": "5.11.0",
"version": "5.12.1",
"description": "TypeScript-ESTree AST spec",
"private": true,
"keywords": [
Expand Down
16 changes: 16 additions & 0 deletions packages/eslint-plugin-internal/CHANGELOG.md
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [5.12.1](https://github.com/typescript-eslint/typescript-eslint/compare/v5.12.0...v5.12.1) (2022-02-21)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal





# [5.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.11.0...v5.12.0) (2022-02-14)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal





# [5.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.10.2...v5.11.0) (2022-02-07)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin-internal/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin-internal",
"version": "5.11.0",
"version": "5.12.1",
"private": true,
"main": "dist/index.js",
"scripts": {
Expand All @@ -14,8 +14,8 @@
},
"dependencies": {
"@types/prettier": "*",
"@typescript-eslint/scope-manager": "5.11.0",
"@typescript-eslint/utils": "5.11.0",
"@typescript-eslint/scope-manager": "5.12.1",
"@typescript-eslint/utils": "5.12.1",
"prettier": "*"
}
}
16 changes: 16 additions & 0 deletions packages/eslint-plugin-tslint/CHANGELOG.md
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [5.12.1](https://github.com/typescript-eslint/typescript-eslint/compare/v5.12.0...v5.12.1) (2022-02-21)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint





# [5.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.11.0...v5.12.0) (2022-02-14)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint





# [5.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.10.2...v5.11.0) (2022-02-07)

**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin-tslint/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin-tslint",
"version": "5.11.0",
"version": "5.12.1",
"main": "dist/index.js",
"typings": "src/index.ts",
"description": "TSLint wrapper plugin for ESLint",
Expand Down Expand Up @@ -38,7 +38,7 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/utils": "5.11.0",
"@typescript-eslint/utils": "5.12.1",
"lodash": "^4.17.21"
},
"peerDependencies": {
Expand All @@ -48,6 +48,6 @@
},
"devDependencies": {
"@types/lodash": "*",
"@typescript-eslint/parser": "5.11.0"
"@typescript-eslint/parser": "5.12.1"
}
}
29 changes: 29 additions & 0 deletions packages/eslint-plugin/CHANGELOG.md
Expand Up @@ -3,6 +3,35 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [5.12.1](https://github.com/typescript-eslint/typescript-eslint/compare/v5.12.0...v5.12.1) (2022-02-21)


### Bug Fixes

* **eslint-plugin:** [no-unnecessary-type-arguments] fix comparison of types ([#4555](https://github.com/typescript-eslint/typescript-eslint/issues/4555)) ([fc3936e](https://github.com/typescript-eslint/typescript-eslint/commit/fc3936e99712374a707ce9e0101bc641807b9ea6))





# [5.12.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.11.0...v5.12.0) (2022-02-14)


### Bug Fixes

* **eslint-plugin:** [init-declarations] fix nested namespace ([#4544](https://github.com/typescript-eslint/typescript-eslint/issues/4544)) ([fe910e6](https://github.com/typescript-eslint/typescript-eslint/commit/fe910e61ca4bb42be3be9acb8ddcec73206754c2))
* **eslint-plugin:** [no-unnecessary-type-arguments] Use Symbol to check if it's the same type ([#4543](https://github.com/typescript-eslint/typescript-eslint/issues/4543)) ([5b7d8df](https://github.com/typescript-eslint/typescript-eslint/commit/5b7d8df149be6554c863cdd5b73c0b0b0a7960db))
* support nested object deconstructuring with type annotation ([#4548](https://github.com/typescript-eslint/typescript-eslint/issues/4548)) ([4da9278](https://github.com/typescript-eslint/typescript-eslint/commit/4da9278c80706f420d4c15a71c11c7b11d935643))


### Features

* add checking property definition for allowNames option ([#4542](https://github.com/typescript-eslint/typescript-eslint/issues/4542)) ([e32bef6](https://github.com/typescript-eslint/typescript-eslint/commit/e32bef6f6b74228c95e54a5cba1cde53d5e40623))





# [5.11.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.10.2...v5.11.0) (2022-02-07)


Expand Down
28 changes: 12 additions & 16 deletions packages/eslint-plugin/docs/rules/member-ordering.md
Expand Up @@ -25,24 +25,20 @@ These options allow to specify how to group the members and sort their groups.
- Sort members within groups: Use `memberTypes` and `order`

```ts
type TypeOptions<T> =
| {
memberTypes: Array<T> | 'never',
order?: 'alphabetically' | 'alphabetically-case-insensitive' | 'as-written',
}
| {
order: 'alphabetically' | 'alphabetically-case-insensitive' | 'as-written',
};

{
default?: TypeOptions<MemberTypes>,
type SortedOrderConfig = {
memberTypes?: MemberType[] | 'never';
order: 'alphabetically' | 'alphabetically-case-insensitive' | 'as-written';
};

classes?: TypeOptions<MemberTypes>,
classExpressions?: TypeOptions<MemberTypes>,
type OrderConfig = MemberType[] | SortedOrderConfig | 'never';

interfaces?: TypeOptions<'signature' | 'field' | 'method' | 'constructor'>,
typeLiterals?: TypeOptions<'signature' | 'field' | 'method' | 'constructor'>,
}
type Options = {
default?: OrderConfig;
classes?: OrderConfig;
classExpressions?: OrderConfig;
interfaces?: OrderConfig;
typeLiterals?: OrderConfig;
};
```

See below for the possible definitions of `MemberType`.
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@typescript-eslint/eslint-plugin",
"version": "5.11.0",
"version": "5.12.1",
"description": "TypeScript plugin for ESLint",
"keywords": [
"eslint",
Expand Down Expand Up @@ -44,9 +44,9 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/scope-manager": "5.11.0",
"@typescript-eslint/type-utils": "5.11.0",
"@typescript-eslint/utils": "5.11.0",
"@typescript-eslint/scope-manager": "5.12.1",
"@typescript-eslint/type-utils": "5.12.1",
"@typescript-eslint/utils": "5.12.1",
"debug": "^4.3.2",
"functional-red-black-tree": "^1.0.1",
"ignore": "^5.1.8",
Expand Down
Expand Up @@ -232,7 +232,8 @@ export default util.createRule<Options, MessageIds>({
} else if (
node.type === AST_NODE_TYPES.MethodDefinition ||
node.type === AST_NODE_TYPES.TSAbstractMethodDefinition ||
(node.type === AST_NODE_TYPES.Property && node.method)
(node.type === AST_NODE_TYPES.Property && node.method) ||
node.type === AST_NODE_TYPES.PropertyDefinition
) {
if (
node.key.type === AST_NODE_TYPES.Literal &&
Expand Down
25 changes: 20 additions & 5 deletions packages/eslint-plugin/src/rules/init-declarations.ts
Expand Up @@ -35,17 +35,32 @@ export default createRule<Options, MessageIds>({
if (node.declare) {
return;
}
if (
node.parent?.type === AST_NODE_TYPES.TSModuleBlock &&
node.parent.parent?.type === AST_NODE_TYPES.TSModuleDeclaration &&
node.parent.parent?.declare
) {
if (isAncestorNamespaceDeclared(node)) {
return;
}
}

rules['VariableDeclaration:exit'](node);
},
};

function isAncestorNamespaceDeclared(
node: TSESTree.VariableDeclaration,
): boolean {
let ancestor = node.parent;

while (ancestor) {
if (
ancestor.type === AST_NODE_TYPES.TSModuleDeclaration &&
ancestor.declare
) {
return true;
}

ancestor = ancestor.parent;
}

return false;
}
},
});
47 changes: 41 additions & 6 deletions packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts
Expand Up @@ -37,7 +37,22 @@ export default util.createRule<[], MessageIds>({
create(context) {
const parserServices = util.getParserServices(context);
const checker = parserServices.program.getTypeChecker();
const sourceCode = context.getSourceCode();

function getTypeForComparison(type: ts.Type): {
type: ts.Type;
typeArguments: readonly ts.Type[];
} {
if (util.isTypeReferenceType(type)) {
return {
type: type.target,
typeArguments: util.getTypeArguments(type, checker),
};
}
return {
type,
typeArguments: [],
};
}

function checkTSArgsAndParameters(
esParameters: TSESTree.TSTypeParameterInstantiation,
Expand All @@ -47,13 +62,33 @@ export default util.createRule<[], MessageIds>({
const i = esParameters.params.length - 1;
const arg = esParameters.params[i];
const param = typeParameters[i];
if (!param?.default) {
return;
}

// TODO: would like checker.areTypesEquivalent. https://github.com/Microsoft/TypeScript/issues/13502
if (
!param?.default ||
param.default.getText() !== sourceCode.getText(arg)
) {
return;
const defaultType = checker.getTypeAtLocation(param.default);
const argTsNode = parserServices.esTreeNodeToTSNodeMap.get(arg);
const argType = checker.getTypeAtLocation(argTsNode);
// this check should handle some of the most simple cases of like strings, numbers, etc
if (defaultType !== argType) {
// For more complex types (like aliases to generic object types) - TS won't always create a
// global shared type object for the type - so we need to resort to manually comparing the
// reference type and the passed type arguments.
// Also - in case there are aliases - we need to resolve them before we do checks
const defaultTypeResolved = getTypeForComparison(defaultType);
const argTypeResolved = getTypeForComparison(argType);
if (
// ensure the resolved type AND all the parameters are the same
defaultTypeResolved.type !== argTypeResolved.type ||
defaultTypeResolved.typeArguments.length !==
argTypeResolved.typeArguments.length ||
defaultTypeResolved.typeArguments.some(
(t, i) => t !== argTypeResolved.typeArguments[i],
)
) {
return;
}
}

context.report({
Expand Down

0 comments on commit 4dc75d3

Please sign in to comment.