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

Rule Change: Add ability to ignore Undefined in Function Params #16711

Closed
1 task done
elliot-huffman opened this issue Dec 26, 2022 · 3 comments
Closed
1 task done

Rule Change: Add ability to ignore Undefined in Function Params #16711

elliot-huffman opened this issue Dec 26, 2022 · 3 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects

Comments

@elliot-huffman
Copy link
Contributor

elliot-huffman commented Dec 26, 2022

What rule do you want to change?

no-undefined

What change to do you want to make?

Generate fewer warnings

How do you think the change should be implemented?

A new option

Example code

const autopilotDevice: WindowsAutopilotDeviceIdentity[] = await this.GraphClient.iterateAllPages(await this.GraphClient.graphMethod('Get', '/deviceManagement/windowsAutopilotDeviceIdentities', undefined, `azureActiveDirectoryDeviceId eq '${ deviceId }'`) as PageCollection) as WindowsAutopilotDeviceIdentity[];

What does the rule currently do for this code?

This rule currently flags the undefined value manually put in the call signature of the graphMethod method to skip an optional parameter to be able to use a parameter that is further down the call signature.

What will the rule do after it's changed?

After changing the rule, the rule will have a new option that allows for silencing the use of undefined in call signatures. All other undefined usage detections should not be modified, just undefined usage in call signatures.

Participation

  • I am willing to submit a pull request to implement this change.

Additional comments

As seen here:
https://stackoverflow.com/questions/8356227/skipping-optional-function-parameters-in-javascript

@elliot-huffman elliot-huffman added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules labels Dec 26, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Dec 26, 2022
@mdjermanovic mdjermanovic moved this from Needs Triage to Triaging in Triage Dec 26, 2022
@mdjermanovic
Copy link
Member

Hi @elliot-huffman, thanks for the issue!

The no-undefined rule disallows the use of undefined as an identifier. In other words, this rule disallows references to the global variable undefined, such as in the example you provided. It doesn't disallow generating undefined values. As stated in the documentation, for this purpose you can use void 0, and that will be valid code for this rule:

this.GraphClient.graphMethod('Get', '/deviceManagement/windowsAutopilotDeviceIdentities', void 0, `azureActiveDirectoryDeviceId eq '${ deviceId }'`)

I think that specifically allowing undefined identifiers in function calls wouldn't be in line with the purpose of this rule as there's no real difference between function calls and other contexts in this regard.

@mdjermanovic mdjermanovic closed this as not planned Won't fix, can't repro, duplicate, stale Dec 26, 2022
Triage automation moved this from Triaging to Complete Dec 26, 2022
@elliot-huffman
Copy link
Contributor Author

I missed that context for my usage, I am so sorry for the trouble. Good point. I completely agree on keeping the rule the same because of the ability to replace the value.

@elliot-huffman
Copy link
Contributor Author

Opened Pull Request #16712 to update the docs to include my scenario because I know others may have a mindset like mine :-P

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jun 25, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

2 participants