提交 14777342 编写于 作者: D Dan Zajdband 提交者: Guillermo Rauch

Added linting using standard (#27)

* Added linting using standard

* Linting on test
上级 97ad0538
import React, { Component } from 'react'
import { StyleSheet, css } from 'next/css'
const spans = () => (
)
export default class CrazyCSS extends Component {
spans () {
const out = []
......
......@@ -3,15 +3,15 @@ import React from 'react'
export default () => {
return (
<ul>
{items()}
</ul>
{items()}
</ul>
)
}
const items = () => {
var out = new Array(10000)
for (let i = 0; i < out.length; i++) {
out[i] = <li key={i}>This is row {i+1}</li>
out[i] = <li key={i}>This is row {i + 1}</li>
}
return out
}
......@@ -5,7 +5,7 @@ import { render as _render } from '../server/render'
import Benchmark from 'benchmark'
const dir = resolve(__dirname, 'fixtures', 'basic')
const suite = new Benchmark.Suite('Next.js');
const suite = new Benchmark.Suite('Next.js')
suite
.on('start', async () => build(dir))
......
#!/usr/bin/env node
import { resolve } from 'path'
import parseArgs from 'minimist'
import { spawn } from 'cross-spawn';
import { spawn } from 'cross-spawn'
const defaultCommand = 'dev'
const commands = new Set([
......
......@@ -6,7 +6,7 @@ import build from '../server/build'
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
h: 'help'
},
boolean: ['h']
})
......
......@@ -22,7 +22,7 @@ build(dir)
.then(async () => {
const srv = new Server({ dir, dev: true })
await srv.start(argv.port)
console.log('> Ready on http://localhost:%d', argv.port);
console.log('> Ready on http://localhost:%d', argv.port)
})
.catch((err) => {
console.error(err)
......
......@@ -20,7 +20,7 @@ const dir = resolve(argv._[0] || '.')
const srv = new Server({ dir })
srv.start(argv.port)
.then(() => {
console.log('> Ready on http://localhost:%d', argv.port);
console.log('> Ready on http://localhost:%d', argv.port)
})
.catch((err) => {
console.error(err)
......
......@@ -23,7 +23,7 @@ export default class HeadManager {
let title
if (component) {
const { children } = component.props
title = 'string' === typeof children ? children : children.join('')
title = typeof children === 'string' ? children : children.join('')
} else {
title = DEFAULT_TITLE
}
......@@ -53,7 +53,7 @@ function reactElementToDOM ({ type, props }) {
const el = document.createElement(type)
for (const p in props) {
if (!props.hasOwnProperty(p)) continue
if ('children' === p || 'dangerouslySetInnerHTML' === p) continue
if (p === 'children' || p === 'dangerouslySetInnerHTML') continue
const attr = HTMLDOMPropertyConfig.DOMAttributeNames[p] || p.toLowerCase()
el.setAttribute(attr, props[p])
......@@ -63,7 +63,7 @@ function reactElementToDOM ({ type, props }) {
if (dangerouslySetInnerHTML) {
el.innerHTML = dangerouslySetInnerHTML.__html || ''
} else if (children) {
el.textContent = 'string' === typeof children ? children : children.join('')
el.textContent = typeof children === 'string' ? children : children.join('')
}
return el
}
......@@ -13,7 +13,7 @@ const {
const App = app ? evalScript(app).default : DefaultApp
const Component = evalScript(component).default
const router = new Router(location.href, { Component })
const router = new Router(window.location.href, { Component })
const headManager = new HeadManager()
const container = document.getElementById('__next')
const appProps = { Component, props, router, headManager }
......
......@@ -5,8 +5,8 @@ export default () => (
<div>
<Head>
<title>This page has a title 🤔</title>
<meta charSet="utf-8" />
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<meta charSet='utf-8' />
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
</Head>
<h1>This page has a title 🤔</h1>
......
import React from 'react'
import Link from 'next/link'
export default () => (
<div>Hello World. <Link href="/about">About</Link></div>
<div>Hello World. <Link href='/about'>About</Link></div>
)
......@@ -5,14 +5,14 @@ import { css, StyleSheet } from 'next/css'
export default () => (
<div className={css(styles.main)}>
<Post title="My first blog post">
<Post title='My first blog post'>
<P>Hello there</P>
<P>This is an example of a componentized blog post</P>
</Post>
<Hr />
<Post title="My second blog post">
<Post title='My second blog post'>
<P>Hello there</P>
<P>This is another example.</P>
<P>Wa-hoo!</P>
......@@ -20,7 +20,7 @@ export default () => (
<Hr />
<Post title="The final blog post">
<Post title='The final blog post'>
<P>C'est fin</P>
</Post>
</div>
......
......@@ -86,7 +86,7 @@ gulp.task('copy-bench-fixtures', () => {
})
gulp.task('build', [
'build-dev-client',
'build-dev-client'
])
gulp.task('build-release', [
......
......@@ -14,11 +14,11 @@ export default class Document extends Component {
render () {
return <html>
<Head/>
<Head />
<body>
<Main/>
<DevTools/>
<NextScript/>
<Main />
<DevTools />
<NextScript />
</body>
</html>
}
......@@ -30,14 +30,14 @@ export function Head (props, context) {
.map((h, i) => React.cloneElement(h, { key: '_next' + i }))
return <head>
{h}
<style data-aphrodite="" dangerouslySetInnerHTML={{ __html: css.content }} />
<style data-aphrodite='' dangerouslySetInnerHTML={{ __html: css.content }} />
</head>
}
Head.contextTypes = { _documentProps: PropTypes.any }
export function Main (props, context) {
const { html, data, staticMarkup } = context._documentProps;
const { html, data, staticMarkup } = context._documentProps
return <div>
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
{staticMarkup ? null : <script dangerouslySetInnerHTML={{ __html: '__NEXT_DATA__ = ' + htmlescape(data) }} />}
......@@ -48,16 +48,16 @@ Main.contextTypes = { _documentProps: PropTypes.any }
export function DevTools (props, context) {
const { hotReload } = context._documentProps
return hotReload ? <div id='__next-hot-code-reloading-indicator'/> : null
return hotReload ? <div id='__next-hot-code-reloading-indicator' /> : null
}
DevTools.contextTypes = { _documentProps: PropTypes.any }
export function NextScript (props, context) {
const { dev, staticMarkup } = context._documentProps;
const { dev, staticMarkup } = context._documentProps
if (staticMarkup) return null
const src = !dev ? '/_next/next.bundle.js' : '/_next/next-dev.bundle.js'
return <script type='text/javascript' src={src}/>
return <script type='text/javascript' src={src} />
}
NextScript.contextTypes = { _documentProps: PropTypes.any }
......@@ -62,7 +62,7 @@ function unique () {
const metatype = METATYPES[i]
if (!h.props.hasOwnProperty(metatype)) continue
if ('charSet' === metatype) {
if (metatype === 'charSet') {
if (metaTypes.has(metatype)) return false
metaTypes.add(metatype)
} else {
......
......@@ -11,8 +11,8 @@ export default class Link extends Component {
}
linkClicked (e) {
if ('A' === e.target.nodeName &&
(e.metaKey || e.ctrlKey || e.shiftKey || 2 === e.nativeEvent.which)) {
if (e.target.nodeName === 'A' &&
(e.metaKey || e.ctrlKey || e.shiftKey || e.nativeEvent.which === 2)) {
// ignore click for new tab / new window behavior
return
}
......@@ -30,7 +30,7 @@ export default class Link extends Component {
this.context.router.push(null, href)
.then((success) => {
if (!success) return
if (false !== scroll) window.scrollTo(0, 0)
if (scroll !== false) window.scrollTo(0, 0)
})
.catch((err) => {
if (this.props.onError) this.props.onError(err)
......@@ -43,7 +43,7 @@ export default class Link extends Component {
onClick: this.linkClicked
}
const isAnchor = child && 'a' === child.type
const isAnchor = child && child.type === 'a'
// if child does not specify a href, specify it
// so that repetition is not needed by the user
......@@ -63,7 +63,7 @@ export default class Link extends Component {
}
function isLocal (href) {
const origin = location.origin
const origin = window.location.origin
return !/^https?:\/\//.test(href) ||
origin === href.substr(0, origin.length)
}
......@@ -9,7 +9,7 @@ export default class Error extends React.Component {
render () {
const { statusCode } = this.props
const title = 404 === statusCode ? 'This page could not be found' : 'Internal Server Error'
const title = statusCode === 404 ? 'This page could not be found' : 'Internal Server Error'
return <div className={css(styles.error, styles['error_' + statusCode])}>
<div className={css(styles.text)}>
......
......@@ -4,7 +4,7 @@ import shallowEquals from './shallow-equals'
export default class Router {
constructor (url, initialData) {
const parsed = parse(url, true);
const parsed = parse(url, true)
// represents the current component key
this.route = toRoute(parsed.pathname)
......@@ -18,7 +18,7 @@ export default class Router {
this.componentLoadCancel = null
this.onPopState = this.onPopState.bind(this)
if ('undefined' !== typeof window) {
if (typeof window !== 'undefined') {
window.addEventListener('popstate', this.onPopState)
}
}
......@@ -26,7 +26,7 @@ export default class Router {
onPopState (e) {
this.abortComponentLoad()
const route = (e.state || {}).route || toRoute(location.pathname)
const route = (e.state || {}).route || toRoute(window.location.pathname)
Promise.resolve()
.then(async () => {
......@@ -45,7 +45,7 @@ export default class Router {
// the only way we can appropriately handle
// this failure is deferring to the browser
// since the URL has already changed
location.reload()
window.location.reload()
})
}
......@@ -68,7 +68,7 @@ export default class Router {
}
back () {
history.back()
window.history.back()
}
push (route, url) {
......@@ -96,7 +96,7 @@ export default class Router {
throw err
}
history[method]({ route }, null, url)
window.history[method]({ route }, null, url)
this.route = route
this.set(url, { ...data, props })
return true
......@@ -182,7 +182,7 @@ export default class Router {
}
function getURL () {
return location.pathname + (location.search || '') + (location.hash || '')
return window.location.pathname + (window.location.search || '') + (window.location.hash || '')
}
function toRoute (path) {
......@@ -190,7 +190,7 @@ function toRoute (path) {
}
function toJSONUrl (route) {
return ('/' === route ? '/index' : route) + '.json'
return (route === '/' ? '/index' : route) + '.json'
}
function loadComponent (url, fn) {
......@@ -212,7 +212,7 @@ function loadComponent (url, fn) {
}
function loadJSON (url, fn) {
const xhr = new XMLHttpRequest()
const xhr = new window.XMLHttpRequest()
xhr.onload = () => {
let data
......
export default function shallowEquals (a, b) {
for (const i in a) {
if (b[i] !== a[i]) return false;
if (b[i] !== a[i]) return false
}
for (const i in b) {
if (b[i] !== a[i]) return false;
if (b[i] !== a[i]) return false
}
return true;
return true
}
......@@ -49,7 +49,7 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
static contextTypes = WrappedComponent.contextTypes
// Expose canUseDOM so tests can monkeypatch it
static canUseDOM = 'undefined' !== typeof window
static canUseDOM = typeof window !== 'undefined'
static peek () {
return state
......
......@@ -12,7 +12,8 @@
},
"scripts": {
"build": "gulp",
"test": "gulp test"
"test": "standard && gulp test",
"lint": "standard"
},
"dependencies": {
"aphrodite": "0.5.0",
......@@ -44,12 +45,14 @@
"webpack": "1.13.2"
},
"devDependencies": {
"babel-eslint": "^7.0.0",
"del": "2.2.2",
"gulp": "3.9.1",
"gulp-ava": "0.14.1",
"gulp-babel": "6.1.2",
"gulp-cached": "1.1.0",
"gulp-notify": "2.2.0",
"standard": "^8.4.0",
"webpack-stream": "3.2.0"
},
"ava": {
......@@ -65,5 +68,8 @@
"transform-runtime"
]
}
},
"standard": {
"parser": "babel-eslint"
}
}
import { dirname } from 'path'
import fs from 'mz/fs'
import mkdirp from 'mkdirp-then';
import mkdirp from 'mkdirp-then'
import { transformFile } from 'babel-core'
import preset2015 from 'babel-preset-es2015'
import presetReact from 'babel-preset-react'
......@@ -11,7 +11,7 @@ import transformRuntime from 'babel-plugin-transform-runtime'
import moduleAlias from 'babel-plugin-module-alias'
const babelRuntimePath = require.resolve('babel-runtime/package')
.replace(/[\\\/]package\.json$/, '');
.replace(/[\\\/]package\.json$/, '')
const babelOptions = {
presets: [preset2015, presetReact],
......
......@@ -14,8 +14,8 @@ export default class Server {
this.run(req, res)
.catch((err) => {
console.error(err)
res.status(500);
res.end('error');
res.status(500)
res.end('error')
})
})
}
......@@ -62,7 +62,7 @@ export default class Server {
try {
html = await render(req.url, { req, res }, { dir, dev })
} catch (err) {
if ('ENOENT' === err.code) {
if (err.code === 'ENOENT') {
res.statusCode = 404
} else {
console.error(err)
......@@ -80,7 +80,7 @@ export default class Server {
try {
json = await renderJSON(req.url, { dir })
} catch (err) {
if ('ENOENT' === err.code) {
if (err.code === 'ENOENT') {
res.statusCode = 404
} else {
console.error(err)
......@@ -107,7 +107,7 @@ export default class Server {
return new Promise((resolve, reject) => {
send(req, path)
.on('error', (err) => {
if ('ENOENT' === err.code) {
if (err.code === 'ENOENT') {
this.render404(req, res).then(resolve, reject)
} else {
reject(err)
......
import { relative, resolve } from 'path'
import { resolve } from 'path'
import { parse } from 'url'
import { createElement } from 'react'
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import fs from 'mz/fs'
import requireResolve from './resolve'
import read from './read'
import Router from '../lib/router'
......
......@@ -4,7 +4,7 @@ import Head from 'next/head'
export default () => <div>
<Head>
<meta content="my meta" />
<meta content='my meta' />
</Head>
<h1>I can haz meta tags</h1>
</div>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册