Coder Social home page Coder Social logo

prettier-setup's Introduction

prettier-setup Twitter Follow

This project sets up formatting and linting tools to keep your code clean and consistent, so you never have to argue about style again:

  • Prettier is an opinionated code formatter that enforces a consistent style by parsing your code and re-printing it with its own rules.
  • ESLint checks JavaScript code for stylistic or programming errors.
  • Husky uses Git hooks to ensure that Prettier and ESLint run on all staged changes to fix files before committing.

The setup described here will format JavaScript, JSON, Sass, and Markdown files, but you can adjust the settings to your own needs.

Installing ESLint and Prettier

This step adds ESLint and Prettier to your project's dependencies so they're available locally regardless of the system configuration.

Install with yarn

yarn add eslint-{config,plugin}-prettier eslint prettier --dev --exact
Install with npm

npm install eslint-{config,plugin}-prettier eslint prettier --save-dev --save-exact

Set up the scripts

Open the package.json file in your project and add the following scripts* entries:

"scripts": {
  "fix:other": "yarn prettier --write",
  "fix:js": "yarn test:js --fix",
  "fix": "yarn fix:js && yarn fix:other",
  "prettier": "prettier --ignore-path .gitignore  \"**/*.{json,md,scss}\"",
  "test:other": "yarn prettier --list-different",
  "test:js": "eslint --ignore-path .gitignore --ignore-path .prettierignore \"**/*.{js,jsx}\"",
  "test": "yarn test:other && yarn test:js"
}

* If you are using npm, replace yarn with npm run in the above section.

Installing Husky and commit hooks

Set up Husky and the lint-staged commit hooks to format changed files before each commit.

Install with yarn

yarn add husky lint-staged --dev --exact
Install with npm

npm install husky lint-staged --save-dev --save-exact

Set up the rules

Add the lint-staged rules to the package.json file in your project:

"lint-staged": {
  "*.{js,jsx}": ["eslint --fix", "git add"],
  "*.{json,md,scss}": ["prettier --write", "git add"]
},

Add the precommit hook to the scripts:

"scripts": {
  "precommit": "lint-staged"
}

Prettier rules

This project defines the following settings in the .prettierrc.yaml file. You can adjust these values according to your own preferences.

Rule Value*
arrowParens avoid
bracketSpacing false
jsxBracketSameLine false
printWidth 80
proseWrap preserve
requirePragma false
semi true
singleQuote true
tabWidth 2
trailingComma all
useTabs false

* Values in bold differ from the Prettier defaults.

ESLint rules

Adjust your own rules by updating the .eslintrc.yaml.

Dependencies

prettier-setup's People

Contributors

lipis avatar dependabot[bot] avatar greenkeeper[bot] avatar yserz avatar infotexture avatar

Watchers

Anikeychik Dmitry avatar

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.