Skip to content

Commit d6a4885

Browse files
committed
feat: add color-function-alias-notation rule
1 parent 96764c0 commit d6a4885

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { RuleConfig } from '../rule-config'
2+
3+
export type ColorFunctionAliasNatationOptions = RuleConfig<
4+
'without-alpha' | 'with-alpha',
5+
{
6+
message?: string | ((unfixed: string, fixed: string) => string)
7+
}
8+
>

src/rules/stylelint/index.d.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { AtRuleNoVendorPrefixOptions } from './at-rule-no-vendor-prefix'
1111
import type { AtRulePreludeNoInvalidOptions } from './at-rule-prelude-no-invalid'
1212
import type { AtRulePropertyRequiredListOptions } from './at-rule-property-required-list'
1313
import type { BlockNoEmptyOptions } from './block-no-empty'
14+
import type { ColorFunctionAliasNatationOptions } from './color-function-alias-notation'
1415
import type { ColorFunctionNatationOptions } from './color-function-notation'
1516
import type { ColorHexAlphaOptions } from './color-hex-alpha'
1617
import type { ColorHexLengthOptions } from './color-hex-length'
@@ -379,6 +380,25 @@ export interface StyleLintRules {
379380
*/
380381
'block-no-empty': BlockNoEmptyOptions
381382

383+
/**
384+
* Specify alias notation for color-functions
385+
*
386+
* ```scss
387+
* a { color: rgb(0 0 0 / 0.2) }
388+
* // ^^^
389+
* // This notation
390+
* ```
391+
*
392+
* Color functions `rgb()` and `hsl()` have aliases `rgba()` and `hsla()`. Those are exactly equivalent, and [it's preferable](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb) to use the first variant without `a`.
393+
*
394+
* ### Primary Options
395+
* - `'without-alpha'`: Applicable color-functions must always use the without alpha notation.
396+
* - `'with-alpha'`: Applicable color-functions must always use with alpha notation.
397+
*
398+
* @see [color-function-alias-notation](https://stylelint.io/user-guide/rules/color-function-alias-notation)
399+
*/
400+
'color-function-alias-notation': ColorFunctionAliasNatationOptions
401+
382402
/**
383403
* Specify modern or legacy notation for color-functions.
384404
*
@@ -399,7 +419,7 @@ export interface StyleLintRules {
399419
* - `"modern"`: Applicable color-functions must always use modern notation.
400420
* - `"legacy"`: Applicable color-functions must always use the legacy notation.
401421
*
402-
* #### Optional Secondary Options
422+
* ### Optional Secondary Options
403423
* - `ignore`
404424
*
405425
* @see [color-function-notation](https://stylelint.io/user-guide/rules/color-function-notation)

0 commit comments

Comments
 (0)