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: update eslint + prettier rules #254

Merged
merged 18 commits into from
Oct 10, 2019
Merged

chore: update eslint + prettier rules #254

merged 18 commits into from
Oct 10, 2019

Conversation

ftonato
Copy link
Contributor

@ftonato ftonato commented Oct 6, 2019

Summary:

  • Add a more opiniated linter: Prettier

Closes #253

@CLAassistant
Copy link

CLAassistant commented Oct 6, 2019

CLA assistant check
All committers have signed the CLA.

@amaury1093
Copy link
Member

Thanks! I hope it was clear in the issue, but the scope of #253 also contains fixing the ~500 linting issues we have now.

@ftonato
Copy link
Contributor Author

ftonato commented Oct 6, 2019

Hey there,
I saw it, but I prefer to separate things and I'll send another Pull-request with these fix, hold for that... ⏳

@amaury1093
Copy link
Member

Ah, I see! I would still prefer 1 PR for all this, because I will not merge a PR with a red CI.

@ftonato
Copy link
Contributor Author

ftonato commented Oct 6, 2019

Ahh okay okay, just wait for it (please). I'll fix here =)

@ftonato
Copy link
Contributor Author

ftonato commented Oct 7, 2019

Hello @amaurymartiny,

I have a few doubts about this linting issues, let me know what do you think about them:

Some of the most common errors:

  1. (33 occurrences) Forbidden non-null assertion @typescript-eslint/no-non-null-assertion
  2. (02 occurrences) Type assertion on object literals is forbidden, use a type annotation instead @typescript-eslint/no-object-literal-type-assertion

Some of the most common warnings:

  1. (173 occurrences) Missing return type on function @typescript-eslint/explicit-function-return-type

I think we can ignore this for a while, disabling the rule for all files, right?

  1. (33 occurrences) Unexpected any. Specify a different type @typescript-eslint/no-explicit-any

In the file App/Screens/Search/fetchAlgolia.ts#47, we have the following problem:
What is the impact of changing this to a camel case?

@amaury1093
Copy link
Member

amaury1093 commented Oct 7, 2019

(33 occurrences) Forbidden non-null assertion @typescript-eslint/no-non-null-assertion

This one is important! It might catch some bugs, so I wish to keep it.

Basically, for example https://github.com/amaurymartiny/shoot-i-smoke/blob/9641cf6437f9043fd95295a67f8ebcb77687fdc0/App/Screens/Home/Home.tsx#L44

you would need to write:

if (!api) {
  throw new Error('Home.tsx only reachable when `api` is defined.'); // Or some message like this
}

const cigarettesPerDay = api.shootISmoke.cigarettes; 

(02 occurrences) Type assertion on object literals is forbidden, use a type annotation instead @typescript-eslint/no-object-literal-type-assertion

I would like to keep these two too. I didn't find where they were, if you need help for those two I can have a look too.

Warnings

This PR seems bigger than I thought. In this case you can do

  rules: {
    '@typescript-eslint/no-explicit-any': 0,
    '@typescript-eslint/explicit-function-return-type': 0
  },

for now in .eslintrc.js, we can do those in a separate PR.

In the file App/Screens/Search/fetchAlgolia.ts#47, we have the following problem:
What is the impact of changing this to a camel case?

Algolia gives snake_case here, so here the only solution would be a eslint-disable-next-line

add rule to avoid warnings with:

  - @typescript-eslint/explicit-function-return-type
  - @typescript-eslint/no-explicit-any
  - react/prop-types
@ftonato
Copy link
Contributor Author

ftonato commented Oct 8, 2019

I found these errors:

  • App/Screens/Screens.tsx
    44:10 error Type assertion on object literals is forbidden, use a type annotation instead @typescript-eslint/no-object-literal-type-assertion

  • App/stores/fetchGpsPosition/fetchGpsPosition.ts
    48:10 error Type assertion on object literals is forbidden, use a type annotation instead @typescript-eslint/no-object-literal-type-assertion

Do you have any suggestion or would you like to fix them?

Copy link
Member

@amaury1093 amaury1093 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 very, very, very cool. Thanks a lot 🎉

Some little nits:

  • replace all && || with ?:
  • replace if (currentLocation === undefined || !Object.keys(currentLocation).length) with simply if(!currentLocation) is enough

App/stores/fetchGpsPosition/fetchGpsPosition.ts

You can remove the as Location cast

App/Screens/Screens.tsx

You can replace the function with

function stackNavigatorOptions(
  initialRouteName: string
): CreateNavigatorConfig<
  NavigationStackConfig,
  NavigationStackRouterConfig,
  NavigationStackOptions,
  NavigationStackProp<NavigationRoute, any>
> {
  return {
    cardStyle: {
      backgroundColor: theme.backgroundColor
    },
    headerMode: 'none',
    initialRouteName,
    defaultNavigationOptions: {
      // FIXME the `headerVisible` field has been moved away from this config
      // @ts-ignore
      headerVisible: false
    }
  };
}

And after that I think we're ready to merge!

.eslintrc.js Outdated Show resolved Hide resolved
App/Screens/Details/Details.tsx Outdated Show resolved Hide resolved
App/Screens/Details/Details.tsx Outdated Show resolved Hide resolved
App/Screens/Home/Footer/Footer.tsx Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Member

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

Looks good! Just tested the code, nothing broke, so that's perfect.

I'll merge once the CLA is signed and conflicts solved.

@ftonato
Copy link
Contributor Author

ftonato commented Oct 8, 2019

Time to merge my friend 🦄

@amaury1093
Copy link
Member

Thanks, almost there but not yet! There are 2 errors on Travis, surely because of the master merge. The DistanceUnit type comes from stores/distanceUnit.tsx now

@ftonato
Copy link
Contributor Author

ftonato commented Oct 8, 2019

My bad, I did merge using GitHub instead of the command-line interface, but I hope that it's correct now 🚀 🔬

Copy link
Member

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

There are some regression errors due to merge.

App/Screens/About/About.tsx Outdated Show resolved Hide resolved
App/Screens/Home/Header/Header.tsx Outdated Show resolved Hide resolved
App/Screens/Details/Distance/Distance.tsx Outdated Show resolved Hide resolved
App/Screens/Home/Header/Header.tsx Outdated Show resolved Hide resolved
App/Screens/About/About.tsx Outdated Show resolved Hide resolved
App/Screens/ErrorScreen/ErrorScreen.tsx Outdated Show resolved Hide resolved
App/Screens/ShareScreen/ShareScreen.tsx Outdated Show resolved Hide resolved
Copy link
Member

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

Sorry, 2 more merge errors. Should be the last 2 ones!

App/Screens/Home/Footer/Footer.tsx Outdated Show resolved Hide resolved
App/Screens/Details/Details.tsx Show resolved Hide resolved
@ftonato
Copy link
Contributor Author

ftonato commented Oct 10, 2019

I will never merge again using GitHub 🐛

Copy link
Member

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

This time everything looks good! A huge thanks to you @ftonato

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.

Add a more opiniated linter: Prettier
3 participants