-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
ESLint support for documentation #3047
Conversation
examples/enzyme/yarn-error.log
Outdated
@@ -0,0 +1,43 @@ | |||
Arguments: |
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.
Remove this file and update .gitignore
?
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.
Ooops How did this get in...
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.
Thanks fixed!
@DmitriiAbramov The Should I run this separately in circle.yml file, or is it fine including it with |
According to Dmitrii! it can be included in |
docs/GlobalAPI.md
Outdated
@@ -195,6 +195,8 @@ Also under the alias: `fdescribe(name, fn)` | |||
You can use `describe.only` if you want to run only one describe block: | |||
|
|||
```js | |||
|
|||
/* eslint jest/no-focused-tests: "off" */ |
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.
As this is the description of describe.only
itself, we have to explicitly turn off the jest/no-focused-tests
rule for this one by adding a comment. If this causes confusion in the documentation, can we turn off this rule globally?
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.
yeah. i think we should disable it for the whole .md
run
docs/GlobalAPI.md
Outdated
@@ -281,13 +283,15 @@ When you are debugging a large codebase, you will often only want to run a subse | |||
For example, let's say you had these tests: | |||
|
|||
```js | |||
/* eslint jest/no-focused-tests: "off" */ |
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.
Another explicit eslint
comment
views | ||
config | ||
```bash | ||
. |
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.
Generated this tree using tree
command. Want to keep it?
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.
that looks good!
bound(); | ||
|
||
console.log(myMock.mock.instances); | ||
> [ <a>, <b> ] | ||
// > [ <a>, <b> ] |
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.
@DmitriiAbramov The syntax of // >
itself is quite different from the other files, and is only used in this one MockFunctions.md file. Adding comment is necessary otherwise eslint breaks.
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.
👍
docs/GlobalAPI.md
Outdated
@@ -195,6 +195,8 @@ Also under the alias: `fdescribe(name, fn)` | |||
You can use `describe.only` if you want to run only one describe block: | |||
|
|||
```js | |||
|
|||
/* eslint jest/no-focused-tests: "off" */ |
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.
yeah. i think we should disable it for the whole .md
run
views | ||
config | ||
```bash | ||
. |
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.
that looks good!
package.json
Outdated
"postinstall": "node ./scripts/postinstall.js && node ./scripts/build.js && (cd packages/eslint-plugin-jest && yarn link) && yarn link eslint-plugin-jest", | ||
"publish": "yarn run build-clean && yarn run build && lerna publish", | ||
"test-ci": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest-coverage -- -i && yarn run test-examples && node scripts/mapCoverage.js && codecov", | ||
"test-ci-partial": "yarn run build && yarn run jest -- -i && yarn run test-examples", | ||
"test-examples": "node scripts/test_examples.js", | ||
"test-pretty-format-perf": "node packages/pretty-format/perf/test.js", | ||
"test": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest && yarn run test-examples", | ||
"test": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest && yarn run test-examples && yarn run lint-docs", |
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.
we should probably put it after yarn run lint
. You don't want to wait for the entire test suite to run to find out that you have 1 lint error in the docs :)
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.
Cool, Thanks will do, makes sense
bound(); | ||
|
||
console.log(myMock.mock.instances); | ||
> [ <a>, <b> ] | ||
// > [ <a>, <b> ] |
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.
👍
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.
it looks awesome!! it'll help us keep the docs clean!
just a few changes and i think it's good to go!
@DmitriiAbramov Thank you for pointing out the changes, I have move the jest and react specific configurations to the top, so we don't have to specify them within the code blocks, which can get confusing for the readers. The --rules in package.json was getting bloated, so I have moved the rules to an additional |
I changed the order for running lint-docs after lint and and also added it to test-ci so it's tested by the continuous integration system too. :) |
Sorry closed this by mistake |
This is awesome @abdulhannanali! I'll let @DmitriiAbramov merge this one :) Would you mind resolving the conflict in the yarn lockfile? |
test script already includes lint-docs, it'll be reduntant to do the same for more than one node versions
Removing eslint comments from docs and moving them to top level in .eslintrc-docs.json
Awesome work. Thank you! |
@abdulhannanali what do you think of also enabling this set of lint rules to the "examples/" folder? The code there should be the same as in the documentation :) |
@cpojer Sorry for not resolving the merge conflict at time. Yes it can definitely be done. Thanks a lot for merging 😄 |
@cpojer Most of the rules we have added in |
@cpojer These are the rules we are using {
"rules": {
"react/react-in-jsx-scope": 0,
"react/jsx-no-undef": 0,
"jest/no-focused-tests": 0,
"no-undef": 0,
"no-unused-vars": 0,
"consistent-return": 0
},
"description": ".eslintrc-docs.json overrides the rules specified in .eslintrc, to make it more suitable for running on code examples in docs/ folder"
} |
@abdulhannanali I mostly recommended that to make sure that the style in the examples matches those in the documentation. |
@cpojer As far as the apparent styles are concerned, they are definitely going to match. Since both use the Fb Linting Standards. The rules for the docs are more concerned with validation errors we get in the docs. :) |
Oh, you are right. We are linting everything but the react-native example for some reason :) I thought we ignored them all. |
* add markdown plugin in eslint * add lint-docs build step * lint JavaScript file * final lint-docs command * lint ExpectAPI * lint GettingStarted.md * lint GlobalAPI * lint GlobalAPI * lint JestObjectAPI * lint Webpack.md * lint UsingMatchers.md in docs * lint TutorialReactNative.md in docs * lint TutorialReact.md in docs * lint docs file * add lint-docs to test-ci script * add lint-docs script to test & test-ci * turn off more rules to lint-docs in package.json * remove lint-docs from test and test-ci * add lint-docs to test script in package.json * remove lint-docs script from circle.yml * add lint-docs script to test-ci in package.json * rename js codeblock with json appropriately * remove unnecessary log files * remove lint-docs from test-ci test script already includes lint-docs, it'll be reduntant to do the same for more than one node versions * remove error.log file * use eslintrc-docs.json for overriding * remove eslint comments from docs Removing eslint comments from docs and moving them to top level in .eslintrc-docs.json * add lint-docs in correct order to test-ci and test
* add markdown plugin in eslint * add lint-docs build step * lint JavaScript file * final lint-docs command * lint ExpectAPI * lint GettingStarted.md * lint GlobalAPI * lint GlobalAPI * lint JestObjectAPI * lint Webpack.md * lint UsingMatchers.md in docs * lint TutorialReactNative.md in docs * lint TutorialReact.md in docs * lint docs file * add lint-docs to test-ci script * add lint-docs script to test & test-ci * turn off more rules to lint-docs in package.json * remove lint-docs from test and test-ci * add lint-docs to test script in package.json * remove lint-docs script from circle.yml * add lint-docs script to test-ci in package.json * rename js codeblock with json appropriately * remove unnecessary log files * remove lint-docs from test-ci test script already includes lint-docs, it'll be reduntant to do the same for more than one node versions * remove error.log file * use eslintrc-docs.json for overriding * remove eslint comments from docs Removing eslint comments from docs and moving them to top level in .eslintrc-docs.json * add lint-docs in correct order to test-ci and test
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Add Eslint support for documentation using the plugin
eslint-plugin-markdown
to lint the code injs
code blocks. The PR intends to solve #3028 , by linting preexisting example code in Jestdocs
folder according to the JavaScript standards Jest uses, and also adds a script to automatically lint code in future using build step. The Markdown files in the docs/ folder can be linted using the scriptyarn run lint-docs
Test plan
No changes to the code, The code makes some changes to the docs, the following commands pass on this code
and for the Jest code
yarn run test yarn run test-ci yarn run test-ci-partial