mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
lint: require await in async function (#3676)
* lint: require await in async function * lint: replace "error" with 2 in config
This commit is contained in:
parent
427e836688
commit
b4d81dc584
18
.eslintrc.js
18
.eslintrc.js
@ -14,7 +14,7 @@ module.exports = {
|
|||||||
'standard-jsx',
|
'standard-jsx',
|
||||||
'plugin:import/errors',
|
'plugin:import/errors',
|
||||||
'plugin:import/warnings',
|
'plugin:import/warnings',
|
||||||
"plugin:vue/recommended"
|
'plugin:vue/recommended'
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
'vue',
|
'vue',
|
||||||
@ -33,7 +33,7 @@ module.exports = {
|
|||||||
'import/first': 2,
|
'import/first': 2,
|
||||||
|
|
||||||
// Other import rules
|
// Other import rules
|
||||||
"import/no-mutable-exports": 2,
|
'import/no-mutable-exports': 2,
|
||||||
|
|
||||||
// Allow unresolved imports
|
// Allow unresolved imports
|
||||||
'import/no-unresolved': 0,
|
'import/no-unresolved': 0,
|
||||||
@ -48,12 +48,16 @@ module.exports = {
|
|||||||
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
|
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
|
||||||
|
|
||||||
// Prefer const over let
|
// Prefer const over let
|
||||||
"prefer-const": ["error", {
|
'prefer-const': [2, {
|
||||||
"destructuring": "any",
|
'destructuring': 'any',
|
||||||
"ignoreReadBeforeAssign": false
|
'ignoreReadBeforeAssign': false
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
// No async function without await
|
||||||
|
'require-await': 2,
|
||||||
|
|
||||||
'dot-notation': 2,
|
'dot-notation': 2,
|
||||||
|
|
||||||
// Do not allow console.logs etc...
|
// Do not allow console.logs etc...
|
||||||
'no-console': 2,
|
'no-console': 2,
|
||||||
'space-before-function-paren': [2, {
|
'space-before-function-paren': [2, {
|
||||||
@ -63,8 +67,8 @@ module.exports = {
|
|||||||
'vue/no-parsing-error': [2, {
|
'vue/no-parsing-error': [2, {
|
||||||
'x-invalid-end-tag': false
|
'x-invalid-end-tag': false
|
||||||
}],
|
}],
|
||||||
"vue/max-attributes-per-line": [2, {
|
'vue/max-attributes-per-line': [2, {
|
||||||
"singleline": 5,
|
'singleline': 5,
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ export default class ModuleContainer {
|
|||||||
return this.addModule(moduleOpts, true /* require once */)
|
return this.addModule(moduleOpts, true /* require once */)
|
||||||
}
|
}
|
||||||
|
|
||||||
async addModule(moduleOpts, requireOnce) {
|
addModule(moduleOpts, requireOnce) {
|
||||||
let src
|
let src
|
||||||
let options
|
let options
|
||||||
let handler
|
let handler
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
async asyncData(context, callback) {
|
asyncData(context, callback) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
callback(null, { name: 'Callback Nuxt.js' })
|
callback(null, { name: 'Callback Nuxt.js' })
|
||||||
}, 10)
|
}, 10)
|
||||||
|
@ -14,7 +14,7 @@ const countries = [
|
|||||||
'Czech Republic',
|
'Czech Republic',
|
||||||
'Netherlands'
|
'Netherlands'
|
||||||
]
|
]
|
||||||
async function search(q) {
|
function search(q) {
|
||||||
q = String(q || '').toLowerCase()
|
q = String(q || '').toLowerCase()
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
2
test/fixtures/ssr/pages/asyncData.vue
vendored
2
test/fixtures/ssr/pages/asyncData.vue
vendored
@ -6,7 +6,7 @@
|
|||||||
import { nextId } from '@/lib/db'
|
import { nextId } from '@/lib/db'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async asyncData() {
|
asyncData() {
|
||||||
return {
|
return {
|
||||||
id: nextId()
|
id: nextId()
|
||||||
}
|
}
|
||||||
|
2
test/fixtures/ssr/pages/fetch.vue
vendored
2
test/fixtures/ssr/pages/fetch.vue
vendored
@ -6,7 +6,7 @@
|
|||||||
import { nextId } from '@/lib/db'
|
import { nextId } from '@/lib/db'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async fetch({store}) {
|
fetch({store}) {
|
||||||
// We use store just as a shared reference
|
// We use store just as a shared reference
|
||||||
store.__id = nextId()
|
store.__id = nextId()
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,13 @@ describe('basic config defaults', () => {
|
|||||||
expect(Nuxt.version).toBe(version)
|
expect(Nuxt.version).toBe(version)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('modulesDir uses /node_modules as default if not set', async () => {
|
test('modulesDir uses /node_modules as default if not set', () => {
|
||||||
const options = Options.from({})
|
const options = Options.from({})
|
||||||
const currentNodeModulesDir = resolve(__dirname, '..', '..', 'node_modules')
|
const currentNodeModulesDir = resolve(__dirname, '..', '..', 'node_modules')
|
||||||
expect(options.modulesDir.includes(currentNodeModulesDir)).toBe(true)
|
expect(options.modulesDir.includes(currentNodeModulesDir)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('vendor has been deprecated', async () => {
|
test('vendor has been deprecated', () => {
|
||||||
jest.spyOn(consola, 'warn')
|
jest.spyOn(consola, 'warn')
|
||||||
|
|
||||||
const options = Options.from({
|
const options = Options.from({
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { loadFixture, getPort, Nuxt, Builder, rp } from '../utils'
|
import { Builder, getPort, loadFixture, Nuxt, rp } from '../utils'
|
||||||
|
|
||||||
let port
|
let port
|
||||||
const url = route => 'http://localhost:' + port + route
|
const url = route => 'http://localhost:' + port + route
|
||||||
@ -32,7 +32,7 @@ describe('basic dev', () => {
|
|||||||
await nuxt.listen(port, 'localhost')
|
await nuxt.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Config: build.transpile', async () => {
|
test('Config: build.transpile', () => {
|
||||||
expect(transpile('vue-test')).toBe(true)
|
expect(transpile('vue-test')).toBe(true)
|
||||||
expect(transpile('node_modules/test.js')).toBe(false)
|
expect(transpile('node_modules/test.js')).toBe(false)
|
||||||
expect(transpile('node_modules/vue-test')).toBe(true)
|
expect(transpile('node_modules/vue-test')).toBe(true)
|
||||||
|
@ -4,7 +4,7 @@ describe('basic fail generate', () => {
|
|||||||
test('Fail with routes() which throw an error', async () => {
|
test('Fail with routes() which throw an error', async () => {
|
||||||
const options = loadFixture('basic', {
|
const options = loadFixture('basic', {
|
||||||
generate: {
|
generate: {
|
||||||
async routes() {
|
routes() {
|
||||||
throw new Error('Not today!')
|
throw new Error('Not today!')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { resolve } from 'path'
|
|||||||
import { remove } from 'fs-extra'
|
import { remove } from 'fs-extra'
|
||||||
import serveStatic from 'serve-static'
|
import serveStatic from 'serve-static'
|
||||||
import finalhandler from 'finalhandler'
|
import finalhandler from 'finalhandler'
|
||||||
import { loadFixture, getPort, Nuxt, Generator, Builder, rp } from '../utils'
|
import { Builder, Generator, getPort, loadFixture, Nuxt, rp } from '../utils'
|
||||||
|
|
||||||
let port
|
let port
|
||||||
const url = route => 'http://localhost:' + port + route
|
const url = route => 'http://localhost:' + port + route
|
||||||
@ -16,7 +16,7 @@ let generator = null
|
|||||||
|
|
||||||
describe('basic generate', () => {
|
describe('basic generate', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const config = loadFixture('basic', {generate: {dir: '.nuxt-generate'}})
|
const config = loadFixture('basic', { generate: { dir: '.nuxt-generate' } })
|
||||||
const nuxt = new Nuxt(config)
|
const nuxt = new Nuxt(config)
|
||||||
const builder = new Builder(nuxt)
|
const builder = new Builder(nuxt)
|
||||||
builder.build = jest.fn()
|
builder.build = jest.fn()
|
||||||
@ -34,16 +34,16 @@ describe('basic generate', () => {
|
|||||||
server.listen(port)
|
server.listen(port)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Check builder', async () => {
|
test('Check builder', () => {
|
||||||
expect(generator.builder.isStatic).toBe(true)
|
expect(generator.builder.isStatic).toBe(true)
|
||||||
expect(generator.builder.build).toHaveBeenCalledTimes(1)
|
expect(generator.builder.build).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Check ready hook called', async () => {
|
test('Check ready hook called', () => {
|
||||||
expect(generator.nuxt.__hook_called__).toBe(true)
|
expect(generator.nuxt.__hook_called__).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Format errors', async () => {
|
test('Format errors', () => {
|
||||||
const error = generator._formatErrors([
|
const error = generator._formatErrors([
|
||||||
{ type: 'handled', route: '/h1', error: 'page not found' },
|
{ type: 'handled', route: '/h1', error: 'page not found' },
|
||||||
{ type: 'unhandled', route: '/h2', error: { stack: 'unhandled error stack' } }
|
{ type: 'unhandled', route: '/h2', error: { stack: 'unhandled error stack' } }
|
||||||
|
@ -18,7 +18,7 @@ const getHeader = debug => debug ? 'content-security-policy-report-only' : 'cont
|
|||||||
const cspHeader = getHeader(false)
|
const cspHeader = getHeader(false)
|
||||||
const reportOnlyHeader = getHeader(true)
|
const reportOnlyHeader = getHeader(true)
|
||||||
|
|
||||||
const startCspDevServer = async csp => startCspServer(csp, false)
|
const startCspDevServer = csp => startCspServer(csp, false)
|
||||||
|
|
||||||
describe('basic ssr csp', () => {
|
describe('basic ssr csp', () => {
|
||||||
let nuxt
|
let nuxt
|
||||||
|
@ -33,7 +33,7 @@ describe('error', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Error: resolvePath()', async () => {
|
test('Error: resolvePath()', () => {
|
||||||
expect(() => nuxt.resolvePath()).toThrowError()
|
expect(() => nuxt.resolvePath()).toThrowError()
|
||||||
expect(() => nuxt.resolvePath('@/pages/about.vue')).toThrowError('Cannot resolve "@/pages/about.vue"')
|
expect(() => nuxt.resolvePath('@/pages/about.vue')).toThrowError('Cannot resolve "@/pages/about.vue"')
|
||||||
})
|
})
|
||||||
|
@ -57,7 +57,7 @@ describe('fallback generate', () => {
|
|||||||
expect(existsSync(resolve(distDir, '404.html'))).toBe(false)
|
expect(existsSync(resolve(distDir, '404.html'))).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('generate.fallback = true is transformed to /404.html', async () => {
|
test('generate.fallback = true is transformed to /404.html', () => {
|
||||||
nuxt.options.generate.fallback = true
|
nuxt.options.generate.fallback = true
|
||||||
const options = Options.from(nuxt.options)
|
const options = Options.from(nuxt.options)
|
||||||
expect(options.generate.fallback).toBe('404.html')
|
expect(options.generate.fallback).toBe('404.html')
|
||||||
|
@ -31,12 +31,12 @@ describe('module', () => {
|
|||||||
expect(html.includes('<h1>Module Layouts</h1>')).toBe(true)
|
expect(html.includes('<h1>Module Layouts</h1>')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Hooks', async () => {
|
test('Hooks', () => {
|
||||||
expect(nuxt.__module_hook).toBe(1)
|
expect(nuxt.__module_hook).toBe(1)
|
||||||
expect(nuxt.__renderer_hook).toBe(2)
|
expect(nuxt.__renderer_hook).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Hooks - Functional', async () => {
|
test('Hooks - Functional', () => {
|
||||||
expect(nuxt.__ready_called__).toBe(true)
|
expect(nuxt.__ready_called__).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ describe('module', () => {
|
|||||||
expect(nuxt.__render_context).toBeTruthy()
|
expect(nuxt.__render_context).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('AddVendor - deprecated', async () => {
|
test('AddVendor - deprecated', () => {
|
||||||
jest.spyOn(consola, 'warn')
|
jest.spyOn(consola, 'warn')
|
||||||
|
|
||||||
nuxt.moduleContainer.addVendor('nuxt-test')
|
nuxt.moduleContainer.addVendor('nuxt-test')
|
||||||
|
Loading…
Reference in New Issue
Block a user