Skip to content

Commit 8736216

Browse files
committed
catch router.alias
1 parent 3f527dc commit 8736216

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

rules/vue-router/router-alias.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
var chalk = require('chalk')
4+
5+
module.exports = {
6+
pattern: /\b(router\s*?\.\s*?alias)\s*?\(/,
7+
warning: function (match, routerAlias) {
8+
return {
9+
reason: 'Aliases have been moved to an option on route definitions to improve config organization',
10+
fix: (
11+
'Replace ' + chalk.red(routerAlias) + ' with ' +
12+
'an alias option in a route definition (see link below for details)'
13+
),
14+
docsHash: 'router-alias-deprecated'
15+
}
16+
}
17+
}

rules/vue-router/router-alias.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-alias')
4+
5+
describe('Rule: router-alias', () => {
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 "alias"', () => {
17+
const warning = check('on')
18+
expect(warning).toBe(null)
19+
})
20+
21+
it('matches "router.alias("', () => {
22+
const warning = check(`
23+
router.alias(
24+
`)
25+
expect(warning).toBeTruthy()
26+
expect(warning.fix).toBe('Replace router.alias with an alias option in a route definition (see link below for details)')
27+
})
28+
})

0 commit comments

Comments
 (0)