Skip to content
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

Merged
merged 4 commits into from
Apr 5, 2020

Conversation

doniyor2109
Copy link
Contributor

Fixes #49

@codecov
Copy link

codecov bot commented Mar 27, 2020

Codecov Report

Merging #50 into master will not change coverage by %.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #50   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines          111       116    +5     
=========================================
+ Hits           111       116    +5     
Impacted Files Coverage Δ
rules/from-map.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 51e547a...09f515b. Read the comment docs.

@freaktechnik
Copy link
Owner

Hm, if the location info is indeed the issue I fear most rules won't behave properly with the TS parser.

@freaktechnik
Copy link
Owner

More importantly: thank you very much for the PR, I'll try to get to it within a week or so.

@doniyor2109
Copy link
Contributor Author

We have big codebase using Typescript and only this rule is broken at the moment

@@ -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);
Copy link
Owner

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.

}
});

ruleTester.run('from-map', rule, {
Copy link
Owner

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.

Copy link
Owner

@freaktechnik freaktechnik left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[from-map] Does not work with TS files
2 participants