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

Rule for dollar-variable-empty-line-after #373

Merged
merged 1 commit into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Please also see the [example configs](./docs/examples/) for special cases.
- [`dollar-variable-colon-space-after`](./src/rules/dollar-variable-colon-space-after/README.md): Require or disallow whitespace after the colon in `$`-variable declarations (Autofixable).
- [`dollar-variable-colon-space-before`](./src/rules/dollar-variable-colon-space-before/README.md): Require a single space or disallow whitespace before the colon in `$`-variable declarations (Autofixable).
- [`dollar-variable-default`](./src/rules/dollar-variable-default/README.md): Require `!default` flag for `$`-variable declarations.
- [`dollar-variable-empty-line-after`](./src/rules/dollar-variable-empty-line-after/README.md): Require a single empty line or disallow empty lines after `$`-variable declarations (Autofixable).
- [`dollar-variable-empty-line-before`](./src/rules/dollar-variable-empty-line-before/README.md): Require a single empty line or disallow empty lines before `$`-variable declarations (Autofixable).
- [`dollar-variable-no-missing-interpolation`](./src/rules/dollar-variable-no-missing-interpolation/README.md): Disallow Sass variables that are used without interpolation with CSS features that use custom identifiers.
- [`dollar-variable-pattern`](./src/rules/dollar-variable-pattern/README.md): Specify a pattern for Sass-like variables.
Expand Down
185 changes: 185 additions & 0 deletions src/rules/dollar-variable-empty-line-after/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# dollar-variable-empty-line-after

Require an empty line or disallow empty lines after `$`-variable declarations.

If the `$`-variable declaration is the last declaration in a file, it's ignored.

The `--fix` option on the [command line](https://github.com/stylelint/stylelint/blob/master/docs/user-guide/cli.md#autofixing-errors) can automatically fix all of the problems reported by this rule.

## Options

`string`: `"always"|"never"`

### `"always"`

There *must always* be one empty line after a `$`-variable declaration.

The following patterns are considered warnings:

```scss
$var: 200px;
@import '1.css';
```

```scss
a {
$var: 1;
}
```

The following patterns are *not* considered warnings:

```scss
$var: 100px; // The last declaration in a stylesheet
```

```scss
$var: 1;

a { color: red; }
```

### `"never"`

There *must never* be an empty line after a `$`-variable declaration.

The following patterns are considered warnings:

```scss
$var: 1;

a { color: red; }
```

The following patterns are *not* considered warnings:

```scss
$var: 100px;
$var2: 200px;
```

```scss
$var: 1;
a {
width: auto;
}
```

## Optional secondary options

### `except: ["last-nested", "before-comment", "before-dollar-variable"]`

### `"last-nested"`

Reverse the primary option for a `$`-variable declaration if it's the last child of its parent.

For example, with `"always"`:

The following patterns are considered warnings:

```scss
a {
$var: 1;
color: red;
}

b {
$var: 1;

}
```

The following patterns are *not* considered warnings:

```scss
a {
color: red;
$var: 1;
}

b {
$var: 1;

color: red;
}
```

### `"before-comment"`

Reverse the primary option for `$`-variable declarations that go before comments.

For example, with `"always"`:

The following patterns are *not* considered warnings:

```scss
a {
$var: 1;
// comment
}
```

### `"before-dollar-variable"`

Reverse the primary option for `$`-variable declarations that go right after another `$`-variable declaration.

For example, with `"always"`:

The following patterns are considered warnings:

```scss
a {
$var: 1; // this one is ok
$var1: 2; // and this one shouldn't have a preceding empty line
b {
width: 100px;
}
}
```

The following patterns are *not* considered warnings:

```scss
a {
$var: 1;
$var1: 2;

b {
width: 100%;
}
}
```

### `ignore: ["before-comment", "inside-single-line-block"]`

### `"before-comment"`

Ignore `$`-variables that go before a comment.

For example, with `"always"`:

The following patterns are *not* considered warnings:

```scss
$var: 1
// comment

$var2: 1;
/* comment */
```

### `"inside-single-line-block"`

Ignore `$`-variables that are inside single-line blocks.

For example, with `"always"`:

The following patterns are *not* considered warnings:

```scss
a { $var: 10; }
```

### `disableFix: true`

Disables autofixing for this rule.
Loading