Skip to content

Commit

Permalink
feat: Add max-line-length rule. (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntwb committed May 31, 2020
1 parent b947ba4 commit b5f8108
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/stylelint-config-wordpress/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Removed: `stylelint < 6.9.0` compatibility.
* Added: `selector-attribute-quotes` rule.
* Added: `font-weight-notation` rule.
* Added: `max-line-length` rule.

# 8.0.0

Expand Down
4 changes: 4 additions & 0 deletions packages/stylelint-config-wordpress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ Correct:
position: absolute;
top: 0 !important; /* I should explain why this is so !important */
}

/* Long comments should manually break the line length at 80 characters. */
```
Incorrect:
```css
Expand All @@ -383,6 +385,8 @@ Incorrect:
position: absolute;
top: 0 !important; /* I should explain why this is so !important */
}

/* Comments shouldn't have a line length greater than 80 characters, they should manually break the line length at 80 characters */
```

### Best Practices - [Handbook](https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/#best-practices)
Expand Down
7 changes: 6 additions & 1 deletion packages/stylelint-config-wordpress/__tests__/commenting.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const validCss = (`
position: absolute;
top: 0 !important; /* I should explain why this is so !important */
}
/* Long comments should manually break the line length at 80 characters. */
`)

const invalidCss = (`
Expand All @@ -56,6 +58,8 @@ const invalidCss = (`
position: absolute;
top: 0 !important; /* I should explain why this is so !important */
}
/* Comments shouldn't have a line length greater than 80 characters, they should manually break the line length at 80 characters */
`)
/* eslint-enable */

Expand All @@ -81,8 +85,9 @@ test("There are warnings with invalid commenting CSS", t => {
const { errored, results } = data
const { warnings } = results[0]
t.truthy(errored, "errored")
t.is(warnings.length, 2, "flags eight warnings")
t.is(warnings.length, 3, "flags three warnings")
t.is(warnings[0].text, "Expected empty line before comment (comment-empty-line-before)", "correct warning text")
t.is(warnings[1].text, "Expected empty line before comment (comment-empty-line-before)", "correct warning text")
t.is(warnings[2].text, "Expected line length to be no more than 80 characters (max-line-length)", "correct warning text")
})
})
3 changes: 3 additions & 0 deletions packages/stylelint-config-wordpress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ module.exports = {
"keyframe-declaration-no-important": true,
"length-zero-no-unit": true,
"max-empty-lines": 2,
"max-line-length": [ 80, {
"ignore": "non-comments",
} ],
"media-feature-colon-space-after": "always",
"media-feature-colon-space-before": "never",
"media-feature-no-missing-punctuation": true,
Expand Down

0 comments on commit b5f8108

Please sign in to comment.