-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: visitor-keysIssues related to @typescript-eslint/visitor-keysIssues related to @typescript-eslint/visitor-keys
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Relevant Package
visitor-keys
Playground Link
Repro Code
/*
* TSImportType
* Keys: ['argument', 'qualifier', 'typeArguments', 'options']
* Should be: ['argument', 'options', 'qualifier', 'typeArguments']
*/
type A = import('foo', { assert: { 'resolution-mode': 'import' } }).qualifier<T>;
// argument ^^^^^
// options ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// qualifier ^^^^^^^^^
// typeArguments ^^^
/*
* TSIndexedAccessType
* Keys: ['indexType', 'objectType']
* Should be: ['objectType', 'indexType']
*/
type B = Person["age" | "name"];
// ^^^^^^ objectType
// ^^^^^^^^^^^^^^^^ indexType
/*
* TSMethodSignature
* Keys: ['typeParameters', 'key', 'params', 'returnType']
* Should be: ['key', 'typeParameters', 'params', 'returnType']
*/
interface Foo { bar<T>(a: number): string; }
// key ^^^
// typeParameters ^^^
// params ^^^^^^^^^
// returnType ^^^^^^
/*
* TSPropertySignature
* Keys: ['typeAnnotation', 'key']
* Should be: ['key', 'typeAnnotation']
*/
interface Bar { qux: number }
// key ^^^
// typeAnnotation ^^^^^^
/*
* TSTypePredicate
* Keys: ['typeAnnotation', 'parameterName']
* Should be: ['parameterName', 'typeAnnotation']
*/
function isString(maybe: unknown): maybe is string { return typeof maybe === 'string'; }
// parameterName ^^^^^
// typeAnnotation ^^^^^^
ESLint Config
tsconfig
Expected Result
A comment in visitor-keys
package states that keys "should be sorted in the order that they appear in the source code".
typescript-eslint/packages/visitor-keys/src/visitor-keys.ts
Lines 111 to 132 in 0f5c59c
/* | |
********************************** IMPORTANT NOTE ******************************** | |
* * | |
* The key arrays should be sorted in the order in which you would want to visit * | |
* the child keys. * | |
* * | |
* DO NOT SORT THEM ALPHABETICALLY! * | |
* * | |
* They should be sorted in the order that they appear in the source code. * | |
* For example: * | |
* * | |
* class Foo extends Bar { prop: 1 } * | |
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ClassDeclaration * | |
* ^^^ id ^^^ superClass * | |
* ^^^^^^^^^^^ body * | |
* * | |
* It would be incorrect to provide the visitor keys ['body', 'id', 'superClass'] * | |
* because the body comes AFTER everything else in the source code. * | |
* Instead the correct ordering would be ['id', 'superClass', 'body']. * | |
* * | |
********************************************************************************** | |
*/ |
This is not the case for 5 types:
TSImportType
TSIndexedAccessType
TSMethodSignature
TSPropertySignature
TSTypePredicate
Please see above for examples.
Actual Result
Properties are visited not in source code order.
Additional Info
No response
Versions
package | version |
---|---|
@typescript-eslint/visitor-keys |
8.33.1 |
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: visitor-keysIssues related to @typescript-eslint/visitor-keysIssues related to @typescript-eslint/visitor-keys