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

ESLint support for documentation #3047

Merged
merged 28 commits into from
Mar 4, 2017
Merged

Conversation

abdulhannanali
Copy link
Contributor

Summary

Add Eslint support for documentation using the plugin eslint-plugin-markdown to lint the code in js code blocks. The PR intends to solve #3028 , by linting preexisting example code in Jest docs 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 script yarn 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

cd website
yarn run test

and for the Jest code

yarn run test
yarn run test-ci
yarn run test-ci-partial

@@ -0,0 +1,43 @@
Arguments:
Copy link
Contributor

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 ?

Copy link
Contributor Author

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks fixed!

@abdulhannanali
Copy link
Contributor Author

@DmitriiAbramov The lint-docs script which lints the documentation using eslint-plugin-markdown is added to scripts yarn run test and yarn run test-ci, so I don't need to change the circle.yml file in any way, and they run in an order, where first the checks are performed on the code, and if everything works fine, documentation is checked for the errors.

Should I run this separately in circle.yml file, or is it fine including it with test and test-ci scripts. You can check package.json for more info.

@abdulhannanali
Copy link
Contributor Author

According to Dmitrii! it can be included in test as running test script means usually, that everything is working fine, and there are no major errors that are breaking the tests or code. It includes docs as well. Removing this from test-ci as this seems unnecessary. 👍

@@ -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" */
Copy link
Contributor Author

@abdulhannanali abdulhannanali Mar 2, 2017

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?

Copy link
Contributor

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

@@ -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" */
Copy link
Contributor Author

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
.
Copy link
Contributor Author

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?

Copy link
Contributor

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> ]
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -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" */
Copy link
Contributor

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
.
Copy link
Contributor

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",
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 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 :)

Copy link
Contributor Author

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> ]
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@aaronabramov aaronabramov left a 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!

@abdulhannanali
Copy link
Contributor Author

abdulhannanali commented Mar 3, 2017

@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 .eslintrc-docs.json file to override the rules present in .eslintrc.

@abdulhannanali
Copy link
Contributor Author

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. :)

@abdulhannanali
Copy link
Contributor Author

Sorry closed this by mistake

@abdulhannanali abdulhannanali reopened this Mar 3, 2017
@cpojer
Copy link
Member

cpojer commented Mar 3, 2017

This is awesome @abdulhannanali! I'll let @DmitriiAbramov merge this one :) Would you mind resolving the conflict in the yarn lockfile?

@cpojer
Copy link
Member

cpojer commented Mar 4, 2017

Awesome work. Thank you!

@cpojer cpojer merged commit 5ab8e28 into jestjs:master Mar 4, 2017
@cpojer
Copy link
Member

cpojer commented Mar 4, 2017

@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 :)

@abdulhannanali
Copy link
Contributor Author

@cpojer Sorry for not resolving the merge conflict at time. Yes it can definitely be done. Thanks a lot for merging 😄

@abdulhannanali
Copy link
Contributor Author

@cpojer Most of the rules we have added in eslint-docs.json are there because of the code examples in the docs can't run standalone except the consistent-return as this was just annoying. However examples are standalone examples, we can run. I see no point of adopting the same linting rules for examples/.

@abdulhannanali
Copy link
Contributor Author

@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"
}

@cpojer
Copy link
Member

cpojer commented Mar 6, 2017

@abdulhannanali I mostly recommended that to make sure that the style in the examples matches those in the documentation.

@abdulhannanali
Copy link
Contributor Author

@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. :)

@cpojer
Copy link
Member

cpojer commented Mar 6, 2017

Oh, you are right. We are linting everything but the react-native example for some reason :) I thought we ignored them all.

@abdulhannanali
Copy link
Contributor Author

@cpojer #3080 fixes it 😄

skovhus pushed a commit to skovhus/jest that referenced this pull request Apr 29, 2017
* 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
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
* 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
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants