-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Add content to eslint.md #8701
Conversation
why use ESLint, how to use it, and include starter file
There was a problem hiding this 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!
docs/docs/eslint.md
Outdated
|
||
`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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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. |
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: |
@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.
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. |
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/packages/gatsby/src/utils/webpack.config.js Lines 301 to 304 in 0fc973c
|
@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? |
I don't understand what do you mean (too many user dotfiles :D) |
There was a problem hiding this 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!
docs/docs/eslint.md
Outdated
|
||
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 |
There was a problem hiding this comment.
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
docs/docs/eslint.md
Outdated
|
||
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
@pieh I misread that and the code at first I think, ignore me 😬 |
Thanks @josefaidt! Looks great and I added the capitalization to the |
@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 Note: |
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