Skip to content

Commit 84157a3

Browse files
kazuponchrisvfritz
authored andcommitted
add cache option rule (#29)
* add cache option rule * Update warning for the cache: false option * Update cache-false.spec.js
1 parent 3c21eac commit 84157a3

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

rules/vue/cache-false.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
var chalk = require('chalk')
4+
5+
module.exports = {
6+
pattern: /\bcache\s*?:\s*?false\b/,
7+
warning: function (match) {
8+
return {
9+
reason: 'The cache option on computed properties has been deprecated, as it\'s better to simply use a method instead',
10+
fix: 'Refactor the computed property into a method',
11+
docsHash: 'cache-false',
12+
type: 'js'
13+
}
14+
}
15+
}

rules/vue/cache-false.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict'
2+
3+
const check = createRuleChecker('vue/cache-false')
4+
5+
describe('Rule: cache-false', () => {
6+
it('does not match an empty line', () => {
7+
const warning = check('')
8+
expect(warning).toBe(null)
9+
})
10+
11+
it('does not match "cache"', () => {
12+
const warning = check('cache')
13+
expect(warning).toBe(null)
14+
})
15+
16+
it('matches "cache: false,"', () => {
17+
const warning = check(`
18+
cache: false,
19+
`)
20+
expect(warning).toBeTruthy()
21+
expect(warning.fix).toBe('Refactor the computed property into a method')
22+
})
23+
24+
it('matches "cache:false,"', () => {
25+
const warning = check(`
26+
cache:false,
27+
`)
28+
expect(warning).toBeTruthy()
29+
expect(warning.fix).toBe('Refactor the computed property into a method')
30+
})
31+
32+
it('matches "cache: false,"', () => {
33+
const warning = check(`
34+
cache : false,
35+
`)
36+
expect(warning).toBeTruthy()
37+
expect(warning.fix).toBe('Refactor the computed property into a method')
38+
})
39+
})

0 commit comments

Comments
 (0)