Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Add prettier + eslint #89

Merged
merged 3 commits into from
Jun 20, 2018
Merged

Conversation

fathyb
Copy link
Contributor

@fathyb fathyb commented Jun 20, 2018

This PR adds prettier-eslint, which is just prettier with its output piped to eslint --fix. js files are formatted using eslint rules, while md and json files only using prettier.

husky is added to setup a Git precommit hook, and lint-staged to only check staged files. This will make sure every commit is properly formatted and passes the lint test. This can be bypassed by using the Git commit --no-verify option.

A format script is added to run prettier on all files.

Demo


https://segment.atlassian.net/browse/LIB-413
cc @f2prateek

@fathyb fathyb force-pushed the chore/add-prettier branch from 8042641 to 12f490a Compare June 20, 2018 04:45
@@ -2,7 +2,7 @@ version: 2
jobs:
test:
docker:
- image: circleci/node:4-browsers
- image: circleci/node:8-browsers
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to upgrade to 8 for lint-staged, see CI Job#14

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this have any effect on the final functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final artifact is built by the analytics.js repo so it should only affect tests

@fathyb fathyb force-pushed the chore/add-prettier branch from 12f490a to 50b6f86 Compare June 20, 2018 04:55
@@ -1,3 +1,3 @@
{
"extends": "@segment/eslint-config/browser/legacy"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we still need to keep the old config around?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should, browser/legacy ensures we are only using ES3 compatible code which we can't really guarantee otherwise given we don't use any transpilers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, that makes sense - we definitely need that 🙏

@@ -58,12 +58,13 @@ distclean: clean

# Lint JavaScript source files.
lint: install
@$(ESLINT) $(ALL_FILES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're not using ESLint anymore in the makefile, we could remove it from line 5 as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today's free tip: with newer versions of yarn you can directly invoke bin programs.
Example: yarn codecov instead of ./node_modules/.bin/codecov

@@ -0,0 +1,3 @@
{
"singleQuote": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? What does it do? I see our internal app codebase using single quotes but not have this prettier rule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nvm, they pass it as an option in the binary instead: /prettier --write --single-quote --no-semi 'src/**/*.js'. I like putting it the config better 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove it prettier will use double quotes when formatting. It could also be in .eslintrc and package.json IIRC. I've put it in this file so editor plugins can use this setting.

Copy link
Contributor

@f2prateek f2prateek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of questions but looks great overall.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants