-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[New] no-internal-modules
: Add forbid
option
#1846
[New] no-internal-modules
: Add forbid
option
#1846
Conversation
@@ -14,6 +14,13 @@ ruleTester.run('no-internal-modules', rule, { | |||
filename: testFilePath('./internal-modules/plugins/plugin.js'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added tests, but maybe not enough. Don't hesitate to ask me to implement other tests if you see something I've missed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd saw this is worth a lot more test cases :-) I don't have any concrete ones in mind, but the more there are, the more convincing the PR is.
docs/rules/no-internal-modules.md
Outdated
@@ -4,7 +4,10 @@ Use this rule to prevent importing the submodules of other modules. | |||
|
|||
## Rule Details | |||
|
|||
This rule has one option, `allow` which is an array of [minimatch/glob patterns](https://github.com/isaacs/node-glob#glob-primer) patterns that whitelist paths and import statements that can be imported with reaching. | |||
This rule has two options that are arrays of [minimatch/glob patterns](https://github.com/isaacs/node-glob#glob-primer) patterns: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rule has two options that are arrays of [minimatch/glob patterns](https://github.com/isaacs/node-glob#glob-primer) patterns: | |
This rule has two mutually exclusive options that are arrays of [minimatch/glob](https://github.com/isaacs/node-glob#glob-primer) patterns: |
docs/rules/no-internal-modules.md
Outdated
"allow": [ "**/actions/*", "source-map-support/*" ], | ||
"forbid": [ "**/actions/special/*" ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be possible to both allow and forbid specific things? When "allow" is specified, it takes precedence over a default "forbid" of "/*". When "forbid" is specified, it takes precedence over a default "allow" of "/*".
I'd expect the schema to only allow one or the other, never both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By
I'd expect the schema to only allow one or the other, never both.
You mean the user will either provide allow
array or forbid
array but never both ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. If both are provided, we have to define a precedence between them - with allow
of A and forbid
of B
, what's intended with C
? Is it allowed, because it's not forbidden? Or is it forbidden, because it's not allowed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I understand now! I will rework the PR to do that 👍
@ljharb I took the time to work again on this PR. |
Hello @ljharb, do you need something else on this PR ? |
no-internal-modules
: Add forbid
option
Hi @ljharb This feature seems to have been released in the docs, but it is not released in the newest release (v.2.22.1) which is pretty confusing. Is this a mistake? I was trying to use the feature as described in the docs, but it failed with the following error:
Best regards |
It's not a mistake at all. If you're looking at the docs on master, you'll see unreleased things. I created the "github release" for v2.22.1 yesterday, but it was actually released in September (see the changelog link). This PR has not yet been released. |
Okay, thanks for clarifying. Never realized that I actually have to look in the release zip for the current documentation :) |
Yes, on every project on github, you have to switch to the latest release tag to see the current documentation. |
When does it goes to an official release? |
Here is the pull request that implements #1842.
Without
forbid
option provided, the behavior stay the same. It should be a semver-minor PR.With
forbid
option provided, the rule check if a given path is explicitly forbidden before testing if it's allowed.