Skip to content

feat(eslint-plugin): [no-redundant-type-constituents] use assignability checking for redundancy checks #10744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e9c19a6
feat : work for object type in union types
mdm317 Jan 29, 2025
6207864
test : add test for object type in union types
mdm317 Jan 29, 2025
ac85ecb
test : add more case
mdm317 Jan 30, 2025
11cc737
feat : intersection type exists within a union type
mdm317 Feb 8, 2025
98ac978
feat : intersection case
mdm317 Feb 9, 2025
f4939b7
fix : using getText instead of typetostring
mdm317 Feb 12, 2025
a6c822a
refactor
mdm317 Feb 12, 2025
91b9cc5
fix : Emit an error for a union type only when the objects have the s…
gen-ip-1 Feb 28, 2025
81264c0
test: add test for union
gen-ip-1 Feb 28, 2025
686e5a0
feat : intersection case where objects have different keys
mdm317 Mar 3, 2025
6fa4e1b
reafactor
mdm317 Mar 4, 2025
567e062
fix : lint err
mdm317 Mar 4, 2025
a81a06e
fix: improve test coverage
mdm317 Mar 5, 2025
7a8d574
fix : lint err
mdm317 Mar 5, 2025
ba0dd2d
Merge branch 'main' into 7742-no-redundant-type-constituents
mdm317 Mar 5, 2025
70fbe0c
fix : infinite loop at no unused var
mdm317 Mar 5, 2025
e2ded16
refactor : use typeToString instead of getText
mdm317 Mar 30, 2025
2b9d3b0
refactor: integrate message IDs and error reports function
mdm317 Mar 30, 2025
6e69343
refactor: unifying the existing and new logic
mdm317 Apr 1, 2025
c11d7c9
feat : support mapped type and utility type
mdm317 Apr 1, 2025
b92d6fa
fix : lint error
mdm317 Apr 1, 2025
db67764
chore : change error message
mdm317 Apr 1, 2025
f2aa34c
feat: optional property in intersection
mdm317 Apr 5, 2025
35d90d0
refactor: remove redundunt type
mdm317 Apr 6, 2025
17bf29a
fix : optional property in intersection
mdm317 Apr 10, 2025
200f6f0
test : add interface case
mdm317 Apr 10, 2025
5c68891
refactor : hasTargetOnlyOptionalProps function
mdm317 Apr 10, 2025
23d8780
fix :nested object type in union
mdm317 Apr 10, 2025
d240c5f
fix : intersection where the objects have no properties.
mdm317 Apr 13, 2025
c01e485
Revert (Partial) "refactor: remove redundunt type"
mdm317 Apr 13, 2025
5c0de98
fix: infinite loop when compare property
mdm317 Apr 13, 2025
b97cb46
refactor : fix lint error
mdm317 Apr 13, 2025
04d71c1
refactor:redundant type detection in intersection types
mdm317 Apr 13, 2025
28c64b4
Merge branch 'main' into 7742-no-redundant-type-constituents
mdm317 Apr 13, 2025
f89b9a6
fix: check assignability when both objects have zero properties in in…
mdm317 Apr 14, 2025
3ef7b27
fix: error message when super types have the same name but are differ…
mdm317 Apr 14, 2025
f2eaf07
refactor: integrate error reporting functionality and refactor assign…
mdm317 Apr 14, 2025
1457723
Merge branch '7742-no-redundant-type-constituents' of https://github.…
mdm317 Apr 14, 2025
8a00f2b
Merge branch 'main' into 7742-no-redundant-type-constituents
mdm317 Apr 15, 2025
729a6fc
fix : snapshot error
mdm317 Apr 15, 2025
e240759
test : add test case
mdm317 Apr 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/ast-spec/src/declaration/ClassDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@ export interface ClassDeclarationWithOptionalName extends ClassDeclarationBase {
id: Identifier | null;
}

export type ClassDeclaration =
| ClassDeclarationWithName
| ClassDeclarationWithOptionalName;
export type ClassDeclaration = ClassDeclarationWithOptionalName;
4 changes: 2 additions & 2 deletions packages/ast-spec/src/declaration/FunctionDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ export interface FunctionDeclarationWithOptionalName
}

export type FunctionDeclaration =
| FunctionDeclarationWithName
| FunctionDeclarationWithOptionalName;
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
FunctionDeclarationWithName | FunctionDeclarationWithOptionalName;
Copy link
Contributor Author

@mdm317 mdm317 Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to Merging Interfaces, it should not be considered as redundant types.
So I added a lint disable comment for the line.

interface FunctionDeclarationWithName {
parent:
| TSESTree.BlockStatement
| TSESTree.ExportDefaultDeclaration
| TSESTree.ExportNamedDeclaration

4 changes: 1 addition & 3 deletions packages/ast-spec/src/special/ExportSpecifier/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ export interface ExportSpecifierWithStringOrLiteralLocal
local: Identifier | StringLiteral;
}

export type ExportSpecifier =
| ExportSpecifierWithIdentifierLocal
| ExportSpecifierWithStringOrLiteralLocal;
export type ExportSpecifier = ExportSpecifierWithStringOrLiteralLocal;
5 changes: 2 additions & 3 deletions packages/ast-spec/src/special/VariableDeclarator/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export interface VariableDeclaratorDefiniteAssignment

export type LetOrConstOrVarDeclarator =
| VariableDeclaratorDefiniteAssignment
| VariableDeclaratorMaybeInit
| VariableDeclaratorNoInit;
| VariableDeclaratorMaybeInit;

export interface UsingInNormalContextDeclarator extends VariableDeclaratorBase {
definite: false;
Expand All @@ -65,4 +64,4 @@ export type UsingDeclarator =
| UsingInForOfDeclarator
| UsingInNormalContextDeclarator;

export type VariableDeclarator = LetOrConstOrVarDeclarator | UsingDeclarator;
export type VariableDeclarator = LetOrConstOrVarDeclarator;
9 changes: 3 additions & 6 deletions packages/ast-spec/src/unions/ExportDeclaration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import type {
ClassDeclarationWithName,
ClassDeclarationWithOptionalName,
} from '../declaration/ClassDeclaration/spec';
import type { ClassDeclarationWithOptionalName } from '../declaration/ClassDeclaration/spec';
import type {
FunctionDeclarationWithName,
FunctionDeclarationWithOptionalName,
Expand All @@ -20,7 +17,6 @@ import type { Expression } from './Expression';
export type DefaultExportDeclarations =
| ClassDeclarationWithOptionalName
| Expression
| FunctionDeclarationWithName
| FunctionDeclarationWithOptionalName
| TSDeclareFunction
| TSEnumDeclaration
Expand All @@ -32,8 +28,8 @@ export type DefaultExportDeclarations =
// TODO(#1852) - the following are disallowed syntactically, but allowed by TS error recovery:
// ClassDeclarationWithOptionalName, FunctionDeclarationWithOptionalName
export type NamedExportDeclarations =
| ClassDeclarationWithName
| ClassDeclarationWithOptionalName
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
| FunctionDeclarationWithName
| FunctionDeclarationWithOptionalName
| TSDeclareFunction
Expand All @@ -47,4 +43,5 @@ export type NamedExportDeclarations =
// TODO - breaking change remove this in the next major
export type ExportDeclaration =
| DefaultExportDeclarations
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
| NamedExportDeclarations;
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default createRule({
* @returns the name and attribute of the member or null if it's a member not relevant to the rule.
*/
function getMemberMethod(
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
member: Member | MemberDeclaration,
Copy link
Contributor Author

@mdm317 mdm317 Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Member -> ProgramStatement -> Statement -> ClassDeclarationWithName
MemberDeclaration -> DefaultExportDeclarations -> ClassDeclarationWithOptionalName
ClassDeclarationWithName is overriden by ClassDeclarationWithOptionalName
I think modifying it too complex, so I added a lint disable code.

): Method | null {
switch (member.type) {
Expand Down
Loading
Loading