Whether you work in a company, a big team or by yourself, having consistently formatted code is significant for maintainability and readability. Also, there are tons of ways and this is the standard way and most developers should look into it.
Too Long; Didn’t Read
Most developers know the tool of
Prettier because it is very easy to use and it makes sense to run the command.
npm run prettier
However, we will forget or sometimes when you push to pipeline, you realize the problem that you didn’t run the prettier before you commit. Or sometimes, the VPS you used does not have
prettier or nothing like
linter install. That means it will make your pipeline fail.
Check out the Emberjs Application repo:
demo: https://bloging.netlify.com/ or: https://shijiezhou1.github.io/Ember-Blog/ TL;DR; This README outlines the…
The major issue is that you forget to format the Ember Code, it can create the mess that other developers may have a problem reading the code. See. e.g.
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router
export default Router;
As you can see, the code above does not make use to read easily.
Format Code Like Pro:
Is that an easier way to format your code without using any IDE like VS Code, IntelliJ, NetBeans, or Eclipse when you commit your project to Github/GitLab/Bitbucket? Of course, that can be as simple as it is.
So, there are three packages you need to install before :
npm i husky prettier pretty-quick --save-dev
Now you should see the package that installs on your Emberjs:
"husky": "^3.1.0","prettier": "^1.19.1","pretty-quick": "^2.0.1"
Once you have all those packages installed, there is one last step before you will make your commit much efficient.
prettier": "prettier --write \"app/*/*.js\""
"pre-commit": "npm run prettier && pretty-quick --staged && git add ."
Now you are all set up! Test out by running this on your ember project.
git add .
git commit -m 'automation format'// output
🔍 Finding changed files since git revision 123456.
🎯 Found 0 changed files.
✅ Everything is awesome!
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Check out full repo on the Link to see how easy it is.