Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cedc497

Browse files
committedOct 24, 2016
prevent router lifecycle hooks matching embedded text with parentheses
1 parent 619d00e commit cedc497

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed
 

‎rules/vue-router/router-lifecycle-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var chalk = require('chalk')
44

55
module.exports = {
6-
pattern: /\bdata\s*?(?::\s*\(?\s*[\w,\s]+\)?\s*=>|\(\s*\w+)/,
6+
pattern: /^\s*data\s*?(?::\s*\(?\s*[\w,\s]+\)?\s*=>|\(\s*\w+)/,
77
warning: function (match, hook) {
88
return {
99
reason: 'The data route lifecycle hook has been deprecated',

‎rules/vue-router/router-lifecycle-data.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ describe('Rule: router-lifecycle-data', () => {
5757
expect(warning).toBe(null)
5858
})
5959

60+
it('does not match activate in text with parentheses after it', () => {
61+
const warning = check(`
62+
blah blah data (blah blah)
63+
`)
64+
expect(warning).toBe(null)
65+
})
66+
6067
it('matches data with ES2015 arrow function and one argument', () => {
6168
const warning = check(`
6269
data: foo => {

‎rules/vue-router/router-lifecycle-hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const extraInfo = {
1818

1919
module.exports = {
2020
pattern: new RegExp(
21-
'\\b(' +
21+
'^\\s*(' +
2222
Object.keys(hookReplacements).join('|') +
2323
')\\s*?(?::|\\()'
2424
),

‎rules/vue-router/router-lifecycle-hooks.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ describe('Rule: router-lifecycle-hooks', () => {
1313
expect(warning).toBe(null)
1414
})
1515

16+
it('does not match activated:', () => {
17+
const warning = check('activated:')
18+
expect(warning).toBe(null)
19+
})
20+
21+
it('does not match data in text with parentheses after it', () => {
22+
const warning = check(`
23+
blah blah activate (blah blah)
24+
`)
25+
expect(warning).toBe(null)
26+
})
27+
1628
it('matches activate with ES5 function', () => {
1729
const warning = check(`
1830
activate: function () {

0 commit comments

Comments
 (0)
Please sign in to comment.