-
-
Notifications
You must be signed in to change notification settings - Fork 681
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
Conversation
Adds documentation.
@mysticatea @michalsnik 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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
max-attributes-per-line
(resolves #47)
@michalsnik thank you so much for your feedback 😊 going to update it asap! :) |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed ✅
@michalsnik can you please review this? Thank you! |
There was a problem hiding this 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:
lib/rules/max-attributes-per-line.js
Outdated
category: 'Stylistic Issues', | ||
recommended: false | ||
}, | ||
fixable: 'code', |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♀️ forgot about that! Fixed!
lib/rules/max-attributes-per-line.js
Outdated
const configuration = context.options[0] | ||
const multilineMaximum = configuration.multiline | ||
const singlelinemMaximum = configuration.singleline | ||
const canHaveFirstLine = configuration.firstline !== 0 |
There was a problem hiding this comment.
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}
}
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
lib/rules/max-attributes-per-line.js
Outdated
create: function (context) { | ||
const configuration = context.options[0] | ||
const multilineMaximum = configuration.multiline | ||
const singlelinemMaximum = configuration.singleline |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}
?
There was a problem hiding this comment.
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
lib/rules/max-attributes-per-line.js
Outdated
context.report({ | ||
node, | ||
loc: node.loc, | ||
message: 'It has more than {{singlelinemMaximum}} attributes per line.', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! :)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 }] | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed ✅
Thanks @mysticatea! Will update asap :) |
- Adds defaults values - Adds tests for the default values
@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! |
@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.'] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♀️
lib/rules/max-attributes-per-line.js
Outdated
}, | ||
|
||
create: function (context) { | ||
const configuration = context.options[0] || { singleline: 3, multiline: { max: 1, allowFirstLine: false }} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
}
There was a problem hiding this 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.
lib/rules/max-attributes-per-line.js
Outdated
type: 'number', | ||
minimum: 1 | ||
}, | ||
'multiline': { |
There was a problem hiding this comment.
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}}
.
lib/rules/max-attributes-per-line.js
Outdated
}, | ||
|
||
create: function (context) { | ||
const configuration = context.options[0] || { singleline: 3, multiline: { max: 1, allowFirstLine: false }} |
There was a problem hiding this comment.
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
}
lib/rules/max-attributes-per-line.js
Outdated
if (isSingleLine(node) && numberOfAttributes > singlelinemMaximum) { | ||
context.report({ | ||
node, | ||
loc: node.loc, |
There was a problem hiding this comment.
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]
@michalsnik @mysticatea I am little lost 😅 , can you confirm this is what you are suggesting:
and
In the latter, assumes the default
Is this it? |
|
I need help :) how do I set the schema to accept 2 different configs for
Should I not set a schema? I do not see it in most of the other rules 🤔 |
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
@mysticatea @michalsnik all fixed :) Can you please check again? Thanks! |
@filipalacerda i like this but i see one issue here you are allways reporting VStartTag instead of VAttribute
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
+ }]
}
]
}) |
There was a problem hiding this 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 :)
lib/rules/max-attributes-per-line.js
Outdated
|
||
const propsPerLine = [[node.attributes[0]]] | ||
|
||
node.attributes.reduce(function (previous, current) { |
There was a problem hiding this comment.
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
orcollectAttributes
function that would takenode.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)
lib/rules/max-attributes-per-line.js
Outdated
// ---------------------------------------------------------------------- | ||
// Helpers | ||
// ---------------------------------------------------------------------- | ||
function isSingleLine (node) { |
There was a problem hiding this comment.
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
lib/rules/max-attributes-per-line.js
Outdated
context.report({ | ||
node, | ||
loc: node.loc, | ||
message: 'Attribute {{propName}} should be on a new line.', |
There was a problem hiding this comment.
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 :)
lib/rules/max-attributes-per-line.js
Outdated
return current | ||
}) | ||
|
||
propsPerLine.forEach(function (attributes) { |
There was a problem hiding this comment.
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
lib/utils/index.js
Outdated
/** | ||
* Check whether the component is declared in a single line or not. | ||
* @param {ASTNode} node | ||
* @returns {boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are missing here }
@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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## :wrench: Options
@filipalacerda i added few comments about documentation |
* 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)
@michalsnik @mysticatea @armano2 I have made all the changes you requested, do you think this is ready to go? |
lib/rules/max-attributes-per-line.js
Outdated
attributes.forEach((prop) => { | ||
context.report({ | ||
node, | ||
loc: node.loc, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😊
There was a problem hiding this 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.
@michalsnik Could you re-review and merge? |
There was a problem hiding this 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! :)
WIP for #47
Adds rule to verify the number of props per line.