Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-xxxx-keys: change to handle setup #1082

Merged
merged 2 commits into from Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}]
}
]
})