Skip to content

Commit

Permalink
Lint examples (#4985)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
HaNdTriX authored and timneutkens committed Aug 20, 2018
1 parent 639df91 commit 5ff7c07
Show file tree
Hide file tree
Showing 25 changed files with 49 additions and 51 deletions.
4 changes: 2 additions & 2 deletions examples/with-apollo-and-redux-saga/lib/clock/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ export const actionTypes = {
TICK_CLOCK: 'TICK_CLOCK'
}

export function startClock(isServer=true) {
export function startClock (isServer = true) {
return {
type: actionTypes.START_CLOCK,
light: isServer,
lastUpdate: null
}
}

export function tickClock(isServer) {
export function tickClock (isServer) {
return {
type: actionTypes.TICK_CLOCK,
light: !isServer,
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo-and-redux-saga/lib/clock/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo-and-redux-saga/lib/clock/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions examples/with-apollo-and-redux-saga/lib/count/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
2 changes: 1 addition & 1 deletion examples/with-apollo-and-redux-saga/lib/count/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/with-apollo-and-redux-saga/lib/initApollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions examples/with-apollo-and-redux-saga/lib/placeholder/sagas.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo-and-redux-saga/lib/rootSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

Expand Down
8 changes: 4 additions & 4 deletions examples/with-apollo-and-redux-saga/lib/withApollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -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: {
Expand Down Expand Up @@ -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} />
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo-and-redux-saga/lib/withReduxSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import rootSaga from './rootSaga'

const sagaMiddleware = createSagaMiddleware()

export function configureStore(initialState = {}) {
export function configureStore (initialState = {}) {
const store = createStore(
rootReducer,
initialState,
Expand Down
4 changes: 2 additions & 2 deletions examples/with-apollo-and-redux/lib/initApollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo-and-redux/lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ export const addCount = () => dispatch => {

export const initStore = (initialState = exampleInitialState) => {
return createStore(reducer, initialState, composeWithDevTools(applyMiddleware(thunkMiddleware)))
}
}
8 changes: 4 additions & 4 deletions examples/with-apollo-and-redux/lib/withApollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -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: {
Expand Down Expand Up @@ -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} />
Expand Down
8 changes: 4 additions & 4 deletions examples/with-apollo-auth/lib/withApollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -82,7 +82,7 @@ export default App => {
})
}

render() {
render () {
return <App {...this.props} apolloClient={this.apolloClient} />
}
}
Expand Down
8 changes: 3 additions & 5 deletions examples/with-apollo/lib/init-apollo.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions examples/with-apollo/lib/with-apollo-client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react'
import initApollo from './init-apollo'
import Head from 'next/head'
import { getDataFromTree } from 'react-apollo'
Expand Down
4 changes: 2 additions & 2 deletions examples/with-google-analytics/lib/gtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

Expand All @@ -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
})
}
2 changes: 1 addition & 1 deletion examples/with-higher-order-component/lib/getDisplayName.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function getDisplayName(Component) {
export function getDisplayName (Component) {
return Component.displayName || Component.name || 'Unknown'
}
8 changes: 4 additions & 4 deletions examples/with-react-i18next/lib/withI18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions examples/with-redux/lib/with-redux-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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} />
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/with-relay-modern/lib/createRelayEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function fetchQuery (
operation,
variables,
cacheConfig,
uploadables,
uploadables
) {
return fetch(process.env.RELAY_ENDPOINT, {
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion examples/with-universal-configuration-runtime/lib/env.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default ('undefined' !== typeof window ? window.__ENV__ : process.env)
export default (typeof window !== 'undefined' ? window.__ENV__ : process.env)
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"parser": "babel-eslint",
"ignore": [
"**/node_modules/**",
"**/examples/**/lib/**",
"**/examples/with-ioc/**",
"**/examples/with-kea/**",
"**/examples/with-mobx/**",
Expand Down

0 comments on commit 5ff7c07

Please sign in to comment.