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

Support comments in arrow functions when fixing #253

Merged
merged 2 commits into from
May 29, 2020

Conversation

edg2s
Copy link
Contributor

@edg2s edg2s commented May 27, 2020

Fixes #251

@@ -16,21 +15,31 @@ module.exports = {
create(context) {
const sourceCode = context.getSourceCode();

// eslint-disable-next-line max-statements
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how you feel about this rule, but I didn't see an obvious way to break up this method without passing multiple return values.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not a hard requirement. I don’t have a better approach in mind for now. As long as we have a good test coverage we can always refactor the code later 😉.

let functionKeyword = 'function';
const beforeArrowComment = sourceCode.text.slice(beforeArrowToken.range[1], arrow.range[0]).trim();
const afterArrowComment = sourceCode.text.slice(arrow.range[1], fn.body.range[0]).trim();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better readability I would suggest to extract the repeated pattern of sourceCode.text.slice(start, end).trim() to a function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is

sliceAndTrim( sourceCode.text, beforeArrowToken.range[1], arrow.range[0] );

much more concise or legible?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think sourceCode.text doesn’t need to be a parameter when we define the new function in the scope of the create function. Maybe a better name would be something like extractSourceTextByRange(). WDYT?

Copy link
Owner

@lo1tuma lo1tuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

@lo1tuma lo1tuma merged commit bb1bc45 into lo1tuma:master May 29, 2020
@edg2s edg2s deleted the arrow-comments branch May 29, 2020 19:13
@lo1tuma lo1tuma added the bug label May 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no-mocha-arrows drops comments in the function head when fixing
2 participants