From 57f7b0d372a7461f019ce86a9003371d45204f3b Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Mon, 2 Oct 2017 18:12:18 -0400 Subject: [PATCH] Lint (#2313) * don't swallow errors * rm ignored file * rm one more error * fix lint errors and add it to CI * fix test * Run format --- .eslintignore | 3 +- .eslintrc | 17 +- .travis.yml | 2 +- .../using-gatsby-image/src/pages/index.js | 4 +- package.json | 4 +- packages/gatsby-dev-cli/src/watch.js | 5 +- packages/gatsby-image/.eslintrc | 2 + packages/gatsby-image/src/index.js | 2 +- packages/gatsby-link/.eslintrc | 4 + packages/gatsby-link/src/__tests__/index.js | 2 - packages/gatsby-link/src/index.js | 18 +- packages/gatsby-module-loader/src/patch.js | 1 + packages/gatsby-plugin-catch-links/.eslintrc | 2 + .../gatsby-plugin-glamor/src/gatsby-ssr.js | 7 +- .../src/gatsby-browser.js | 4 +- .../src/gatsby-ssr.js | 2 + .../src/build-headers-program.js | 5 +- .../src/create-redirects.js | 52 +-- .../src/__tests__/gatsby-node.js | 2 +- .../src/gatsby-browser.js | 6 +- packages/gatsby-react-router-scroll/.eslintrc | 4 + .../src/index.js | 2 +- .../src/__tests__/index.js | 2 +- .../gatsby-remark-smartypants/src/index.js | 1 - .../src/extend-node-type.js | 368 +++++++++--------- .../gatsby-source-contentful/src/fetch.js | 4 + .../gatsby-source-drupal/src/gatsby-node.js | 11 +- .../src/__tests__/gatsby-node.js | 3 - .../src/create-remote-file-node.js | 3 +- .../src/gatsby-node.js | 4 +- packages/gatsby-source-lever/src/normalize.js | 1 - .../gatsby-source-mongodb/src/gatsby-node.js | 10 +- packages/gatsby-source-wordpress/src/fetch.js | 4 +- .../src/gatsby-node.js | 12 - .../gatsby-source-wordpress/src/normalize.js | 2 +- .../src/gatsby-node.js | 2 - .../src/gatsby-node.js | 2 - .../src/on-node-create.js | 2 +- .../src/parse.js | 1 + .../src/__tests__/gatsby-node.js | 2 - .../src/__tests__/gatsby-node.js | 3 - .../src/gatsby-node.js | 2 - packages/gatsby/cache-dir/find-page.js | 2 +- .../component-layout-creator/gatsby-node.js | 2 +- .../dev-404-page/raw_dev-404-page.js | 8 +- .../query-runner/gatsby-node.js | 1 - .../query-runner/page-query-runner.js | 1 + .../query-runner/query-compiler.js | 1 - .../query-runner/query-printer.js | 1 + packages/gatsby/src/redux/__tests__/jobs.js | 3 +- packages/gatsby/src/redux/__tests__/nodes.js | 2 +- packages/gatsby/src/redux/__tests__/pages.js | 1 - packages/gatsby/src/redux/__tests__/status.js | 2 +- packages/gatsby/src/redux/actions.js | 4 +- .../src/redux/actions/add-page-dependency.js | 2 +- packages/gatsby/src/redux/plugin-runner.js | 1 - packages/gatsby/src/redux/reducers/config.js | 3 +- packages/gatsby/src/redux/reducers/jobs.js | 7 +- packages/gatsby/src/redux/reducers/layouts.js | 3 +- packages/gatsby/src/redux/reducers/pages.js | 3 +- ...fer-graphql-input-type-from-fields-test.js | 6 +- .../infer-graphql-input-type-test.js | 4 +- .../src/schema/__tests__/prepare-regex.js | 2 +- .../src/schema/build-node-connections.js | 3 +- .../gatsby/src/schema/build-node-types.js | 2 - .../gatsby/src/schema/create-sort-field.js | 48 +++ .../infer-graphql-input-fields-from-fields.js | 145 ++----- .../src/schema/infer-graphql-input-fields.js | 2 - .../gatsby/src/schema/infer-graphql-type.js | 16 +- packages/gatsby/src/schema/node.js | 6 +- packages/gatsby/src/schema/run-sift.js | 8 +- packages/gatsby/src/utils/develop.js | 35 +- packages/gatsby/src/utils/webpack.config.js | 2 +- .../src/connection/__tests__/connection.js | 5 - yarn.lock | 12 +- 75 files changed, 449 insertions(+), 483 deletions(-) create mode 100644 packages/gatsby-image/.eslintrc create mode 100644 packages/gatsby-link/.eslintrc create mode 100644 packages/gatsby-plugin-catch-links/.eslintrc create mode 100644 packages/gatsby-react-router-scroll/.eslintrc delete mode 100644 packages/gatsby-source-filesystem/src/__tests__/gatsby-node.js create mode 100644 packages/gatsby/src/schema/create-sort-field.js diff --git a/.eslintignore b/.eslintignore index 3a4f3989dbcdf..e6c2203b7bb13 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ -interfaces \ No newline at end of file +interfaces +**/__tests__/fixtures/ diff --git a/.eslintrc b/.eslintrc index 6ecc7c48c5e5e..960579931c9e8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -69,5 +69,20 @@ "ignore": ["children"] } ] - } + }, + "overrides": [ + { + "files": [ + "packages/**/gatsby-browser.js", + "pacakges/gatsby/cache-dir/**/*" + ], + "env": { + "browser": true + }, + "globals": { + "___loader": false, + "___emitter": false + } + } + ] } diff --git a/.travis.yml b/.travis.yml index 15d374da163f3..24e4651bcd3a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,4 @@ install: - yarn run bootstrap script: - - npm test + - yarn test diff --git a/examples/using-gatsby-image/src/pages/index.js b/examples/using-gatsby-image/src/pages/index.js index c4046c236cc4c..74b2be6e084b7 100644 --- a/examples/using-gatsby-image/src/pages/index.js +++ b/examples/using-gatsby-image/src/pages/index.js @@ -26,7 +26,7 @@ class IndexComponent extends React.Component {

gatsby-image - {" "} + {` `} is the official Image component for use in building Gatsby websites. It provides the fastest, most optimized image loading performance possible for Gatsby (and other React) websites. @@ -39,7 +39,7 @@ class IndexComponent extends React.Component {

See the site source - {" "} + {` `} on how to start using gatsby-image on your site. Full documentation coming soon.

diff --git a/package.json b/package.json index 41d99e75ae713..5a0231eb0dc8a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "format-scripts": "prettier-eslint --write \"scripts/**/*.js\"", "format-www": "prettier-eslint --write \"www/*.js\" \"www/src/**/*.js\"", "lerna": "lerna", - "lint": "npm run check-versions && eslint --ext .js,.jsx --ignore-path .gitignore .", + "lint": "eslint --ext .js,.jsx packages/**/src", "lint:flow": "babel-node scripts/flow-check.js", "plop": "plop", "bootstrap": "yarn && npm run check-versions && lerna run prepublish", @@ -56,7 +56,7 @@ "publish-canary": "lerna publish --canary --yes", "publish-next": "lerna publish --npm-tag=next", "remotedev": "remotedev --hostname=localhost --port=19999", - "test": "jest", + "test": "yarn run lint && jest", "test:update": "jest --updateSnapshot", "test:watch": "jest --watch", "test_bkup": "npm run lint && npm run test-node && npm run test-integration", diff --git a/packages/gatsby-dev-cli/src/watch.js b/packages/gatsby-dev-cli/src/watch.js index 4db686cee6baa..47d87cf287703 100644 --- a/packages/gatsby-dev-cli/src/watch.js +++ b/packages/gatsby-dev-cli/src/watch.js @@ -13,7 +13,8 @@ const debouncedQuit = _.debounce(() => { const copyPath = (oldPath, newPath, quiet) => { fs.copy(oldPath, newPath, err => { if (err) { - return console.error(err) + console.error(err) + return } numCopied += 1 @@ -28,7 +29,7 @@ function watch(root, packages, { scanOnce, quiet }) { const prefix = syspath.join(root, `/packages/`, p) const ignoreRegs = [ - /[\/\\]node_modules[\/\\]/i, + /[/\\]node_modules[/\\]/i, /\.git/i, new RegExp(`${p}[\\/\\\\]src[\\/\\\\]`, `i`), ] diff --git a/packages/gatsby-image/.eslintrc b/packages/gatsby-image/.eslintrc new file mode 100644 index 0000000000000..5c9fc4c255341 --- /dev/null +++ b/packages/gatsby-image/.eslintrc @@ -0,0 +1,2 @@ +env: + browser: true diff --git a/packages/gatsby-image/src/index.js b/packages/gatsby-image/src/index.js index 01740af2656c5..aa5dd5e57a791 100644 --- a/packages/gatsby-image/src/index.js +++ b/packages/gatsby-image/src/index.js @@ -49,7 +49,7 @@ const Img = props => { Img.propTypes = { opacity: PropTypes.number, - onLoad: PropTypes.func + onLoad: PropTypes.func, } class Image extends React.Component { diff --git a/packages/gatsby-link/.eslintrc b/packages/gatsby-link/.eslintrc new file mode 100644 index 0000000000000..6f3b6683ff79e --- /dev/null +++ b/packages/gatsby-link/.eslintrc @@ -0,0 +1,4 @@ +env: + browser: true +globals: + ___loader: false diff --git a/packages/gatsby-link/src/__tests__/index.js b/packages/gatsby-link/src/__tests__/index.js index 3ccbc7629320d..dbc70acff3916 100644 --- a/packages/gatsby-link/src/__tests__/index.js +++ b/packages/gatsby-link/src/__tests__/index.js @@ -1,5 +1,3 @@ -import React from "react" - const getInstance = (props, pathPrefix = ``) => { Object.assign(global.window, { __PREFIX_PATHS__: pathPrefix ? true : false, diff --git a/packages/gatsby-link/src/index.js b/packages/gatsby-link/src/index.js index 2c58f5c435024..1560cfbdb2fd9 100644 --- a/packages/gatsby-link/src/index.js +++ b/packages/gatsby-link/src/index.js @@ -28,11 +28,6 @@ class GatsbyLink extends React.Component { to: normalizePath(pathPrefix + props.to), } } - propTypes: { - ...NavLinkPropTypes, - to: PropTypes.string.isRequired, - onClick: PropTypes.func, - } componentWillReceiveProps(nextProps) { if (this.props.to !== nextProps.to) { @@ -49,16 +44,19 @@ class GatsbyLink extends React.Component { render() { const { onClick, ...rest } = this.props + let El if (Object.keys(NavLinkPropTypes).some(propName => this.props[propName])) { - var El = NavLink + El = NavLink } else { - var El = Link + El = Link } return ( { + // eslint-disable-line onClick && onClick(e) + if ( e.button === 0 && // ignore right clicks !this.props.target && // let browser handle "target=_blank" @@ -104,6 +102,12 @@ class GatsbyLink extends React.Component { } } +GatsbyLink.propTypes = { + ...NavLinkPropTypes, + to: PropTypes.string.isRequired, + onClick: PropTypes.func, +} + GatsbyLink.contextTypes = { router: PropTypes.object, } diff --git a/packages/gatsby-module-loader/src/patch.js b/packages/gatsby-module-loader/src/patch.js index d4383d2e52ab2..9f6595f4aa1d4 100644 --- a/packages/gatsby-module-loader/src/patch.js +++ b/packages/gatsby-module-loader/src/patch.js @@ -1,3 +1,4 @@ +/* global document: false, __webpack_require__: false */ patch() function patch() { diff --git a/packages/gatsby-plugin-catch-links/.eslintrc b/packages/gatsby-plugin-catch-links/.eslintrc new file mode 100644 index 0000000000000..5c9fc4c255341 --- /dev/null +++ b/packages/gatsby-plugin-catch-links/.eslintrc @@ -0,0 +1,2 @@ +env: + browser: true diff --git a/packages/gatsby-plugin-glamor/src/gatsby-ssr.js b/packages/gatsby-plugin-glamor/src/gatsby-ssr.js index ffb5d658f056d..0bc84f63b7338 100644 --- a/packages/gatsby-plugin-glamor/src/gatsby-ssr.js +++ b/packages/gatsby-plugin-glamor/src/gatsby-ssr.js @@ -14,9 +14,14 @@ exports.replaceRenderer = ({ replaceBodyHTMLString(html) setHeadComponents([ -