Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Prettier to format files before git commit #466

Closed
kalpeshsingh opened this issue Sep 2, 2020 · 1 comment
Closed

Introduce Prettier to format files before git commit #466

kalpeshsingh opened this issue Sep 2, 2020 · 1 comment

Comments

@kalpeshsingh
Copy link
Contributor

kalpeshsingh commented Sep 2, 2020

This is part of main issue #457

Motivation

When multiple people contribute then it gets out of hand when we don't enforce code formatting. We can use tools like Prettier to make formatting consistent in a codebase without manual effort.

Steps to achieve

Assuming you have prettier at global level.
  • Add .prettierrc file for configuration (feel free to add your team's decided configuration)
{
  "singleQuote": true,
  "useTabs": true,
  "tabWidth": 2
}
  • Add npm script
  "scripts": {
    ...
    "format": "prettier --write"
  },
  • Update lint-staged configuration

Before

  "lint-staged": {
    "*.{js,vue}": [
      "vue-cli-service lint",
      "git add"
    ]
  }

After

 "lint-staged": {
    "*.{js,vue}": [
      "vue-cli-service lint"
    ],
    "*.{js,vue,json,css,md}": [
      "npm run format"
    ]
  }

Additional changes

  • Upgraded lint-staged to ^10.3.0 (so we don't need to use "git add in lint-staged)
  • Added prettier so developers don't need to install it at global level

🚧 Words of caution

  • You need to run npm run format to fix existing formatting issues in all the files. I want to give this opportunity to one of the contributor as it will affect 132 files will require a sanity testing.
kalpeshsingh added a commit to kalpeshsingh/frontend.social that referenced this issue Sep 2, 2020
add prettier script, configuration file and add it in lint-staged to format and again add formatted
files during git commit

shoonyatech#466
kalpeshsingh added a commit to kalpeshsingh/frontend.social that referenced this issue Sep 2, 2020
add prettier script, configuration file and add it in lint-staged to format and again add formatted
files during git commit

shoonyatech#466
souvikbasu pushed a commit that referenced this issue Sep 8, 2020
add prettier script, configuration file and add it in lint-staged to format and again add formatted
files during git commit

#466
@kalpeshsingh
Copy link
Contributor Author

Closing this as PR is merged.
Thank you @souvikbasu 🥳

kalpeshsingh added a commit to kalpeshsingh/frontend.social that referenced this issue Sep 26, 2020
add prettier script, configuration file and add it in lint-staged to format and again add formatted
files during git commit

shoonyatech#466
kalpeshsingh added a commit to kalpeshsingh/frontend.social that referenced this issue Sep 26, 2020
* chore: enforce commit message formate using commitlint

shoonyatech#475

* build(frontend.social): add prettier to format files

add prettier script, configuration file and add it in lint-staged to format and again add formatted
files during git commit

shoonyatech#466

* Prettier integration (#3)

* chore(package.json): add prettier and remove file glob from format script

* chore(package.json): updgrade lint-stage dependency for improvement

* chore: enforce commit message formate using commitlint

shoonyatech#475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant