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] Add options to ignore certain import kinds #1900

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

RebeccaStevens
Copy link

This adds a new option called "allowedImportKinds" to the rule no-restricted-paths.
This option defaults to an empty array and can be set to an array of strings.

This option allows imports of the specified kind(s) to be ignore by this rule.

Example use:

{
  // Allow type imports.
  "allowedImportKinds": ["type"],
  "zones": [ {
    "target": "./tests/files/restricted-paths/server/one",
    "from": "./tests/files/restricted-paths/server",
    // Override above `allowedImportKinds`, don't make an exception for any import kinds.
    "allowedImportKinds": [],
  } ]
}

@coveralls
Copy link

coveralls commented Sep 15, 2020

Coverage Status

Coverage increased (+0.005%) to 97.911% when pulling 7e9d9a4 on RebeccaStevens:no-restricted-paths/allowed-import-kinds into fef718c on benmosher:master.

@RebeccaStevens
Copy link
Author

@ljharb

I'm not sure if we need an enum - will there ever be another kind of import that's not value or type?

In this PR I haven't enforced the option being an enum, any strings can be given. With regard to whether there will be any other kinda of import, most likely not - but it's probably best to keep things flexible just in case.

@RebeccaStevens RebeccaStevens force-pushed the no-restricted-paths/allowed-import-kinds branch from 22a95d8 to f8e4a91 Compare September 15, 2020 00:45
@RebeccaStevens RebeccaStevens force-pushed the no-restricted-paths/allowed-import-kinds branch from 6b6b975 to 7e9d9a4 Compare September 15, 2020 01:09
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending schema change.

Comment on lines +9 to +16
const allowedImportKindsSchema = {
type: 'array',
items: {
type: 'string',
},
uniqueItems: true,
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do think we should restrict this for now to known import types. we can extend it in the future if needed, but we can't lock it down so easily.

@ljharb ljharb self-assigned this Jan 26, 2021
@ljharb ljharb removed their assignment Jan 26, 2021
@ljharb ljharb marked this pull request as draft January 26, 2021 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants