Skip to content

Improve support for spread operator #146

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

Merged
merged 3 commits into from
Aug 14, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/rules/order-in-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ function getOrderMap (order) {
}

function checkOrder (propertiesNodes, orderMap, context) {
const properties = propertiesNodes.map(property => property.key)
const properties = propertiesNodes
.filter(property => property.type === 'Property')
.map(property => property.key)

properties.forEach((property, i) => {
const propertiesAbove = properties.slice(0, i)
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ module.exports = {
getComputedProperties (componentObject) {
const computedPropertiesNode = componentObject.properties
.find(p =>
p.type === 'Property' &&
p.key.type === 'Identifier' &&
p.key.name === 'computed' &&
p.value.type === 'ObjectExpression'
Expand Down Expand Up @@ -480,6 +481,8 @@ module.exports = {
const nodes = node.properties.filter(p => p.type === 'Property' && groups.has(this.getStaticPropertyName(p.key)))
for (const item of nodes) {
const name = this.getStaticPropertyName(item.key)
if (!name) continue

if (item.value.type === 'ArrayExpression') {
yield * this.iterateArrayExpression(item.value, name)
} else if (item.value.type === 'ObjectExpression') {
Expand Down Expand Up @@ -531,7 +534,7 @@ module.exports = {
assert(node.type === 'FunctionExpression')
if (node.body.type === 'BlockStatement') {
for (const item of node.body.body) {
if (item.type === 'ReturnStatement' && item.argument.type === 'ObjectExpression') {
if (item.type === 'ReturnStatement' && item.argument && item.argument.type === 'ObjectExpression') {
yield * this.iterateObjectExpression(item.argument, groupName)
}
}
Expand Down
33 changes: 18 additions & 15 deletions tests/lib/rules/html-end-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,24 @@ tester.run('html-end-tags', rule, {
}
],
invalid: [
// {
// filename: "test.vue",
// code: "<template><div><hr></hr></div></template>",
// errors: ["'<hr>' should not have end tag."],
// },
// {
// filename: "test.vue",
// code: "<template><div><img></img></div></template>",
// errors: ["'<img>' should not have end tag."],
// },
// {
// filename: "test.vue",
// code: "<template><div><input></input></div></template>",
// errors: ["'<input>' should not have end tag."],
// },
// {
// filename: 'test.vue',
// code: '<template><div><hr></hr></div></template>',
// output: '<template><div><hr></template>',
// errors: ["'<hr>' should not have end tag."]
// },
// {
// filename: 'test.vue',
// code: '<template><div><img></img></div></template>',
// output: '<template><div><img></template>',
// errors: ["'<img>' should not have end tag."]
// },
// {
// filename: 'test.vue',
// code: '<template><div><input></input></div></template>',
// output: '<template><div><input></template>',
// errors: ["'<input>' should not have end tag."]
// },
{
filename: 'test.vue',
code: '<template><div><div></div></template>',
Expand Down
13 changes: 12 additions & 1 deletion tests/lib/rules/name-property-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const RuleTester = require('eslint').RuleTester

const parserOptions = {
ecmaVersion: 6,
sourceType: 'module'
sourceType: 'module',
ecmaFeatures: { experimentalObjectRestSpread: true }
}

const ruleTester = new RuleTester()
Expand All @@ -33,6 +34,16 @@ ruleTester.run('name-property-casing', rule, {
options: ['camelCase'],
parserOptions
},
{
filename: 'test.vue',
code: `
export default {
...name
}
`,
options: ['camelCase'],
parserOptions
},
{
filename: 'test.vue',
code: `
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/no-async-in-computed-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ruleTester.run('no-async-in-computed-properties', rule, {
filename: 'test.vue',
code: `
export default {
...foo,
computed: {
...mapGetters({
test: 'getTest'
Expand Down
10 changes: 9 additions & 1 deletion tests/lib/rules/no-dupe-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ ruleTester.run('no-dupe-keys', rule, {
dat: null
}
},
data () {
return
},
methods: {
_foo () {},
test () {
Expand Down Expand Up @@ -68,7 +71,12 @@ ruleTester.run('no-dupe-keys', rule, {
...foo(),
test () {
}
}
},
data () {
return {
...dat
}
},
}
`,
parserOptions: { ecmaVersion: 8, sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true }}
Expand Down
8 changes: 7 additions & 1 deletion tests/lib/rules/no-reservered-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
const rule = require('../../../lib/rules/no-reservered-keys')
const RuleTester = require('eslint').RuleTester

const parserOptions = {
ecmaVersion: 7,
sourceType: 'module',
ecmaFeatures: { experimentalObjectRestSpread: true }
}

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -39,7 +45,7 @@ ruleTester.run('no-reservered-keys', rule, {
}
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
parserOptions
}
],

Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/no-shared-component-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ ruleTester.run('no-shared-component-data', rule, {
})
`
},
{
filename: 'test.js',
code: `
new Vue({
...data,
data () {
return {
foo: 'bar'
}
}
})
`,
parserOptions: {
ecmaVersion: 7,
sourceType: 'module',
ecmaFeatures: { experimentalObjectRestSpread: true }
}
},
{
filename: 'test.js',
code: `
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/no-side-effects-in-computed-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ruleTester.run('no-side-effects-in-computed-properties', rule, {
valid: [
{
code: `Vue.component('test', {
...foo,
computed: {
...test0({}),
test1() {
Expand Down
21 changes: 14 additions & 7 deletions tests/lib/rules/order-in-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ const RuleTester = require('eslint').RuleTester

const ruleTester = new RuleTester()

const parserOptions = {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: { experimentalObjectRestSpread: true }
}

ruleTester.run('order-in-components', rule, {

valid: [
Expand All @@ -20,28 +26,29 @@ ruleTester.run('order-in-components', rule, {
props: {
propA: Number,
},
...a,
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
parserOptions
},
{
filename: 'test.vue',
code: `
export default {}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
parserOptions
},
{
filename: 'test.vue',
code: `
export default 'example-text'
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
parserOptions
},
{
filename: 'test.jsx',
Expand All @@ -55,7 +62,7 @@ ruleTester.run('order-in-components', rule, {
},
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
parserOptions
},
{
filename: 'test.js',
Expand Down Expand Up @@ -136,7 +143,7 @@ ruleTester.run('order-in-components', rule, {
},
}
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parserOptions,
errors: [{
message: 'The "props" property should be above the "data" property on line 4.',
line: 9
Expand Down Expand Up @@ -268,7 +275,7 @@ ruleTester.run('order-in-components', rule, {
name: 'burger',
};
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parserOptions,
errors: [{
message: 'The "name" property should be above the "data" property on line 3.',
line: 16
Expand All @@ -284,7 +291,7 @@ ruleTester.run('order-in-components', rule, {
test: 'ok'
};
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parserOptions,
options: [{ order: ['data', 'test', 'name'] }],
errors: [{
message: 'The "test" property should be above the "name" property on line 5.',
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/require-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ruleTester.run('require-prop-types', rule, {
filename: 'test.vue',
code: `
export default {
...foo,
props: {
...test(),
foo: String
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/require-render-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ruleTester.run('require-render-return', rule, {
valid: [
{
code: `Vue.component('test', {
...foo,
render() {
return {}
}
Expand Down
18 changes: 17 additions & 1 deletion tests/lib/rules/require-valid-default-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const RuleTester = require('eslint').RuleTester

const parserOptions = {
ecmaVersion: 6,
sourceType: 'module'
sourceType: 'module',
ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true }
}

function errorMessage (type) {
Expand All @@ -32,6 +33,14 @@ const ruleTester = new RuleTester()
ruleTester.run('require-valid-default-prop', rule, {

valid: [
{
filename: 'test.vue',
code: `export default {
...foo,
props: { ...foo }
}`,
parserOptions
},
{
filename: 'test.vue',
code: `export default {
Expand Down Expand Up @@ -65,8 +74,13 @@ ruleTester.run('require-valid-default-prop', rule, {
foo: null,
foo: Number,
foo: [String, Number],
foo: { },
foo: { type: String },
foo: { type: Number, default: VAR_BAR },
foo: { type: Number, default: 100 },
foo: { type: Number, default: Number.MAX_VALUE },
foo: { type: Number, default: Foo.BAR },
foo: { type: {}, default: '' },
foo: { type: [String, Number], default: '' },
foo: { type: [String, Number], default: 0 },
foo: { type: String, default: '' },
Expand All @@ -80,6 +94,8 @@ ruleTester.run('require-valid-default-prop', rule, {
foo: { type: Symbol, default () { } },
foo: { type: Array, default () { } },
foo: { type: Symbol, default: Symbol('a') },
foo: { type: String, default: \`Foo\` },
foo: { type: Foo, default: Foo('a') },
foo: { type: String, default: \`Foo\` }
}
})`,
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/valid-v-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ tester.run('valid-v-for', rule, {
{
filename: 'test.vue',
code: '<template v-for="x of list"><slot name="item" /></template>'
},
{
filename: 'test.vue',
code: '<template v-for="x of list">foo<div></div></template>'
}
],
invalid: [
Expand Down Expand Up @@ -170,6 +174,11 @@ tester.run('valid-v-for', rule, {
filename: 'test.vue',
code: '<template><div><template v-for="x in list" :key="x"><custom-component></custom-component></template></div></template>',
errors: ["Custom elements in iteration require 'v-bind:key' directives."]
},
{
filename: 'test.vue',
code: '<template><div><template v-for="xin list"><div></div></template></div></template>',
errors: ["'v-for' directives require that attribute value."]
}
]
})