software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.13k stars 982 forks source link

Unify comments and simplify some conditions. #2984

Closed m-bert closed 4 months ago

m-bert commented 4 months ago

Description

This PR changes 3 things:

  1. Unifies comments convention across ts/tsx files.

  2. Simplifies one return statement in GestureHandler on web

  3. Simplifies userSelect assignment in GestureHandlerWebDelegate

  4. leads to many changed files, so if you think that 2. and 3. deserve their own PRs I'll open them 😅

Comments

Changed things:

It also adds ESlint rule spaced-comment, which enforces spaces between // and comment content.

return

I've removed if condition and moved it right to return statement

Before ```tsx if ( offsetX >= left && offsetX <= right && offsetY >= top && offsetY <= bottom ) { return true; } return false; ```
After ```tsx return ( offsetX >= left && offsetX <= right && offsetY >= top && offsetY <= bottom ); ```

userSelect assignment

I've changed userSelect assignment in GestureHandlerWebDelegate to use ?? operator

Before ```tsx if (!config.userSelect) { this.view.style['webkitUserSelect'] = 'none'; this.view.style['userSelect'] = 'none'; } else { this.view.style['webkitUserSelect'] = config.userSelect; this.view.style['userSelect'] = config.userSelect; } ```
After ```tsx this.view.style['userSelect'] = config.userSelect ?? 'none'; this.view.style['webkitUserSelect'] = config.userSelect ?? 'none'; ```

Test plan

Verified that example app works as it used to.

m-bert commented 4 months ago

We can make a CI out of this

I've partially did this. I don't think adding CI for capital letters makes sense (for example we have some eslint-disable comments).

For the key part I've added new ESlint rule called spaced-comment - it enforces spaces after //. It will also catch /// stuff and similar problems. Unfortunately it is not run with lint-staged so it won't be caught in pre-commit, but it will be checked on CI.