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

Intended? Bug in import rule #9

Closed
bel0v opened this issue May 6, 2019 · 1 comment · May be fixed by #10
Closed

Intended? Bug in import rule #9

bel0v opened this issue May 6, 2019 · 1 comment · May be fixed by #10

Comments

@bel0v
Copy link

bel0v commented May 6, 2019

Hi and thanks for the plugin.

We've faced a following issue:
Say we have a rule:

    "deprecate/import": [
      "error",
      { "name": "app/elements/deprecated", "use": "a new fancy element" }
    ]

But due to indexing, we've got many imports like this:

import {OkayElement1, OkayElement2 } from 'app/elements'

which also triggers an error.

This happens because of the line 69 in import.js:

filter(([importString]) => importString.includes(importPath))

which should be vice versa,

importPath.includes(importString))

I've forked the repo and fixed it for us, but I noticed that you have tests for that behaviour. E.g.:

        {
            code: 'import a from "Legacy"',
            parser: 'babel-eslint',
            options: [{ name: 'path/to/Legacy', use: 'New' }],
            errors: [{
                message: 'Module path/to/Legacy is deprecated. Use New instead.'
            }]
        },

you consider Legacy module to be deprecated, even though in the rule only specific module is stated, namely the one located in /path/to/.
From my perspective this is not right and causes issues like ours (partly paths overlapping) or conflicting module names.

If you agree I can provide a PR to fix the behaviour.

@bel0v bel0v mentioned this issue May 6, 2019
@AlexMost
Copy link
Owner

Hey, sorry for the late response. Just have missed your message. This issue can be solved by nameRegExp option in 0.7.0. This option allows you to set a regular expression that will validate your import. You can see an examples in a doc - https://github.com/AlexMost/eslint-plugin-deprecate/blob/master/docs/rules/import.md

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 a pull request may close this issue.

2 participants