-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
ci(eslint): add rule to encourage generic naming convention as ^(T|T[A-Z][A-Za-z]+)$
#6684
ci(eslint): add rule to encourage generic naming convention as ^(T|T[A-Z][A-Za-z]+)$
#6684
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 3be51b3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 3be51b3:
|
'^(T|\\$)[A-Z][a-zA-Z]+[0-9]*$'
'^(T|\\$)[A-Z][a-zA-Z]+[0-9]*$'
^(T|\\$)[A-Z][a-zA-Z]+[0-9]*$
^(T|\\$)[A-Z][a-zA-Z]+[0-9]*$
^(T|\\$)[A-Z][a-zA-Z]+[0-9]*$
.eslintrc.cjs
Outdated
selector: 'typeParameter', | ||
format: ['PascalCase'], | ||
leadingUnderscore: 'allow', | ||
custom: { | ||
regex: '^(T|\\$)[A-Z][a-zA-Z]+[0-9]*$', | ||
match: true, |
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.
hmm why would we allow leading underscores on a type param? I've set this in other projects to:
{
selector: 'typeParameter',
format: ['PascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
custom: {
regex: '^(T|\\$)([A-Z][a-z]+)*$',
match: true,
},
},
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.
hmm why would we allow leading underscores on a type param?
Oh thanks, I didn't care these options(leadingUnderscore, trailingUnderscore) mistakely.
I banned underscores, and simplified regex
like below
{
selector: 'typeParameter',
format: ['PascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
custom: {
regex: '^([A-Z]|T[A-Z][A-Za-z]+)$'',
match: true,
},
}
@TkDodo I will resolve eslint errors soon. wait a minutes please. |
I tried to resolve eslint errors, but there was too many cases that don't need this rule like below. 🥲 export type MaybeRef<T> = Ref<T> | T // isn't it T also good? I think warning is enough for this case
export type MaybeRefOrGetter<T> = MaybeRef<T> | (() => T)
...smillar cases or this rule as error in each files with eslint-disable if need? |
T alone should be valid according to the regex, no? |
Ah~, I thought T should be banned before. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #6684 +/- ##
=======================================
Coverage 41.78% 41.78%
=======================================
Files 178 178
Lines 7017 7017
Branches 1421 1421
=======================================
Hits 2932 2932
Misses 3722 3722
Partials 363 363 ☔ View full report in Codecov by Sentry. |
^(T|\\$)[A-Z][a-zA-Z]+[0-9]*$
^([A-Z]|T[A-Z][A-Za-z]+)$
@TkDodo sorry, My reply was late because I didn't know much about regex and was studying it. I update regex for this rule as This rule will make contributors use only below. okayalone T, U, V, etc. is okay not okayKQueryData, Result, Depth, State, DefinedQueryObserver, Runner, Args, TaggedQueryKey, Type, Value, etc. is banned from now. these should be started with T And I updated codes not following this rule ps. When I test this rule, I used this tool(https://rex.antfu.me/) made by @antfu. so cool thanks anthony fu! |
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
0f245e4
to
25177d2
Compare
@TkDodo check this again please |
@manudeli I would prefer it if Imo one-character generics are best if there is only one on a given type / function. With two or more, you always need to now what they stand for ... |
Ahha, I understood your intention. and I agree your opinion. then I'll change it as following you want |
^([A-Z]|T[A-Z][A-Za-z]+)$
^(T|T[A-Z][A-Za-z]+)$
can you please fix the conflicts ? |
@TkDodo Sure, I resolved conflict now |
# Overview <!-- A clear and concise description of what this pr is about. --> TanStack/query#6684 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
# Overview <!-- A clear and concise description of what this pr is about. --> TanStack/query#6684 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
# Overview <!-- A clear and concise description of what this pr is about. --> TanStack/query#6684 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
# Overview <!-- A clear and concise description of what this pr is about. --> TanStack/query#6684 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
# Overview <!-- A clear and concise description of what this pr is about. --> TanStack/query#6684 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
@TkDodo I saw your post in X and @juliusmarminge's solution by @typescript-eslint/naming-convention with regex
I want to add it in this repository
I've been using this rule in various repositories for quite some time, and I really liked the fact that when defining a new generic, it encouraged me not to just name it T. It make coworker and interface user feel better DX.
@juliusmarminge Thanks for sharing your cool solution too.