Gatsby: Add a precommit hook for auto-formatting in starters ( default | blog )

Created on 18 Jun 2019  路  6Comments  路  Source: gatsbyjs/gatsby

Summary

Brief explanation of the feature.

Add a precommit hook for auto-formatting in gatsby starters default and blog with a minimum set up eslint and prettier.

Basic example

package.json

"scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "lint": "eslint src/**/*.js",
    "lint:fix": "npm run lint -- --fix",
    "precommit": "cross-env NODE_ENV=production lint-staged",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\""
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    ".{js,jsx}": [
      "pretty-quick --staged",
      "npm run lint:fix",
      "git add"
    ]
  },

If the proposal involves a new or changed API, include a basic code example. Omit this section if it's not applicable.

Motivation

Why are we doing this? What use cases does it support? What is the expected outcome?

I always have to set up a lint before starting a new project. This always takes a long time. With this coming as default will be much faster to start a new project and will also be very good for the developer to have a better quality in your code.

question or discussion

All 6 comments

People are very opinionated about linting and format. I would suggest that this is moving away from the requirements of Gatsby.

I think not! I suggestion is a set up very very basic! to keep a minimum of quality in the code thus avoiding several bug that lint ja solve! I believe that with this I even decrease the issues here. because lint would already help in the code.

While I personally agree that adding linting and a pre commit hook would be nice, I鈥檓 not sure we should add this to the default starters because

  1. This stuff can get pretty opinionated like @LpmRaven mentioned
  2. Pre commit hooks require husky to be installed and we need to be wary of adding too many dependencies

Let鈥檚 hear what the rest of @gatsbyjs/core has to say

I agree with @sidharthachatterjee. We have enough gatsby starters that do include linting. We don't want to add too much complexity to our official starters.

@alexandreramosdev thanks for this!

Unfortunately, for the reasons that @wardpeet and @sidharthachatterjee mentioned, we are not going to merge this PR at this time. Why?

Starters (particularly the official ones!) should be as relatively non-opinionated as possible. Each opinion we introduce introduces a potential conflict with a user's model of what they want to build. If a user begins the process of developing by removing these types of choices, that's less time spent _building_ and we always want to make building an application with Gatsby as simple, easy, and quick as possible!

From this perspective, the introduction of a lint hook introduces the potential for churn and conflict with this model. A user who _wants_ this can certainly introduce this functionality if they so desire, but we'd like to not introduce it in the official starters.

Thanks for this issue--hope to see more from you soon!

I'm understand! thanks your for feedback.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

signalwerk picture signalwerk  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

benstr picture benstr  路  3Comments

magicly picture magicly  路  3Comments

dustinhorton picture dustinhorton  路  3Comments