-
Notifications
You must be signed in to change notification settings - Fork 142
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
refactor: use micromatch for matching files to be reported #296
Conversation
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.
Looking at the tests now, I think we should just remove the file-patterns
rule? 🤔
We already said that we could actually do that by using ESLint itself and just do a file/path override.
Looking at the tests here, it really feels wrong to me to have to add the file-pattern
setting in each test or to provide the fileName
.
Also: we now have 2 ways of telling "apply these rules to these files"
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.
After getting some more information by @Belco90, I came to the conclusion that I misunderstood why we sometimes have set the setting of filename rule.
LGTM! 👊
I'm gonna clarify couple of things so everyone has the proper context. The {
settings: { 'testing-library/file-patterns': ['**/?(*.)+(not-matching).[jt]s?(x)'] },
code: `const button = screen.getByRole('button')`,
filename: 'project/src/MyComponent.test.ts'
} it's literally simulating the following case: // MyComponent.test.ts, located at "project/src/"
const button = screen.getByRole('button')
// .eslintrc
settings: { 'testing-library/file-patterns': ['**/?(*.)+(not-matching).[jt]s?(x)'] } So the Having said that, why adding this What's the purpose of this Aggressive Reporting then? It will assume:
Why?
This is Aggressive Reporting already implemented in v4: it assumes things that are not 100% sure if could be related to Testing Library are actually related. So far so good. But what if someone needs to disable this for any reason? That's where the global settings come into play. The two first settings we introduced are:
The {
settings: { 'testing-library/file-patterns': ['**/?(*.)+(not-matching).[jt]s?(x)'] },
code: `const button = screen.getByRole('button')`,
filename: 'project/src/MyComponent.test.ts'
} it's literally simulating the following case: // MyComponent.test.ts, located at "project/src/"
const button = screen.getByRole('button')
// .eslintrc
settings: { 'testing-library/file-patterns': ['**/?(*.)+(not-matching).[jt]s?(x)'] } So the Having said that, why adding this What's the purpose of this Aggressive Reporting then? It will assume:
Why?
This is Aggressive Reporting already implemented in v4: it assumes things that are not 100% sure if could be related to Testing Library are actually related. So far so good. But what if someone needs to disable this for any reason? That's where the global settings come into play. The two first settings we introduced are:
Of course these 2 settings are related, so if you set them both, only things from indicated renders imported from indicated Testing Library modules would be reported. So this is everything about the Aggressive Reporting, its inspiration and how to opt it out. However, could this Aggressive Reporting be too much in some situations? It could be: rules like This is why I thought about adding the 3rd setting modified on this PR: This is nice to only report tests files, but can silence errors again. ESLint already allows you to run specific configurations for a subset of files matched by glob pattern, so we are re-adding the same behavior which can lead to false negatives situations really easy: the user has a different pattern for their files (e.g. only files with suffix So, after this massive explanation, what do you think we should do with this setting?
|
@CreativeTechGuy pinging you here in case you have some feedback about it :) |
I think @kentcdodds can give some valuable input on this idea too |
Long issue. What do you want my feedback on? |
I think in the spirit of the aggressive reporting, it would make sense to report in all files. But I can see how a lot of people would really hate this especially if they upgrade to v4 and suddenly have hundreds of linting errors which might cause people to immediately downgrade again. What about this compromise, custom lint error messages depending on the file path. This way the error sort of acts like a suggestion when it's less confident. If the file containing the error matches the condition you mention above (same as Jest) then the normal error message can be shown. It's fairly safe to assume in that context that it's a real error. But if the error appears in non I think the worst thing that this aggressive reporting update could do is be wrong far too often that it becomes overly painful and people avoid using it. And for any new users, the documentation for these global settings should be front and center in the setup instructions. That's my 2c at first glance. Great work on this! Excited to see it finally released. :) |
@CreativeTechGuy that's a really interesting approach indeed! What we can do is wrapping errors reported from outside those paths like To be honest, I don't think the v4 will report almost anything on a regular file for most of the users. Even if we have this Aggressive reporting in place, the utils names must much with Testing Library ones and I don't think it's usual to find |
To be clear, the objective here is basically to avoid this rule applying on non-test files? If that's the case, then that's outside the scope of this package. The responsibility of which rules apply to which files should be within the person configuring ESLint. They should use ESLint's |
@kentcdodds yeah it was basically that. I realized while writing the whole explanation around deciding to apply the rules based on file matching a pattern that it may be doing more harm than good. I like the idea @CreativeTechGuy described tho, so we could give some hint to the user if the plugin is not sure about reporting a testing file, but I'll leave it as a nice to have to be discussed in the future after v4 is released. I'm closing this issue then in favor of creating a new one removing this mechanism. Thanks guys, specially @MichaelDeBoey for starting to test an alpha of v4 and making me rethink about all this stuff! PS: at least I can use my massive message here as a draft for writing some documentation for next version of the plugin 😅 |
I know how it feels to put a bunch of work into something and then realize it's not the right direction. Real bummer. But I think you're making the right call 👍 Thanks for being receptive to the feedback! |
No problem. I'm more worried about having some sanity checks around this kind of decisions than delete code to be honest. I've been writing this new version for so long that I don't know if what I'm doing makes sense anymore 🙃 . Thanks for your help mates, really appreaciate it. |
I think we could indeed add this as a nice to have after v4 is released. |
Relates to #198
After discussing this with @MichaelDeBoey and rethinking about using micromatch instead of regexp, I decided to switch this since
ESLint.getFileName()
returns not just the filename itself but its path (I had to put a console.log in an alpha version to verify this). Since I have the whole path then, I can match more than just the filename for reporting Testing Library files or not, so the plugin will match same as Jest by default: files under__tests__
folder or files with.spec
or.test
suffix.