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 content to eslint.md #8701

Merged
merged 5 commits into from
Oct 4, 2018
Merged

Add content to eslint.md #8701

merged 5 commits into from
Oct 4, 2018

Conversation

josefaidt
Copy link
Contributor

Includes: why use ESLint, how to use it, and starter file

I used Yarn in the example, however I can switch this to an npm command (after finding issue #4514). Gatsby documentation is back & forth with yarn/npm from what I've noticed so I wasn't sure what I should use. Please consider defining the preferred package manager in the Gatsby Style Guide

Also, the L in ESLint is not capitalized on the sidebar
image

why use ESLint, how to use it, and include starter file
@josefaidt josefaidt requested a review from a team October 2, 2018 14:50
Copy link
Contributor

@jlengstorf jlengstorf left a comment

Choose a reason for hiding this comment

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

This looks great! I'm going to let @shannonbux give this the 👍 👎, since she owns docs.

I had one comment as well. Thanks so much for contributing!


`yarn remove prettier; yarn add -D eslint babel-eslint eslint-config-standard eslint-plugin-import eslint-plugin-promise eslint-plugin-standard eslint-plugin-react`

Now that we have our packages installed, remove `.prettierrc` from the root of your new Gatsby project and create a new file named `.eslintrc.js`. We recommend copying our default .eslintrc.js below to the root of your site and modifying it per your needs. Reference ESLint's [rules documentation](https://eslint.org/docs/rules/) for more options.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd love to see the deletion and creation of files put into the instructions above or into a separate code block, e.g.:

# Remove the Prettier config file
rm .prettierrc

# Create a config file for ESLint
touch .eslintrc.js

It's a little easier to catch than in long form.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated 😀

add defined commands for removing prettier and installing eslint packages and dotfiles
@LekoArts
Copy link
Contributor

LekoArts commented Oct 2, 2018

I used Yarn in the example, however I can switch this to an npm command (after finding issue #4514). Gatsby documentation is back & forth with yarn/npm from what I've noticed so I wasn't sure what I should use.

Where did you saw a back & forth? I went through all docs yesterday (quickly) and mostly if not only saw npm. yarn is used for the Contribution docs as it’s necessary.
Therefore npm is the appropriate choice as I see it.

@LekoArts
Copy link
Contributor

LekoArts commented Oct 2, 2018

Sidenote: You can use ESLint with prettier as a formatter (as a plugin) and ESLint is only the linter then. I use it like that:
https://github.com/LeKoArts/portfolio/blob/feature/prismic/.eslintrc

@josefaidt
Copy link
Contributor Author

@LekoArts I saw it in the Contribution docs. I could've sworn I saw it elsewhere previously, but when I went to look it was only the Contribution docs. I did go back and change it to npm, though.

Sidenote: You can use ESLint with prettier as a formatter (as a plugin) and ESLint is only the linter then. I use it like that:

I intentionally left it out of the configuration to fully demonstrate ESLint's power as a alternative package, but I could change it if yall prefer the Prettier integration in the starter config. The below piece is the primary reason I migrated away from Prettier in my personal projects:

    // standard.js
    'space-before-function-paren': ['error', {
      'named': 'always',
      'anonymous': 'always',
      'asyncArrow': 'always'
    }],

The configuration I committed is based on my current config so it is definitely opinionated, and performs a few extra formatting pieces Prettier does not perform.

If we want to move to the Prettier integration to present a smaller, more concise starter file for users that's analogous to the default-starter's initial Prettier setup I'm all for it.

@pieh
Copy link
Contributor

pieh commented Oct 2, 2018

Maybe it's worth to mention that in gatsby v2 there is basic eslint ( https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/eslint-config.js ) running as part of gatsby develop and it gets disabled when user provide their own eslint config

// if no local eslint config, then add gatsby config
if (!hasLocalEslint(program.directory)) {
configRules = configRules.concat([rules.eslint(schema)])
}
(if someone provide eslint rules we assume he will take care of linting)

@josefaidt
Copy link
Contributor Author

@pieh That's super interesting, I did not realize that. I noticed it also has a GraphQL plugin. Do you know if the user provides an ESLint dotfile, will the provided dotfile be rolled into the user dotfile? It doesn't look like it does, therefore I should probably add that to my starter file. Any thoughts?

@pieh
Copy link
Contributor

pieh commented Oct 3, 2018

Do you know if the user provides an ESLint dotfile, will the provided dotfile be rolled into the user dotfile?

I don't understand what do you mean (too many user dotfiles :D)

Copy link
Contributor

@shannonbux shannonbux left a comment

Choose a reason for hiding this comment

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

This looks good to me--just address the couple comments I left and any others left in the conversation about this doc! Thanks for picking this up, @josefaidt!


We recommend copying our default .eslintrc.js content below to your newly created `.eslintrc.js` file and modifying it per your needs. Reference ESLint's [rules documentation](https://eslint.org/docs/rules/) for more options.

```js
Copy link
Contributor

Choose a reason for hiding this comment

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

@DSchau recently implemented a way to add the title of a file to the top of a code snippet. You would write it as follows:

```js:title=.eslintrc.js


Please use the [Gatsby Style Guide](/docs/gatsby-style-guide/) to ensure your
pull request gets accepted.
Gatsby ships with Prettier, which is a simple, opinionated code *formatter*. [ESLint](https://eslint.org) can be both a *linter* and *formatter*, meaning you can use it to check for syntactical errors as well as formatting. Prettier will work for most sites, however if you'd like to add linting capabilities *and* highly-configurable formatting you should implement ESLint into your new Gatsby project.
Copy link
Contributor

Choose a reason for hiding this comment

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

This paragraph mentions "new" Gatsby project in the last sentence. Is there significance to that? Do you have to install ESLint at the beginning of a project?

Copy link
Contributor

Choose a reason for hiding this comment

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

@shannonbux good catch! Want to just remove new here!

@josefaidt
Copy link
Contributor Author

@pieh I misread that and the code at first I think, ignore me 😬
@shannonbux anytime, happy to contribute!

@shannonbux shannonbux merged commit 9d1e64d into gatsbyjs:master Oct 4, 2018
@shannonbux
Copy link
Contributor

Thanks @josefaidt! Looks great and I added the capitalization to the doc-links.yml file for the sidebar 👍

@shannonbux shannonbux added the type: documentation An issue or pull request for improving or updating Gatsby's documentation label Oct 4, 2018
@josefaidt josefaidt deleted the patch-2 branch October 4, 2018 23:32
@Siyfion
Copy link
Contributor

Siyfion commented Oct 11, 2018

@josefaidt Looks great, but just to add to this; if the example you provided at the bottom looks a little intimidating to anyone you can simplify it massively and still have Standard JS, Prettier and all the "recommended" ESLint settings, with this:

{
  "parser": "babel-eslint",
  "plugins": [
    "prettier",
    "react",
    "standard"
  ],
  "extends": [
    "standard",
    "plugin:react/recommended",
    "prettier",
    "prettier/react",
    "prettier/standard"
  ],
  "parserOptions": {
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "env": {
    "browser": true,
    "es6": true,
    "jest": true,
    "node": true
  },
  "rules": {
    "prettier/prettier": "error"
  },
  "settings": {
    "react": {
      "version": "16.4"
    }
  }
}

Then you simply keep your .prettierrc file and away you go!

Note: "jest": true, is only needed if you're doing testing with jest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants