Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

import-name rule should support regex pattern matching #853

Closed
jeffryang24 opened this issue Mar 29, 2019 · 2 comments
Closed

import-name rule should support regex pattern matching #853

jeffryang24 opened this issue Mar 29, 2019 · 2 comments
Labels
Status: In Discussion Please continue discussing the proposed change before sending a pull request. Type: Rule Feature Adding a feature to an existing rule.

Comments

@jeffryang24
Copy link

jeffryang24 commented Mar 29, 2019

Rule Suggestion

Is your rule for a general problem or is it specific to your development style?

I think it is only for my development style, but it could be useful for the general problem too.

What does your suggested rule do?

Currently, import-name only supports static name matching, such as: underscore to _, etc. But, I actually found that the import-name rule also supports regex matching while the documentation (README.md) doesn't tell it so.

List several examples where your rule could be used

I have many container components with (\w+)Container.tsx pattern, such as RebookModalButtonContainer.tsx, etc. I thought that import-name rule could accept regex pattern, so I add the rule below.

path/to/someFile.tsx

import RebookModalButton from 'path/to/RebookModalButtonContainer'; // triggers warning from tslint.

tslint.json

{
  "rules": {
    "import-name": [true, {
      "(\\w+)Container": "$1", // this rule doesn't work
      "*Container": "$1",  // this rule works
      "*Container": "", // this rule also works
    }]
  }
}

And the warning for import script above is gone away. But, this is my question for this issue.

  • Does import-name rule officially support regex pattern for current version?
  • If it doesn't support regex pattern, does this issue count as bug or undocumented feature (actually it can but forget to tell inside README.md)?

Additional context

VSCode: 1.32.3 (Snap package)
TSLint extension: https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-tslint-plugin
TSLint version: ^5.14.0
tslint-microsoft-contrib: ~5.2.1

Currently, I only want to know if import-name rule supports regex pattern matching, which is very helpful for handling the same import-name pattern instead of manually register it one by one. If it doesn't support it, maybe I can help to fix this issue if possible. 😄

@JoshuaKGoldberg
Copy link

Currently, I only want to know if import-name rule supports regex pattern matching

Alas, right now it does not. That would be a feature request.

maybe I can help to fix this issue if possible

Yes please! That'd be great!

However, we should note that there might be backwards compatibility issues: if an existing rule configuration is meant to explicitly refer to a single path, and that path happens to include characters that mean something in a regular expression, adding in regex support would change the rule's behavior. How can the rule support regular expressions in a non-breaking way?

Related: #452

@JoshuaKGoldberg JoshuaKGoldberg added Status: In Discussion Please continue discussing the proposed change before sending a pull request. Type: Rule Feature Adding a feature to an existing rule. labels Mar 31, 2019
@JoshuaKGoldberg
Copy link

☠️ It's time! ☠️

Per #876, this repository is no longer accepting feature pull requests. TSLint is being deprecated and we recommend you switch to https://typescript-eslint.io.

Thanks for open sourcing with us, everyone!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Status: In Discussion Please continue discussing the proposed change before sending a pull request. Type: Rule Feature Adding a feature to an existing rule.
Projects
None yet
Development

No branches or pull requests

2 participants