Skip to content
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

Add rule-empty-line-before rule #2309

Merged
merged 6 commits into from Feb 2, 2017
Merged

Add rule-empty-line-before rule #2309

merged 6 commits into from Feb 2, 2017

Conversation

jeddy3
Copy link
Member

@jeddy3 jeddy3 commented Jan 31, 2017

Closes #2229

I’ll update the rule to use the new empty line utils (to ignore shared-line comments) in v8.

Copy link
Member

@hudochenkov hudochenkov left a comment

Choose a reason for hiding this comment

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

Good job!

With new rule it won't be possible to enforce this style:

a {
    display: block;
    
    span {
    }
    strong {
    }
}
a {
    span {
    }
    strong {
    }
}

There should be no empty lines before a rule, except if it's inside a block and after non-rule. I can enforce this style with:

{
    "rules": {
        "rule-non-nested-empty-line-before": ["never", {
            "ignore": ["after-comment"]
        }],
        "rule-nested-empty-line-before": ["always", {
            "except": ["first-nested", "after-rule"],
            "ignore": ["after-comment"]
        }]
    }
}

How about new option except: ["inside-block-and-after-non-rule"]?

Then I would be able enforce this style with:

{
    "rules": {
        "rule-empty-line-before": ["never", {
            "except": ["inside-block-and-after-non-rule"],
            "ignore": ["after-comment"]
        }]
    }
}

@@ -188,8 +188,7 @@ Here are all the rules within stylelint, grouped by the [*thing*](http://apps.wo

### Rule

- [`rule-nested-empty-line-before`](../../lib/rules/rule-nested-empty-line-before/README.md): Require or disallow an empty line before nested rules.
- [`rule-non-nested-empty-line-before`](../../lib/rules/rule-non-nested-empty-line-before/README.md): Require or disallow an empty line before non-nested rules.
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it's a good idea delete links to docs? These rules still in stylelint, despite the fact they are deprecated. When user will see a deprecation message, she may want to read what this rule for. But it will be very difficult to find.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point.

Can you create a PR that adds them back in for the other 13 deprecated rules? Please append "(deprecated)." to the end of the description.

Copy link
Member

Choose a reason for hiding this comment

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

Will do today.


### `except: ["after-single-line-comment", "inside-block-and-after-rule", "first-nested"]`

#### `"after-single-line-comment"`
Copy link
Member

Choose a reason for hiding this comment

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

Why it's explicitly for a single-line comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

This rule mimics the options from the previous two rules. Only the rule-nested... had the after single line comment exception, as there was a specific request for that functionality.

@jeddy3
Copy link
Member Author

jeddy3 commented Feb 1, 2017

With new rule it won't be possible to enforce this style:

@hudochenkov Thanks for the feedback.

How about new option except: ["inside-block-and-after-non-rule"]?

We don't have the concept of non-things as the recommend approach is to set the primary option to the most common occurrence and then invert it using except options. So, instead of "never" and except: ["after-non-rule"], the recommendation is to use "always" and except: ["after-rule"].

I've added except: ["after-rule"].

I think that covers off a few use-cases. I suggest we roll with what we have and then wait for requests for more idiosyncratic code styles.

}, {
code: "@media {}\n\na{}",
description: "media rule",
} ],
Copy link
Member

Choose a reason for hiding this comment

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

Could you add tests for nested rules either, please? New option affects both non-nested and nested rules.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@hudochenkov
Copy link
Member

except: ["after-rule"] makes sense. Thank you!

Copy link
Member

@hudochenkov hudochenkov left a comment

Choose a reason for hiding this comment

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

Nicely done!

@@ -188,8 +188,7 @@ Here are all the rules within stylelint, grouped by the [*thing*](http://apps.wo

### Rule

- [`rule-nested-empty-line-before`](../../lib/rules/rule-nested-empty-line-before/README.md): Require or disallow an empty line before nested rules.
- [`rule-non-nested-empty-line-before`](../../lib/rules/rule-non-nested-empty-line-before/README.md): Require or disallow an empty line before non-nested rules.
Copy link
Member

Choose a reason for hiding this comment

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

Will do today.

Copy link
Contributor

@davidtheclark davidtheclark left a comment

Choose a reason for hiding this comment

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

👍 I think the multi-line examples should be improved; otherwise looks good.

{}
b
{}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these are confusing examples. Multi-line rules typically manifest as multiple lines of declarations — that's what people will recognize. Let's do that.

Copy link
Member Author

@jeddy3 jeddy3 Feb 1, 2017

Choose a reason for hiding this comment

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

Done, or did you mean actually put a declaration inside the block?

Copy link
Member

Choose a reason for hiding this comment

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

@jeddy3 As a user I would have better understanding if there would be declarations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thing is, "multi-line" doesn't necessarily mean multiple declarations.

This is multi-line:

a {
  color: red;
}

i.e. the rule spans multiple lines.

Perhaps a single declaration is the clearest?

Copy link
Member

Choose a reason for hiding this comment

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

From a user perspective your example with a single declaration isn't always a multi-line rule :) User might assume that this is single-line rule.

In fact you're right, of course.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jeddy3 You're right: that seems fine to me, too.

@jeddy3
Copy link
Member Author

jeddy3 commented Feb 1, 2017

@davidtheclark I'm around this evening and can finish the release (woohoo!), if you're about to review stylelint/stylelint-config-standard#60 and feedback on the example changes here.

FYI:

  • stylelint-config-standard
  • stylelint.io
  • stylelint-demo

Are all ready-to-go against this branch.

@jeddy3 jeddy3 merged commit 06943a4 into master Feb 2, 2017
@jeddy3 jeddy3 deleted the add-rule-empty-line-before branch February 2, 2017 09:54
@jeddy3
Copy link
Member Author

jeddy3 commented Feb 2, 2017

Changlog:

  • Deprecated: 15 rules (#2197, #2285 & #2309).
    - rule-nested-empty-line-before and rule-non-nested-empty-line-before. Use the new rule-empty-line-before rule instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants