Skip to content

Commit

Permalink
Lint (#2313)
Browse files Browse the repository at this point in the history
* don't swallow errors

* rm ignored file

* rm one more error

* fix lint errors and add it to CI

* fix test

* Run format
  • Loading branch information
jquense authored and KyleAMathews committed Oct 2, 2017
1 parent 3449cbf commit 57f7b0d
Show file tree
Hide file tree
Showing 75 changed files with 449 additions and 483 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
interfaces
interfaces
**/__tests__/fixtures/
17 changes: 16 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,20 @@
"ignore": ["children"]
}
]
}
},
"overrides": [
{
"files": [
"packages/**/gatsby-browser.js",
"pacakges/gatsby/cache-dir/**/*"
],
"env": {
"browser": true
},
"globals": {
"___loader": false,
"___emitter": false
}
}
]
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ install:
- yarn run bootstrap

script:
- npm test
- yarn test
4 changes: 2 additions & 2 deletions examples/using-gatsby-image/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IndexComponent extends React.Component {
<p>
<a href="https://www.gatsbyjs.org/packages/gatsby-image/">
gatsby-image
</a>{" "}
</a>{` `}
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.
Expand All @@ -39,7 +39,7 @@ class IndexComponent extends React.Component {
<p>
<a href="https://github.com/gatsbyjs/gatsby/blob/master/examples/using-gatsby-image/">
See the site source
</a>{" "}
</a>{` `}
on how to start using gatsby-image on your site. Full documentation
coming soon.
</p>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
"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",
"publish": "lerna publish",
"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",
Expand Down
5 changes: 3 additions & 2 deletions packages/gatsby-dev-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`),
]
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby-image/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env:
browser: true
2 changes: 1 addition & 1 deletion packages/gatsby-image/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Img = props => {

Img.propTypes = {
opacity: PropTypes.number,
onLoad: PropTypes.func
onLoad: PropTypes.func,
}

class Image extends React.Component {
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-link/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env:
browser: true
globals:
___loader: false
2 changes: 0 additions & 2 deletions packages/gatsby-link/src/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from "react"

const getInstance = (props, pathPrefix = ``) => {
Object.assign(global.window, {
__PREFIX_PATHS__: pathPrefix ? true : false,
Expand Down
18 changes: 11 additions & 7 deletions packages/gatsby-link/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 (
<El
onClick={e => {
// eslint-disable-line
onClick && onClick(e)

if (
e.button === 0 && // ignore right clicks
!this.props.target && // let browser handle "target=_blank"
Expand Down Expand Up @@ -104,6 +102,12 @@ class GatsbyLink extends React.Component {
}
}

GatsbyLink.propTypes = {
...NavLinkPropTypes,
to: PropTypes.string.isRequired,
onClick: PropTypes.func,
}

GatsbyLink.contextTypes = {
router: PropTypes.object,
}
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-module-loader/src/patch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global document: false, __webpack_require__: false */
patch()

function patch() {
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby-plugin-catch-links/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env:
browser: true
7 changes: 6 additions & 1 deletion packages/gatsby-plugin-glamor/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ exports.replaceRenderer = ({
replaceBodyHTMLString(html)

setHeadComponents([
<style id="glamor-styles" dangerouslySetInnerHTML={{ __html: css }} />,
<style
id="glamor-styles"
key="glamor-styles"
dangerouslySetInnerHTML={{ __html: css }}
/>,
<script
id="glamor-ids"
key="glamor-ids"
dangerouslySetInnerHTML={{
__html: `
// <![CDATA[
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-google-analytics/src/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exports.onRouteUpdate = function({ location }) {
// Don't track while developing.
if (process.env.NODE_ENV === `production` && typeof ga === `function`) {
ga(`set`, `page`, (location || {}).pathname)
ga(`send`, `pageview`)
window.ga(`set`, `page`, (location || {}).pathname)
window.ga(`send`, `pageview`)
}
}
2 changes: 2 additions & 0 deletions packages/gatsby-plugin-google-analytics/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ exports.onRenderBody = ({ setPostBodyComponents }, pluginOptions) => {
/>,
])
}

return null
}
5 changes: 2 additions & 3 deletions packages/gatsby-plugin-netlify/src/build-headers-program.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import _ from "lodash"
import { writeFile } from "fs-extra"
import { writeFile, existsSync } from "fs-extra"
import { HEADER_COMMENT } from "./constants"

import {
ROOT_WILDCARD,
COMMON_BUNDLES,
SECURITY_HEADERS,
CACHING_HEADERS,
Expand Down Expand Up @@ -93,7 +92,7 @@ function transformLink(manifest, publicFolder, pathPrefix) {
const hashed = manifest[file]
if (hashed) {
return `${prefix}${pathPrefix}${hashed}${suffix}`
} else if (fs.existsSync(publicFolder(file))) {
} else if (existsSync(publicFolder(file))) {
return `${prefix}${pathPrefix}${file}${suffix}`
} else {
throw new Error(
Expand Down
52 changes: 26 additions & 26 deletions packages/gatsby-plugin-netlify/src/create-redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import { appendFile, exists, readFile, writeFile } from "fs-extra"
export default async function writeRedirectsFile(pluginData, redirects) {
const { publicFolder } = pluginData

if (redirects.length > 0) {
const FILE_PATH = publicFolder(`_redirects`)

// Map redirect data to the format Netlify expects
// https://www.netlify.com/docs/redirects/
redirects = redirects.map(redirect => {
const status = redirect.isPermanent ? 301 : 302
return `${redirect.fromPath} ${redirect.toPath} ${status}`
})

let appendToFile = false

// Websites may also have statically defined redirects
// In that case we should append to them (not overwrite)
// Make sure we aren't just looking at previous build results though
const fileExists = await exists(FILE_PATH)
if (fileExists) {
const fileContents = await readFile(FILE_PATH)
if (fileContents.indexOf(HEADER_COMMENT) < 0) {
appendToFile = true
}
}
if (!redirects.length) return null

const FILE_PATH = publicFolder(`_redirects`)

// Map redirect data to the format Netlify expects
// https://www.netlify.com/docs/redirects/
redirects = redirects.map(redirect => {
const status = redirect.isPermanent ? 301 : 302
return `${redirect.fromPath} ${redirect.toPath} ${status}`
})

const data = `${HEADER_COMMENT}\n\n${redirects.join(`\n`)}`
let appendToFile = false

return appendToFile
? appendFile(FILE_PATH, `\n\n${data}`)
: writeFile(FILE_PATH, data)
// Websites may also have statically defined redirects
// In that case we should append to them (not overwrite)
// Make sure we aren't just looking at previous build results though
const fileExists = await exists(FILE_PATH)
if (fileExists) {
const fileContents = await readFile(FILE_PATH)
if (fileContents.indexOf(HEADER_COMMENT) < 0) {
appendToFile = true
}
}

const data = `${HEADER_COMMENT}\n\n${redirects.join(`\n`)}`

return appendToFile
? appendFile(FILE_PATH, `\n\n${data}`)
: writeFile(FILE_PATH, data)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe(`gatsby-plugin-react-css-modules`, () => {

it(`includes custom options when modifying babelrc`, () => {
const options = {
exclude: `\/global\/`,
exclude: `/global/`,
filetypes: {
".scss": { syntax: `postcss-scss` },
},
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-plugin-twitter/src/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
exports.onRouteUpdate = function({ location }) {
if (
typeof twttr !== `undefined` &&
twttr.widgets &&
typeof twttr.widgets.load === `function`
window.twttr.widgets &&
typeof window.twttr.widgets.load === `function`
) {
twttr.widgets.load()
window.twttr.widgets.load()
}
}
4 changes: 4 additions & 0 deletions packages/gatsby-react-router-scroll/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env:
browser: true
globals:
__DEV__: false
2 changes: 1 addition & 1 deletion packages/gatsby-remark-responsive-iframe/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = ({ markdownAST }, pluginOptions = {}) =>
if (iframe) {
const width = iframe.attr(`width`)
const height = iframe.attr(`height`)
const src = iframe.attr(`src`)

if (width && height) {
$(`iframe, object`).attr(
`style`,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-remark-smartypants/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const remark = new Remark().data(`settings`, {

describe(`gatsby-remark-smartypants`, () => {
it(`applies smartypants to text nodes`, () => {
const sentence = `He said, "A \'simple\' english sentence. . .`
const sentence = `He said, "A 'simple' english sentence. . .`

const markdownAST = remark.parse(`
${sentence}
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby-remark-smartypants/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const retext = require(`retext`)
const visit = require(`unist-util-visit`)
const smartypants = require(`retext-smartypants`)
const _ = require(`lodash`)

module.exports = ({ markdownAST }, pluginOptions = {}) => {
visit(markdownAST, `text`, node => {
Expand Down
Loading

0 comments on commit 57f7b0d

Please sign in to comment.