Skip to content

Commit

Permalink
Merge pull request nuxt#1994 from clarkdo/examples_lint
Browse files Browse the repository at this point in the history
refactor: add examples to lint
  • Loading branch information
Atinux committed Oct 31, 2017
2 parents b132dec + 3e637c5 commit a99ecda
Show file tree
Hide file tree
Showing 94 changed files with 368 additions and 338 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app
node_modules
dist
.nuxt
2 changes: 1 addition & 1 deletion examples/async-component-injection/pages/_slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getPost = (slug) => ({
})
export default {
beforeCreate () {
beforeCreate() {
this.component = () => getPost(this.$route.params.slug)
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/async-data/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
},
generate: {
routes: [
'/posts/1',
'/posts/1'
]
}
}
4 changes: 2 additions & 2 deletions examples/async-data/pages/posts/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import axios from 'axios'
export default {
async asyncData ({ params }) {
async asyncData({ params }) {
// We can use async/await ES6 feature
let { data } = await axios.get(`https://jsonplaceholder.typicode.com/posts/${params.id}`)
return { post: data }
},
head () {
head() {
return {
title: this.post.title
}
Expand Down
8 changes: 4 additions & 4 deletions examples/async-data/pages/posts/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import axios from 'axios'
export default {
asyncData ({ req, params }) {
asyncData({ req, params }) {
// We can return a Promise instead of calling the callback
return axios.get('https://jsonplaceholder.typicode.com/posts')
.then((res) => {
return { posts: res.data.slice(0, 5) }
})
.then((res) => {
return { posts: res.data.slice(0, 5) }
})
},
head: {
title: 'List of posts'
Expand Down
2 changes: 1 addition & 1 deletion examples/auth-routes/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ router.post('/logout', (req, res) => {
module.exports = {
path: '/api',
handler: router
}
}
8 changes: 4 additions & 4 deletions examples/auth-routes/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

<script>
export default {
data () {
data() {
return {
formError: null,
formUsername: '',
formPassword: ''
}
},
methods: {
async login () {
async login() {
try {
await this.$store.dispatch('login', {
username: this.formUsername,
Expand All @@ -37,11 +37,11 @@ export default {
this.formUsername = ''
this.formPassword = ''
this.formError = null
} catch(e) {
} catch (e) {
this.formError = e.message
}
},
async logout () {
async logout() {
try {
await this.$store.dispatch('logout')
} catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions examples/auth-routes/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const mutations = {

export const actions = {
// nuxtServerInit is called by Nuxt.js before server-rendering every page
nuxtServerInit ({ commit }, { req }) {
nuxtServerInit({ commit }, { req }) {
if (req.session && req.session.authUser) {
commit('SET_USER', req.session.authUser)
}
},
async login ({ commit }, { username, password }) {
async login({ commit }, { username, password }) {
try {
const { data } = await axios.post('/api/login', { username, password })
commit('SET_USER', data)
Expand All @@ -29,7 +29,7 @@ export const actions = {
}
},

async logout ({ commit }) {
async logout({ commit }) {
await axios.post('/api/logout')
commit('SET_USER', null)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/axios/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
export default {
async asyncData ({ app }) {
async asyncData({ app }) {
const { data: { message: dog } } = await app.$axios.get('/dog')
return { dog }
}
Expand Down
4 changes: 2 additions & 2 deletions examples/cached-components/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<script>
export default {
name: 'date',
serverCacheKey () {
serverCacheKey() {
// Will change every 10 secondes
return Math.floor(Date.now() / 10000)
},
data () {
data() {
return { date: Date.now() }
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-build/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
app: 'app.[chunkhash].js' // default: nuxt.bundle.[chunkhash].js
},
vendor: ['lodash'],
extend (config, { isDev }) {
extend(config, { isDev }) {
if (isDev) {
config.devtool = 'eval-source-map'
}
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-layouts/pages/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script>
export default {
layout: 'dark',
asyncData ({ req }) {
asyncData({ req }) {
return {
name: req ? 'server' : 'client'
}
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-loading/components/loading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export default {
loading: false
}),
methods: {
start () {
start() {
this.loading = true
},
finish () {
finish() {
this.loading = false
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-loading/pages/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<script>
export default {
asyncData () {
asyncData() {
return new Promise((resolve) => {
setTimeout(function () {
resolve({})
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-loading/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<script>
export default {
asyncData () {
asyncData() {
return new Promise((resolve) => {
setTimeout(function () {
resolve({ name: 'world' })
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-routes/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import axios from 'axios'
export default {
async asyncData () {
async asyncData() {
const { data } = await axios.get('https://jsonplaceholder.typicode.com/users')
return { users: data }
}
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-routes/pages/users/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import axios from 'axios'
export default {
validate ({ params }) {
validate({ params }) {
return !isNaN(+params.id)
},
async asyncData ({ params, error }) {
async asyncData({ params, error }) {
try {
const { data } = await axios.get(`https://jsonplaceholder.typicode.com/users/${+params.id}`)
return data
Expand Down
1 change: 0 additions & 1 deletion examples/custom-server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "nuxt-custom-server",
"dependencies": {
"chalk": "^2.2.0",
"express": "^4.15.3",
"nuxt": "latest"
},
Expand Down
2 changes: 0 additions & 2 deletions examples/custom-server/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const app = require('express')()
const { Nuxt, Builder } = require('nuxt')
const chalk = require('chalk')

const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000
Expand All @@ -22,4 +21,3 @@ app.use(nuxt.render)

// Start express server
app.listen(port, host)
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${host}:${port}`))
2 changes: 1 addition & 1 deletion examples/dynamic-components/components/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default async () => {

return VueChart.Bar.extend({
props: ['data'],
mounted () {
mounted() {
this.renderChart(this.data)
}
})
Expand Down
4 changes: 2 additions & 2 deletions examples/dynamic-components/components/image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export default {
data: () => ({
loaded: false
}),
beforeMount () {
beforeMount() {
// Preload image
const img = new Image()
img.onload = () => {
this.loaded = true
};
}
img.src = this.data
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic-components/js/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const messages = [
{ component: 'vText', data: 'End of demo 🎉' }
]

async function streamMessages (fn, i = 0) {
async function streamMessages(fn, i = 0) {
if (i >= messages.length) return
await fn(messages[i])
setTimeout(() => streamMessages(fn, i + 1), 1500)
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic-components/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ module.exports = {
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }
]
}
}
}
2 changes: 1 addition & 1 deletion examples/dynamic-components/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
data: () => ({
messages: []
}),
mounted () {
mounted() {
// Listen for incoming messages
streamMessages(async (message) => {
// Wait for the component to load before displaying it
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic-layouts/pages/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script>
export default {
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default',
asyncData ({ req }) {
asyncData({ req }) {
return {
name: req ? 'server' : 'client'
}
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic-layouts/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

<script>
export default {
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default',
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default'
}
</script>
4 changes: 2 additions & 2 deletions examples/hello-world-jsx/pages/about.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script>
export default {
asyncData ({ req }) {
asyncData({ req }) {
return {
name: req ? 'server' : 'client'
}
},
render (h) {
render(h) {
return <div>
<p>Hi from {this.name}</p>
<nuxt-link to="/">Home page</nuxt-link>
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world-jsx/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default {
render (h) {
render(h) {
return <div>
<h1>Welcome !</h1>
<nuxt-link to="/about">About page</nuxt-link>
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world/pages/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<script>
export default {
asyncData () {
asyncData() {
return {
name: process.static ? 'static' : (process.server ? 'server' : 'client')
}
Expand Down
2 changes: 1 addition & 1 deletion examples/i18n/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<script>
export default {
methods: {
path (url) {
path(url) {
return (this.$i18n.locale === 'en' ? url : '/' + this.$i18n.locale + url)
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/i18n/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
router: {
middleware: 'i18n'
},
plugins: ['~/plugins/i18n.js',],
plugins: ['~/plugins/i18n.js'],
generate: {
routes: ['/', '/about', '/fr', '/fr/about']
}
Expand Down
2 changes: 1 addition & 1 deletion examples/i18n/pages/_lang/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script>
export default {
head () {
head() {
return { title: this.$t('about.title') }
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/i18n/pages/_lang/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script>
export default {
head () {
head() {
return { title: this.$t('home.title') }
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/i18n/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const state = () => ({
})

export const mutations = {
SET_LANG (state, locale) {
SET_LANG(state, locale) {
if (state.locales.indexOf(locale) !== -1) {
state.locale = locale
}
Expand Down
4 changes: 2 additions & 2 deletions examples/layout-transitions/pages/users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import axios from 'axios'
export default {
transition (to, from) {
transition(to, from) {
if (!from) return 'slide-left'
return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
},
async asyncData ({ query }) {
async asyncData({ query }) {
const page = query.page || 1
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
return {
Expand Down
2 changes: 1 addition & 1 deletion examples/markdownit/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<script>
export default {
data () {
data() {
return {
model: 'I am index'
}
Expand Down

0 comments on commit a99ecda

Please sign in to comment.