-
-
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
Changes from 1 commit
a7d9313
7ef1ca5
6a62bdd
1d34713
c78b20d
56f5f70
ca31f09
ed73ad8
df1207b
39d0743
796611e
982d9f2
2f0492d
5539686
dcb3ee3
dc64c62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
||
## Rule Details | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Again |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Maybe something like: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
The default is one prop per line | ||
|
||
Examples of **incorrect** code for this rule: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
```js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
<component foo="1" bar="3"></component> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think default should be:
Then examples could look like this:
Correct:
We should probably add additional option for specifying if we accept attribute in first line or not too, maybe something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me! |
||
|
||
<component foo="1" bar="2" | ||
foobar="3"></component> | ||
|
||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
```js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
<component | ||
foo="1" | ||
bar="3" | ||
> | ||
</component> | ||
|
||
``` | ||
|
||
### Options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
``` | ||
{ | ||
"vue/max-attributes-per-line": ["error", { | ||
"singleline": 2, | ||
"multiline": 1 | ||
}] | ||
} | ||
``` | ||
### `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 commentThe reason will be displayed to describe this comment to others. Learn more. When the opening tag is in a single line to be precise. |
||
|
||
The following patterns is considered a warning: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ |
||
```js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// ["error", { "singleline": 2, "multiline": 1}] | ||
<component foo="John" bar="Smith" foobar={5555555}></component>; | ||
``` | ||
|
||
The following pattern is not considered a warning: | ||
```js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// ["error", { "singleline": 3, "multiline": 1}] | ||
<component foo="John" bar="Smith" foobar={5555555}></component>; | ||
``` | ||
|
||
|
||
### `multiline` | ||
Number of maximum number of props when a tag is in a single line. | ||
|
||
|
||
The following patterns is considered a warning: | ||
```js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// ["error", { "singleline": 2, "multiline": 1}] | ||
<component foo="John" bar="Smith" | ||
foobar={5555555}> | ||
</component>; | ||
``` | ||
|
||
The following pattern is not considered a warning: | ||
```js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// ["error", { "singleline": 3, "multiline": 1}] | ||
<component | ||
foo="John" | ||
bar="Smith" | ||
foobar={5555555} | ||
> | ||
</component>; | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you do not want to check the number of props declared per line you can disable this rule. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @fileoverview Define the number of attributes allows per line | ||
* @author Filipa Lacerda | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "Define the number of attributes allows per line", | ||
category: "Fill me in", | ||
recommended: false | ||
}, | ||
fixable: null, // or "code" or "whitespace" | ||
schema: [ | ||
// fill in your schema | ||
] | ||
}, | ||
|
||
create: function(context) { | ||
|
||
// variables should be defined here | ||
|
||
//---------------------------------------------------------------------- | ||
// Helpers | ||
//---------------------------------------------------------------------- | ||
|
||
// any helper functions should go here or else delete this section | ||
|
||
//---------------------------------------------------------------------- | ||
// Public | ||
//---------------------------------------------------------------------- | ||
|
||
return { | ||
|
||
// give me methods | ||
|
||
}; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* @fileoverview Define the number of attributes allows per line | ||
* @author Filipa Lacerda | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var rule = require("../../../lib/rules/max-attributes-per-line"), | ||
|
||
RuleTester = require("eslint").RuleTester; | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
var ruleTester = new RuleTester(); | ||
ruleTester.run("max-attributes-per-line", rule, { | ||
|
||
valid: [ | ||
|
||
// give me some code that won't trigger a warning | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: "", | ||
errors: [{ | ||
message: "Fill me in.", | ||
type: "Me too" | ||
}] | ||
} | ||
] | ||
}); |
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.