Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat(eslint-plugin): [consistent-generic-constructors] add rule #4924
feat(eslint-plugin): [consistent-generic-constructors] add rule #4924
Changes from 9 commits
8e5d39f
df8de5c
aa7c312
c6434c7
7e29ee3
85b851c
33cb2d3
ba54b9e
46de101
867152a
c40ab67
ff8dfc7
2110540
119393c
371983e
5e49222
63e4cb9
be2f1af
1bdedec
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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'm under the impression we generally try to use objects for the schemas. They're a bit more future-proof and enforce using a property key to explain what the object is for. Only a few rules still have an enum schema.
type: "object"
withadditionalProperties: false
is preferred.(are there docs on this anywhere in this project or ESLint core? we should write some somewhere if not...)
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.
String option is preferred when a rule enforces two kinds of styles, and the rule needs to know which side you are on to be functional at all. Object option is used when you are making refinements to the given style. To give a few examples:
arrow-body-style
func-style
consistent-indexed-object-style
I noticed that we tend to use an object containing a
prefer
property, but IMO that deviates from ESLint core's API design😅 Sometimes ESLint core would have both string and object, likefunc-name-matching
. When you really look into it, you would understand the differing semantics between string and object.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.
Yeah the types for these queries can be tricky. More support of us using fancy template literal magicks to parse them (#4065).
Going off the "complex types are from complex code" philosophy: how about splitting this into two queries?
VariableDeclarator[init.callee.type='Identifier'][init.type='NewExpression']
could run just the right-hand-side logic.Search
NodeWithModifiers
andTypeParameterWithConstraint
for examples of places where we've had to manually adjust node types in the past.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'm not particularly good at AST selectors, so I always felt a bit cornered when I have to use them...
Also, we simultaneously need
lhs
andrhs
, and there are a few cases (especiallylhs.typeName.name !== rhs.callee.name
) where we kind of depend on both for refinement, so I've kept it like this.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 tried, it was ugly refined types like
Combined with ugly selectors😇 I suggest we don't do it?
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.
question: do we want to handle namespaced names like
const foo: immutable.Set<string> = new immutable.Set();
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.
Yeah we should... is there a utility function to match potentially nested qualified names?
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.
We don't - I don't think it's something we do all that much!
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.
Let's leave it off for now - we can add it in later.
It's not super common to be doing this.