UNPKG

31.9 kBTypeScriptView Raw
1import type * as PostCSS from 'postcss';
2import type { GlobbyOptions } from 'globby';
3import type { cosmiconfig, TransformSync as CosmiconfigTransformSync } from 'cosmiconfig';
4
5type ConfigExtends = string | string[];
6
7type ConfigPlugins = string | stylelint.Plugin | (string | stylelint.Plugin)[];
8
9type ConfigIgnoreFiles = string | string[];
10
11type ConfigRules = {
12 [ruleName: string]: stylelint.ConfigRuleSettings<any, Object>;
13};
14
15type ConfigOverride = Omit<stylelint.Config, 'overrides'> & {
16 files: string | string[];
17 name?: string;
18};
19
20type ConfigProcessors = string[];
21
22type DisableSettings = stylelint.ConfigRuleSettings<boolean, stylelint.DisableOptions>;
23
24// A meta-type that returns a union over all properties of `T` whose values
25// have type `U`.
26type PropertyNamesOfType<T, U> = {
27 [K in keyof T]-?: T[K] extends U ? K : never;
28}[keyof T];
29
30type FileCache = {
31 calcHashOfConfig: (config: stylelint.Config) => void;
32 hasFileChanged: (absoluteFilepath: string) => boolean;
33 reconcile: () => void;
34 destroy: () => void;
35 removeEntry: (absoluteFilepath: string) => void;
36};
37
38// Note: With strict function types enabled, function signatures are checked contravariantly.
39// This means that it would not be possible for rule authors to narrow the message function
40// parameters to e.g. just `string`. Declaring the type for rule message functions through
41// method declarations tricks TypeScript into bivariant signature checking. More details can
42// be found here: https://stackoverflow.com/questions/52667959/what-is-the-purpose-of-bivariancehack-in-typescript-types.
43// and in the original discussion: https://github.com/stylelint/stylelint/pull/6147#issuecomment-1155337016.
44type RuleMessageFunc = {
45 bivariance(...args: (string | number | boolean | RegExp)[]): string;
46}['bivariance'];
47
48type RuleSeverityFunc = {
49 bivariance(...args: (string | number | boolean | RegExp)[]): stylelint.Severity | null;
50}['bivariance'];
51
52type RuleOptionsPossibleFunc = (value: unknown) => boolean;
53
54type DisableReportEntry = {
55 source?: string;
56 ranges: stylelint.DisableReportRange[];
57};
58
59declare namespace stylelint {
60 /**
61 * Rule severity.
62 */
63 export type Severity = 'warning' | 'error';
64
65 /**
66 * A Stylelint plugin.
67 */
68 export type Plugin =
69 | { default?: { ruleName: string; rule: Rule } }
70 | { ruleName: string; rule: Rule };
71
72 /** @internal */
73 export type ConfigRuleSettings<T, O extends Object> =
74 | null
75 | undefined
76 | NonNullable<T>
77 | [NonNullable<T>]
78 | [NonNullable<T>, O];
79
80 /** @internal */
81 export type DisableOptions = {
82 except?: Array<StringOrRegex>;
83 severity?: Severity;
84 };
85
86 /**
87 * Configuration.
88 */
89 export type Config = {
90 extends?: ConfigExtends;
91 plugins?: ConfigPlugins;
92 pluginFunctions?: {
93 [pluginName: string]: Rule;
94 };
95 ignoreFiles?: ConfigIgnoreFiles;
96 ignorePatterns?: string;
97 rules?: ConfigRules;
98 quiet?: boolean;
99 formatter?: FormatterType | Formatter;
100 defaultSeverity?: Severity;
101 ignoreDisables?: boolean;
102 reportNeedlessDisables?: DisableSettings;
103 reportInvalidScopeDisables?: DisableSettings;
104 reportDescriptionlessDisables?: DisableSettings;
105 reportUnscopedDisables?: DisableSettings;
106 configurationComment?: string;
107 overrides?: ConfigOverride[];
108 customSyntax?: CustomSyntax;
109 processors?: ConfigProcessors;
110 /** @internal */
111 _processorFunctions?: Map<string, ReturnType<Processor>['postprocess']>;
112 allowEmptyInput?: boolean;
113 cache?: boolean;
114 fix?: boolean;
115 validate?: boolean;
116 };
117
118 /** @internal */
119 export type DisablePropertyName = PropertyNamesOfType<Config, DisableSettings>;
120
121 /** @internal */
122 export type CosmiconfigResult =
123 | (ReturnType<CosmiconfigTransformSync> & { config: Config })
124 | null;
125
126 /** @internal */
127 export type DisabledRange = {
128 node: PostCSS.Node;
129 start: number;
130 strictStart: boolean;
131 end?: number;
132 strictEnd?: boolean;
133 rules?: string[];
134 description?: string;
135 };
136
137 /** @internal */
138 export type DisabledRangeObject = {
139 [ruleName: string]: DisabledRange[];
140 };
141
142 /** @internal */
143 export type DisabledWarning = { line: number; rule: string };
144
145 /** @internal */
146 export type StylelintPostcssResult = {
147 ruleSeverities: { [ruleName: string]: RuleSeverity };
148 customMessages: { [ruleName: string]: RuleMessage };
149 customUrls: { [ruleName: string]: string };
150 ruleMetadata: { [ruleName: string]: Partial<RuleMeta> };
151 fixersData: { [ruleName: string]: Array<FixerData> };
152 quiet?: boolean;
153 disabledRanges: DisabledRangeObject;
154 disabledWarnings?: DisabledWarning[];
155 ignored?: boolean;
156 stylelintError?: boolean;
157 stylelintWarning?: boolean;
158 config?: Config;
159 };
160
161 type StylelintWarningType = 'deprecation' | 'invalidOption' | 'parseError';
162
163 /** @internal */
164 export type WarningOptions = PostCSS.WarningOptions & {
165 stylelintType?: StylelintWarningType;
166 severity?: Severity;
167 url?: string;
168 rule?: string;
169 };
170
171 /** @internal */
172 export type PostcssResult = PostCSS.Result & {
173 stylelint: StylelintPostcssResult;
174 warn(message: string, options?: WarningOptions): void;
175 };
176
177 /** @internal */
178 export type Formatter = (results: LintResult[], returnValue: LinterResult) => string;
179
180 type Formatters = {
181 readonly compact: Promise<Formatter>;
182 /** @deprecated */
183 readonly github: Promise<Formatter>;
184 readonly json: Promise<Formatter>;
185 readonly string: Promise<Formatter>;
186 readonly tap: Promise<Formatter>;
187 readonly unix: Promise<Formatter>;
188 readonly verbose: Promise<Formatter>;
189 };
190
191 /** @internal */
192 export type FormatterType = keyof Formatters;
193
194 /** @internal */
195 export type CustomSyntax = string | PostCSS.Syntax;
196
197 /**
198 * WARNING: This is an experimental feature. The API may change in the future.
199 */
200 export type Processor = () => {
201 name: string;
202 postprocess: (result: LintResult, root?: PostCSS.Root) => void;
203 };
204
205 /** @internal */
206 export type RuleMessage = string | RuleMessageFunc;
207
208 /** @internal */
209 export type RuleMessages = { [message: string]: RuleMessage };
210
211 /** @internal */
212 export type RuleOptionsPossible = boolean | number | string | RuleOptionsPossibleFunc;
213
214 /** @internal */
215 export type RuleOptions = {
216 actual: unknown;
217 possible?:
218 | RuleOptionsPossibleFunc
219 | RuleOptionsPossible[]
220 | Record<string, RuleOptionsPossible[]>;
221 optional?: boolean;
222 };
223
224 /** @internal */
225 type RuleSeverity = Severity | RuleSeverityFunc;
226
227 /**
228 * A rule context.
229 */
230 export type RuleContext = {
231 configurationComment?: string | undefined;
232 fix?: boolean | undefined;
233 newline?: string | undefined;
234 };
235
236 /** @internal */
237 export type RuleBase<P = any, S = any> = (
238 primaryOption: P,
239 secondaryOptions: S,
240 context: RuleContext,
241 ) => (root: PostCSS.Root, result: PostcssResult) => Promise<void> | void;
242
243 /** @internal */
244 export type RuleMeta = {
245 url: string;
246 deprecated?: boolean;
247 fixable?: boolean;
248 };
249
250 /** @internal */
251 export type Range = {
252 start: Position;
253 end: Position;
254 };
255
256 type FixerData = {
257 range?: Range;
258 fixed: boolean;
259 };
260
261 /**
262 * A rule.
263 */
264 export type Rule<P = any, S = any> = RuleBase<P, S> & {
265 ruleName: string;
266 messages: RuleMessages;
267 primaryOptionArray?: boolean;
268 meta?: RuleMeta;
269 };
270
271 type StringOrRegex = string | RegExp;
272 type OneOrMany<S> = S | S[];
273 type Primary = number | true | OneOrMany<StringOrRegex> | Record<string, any>;
274 type Secondary = Record<string, any>;
275 type CoreRule<P extends Primary, S extends Secondary = any> = Rule<P, S>;
276
277 /** @internal */
278 export type CoreRules = {
279 'alpha-value-notation': CoreRule<
280 'number' | 'percentage',
281 { exceptProperties: OneOrMany<StringOrRegex> }
282 >;
283 'annotation-no-unknown': CoreRule<true, { ignoreAnnotations: OneOrMany<StringOrRegex> }>;
284 'at-rule-allowed-list': CoreRule<OneOrMany<string>>;
285 'at-rule-disallowed-list': CoreRule<OneOrMany<string>>;
286 'at-rule-empty-line-before': CoreRule<
287 'always' | 'never',
288 {
289 except: OneOrMany<
290 | 'after-same-name'
291 | 'inside-block'
292 | 'blockless-after-same-name-blockless'
293 | 'blockless-after-blockless'
294 | 'first-nested'
295 >;
296 ignore: OneOrMany<
297 | 'after-comment'
298 | 'first-nested'
299 | 'inside-block'
300 | 'blockless-after-same-name-blockless'
301 | 'blockless-after-blockless'
302 >;
303 ignoreAtRules: OneOrMany<string>;
304 }
305 >;
306 'at-rule-no-unknown': CoreRule<true, { ignoreAtRules: OneOrMany<StringOrRegex> }>;
307 'at-rule-no-vendor-prefix': CoreRule<true>;
308 'at-rule-property-required-list': CoreRule<Record<string, OneOrMany<string>>>;
309 'block-no-empty': CoreRule<true, { ignore: OneOrMany<'comments'> }>;
310 'color-function-notation': CoreRule<
311 'modern' | 'legacy',
312 { ignore: OneOrMany<'with-var-inside'> }
313 >;
314 'color-hex-alpha': CoreRule<'always' | 'never'>;
315 'color-hex-length': CoreRule<'short' | 'long'>;
316 'color-named': CoreRule<
317 'never' | 'always-where-possible',
318 { ignoreProperties: OneOrMany<StringOrRegex>; ignore: OneOrMany<'inside-function'> }
319 >;
320 'color-no-hex': CoreRule<true>;
321 'color-no-invalid-hex': CoreRule<true>;
322 'comment-empty-line-before': CoreRule<
323 'always' | 'never',
324 {
325 except: OneOrMany<'first-nested'>;
326 ignore: OneOrMany<'stylelint-commands' | 'after-comment'>;
327 ignoreComments: OneOrMany<StringOrRegex>;
328 }
329 >;
330 'comment-no-empty': CoreRule<true>;
331 'comment-pattern': CoreRule<StringOrRegex>;
332 'comment-whitespace-inside': CoreRule<'always' | 'never'>;
333 'comment-word-disallowed-list': CoreRule<OneOrMany<StringOrRegex>>;
334 'custom-media-pattern': CoreRule<StringOrRegex>;
335 'custom-property-empty-line-before': CoreRule<
336 'always' | 'never',
337 {
338 except: OneOrMany<'first-nested' | 'after-comment' | 'after-custom-property'>;
339 ignore: OneOrMany<'after-comment' | 'first-nested' | 'inside-single-line-block'>;
340 }
341 >;
342 'custom-property-no-missing-var-function': CoreRule<true>;
343 'custom-property-pattern': CoreRule<StringOrRegex>;
344 'declaration-block-no-duplicate-custom-properties': CoreRule<
345 true,
346 { ignoreProperties: OneOrMany<StringOrRegex> }
347 >;
348 'declaration-block-no-duplicate-properties': CoreRule<
349 true,
350 {
351 ignore: OneOrMany<
352 | 'consecutive-duplicates'
353 | 'consecutive-duplicates-with-different-values'
354 | 'consecutive-duplicates-with-different-syntaxes'
355 | 'consecutive-duplicates-with-same-prefixless-values'
356 >;
357 ignoreProperties: OneOrMany<StringOrRegex>;
358 }
359 >;
360 'declaration-block-no-redundant-longhand-properties': CoreRule<
361 true,
362 {
363 ignoreShorthands: OneOrMany<StringOrRegex>;
364 ignoreLonghands: OneOrMany<string>;
365 }
366 >;
367 'declaration-block-no-shorthand-property-overrides': CoreRule<true>;
368 'declaration-block-single-line-max-declarations': CoreRule<number>;
369 'declaration-empty-line-before': CoreRule<
370 'always' | 'never',
371 {
372 except: OneOrMany<'first-nested' | 'after-comment' | 'after-declaration'>;
373 ignore: OneOrMany<
374 'after-comment' | 'after-declaration' | 'first-nested' | 'inside-single-line-block'
375 >;
376 }
377 >;
378 'declaration-no-important': CoreRule<true>;
379 'declaration-property-max-values': CoreRule<Record<string, number>>;
380 'declaration-property-unit-allowed-list': CoreRule<
381 Record<string, OneOrMany<string>>,
382 { ignore: OneOrMany<'inside-function'> }
383 >;
384 'declaration-property-unit-disallowed-list': CoreRule<Record<string, OneOrMany<string>>>;
385 'declaration-property-value-allowed-list': CoreRule<Record<string, OneOrMany<StringOrRegex>>>;
386 'declaration-property-value-disallowed-list': CoreRule<
387 Record<string, OneOrMany<StringOrRegex>>
388 >;
389 'declaration-property-value-no-unknown': CoreRule<
390 true,
391 {
392 ignoreProperties: Record<string, OneOrMany<StringOrRegex>>;
393 propertiesSyntax: Record<string, string>;
394 typesSyntax: Record<string, string>;
395 }
396 >;
397 'font-family-name-quotes': CoreRule<
398 'always-where-required' | 'always-where-recommended' | 'always-unless-keyword'
399 >;
400 'font-family-no-duplicate-names': CoreRule<
401 true,
402 { ignoreFontFamilyNames: OneOrMany<StringOrRegex> }
403 >;
404 'font-family-no-missing-generic-family-keyword': CoreRule<
405 true,
406 { ignoreFontFamilies: OneOrMany<StringOrRegex> }
407 >;
408 'font-weight-notation': CoreRule<
409 'numeric' | 'named-where-possible',
410 { ignore: OneOrMany<'relative'> }
411 >;
412 'function-allowed-list': CoreRule<OneOrMany<StringOrRegex>>;
413 'function-calc-no-unspaced-operator': CoreRule<true>;
414 'function-disallowed-list': CoreRule<OneOrMany<StringOrRegex>>;
415 'function-linear-gradient-no-nonstandard-direction': CoreRule<true>;
416 'function-name-case': CoreRule<
417 'lower' | 'upper',
418 { ignoreFunctions: OneOrMany<StringOrRegex> }
419 >;
420 'function-no-unknown': CoreRule<true, { ignoreFunctions: OneOrMany<StringOrRegex> }>;
421 'function-url-no-scheme-relative': CoreRule<true>;
422 'function-url-quotes': CoreRule<'always' | 'never', { except: OneOrMany<'empty'> }>;
423 'function-url-scheme-allowed-list': CoreRule<OneOrMany<StringOrRegex>>;
424 'function-url-scheme-disallowed-list': CoreRule<OneOrMany<StringOrRegex>>;
425 'hue-degree-notation': CoreRule<'angle' | 'number'>;
426 'import-notation': CoreRule<'string' | 'url'>;
427 'keyframe-block-no-duplicate-selectors': CoreRule<true>;
428 'keyframe-declaration-no-important': CoreRule<true>;
429 'keyframe-selector-notation': CoreRule<
430 'keyword' | 'percentage' | 'percentage-unless-within-keyword-only-block'
431 >;
432 'keyframes-name-pattern': CoreRule<StringOrRegex>;
433 'length-zero-no-unit': CoreRule<
434 true,
435 {
436 ignore: OneOrMany<'custom-properties'>;
437 ignoreFunctions: OneOrMany<StringOrRegex>;
438 }
439 >;
440 'lightness-notation': CoreRule<'percentage' | 'number'>;
441 'max-nesting-depth': CoreRule<
442 number,
443 {
444 ignore: OneOrMany<'blockless-at-rules' | 'pseudo-classes'>;
445 ignoreAtRules: OneOrMany<StringOrRegex>;
446 ignoreRules: OneOrMany<StringOrRegex>;
447 ignorePseudoClasses: OneOrMany<StringOrRegex>;
448 }
449 >;
450 'media-feature-name-allowed-list': CoreRule<OneOrMany<StringOrRegex>>;
451 'media-feature-name-disallowed-list': CoreRule<OneOrMany<StringOrRegex>>;
452 'media-feature-name-no-unknown': CoreRule<
453 true,
454 { ignoreMediaFeatureNames: OneOrMany<StringOrRegex> }
455 >;
456 'media-feature-name-no-vendor-prefix': CoreRule<true>;
457 'media-feature-name-unit-allowed-list': CoreRule<Record<string, OneOrMany<string>>>;
458 'media-feature-name-value-allowed-list': CoreRule<Record<string, OneOrMany<StringOrRegex>>>;
459 'media-feature-name-value-no-unknown': CoreRule<true>;
460 'media-feature-range-notation': CoreRule<'prefix' | 'context'>;
461 'media-query-no-invalid': CoreRule<true, { ignoreFunctions: OneOrMany<StringOrRegex> }>;
462 'named-grid-areas-no-invalid': CoreRule<true>;
463 'no-descending-specificity': CoreRule<true, { ignore: OneOrMany<'selectors-within-list'> }>;
464 'no-duplicate-at-import-rules': CoreRule<true>;
465 'no-duplicate-selectors': CoreRule<true, { disallowInList: boolean }>;
466 'no-empty-source': CoreRule<true>;
467 'no-invalid-double-slash-comments': CoreRule<true>;
468 'no-invalid-position-at-import-rule': CoreRule<
469 true,
470 { ignoreAtRules: OneOrMany<StringOrRegex> }
471 >;
472 'no-irregular-whitespace': CoreRule<true>;
473 'no-unknown-animations': CoreRule<true>;
474 'no-unknown-custom-media': CoreRule<true>;
475 'no-unknown-custom-properties': CoreRule<true>;
476 'number-max-precision': CoreRule<
477 number,
478 {
479 ignoreProperties: OneOrMany<StringOrRegex>;
480 ignoreUnits: OneOrMany<StringOrRegex>;
481 insideFunctions: Record<string, number>;
482 }
483 >;
484 'property-allowed-list': CoreRule<OneOrMany<StringOrRegex>>;
485 'property-disallowed-list': CoreRule<OneOrMany<StringOrRegex>>;
486 'property-no-unknown': CoreRule<
487 true,
488 {
489 checkPrefixed: boolean;
490 ignoreAtRules: OneOrMany<StringOrRegex>;
491 ignoreProperties: OneOrMany<StringOrRegex>;
492 ignoreSelectors: OneOrMany<StringOrRegex>;
493 }
494 >;
495 'property-no-vendor-prefix': CoreRule<true, { ignoreProperties: OneOrMany<StringOrRegex> }>;
496 'rule-empty-line-before': CoreRule<
497 'always' | 'never' | 'always-multi-line' | 'never-multi-line',
498 {
499 ignore: OneOrMany<'after-comment' | 'first-nested' | 'inside-block'>;
500 except: OneOrMany<
501 | 'after-rule'
502 | 'after-single-line-comment'
503 | 'first-nested'
504 | 'inside-block-and-after-rule'
505 | 'inside-block'
506 >;
507 }
508 >;
509 'rule-selector-property-disallowed-list': CoreRule<
510 Record<string, OneOrMany<StringOrRegex>>,
511 {
512 ignore: OneOrMany<'keyframe-selectors'>;
513 }
514 >;
515 'selector-anb-no-unmatchable': CoreRule<true>;
516 'selector-attribute-name-disallowed-list': CoreRule<OneOrMany<StringOrRegex>>;
517 'selector-attribute-operator-allowed-list': CoreRule<OneOrMany<string>>;
518 'selector-attribute-operator-disallowed-list': CoreRule<OneOrMany<string>>;
519 'selector-attribute-quotes': CoreRule<'always' | 'never'>;
520 'selector-class-pattern': CoreRule<StringOrRegex, { resolveNestedSelectors: boolean }>;
521 'selector-combinator-allowed-list': CoreRule<OneOrMany<string>>;
522 'selector-combinator-disallowed-list': CoreRule<OneOrMany<string>>;
523 'selector-disallowed-list': CoreRule<
524 OneOrMany<StringOrRegex>,
525 { splitList: boolean; ignore: OneOrMany<'inside-block' | 'keyframe-selectors'> }
526 >;
527 'selector-id-pattern': CoreRule<StringOrRegex>;
528 'selector-max-attribute': CoreRule<number, { ignoreAttributes: OneOrMany<StringOrRegex> }>;
529 'selector-max-class': CoreRule<number>;
530 'selector-max-combinators': CoreRule<number>;
531 'selector-max-compound-selectors': CoreRule<
532 number,
533 { ignoreSelectors: OneOrMany<StringOrRegex> }
534 >;
535 'selector-max-id': CoreRule<
536 number,
537 {
538 ignoreContextFunctionalPseudoClasses: OneOrMany<StringOrRegex>;
539 checkContextFunctionalPseudoClasses: OneOrMany<StringOrRegex>;
540 }
541 >;
542 'selector-max-pseudo-class': CoreRule<number>;
543 'selector-max-specificity': CoreRule<string, { ignoreSelectors: OneOrMany<StringOrRegex> }>;
544 'selector-max-type': CoreRule<
545 number,
546 {
547 ignore: OneOrMany<
548 'descendant' | 'child' | 'compounded' | 'next-sibling' | 'custom-elements'
549 >;
550 ignoreTypes: OneOrMany<StringOrRegex>;
551 }
552 >;
553 'selector-max-universal': CoreRule<number, { ignoreAfterCombinators: OneOrMany<string> }>;
554 'selector-nested-pattern': CoreRule<StringOrRegex, { splitList: boolean }>;
555 'selector-no-qualifying-type': CoreRule<
556 true,
557 { ignore: OneOrMany<'attribute' | 'class' | 'id'> }
558 >;
559 'selector-no-vendor-prefix': CoreRule<true, { ignoreSelectors: OneOrMany<StringOrRegex> }>;
560 'selector-not-notation': CoreRule<'simple' | 'complex'>;
561 'selector-pseudo-class-allowed-list': CoreRule<OneOrMany<StringOrRegex>>;
562 'selector-pseudo-class-disallowed-list': CoreRule<OneOrMany<StringOrRegex>>;
563 'selector-pseudo-class-no-unknown': CoreRule<
564 true,
565 { ignorePseudoClasses: OneOrMany<StringOrRegex> }
566 >;
567 'selector-pseudo-element-allowed-list': CoreRule<OneOrMany<StringOrRegex>>;
568 'selector-pseudo-element-colon-notation': CoreRule<'single' | 'double'>;
569 'selector-pseudo-element-disallowed-list': CoreRule<OneOrMany<StringOrRegex>>;
570 'selector-pseudo-element-no-unknown': CoreRule<
571 true,
572 { ignorePseudoElements: OneOrMany<StringOrRegex> }
573 >;
574 'selector-type-case': CoreRule<'lower' | 'upper', { ignoreTypes: OneOrMany<StringOrRegex> }>;
575 'selector-type-no-unknown': CoreRule<
576 true,
577 {
578 ignore: OneOrMany<'custom-elements' | 'default-namespace'>;
579 ignoreNamespaces: OneOrMany<StringOrRegex>;
580 ignoreTypes: OneOrMany<StringOrRegex>;
581 }
582 >;
583 'shorthand-property-no-redundant-values': CoreRule<true>;
584 'string-no-newline': CoreRule<true>;
585 'time-min-milliseconds': CoreRule<number, { ignore: OneOrMany<'delay'> }>;
586 'unit-allowed-list': CoreRule<
587 OneOrMany<string>,
588 {
589 ignoreFunctions: OneOrMany<StringOrRegex>;
590 ignoreProperties: Record<string, OneOrMany<StringOrRegex>>;
591 }
592 >;
593 'unit-disallowed-list': CoreRule<
594 OneOrMany<string>,
595 {
596 ignoreFunctions: OneOrMany<StringOrRegex>;
597 ignoreProperties: Record<string, OneOrMany<StringOrRegex>>;
598 ignoreMediaFeatureNames: Record<string, OneOrMany<StringOrRegex>>;
599 }
600 >;
601 'unit-no-unknown': CoreRule<
602 true,
603 {
604 ignoreUnits: OneOrMany<StringOrRegex>;
605 ignoreFunctions: OneOrMany<StringOrRegex>;
606 }
607 >;
608 'value-keyword-case': CoreRule<
609 'lower' | 'upper',
610 {
611 ignoreProperties: OneOrMany<StringOrRegex>;
612 ignoreKeywords: OneOrMany<StringOrRegex>;
613 ignoreFunctions: OneOrMany<StringOrRegex>;
614 camelCaseSvgKeywords: boolean;
615 }
616 >;
617 'value-no-vendor-prefix': CoreRule<true, { ignoreValues: OneOrMany<StringOrRegex> }>;
618 };
619
620 /** @internal */
621 export type GetPostcssOptions = {
622 code?: string;
623 codeFilename?: string;
624 filePath?: string;
625 customSyntax?: CustomSyntax;
626 };
627
628 /** @internal */
629 export type GetLintSourceOptions = GetPostcssOptions & {
630 existingPostcssResult?: PostCSS.Result;
631 cache?: boolean;
632 };
633
634 /**
635 * Linter options.
636 */
637 export type LinterOptions = {
638 files?: OneOrMany<string>;
639 globbyOptions?: GlobbyOptions;
640 cache?: boolean;
641 cacheLocation?: string;
642 cacheStrategy?: string;
643 code?: string;
644 codeFilename?: string;
645 config?: Config;
646 configFile?: string;
647 configBasedir?: string;
648 /**
649 * The working directory to resolve files from. Defaults to the
650 * current working directory.
651 */
652 cwd?: string;
653 ignoreDisables?: boolean;
654 ignorePath?: OneOrMany<string>;
655 ignorePattern?: string[];
656 reportDescriptionlessDisables?: boolean;
657 reportNeedlessDisables?: boolean;
658 reportInvalidScopeDisables?: boolean;
659 reportUnscopedDisables?: boolean;
660 maxWarnings?: number;
661 customSyntax?: CustomSyntax;
662 /** @internal */
663 _defaultFormatter?: FormatterType;
664 formatter?: FormatterType | Formatter;
665 disableDefaultIgnores?: boolean;
666 fix?: boolean;
667 allowEmptyInput?: boolean;
668 quiet?: boolean;
669 quietDeprecationWarnings?: boolean;
670 validate?: boolean;
671 };
672
673 /**
674 * A CSS syntax error.
675 */
676 export type CssSyntaxError = {
677 file?: string;
678 input: {
679 column: number;
680 file?: string;
681 line: number;
682 source: string;
683 };
684 /**
685 * The line of the inclusive start position of the error.
686 */
687 line: number;
688 /**
689 * The column of the inclusive start position of the error.
690 */
691 column: number;
692 /**
693 * The line of the exclusive end position of the error.
694 */
695 endLine?: number;
696 /**
697 * The column of the exclusive end position of the error.
698 */
699 endColumn?: number;
700 message: string;
701 name: string;
702 reason: string;
703 source: string;
704 };
705
706 /**
707 * A lint warning.
708 */
709 export type Warning = {
710 /**
711 * The line of the inclusive start position of the warning.
712 */
713 line: number;
714 /**
715 * The column of the inclusive start position of the warning.
716 */
717 column: number;
718 /**
719 * The line of the exclusive end position of the warning.
720 */
721 endLine?: number;
722 /**
723 * The column of the exclusive end position of the warning.
724 */
725 endColumn?: number;
726 rule: string;
727 severity: Severity;
728 text: string;
729 url?: string;
730 stylelintType?: StylelintWarningType;
731 };
732
733 /**
734 * A lint result.
735 */
736 export type LintResult = {
737 source?: string;
738 deprecations: {
739 text: string;
740 reference?: string;
741 }[];
742 invalidOptionWarnings: {
743 text: string;
744 }[];
745 parseErrors: (PostCSS.Warning & {
746 stylelintType: Extract<StylelintWarningType, 'parseError'>;
747 })[];
748 errored?: boolean;
749 warnings: Warning[];
750 ignored?: boolean;
751 /**
752 * Internal use only. Do not use or rely on this property. It may
753 * change at any time.
754 * @internal
755 */
756 _postcssResult?: PostcssResult;
757 };
758
759 /** @internal */
760 export type DisableReportRange = {
761 rule: string;
762 start: number;
763 end?: number;
764 };
765
766 /**
767 * A linter result.
768 */
769 export type LinterResult = {
770 /**
771 * The working directory from which the linter was run when the
772 * results were generated.
773 */
774 cwd: string;
775 results: LintResult[];
776 errored: boolean;
777 /**
778 * @deprecated Use `report` for the formatted problems, or use `code`
779 * for the autofixed code instead. This will be removed in the next major version.
780 */
781 output: string;
782 /** @internal To show the deprecation warning. */
783 _output?: string;
784 /** @internal To show the deprecation warning. */
785 _outputWarned?: boolean;
786 /**
787 * A string that contains the formatted problems.
788 */
789 report: string;
790 /**
791 * A string that contains the autofixed code, if the `fix` option is set to `true`
792 * and the `code` option is provided.
793 */
794 code?: string;
795 maxWarningsExceeded?: {
796 maxWarnings: number;
797 foundWarnings: number;
798 };
799 reportedDisables: DisableOptionsReport;
800 descriptionlessDisables?: DisableOptionsReport;
801 needlessDisables?: DisableOptionsReport;
802 invalidScopeDisables?: DisableOptionsReport;
803 /**
804 * Each rule metadata by name.
805 */
806 ruleMetadata: { [ruleName: string]: Partial<RuleMeta> };
807 };
808
809 type Position = {
810 line: number;
811 column: number;
812 };
813
814 /**
815 * A lint problem.
816 */
817 export type Problem = {
818 ruleName: string;
819 result: PostcssResult;
820 message: RuleMessage;
821 messageArgs?: Parameters<RuleMessageFunc> | undefined;
822 node: PostCSS.Node;
823 /**
824 * The inclusive start index of the problem, relative to the node's
825 * source text.
826 */
827 index?: number;
828 /**
829 * The exclusive end index of the problem, relative to the node's
830 * source text.
831 */
832 endIndex?: number;
833 /**
834 * The inclusive start position of the problem, relative to the
835 * node's source text. If provided, this will be used instead of
836 * `index`.
837 */
838 start?: Position;
839 /**
840 * The exclusive end position of the problem, relative to the
841 * node's source text. If provided, this will be used instead of
842 * `endIndex`.
843 */
844 end?: Position;
845 word?: string;
846 line?: number;
847 /**
848 * Optional severity override for the problem.
849 */
850 severity?: RuleSeverity;
851 fix?: () => void | undefined | never;
852 };
853
854 /** @internal */
855 export type ShorthandProperties =
856 | 'animation'
857 | 'background'
858 | 'border'
859 | 'border-block'
860 | 'border-block-end'
861 | 'border-block-start'
862 | 'border-inline'
863 | 'border-inline-end'
864 | 'border-inline-start'
865 | 'border-bottom'
866 | 'border-color'
867 | 'border-image'
868 | 'border-inline-end'
869 | 'border-inline-start'
870 | 'border-left'
871 | 'border-radius'
872 | 'border-right'
873 | 'border-style'
874 | 'border-top'
875 | 'border-width'
876 | 'column-rule'
877 | 'columns'
878 | 'flex'
879 | 'flex-flow'
880 | 'font'
881 | 'font-synthesis'
882 | 'font-variant'
883 | 'gap'
884 | 'grid'
885 | 'grid-area'
886 | 'grid-column'
887 | 'grid-gap'
888 | 'grid-row'
889 | 'grid-template'
890 | 'inset'
891 | 'inset-block'
892 | 'inset-inline'
893 | 'list-style'
894 | 'margin'
895 | 'margin-block'
896 | 'margin-inline'
897 | 'mask'
898 | 'outline'
899 | 'overflow'
900 | 'overscroll-behavior'
901 | 'padding'
902 | 'padding-block'
903 | 'padding-inline'
904 | 'place-content'
905 | 'place-items'
906 | 'place-self'
907 | 'scroll-margin'
908 | 'scroll-margin-block'
909 | 'scroll-margin-inline'
910 | 'scroll-padding'
911 | 'scroll-padding-block'
912 | 'scroll-padding-inline'
913 | 'text-decoration'
914 | 'text-emphasis'
915 | 'transition';
916
917 /** @internal */
918 export type LonghandSubPropertiesOfShorthandProperties = ReadonlyMap<
919 ShorthandProperties,
920 ReadonlySet<string>
921 >;
922
923 /**
924 * Utility functions.
925 */
926 export type Utils = {
927 /**
928 * Report a problem.
929 *
930 * This function accounts for `disabledRanges` attached to the result.
931 * That is, if the reported problem is within a disabledRange,
932 * it is ignored. Otherwise, it is attached to the result as a
933 * postcss warning.
934 *
935 * It also accounts for the rule's severity.
936 *
937 * You *must* pass *either* a node or a line number.
938 *
939 * @param problem - A problem
940 */
941 report: (problem: Problem) => void;
942
943 /**
944 * Given an object of problem messages, return another
945 * that provides the same messages postfixed with the rule
946 * that has been violated.
947 *
948 * @param ruleName - A rule name
949 * @param messages - An object whose keys are message identifiers
950 * and values are either message strings or functions that return message strings
951 * @returns New message object, whose messages will be marked with the rule name
952 */
953 ruleMessages: <T extends RuleMessages, R extends { [K in keyof T]: T[K] }>(
954 ruleName: string,
955 messages: T,
956 ) => R;
957
958 /**
959 * Validate a rule's options.
960 *
961 * See existing rules for examples.
962 *
963 * @param result - PostCSS result
964 * @param ruleName - A rule name
965 * @param optionDescriptions - Each optionDescription can have the following properties:
966 * - `actual` (required): the actual passed option value or object.
967 * - `possible` (required): a schema representation of what values are
968 * valid for those options. `possible` should be an object if the
969 * options are an object, with corresponding keys; if the options are not an
970 * object, `possible` isn't, either. All `possible` value representations
971 * should be **arrays of either values or functions**. Values are === checked
972 * against `actual`. Functions are fed `actual` as an argument and their
973 * return value is interpreted: truthy = valid, falsy = invalid.
974 * - `optional` (optional): If this is `true`, `actual` can be undefined.
975 * @returns Whether or not the options are valid (`true` = valid)
976 */
977 validateOptions: (
978 result: PostcssResult,
979 ruleName: string,
980 ...optionDescriptions: RuleOptions[]
981 ) => boolean;
982
983 /**
984 * Useful for third-party code (e.g. plugins) to run a PostCSS Root
985 * against a specific rule and do something with the warnings.
986 */
987 checkAgainstRule: <T, O extends Object>(
988 options: {
989 ruleName: string;
990 ruleSettings: ConfigRuleSettings<T, O>;
991 root: PostCSS.Root;
992 result?: PostcssResult;
993 context?: RuleContext;
994 },
995 callback: (warning: PostCSS.Warning) => void,
996 ) => Promise<void>;
997 };
998
999 /**
1000 * Internal use only. Do not use or rely on this type. It may change at
1001 * any time.
1002 * @internal
1003 */
1004 export type InternalApi = {
1005 _options: LinterOptions & { cwd: string };
1006 _extendExplorer: ReturnType<typeof cosmiconfig>;
1007 _specifiedConfigCache: Map<Config, Map<string, CosmiconfigResult>>;
1008 _postcssResultCache: Map<string, PostCSS.Result>;
1009 _fileCache: FileCache;
1010 };
1011
1012 /** @internal */
1013 export type DisableOptionsReport = DisableReportEntry[];
1014
1015 /** @internal */
1016 export type PostcssPluginOptions = Omit<LinterOptions, 'customSyntax'> | Config;
1017
1018 /**
1019 * The Stylelint public API.
1020 */
1021 export type PublicApi = PostCSS.PluginCreator<PostcssPluginOptions> & {
1022 /**
1023 * Runs Stylelint with the given options and returns a Promise that
1024 * resolves to the results.
1025 *
1026 * @param options - A lint options object
1027 * @returns A lint result
1028 */
1029 lint: (options: LinterOptions) => Promise<LinterResult>;
1030
1031 /**
1032 * Available rules.
1033 */
1034 rules: { readonly [name in keyof CoreRules]: Promise<CoreRules[name]> };
1035
1036 /**
1037 * Result report formatters by name.
1038 */
1039 formatters: Formatters;
1040
1041 /**
1042 * Creates a Stylelint plugin.
1043 */
1044 createPlugin: (ruleName: string, rule: Rule) => Plugin;
1045
1046 /**
1047 * The Stylelint "internal API" is passed among functions
1048 * so that methods on a Stylelint instance can invoke
1049 * each other while sharing options and caches.
1050 *
1051 * @internal
1052 */
1053 _createLinter: (options: LinterOptions) => InternalApi;
1054
1055 /**
1056 * Resolves the effective configuration for a given file. Resolves to
1057 * `undefined` if no config is found.
1058 *
1059 * @param filePath - The path to the file to get the config for.
1060 * @param options - The options to use when creating the Stylelint instance.
1061 * @returns A resolved config or `undefined`.
1062 */
1063 resolveConfig: (
1064 filePath: string,
1065 options?: Pick<LinterOptions, 'cwd' | 'config' | 'configBasedir' | 'configFile'>,
1066 ) => Promise<Config | undefined>;
1067
1068 /**
1069 * Utility functions.
1070 */
1071 utils: Utils;
1072
1073 /**
1074 * Reference objects.
1075 */
1076 reference: {
1077 longhandSubPropertiesOfShorthandProperties: LonghandSubPropertiesOfShorthandProperties;
1078 };
1079 };
1080}
1081
1082declare const stylelint: stylelint.PublicApi;
1083
1084export = stylelint;