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

Strictness migration #3210

Merged
merged 4 commits into from
Apr 24, 2020
Merged

Strictness migration #3210

merged 4 commits into from
Apr 24, 2020

Conversation

ds300
Copy link
Contributor

@ds300 ds300 commented Apr 21, 2020

The approach taken here is as was discussed in slack

i.e.

  1. Switch strict mode on in tsconfig.json
  2. Suppress all the errors that are created as a result, tagging the locations with STRICTNESS_MIGRATION in comments
  3. Add tooling to prevent new instances of STRICTNESS_MIGRATION from appearing
  4. Add tooling to encourage folks to fix existing STRICTNESS_MIGRATION issues

DX Changes

  • We are temporarily requiring PRs to be up-to-date before merging, because if people forget to update their branches it will cause type errors in master.

  • Life will be harder at first. Strict mode definitely has a learning curve, but once you get up to speed it will barely be noticeable, and will be a big win for preventing run time bugs and increasing maintainability.

  • The biggest source of pain will probably be dealing with Metaphysics data.

    MP was not written with strictness in mind so there are lots of places where fields that shouldn't be nullable are in fact nullable. The good news is that it's not a breaking change to make nullable fields non-nullable, and it should be pretty straightforward to do.

  • If you want to be extra helpful in refactoring older code to be strict you can run

    touch .i-am-helping-out-with-the-strictness-migration
    

    and then an extra check will be added to your pre-commit hook. This check will fail if any of your staged files have STRICTNESS_MIGRATION tags inside, so you are encouraged to spend a few minutes cleaning them up.

    Note that this is opt-in. If you want to be heads-down on shipping product rather than improving old code, that takes priority.

  • If you add any STRICTNESS_MIGRATION tags, e.g. by copy-pasting code, CI will fail.

@ds300 ds300 self-assigned this Apr 21, 2020
@ds300 ds300 force-pushed the strictness-migration branch 4 times, most recently from 9e2959a to c8b01d4 Compare April 22, 2020 11:02
Copy link
Contributor

@ashfurrow ashfurrow left a comment

Choose a reason for hiding this comment

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

This is really cool, thanks David!

const _ = require("lodash")
const path = require("path")

const HERO_HELPER_FILENAME = ".i-am-helping-out-with-the-strictness-migration"
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

command: |
set -e
current_issues=$(node scripts/strictness-migration.js count)
git checkout origin/master
Copy link
Contributor

Choose a reason for hiding this comment

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

My initial thought was this would go nicely in a Danger rule, but this actually makes way more sense as its own build step, since we don't need to worry about changing the git head back or anything 👍 The only benefit a Danger rule would have is the ability to report back to the PR in a comment. To do it, I think we'd need to run Danger in its own job like this anyway.

@@ -28,12 +29,12 @@ export const FilterModalNavigator: React.SFC<FilterModalProps> = props => {

const handleClosingModal = () => {
dispatch({ type: "resetFilters" })
closeModal()
closeModal?.()
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird that we need the ., but that might be my Swift bias. In Swift, we'd write this as closeModal?()

@@ -15,7 +15,7 @@
"plugins": [{ "name": "typescript-styled-plugin" }],
"pretty": true,
"resolveJsonModule": true,
"strict": false,
"strict": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@ds300
Copy link
Contributor Author

ds300 commented Apr 23, 2020

@ashfurrow if this is 🍏for you then I'll fix the conflicts and merge tomorrow morning UK time, then socialise the info in the PR description in #front-end-ios. Sound good?

@ashfurrow
Copy link
Contributor

@ds300 Yeah, looks good to me! Merging in the morning UK time works, to avoid merge conflicts, and then we'll have the FE iOS Practice meeting in the morning NYC time, to catch people up 👍

530583e79e4fc7f75855995d511e185c

@ds300 ds300 force-pushed the strictness-migration branch from c8b01d4 to 164a2aa Compare April 24, 2020 09:57
@ds300 ds300 merged commit 568d2fa into master Apr 24, 2020
@ds300 ds300 deleted the strictness-migration branch April 24, 2020 10:09
@ashfurrow ashfurrow changed the title [HOLD] Strictness migration Strictness migration May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants