Inline comment after func params is printed inside the params
See original GitHub issueOriginal
I’ve migrated a large codebase which used this function definition style:
function func(a, b) // `a` is the first arg
{
return 'done'
}
Reprinted
prettier
reprinted all comments following function params like this:
function func(
a,
b // `a` is the first arg
) {
return "done";
}
This is extra confusing as the comment is on the same line as a parameter it does not refer to. We have many of these cases as you might imagine.
Proposal
The comment must be moved since an inline comment can’t appear between the closing paren and opening curly: ) {
. Since the original comment was not inside the parentheses, IMHO, it should not be moved inside when reprinted.
I would think most humans would rewrite the original function with the comment on the line above the function:
// `a` is the first arg
function func(a, b) {
return "done";
}
Would love to hear feedback on this.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Writing comment block for function where parameters change
After @param, it should be the type of the variables you pass, if there are several possible types, you can separate them with...
Read more >Examples of Comment-Based Help - PowerShell
The following sample function includes comment-based Help. Notice the blank lines between the closing #> and the Param statement. In a script ...
Read more >Writing Comments in Python (Guide)
Learn how to write Python comments that are clean, concise, and useful. Quickly get up to speed on what the best practices are,...
Read more >How to Write Doc Comments for the Javadoc Tool - Oracle
Our documentation comments define the official Java Platform API Specification. ... In this example, the block tags are @param , @return , and...
Read more >Activity: Function Documentation - Microsoft MakeCode Arcade
To comment on a parameter, start the line with @param , followed by the parameter's name, and then a short description of what...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hm, thinking this through. I’m not sure what the impact might be to code that must appear directly above a function like decorators, docblocks, etc.
A less desirable alternative might be to print the inline comment on the first line of the func body. Will leave it at that for now.
Agreed, closing for the sake of progress.