Skip to content

Add rule max-attributes-per-line (resolves #47) #60

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 16 commits into from
Aug 15, 2017

Conversation

filipalacerda
Copy link
Contributor

WIP for #47

Adds rule to verify the number of props per line.

Adds documentation.
@filipalacerda
Copy link
Contributor Author

@mysticatea @michalsnik
I opened this PR as a WIP to check the rule definition with you before starting implementing, hope that's ok.

Can you please check https://github.com/vuejs/eslint-plugin-vue/pull/60/files#diff-c73e4e318ae2ee54c86d3c86d4f0434f and see if the rule definition matches what you were expecting or if I need to change it?

Thanks!

@@ -0,0 +1,88 @@
# Define the number of attributes allows per line (max-attributes-per-line)

Limits the maximum number of props per line to improve readability
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say maximum number of attributes/properties and add . at the end of the sentence.


## Rule Details

This rule aims to enforce a number of props per line in templates. It checks all the elements in a template and verifies that the number of props per line does not exceed the defined maximum.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again attributes, unless we only care about components' props. But I think we should care about every attribute. Prop is just another type of property/attribute.

## Rule Details

This rule aims to enforce a number of props per line in templates. It checks all the elements in a template and verifies that the number of props per line does not exceed the defined maximum.
A prop is considered to be in a new line when there is a line break between two props.
Copy link
Member

@michalsnik michalsnik Jun 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like: There is configurable number of props that are acceptable in one-line case, as well as how many attributes should be acceptable per line in multi-line case.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little lost here, should I add it or replace something with it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of text on line 9.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
```
### `singleline`
Number of maximum number of props when a tag is in a single line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the opening tag is in a single line to be precise.


```js

<component foo="1" bar="3"></component>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think default should be:

  • singleline: 3
  • multiline: 1

Then examples could look like this:
Incorrect:

<component lorem="1" ipsum="2" dolor="3" sit="4">
</component>

<component
  lorem="1" ipsum="2"
  dolor="3"
  sit="4"
>
</component>

Correct:

<component lorem="1" ipsum="2" dolor="3">
</component>

<component
  lorem="1"
  ipsum="2"
  dolor="3"
  sit="4"
>
</component>

We should probably add additional option for specifying if we accept attribute in first line or not too, maybe something like firstline: 1, that would make it possible to have one property in the first line, or more if specified. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

@michalsnik michalsnik changed the title WIP: Add rule to verify number of props per line Add rule max-attributes-per-line (resolves #47) Jun 29, 2017
@filipalacerda
Copy link
Contributor Author

@michalsnik thank you so much for your feedback 😊 going to update it asap! :)

Copy link
Member

@michalsnik michalsnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're almost there :) Few additional tweaks. Great work so far!


The default is one prop per line
There is predefined number of attributes that are acceptable in one-line case, as well as how many attributes are acceptable per line in multi-line case.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update a little bit more:

There is a configurable number of attributes that are acceptable in one-line case (default 3), as well as how many attributes are acceptable per line in multi-line case (default 1).

And then we can remove the next sentence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed ✅

### `firstline`
For muliline declarations, defines if it accepts an attribute in the first line.

The following patterns is considered a warning:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be consistent :)

Example of **incorrect** code for this setting:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed ✅

</component>;
```

The following pattern is not considered a warning:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of **correct** code for this setting:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed them all ✅

### `singleline`
Number of maximum number of props when a tag is in a single line.
Number of maximum attributes per line when the opening tag is in a single line.

The following patterns is considered a warning:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above:

Example of **incorrect** code for this setting:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"singleline": 2,
"multiline": 1
}]
}
```

### `firstline`
For muliline declarations, defines if it accepts an attribute in the first line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multi-line declarations, defines how many attributes are acceptable to be put in the first line. (Default 0)

We can discuss default settings later :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed ✅

@filipalacerda
Copy link
Contributor Author

@michalsnik can you please review this? Thank you!

Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contributing!

Looks good to me but I think we can improve this rule in some points. Please see below:

category: 'Stylistic Issues',
recommended: false
},
fixable: 'code',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fixable: null.
fixable: 'code' means that this rule modifies source code with eslint --fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♀️ forgot about that! Fixed!

const configuration = context.options[0]
const multilineMaximum = configuration.multiline
const singlelinemMaximum = configuration.singleline
const canHaveFirstLine = configuration.firstline !== 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think boolean or string option is more proper in this case.
How about the below?

A: Simple boolean option.

{
    "singleline": 3,
    "multiline": 1,
    "allowFirstLine": false // or true
}

B: I think that the first attribute position is a taste for each people. It might be good if people can specify the position. But I'm not sure it's a responsibility of this rule.

{
    "singleline": 3,
    "multiline": 1,
    "firstAttributeOfMultiline": "newline" // or "beside"
}

C: I'm wondering that it's a setting of multiline. Should it locate in the multiline?

{
    "singleline": 3,
    "multiline": {"max": 1, "allowFirstLine": false}
}

Copy link
Contributor Author

@filipalacerda filipalacerda Jul 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only for multiline, I will go with C, what do you think @mysticatea ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go with C but still keep it as number, e.g.:

{
    "singleline": 3,
    "multiline": {"max": 1, "maxInFirstLine": 2}
}

So it's possible to have two properties in the first line but the rest in new lines in capacity of 1 per line, like here:

<input name="someField" class="input"
  v-model="message"
  placeholder="Lorem ipsum"
>

What do you think @filipalacerda @mysticatea ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I get it know @mysticatea. You meant that the value for a singleline option should be considered the max for the first line, when allowFirstLine is true? If that's the case I'm all for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalsnik This is suggestion which is based on this line of the implementation: const canHaveFirstLine = configuration.firstline !== 0. It uses multiline.max for the first line if allowFirstLine: true.

create: function (context) {
const configuration = context.options[0]
const multilineMaximum = configuration.multiline
const singlelinemMaximum = configuration.singleline
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documents say the options have each default value. But this looks to not have default values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mysticatea
I am looking at the docs and I am a little lost here. I thought they were assumed by default, meaning, if no options were provided they would fallback to the ones in the schema.

Should I do something like:
const configuration = context.options[0] || { firstline: 0, singleline: 1, multiline: 1}
?

Copy link
Member

@michalsnik michalsnik Jul 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be something like:

const configuration = context.options[0] || {}
const multilineMaximum = configuration.multiline || 1
const singlelinemMaximum = configuration.singleline || 1

so you can pass only multiline option and still get fallback for singleline

context.report({
node,
loc: node.loc,
message: 'It has more than {{singlelinemMaximum}} attributes per line.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better if this rule reports the violated attributes instead of elements which have the violated attributes.
Because editors can indicate more proper locations with red lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! :)

Copy link
Contributor Author

@filipalacerda filipalacerda Jul 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:

with the default of 3, if it has more than 3, we would trigger an error saying:"attribute(s) x and z should be in a new line."
But if the multiline max is 1 putting those last ones in a new line will trigger another error.

🤔

What do you think we should do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have imaged like that logic. (sorry, I have not run that code.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can simply put:
There are 3 attributes in this line, but the maximum is 2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather go with @michalsnik suggestion, since as a user I think it will help me more to know the exact numbers :)

</component>
</template>`,
options: [{ singleline: 3, multiline: 2, firstline: 0 }]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to see tests with no options (use default values) as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed ✅

@filipalacerda
Copy link
Contributor Author

Thanks @mysticatea! Will update asap :)

- Adds defaults values
- Adds tests for the default values
@filipalacerda
Copy link
Contributor Author

@mysticatea updated some of the things you mentioned but I need your help regarding the single line error: #60 (comment)

And I need you to confirm the defaults part, not sure if it is the right way of doing it 😅

Thanks for your help!

@filipalacerda
Copy link
Contributor Author

@mysticatea @michalsnik all points were addressed :)

Can you please check again?

@@ -71,7 +71,7 @@ ruleTester.run('max-attributes-per-line', rule, {
invalid: [
{
code: `<template><component name="John Doe" age="30" job="Vet" petname="Snoopy"></component></template>`,
errors: ['It has more than 3 attributes per line.']
errors: ['There are 4 in this line, but the maximum is 3.']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add attributes keyword to the message :) So it says:
There are 4 attributes in this line, but the maximum is 3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♀️

},

create: function (context) {
const configuration = context.options[0] || { singleline: 3, multiline: { max: 1, allowFirstLine: false }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update settings so it's possible to override only part of it without the need to update everything. You can use Object.assign to merge passed settings with default ones:

const configuration = Object.assign({}, context.options[0] || {}, {
  singleline: 3,
  multiline: { max: 1, allowFirstLine: false }
})

And I'd also consider accepting setting: multiline: 4 as just a number, then we would assume allowFirstLine is false. What do you think?

Copy link
Contributor Author

@filipalacerda filipalacerda Jul 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having only one way of setting a rule would make user's lives easier, but I can change it if you don't agree :)

What do you think @michalsnik ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const configuration = context.options[0] || { singleline: 3, multiline: { max: 1, allowFirstLine: false }}

In that case, if somebody write ["error", {"singleline": 1}] then it's going to throw a TypeError at const multilineMaximum = configuration.multiline.max. I'd like to define parseOptions function:

function parseOptions(options) {
    const result = { singlelineMax: 3, multilineMax: 1, allowFirstLine: false }

    if (options) {
        if (typeof options.singleline === "number") {
            result.singlelineMax = options.singleline
        } else if (options.singleline && options.singleline.max) {
            result.singlelineMax = options.singleline.max
        }

        if (typeof options.multiline === "number") {
            result.multilineMax = options.multiline
        } else if (options.multiline) {
            if (options.multiline.max) {
                result.multilineMax = options.multiline.max
            }
            if (options.multiline.allowFirstLine) {
                result.allowFirstLine = options.multiline.allowFirstLine
            }
        }
    }

    return result
}

Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for late response.
I think that we can improve this rule in some points.

  • More consistent for the option schema.
  • About the default values of options.
  • The location of warnings.

type: 'number',
minimum: 1
},
'multiline': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to change this schema to https://jsonschemalint.com/#/version/draft-06/markup/json?gist=a6a3592eaf8365d069031288f29e5445

  • That schema allows {singleline: 1, multiline: 3} if somebody don't mind {allowFirstLine: false}. It's simple.
  • On the other hand, that schema allows {singleline: {max: 1}, multiline: {max: 3}} if somebody want to write as details. It's more consistent than {singleline: 1, multiline: {max: 3}}.

},

create: function (context) {
const configuration = context.options[0] || { singleline: 3, multiline: { max: 1, allowFirstLine: false }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const configuration = context.options[0] || { singleline: 3, multiline: { max: 1, allowFirstLine: false }}

In that case, if somebody write ["error", {"singleline": 1}] then it's going to throw a TypeError at const multilineMaximum = configuration.multiline.max. I'd like to define parseOptions function:

function parseOptions(options) {
    const result = { singlelineMax: 3, multilineMax: 1, allowFirstLine: false }

    if (options) {
        if (typeof options.singleline === "number") {
            result.singlelineMax = options.singleline
        } else if (options.singleline && options.singleline.max) {
            result.singlelineMax = options.singleline.max
        }

        if (typeof options.multiline === "number") {
            result.multilineMax = options.multiline
        } else if (options.multiline) {
            if (options.multiline.max) {
                result.multilineMax = options.multiline.max
            }
            if (options.multiline.allowFirstLine) {
                result.allowFirstLine = options.multiline.allowFirstLine
            }
        }
    }

    return result
}

if (isSingleLine(node) && numberOfAttributes > singlelinemMaximum) {
context.report({
node,
loc: node.loc,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think better if this rule reports the violated attributes instead of elements which have the violated attributes.
This is consistent with the core rules which have similar functionally.

/*eslint 
    max-statements-per-line: error,
    newline-per-chained-call: error,
    object-property-newline: error,
    array-element-newline: error
 */

aaa(); bbb(); ccc();
test.aaa().bbb().ccc().ddd()
var obj = {aaa:1, bbb:2, ccc:3}
var ary = [1, 2, 3]

image

@filipalacerda
Copy link
Contributor Author

@michalsnik @mysticatea I am little lost 😅 , can you confirm this is what you are suggesting:

  1. Update config to accept:
{
  singleline: 1,
  multiline: { max: 3, allowFirstLine: false}
}

and

{
  singleline: 1,
  multiline: 3
}

In the latter, assumes the default false for allowFirstLine

  1. Show which attributes are wrong in the single line case

  2. Update defaults to allow for only one of them being provided

Is this it?
Thanks!

@mysticatea
Copy link
Member

@filipalacerda

  1. Yes. I hope that the codes in my comments help you.
  2. I think that this rule should report attributes instead of elements at all. Like this.
  3. Yes.

@filipalacerda
Copy link
Contributor Author

@mysticatea @michalsnik

I need help :) how do I set the schema to accept 2 different configs for multiline? 🤔

schema: [
  'multiline': {
    type: // can be an object or a number
   }
]

Should I not set a schema? I do not see it in most of the other rules 🤔

@filipalacerda
Copy link
Contributor Author

found it! ignore me! 🙈

Changes options parser to allow to redifine only one prop
Changes error thrown for singleline errors
Updates tests and docs accordingly
@filipalacerda
Copy link
Contributor Author

@mysticatea @michalsnik all fixed :) Can you please check again? Thanks!

@armano2
Copy link
Contributor

armano2 commented Jul 24, 2017

@filipalacerda i like this but i see one issue here you are allways reporting VStartTag instead of VAttribute

    message: 'Attribute age should be on a new line.',
    line: 1,
    column: 11,
    nodeType: 'VStartTag',

i will love to have accurate reports for editors to match this:

diff --git a/tests/lib/rules/max-attributes-per-line.js b/tests/lib/rules/max-attributes-per-line.js
index ab98db5..f3a65b9 100644
--- a/tests/lib/rules/max-attributes-per-line.js
+++ b/tests/lib/rules/max-attributes-per-line.js
@@ -83,7 +83,11 @@ ruleTester.run('max-attributes-per-line', rule, {
   invalid: [
     {
       code: `<template><component name="John Doe" age="30" job="Vet" petname="Snoopy"></component></template>`,
-      errors: ['Attribute petname should be on a new line.']
+      errors: [{
+        message: 'Attribute petname should be on a new line.',
+        type: 'VAttribute',
+        line: 1
+      }]
     },
     {
       code: `<template><component job="Vet"
@@ -91,12 +95,24 @@ ruleTester.run('max-attributes-per-line', rule, {
         age="30">
         </component>
       </template>`,
-      errors: ['Attribute job should be on a new line.']
+      errors: [{
+        message: 'Attribute job should be on a new line.',
+        type: 'VAttribute',
+        line: 1
+      }]
     },
     {
       code: `<template><component name="John Doe" age="30" job="Vet"></component></template>`,
       options: [{ singleline: 1, multiline: { max: 1, allowFirstLine: false }}],
-      errors: ['Attribute age should be on a new line.', 'Attribute job should be on a new line.']
+      errors: [{
+        message: 'Attribute age should be on a new line.',
+        type: 'VAttribute',
+        line: 1
+      }, {
+        message: 'Attribute job should be on a new line.',
+        type: 'VAttribute',
+        line: 1
+      }]
     },
     {
       code: `<template><component name="John Doe"
@@ -104,7 +120,11 @@ ruleTester.run('max-attributes-per-line', rule, {
         </component>
       </template>`,
       options: [{ singleline: 3, multiline: { max: 1, allowFirstLine: false }}],
-      errors: ['Attribute name should be on a new line.']
+      errors: [{
+        message: 'Attribute name should be on a new line.',
+        type: 'VAttribute',
+        line: 1
+      }]
     },
     {
       code: `<template><component
@@ -113,7 +133,11 @@ ruleTester.run('max-attributes-per-line', rule, {
         </component>
       </template>`,
       options: [{ singleline: 3, multiline: { max: 1, allowFirstLine: false }}],
-      errors: ['Attribute age should be on a new line.']
+      errors: [{
+        message: 'Attribute age should be on a new line.',
+        type: 'VAttribute',
+        line: 2
+      }]
     },
     {
       code: `<template><component
@@ -122,7 +146,11 @@ ruleTester.run('max-attributes-per-line', rule, {
         </component>
       </template>`,
       options: [{ singleline: 3, multiline: { max: 2, allowFirstLine: false }}],
-      errors: ['Attribute petname should be on a new line.']
+      errors: [{
+        message: 'Attribute petname should be on a new line.',
+        type: 'VAttribute',
+        line: 3
+      }]
     },
     {
       code: `<template><component
@@ -131,10 +159,15 @@ ruleTester.run('max-attributes-per-line', rule, {
         </component>
       </template>`,
       options: [{ singleline: 3, multiline: { max: 2, allowFirstLine: false }}],
-      errors: [
-        'Attribute petname should be on a new line.',
-        'Attribute extra should be on a new line.'
-      ]
+      errors: [{
+        message: 'Attribute petname should be on a new line.',
+        type: 'VAttribute',
+        line: 3
+      }, {
+        message: 'Attribute extra should be on a new line.',
+        type: 'VAttribute',
+        line: 3
+      }]
     }
   ]
 })

Copy link
Member

@michalsnik michalsnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @filipalacerda ! 💪

I added few last tiny suggestions and it's all from my side :)


const propsPerLine = [[node.attributes[0]]]

node.attributes.reduce(function (previous, current) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Use arrow function
  • I'd create groupAttrsByLine or collectAttributes function that would take node.attributes as parameter and return 2d array, using such function in this place would make this code more readable:
const attrsGroupedByLine = groupAttrsByLine(node.attributes);

attrsGroupedByLine
  .filter(attrs => attrs.length > multilineMaximum)
  .forEach(attrs => showErrors(attrs.splice(multilineMaximum), node)

// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------
function isSingleLine (node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this function to utils

context.report({
node,
loc: node.loc,
message: 'Attribute {{propName}} should be on a new line.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "" around propName, it will make there errors even more readable :)

return current
})

propsPerLine.forEach(function (attributes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use arrow function, you don't need the context here

Uses arrow function
Improves readability
/**
* Check whether the component is declared in a single line or not.
* @param {ASTNode} node
* @returns {boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing here }

@filipalacerda
Copy link
Contributor Author

@michalsnik all done :) Can you please check again?

@armano2 I opted by this report since it matches the error style thrown in the other rules. (At least at the time I opened this MR) I would rather keep it, if you do not mind :)


Examples of **correct** code for this rule:

```js
Copy link
Contributor

@armano2 armano2 Jul 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```html


Examples of **incorrect** code for this rule:

```js
Copy link
Contributor

@armano2 armano2 Jul 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```html

Limits the maximum number of attributes/properties per line to improve readability.


## Rule Details
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

## :book: Rule Details


There is a configurable number of attributes that are acceptable in one-line case (default 3), as well as how many attributes are acceptable per line in multi-line case (default 1).

Examples of **incorrect** code for this rule:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-1: Examples of **incorrect** code for this rule:

</component>
```

Examples of **correct** code for this rule:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:+1: Examples of **correct** code for this rule:

### `allowFirstLine`
For multi-line declarations, defines if allows attributes to be put in the first line. (Default false)

Example of **incorrect** code for this setting:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-1: Examples of **incorrect** code for this rule:

### `multiline`
Number of maximum attributes per line when a tag is in multiple lines. (Default is 1)

Example of **incorrect** code for this setting:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-1: Examples of **incorrect** code for this rule:

</component>;
```

Example of **correct** code for this setting:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:+1: Examples of **correct** code for this rule:

}
```

### `allowFirstLine`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be 4th lvl header because its part of Options


```

### Options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

## :wrench: Options

@armano2
Copy link
Contributor

armano2 commented Jul 30, 2017

@filipalacerda i added few comments about documentation

Filipa Lacerda added 2 commits August 5, 2017 14:22
* master:
  Add rule `vue/require-valid-default-prop`. (vuejs#119)
  3.10.0
  Update readme to 3.10.0
  Chore: remove package-lock.json (vuejs#128)
  Fix: parserService must exist always (fixes vuejs#125) (vuejs#127)
  Add rule `require-render-return`. (vuejs#114)
  3.9.0
  Update package-lock
  Update: options for `no-duplicate-attributes` (fixes vuejs#112)(vuejs#113)
  New: add rule `attribute-hyphenation`. (fixes vuejs#92)(vuejs#95)
  Add namespace check of svg & mathML instead of tag names (vuejs#120)
  ⚠️ Add support for deprecated state in update-rules ⚠️ (vuejs#121)
  Add rules: `no-dupe-keys` and `no-reserved-keys`. (vuejs#88)
  Chore: Improve tests for name-property-casing & improve documentation (vuejs#115)
  New: add `require-prop-types` rule (fixes vuejs#19)(vuejs#85)
  Update: upgrade vue-eslint-parser (fixes vuejs#36, fixes vuejs#56, fixes vuejs#96) (vuejs#116)
@filipalacerda
Copy link
Contributor Author

@michalsnik @mysticatea @armano2

I have made all the changes you requested, do you think this is ready to go?

attributes.forEach((prop) => {
context.report({
node,
loc: node.loc,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think better if this rule reports the violated attributes instead of elements which have the violated attributes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipalacerda can you look on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try, but probably only next weekend! If any of you wants/is able to take over please feel free to do so, I can give you access to the fork 😊

Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the amazing work!!

LGTM.

@mysticatea
Copy link
Member

@michalsnik Could you re-review and merge?

Copy link
Member

@michalsnik michalsnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 Thanks @filipalacerda for great work! :)

@michalsnik michalsnik merged commit 85558dc into vuejs:master Aug 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants