-
Notifications
You must be signed in to change notification settings - Fork 510
New Rule: requirePaddingNewlinesBeforeKeywords #586
Conversation
One interesting proposal from the conversation on Reddit: Add a configuration for minimum block size before the rule kicks in. This would prevent the rule from suggesting extra padding lines in very short functions/code blocks. Example: Widget.prototype.exec = function(n) {
var method = n > 0 ? 'get' : 'set';
return this[method](n);
}; I'm open to thoughts/suggestions on this. |
@@ -80,6 +80,8 @@ StringChecker.prototype = { | |||
this.registerRule(new (require('./rules/require-padding-newlines-in-blocks'))()); | |||
this.registerRule(new (require('./rules/require-newline-before-block-statements'))()); | |||
this.registerRule(new (require('./rules/disallow-newline-before-block-statements'))()); | |||
|
|||
this.registerRule(new (require('./rules/require-padding-newlines-before-keywords'))()); |
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 correct the indentation
Would you able provide the opposite rule? Could you add more tests? Like one in the doc, it would be preferable to have test for every keywords too. |
Hi Markelog, I have provided the opposite rule, fixed indentation and added a bunch of unit tests. Hope that helps. |
db9f580
to
2fa147c
Compare
@markelog can you please review this one? |
Yep, will do that tomorrow |
@avishnyak please rebase with current master, fix the lint errors that will come up after rebase and i'm gonna land this |
… the keyword is the first expression in a block.
@markelog Should be good to go now. |
@markelog ping! |
@avishnyak sorry it took that long, missed the letter with your comment. One other thing, could these rules accept If value is Line 72 in a16a694
|
…ed commits) Squashed commits: [0800db4] Added true as a configuration option
@markelog This should be good to go now. |
|
||
```js | ||
"requirePaddingNewlinesBeforeKeywords": [ | ||
"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.
Additional spacing?
Could you add a test for |
I finished up with your pull, thank you |
Requires an empty line above the specified keywords unless the keyword is the first expression in a block.
Configured like so:
The intent of the rule is to introduce newlines (whitespace) between expressions. Many libraries and individuals already follow this type of convention intuitively.
The rule simply transforms code like this:
into code like this:
Note the empty lines above the if, for and return.