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

docs: paths and patterns difference in no-restricted-imports #18273

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

Tanujkanti4441
Copy link
Contributor

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 and patterns option of no-restricted-imports rule.

Is there anything you'd like reviewers to focus on?

Fixes: #18253

@Tanujkanti4441 Tanujkanti4441 requested a review from a team as a code owner April 5, 2024 09:33
@eslint-github-bot eslint-github-bot bot added the documentation Relates to ESLint's documentation label Apr 5, 2024
Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit b67c6ef
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/66181089261cb0000704aec2
😎 Deploy Preview https://deploy-preview-18273--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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.
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! added examples.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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:

@amareshsm amareshsm added the accepted There is consensus among the team that this change meets the criteria for inclusion label Apr 9, 2024
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 301 to 309
```json
"no-restricted-imports": ["error", {
"patterns": [{
"group": ["import1/*"],
}]
}]
```

Here rule will restrict all modules inside `import1` directory.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
```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`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@nzakas nzakas merged commit df5f8a9 into eslint:main Apr 11, 2024
19 checks passed
@Tanujkanti4441 Tanujkanti4441 deleted the docs-diff branch April 12, 2024 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion documentation Relates to ESLint's documentation
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

Docs: no-restricted-imports doesn't explain paths vs. patterns
3 participants