1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Lint examples (#4985)

* Lint examples/with-apollo-and-redux-saga

* Lint examples/with-apollo-auth

* Lint examples/with-apollo

* Lint exampels/with-google-analytics

* Lint examples/with-higher-order-component

* Lint examples/with-react-i18next

* Lint exampels/with-redux

* Lint exampels/with-relay-modern

* Lint examples/with-universal-configuration-runtime

* Add **/examples/**/lib/** to linter
This commit is contained in:
HaNdTriX 2018-08-20 08:31:24 +02:00 committed by Tim Neutkens
parent 639df91c87
commit 5ff7c0742c
25 changed files with 49 additions and 51 deletions

View file

@ -3,7 +3,7 @@ export const actionTypes = {
TICK_CLOCK: 'TICK_CLOCK'
}
export function startClock(isServer=true) {
export function startClock (isServer = true) {
return {
type: actionTypes.START_CLOCK,
light: isServer,
@ -11,7 +11,7 @@ export function startClock(isServer=true) {
}
}
export function tickClock(isServer) {
export function tickClock (isServer) {
return {
type: actionTypes.TICK_CLOCK,
light: !isServer,

View file

@ -5,7 +5,7 @@ export const initialState = {
light: false
}
function reducer(state = initialState, action) {
function reducer (state = initialState, action) {
switch (action.type) {
case actionTypes.TICK_CLOCK:
return {

View file

@ -7,7 +7,7 @@ import { actionTypes, tickClock } from './actions'
es6promise.polyfill()
function* runClockSaga() {
function * runClockSaga () {
yield take(actionTypes.START_CLOCK)
while (true) {
yield put(tickClock(false))

View file

@ -3,10 +3,10 @@ export const actionTypes = {
COUNT_DECREASE: 'COUNT_DECREASE'
}
export function countIncrease() {
export function countIncrease () {
return { type: actionTypes.COUNT_INCREASE }
}
export function countDecrease() {
export function countDecrease () {
return { type: actionTypes.COUNT_DECREASE }
}

View file

@ -2,7 +2,7 @@ import { actionTypes } from './actions'
const initialState = 0
function reducer(state = initialState, action) {
function reducer (state = initialState, action) {
switch (action.type) {
case actionTypes.COUNT_INCREASE:
return state + 1

View file

@ -10,7 +10,7 @@ if (!process.browser) {
global.fetch = fetch
}
function create(initialState) {
function create (initialState) {
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
return new ApolloClient({
connectToDevTools: process.browser,
@ -23,7 +23,7 @@ function create(initialState) {
})
}
export default function initApollo(initialState) {
export default function initApollo (initialState) {
// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
if (!process.browser) {

View file

@ -4,18 +4,18 @@ export const actionTypes = {
LOAD_DATA_ERROR: 'LOAD_DATA_ERROR'
}
export function loadData() {
export function loadData () {
return { type: actionTypes.LOAD_DATA }
}
export function loadDataSuccess(data) {
export function loadDataSuccess (data) {
return {
type: actionTypes.LOAD_DATA_SUCCESS,
data
}
}
export function loadDataError(error) {
export function loadDataError (error) {
return {
type: actionTypes.LOAD_DATA_ERROR,
error

View file

@ -5,7 +5,7 @@ export const initialState = {
error: false
}
function reducer(state = initialState, action) {
function reducer (state = initialState, action) {
switch (action.type) {
case actionTypes.LOAD_DATA_SUCCESS:
return {

View file

@ -1,12 +1,12 @@
import { put, takeLatest } from 'redux-saga/effects'
import es6promise from 'es6-promise'
import 'isomorphic-unfetch'
import fetch from 'isomorphic-unfetch'
import { actionTypes, loadDataSuccess, loadDataError } from './actions'
es6promise.polyfill()
function* loadDataSaga() {
function * loadDataSaga () {
try {
const res = yield fetch('https://jsonplaceholder.typicode.com/users')
const data = yield res.json()

View file

@ -3,7 +3,7 @@ import { all } from 'redux-saga/effects'
import clock from './clock/sagas'
import placeholder from './placeholder/sagas'
function* rootSaga() {
function * rootSaga () {
yield all([clock, placeholder])
}

View file

@ -5,7 +5,7 @@ import Head from 'next/head'
import initApollo from './initApollo'
// Gets the display name of a JSX component for dev tools
function getComponentDisplayName(Component) {
function getComponentDisplayName (Component) {
return Component.displayName || Component.name || 'Unknown'
}
@ -18,7 +18,7 @@ export default ComposedComponent => {
serverState: PropTypes.object.isRequired
}
static async getInitialProps(ctx) {
static async getInitialProps (ctx) {
// Initial serverState with apollo (empty)
let serverState = {
apollo: {
@ -76,12 +76,12 @@ export default ComposedComponent => {
}
}
constructor(props) {
constructor (props) {
super(props)
this.apollo = initApollo(props.serverState.apollo.data)
}
render() {
render () {
return (
<ApolloProvider client={this.apollo}>
<ComposedComponent {...this.props} />

View file

@ -10,7 +10,7 @@ import rootSaga from './rootSaga'
const sagaMiddleware = createSagaMiddleware()
export function configureStore(initialState = {}) {
export function configureStore (initialState = {}) {
const store = createStore(
rootReducer,
initialState,

View file

@ -10,7 +10,7 @@ if (!process.browser) {
global.fetch = fetch
}
function create(initialState) {
function create (initialState) {
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
return new ApolloClient({
connectToDevTools: process.browser,
@ -23,7 +23,7 @@ function create(initialState) {
})
}
export default function initApollo(initialState) {
export default function initApollo (initialState) {
// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
if (!process.browser) {

View file

@ -41,4 +41,4 @@ export const addCount = () => dispatch => {
export const initStore = (initialState = exampleInitialState) => {
return createStore(reducer, initialState, composeWithDevTools(applyMiddleware(thunkMiddleware)))
}
}

View file

@ -5,7 +5,7 @@ import Head from 'next/head'
import initApollo from './initApollo'
// Gets the display name of a JSX component for dev tools
function getComponentDisplayName(Component) {
function getComponentDisplayName (Component) {
return Component.displayName || Component.name || 'Unknown'
}
@ -18,7 +18,7 @@ export default ComposedComponent => {
serverState: PropTypes.object.isRequired
}
static async getInitialProps(ctx) {
static async getInitialProps (ctx) {
// Initial serverState with apollo (empty)
let serverState = {
apollo: {
@ -74,12 +74,12 @@ export default ComposedComponent => {
}
}
constructor(props) {
constructor (props) {
super(props)
this.apollo = initApollo(this.props.serverState.apollo.data)
}
render() {
render () {
return (
<ApolloProvider client={this.apollo}>
<ComposedComponent {...this.props} />

View file

@ -6,7 +6,7 @@ import Head from 'next/head'
import initApollo from './initApollo'
function parseCookies(req, options = {}) {
function parseCookies (req, options = {}) {
return cookie.parse(
req ? req.headers.cookie || '' : document.cookie,
options
@ -20,7 +20,7 @@ export default App => {
apolloState: PropTypes.object.isRequired
}
static async getInitialProps(ctx) {
static async getInitialProps (ctx) {
const { Component, router, ctx: { req, res } } = ctx
const apollo = initApollo({}, {
getToken: () => parseCookies(req).token
@ -73,7 +73,7 @@ export default App => {
}
}
constructor(props) {
constructor (props) {
super(props)
// `getDataFromTree` renders the component first, the client is passed off as a property.
// After that rendering is done using Next's normal rendering pipeline
@ -82,7 +82,7 @@ export default App => {
})
}
render() {
render () {
return <App {...this.props} apolloClient={this.apolloClient} />
}
}

View file

@ -1,6 +1,4 @@
import { ApolloClient } from 'apollo-boost'
import { HttpLink } from 'apollo-boost'
import { InMemoryCache } from 'apollo-boost'
import { ApolloClient, InMemoryCache, HttpLink } from 'apollo-boost'
import fetch from 'isomorphic-unfetch'
let apolloClient = null
@ -10,7 +8,7 @@ if (!process.browser) {
global.fetch = fetch
}
function create(initialState) {
function create (initialState) {
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
return new ApolloClient({
connectToDevTools: process.browser,
@ -23,7 +21,7 @@ function create(initialState) {
})
}
export default function initApollo(initialState) {
export default function initApollo (initialState) {
// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
if (!process.browser) {

View file

@ -1,3 +1,4 @@
import React from 'react'
import initApollo from './init-apollo'
import Head from 'next/head'
import { getDataFromTree } from 'react-apollo'

View file

@ -3,7 +3,7 @@ export const GA_TRACKING_ID = '<YOUR_GA_TRACKING_ID>'
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const pageview = url => {
window.gtag('config', GA_TRACKING_ID, {
page_location: url,
page_location: url
})
}
@ -12,6 +12,6 @@ export const event = ({ action, category, label, value }) => {
window.gtag('event', action, {
event_category: category,
event_label: label,
value: value,
value: value
})
}

View file

@ -1,3 +1,3 @@
export function getDisplayName(Component) {
export function getDisplayName (Component) {
return Component.displayName || Component.name || 'Unknown'
}

View file

@ -11,12 +11,12 @@ export const withI18next = (namespaces = ['common']) => ComposedComponent => {
? await ComposedComponent.getInitialProps(ctx)
: {}
const i18nInitialProps = ctx.req
const i18nInitialProps = ctx.req
? getInitialProps(ctx.req, namespaces)
: await loadNamespaces({
components: [{ props: { namespaces } }],
i18n: I18n,
});
components: [{ props: { namespaces } }],
i18n: I18n
})
return {
...composedInitialProps,

View file

@ -4,7 +4,7 @@ import {initializeStore} from '../store'
const isServer = typeof window === 'undefined'
const __NEXT_REDUX_STORE__ = '__NEXT_REDUX_STORE__'
function getOrCreateStore(initialState) {
function getOrCreateStore (initialState) {
// Always make a new store if server, otherwise state is shared between requests
if (isServer) {
return initializeStore(initialState)
@ -29,7 +29,7 @@ export default (App) => {
let appProps = {}
if (typeof App.getInitialProps === 'function') {
appProps = await App.getInitialProps.call(App, appContext)
appProps = await App.getInitialProps(appContext)
}
return {
@ -38,12 +38,12 @@ export default (App) => {
}
}
constructor(props) {
constructor (props) {
super(props)
this.reduxStore = getOrCreateStore(props.initialReduxState)
}
render() {
render () {
return <App {...this.props} reduxStore={this.reduxStore} />
}
}

View file

@ -9,7 +9,7 @@ function fetchQuery (
operation,
variables,
cacheConfig,
uploadables,
uploadables
) {
return fetch(process.env.RELAY_ENDPOINT, {
method: 'POST',

View file

@ -1 +1 @@
export default ('undefined' !== typeof window ? window.__ENV__ : process.env)
export default (typeof window !== 'undefined' ? window.__ENV__ : process.env)

View file

@ -46,7 +46,6 @@
"parser": "babel-eslint",
"ignore": [
"**/node_modules/**",
"**/examples/**/lib/**",
"**/examples/with-ioc/**",
"**/examples/with-kea/**",
"**/examples/with-mobx/**",