Skip to content

Commit 42b4c19

Browse files
committed
catch router.start
1 parent 1020a54 commit 42b4c19

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

rules/vue-router/router-start.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
var chalk = require('chalk')
4+
5+
module.exports = {
6+
pattern: /\b(router\s*?\.\s*?start)\s*?\(/,
7+
warning: function (match, routerStart) {
8+
return {
9+
reason: 'Starting an app with routing no longer requires a special method - the router can simply be passed to the root Vue instance as option',
10+
fix: (
11+
'Replace ' + chalk.red(routerStart) + ' with ' +
12+
chalk.green('router: router') +
13+
' on your root Vue instance (see link below for details)'
14+
),
15+
docsHash: 'router-start-deprecated'
16+
}
17+
}
18+
}

rules/vue-router/router-start.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict'
2+
3+
const check = createRuleChecker('vue-router/router-start')
4+
5+
describe('Rule: router-start', () => {
6+
it('does not match an empty line', () => {
7+
const warning = check('')
8+
expect(warning).toBe(null)
9+
})
10+
11+
it('does not match "router"', () => {
12+
const warning = check('router')
13+
expect(warning).toBe(null)
14+
})
15+
16+
it('does not match "start"', () => {
17+
const warning = check('on')
18+
expect(warning).toBe(null)
19+
})
20+
21+
it('matches "router.start("', () => {
22+
const warning = check(`
23+
router.start(
24+
`)
25+
expect(warning).toBeTruthy()
26+
expect(warning.fix).toBe('Replace router.start with router: router on your root Vue instance (see link below for details)')
27+
})
28+
})

0 commit comments

Comments
 (0)