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

Add Prettier and ESLint standard configs #5

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

msanroman
Copy link
Member

@msanroman msanroman commented Jun 3, 2020

Purpose

Prettier

This is the standard Prettier config file for the projects within the https://github.com/bufferapp GitHub organization.

This was created by taking a look at Account, Publish, Authentication Service, Engage (backend), and Engage (frontend) and aiming for a minimal version that relies on Pretier defaults and uses the most common settings set already by our different teams.

There were repositories setting items with default values, such as tabWidth : 2 or bracketSpacing: true.

Eslint

This exposes two different ESLint configs: one for React frontends and another for Typescript backends. The aim here is to reduce external dependencies and have a minimal configuration that relies on standards based on the tools themselves rather than external companies (aka: eslint-airbnb).

These configurations omit any default setting for now.

Issues

Closes #1 and #2

Copy link

@esclapes esclapes left a comment

Choose a reason for hiding this comment

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

Hey @msanroman thanks for kick starting this work.

Regarding prettier, Core is only using it integrated with eslint via this plugin and config and not run independently for the following reasons:

  • eslint has two broad categories of rules: format and code check, while prettier only cares about format (and it's quite opinionated about it)
  • when working together it's possible to have rules conflicting, so eslint has a set of configs that help you disable the formatting rules from eslint and a plugin that allows you to check and fix formatting rules via prettier-eslint integration (basically eslint runs prettier under the hook).

If the next step in standardization is to have a common eslint setup, I'd find more value on bundling both eslint and prettier configuration in a single shared module.

However, I may be missing some cases where we will have prettier enabled and not eslint. If that's the case then this would be fine. 😄

Comment on lines 8 to 10
> npm install --save-dev @bufferapp/prettier-config
# or
> yarn add -D @bufferapp/prettier-config

Choose a reason for hiding this comment

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

If prettier is a peer dependency it would be great to include it in the install command.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeeeees! 🙌

@msanroman
Copy link
Member Author

Hey @msanroman thanks for kick starting this work.

Regarding prettier, Core is only using it integrated with eslint via this plugin and config and not run independently for the following reasons:

  • eslint has two broad categories of rules: format and code check, while prettier only cares about format (and it's quite opinionated about it)
  • when working together it's possible to have rules conflicting, so eslint has a set of configs that help you disable the formatting rules from eslint and a plugin that allows you to check and fix formatting rules via prettier-eslint integration (basically eslint runs prettier under the hook).

If the next step in standardization is to have a common eslint setup, I'd find more value on bundling both eslint and prettier configuration in a single shared module.

However, I may be missing some cases where we will have prettier enabled and not eslint. If that's the case then this would be fine. 😄

Yes! That's a very good one @esclapes . I was prepping an ESLint PR for kicking off the discussion for frontend and backend teams and sharing base settings between them, but maybe we can merge these into this.

Right now we have repos that don't have Prettier enabled at all, but the goal is to have both anywhere anyway 😄

@msanroman
Copy link
Member Author

@esclapes - just added eslint as a different package for now. As far as I can understand reading https://eslint.org/docs/developer-guide/shareable-configs, there would be some resolution issues if we were to package both things together.

Still, I think with documentation (and if needed, scripting) we could automate the installation of both if needed.

@msanroman msanroman changed the title Add Prettier standard config Add Prettier and ESLint standard configs Jun 12, 2020
@CoxyBoris CoxyBoris requested review from CoxyBoris and removed request for CoxyBoris June 19, 2020 05:29
Copy link

@CoxyBoris CoxyBoris left a comment

Choose a reason for hiding this comment

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

Heya @msanroman thanks for kicking this off!

There is a bunch of options I needed to add for Engage in order to remove some false errors or to make jest compatible with this configuration. I wonder if we should include this as well in this PR?

extends: [
"./index.js",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint"

Choose a reason for hiding this comment

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

Curious if we should use "plugin:prettier/recommended" as well? We've used it on Engage to displays prettier errors as ESLint errors.

plugins: [
"typescript-eslint",
],
parser: "@typescript-eslint/parser",

Choose a reason for hiding this comment

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

Had to use these option to have the parser working correctly. Not sure it's still necessary:
"parserOptions": { "ecmaVersion": 2018, "sourceType": "module" },

@CoxyBoris
Copy link

Hey @msanroman ! 👋 Curious if you've seen my comments on the PR :) No rush at all!

Copy link
Contributor

@philippemiguet philippemiguet left a comment

Choose a reason for hiding this comment

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

Hey @msanroman @CoxyBoris, as mentioned in #10, I have come up with some base configuration using what is in this repo + what was missing from core/engage that we find really useful.

What I have in my PR may represent and include the addition from Boris and Edu wanted to make to this PR.

Two questions:

@CoxyBoris
Copy link

CoxyBoris commented Oct 4, 2021

How do you feel about updating this PR with the files I have in #10? I'm happy to own that 😊

Sounds good to me thanks!!

How does it work when importing eslint config which requires installing packages? Do we simply need to tell engineers to install this package + all dependencies?

hmm shouldn't all dependencies be already listed in package.json and installed on npm install ? Sorry if I'm missing something here

@philippemiguet
Copy link
Contributor

hmm shouldn't all dependencies be already listed in package.json and installed on npm install? Sorry if I'm missing something here

Yeah maybe! I have no knowledge about how this works, I will only know once I try it. Maybe declaring the dependencies in this package will be enough 🤔 @msanroman since you already researched that part, do you know?

@msanroman
Copy link
Member Author

They should be declared as both devDependencies for working in the package and as peerDependencies for when you're installing the package as a dependency. That's how I've seen it work with Airbnb's ESLint config 1

Footnotes

  1. https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/package.json

@msanroman
Copy link
Member Author

We can use this shortcut to make sure we install the peerDependencies alongside the package:

npx install-peerdeps --dev eslint-config-airbnb

The key thing is to make sure only the absolute needed is marked as peer deps :)

@philippemiguet
Copy link
Contributor

Wow, I didn't know about the peerDependencies attribute 🤯

"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: change this for built

"typescript-eslint",
],
parser: "@typescript-eslint/parser",
ignorePatterns: ["node_modules/*", "built/*", "lib/*", "build/*"],
Copy link
Contributor

Choose a reason for hiding this comment

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

We should standardize our tsconfig outDir folder for all repositories. Right now, we have: lib, build, and built depending on repos. I would go for built 😊

Choose a reason for hiding this comment

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

built sounds good to me!

"jest/valid-expect": "error",
"no-underscore-dangle": "off"
}
"env": {
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: replace with actual eslint package we are creating here

Comment on lines +17 to +27
rules: {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/explicit-module-boundary-types": "error",
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error",
"no-underscore-dangle": "off"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Tempted to add these rules to the index.js as they should be applied to both FE and BE :in my opinion.

@philippemiguet
Copy link
Contributor

Listing next steps here @msanroman @CoxyBoris

  • Set rules to index.js to apply to both BE and FE
  • Add peerDependencies to eslint package
  • Decide on TS config outDir standard name: built vs build vs lib
  • Move tsconfig to a package: is that possible?
  • Update backend libs to use prettier and eslint package as a first example

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

Successfully merging this pull request may close these issues.

Add Prettier
4 participants