Skip to content

Commit f72621c

Browse files
committed
catch router root option
1 parent 101b2a2 commit f72621c

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

rules/vue-router/root-option.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: /\broot\s*?:\s*?['"`]\//,
7+
warning: function (match) {
8+
return {
9+
reason: 'Renamed to base for consistency with the HTML <base> element',
10+
fix: (
11+
'Rename the ' + chalk.red('root') + ' option to ' +
12+
chalk.green('base')
13+
),
14+
docsHash: 'root-deprecated'
15+
}
16+
}
17+
}

rules/vue-router/root-option.spec.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'use strict'
2+
3+
const check = createRuleChecker('vue-router/root-option')
4+
5+
describe('Rule: root-option', () => {
6+
it('does not match an empty line', () => {
7+
const warning = check('')
8+
expect(warning).toBe(null)
9+
})
10+
11+
it('does not match "root"', () => {
12+
const warning = check('root')
13+
expect(warning).toBe(null)
14+
})
15+
16+
it('does not match "root:"', () => {
17+
const warning = check('root:')
18+
expect(warning).toBe(null)
19+
})
20+
21+
it('does not match "root: \'\'"', () => {
22+
const warning = check('root: \'\'')
23+
expect(warning).toBe(null)
24+
})
25+
26+
it('does not match "root: \'foo\'"', () => {
27+
const warning = check('root: \'foo\'')
28+
expect(warning).toBe(null)
29+
})
30+
31+
it('matches "root: \'/\'"', () => {
32+
const warning = check(`
33+
root: '/'
34+
`)
35+
expect(warning).toBeTruthy()
36+
expect(warning.fix).toBe('Rename the root option to base')
37+
})
38+
39+
it('matches "root: "/""', () => {
40+
const warning = check(`
41+
root: "/"
42+
`)
43+
expect(warning).toBeTruthy()
44+
expect(warning.fix).toBe('Rename the root option to base')
45+
})
46+
47+
it('matches "root: `/`', () => {
48+
const warning = check(`
49+
root: \`/\`
50+
`)
51+
expect(warning).toBeTruthy()
52+
expect(warning.fix).toBe('Rename the root option to base')
53+
})
54+
55+
it('matches "root: \'/foo\'"', () => {
56+
const warning = check(`
57+
root: '/foo'
58+
`)
59+
expect(warning).toBeTruthy()
60+
expect(warning.fix).toBe('Rename the root option to base')
61+
})
62+
63+
it('matches "root: \'/foo/bar\'"', () => {
64+
const warning = check(`
65+
root: '/foo/bar'
66+
`)
67+
expect(warning).toBeTruthy()
68+
expect(warning.fix).toBe('Rename the root option to base')
69+
})
70+
})

0 commit comments

Comments
 (0)