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

Inspections can't detect jQuery usages if non-$ alias is used #18

Open
alies-dev opened this issue Sep 10, 2018 · 2 comments
Open

Inspections can't detect jQuery usages if non-$ alias is used #18

alies-dev opened this issue Sep 10, 2018 · 2 comments

Comments

@alies-dev
Copy link

alies-dev commented Sep 10, 2018

Inspections can't detect jQuery usages if non-$ alias is used

Example of a code that can be omitted by jquery/no-ajax rule:

import jQuery from 'jquery';

jQuery
    .ajax({ url: url, method: 'POST' })
    .done(() => { });

That's because some rules contains the following code:

if (node.callee.object.name !== '$') return

the quick-fix solution is to check for jQuery/jquery also:

const jQueryAliases = ['$', 'jQuery', 'jquery'];
const calleeObjectName = node.callee.object.name;
if (! jQueryAliases.includes(calleeObjectName)) return

Ideally jQueryAliases should be a configurable option

PS: If you agree with this solution - I can create a PR 👍

@alies-dev alies-dev changed the title Inspections can't detect jQuery usages if non-$ alias used Inspections can't detect jQuery usages if non-$ alias is used Sep 10, 2018
@macklinu
Copy link
Contributor

macklinu commented Sep 24, 2018

Not a maintainer of this plugin, but I think this would be a good idea. I wonder if this would be a use case for using ESLint's shared settings so the aliases are accessible across all rules.

// .eslintrc.js
module.exports = {
  settings: {
    jQueryAliases: ['jquery', 'jQuery', '$'],
  },
}

// in your rule
module.exports = {
  create(context) {
    const jQueryAliases =
      context.settings && context.settings.jQueryAliases
        ? [].concat(context.settings.jQueryAliases)
        : ['$']

    return {
      // use `jQueryAliases` in your visitor
    }
  },
}

@alies-dev
Copy link
Author

I think it makes sense to implement this feature only after merging #20

Otherwise we will have a lot of conflicts

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

No branches or pull requests

2 participants