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
feat: added newline formatting for comments #251
Conversation
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.
What do you think about making this functionality an option?
src/index.js
Outdated
const commentsFormatting = tree => { | ||
tree.walk = walk; | ||
tree.walk(node => { | ||
if (typeof node === 'string' && /<!--[^]*-->/gm.test(node.trim())) { |
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.
- Regular expression
/<!--[^]*-->/gm
is better to put in a constant - The beginning
<!--
and the end-->
of the notation for the comment I would put into a constant
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.
yea cool 👍
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.
2. The beginning
<!--
and the end-->
of the notation for the comment I would put into a constant
DOne 👍
- Regular expression
/<!--[^]*-->/gm
is better to put in a constant
I dont know why but when I am putting that into a constant and using the .test
method, its not working.
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.
you create with new RegExp
?
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 tried, its still the same. I don't know why it's happening. Its working fine for the other regex constants
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.
hmm yes that's weird
src/index.js
Outdated
tree.walk(node => { | ||
if (typeof node === 'string' && /<!--[^]*-->/gm.test(node.trim())) { | ||
const originalComments = node.trim(); | ||
const content = originalComments.replace(/^<!--/g, '').replace(/-->$/, ''); |
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.
Here, it seems to me that a regular expression that takes into account a multiline is better - <!--([\s\S]*?)-->
content will match
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 will check this.
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.
done
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.
Pay attention to this post here is a coincidence and there will be our content, and we do not need to replace
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 didnt get this 🔼
yea we can, can you suggest the option name ? may be |
I like it better when there is narrowness first and then its options, for example
|
|
about node = node?.trim()
I guess optional chaining doesnt work the type , it just checks the whether its undefined or not, right !. Let me know if I missed anything. |
Yes, in this case only |
but with |
Ohhh yes, I think I missed this little detail of the fact that the first condition is string checking I think then it will be better if we put out the regular expression test in the condition if (typeof(node) === 'string') {
node = node.trim()
if (...) {...}
} |
@anikethsaha Hi, reviewers please )) |
Looks good to me. 🎉 |
@anikethsaha Good job, thanks |
fixes #250
Before
After