From cbceb16b6e9c1b35a307390b612ed932193c5010 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Tue, 20 Aug 2024 01:03:55 +0800 Subject: [PATCH] feat: add `declaration-property-value-no-unknown` rule --- ...declaration-property-value-no-unknown.d.ts | 31 +++++++++++++++++++ lib/types.d.ts | 22 +++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 lib/rules/declaration-property-value-no-unknown.d.ts diff --git a/lib/rules/declaration-property-value-no-unknown.d.ts b/lib/rules/declaration-property-value-no-unknown.d.ts new file mode 100644 index 0000000..d2fecf5 --- /dev/null +++ b/lib/rules/declaration-property-value-no-unknown.d.ts @@ -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 + /** + * 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 + + /** + * 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 + } +> diff --git a/lib/types.d.ts b/lib/types.d.ts index 02df861..2a2f1ab 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -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 @@ -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. *