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

vue/define-macros-order bug #1861

Merged
merged 2 commits into from Apr 22, 2022
Merged

Conversation

edikdeisling
Copy link
Contributor

Fix bugs from #1856

@@ -45,7 +57,11 @@ function getTargetStatementPosition(program) {
])

for (const [index, item] of program.body.entries()) {
if (!skipStatements.has(item.type) && !isUseStrictStatement(item)) {
if (
inScriptSetup(scriptSetup, item) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -213,13 +232,12 @@ function create(context) {
const targetComment = sourceCode.getTokenAfter(beforeTargetToken, {
includeComments: true
})
const textSpace = getTextBetweenTokens(beforeTargetToken, targetComment)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This thing fixes these newlines https://github.com/vuejs/eslint-plugin-vue/pull/1861/files#diff-6ebdd3c21be70e29ce94a2f399884fd220d4fe9bba358ade66b0bceb325d3102L158

Before we took space before the target token and added it after the moving token.
Now we take space after the target token and added it after the moving token.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm. I think this change is an improvement. I don't think this should be included in the patch, so could you revert this change in this PR and open another PR?

afterTargetComment.range[0]
)
// handle case when a();b() -> b()a();
const invalidResult = !textNode.endsWith(';') && !/[\n;]/.test(afterText)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the corner case I found

@edikdeisling
Copy link
Contributor Author

edikdeisling commented Apr 22, 2022

I ran it in my project and the result was great. The only annoying thing left is this:
image

There is an option to introduce "newLineAfterDefineMacros: true" option maybe... For now, I've done nothing

afterTargetComment.range[0]
)
// handle case when a();b() -> b()a();
const invalidResult = !textNode.endsWith(';') && !/[\n;]/.test(afterText)
Copy link
Member

Choose a reason for hiding this comment

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

I guess it should check the start only, right?

Suggested change
const invalidResult = !textNode.endsWith(';') && !/[\n;]/.test(afterText)
const invalidResult = !textNode.endsWith(';') && !/^[\n;]/.test(afterText)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this value also get valid result

const afterText = '   ;   '

//a()   ;   b();

Copy link
Member

Choose a reason for hiding this comment

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

But wouldn't it also return true for b();c()? Or (b();)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm. This variable contains only whitespaces and new lines I suppose... because it's all can exist between node and next comment after node

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe i need to remove ; from regexp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -213,13 +232,12 @@ function create(context) {
const targetComment = sourceCode.getTokenAfter(beforeTargetToken, {
includeComments: true
})
const textSpace = getTextBetweenTokens(beforeTargetToken, targetComment)
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm. I think this change is an improvement. I don't think this should be included in the patch, so could you revert this change in this PR and open another PR?

@edikdeisling
Copy link
Contributor Author

edikdeisling commented Apr 22, 2022

@ota-meshi sure. Am I need to open an issue?

@ota-meshi
Copy link
Member

If you write an explanation in the PR, you do not need to open an issue.

Copy link
Member

@ota-meshi ota-meshi 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!

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.

None yet

3 participants