Skip to content

Commit

Permalink
Fixing the primer/colors and primer/borders rules (#111)
Browse files Browse the repository at this point in the history
* Fixing the primer/colors and primer/borders rules

* Updating the tests

* Create quiet-mugs-turn.md

* Fixing error links
  • Loading branch information
jonrohan authored Sep 8, 2021
1 parent 027106f commit 3a4654b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-mugs-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint-config-primer": patch
---

Fixing the primer/colors and primer/borders rules
1 change: 1 addition & 0 deletions __tests__/borders.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe(ruleName, () => {
.y { border-color: var(--color-btn-border-hover); }
.z { border-color: var(--color-diff-deletion-border); }
.a { border-color: var(--color-border); }
.a { border-color: var(--color-accent); }
`,
config: configWithOptions(true)
})
Expand Down
14 changes: 8 additions & 6 deletions __tests__/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe(ruleName, () => {
expect(data).toHaveErrored()
expect(data).toHaveWarningsLength(1)
expect(data).toHaveWarnings([
`Please use a text color variable instead of "#f00". See https://primer.style/css/utilities/colors. (${ruleName})`
`Please use a text color variable instead of "#f00". See https://primer.style/primitives/colors. (${ruleName})`
])
})
})
Expand Down Expand Up @@ -84,7 +84,7 @@ describe(ruleName, () => {
expect(data).toHaveErrored()
expect(data).toHaveWarningsLength(1)
expect(data).toHaveWarnings([
`Please use a background color variable instead of "$red". See https://primer.style/css/utilities/colors. (${ruleName})`
`Please use a background color variable instead of "$red". See https://primer.style/primitives/colors. (${ruleName})`
])
})
})
Expand All @@ -109,6 +109,7 @@ describe(ruleName, () => {
.y { background-color: var(--color-btn-bg-hover); }
.z { background-color: var(--color-diff-deletion-bg); }
.a { background-color: var(--color-bg); }
.a { background-color: var(--color-accent); }
`,
config: configWithOptions(true)
})
Expand All @@ -125,7 +126,8 @@ describe(ruleName, () => {
.x { color: var(--color-text-primary); }
.y { color: var(--color-btn-text-hover); }
.z { color: var(--color-diff-deletion-text); }
.a { color: var(--color-text); }
.a { color: var(--color-fg); }
.a { color: var(--color-accent); }
`,
config: configWithOptions(true)
})
Expand All @@ -145,7 +147,7 @@ describe(ruleName, () => {
expect(data).toHaveErrored()
expect(data).toHaveWarningsLength(1)
expect(data).toHaveWarnings([
`Please use a background color variable instead of "red". See https://primer.style/css/utilities/colors. (${ruleName})`
`Please use a background color variable instead of "red". See https://primer.style/primitives/colors. (${ruleName})`
])
})
})
Expand Down Expand Up @@ -218,7 +220,7 @@ describe(ruleName, () => {
expect(data).toHaveErrored()
expect(data).toHaveWarningsLength(1)
expect(data).toHaveWarnings([
`Please use a text color variable instead of "#f00". See https://primer.style/css/utilities/colors. (${ruleName})`
`Please use a text color variable instead of "#f00". See https://primer.style/primitives/colors. (${ruleName})`
])
})
})
Expand All @@ -239,7 +241,7 @@ describe(ruleName, () => {
expect(data).toHaveErrored()
expect(data).toHaveWarningsLength(1)
expect(data).toHaveWarnings([
`Please use a text color variable instead of "#f00". See https://primer.style/css/utilities/colors. (${ruleName})`
`Please use a text color variable instead of "#f00". See https://primer.style/primitives/colors. (${ruleName})`
])
})
})
Expand Down
3 changes: 2 additions & 1 deletion plugins/borders.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = createVariableRule(
'transparent',
'currentColor',
// Match variables in any of the following formats: --color-border-*, --color-*-border-*, --color-*-border
/var\(--color-(.+-)*border(-.+)*\)/
/var\(--color-(.+-)*border(-.+)*\)/,
/var\(--color-[^)]+\)/
],
replacements: {
'$border-gray': '$border-color'
Expand Down
17 changes: 7 additions & 10 deletions plugins/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const bgVars = [
'$bg-*',
'$tooltip-background-color',
// Match variables in any of the following formats: --color-bg-*, --color-*-bg-*, --color-*-bg
/var\(--color-(.+-)*bg(-.+)*\)/
/var\(--color-(.+-)*bg(-.+)*\)/,
/var\(--color-[^)]+\)/
]

module.exports = createVariableRule(
Expand All @@ -26,15 +27,11 @@ module.exports = createVariableRule(
'$tooltip-text-color',
'inherit',
// Match variables in any of the following formats: --color-text-*, --color-*-text-*, --color-*-text
/var\(--color-(.+-)*text(-.+)*\)/
],
replacements: {
'#fff': '$text-white',
white: '$text-white',
'#000': '$text-gray-dark',
black: '$black'
}
/var\(--color-(.+-)*text(-.+)*\)/,
/var\(--color-(.+-)*fg(-.+)*\)/,
/var\(--color-[^)]+\)/
]
}
},
'https://primer.style/css/utilities/colors'
'https://primer.style/primitives/colors'
)

0 comments on commit 3a4654b

Please sign in to comment.