Skip to content

Commit

Permalink
feat: Add font-weight-notation rule. (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntwb committed May 31, 2020
1 parent 805eea9 commit b947ba4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/stylelint-config-wordpress/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Removed: `stylelint < 6.9.0` compatibility.
* Added: `selector-attribute-quotes` rule.
* Added: `font-weight-notation` rule.

# 8.0.0

Expand Down
9 changes: 8 additions & 1 deletion packages/stylelint-config-wordpress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ There are numerous ways to input values for properties. Follow the guidelines be
- Do not pad parentheses with spaces
- Always end in a semicolon
- Use double quotes rather than single quotes, and only when needed, such as when a font name has a space.
0 values should not have units unless necessary, such as with transition-duration.
- Font weights should be defined using numeric values (e.g. `400` instead of `normal`, `700` rather than `bold`).
- 0 values should not have units unless necessary, such as with transition-duration.
- Line height should also be unit-less, unless necessary to be defined as a specific pixel value. This is more than just a style convention, but is worth mentioning here. More information: http://meyerweb.com/eric/thoughts/2006/02/08/unitless-line-heights/
- Use a leading zero for decimal values, including in rgba().
- Multiple comma-separated values for one property should be separated by either a space or a newline, including within rgba(). Newlines should be used for lengthier multi-part values such as those for shorthand properties like box-shadow and text-shadow. Each subsequent value after the first should then be on a new line, indented to the same level as the selector and then spaced over to left-align with the previous value.
Expand All @@ -241,6 +242,7 @@ Correct:
.class { /* Correct usage of quotes */
background-image: url(images/bg.png);
font-family: "Helvetica Neue", sans-serif;
font-weight: 700;
}

.class { /* Correct usage of zero values */
Expand All @@ -258,6 +260,11 @@ Incorrect:
.class { /* Avoid adding a unit on a zero value */
margin: 0px 0px 20px 0px;
}

.class {
font-family: Times New Roman, serif; /* Quote font names when required */
font-weight: bold; /* Avoid named font weights */
}
```

### Media Queries - [Handbook](https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/#media-queries) / [Tests](https://github.com/ntwb/stylelint-config-wordpress/blob/master/__tests__/media-queries.js)
Expand Down
17 changes: 12 additions & 5 deletions packages/stylelint-config-wordpress/__tests__/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const validCss = (`
.class { /* Correct usage of quotes */
background-image: url(images/bg.png);
font-family: "Helvetica Neue", sans-serif;
font-weight: 700;
}
.class { /* Correct usage of zero values */
Expand All @@ -25,6 +26,11 @@ const invalidCss = (`
.class { /* Avoid adding a unit on a zero value */
margin: 0px 0px 20px 0px;
}
.class {
font-family: Times New Roman, serif; /* Quote font names when required */
font-weight: bold; /* Avoid named font weights */
}
`)
/* eslint-enable */

Expand All @@ -50,12 +56,13 @@ test("There are warnings with invalid values CSS", t => {
const { errored, results } = data
const { warnings } = results[0]
t.truthy(errored, "errored")
t.is(warnings.length, 6, "flags eight warnings")
t.is(warnings.length, 8, "flags eight warnings")
t.is(warnings[0].text, "Expected a trailing semicolon (declaration-block-trailing-semicolon)", "correct warning text")
t.is(warnings[1].text, "Expected single space after \":\" with a single-line declaration (declaration-colon-space-after)", "correct warning text")
t.is(warnings[2].text, "Unexpected unit (length-zero-no-unit)", "correct warning text")
t.is(warnings[3].text, "Unexpected unit (length-zero-no-unit)", "correct warning text")
t.is(warnings[2].text, "Expected quotes around font-family name \"Times New Roman\" (font-family-name-quotes)", "correct warning text")
t.is(warnings[3].text, "Expected numeric font-weight notation (font-weight-notation)", "correct warning text")
t.is(warnings[4].text, "Unexpected unit (length-zero-no-unit)", "correct warning text")
t.is(warnings[5].text, "Unexpected longhand value '0px 0px 20px 0px' instead of '0px 0px 20px' (shorthand-property-no-redundant-values)", "correct warning text")
})
t.is(warnings[5].text, "Unexpected unit (length-zero-no-unit)", "correct warning text")
t.is(warnings[6].text, "Unexpected unit (length-zero-no-unit)", "correct warning text")
t.is(warnings[7].text, "Unexpected longhand value '0px 0px 20px 0px' instead of '0px 0px 20px' (shorthand-property-no-redundant-values)", "correct warning text") })
})
1 change: 1 addition & 0 deletions packages/stylelint-config-wordpress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
"declaration-colon-space-after": "always-single-line",
"declaration-colon-space-before": "never",
"font-family-name-quotes": "always-where-recommended",
"font-weight-notation": "numeric",
"function-calc-no-unspaced-operator": true,
"function-comma-space-after": "always",
"function-comma-space-before": "never",
Expand Down

0 comments on commit b947ba4

Please sign in to comment.