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

Conversation

3 participants
@jeddy3
Member

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.

@hudochenkov

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.

This comment has been minimized.

@hudochenkov

hudochenkov Jan 31, 2017

Member

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.

This comment has been minimized.

@jeddy3

jeddy3 Feb 1, 2017

Member

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.

This comment has been minimized.

@hudochenkov

hudochenkov Feb 1, 2017

Member

Will do today.

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

This comment has been minimized.

@hudochenkov

hudochenkov Jan 31, 2017

Member

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

This comment has been minimized.

@jeddy3

jeddy3 Feb 1, 2017

Member

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

This comment has been minimized.

Member

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",
} ],

This comment has been minimized.

@hudochenkov

hudochenkov Feb 1, 2017

Member

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

This comment has been minimized.

@jeddy3

jeddy3 Feb 1, 2017

Member

Done

@hudochenkov

This comment has been minimized.

Member

hudochenkov commented Feb 1, 2017

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

@hudochenkov

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.

This comment has been minimized.

@hudochenkov

hudochenkov Feb 1, 2017

Member

Will do today.

@davidtheclark

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

{}
b
{}
```

This comment has been minimized.

@davidtheclark

davidtheclark Feb 1, 2017

Contributor

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.

This comment has been minimized.

@jeddy3

jeddy3 Feb 1, 2017

Member

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

This comment has been minimized.

@hudochenkov

hudochenkov Feb 1, 2017

Member

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

This comment has been minimized.

@jeddy3

jeddy3 Feb 1, 2017

Member

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?

This comment has been minimized.

@hudochenkov

hudochenkov Feb 1, 2017

Member

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.

This comment has been minimized.

@davidtheclark

davidtheclark Feb 2, 2017

Contributor

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

@jeddy3

This comment has been minimized.

Member

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

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@jeddy3 jeddy3 deleted the add-rule-empty-line-before branch Feb 2, 2017

@jeddy3

This comment has been minimized.

Member

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