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

Add quick fix for S4623 for ('no-undefined-argument') #3040

Merged
merged 4 commits into from
Mar 15, 2022
Merged

Conversation

yassin-kammoun-sonarsource
Copy link
Contributor

Fixes #3028

{
messageId: 'suggestRemoveUndefined',
fix: fixer => {
const singleArgument = call.arguments.length === 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would inline this

messages: {
removeUndefined: 'Remove this redundant "undefined".',
suggestRemoveUndefined: 'Remove "undefined"',
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say Remove this redundant argument

errors: 2,
errors: [
{
messageId: 'removeUndefined',
Copy link
Contributor

Choose a reason for hiding this comment

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

I would drop this extra assertion of issue message

},
],
},
],
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have test with trailing comma?

desc: 'Remove this redundant argument',
output: `
function fun(p = 42) {}
fun(,);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is syntax error, we can't have such fix

Copy link
Contributor

Choose a reason for hiding this comment

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

add test with trailing comma when there are several arguments

@yassin-kammoun-sonarsource yassin-kammoun-sonarsource changed the title Add quick fix for S4623: "undefined" should not be passed as the value of optional parameters Add quick fix for S4623 for ('no-undefined-argument') Mar 14, 2022
desc: 'Remove this redundant argument',
output: `
function fun(p, q, r = 42) {}
fun(1, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO we should keep trailing comma here. That would be most probably used for multiline and then it's expected to have comma after each argument:

foo(
  1,
  2,
  undefined,
);

// will become 
foo(
  1,
  2
);
// and this will violate style... while it's probably pretty minor

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am fine with the behaviour you are suggesting.

Copy link
Contributor

@vilchik-elena vilchik-elena left a comment

Choose a reason for hiding this comment

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

@yassin-kammoun-sonarsource I think you misunderstood me. I wanted to keep the styling: so if trailing comma is there we should keep it, if there is no trailing comma, there should be none in the result as well.

@sonarsource-next
Copy link

@vilchik-elena vilchik-elena merged commit 5de0ba9 into master Mar 15, 2022
@vilchik-elena vilchik-elena deleted the issue-3028 branch March 15, 2022 14:32
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.

Add quick fix for S4623: "undefined" should not be passed as the value of optional parameters
2 participants