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 a knob to control opt_ prefixes #509

Closed
vapier opened this issue Apr 7, 2020 · 5 comments
Closed

add a knob to control opt_ prefixes #509

vapier opened this issue Apr 7, 2020 · 5 comments

Comments

@vapier
Copy link

vapier commented Apr 7, 2020

we want to stop people from using opt_ prefixes when a parameter is optional, but muscle memory can be hard, and sometimes we miss it during review. could a config knob be added to require/disallow/ignore opt_ prefixes on parameters relative to its optional setting ?

for example, we have code that does:

/**
 * Internal helper for resyncing internal state.
 *
 * Used when the mappings change.
 *
 * @param {!Object=} opt_glmap Additional mappings to overlay on top of the
 *     base mapping.
 */
function foo(opt_glmap) {

since the @param has an = on it, we don't want the opt_ prefix as it's redundant.

@brettz9
Copy link
Collaborator

brettz9 commented Apr 11, 2020

Though #483 is in the context of spaces/tabs, the discussion there kind of ties in to this, as we could have regexes which match against the name portion (though such a rule would also need to specify contexts and tags--like match-description).

@brettz9
Copy link
Collaborator

brettz9 commented Jun 18, 2020

If there were a match-name rule (which could be used to prevent all opt_--not tied to whether there were a = or not), would that meet your needs? Is this practice used in any big projects like Closure that you know? Or is this just your local convention? I'm afraid that if unless it is just a rule to match names, it seems to me to be a bit project-specific.

@vapier
Copy link
Author

vapier commented Jun 18, 2020

a knob to run a regex across all variable names would suffice

the "don't use opt_" rule comes from the Google JS style guide:
https://google.github.io/styleguide/jsguide.html#features-functions-parameter-return-types

i won't make claims for how widely that guide is adopted outside of Google and Google-maintained projects, but it does seem to be in the top hits when searching for the topic, and referenced in articles discussing JS style guides.

@brettz9
Copy link
Collaborator

brettz9 commented May 30, 2021

Here's a new test case for the jsdoc/no-restricted-syntax rule which now will let you at least get reporting for (though not fixing of) opt_ prefixes:

{
      code: `
        /**
         * @param opt_a
         * @param opt_b
         */
        function a () {}
      `,
      errors: [{
        line: 2,
        message: 'Only allowing names not matching `/^opt_/i`.',
      }],
      options: [{
        contexts: [
          {
            comment: 'JsdocBlock:has(JsdocTag[name=/opt_/])',
            context: 'any',
            message: 'Only allowing names not matching `/^opt_/i`.',
          },
        ],
      }],
    },

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jun 14, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jun 14, 2021
@gajus
Copy link
Owner

gajus commented Jun 16, 2021

🎉 This issue has been resolved in version 35.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants