Skip to content

Commit 7c24f5e

Browse files
authored
no-xxxx-keys: change to handle setup (#1082)
* no-dupe-keys: change to handle setup * no-reserved-keys: change to handle setup
1 parent 335692e commit 7c24f5e

File tree

4 files changed

+310
-2
lines changed

4 files changed

+310
-2
lines changed

Diff for: lib/rules/no-dupe-keys.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const utils = require('../utils')
1010
// Rule Definition
1111
// ------------------------------------------------------------------------------
1212

13-
const GROUP_NAMES = ['props', 'computed', 'data', 'methods']
13+
const GROUP_NAMES = ['props', 'computed', 'data', 'methods', 'setup']
1414

1515
module.exports = {
1616
meta: {

Diff for: lib/rules/no-reserved-keys.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const utils = require('../utils')
1111
// ------------------------------------------------------------------------------
1212

1313
const RESERVED_KEYS = require('../utils/vue-reserved.json')
14-
const GROUP_NAMES = ['props', 'computed', 'data', 'methods']
14+
const GROUP_NAMES = ['props', 'computed', 'data', 'methods', 'setup']
1515

1616
module.exports = {
1717
meta: {

Diff for: tests/lib/rules/no-dupe-keys.js

+265
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,37 @@ ruleTester.run('no-dupe-keys', rule, {
4444
`,
4545
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
4646
},
47+
{
48+
filename: 'test.vue',
49+
code: `
50+
export default {
51+
props: ['foo'],
52+
data () {
53+
return {
54+
dat: null
55+
}
56+
},
57+
data () {
58+
return
59+
},
60+
methods: {
61+
_foo () {},
62+
test () {
63+
}
64+
},
65+
setup () {
66+
const _foo = () => {}
67+
const dat = ref(null)
68+
const bar = computed(() => 'bar')
69+
70+
return {
71+
bar
72+
}
73+
}
74+
}
75+
`,
76+
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
77+
},
4778

4879
{
4980
filename: 'test.vue',
@@ -134,6 +165,51 @@ ruleTester.run('no-dupe-keys', rule, {
134165
parserOptions: { ecmaVersion: 2018, sourceType: 'module' }
135166
},
136167

168+
{
169+
filename: 'test.vue',
170+
code: `
171+
export default {
172+
...foo(),
173+
props: {
174+
...foo(),
175+
foo: String
176+
},
177+
computed: {
178+
...mapGetters({
179+
test: 'getTest'
180+
}),
181+
bar: {
182+
get () {
183+
}
184+
}
185+
},
186+
data: {
187+
...foo(),
188+
dat: null
189+
},
190+
methods: {
191+
...foo(),
192+
test () {
193+
}
194+
},
195+
data () {
196+
return {
197+
...dat
198+
}
199+
},
200+
setup () {
201+
const com = computed(() => 1)
202+
203+
return {
204+
...foo(),
205+
com
206+
}
207+
}
208+
}
209+
`,
210+
parserOptions: { ecmaVersion: 2018, sourceType: 'module' }
211+
},
212+
137213
{
138214
filename: 'test.vue',
139215
code: `
@@ -224,6 +300,39 @@ ruleTester.run('no-dupe-keys', rule, {
224300
}
225301
`,
226302
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
303+
},
304+
{
305+
filename: 'test.vue',
306+
code: `
307+
// @vue/component
308+
export const compA = {
309+
props: {
310+
propA: String
311+
},
312+
setup (props) {
313+
const com = computed(() => props.propA)
314+
315+
return {
316+
com
317+
}
318+
}
319+
}
320+
321+
// @vue/component
322+
export const compB = {
323+
props: {
324+
propA: String
325+
},
326+
setup (props) {
327+
const com = computed(() => props.propA)
328+
329+
return {
330+
com
331+
}
332+
}
333+
}
334+
`,
335+
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
227336
}
228337
],
229338

@@ -245,6 +354,13 @@ ruleTester.run('no-dupe-keys', rule, {
245354
methods: {
246355
foo () {
247356
}
357+
},
358+
setup () {
359+
const foo = ref(1)
360+
361+
return {
362+
foo
363+
}
248364
}
249365
}
250366
`,
@@ -258,6 +374,9 @@ ruleTester.run('no-dupe-keys', rule, {
258374
}, {
259375
message: 'Duplicated key \'foo\'.',
260376
line: 14
377+
}, {
378+
message: 'Duplicated key \'foo\'.',
379+
line: 21
261380
}]
262381
},
263382
{
@@ -277,6 +396,13 @@ ruleTester.run('no-dupe-keys', rule, {
277396
methods: {
278397
foo () {
279398
}
399+
},
400+
setup: () => {
401+
const foo = computed(() => 0)
402+
403+
return {
404+
foo
405+
}
280406
}
281407
}
282408
`,
@@ -290,6 +416,9 @@ ruleTester.run('no-dupe-keys', rule, {
290416
}, {
291417
message: 'Duplicated key \'foo\'.',
292418
line: 14
419+
}, {
420+
message: 'Duplicated key \'foo\'.',
421+
line: 21
293422
}]
294423
},
295424
{
@@ -341,6 +470,13 @@ ruleTester.run('no-dupe-keys', rule, {
341470
methods: {
342471
foo () {
343472
}
473+
},
474+
setup (props) {
475+
const foo = computed(() => props.foo)
476+
477+
return {
478+
foo
479+
}
344480
}
345481
}
346482
`,
@@ -354,6 +490,9 @@ ruleTester.run('no-dupe-keys', rule, {
354490
}, {
355491
message: 'Duplicated key \'foo\'.',
356492
line: 16
493+
}, {
494+
message: 'Duplicated key \'foo\'.',
495+
line: 23
357496
}]
358497
},
359498
{
@@ -374,6 +513,132 @@ ruleTester.run('no-dupe-keys', rule, {
374513
message: 'Duplicated key \'bar\'.',
375514
line: 7
376515
}]
516+
},
517+
{
518+
filename: 'test.vue',
519+
code: `
520+
export default {
521+
methods: {
522+
foo () {
523+
return 0
524+
}
525+
},
526+
setup () {
527+
const foo = () => 0
528+
529+
return {
530+
foo
531+
}
532+
}
533+
}
534+
`,
535+
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
536+
errors: [{
537+
message: 'Duplicated key \'foo\'.',
538+
line: 12
539+
}]
540+
},
541+
{
542+
filename: 'test.vue',
543+
code: `
544+
export default {
545+
methods: {
546+
foo () {
547+
return 0
548+
}
549+
},
550+
setup () {
551+
return {
552+
foo: () => 0
553+
}
554+
}
555+
}
556+
`,
557+
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
558+
errors: [{
559+
message: 'Duplicated key \'foo\'.',
560+
line: 10
561+
}]
562+
},
563+
{
564+
filename: 'test.vue',
565+
code: `
566+
export default {
567+
methods: {
568+
foo () {
569+
return 0
570+
}
571+
},
572+
setup: () => ({
573+
foo: () => 0
574+
})
575+
}
576+
`,
577+
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
578+
errors: [{
579+
message: 'Duplicated key \'foo\'.',
580+
line: 9
581+
}]
582+
},
583+
{
584+
filename: 'test.vue',
585+
code: `
586+
export default {
587+
computed: {
588+
foo () {
589+
return 0
590+
}
591+
},
592+
setup: () => ({
593+
foo: computed(() => 0)
594+
})
595+
}
596+
`,
597+
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
598+
errors: [{
599+
message: 'Duplicated key \'foo\'.',
600+
line: 9
601+
}]
602+
},
603+
{
604+
filename: 'test.vue',
605+
code: `
606+
export default {
607+
data() {
608+
return {
609+
foo: 0
610+
}
611+
},
612+
setup: () => ({
613+
foo: ref(0)
614+
})
615+
}
616+
`,
617+
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
618+
errors: [{
619+
message: 'Duplicated key \'foo\'.',
620+
line: 9
621+
}]
622+
},
623+
{
624+
filename: 'test.vue',
625+
code: `
626+
export default {
627+
data() {
628+
return {
629+
foo: 0
630+
}
631+
},
632+
setup: () => ({
633+
foo: 0
634+
})
635+
}
636+
`,
637+
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
638+
errors: [{
639+
message: 'Duplicated key \'foo\'.',
640+
line: 9
641+
}]
377642
}
378643
]
379644
})

0 commit comments

Comments
 (0)