Skip to content

Latest commit

 

History

History
200 lines (141 loc) · 4.77 KB

File metadata and controls

200 lines (141 loc) · 4.77 KB

<   JavaScript Project Setup Conventions

The purpose of this document is to outline the code conventions used by all Edge JavaScript projects. It lists the recommendations for utilities, formatting, scripts, etc.


Package Management

We use Yarn v1 to manage our package dependencies. All repositories should commit a .yarnrc file with at least the following:

--ignore-scripts true

This will prevent scripts from running during package installation. As a security measure, we do not allow scripts to run after package installation. All build scripts should run with yarn prepare, separate from yarn.

Security Configuration

Every developer must run yarn config set ignore-scripts true on their local development environment. This prevents scripts from running during package installation for any project missing a properly configured .yarnrc (whether Edge's repo or a 3rd-party's). A shell alias which combines yarn install and yarn prepare may be added to a developers shell config for convenience. For example, add to your .zshrc or .bashrc:

alias yip='yarn && yarn prepare'

Testing

Usage

// package.json
"test": "jest"

Back to the top


Type Checking

Usage

// package.json
"flow": "flow"

Back to the top


 

Commit Hooks

      Installing

yarn add -D husky

Usage

// package.json
"pre-push": "yarn test"

Back to the top


 

Formatting

  • eslint-config-standard-kit - github

  • Eslint - github

  • Prettier - github

  • Lint-staged - github

  • Import-sort - github

  • Sort-package-json - github

    • Installing
    yarn add sort-package-json import-sort-cli import-sort-style-module prettier-eslint-cli lint-staged
    • Usage
    // package.json
    "scripts": {
      "format": "sort-package-json; import-sort -l --write '*.js' 'src/**/*.js'; prettier-eslint --write '*.js' 'src/**/*.js'",
      "precommit": "lint-staged"
    },
    "prettier": {
      "printWidth": 120
    },
    "lint-staged": {
      "*.js": ["yarn format", "git add"]
    },
    "importSort": {
      ".js, .es": {
        "parser": "babylon",
        "style": "module"
      }
    }

Back to the top


 

Dependencies

All dependencies should be defined with their full URLs or NPM package version. GitHub short-hand URLs should not be used due to an outstanding issue with Yarn not running prepare/prepack for these types of dependencies.

Do

{
  "dependencies": {
    "react": "^17.0.1",
    "edge-currency-accountbased": "git://github.com/EdgeApp/edge-currency-accountbased.git#v0.7.33"
  }
}
Don't
{
  "dependencies": {
    "edge-currency-accountbased": "EdgeApp/edge-currency-accountbased#v0.7.33"
  }
}

Back to the top


 

Scripts

Each repo should have the following package.json scripts which accomplish the following:

  • build: If necessary, run rollup, webpack, and flow-copy to populate lib folder. Should not run any lint, flow checking, or tests
  • flow: Run flow
  • lint: Run standard.js or equivalent and flow
  • test: Run lint and flow. Flow should exclude *.js.flow files. Lastly run mocha or jest tests
  • precommit: Run build then test
  • prepare: Run build

Back to the top