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

Grouping all comments in a chain at the beginning of it #708

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Janther
Copy link
Contributor

@Janther Janther commented Jul 18, 2022

addressing some issues with comments in chains. #644

For now we are grouping comments at the beginning of the chain.

This is a good first step however we must address some questions if we want to continue with this approach.

first of all in this scenario:

// Original
begin.
    // Comment 1
    functionCall(/* Comment about parameter */ parameter).
    // Comment 2
    end;

// Formatted
// Comment 1
// Comment 2
begin.
    functionCall(/* Comment about parameter */ parameter).
    end;

This is the expected behaviour but the order of the comments is not the same anymore. Therefore the AST comparison will fail.

Shall we remove the comments from the AST comparison understanding that Prettier already has a lot of security making sure that each comment will be printed?

In this case we are making new advances since Prettier JS does mess up with the order of the comments when the chain get a bit complex and also the indentation.

Thoughts @fvictorio @mattiaerre

there are some more ideas I have but for now this is a good first step.

@Janther Janther requested review from fvictorio and mattiaerre July 18, 2022 04:00
return false;
}

module.exports = handleMemberAccessComments;
Copy link
Member

Choose a reason for hiding this comment

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

Can this file be called also handleMemberAccessComments.js perhaps?

Comment on lines +6 to +10
text,
precedingNode,
enclosingNode,
followingNode,
comment
Copy link
Member

Choose a reason for hiding this comment

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

not all these params have been used; maybe pass an object into the function instead of all these params?

Comment on lines +252 to +258
// Comment before chain
// CONFIG
// Comment 1
// Comment 2
// Comment 3
// Comment 4
// Comment 5
Copy link
Member

Choose a reason for hiding this comment

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

Is this what we would like to achieve? Move all the comments above the chain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes
Have a look at #644 and also try it on Prettier JS to see what they are doing at the moment.
It's not perfect but there is something nice in it.

Copy link
Member

Choose a reason for hiding this comment

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

I'll give it a try

@Janther Janther marked this pull request as draft July 20, 2022 05:06
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.

2 participants