Git Product home page Git Product logo

typescript-eslint-prettier-config's Introduction

npm version format lint

typescript-eslint-prettier-config

Minimal Typescript, ESLint and Prettier configuration.

ESLint and Prettier configurations are pretty standard in Javascript world. The intention of this package is to create a minimal setup with recommendations for eslint and prettier from the authors. According to them, we don't even need advance plugins that tries to get the best of both the worlds. Typescript config is cherry on top and gels easily with them.

Installation

To install:

npm i -D typescript eslint prettier typescript-eslint-prettier-config

or

yarn add -D typescript eslint prettier typescript-eslint-prettier-config

How to use this package

  1. To extend your existing Typescript configuration

**/tsconfig.json

{
    "extends": "**/node_modules/typescript-eslint-prettier-config/tsconfig.json",
    "compilerOptions": {
        ...
    },
    "exclude": ["**/node_modules/**", "build/**", "dist/**"],
    "include": ["src"] // include your src folder or use default
}
  1. To extend your existing ESLint configuration

**/.eslintrc

{
    "root": true,
    "extends": "**/node_modules/typescript-eslint-prettier-config/.eslintrc",
    "parserOptions": {
        "project": ["./tsconfig.json"] // this is your typescript configuration that you extended in the previous step
    }
}
  1. To extend your existing Prettier configuration

**/.prettierrc.ts

module.exports = {
    ...require('**/node_modules/typescript-eslint-prettier-config/prettier.config'),
};

Further ideas to use the setup optimally

VSCode

eslint --fix can be configured in the settings.json file in VSCode to automatically fix the linting errors. Also, adding formatOnSave runs Prettier every time you save.

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.organizeImports": true
  },
  "editor.formatOnSave": true
}

Lint staging

lint-staged in combination with husky can be used in package.json to avoid accidentally committing non-linted files on github.

{
  "husky": {
      "hooks": {
          "pre-commit": "lint-staged"
      }
  },
  "lint-staged": {
      "*.{js,jsx,ts,tsx}": [
          "eslint --fix"
      ],
      "*.{js,jsx,ts,tsx,json,yml,yaml,css,html}": [
          "prettier --write"
      ]
  }
}

Inspiration and Thanks

typescript-eslint-prettier-config's People

Contributors

actions-user avatar dependabot[bot] avatar github-actions[bot] avatar vsramalwan avatar

Stargazers

 avatar

typescript-eslint-prettier-config's Issues

run tsc command as part of lint-staged

Several options to fix this issue:

  • Use package tsc-files
  • Use eslint rule wrapper package eslint-plugin-tsc for ts files like here
  • Add lint-staged.config.js rule like e.g.:
module.exports = {
  "*.{js,jsx}": [
    "eslint --cache --fix",
  ],
  "*.{ts,tsx}": [
    () => "tsc --skipLibCheck --noEmit", 
    "eslint --cache --fix",
  ],
}```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.