Skip to content
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
7 changes: 4 additions & 3 deletions lib/rules/max-attributes-per-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
category: 'strongly-recommended',
url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v4.2.2/docs/rules/max-attributes-per-line.md'
},
fixable: null,
fixable: 'whitespace', // or "code" or "whitespace"
schema: [
{
type: 'object',
Expand Down Expand Up @@ -129,14 +129,15 @@ module.exports = {
}

function showErrors (attributes, node) {
attributes.forEach((prop) => {
attributes.forEach((prop, i) => {
context.report({
node: prop,
loc: prop.loc,
message: 'Attribute "{{propName}}" should be on a new line.',
data: {
propName: prop.key.name
}
},
fix: i === 0 ? (fixer) => fixer.insertTextBefore(prop, '\n') : undefined
})
})
}
Expand Down
41 changes: 41 additions & 0 deletions tests/lib/rules/max-attributes-per-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ ruleTester.run('max-attributes-per-line', rule, {
invalid: [
{
code: `<template><component name="John Doe" age="30"></component></template>`,
output: `<template><component name="John Doe"
age="30"></component></template>`,
errors: ['Attribute "age" should be on a new line.']
},
{
Expand All @@ -99,6 +101,12 @@ ruleTester.run('max-attributes-per-line', rule, {
age="30">
</component>
</template>`,
output: `<template><component
job="Vet"
name="John Doe"
age="30">
</component>
</template>`,
errors: [{
message: 'Attribute "job" should be on a new line.',
type: 'VAttribute',
Expand All @@ -108,6 +116,8 @@ ruleTester.run('max-attributes-per-line', rule, {
{
code: `<template><component name="John Doe" age="30" job="Vet"></component></template>`,
options: [{ singleline: { max: 2 }}],
output: `<template><component name="John Doe" age="30"
job="Vet"></component></template>`,
errors: [{
message: 'Attribute "job" should be on a new line.',
type: 'VAttribute',
Expand All @@ -117,6 +127,8 @@ ruleTester.run('max-attributes-per-line', rule, {
{
code: `<template><component name="John Doe" age="30" job="Vet"></component></template>`,
options: [{ singleline: 1, multiline: { max: 1, allowFirstLine: false }}],
output: `<template><component name="John Doe"
age="30" job="Vet"></component></template>`,
errors: [{
message: 'Attribute "age" should be on a new line.',
type: 'VAttribute',
Expand All @@ -133,6 +145,11 @@ ruleTester.run('max-attributes-per-line', rule, {
</component>
</template>`,
options: [{ singleline: 3, multiline: { max: 1, allowFirstLine: false }}],
output: `<template><component
name="John Doe"
age="30">
</component>
</template>`,
errors: [{
message: 'Attribute "name" should be on a new line.',
type: 'VAttribute',
Expand All @@ -146,6 +163,12 @@ ruleTester.run('max-attributes-per-line', rule, {
</component>
</template>`,
options: [{ singleline: 3, multiline: { max: 1, allowFirstLine: false }}],
output: `<template><component
name="John Doe"
age="30"
job="Vet">
</component>
</template>`,
errors: [{
message: 'Attribute "age" should be on a new line.',
type: 'VAttribute',
Expand All @@ -159,6 +182,12 @@ ruleTester.run('max-attributes-per-line', rule, {
</component>
</template>`,
options: [{ singleline: 3, multiline: 1 }],
output: `<template><component
name="John Doe"
age="30"
job="Vet">
</component>
</template>`,
errors: [{
message: 'Attribute "age" should be on a new line.',
type: 'VAttribute',
Expand All @@ -172,6 +201,12 @@ ruleTester.run('max-attributes-per-line', rule, {
</component>
</template>`,
options: [{ singleline: 3, multiline: { max: 2, allowFirstLine: false }}],
output: `<template><component
name="John Doe" age="30"
job="Vet" pet="dog"
petname="Snoopy">
</component>
</template>`,
errors: [{
message: 'Attribute "petname" should be on a new line.',
type: 'VAttribute',
Expand All @@ -185,6 +220,12 @@ ruleTester.run('max-attributes-per-line', rule, {
</component>
</template>`,
options: [{ singleline: 3, multiline: { max: 2, allowFirstLine: false }}],
output: `<template><component
name="John Doe" age="30"
job="Vet" pet="dog"
petname="Snoopy" extra="foo">
</component>
</template>`,
errors: [{
message: 'Attribute "petname" should be on a new line.',
type: 'VAttribute',
Expand Down