Skip to content

Latest commit

 

History

History
98 lines (71 loc) · 3.29 KB

developer_guide.md

File metadata and controls

98 lines (71 loc) · 3.29 KB

To adapt a code quality guideline similar to Python's PEP8 for TypeScript projects, you'll want to establish a set of coding standards, linting tools, and formatting tools appropriate for TypeScript. Common tools for enforcing code quality in TypeScript projects include ESLint for linting, Prettier for formatting, and optionally, pre-commit hooks to automate checks before commits.

Here’s how you could set up and describe these practices for a TypeScript project:


Code Quality

For our TypeScript projects, we adhere to best practices and coding standards enforced through ESLint and formatted with Prettier. We also utilize pre-commit hooks to ensure code quality and consistency before commits are made.

Setting Up ESLint

ESLint is a popular linting tool for JavaScript and TypeScript that helps identify problematic patterns or code that doesn’t adhere to certain style guidelines.

  1. Install ESLint and TypeScript ESLint Plugin:

    npm install eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin --save-dev
  2. Create an ESLint configuration file: You can create a .eslintrc.json file in the root of your project with rules tailored to your needs. Here is a basic example:

    {
      "parser": "@typescript-eslint/parser",
      "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
      "parserOptions": {
        "ecmaVersion": 2020,
        "sourceType": "module"
      },
      "rules": {
        // Define your own rules, or override defaults here
      }
    }

Setting Up Prettier

Prettier is an opinionated code formatter that supports many languages and integrates with most editors. It can be run from the command line or included as part of your build process.

  1. Install Prettier:

    npm install --save-dev prettier
  2. Create a Prettier configuration file: You can set up a .prettierrc file to define formats. Here's a simple example:

    {
      "semi": true,
      "singleQuote": true
    }

Integrating with Pre-commit Hooks

Pre-commit hooks can be used to run ESLint and Prettier before each commit, ensuring that only code that meets quality standards is committed.

  1. Install pre-commit:

    npm install --save-dev pre-commit
  2. Update package.json: Add a pre-commit section in your package.json to define the hooks.

    "pre-commit": [
      "lint",
      "format"
    ],
    "scripts": {
      "lint": "eslint 'src/**/*.ts'",
      "format": "prettier --write 'src/**/*.ts'"
    }
  3. Install husky (optional but recommended for better hook management):

    npx husky-init && npm install
    npx husky add .husky/pre-commit "npm run lint && npm run format"

Documentation and Resources


This setup ensures that your TypeScript code is linted for potential errors and is consistently formatted according to the project's style guidelines, much like how Python projects might use PEP8, flake8, and pre-commit hooks.

Testing

TODO