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

fix(linter): rule no-restricted-imports support missing options #8076

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Sysix
Copy link
Contributor

@Sysix Sysix commented Dec 23, 2024

The regex property is used to specify the regex patterns for restricting modules.
Note: regex cannot be used in combination with group.

https://eslint.org/docs/latest/rules/no-restricted-imports#regex

This option allows you to use regex patterns to restrict import names:

https://eslint.org/docs/latest/rules/no-restricted-imports#importnamepattern

This is a string option. Inverse of importNamePattern, this option allows imports that matches the specified regex pattern. So it restricts all imports from a module, except specified allowed patterns.
Note: allowImportNamePattern cannot be used in combination with importNames, importNamePattern or allowImportNames.

https://eslint.org/docs/latest/rules/no-restricted-imports#allowimportnamepattern

Needed to install regress to support JS Sntax like Lookaheads and Lookbehinds

Next Goals:

Copy link

graphite-app bot commented Dec 23, 2024

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Dec 23, 2024
Copy link

codspeed-hq bot commented Dec 23, 2024

CodSpeed Performance Report

Merging #8076 will not alter performance

Comparing Sysix:fix-linter-no-restricted-imports-regex-option (87d8da7) with main (6b51e6d)

Summary

✅ 29 untouched benchmarks

@Sysix Sysix marked this pull request as ready for review December 23, 2024 15:21
@Sysix Sysix changed the title fix(linter): rule no-restricted-imports support regex option inside patterns fix(linter): rule no-restricted-imports support regex & importNamePattern option inside patterns Dec 23, 2024
@Sysix Sysix marked this pull request as draft December 23, 2024 17:09
@Sysix Sysix changed the title fix(linter): rule no-restricted-imports support regex & importNamePattern option inside patterns fix(linter): rule no-restricted-imports support missing options Dec 23, 2024
@Sysix Sysix marked this pull request as ready for review December 23, 2024 17:24
Cargo.toml Outdated
@@ -178,6 +178,7 @@ prettyplease = "0.2.25"
project-root = "0.2.2"
rayon = "1.10.0"
regex = "1.11.1"
regress = "0.10.1"
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to not include another regex dependency? It's a bit heavy.

Are we able to limit the regex usage instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rust regex and JS Regex are differently.

In the test are differnt regexs like:

  • @app/(?!(api/enums$)).*
  • foo/(?!bar)

which then would fail. I can disable the test and use rust regex if you want.
I expect that some setups will fail because of this :)

Copy link
Contributor Author

@Sysix Sysix Dec 25, 2024

Choose a reason for hiding this comment

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

Removed the package with this commit: 0da9b9d

Unicode is supported by default (flag u)
Case-Insenstive can not be enabled by the option case_senstive (flag i). It must be included in the regex, see the documentaiton here: https://docs.rs/regex/1.10.4/regex/#grouping-and-flags

@Sysix Sysix requested a review from Boshen December 25, 2024 15:13
return false;
};

let Ok(reg_exp) = Regex::new(regex.as_str()) else {
Copy link
Contributor

Choose a reason for hiding this comment

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

probably a TODO - use https://doc.rust-lang.org/std/sync/struct.OnceLock.html to avoid having to re-compile the regex a bunch of times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not know how to use OnceLock with an array of patterns and inside multiple regex-options.
I reduced the call with this commit: 87d8da7

@camc314 Hope this helps ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-bug Category - Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants