Skip to content

Commit

Permalink
no-xxxx-keys: change to handle setup (#1082)
Browse files Browse the repository at this point in the history
* no-dupe-keys: change to handle setup

* no-reserved-keys: change to handle setup
  • Loading branch information
yoyo930021 committed Apr 21, 2020
1 parent 335692e commit 7c24f5e
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-dupe-keys.js
Expand Up @@ -10,7 +10,7 @@ const utils = require('../utils')
// Rule Definition
// ------------------------------------------------------------------------------

const GROUP_NAMES = ['props', 'computed', 'data', 'methods']
const GROUP_NAMES = ['props', 'computed', 'data', 'methods', 'setup']

module.exports = {
meta: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-reserved-keys.js
Expand Up @@ -11,7 +11,7 @@ const utils = require('../utils')
// ------------------------------------------------------------------------------

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

module.exports = {
meta: {
Expand Down
265 changes: 265 additions & 0 deletions tests/lib/rules/no-dupe-keys.js
Expand Up @@ -44,6 +44,37 @@ ruleTester.run('no-dupe-keys', rule, {
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
},
{
filename: 'test.vue',
code: `
export default {
props: ['foo'],
data () {
return {
dat: null
}
},
data () {
return
},
methods: {
_foo () {},
test () {
}
},
setup () {
const _foo = () => {}
const dat = ref(null)
const bar = computed(() => 'bar')
return {
bar
}
}
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
},

{
filename: 'test.vue',
Expand Down Expand Up @@ -134,6 +165,51 @@ ruleTester.run('no-dupe-keys', rule, {
parserOptions: { ecmaVersion: 2018, sourceType: 'module' }
},

{
filename: 'test.vue',
code: `
export default {
...foo(),
props: {
...foo(),
foo: String
},
computed: {
...mapGetters({
test: 'getTest'
}),
bar: {
get () {
}
}
},
data: {
...foo(),
dat: null
},
methods: {
...foo(),
test () {
}
},
data () {
return {
...dat
}
},
setup () {
const com = computed(() => 1)
return {
...foo(),
com
}
}
}
`,
parserOptions: { ecmaVersion: 2018, sourceType: 'module' }
},

{
filename: 'test.vue',
code: `
Expand Down Expand Up @@ -224,6 +300,39 @@ ruleTester.run('no-dupe-keys', rule, {
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
},
{
filename: 'test.vue',
code: `
// @vue/component
export const compA = {
props: {
propA: String
},
setup (props) {
const com = computed(() => props.propA)
return {
com
}
}
}
// @vue/component
export const compB = {
props: {
propA: String
},
setup (props) {
const com = computed(() => props.propA)
return {
com
}
}
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
}
],

Expand All @@ -245,6 +354,13 @@ ruleTester.run('no-dupe-keys', rule, {
methods: {
foo () {
}
},
setup () {
const foo = ref(1)
return {
foo
}
}
}
`,
Expand All @@ -258,6 +374,9 @@ ruleTester.run('no-dupe-keys', rule, {
}, {
message: 'Duplicated key \'foo\'.',
line: 14
}, {
message: 'Duplicated key \'foo\'.',
line: 21
}]
},
{
Expand All @@ -277,6 +396,13 @@ ruleTester.run('no-dupe-keys', rule, {
methods: {
foo () {
}
},
setup: () => {
const foo = computed(() => 0)
return {
foo
}
}
}
`,
Expand All @@ -290,6 +416,9 @@ ruleTester.run('no-dupe-keys', rule, {
}, {
message: 'Duplicated key \'foo\'.',
line: 14
}, {
message: 'Duplicated key \'foo\'.',
line: 21
}]
},
{
Expand Down Expand Up @@ -341,6 +470,13 @@ ruleTester.run('no-dupe-keys', rule, {
methods: {
foo () {
}
},
setup (props) {
const foo = computed(() => props.foo)
return {
foo
}
}
}
`,
Expand All @@ -354,6 +490,9 @@ ruleTester.run('no-dupe-keys', rule, {
}, {
message: 'Duplicated key \'foo\'.',
line: 16
}, {
message: 'Duplicated key \'foo\'.',
line: 23
}]
},
{
Expand All @@ -374,6 +513,132 @@ ruleTester.run('no-dupe-keys', rule, {
message: 'Duplicated key \'bar\'.',
line: 7
}]
},
{
filename: 'test.vue',
code: `
export default {
methods: {
foo () {
return 0
}
},
setup () {
const foo = () => 0
return {
foo
}
}
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{
message: 'Duplicated key \'foo\'.',
line: 12
}]
},
{
filename: 'test.vue',
code: `
export default {
methods: {
foo () {
return 0
}
},
setup () {
return {
foo: () => 0
}
}
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{
message: 'Duplicated key \'foo\'.',
line: 10
}]
},
{
filename: 'test.vue',
code: `
export default {
methods: {
foo () {
return 0
}
},
setup: () => ({
foo: () => 0
})
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{
message: 'Duplicated key \'foo\'.',
line: 9
}]
},
{
filename: 'test.vue',
code: `
export default {
computed: {
foo () {
return 0
}
},
setup: () => ({
foo: computed(() => 0)
})
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{
message: 'Duplicated key \'foo\'.',
line: 9
}]
},
{
filename: 'test.vue',
code: `
export default {
data() {
return {
foo: 0
}
},
setup: () => ({
foo: ref(0)
})
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{
message: 'Duplicated key \'foo\'.',
line: 9
}]
},
{
filename: 'test.vue',
code: `
export default {
data() {
return {
foo: 0
}
},
setup: () => ({
foo: 0
})
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{
message: 'Duplicated key \'foo\'.',
line: 9
}]
}
]
})

0 comments on commit 7c24f5e

Please sign in to comment.