UNPKG

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