Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [prefer-readonly-parameter-types] handle class sharp private field and member without throwing error#4343
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
bradzacher merged 9 commits intotypescript-eslint:mainfromlonyele:fix/handle-private-identifierMar 1, 2022
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
43e34e4
fix: handle class sharp private field and member
lonyelecf9199f
fix: handle class sharp private field and member
lonyele915f1b3
Merge branch 'fix/handle-private-identifier' of https://github.com/lo…
lonyele9a8d4f9
feat: exempt private identifier from the rule
lonyele2754294
chore: shorten unnecessary logic
lonyele4ba1c7c
test: add unit test
lonyele33e4789
test: cover case that crashed before
lonyele0dc841a
test: add readonly test case
lonyele3d8acb4
Update packages/type-utils/src/propertyTypes.ts
JoshuaKGoldbergFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
20 changes: 19 additions & 1 deletionpackages/eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletionspackages/type-utils/src/isTypeReadonly.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
19 changes: 18 additions & 1 deletionpackages/type-utils/src/propertyTypes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -7,7 +7,7 @@ export function getTypeOfPropertyOfName( | ||
escapedName?: ts.__String, | ||
): ts.Type | undefined { | ||
// Most names are directly usable in the checker and aren't different from escaped names | ||
if (!escapedName || !isSymbol(escapedName)) { | ||
return checker.getTypeOfPropertyOfType(type, name); | ||
} | ||
@@ -34,3 +34,20 @@ export function getTypeOfPropertyOfType( | ||
property.getEscapedName(), | ||
); | ||
} | ||
// Symbolic names need to be specially handled because TS api is not sufficient for these cases. | ||
lonyele marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page.
JoshuaKGoldberg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// Source based on: | ||
// https://github.com/microsoft/TypeScript/blob/0043abe982aae0d35f8df59f9715be6ada758ff7/src/compiler/utilities.ts#L3388-L3402 | ||
function isSymbol(escapedName: string): boolean { | ||
return isKnownSymbol(escapedName) || isPrivateIdentifierSymbol(escapedName); | ||
} | ||
// case for escapedName: "__@foo@10", name: "__@foo@10" | ||
function isKnownSymbol(escapedName: string): boolean { | ||
return escapedName.startsWith('__@'); | ||
} | ||
// case for escapedName: "__#1@#foo", name: "#foo" | ||
function isPrivateIdentifierSymbol(escapedName: string): boolean { | ||
return escapedName.startsWith('__#'); | ||
} |
8 changes: 8 additions & 0 deletionspackages/type-utils/tests/isTypeReadonly.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.