Skip to content

Code Style & Linting Guidelines

Danilo Joksimovic edited this page Oct 10, 2019 · 1 revision

Code Style

Table of Contents

  1. Asynchronous Functions
  2. Dependencies
  3. Imports
  4. Linting

Asynchronous Functions

  • Always use async/await instead of .then()
  • Wrap async operations in try/catch blocks

Dependencies

  • USE YARN instead of npm
  • If you see npm install or npm i -> use yarn add instead
  • See yarn --help for info on commands
  • If dependencies aren't needed in production -> yarn add <package-name> --dev

Imports

  • Keep imports inline unless there are a lot from the same directory
  • Separate package imports, local imports, and asset imports
  • Export files respectively in the index.js of each sub-directory (e.g. app/screens/index.js)

Linting

Run npm run lint and fix any lint errors before pushing any code

Make sure eslint is installed: eslint --version

Follow These Instructions for Visual Studio Code

  1. Install the eslint VS Code extension
  2. Add the following line to your VS Code settings (srvice-api/.vscode/settings.json):
    • "eslint.options": { "configFile": "<Path to .eslintrc.js>" }
  3. Open your VS Code settings (Cmd + , / Ctrl + ,)
  4. Click on srvice-api folder settings
  5. Select the Extensions drop-down menu in the left side-bar of the Settings page
  6. Make sure the Eslint: Enable checkbox is selected
  7. Cmd + Shift + P / Ctrl + Shift + P -> Reload -> Developer: Reload Window

Follow These Instructions for Webstorm

  1. Open Preferences (Cmd + ,)
  2. Search for "eslint" (Languages & Frameworks > JavaScript > Code Quality Tools > ESLint)
  3. Select "Manual ESLint configuration"
  4. Make sure Node Interpreter isn't empty
  5. Set "ESLint package" to <path of srvice-api/node_modules/eslint>
  6. Set "Configuration file" to <path to srvice-api/.eslintrc.js>

Clone this wiki locally