-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
docs: paths
and patterns
difference in no-restricted-imports
#18273
Conversation
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -286,6 +286,8 @@ import { AllowedObject } from "foo"; | |||
|
|||
This is also an object option whose value is an array. This option allows you to specify multiple modules to restrict using `gitignore`-style patterns. | |||
|
|||
Where `paths` option takes exact import paths, `patterns` option can be used to specify the import paths with more flexibility, allowing for the restriction of multiple modules within the same directory. |
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 think we could use some examples in this explanation, as it's still not clear to me what the difference is.
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.
Done! added examples.
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.
Where `paths` option takes exact import paths, `patterns` option can be used to specify the import paths with more flexibility, allowing for the restriction of multiple modules within the same directory. | |
Where `paths` option takes exact import paths, `patterns` option can be used to specify the import paths with more flexibility, allowing for the restriction of multiple modules within the same directory. For example: |
@@ -286,6 +286,8 @@ import { AllowedObject } from "foo"; | |||
|
|||
This is also an object option whose value is an array. This option allows you to specify multiple modules to restrict using `gitignore`-style patterns. | |||
|
|||
Where `paths` option takes exact import paths, `patterns` option can be used to specify the import paths with more flexibility, allowing for the restriction of multiple modules within the same directory. |
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.
Where `paths` option takes exact import paths, `patterns` option can be used to specify the import paths with more flexibility, allowing for the restriction of multiple modules within the same directory. | |
Where `paths` option takes exact import paths, `patterns` option can be used to specify the import paths with more flexibility, allowing for the restriction of multiple modules within the same directory. For example: |
}] | ||
``` | ||
|
||
Here rule will only restrict the `import-foo` module. |
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.
Here rule will only restrict the `import-foo` module. | |
This configuration restricts import of the `import-foo` module but wouldn't restrict the import of `import-foo/bar` or `import-foo/baz`. You can use `patterns` to restrict 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.
Done!
```json | ||
"no-restricted-imports": ["error", { | ||
"patterns": [{ | ||
"group": ["import1/*"], | ||
}] | ||
}] | ||
``` | ||
|
||
Here rule will restrict all modules inside `import1` directory. |
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.
```json | |
"no-restricted-imports": ["error", { | |
"patterns": [{ | |
"group": ["import1/*"], | |
}] | |
}] | |
``` | |
Here rule will restrict all modules inside `import1` directory. | |
```json | |
"no-restricted-imports": ["error", { | |
"paths": [{ | |
"name": "import-foo", | |
}] | |
"patterns": [{ | |
"group": ["import-foo/ba*"], | |
}] | |
}] | |
``` | |
This configuration restricts imports not just from `import-foo` using `path`, but also `import-foo/bar` and `import-foo/baz` using `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.
Done!
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.
LGTM. Thanks!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[x] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
added difference between the
paths
andpatterns
option ofno-restricted-imports
rule.Is there anything you'd like reviewers to focus on?
Fixes: #18253