-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix: from-map rule is not working on TS files #50
Conversation
Codecov Report
@@ Coverage Diff @@
## master #50 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 111 116 +5
=========================================
+ Hits 111 116 +5
Continue to review full report at Codecov.
|
Hm, if the location info is indeed the issue I fear most rules won't behave properly with the TS parser. |
More importantly: thank you very much for the PR, I'll try to get to it within a week or so. |
We have big codebase using Typescript and only this rule is broken at the moment |
rules/from-map.js
Outdated
@@ -76,18 +76,18 @@ module.exports = { | |||
} | |||
// The original map callback from Array.from gets nested as a parameter to the callback from map. | |||
const lastCallback = getCallback(mapCallback, mapThisArgument, `${firstCallback}${restParameterString}`), | |||
restParameters = sourceCode.getText().slice(callback.end, parent.end); | |||
restParameters = sourceCode.getText().slice(callback.loc.end.column, parent.loc.end.column); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use callback.range[1]
instead of loc.end.column
. Same goes for all ranges. range[0]
is the start, range[1]
is the end. I believe the current approach only works because all unit tests only operate on the first line.
test/rules/from-map-ts.js
Outdated
} | ||
}); | ||
|
||
ruleTester.run('from-map', rule, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the actual rule tests should be shared with a helper module, so adding a test for the rule automatically checks for both parsers.
# Conflicts: # package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the fix. I can't promise that I'll get a release out today with these changes, but I've made a task to get it done this week.
Fixes #49