Javascript: ESLint returns "no-unused-expressions" error with LayoutAnimation documentation code snippet

Created on 16 Aug 2019  路  5Comments  路  Source: airbnb/javascript

I'm an intern at my company, and was recently tasked with fixing the ESLint errors of the code (a true intern job). That said, I'm still a beginner with React native, so any mistakes I make, please correct me.

In the app, LayoutAnimation is used in lots of screens, and according to the React Native's documentation, for Android support, the following line must be added:

UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);

Since it's an Android specific configuration, I've put it in the beggining of the constructor, only running if the Platform being used is Android.

But it then returns an ESLint error:

ESLint: Expected an assigenment or function call and instead saw an expression.(no-unused-expressions)

After some research, by using allowShortCircuit in the .eslintrc config, I'm able to bypass this error, but I wouldn't like to change it for the entire project/file. Would there be any way to rewrite this snippet so that this error wouldn't occur?

For a snippet in the documentation to trigger an error in ESLint is kinda strange...

I'm using ESLint 4.17.0

question

All 5 comments

Yes, it's best not to abuse value selection operators for flow control.

if (UIManager.setLayoutAnimationEnabledExperimental) {
  UIManager.setLayoutAnimationEnabledExperimental(true);
}

I imagined It would be something like this, but since I haven't actually implemented a Layout Animation I was kinda insecure about changing something present in the official documentation.

Thx for the help

np!

I'd even suggest making a PR to the docs to make it match idiomatic JS code style (which is never to use && when an if will do)

Where would I do this though?

https://github.com/facebook/react-native-website/blob/master/docs/layoutanimation.md - there's an "edit" button on the upper right corner of the docs webpage.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tunnckoCore picture tunnckoCore  路  3Comments

ar
mbifulco picture mbifulco  路  3Comments

kozhevnikov picture kozhevnikov  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

danielfttorres picture danielfttorres  路  3Comments