Skip to content

Commit

Permalink
feat: add declaration-property-value-no-unknown rule
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Aug 19, 2024
1 parent ed48556 commit cbceb16
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/rules/declaration-property-value-no-unknown.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { CSSPropertiesMap, RuleConfig } from 'stylelint-define-config'

export type DeclarationPropertyValueNoUnknownOptions = RuleConfig<
true,
{
/**
* Ignore the specified property and value pairs.
* Keys in the object indicate property names.
* If a string in the object is surrounded with `"/"`,
* it's interpreted as a regular expression.
*
* For example, `"/.+/"` matches any strings.
*/
ignoreProperties?: Record<CSSPropertiesMap, (string | RegExp)[] | string | RegExp>
/**
* Extend or alter the properties syntax dictionary.
* [CSS Value Definition Syntax](https://github.com/csstree/csstree/blob/master/docs/definition-syntax.md) is used to define a value's syntax.
* If a definition starts with `|` it is added to the [existing definition value](https://csstree.github.io/docs/syntax/) if any.
*/
propertiesSyntax?: Record<CSSPropertiesMap, string>

/**
* Extend or alter the types syntax dictionary.
* [CSS Value Definition Syntax](https://github.com/csstree/csstree/blob/master/docs/definition-syntax.md) is used to define a value's syntax.
* If a definition starts with `|` it is added to the [existing definition value](https://csstree.github.io/docs/syntax/) if any.
*
* Types are something like a preset which allows you to reuse a definition across other definitions. So, you'll likely want to also use the `propertiesSyntax` option when using this option.
*/
typesSyntax?: Record<string, string>
}
>
22 changes: 22 additions & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import type { AtImportPartialExtensionAllowedListOptions } from './rules/at-impo
import type { AtImportPartialExtensionDisallowedListOptions } from './rules/at-import-partial-extension-disallowed-list'
import type { AtMixinNoRiskyNestingSelectorOptions } from './rules/at-mixin-no-risky-nesting-selector'
import type { LoadPartialExtensionOptions } from './rules/load-partial-extension'
import type { DeclarationPropertyValueNoUnknownOptions } from './rules/declaration-property-value-no-unknown'

export interface Extends {
'stylelint-config-standard-scss': void
Expand Down Expand Up @@ -396,6 +397,27 @@ interface RuleOptions {
*/
'scss/declaration-nested-properties': DeclarationNestedPropertiesOptions

/**
* Disallow unknown values for properties within declarations.
*
* This rule considers values for properties defined within the CSS specifications to be known. You can use the `propertiesSyntax` and `typesSyntax` secondary options to extend the syntax.
*
* This rule is only appropriate for CSS. You should not turn it on for CSS-like languages, such as Sass or Less, as they have their own syntaxes.
*
* This rule is experimental with some false negatives that we'll patch in minor releases.
*
* It sometimes overlaps with:
* - [`color-no-invalid-hex`](https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/color-no-invalid-hex/README.md)
* - [`function-no-unknown`](https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/function-no-unknown/README.md)
* - [`string-no-newline`](https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/string-no-newline/README.md)
* - [`unit-no-unknown`](https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/unit-no-unknown/README.md)
*
* If duplicate problems are flagged, you can turn off the corresponding rule.
*
* @see [declaration-property-value-no-unknown](https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/declaration-property-value-no-unknown)
*/
'scss/declaration-property-value-no-unknown': DeclarationPropertyValueNoUnknownOptions

/**
* Disallow `/*`-comments.
*
Expand Down

0 comments on commit cbceb16

Please sign in to comment.