If you take a look at this repo, awesome-eslint, and you will notice there are tons of plugin and rules for Eslint. You may wonder what is the Eslint plugins or configs that you can use for your React Native project. Today, I'm going to share with you some basic Eslint plugins that you can have for your React Native project.
Standard Eslint for React Native
Eslint Plugin for React Native
On top of React, this plugin provide extra few linting particularly for React Native, such as no-unused-styles, no-inline-styles, split-platform-components.
Eslint Plugin for React Hooks
In React 16.8, Facebook introduce React Hooks, where you can use state and other features of React without a Class. It's also allow sharing of state logic across components. Together with React Hooks, Facebook also introduce this Eslint plugin to enforce the rules of Hooks. If you plan to use Hooks, you are highly recommended to install this plugin.
Eslint Plugin for Jest
Jest is a testing framework that widely use for React and React Native applications, it's easy to setup and most importantly, it has snapshot assertion that allow you to test for large object, for example, your React component. This plugin basically will help to guide and lint your Jest tests.
Eslint Plugin for Flowtype
That is all the basic Eslint plugins and configs for React Native, but what if you are working with many React Native projects and you want to adopt these Eslint plugins into all the projects? You will need to install all of them one by one and rewrite all the rules again? I beg you will get yourself crazy with that....
Create Shareable Eslint Config
To avoid duplicate work on settings up Eslint in your projects, you can create a shareable config that allow you to keep all your projects using the same Eslint configuration. First, let's start with create a new Node.js module by create a folder and run npm init, remember to name the package with eslint-config-<your config name> as that is the standard for Eslint shareable config.
Next, create a index.js and put all your rules in the file, for example:
To test your config before publish, you can run npm link in your shareable config folder, and run npm link eslint-config-<your config name> in the project that you want to use the config. Then, you need to update your project's eslintrc.js by extending the shareable config.
Now you should able to test your shareable config in your local machine. Before you want to publish your shareable config, you need to add the dependencies in package.json, at least, you need to define the minimum Eslint version you depending on.
Now, you can run npm publish and your shareable config are now ready to use! In the end of the reading, I hope it's give you some clues on how to create a shareable config for your project or organisation.
Lastly, I have created the shareable Eslint config for React Native, eslint-config-react-native-standard, please feel free to use or contribute. Thank you for reading!
Did you ever have an experience where you automate the build of your games with Unity Cloud Build, but eventually you realise that you forgot to update the build number for iOS and version code for Android? Then, you have to edit the PlayerSettings and wait for the build again....
If you have a same nightmare, don't worry, i have a solution for you.
I think many of you already know that if you set Android version code to 0 in PlayerSettings, Unity will help to populate the version code with "build number" from the Unity Cloud Build. However, that is not the case for iOS. Luckily, you can use PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest) method to make some modification before Unity export the build.
First, create a file in Asset > Editor > AutoIncrementVersionCodeInCloudBuild.cs and put the following code in the script
You will notice that I wrap the whole function with #if UNITY_CLOUD_BUILD because the BuildManifestObject can only access in Unity Cloud Build. This is very important if you wish to build the game in your local machine too. You may refer to the Github repo for complete scripts.
Next, you need to tell Unity Cloud Build to run the PreExport method. Go to your Unity Cloud Build console > Cloud Build > Config > Advanced Settings and put the value "AutoIncrementVersionCodeInCloudBuild.PreExport" in PreExport Method Name.
Now if you build again, you should see your APK or iPA will fill the version code or build number with Unity Cloud Build's build number. Now, you no need to worry about updating the those values every time!