thesis / prettier-config

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

prettier-config

Prettier code formatter configuration shared across Thesis projects.

Usage

Setting up a project

  1. Install dependencies:

      yarn add --Dev github:thesis/prettier-config prettier
  2. Configure prettier:

    The easiest way to configure prettier to use this configuration is to define prettier property in the project’s package.json:

    "prettier": "@thesis/prettier-config"

    For more sophisticated configuration instead of adding this entry add a configuration file (see: Plugins section).

  3. Define scripts property in package.json, e.g.:

    "scripts": {
      "lint:config": "prettier -c '**/*.@(json|yaml|toml)'",
      "lint:config:fix": "prettier -w '**/*.@(json|yaml|toml)'",
    }

    For JavaScript and TypeScript Thesis projects should use prettier-eslint integration in @thesis/eslint-config.

  4. Run yarn lint:config or yarn lint:config:fix

Plugins

To handle .sh or .toml files you need to install dedicated plugins:

  • for sh: yarn add --Dev prettier-plugin-sh

  • for toml: yarn add --Dev prettier-plugin-toml

And configure the plugins usage in .prettierrc.js, e.g.:

module.exports = {
  ...require("@thesis/prettier-config"),
  plugins: ["prettier-plugin-sh", "prettier-plugin-toml"],
}

Adding a pre-commit hook

This solution is using pre-commit.

- id: format
  name: "code config formatting"
  entry: /usr/bin/env bash -c "npm run lint:config"
  language: script
  description: "Checks files formatting with prettier"

About

License:MIT License