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
[array-type] False negative when using 'array-simple' #2323
Comments
When I just remove |
Also it seems that my case has no test defined ^^' Is it that special? |
I'm new to the project's code and don't know how to debug or test only this rule. I guess when using So I found out this:
typescript-eslint/packages/eslint-plugin/src/rules/array-type.ts Lines 207 to 212 in fd90e31
isReadonlyGeneric => true
isReadonlyArray => false
(isReadonlyGeneric && !isReadonly) => maybe true or false, depends on isReadonly
(isReadonlyArray && isReadonly) => always false
typescript-eslint/packages/eslint-plugin/src/rules/array-type.ts Lines 275 to 281 in fd90e31
readonlyOption => 'generic'
defaultOption => 'array-simple'
!(isArrayType || isReadonlyArrayType) => depends on isArrayType and isReadonlyArrayType
(readonlyOption === 'generic' && isReadonlyArrayType) => depends on isReadonlyArrayType
(defaultOption === 'generic' && !isReadonlyArrayType) => always false |
There's a vscode launch config which will allow you to run any given singular test in the vscode debugger. We don't do any magic on top of the commands like other repos do. From what I can see, it looks like you're correct - the logic for the option checks looks wrong. |
Oh my bad! Thanks for leading the way, now I can |
Ok, I have now created a matrix that lists all possible combinations and their expected results The first two columns represent the input values
Is the matrix correct or have I done something wrong? |
This line does always pass, also if input is something like |
Your matrix looks correct to me. I don't think anyone's ever gone so far as to enumerate the options like that. That's a great way to conceptualise it! It looks like the rule's logic is a bit wrong in how it handles things. Or at least it's not clear.
Feel free to gut and rewrite the rule however you see fit to fix this issue! |
I worked on this code and researched it for about 3 hours today There is also the problem that the error messages do not always fit well, e.g. if it should be readonly it is suggested to use But such changes are a minor change instead of a bug fix 😅 Ok, give me a couple of days and I'll try to tackle this 💪 But I think I will also alter tests and add more tests |
There's no requirement to only treat this as a bugfix. Thanks for putting so much care and effort into this! |
Aside whats currently made, what do you expect
Edit: And I dont even know what should happen if someone uses IMO 3, 4 and 5 are the only possible options 🤔 |
This rule only needs to be concerned with one array type at a time. I.e. for type T = number[][][];
// ^^^^^^^^ error 1 - wants to fix to Array<number>[][]
// ^^^^^^^^^^ error 2 - wants to fix to Array<number[]>[]
// ^^^^^^^^^^^^ error 3 - wants to fix to Array<number[][]> The important thing here is we should avoid using the Instead, for example the fixers should be: type T = number[][][];
// ^^^^^^^^ error 1 - wants to insert "Array<" before number, and replace "[]" with ">"
// ^^^^^^^^^^ error 2 - wants to insert "Array<" before number[], and replace "[]" with ">"
// ^^^^^^^^^^^^ error 3 - wants to insert "Array<" before number[][], and replace "[]" with ">" This makes it easier for ESLint to apply the fixers in order. |
So it is 5 - from inner to outer I think? Beside that, your example confuses me a bit ^^'
But damnd this is a hard one task to tackle XD |
sorry, yes - i meant The ESLint docs provide guidance on fixes: In a nutshell, ESLint does all of the heavy lifting of applying fixes to the file, resolving conflicts, etc. A simple example, imagine you have a fixer which adds quotes to object keys:
But what happens if the user prefers double quotes? Well then the So in our case, it's not necessary for the rule itself to care that a user might write
ESLint will handle the rest. In terms of order - outside in vs inside out - that's dependent on what the AST produces. In this case the AST is constructed outside in, so that's the order in which the rule will report errors. In regards to my second point about which fix API to use. This is so that each fix is as small as possible, to make it easier for ESLint to merge the fixes and apply it all at once. |
Just want to let you know that I may come later to this again |
@bradzacher I'm so sorry I hope someone else can benefit from my research an fix this anytime |
I going to work on this issue 🚀 |
Repro
Expected Result
Show warning and suggest to write
Array<ExpandedTextTemplateModel & IsSelectable>
insteadActual Result
No warning shown
Additional Info
This is working as expected and logs many (~116) warnings
So I think the problem/bug has something to do with how I setup my preferred option object 🤔
Versions
@typescript-eslint/eslint-plugin
3.7.0
@typescript-eslint/parser
3.7.0
TypeScript
3.9.7
ESLint
7.5.0
node
v14.1.0
npm
6.14.4
The text was updated successfully, but these errors were encountered: