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

no-restricted-paths no longer supports regular expressions #2123

Closed
RvanderLaan opened this issue Jun 10, 2021 · 5 comments
Closed

no-restricted-paths no longer supports regular expressions #2123

RvanderLaan opened this issue Jun 10, 2021 · 5 comments

Comments

@RvanderLaan
Copy link

RvanderLaan commented Jun 10, 2021

On version 2.22.1 I was able to use regular expressions in the paths for a zone, but this no longer works in 2.23.4:

    "import/no-restricted-paths": [
      "error",
      {
        "zones": [
          {
            "target": "*",
            "from": "src/generated/schema.ts",
            "except": ["src/.*/resolvers.ts"]
          }
        ]
      }
    ]

I suspect it's because of #2090, where the contains-paths dependency was replaced by a custom function.
The way I set up this zone might not really be the intended use case of this rule, but it might break more valid configurations too. Is this something that could be brought back?

Edit: Regex in the except field actually was not supported before, but that would be a nice addition too!

@ljharb
Copy link
Member

ljharb commented Aug 18, 2021

eslint rules should never support regexes; that's the primary source of CVEs (ReDOS, mostly).

https://www.npmjs.com/package/contains-path doesn't mention anything about asterisks being supported, but it's certainly possible they were unintentionally supported, or undocumented, and #2090 removed it.

I'd be happy to review a PR that restored/added the ability for globs (not regexes) to go in zones. It was certainly never intended for this plugin to accept regexes there.

@ninofiliu
Copy link

Hey @ljharb I'd be happy to help there! That would greatly simplify an eslint config we have at our company.

I've never contributed here. Is this section up to date? If so, I'll implement such a glob feature in the next weeks or so

@ljharb
Copy link
Member

ljharb commented Aug 24, 2021

As far as i know it is. A PR would be great, thanks.

@alexmi256
Copy link

This would be a nice feature to have back again.
My use case is that I want to allow imports from /items or but not its subfolder, i.e. items/item1/foo.
AFAICT using the current version requires that I have to add a zone for each different item type, where as with regex support I can use from: items/[a-zA-Z0-9]+

@ljharb
Copy link
Member

ljharb commented Aug 28, 2021

@alexmi256 regex support will not be returning; and should never have been permitted in the first place. However, globs will be supported once a PR comes in, and that will allow items/*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants