Skip to content

Commit 507fcde

Browse files
committed
catch arbitrary route properties
1 parent 1484c49 commit 507fcde

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
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(route\s*\.\s*)((?!(?:path|components?|instances|name|parent|redirect|matchAs|beforeEnter|meta|query|params|matched|router|subRoutes|fullPath))\w+)/,
7+
warning: function (match, routeDot, property) {
8+
return {
9+
reason: 'Arbitrary route properties must now be scoped under the new meta property, to avoid conflicts with future features',
10+
fix: (
11+
'Replace ' + chalk.red(match) + ' with ' +
12+
chalk.green(routeDot + 'meta.' + property) +
13+
', then also update the route option to be scoped under meta'
14+
),
15+
docsHash: 'Arbitrary-Route-Properties'
16+
}
17+
}
18+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict'
2+
3+
const check = createRuleChecker('vue-router/arbitrary-route-properties')
4+
5+
describe('Rule: arbitrary-route-properties', () => {
6+
it('does not match an empty line', () => {
7+
const warning = check('')
8+
expect(warning).toBe(null)
9+
})
10+
11+
it('does not match "route.meta"', () => {
12+
const warning = check('route.meta')
13+
expect(warning).toBe(null)
14+
})
15+
16+
it('does not match "route.path"', () => {
17+
const warning = check('route.path')
18+
expect(warning).toBe(null)
19+
})
20+
21+
it('does not match "route.query"', () => {
22+
const warning = check('route.query')
23+
expect(warning).toBe(null)
24+
})
25+
26+
it('does not match "route.redirect"', () => {
27+
const warning = check('route.query')
28+
expect(warning).toBe(null)
29+
})
30+
31+
it('matches "route.foo"', () => {
32+
const warning = check(`
33+
route.foo
34+
`)
35+
expect(warning).toBeTruthy()
36+
expect(warning.fix).toBe('Replace route.foo with route.meta.foo, then also update the route option to be scoped under meta')
37+
})
38+
39+
it('matches "route.foo.bar.baz"', () => {
40+
const warning = check(`
41+
route.foo.bar.baz
42+
`)
43+
expect(warning).toBeTruthy()
44+
expect(warning.fix).toBe('Replace route.foo with route.meta.foo, then also update the route option to be scoped under meta')
45+
})
46+
47+
it('matches "route.foo[1]"', () => {
48+
const warning = check(`
49+
route.foo[1]
50+
`)
51+
expect(warning).toBeTruthy()
52+
expect(warning.fix).toBe('Replace route.foo with route.meta.foo, then also update the route option to be scoped under meta')
53+
})
54+
})

0 commit comments

Comments
 (0)