Skip to content

Commit 6e88bbf

Browse files
authored
Merge pull request #53 from primer/release-9.0.0
Release 9.0.0
2 parents 1f4a005 + 8d6512f commit 6e88bbf

27 files changed

+1551
-993
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
- uses: actions/checkout@master
88
- uses: actions/setup-node@master
99
with:
10-
version: 11
10+
node-version: 11
1111
- name: install
1212
run: npm install
1313
- name: lint

CHANGELOG.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,47 @@
1-
# HEAD
1+
# 9.0.0
2+
3+
### :boom: Breaking Change
4+
- `primer/variables` is no longer supported; please use the `primer/colors`, `primer/borders`, `primer/box-shadow`, `primer/spacing`, and `primer/typography` rules instead. #50
5+
6+
### :rocket: Enhancements
7+
- The new `primer/colors` rule enforces color variable usage in `color`, `background-color`, and `fill` properties
8+
- The new `primer/borders` rule enforces border variable usage in border CSS props
9+
- The new `primer/box-shadow` rule enforces `$box-shadow*` variables
10+
- The new `primer/spacing` rule enforces `$spacer-*` variables in margin and padding props
11+
- The new `primer/typography` rule enforces typography variable use in `font-family`, `line-height`, and `font-weight` props
12+
- Variable replacements for autofixing are automatically detected in variable data from Primer CSS (see: https://github.com/primer/css/pull/949) #52
13+
- It is now possible to define variable rules using functions that take the variables, as in:
14+
```js
15+
module.exports = createVariableRule('primer/whatever', ({variables}) => {
16+
/* do something with variables here */
17+
})
18+
```
19+
- It's also now possible to provide rule _overrides_ in local stylelint configs as functions:
20+
```js
21+
module.exports = {
22+
extends: 'stylelint-config-primer',
23+
rules: {
24+
'primer/colors': [true, {
25+
rules: ({variables, rules}) => {
26+
/* do something with variables and/or rules here */
27+
return rules
28+
}]
29+
}
30+
})
31+
```
32+
- This release adds support for an optional `singular: true` flag to rule configs, which skips the parsing of individual values in the matched properties. We use this in `primer/box-shadow` to prevent multiple warnings for a single value like `box-shadow: inset 0 1px $blue` (before there would be 4 separate ones!).
33+
34+
### :bug: Bug fixes
35+
- Use `requirePrimerFile()` when loading `dist/variables.json` so that we can access the right file when running _within_ the `@primer/css` repo.
36+
- Walk only declarations (`prop: value`) in rules (blocks with selectors, _not_ `@rules`), and skip linting for declarations nested in `@each`, `@for`, `@function`, and `@mixin` blocks, since those can define their own variables and we can't reliably assert their values.
37+
- Allow `$*-shadow` variable patterns in `primer/box-shadow` to match `$btn-active-shadow` and `$form-control-shadow`
38+
- Allow `color: inherit` in `primer/colors`
39+
- Allow `$em-spacer-*` in `padding` and `margin` properties
40+
- Allow (and auto-fix!) negative spacer variables in `margin` properties
41+
- Make `primer/colors` smarter re: `background` property shorthand values (allowing positions and image `url(*)` values)
42+
- Remove `100%` from allowed values for `border-radius`, and suggest `50%` instead
43+
- Prohibit negative spacer values in `padding` properties
44+
- Allow `$h000-size` for marketing 😬
245

346
# 2.0.0
447

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ Within your [stylelint config object](http://stylelint.io/user-guide/configurati
2727
* [stylelint-scss](https://github.com/kristerkari/stylelint-scss): A collection of SCSS specific linting rules for stylelint
2828
* [scss/selector-no-redundant-nesting-selector](https://github.com/kristerkari/stylelint-scss/blob/master/src/rules/selector-no-redundant-nesting-selector/README.md): Disallow redundant nesting selectors (`&`).
2929
* [primer/no-override](./plugins/#primerno-override): Prohibits custom styles that target Primer CSS selectors.
30-
* [primer/no-unused-vars](./plugins/primerno-unused-vars): Warns about SCSS variables that are declared by not used in your local files.
31-
* [primer/variables](./plugins/primervariables): Constrains certain CSS properties to Primer CSS variables for consistency of color, typography, whitespace, etc.
30+
* [primer/no-unused-vars](./plugins/#primerno-unused-vars): Warns about SCSS variables that are declared by not used in your local files.
31+
- [primer/colors](./plugins/#primercolors): Enforces the use of certain color variables.
32+
- [primer/spacing](./plugins/#primerspacing): Enforces the use of spacing variables for margin and padding.
33+
- [primer/typography](./plugins/#primertypography): Enforces the use of typography variables for certain CSS properties.
34+
- [primer/borders](./plugins/#primerborders): Enforces the use of certain variables for border properties.
35+
- [primer/box-shadow](./plugins/#primerbox-shadow): Enforces the use of certain variables for `box-shadow`.
3236

3337
### Configured lints
3438

__tests__/borders.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
const dedent = require('dedent')
2+
const stylelint = require('stylelint')
3+
const pluginPath = require.resolve('../plugins/borders')
4+
5+
const ruleName = 'primer/borders'
6+
const configWithOptions = args => ({
7+
plugins: [pluginPath],
8+
rules: {
9+
[ruleName]: args
10+
}
11+
})
12+
13+
describe(ruleName, () => {
14+
it('reports compound border properties', () => {
15+
return stylelint
16+
.lint({
17+
code: `
18+
.foo { border: $red; }
19+
`,
20+
config: configWithOptions(true)
21+
})
22+
.then(data => {
23+
expect(data).toHaveErrored()
24+
expect(data).toHaveWarnings([`Please use "$border-red" instead of "$red". (${ruleName})`])
25+
})
26+
})
27+
28+
it('reports multiple border properties', () => {
29+
return stylelint
30+
.lint({
31+
code: `
32+
.foo { border: 1px solid gray; }
33+
`,
34+
config: configWithOptions(true)
35+
})
36+
.then(data => {
37+
expect(data).toHaveErrored()
38+
expect(data).toHaveWarnings([
39+
`Please use "$border-width" instead of "1px". (${ruleName})`,
40+
`Please use "$border-style" instead of "solid". (${ruleName})`,
41+
`Please use a border color variable instead of "gray". (${ruleName})`
42+
])
43+
})
44+
})
45+
46+
it('recognizes function calls as whole tokens', () => {
47+
return stylelint
48+
.lint({
49+
code: `
50+
.foo { border: calc($spacer-2 + var(--derp)) $border-style rgba($border-gray-dark, 50%); }
51+
`,
52+
config: configWithOptions(true)
53+
})
54+
.then(data => {
55+
expect(data).toHaveErrored()
56+
expect(data).toHaveWarnings([
57+
`Please use a border width variable instead of "calc($spacer-2 + var(--derp))". (${ruleName})`,
58+
`Please use a border color variable instead of "rgba($border-gray-dark, 50%)". (${ruleName})`
59+
])
60+
})
61+
})
62+
63+
it('allows $border shorthand in border{,-top,-right,-bottom,-left}', () => {
64+
return stylelint
65+
.lint({
66+
code: dedent`
67+
.a { border: $border; }
68+
.b { border-top: $border; }
69+
.c { border-right: $border; }
70+
.d { border-bottom: $border; }
71+
.e { border-left: $border; }
72+
`,
73+
config: configWithOptions(true)
74+
})
75+
.then(data => {
76+
expect(data).not.toHaveErrored()
77+
expect(data).toHaveWarningsLength(0)
78+
})
79+
})
80+
81+
describe('autofix', () => {
82+
it('fixes border variables', () => {
83+
return stylelint
84+
.lint({
85+
code: dedent`
86+
.a { border: 1px solid $gray-300; }
87+
.b { border: 1px solid $gray-200; }
88+
.c { border: solid 1px $border-gray; }
89+
.d { border: 1px $border-color solid; }
90+
`,
91+
config: configWithOptions(true),
92+
fix: true
93+
})
94+
.then(data => {
95+
expect(data).not.toHaveErrored()
96+
expect(data).toHaveWarningsLength(0)
97+
expect(data.output).toEqual(dedent`
98+
.a { border: $border-width $border-style $border-gray-dark; }
99+
.b { border: $border; }
100+
.c { border: $border; }
101+
.d { border: $border; }
102+
`)
103+
})
104+
})
105+
106+
it('fixes border radius', () => {
107+
return stylelint
108+
.lint({
109+
code: dedent`
110+
.x { border-radius: 3px; }
111+
.y {
112+
border-top-left-radius: 3px;
113+
border-bottom-left-radius: 3px;
114+
}
115+
`,
116+
config: configWithOptions(true),
117+
fix: true
118+
})
119+
.then(data => {
120+
expect(data).not.toHaveErrored()
121+
expect(data).toHaveWarningsLength(0)
122+
expect(data.output).toEqual(dedent`
123+
.x { border-radius: $border-radius; }
124+
.y {
125+
border-top-left-radius: $border-radius;
126+
border-bottom-left-radius: $border-radius;
127+
}
128+
`)
129+
})
130+
})
131+
})
132+
})

__tests__/box-shadow.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const dedent = require('dedent')
2+
const stylelint = require('stylelint')
3+
const pluginPath = require.resolve('../plugins/box-shadow')
4+
5+
const ruleName = 'primer/box-shadow'
6+
const configWithOptions = args => ({
7+
plugins: [pluginPath],
8+
rules: {
9+
[ruleName]: args
10+
}
11+
})
12+
13+
describe(ruleName, () => {
14+
it('works', () => {
15+
return stylelint
16+
.lint({
17+
code: `.x { box-shadow: 0 1px 1px rgba($black, 0.1); }`,
18+
config: configWithOptions(true)
19+
})
20+
.then(data => {
21+
expect(data).toHaveErrored()
22+
expect(data).toHaveWarningsLength(1)
23+
expect(data).toHaveWarnings([
24+
`Please use "$box-shadow" instead of "0 1px 1px rgba($black, 0.1)". (${ruleName})`
25+
])
26+
})
27+
})
28+
29+
describe('autofix', () => {
30+
it('fixes box shadow variables', () => {
31+
return stylelint
32+
.lint({
33+
code: dedent`
34+
.x { box-shadow: 0 1px 1px rgba($black, 0.1); }
35+
`,
36+
config: configWithOptions(true),
37+
fix: true
38+
})
39+
.then(data => {
40+
expect(data).not.toHaveErrored()
41+
expect(data).toHaveWarningsLength(0)
42+
expect(data.output).toEqual(dedent`
43+
.x { box-shadow: $box-shadow; }
44+
`)
45+
})
46+
})
47+
})
48+
})

0 commit comments

Comments
 (0)