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

chore: minor tidy up of code #603

Merged
merged 6 commits into from Jun 20, 2020
Merged

chore: minor tidy up of code #603

merged 6 commits into from Jun 20, 2020

Conversation

G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented Jun 19, 2020

I made a new eslint plugin for linting config files to check they're invalid, and for use of deprecated rules.

There's actually a couple of commits, but wanting to test out github actions annotations.

@G-Rath G-Rath force-pushed the update-linting branch 8 times, most recently from cdc1f24 to d7881f1 Compare June 19, 2020 03:59
package.json Outdated Show resolved Hide resolved
import rule, {
JestVersion,
_clearCachedJestVersion,
} from '../no-deprecated-functions';

const root = process.cwd();
afterEach(() => process.chdir(root));
Copy link
Member

Choose a reason for hiding this comment

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

process.chdir is not actually supported by Jest. It works since it's the real chdir, but it breaks a bunch of Jest's assumptions. Since it actually changes dir, it leaks between test files and the jest process itself.

It's not new though, so no need to change now. But something to keep in mind 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, which is what's happening here - turns out the tests I wrote for the rule are what's been causing the weird CI failure.

I'm not sure why it only happens on Node 8 & 10, but the issue is that by changing the cwd to be outside of the projects folder, when looking for plugins eslint looks into the node_modules in /tmp/eslint-plugin-jest-<tmpdir> while using the config from eslint-plugin-jest, and so fails to find all its plugins.

I hacked this together to confirm, so now I'll break it out into another PR, and then after that I should be able to merge & ship a bunch of our open PRs.

Copy link
Collaborator Author

@G-Rath G-Rath Jun 19, 2020

Choose a reason for hiding this comment

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

On an aside, is there anything we could do in jest core to improve process.chdir support?

One such idea that comes to mind would be to do that I'm doing here: "pin" the cwd as part of jest's setup phase, and then somehow make that available in places; or maybe even just using that as a mechanism to allow jest to spot it's changed, and give people a warning.

I'm not sure how worth it would be, but if there are any low hanging fruit that could be done to even just reduce a few of the assumptions, I'd be happy to explore :)

@G-Rath G-Rath force-pushed the update-linting branch 5 times, most recently from 1f5e5db to d8fe52e Compare June 20, 2020 01:10
@G-Rath G-Rath changed the title chore: adjust linting chore: minor tidy up of code Jun 20, 2020
@G-Rath G-Rath requested a review from SimenB June 20, 2020 01:39
@G-Rath
Copy link
Collaborator Author

G-Rath commented Jun 20, 2020

This is based off #591 so that tests pass consistently, so that PR should be merged first.

I enabled padding-line-between-statements configured to require a newline before returns, and after variable blocks, as imo it produces tidier code that's easier to read by introducing some natural grouping + it's auto-fixable (which I've applied); can drop that commit if there's disagreement.

I also used @typescript-eslint/no-unnecessary-condition to find some conditional checks that are redundant 🎉

@G-Rath G-Rath merged commit 2a8ac30 into master Jun 20, 2020
@G-Rath G-Rath deleted the update-linting branch June 20, 2020 11:11
@github-actions
Copy link

🎉 This PR is included in version 23.14.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants