diff --git a/.changeset/sixty-lions-build.md b/.changeset/sixty-lions-build.md new file mode 100644 index 0000000000..d8d325d077 --- /dev/null +++ b/.changeset/sixty-lions-build.md @@ -0,0 +1,5 @@ +--- +"stylelint": major +--- + +Changed: TypeScript definitions for ESM diff --git a/lib/augmentConfig.cjs b/lib/augmentConfig.cjs index 7df6437e72..7c30a6f471 100644 --- a/lib/augmentConfig.cjs +++ b/lib/augmentConfig.cjs @@ -12,7 +12,6 @@ const getModulePath = require('./utils/getModulePath.cjs'); const normalizeAllRuleSettings = require('./normalizeAllRuleSettings.cjs'); var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('lib/augmentConfig.cjs', document.baseURI).href))); /** @typedef {import('stylelint').InternalApi} StylelintInternalApi */ diff --git a/lib/augmentConfig.mjs b/lib/augmentConfig.mjs index 87d53fbf6f..7654500080 100644 --- a/lib/augmentConfig.mjs +++ b/lib/augmentConfig.mjs @@ -1,5 +1,5 @@ import { createRequire } from 'node:module'; -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. + const require = createRequire(import.meta.url); import { dirname, isAbsolute } from 'node:path'; diff --git a/lib/cli.mjs b/lib/cli.mjs index dc2dfdd401..3c229ea7d6 100644 --- a/lib/cli.mjs +++ b/lib/cli.mjs @@ -3,7 +3,7 @@ import { EOL } from 'node:os'; import process from 'node:process'; import { createRequire } from 'node:module'; -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. + const require = createRequire(import.meta.url); import picocolors from 'picocolors'; @@ -620,7 +620,6 @@ export function buildCLI(argv) { // See also https://github.com/sindresorhus/meow/blob/v12.0.1/source/validate.js#L75 allowUnknownFlags: true, - // @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. importMeta: import.meta, }); } diff --git a/lib/createPlugin.cjs b/lib/createPlugin.cjs index 1888f1a30c..02ce80814c 100644 --- a/lib/createPlugin.cjs +++ b/lib/createPlugin.cjs @@ -3,7 +3,7 @@ 'use strict'; /** - * @type {import('stylelint')['createPlugin']} + * @type {import('stylelint').PublicApi['createPlugin']} */ function createPlugin(ruleName, rule) { return { diff --git a/lib/createPlugin.mjs b/lib/createPlugin.mjs index fc5b650c3f..eab5784b1d 100644 --- a/lib/createPlugin.mjs +++ b/lib/createPlugin.mjs @@ -1,5 +1,5 @@ /** - * @type {import('stylelint')['createPlugin']} + * @type {import('stylelint').PublicApi['createPlugin']} */ export default function createPlugin(ruleName, rule) { return { diff --git a/lib/createStylelint.cjs b/lib/createStylelint.cjs index 8d1b0a5537..da8e207965 100644 --- a/lib/createStylelint.cjs +++ b/lib/createStylelint.cjs @@ -11,7 +11,7 @@ const IS_TEST = process.env.NODE_ENV === 'test'; const STOP_DIR = IS_TEST ? process.cwd() : undefined; /** - * @type {import('stylelint')['_createLinter']} + * @type {import('stylelint').PublicApi['_createLinter']} */ function createStylelint(options = {}) { const cwd = options.cwd || process.cwd(); diff --git a/lib/createStylelint.mjs b/lib/createStylelint.mjs index ae114ec53d..1006cbc009 100644 --- a/lib/createStylelint.mjs +++ b/lib/createStylelint.mjs @@ -9,7 +9,7 @@ const IS_TEST = process.env.NODE_ENV === 'test'; const STOP_DIR = IS_TEST ? process.cwd() : undefined; /** - * @type {import('stylelint')['_createLinter']} + * @type {import('stylelint').PublicApi['_createLinter']} */ export default function createStylelint(options = {}) { const cwd = options.cwd || process.cwd(); diff --git a/lib/formatters/index.cjs b/lib/formatters/index.cjs index d150b53dd8..c28eb07263 100644 --- a/lib/formatters/index.cjs +++ b/lib/formatters/index.cjs @@ -4,7 +4,7 @@ const _interopNamespaceDefaultOnly = e => Object.freeze({ __proto__: null, default: e }); -/** @type {import('stylelint').Formatters} */ +/** @type {import('stylelint').PublicApi['formatters']} */ const formatters = { get compact() { return Promise.resolve().then(() => /*#__PURE__*/_interopNamespaceDefaultOnly(require('./compactFormatter.cjs'))).then((m) => m.default); diff --git a/lib/formatters/index.mjs b/lib/formatters/index.mjs index e1e2144e59..eb527f7e4e 100644 --- a/lib/formatters/index.mjs +++ b/lib/formatters/index.mjs @@ -1,4 +1,4 @@ -/** @type {import('stylelint').Formatters} */ +/** @type {import('stylelint').PublicApi['formatters']} */ const formatters = { get compact() { return import('./compactFormatter.mjs').then((m) => m.default); diff --git a/lib/getPostcssResult.cjs b/lib/getPostcssResult.cjs index 78cebb4ee2..81a4bcc286 100644 --- a/lib/getPostcssResult.cjs +++ b/lib/getPostcssResult.cjs @@ -10,7 +10,6 @@ const postcss = require('postcss'); const getModulePath = require('./utils/getModulePath.cjs'); var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('lib/getPostcssResult.cjs', document.baseURI).href))); /** @typedef {import('postcss').Result} Result */ diff --git a/lib/getPostcssResult.mjs b/lib/getPostcssResult.mjs index acdb9b6b1a..8b642bcf73 100644 --- a/lib/getPostcssResult.mjs +++ b/lib/getPostcssResult.mjs @@ -1,5 +1,5 @@ import { createRequire } from 'node:module'; -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. + const require = createRequire(import.meta.url); import { extname } from 'node:path'; diff --git a/lib/index.cjs b/lib/index.cjs index c9a8fc75c7..f7c88e1eb3 100644 --- a/lib/index.cjs +++ b/lib/index.cjs @@ -15,7 +15,7 @@ const index = require('./rules/index.cjs'); const standalone = require('./standalone.cjs'); const validateOptions = require('./utils/validateOptions.cjs'); -/** @type {import('stylelint')} */ +/** @type {import('stylelint').PublicApi} */ const stylelint = Object.assign(postcssPlugin, { lint: standalone, rules: index, diff --git a/lib/index.mjs b/lib/index.mjs index 77841233a9..90eedd906b 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -11,7 +11,7 @@ import rules from './rules/index.mjs'; import standalone from './standalone.mjs'; import validateOptions from './utils/validateOptions.mjs'; -/** @type {import('stylelint')} */ +/** @type {import('stylelint').PublicApi} */ const stylelint = Object.assign(postcssPlugin, { lint: standalone, rules, diff --git a/lib/resolveConfig.cjs b/lib/resolveConfig.cjs index 74e14eeff3..3bf278e205 100644 --- a/lib/resolveConfig.cjs +++ b/lib/resolveConfig.cjs @@ -8,7 +8,7 @@ const createStylelint = require('./createStylelint.cjs'); const getConfigForFile = require('./getConfigForFile.cjs'); /** - * @type {import('stylelint')['resolveConfig']} + * @type {import('stylelint').PublicApi['resolveConfig']} */ async function resolveConfig( filePath, diff --git a/lib/resolveConfig.mjs b/lib/resolveConfig.mjs index 0e0f947ba6..c20feb64a1 100644 --- a/lib/resolveConfig.mjs +++ b/lib/resolveConfig.mjs @@ -5,7 +5,7 @@ import createStylelint from './createStylelint.mjs'; import getConfigForFile from './getConfigForFile.mjs'; /** - * @type {import('stylelint')['resolveConfig']} + * @type {import('stylelint').PublicApi['resolveConfig']} */ export default async function resolveConfig( filePath, diff --git a/lib/resolveCustomFormatter.cjs b/lib/resolveCustomFormatter.cjs index 17728ccf86..b189dd9b04 100644 --- a/lib/resolveCustomFormatter.cjs +++ b/lib/resolveCustomFormatter.cjs @@ -7,7 +7,6 @@ const node_fs = require('node:fs'); const node_path = require('node:path'); var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('lib/resolveCustomFormatter.cjs', document.baseURI).href))); /** diff --git a/lib/resolveCustomFormatter.mjs b/lib/resolveCustomFormatter.mjs index 044d554725..c5155ff2da 100644 --- a/lib/resolveCustomFormatter.mjs +++ b/lib/resolveCustomFormatter.mjs @@ -1,5 +1,5 @@ import { createRequire } from 'node:module'; -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. + const require = createRequire(import.meta.url); import { existsSync } from 'node:fs'; diff --git a/lib/rules/color-named/colordUtils.cjs b/lib/rules/color-named/colordUtils.cjs index 692ed13752..c1d78feb85 100644 --- a/lib/rules/color-named/colordUtils.cjs +++ b/lib/rules/color-named/colordUtils.cjs @@ -33,7 +33,8 @@ const colord = colord$1.colord; /** * Parses a valid hwb with comma CSS color function * https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hwb()#syntax - * @type {import('colord/types').ParseFunction} + * @param {string} input + * @returns {import('colord').RgbaColor | null} */ function parseHwbWithCommaString(input) { input = input.toLowerCase(); @@ -62,7 +63,8 @@ function parseHwbWithCommaString(input) { /** * Parses a valid gray() CSS color function - * @type {import('colord/types').ParseFunction} + * @param {string} input + * @returns {import('colord').RgbaColor | null} */ function parseGrayString(input) { input = input.toLowerCase(); @@ -84,7 +86,7 @@ function parseGrayString(input) { } /** - * @type {import('colord/types').LabColor | import('colord/types').LabaColor} + * @type {import('colord').LabColor | import('colord').LabaColor} */ let colorObject = { l: Number(lightnessWithUnit.number), diff --git a/lib/rules/color-named/colordUtils.mjs b/lib/rules/color-named/colordUtils.mjs index cc3b79c271..ea68dbeae0 100644 --- a/lib/rules/color-named/colordUtils.mjs +++ b/lib/rules/color-named/colordUtils.mjs @@ -31,7 +31,8 @@ export const colord = colord_; /** * Parses a valid hwb with comma CSS color function * https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hwb()#syntax - * @type {import('colord/types').ParseFunction} + * @param {string} input + * @returns {import('colord').RgbaColor | null} */ function parseHwbWithCommaString(input) { input = input.toLowerCase(); @@ -60,7 +61,8 @@ function parseHwbWithCommaString(input) { /** * Parses a valid gray() CSS color function - * @type {import('colord/types').ParseFunction} + * @param {string} input + * @returns {import('colord').RgbaColor | null} */ function parseGrayString(input) { input = input.toLowerCase(); @@ -82,7 +84,7 @@ function parseGrayString(input) { } /** - * @type {import('colord/types').LabColor | import('colord/types').LabaColor} + * @type {import('colord').LabColor | import('colord').LabaColor} */ let colorObject = { l: Number(lightnessWithUnit.number), diff --git a/lib/rules/index.cjs b/lib/rules/index.cjs index 8fd8323ac7..4657fed286 100644 --- a/lib/rules/index.cjs +++ b/lib/rules/index.cjs @@ -4,7 +4,7 @@ const _interopNamespaceDefaultOnly = e => Object.freeze({ __proto__: null, default: e }); -/** @type {import('stylelint').BuiltInRules} */ +/** @type {import('stylelint').PublicApi['rules']} */ const rules = { get 'alpha-value-notation'() { return Promise.resolve().then(() => /*#__PURE__*/_interopNamespaceDefaultOnly(require('./alpha-value-notation/index.cjs'))).then((m) => m.default); diff --git a/lib/rules/index.mjs b/lib/rules/index.mjs index ca2d4ed0d3..18cc80d0c5 100644 --- a/lib/rules/index.mjs +++ b/lib/rules/index.mjs @@ -1,4 +1,4 @@ -/** @type {import('stylelint').BuiltInRules} */ +/** @type {import('stylelint').PublicApi['rules']} */ const rules = { get 'alpha-value-notation'() { return import('./alpha-value-notation/index.mjs').then((m) => m.default); diff --git a/lib/standalone.cjs b/lib/standalone.cjs index 7d1c88a471..6dfaa0f08d 100644 --- a/lib/standalone.cjs +++ b/lib/standalone.cjs @@ -31,7 +31,7 @@ const ALWAYS_IGNORED_GLOBS = ['**/node_modules/**']; /** @typedef {import('stylelint').FormatterType} FormatterType */ /** - * @type {import('stylelint')['lint']} + * @type {import('stylelint').PublicApi['lint']} */ async function standalone({ allowEmptyInput, diff --git a/lib/standalone.mjs b/lib/standalone.mjs index d4d1c58596..15ae15c143 100644 --- a/lib/standalone.mjs +++ b/lib/standalone.mjs @@ -29,7 +29,7 @@ const ALWAYS_IGNORED_GLOBS = ['**/node_modules/**']; /** @typedef {import('stylelint').FormatterType} FormatterType */ /** - * @type {import('stylelint')['lint']} + * @type {import('stylelint').PublicApi['lint']} */ export default async function standalone({ allowEmptyInput, diff --git a/lib/utils/FileCache.cjs b/lib/utils/FileCache.cjs index d5899ea265..cb151601e9 100644 --- a/lib/utils/FileCache.cjs +++ b/lib/utils/FileCache.cjs @@ -13,7 +13,7 @@ const hash = require('./hash.cjs'); var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; const debug = createDebug('stylelint:file-cache'); -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. + const pkg = JSON.parse(node_fs.readFileSync(new URL('../../package.json', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('lib/utils/FileCache.cjs', document.baseURI).href))), 'utf8')); /** @typedef {import('file-entry-cache').FileDescriptor["meta"] & { hashOfConfig?: string }} CacheMetadata */ diff --git a/lib/utils/FileCache.mjs b/lib/utils/FileCache.mjs index 3645da5252..f1def0b9af 100644 --- a/lib/utils/FileCache.mjs +++ b/lib/utils/FileCache.mjs @@ -15,7 +15,7 @@ import getCacheFile from './getCacheFile.mjs'; import hash from './hash.mjs'; const debug = createDebug('stylelint:file-cache'); -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. + const pkg = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')); /** @typedef {import('file-entry-cache').FileDescriptor["meta"] & { hashOfConfig?: string }} CacheMetadata */ diff --git a/lib/utils/mathMLTags.cjs b/lib/utils/mathMLTags.cjs index cd4ec5e035..e10fa188b1 100644 --- a/lib/utils/mathMLTags.cjs +++ b/lib/utils/mathMLTags.cjs @@ -5,7 +5,6 @@ const node_module = require('node:module'); var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext' const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('lib/utils/mathMLTags.cjs', document.baseURI).href))); // NOTE: mathml-tag-names v3 is a pure ESM package, @@ -13,6 +12,7 @@ const require$1 = node_module.createRequire((typeof document === 'undefined' ? r // // In addition, mathml-tag-names v2 provides only a JSON file, // so ESM cannot import it (raises the "ERR_IMPORT_ASSERTION_TYPE_MISSING" error). +// @ts-expect-error -- mathml-tag-names v2 doesn't have type declarations. const mathMLTags = require$1('mathml-tag-names'); module.exports = mathMLTags; diff --git a/lib/utils/mathMLTags.mjs b/lib/utils/mathMLTags.mjs index f7b5728ad0..3cdb699d71 100644 --- a/lib/utils/mathMLTags.mjs +++ b/lib/utils/mathMLTags.mjs @@ -1,6 +1,5 @@ import { createRequire } from 'node:module'; -// @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext' const require = createRequire(import.meta.url); // NOTE: mathml-tag-names v3 is a pure ESM package, @@ -8,6 +7,7 @@ const require = createRequire(import.meta.url); // // In addition, mathml-tag-names v2 provides only a JSON file, // so ESM cannot import it (raises the "ERR_IMPORT_ASSERTION_TYPE_MISSING" error). +// @ts-expect-error -- mathml-tag-names v2 doesn't have type declarations. const mathMLTags = require('mathml-tag-names'); export default mathMLTags; diff --git a/package.json b/package.json index 717167bdd5..4a2b4cf991 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,10 @@ "author": "stylelint", "exports": { ".": { - "import": "./lib/index.mjs", + "import": { + "types": "./types/stylelint/index.d.ts", + "default": "./lib/index.mjs" + }, "require": "./lib/index.cjs" }, "./package.json": "./package.json", diff --git a/patches/is-plain-object+5.0.0.patch b/patches/is-plain-object+5.0.0.patch new file mode 100644 index 0000000000..6446583973 --- /dev/null +++ b/patches/is-plain-object+5.0.0.patch @@ -0,0 +1,16 @@ +diff --git a/node_modules/is-plain-object/package.json b/node_modules/is-plain-object/package.json +index 3ea169a..622dff4 100644 +--- a/node_modules/is-plain-object/package.json ++++ b/node_modules/is-plain-object/package.json +@@ -25,7 +25,10 @@ + ], + "exports": { + ".": { +- "import": "./dist/is-plain-object.mjs", ++ "import": { ++ "types": "./is-plain-object.d.ts", ++ "default": "./dist/is-plain-object.mjs" ++ }, + "require": "./dist/is-plain-object.js" + }, + "./package.json": "./package.json" diff --git a/tsconfig.json b/tsconfig.json index 3eb5d80922..2d5deb261c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,9 @@ { "compilerOptions": { - "target": "ES2021", - "module": "commonjs", - "lib": ["ES2021", "DOM"], + "module": "Node16", + "moduleResolution": "Node16", + "target": "ES2022", + "lib": ["ES2022"], "checkJs": true, "noEmit": true, "strict": true, @@ -12,13 +13,13 @@ "noImplicitReturns": false, "noUnusedParameters": true, "noUncheckedIndexedAccess": true, - "resolveJsonModule": true, + "resolveJsonModule": false, "esModuleInterop": true, "skipLibCheck": false, "paths": { - "*": ["./node_modules/@types/*", "./types/*"] + "stylelint": ["./types/stylelint/index.d.ts"] } }, - "include": ["lib", "types", "package.json"], - "exclude": ["**/*.test.{js,mjs}", "**/__tests__/", "lib/**/*.cjs"] + "include": ["lib/**/*.mjs", "types/**/*.ts"], + "exclude": ["**/__tests__/**"] } diff --git a/types/stylelint/index.d.ts b/types/stylelint/index.d.ts index ce8d8623fb..0704300364 100644 --- a/types/stylelint/index.d.ts +++ b/types/stylelint/index.d.ts @@ -3,17 +3,20 @@ import type { GlobbyOptions } from 'globby'; import type { cosmiconfig, TransformSync as CosmiconfigTransformSync } from 'cosmiconfig'; type ConfigExtends = string | string[]; -type ConfigPlugins = string | stylelint.Plugin | (string | stylelint.Plugin)[]; + +type ConfigPlugins = string | Plugin | (string | Plugin)[]; + type ConfigIgnoreFiles = string | string[]; type ConfigRules = { - [ruleName: string]: stylelint.ConfigRuleSettings; + [ruleName: string]: ConfigRuleSettings; }; -type ConfigOverride = Omit & { + +type ConfigOverride = Omit & { files: string | string[]; }; -type DisableSettings = stylelint.ConfigRuleSettings; +type DisableSettings = ConfigRuleSettings; // A meta-type that returns a union over all properties of `T` whose values // have type `U`. @@ -22,7 +25,7 @@ type PropertyNamesOfType = { }[keyof T]; type FileCache = { - calcHashOfConfig: (config: stylelint.Config) => void; + calcHashOfConfig: (config: Config) => void; hasFileChanged: (absoluteFilepath: string) => boolean; reconcile: () => void; destroy: () => void; @@ -54,714 +57,717 @@ type RuleMessageFunc = { }['bivariance']; type RuleSeverityFunc = { - bivariance(...args: (string | number | boolean | RegExp)[]): stylelint.Severity | null; + bivariance(...args: (string | number | boolean | RegExp)[]): Severity | null; }['bivariance']; type RuleOptionsPossibleFunc = (value: unknown) => boolean; type DisableReportEntry = { source?: string; - ranges: stylelint.DisableReportRange[]; + ranges: DisableReportRange[]; }; -declare namespace stylelint { - /** - * Rule severity. - */ - type Severity = 'warning' | 'error'; +/** + * Rule severity. + */ +export type Severity = 'warning' | 'error'; + +/** + * A Stylelint plugin. + */ +export type Plugin = + | { default?: { ruleName: string; rule: Rule } } + | { ruleName: string; rule: Rule }; + +/** @internal */ +export type ConfigRuleSettings = + | null + | undefined + | NonNullable + | [NonNullable] + | [NonNullable, O]; + +/** @internal */ +export type DisableOptions = { + except?: (string | RegExp)[]; + severity?: Severity; +}; - /** - * A Stylelint plugin. - */ - type Plugin = { default?: { ruleName: string; rule: Rule } } | { ruleName: string; rule: Rule }; +/** + * Configuration. + */ +export type Config = { + extends?: ConfigExtends; + plugins?: ConfigPlugins; + pluginFunctions?: { + [pluginName: string]: Rule; + }; + ignoreFiles?: ConfigIgnoreFiles; + ignorePatterns?: string; + rules?: ConfigRules; + quiet?: boolean; + defaultSeverity?: Severity; + ignoreDisables?: DisableSettings; + reportNeedlessDisables?: DisableSettings; + reportInvalidScopeDisables?: DisableSettings; + reportDescriptionlessDisables?: DisableSettings; + configurationComment?: string; + overrides?: ConfigOverride[]; + customSyntax?: CustomSyntax; + allowEmptyInput?: boolean; + cache?: boolean; + fix?: boolean; +}; - /** @internal */ - type ConfigRuleSettings = - | null - | undefined - | NonNullable - | [NonNullable] - | [NonNullable, O]; +/** @internal */ +export type DisablePropertyName = PropertyNamesOfType; + +/** @internal */ +export type CosmiconfigResult = (ReturnType & { config: Config }) | null; + +/** @internal */ +export type DisabledRange = { + comment: PostCSS.Comment; + start: number; + strictStart: boolean; + end?: number; + strictEnd?: boolean; + rules?: string[]; + description?: string; +}; - /** @internal */ - type DisableOptions = { - except?: (string | RegExp)[]; - severity?: Severity; - }; +/** @internal */ +export type DisabledRangeObject = { + [ruleName: string]: DisabledRange[]; +}; - /** - * Configuration. - */ - type Config = { - extends?: ConfigExtends; - plugins?: ConfigPlugins; - pluginFunctions?: { - [pluginName: string]: Rule; - }; - ignoreFiles?: ConfigIgnoreFiles; - ignorePatterns?: string; - rules?: ConfigRules; - quiet?: boolean; - defaultSeverity?: Severity; - ignoreDisables?: DisableSettings; - reportNeedlessDisables?: DisableSettings; - reportInvalidScopeDisables?: DisableSettings; - reportDescriptionlessDisables?: DisableSettings; - configurationComment?: string; - overrides?: ConfigOverride[]; - customSyntax?: CustomSyntax; - allowEmptyInput?: boolean; - cache?: boolean; - fix?: boolean; - }; +/** @internal */ +export type DisabledWarning = { line: number; rule: string }; + +/** @internal */ +export type StylelintPostcssResult = { + ruleSeverities: { [ruleName: string]: RuleSeverity }; + customMessages: { [ruleName: string]: RuleMessage }; + ruleMetadata: { [ruleName: string]: Partial }; + quiet?: boolean; + disabledRanges: DisabledRangeObject; + disabledWarnings?: DisabledWarning[]; + ignored?: boolean; + stylelintError?: boolean; + stylelintWarning?: boolean; + disableWritingFix?: boolean; + config?: Config; +}; - /** @internal */ - type DisablePropertyName = PropertyNamesOfType; - - /** @internal */ - type CosmiconfigResult = (ReturnType & { config: Config }) | null; - - /** @internal */ - type DisabledRange = { - comment: PostCSS.Comment; - start: number; - strictStart: boolean; - end?: number; - strictEnd?: boolean; - rules?: string[]; - description?: string; - }; +/** @internal */ +export type WarningOptions = PostCSS.WarningOptions & { + stylelintType?: string; + severity?: Severity; + rule?: string; +}; - /** @internal */ - type DisabledRangeObject = { - [ruleName: string]: DisabledRange[]; - }; +/** @internal */ +export type PostcssResult = (PostCSS.Result | EmptyResult) & { + stylelint: StylelintPostcssResult; + warn(message: string, options?: WarningOptions): void; +}; - /** @internal */ - type DisabledWarning = { line: number; rule: string }; - - /** @internal */ - type StylelintPostcssResult = { - ruleSeverities: { [ruleName: string]: RuleSeverity }; - customMessages: { [ruleName: string]: RuleMessage }; - ruleMetadata: { [ruleName: string]: Partial }; - quiet?: boolean; - disabledRanges: DisabledRangeObject; - disabledWarnings?: DisabledWarning[]; - ignored?: boolean; - stylelintError?: boolean; - stylelintWarning?: boolean; - disableWritingFix?: boolean; - config?: Config; - }; +/** @internal */ +export type Formatter = (results: LintResult[], returnValue: LinterResult) => string; + +type Formatters = { + readonly compact: Promise; + readonly github: Promise; + readonly json: Promise; + readonly string: Promise; + readonly tap: Promise; + readonly unix: Promise; + readonly verbose: Promise; +}; - /** @internal */ - type WarningOptions = PostCSS.WarningOptions & { - stylelintType?: string; - severity?: Severity; - rule?: string; - }; +/** @internal */ +export type FormatterType = keyof Formatters; - /** @internal */ - type PostcssResult = (PostCSS.Result | EmptyResult) & { - stylelint: StylelintPostcssResult; - warn(message: string, options?: WarningOptions): void; - }; +/** @internal */ +export type CustomSyntax = string | PostCSS.Syntax; - /** @internal */ - type Formatter = (results: LintResult[], returnValue: LinterResult) => string; - - /** @internal */ - type Formatters = { - readonly compact: Promise; - readonly github: Promise; - readonly json: Promise; - readonly string: Promise; - readonly tap: Promise; - readonly unix: Promise; - readonly verbose: Promise; - }; +/** @internal */ +export type RuleMessage = string | RuleMessageFunc; - /** @internal */ - type FormatterType = keyof Formatters; +/** @internal */ +export type RuleMessages = { [message: string]: RuleMessage }; - /** @internal */ - type CustomSyntax = string | PostCSS.Syntax; +/** @internal */ +export type RuleOptionsPossible = boolean | number | string | RuleOptionsPossibleFunc; - /** @internal */ - type RuleMessage = string | RuleMessageFunc; +/** @internal */ +export type RuleOptions = { + actual: unknown; + possible?: + | RuleOptionsPossibleFunc + | RuleOptionsPossible[] + | Record; + optional?: boolean; +}; - /** @internal */ - type RuleMessages = { [message: string]: RuleMessage }; +/** @internal */ +type RuleSeverity = Severity | RuleSeverityFunc; - /** @internal */ - type RuleOptionsPossible = boolean | number | string | RuleOptionsPossibleFunc; +/** + * A rule context. + */ +export type RuleContext = { + configurationComment?: string | undefined; + fix?: boolean | undefined; + newline?: string | undefined; +}; - /** @internal */ - type RuleOptions = { - actual: unknown; - possible?: - | RuleOptionsPossibleFunc - | RuleOptionsPossible[] - | Record; - optional?: boolean; - }; +/** @internal */ +export type RuleBase

= ( + primaryOption: P, + secondaryOptions: Record, + context: RuleContext, +) => (root: PostCSS.Root, result: PostcssResult) => Promise | void; + +/** @internal */ +export type RuleMeta = { + url: string; + deprecated?: boolean; + fixable?: boolean; +}; + +/** + * A rule. + */ +export type Rule

= RuleBase & { + ruleName: string; + messages: RuleMessages; + primaryOptionArray?: boolean; + meta?: RuleMeta; +}; + +type BuiltInRules = { + readonly 'alpha-value-notation': Promise; + readonly 'annotation-no-unknown': Promise; + readonly 'at-rule-allowed-list': Promise; + readonly 'at-rule-disallowed-list': Promise; + readonly 'at-rule-empty-line-before': Promise; + readonly 'at-rule-no-unknown': Promise; + readonly 'at-rule-no-vendor-prefix': Promise; + readonly 'at-rule-property-required-list': Promise; + readonly 'block-no-empty': Promise; + readonly 'color-function-notation': Promise; + readonly 'color-hex-alpha': Promise; + readonly 'color-hex-length': Promise; + readonly 'color-named': Promise; + readonly 'color-no-hex': Promise; + readonly 'color-no-invalid-hex': Promise; + readonly 'comment-empty-line-before': Promise; + readonly 'comment-no-empty': Promise; + readonly 'comment-pattern': Promise; + readonly 'comment-whitespace-inside': Promise; + readonly 'comment-word-disallowed-list': Promise; + readonly 'custom-media-pattern': Promise; + readonly 'custom-property-empty-line-before': Promise; + readonly 'custom-property-no-missing-var-function': Promise; + readonly 'custom-property-pattern': Promise; + readonly 'declaration-block-no-duplicate-custom-properties': Promise; + readonly 'declaration-block-no-duplicate-properties': Promise; + readonly 'declaration-block-no-redundant-longhand-properties': Promise; + readonly 'declaration-block-no-shorthand-property-overrides': Promise; + readonly 'declaration-block-single-line-max-declarations': Promise; + readonly 'declaration-empty-line-before': Promise; + readonly 'declaration-no-important': Promise; + readonly 'declaration-property-max-values': Promise; + readonly 'declaration-property-unit-allowed-list': Promise; + readonly 'declaration-property-unit-disallowed-list': Promise; + readonly 'declaration-property-value-allowed-list': Promise; + readonly 'declaration-property-value-disallowed-list': Promise; + readonly 'declaration-property-value-no-unknown': Promise; + readonly 'font-family-name-quotes': Promise; + readonly 'font-family-no-duplicate-names': Promise; + readonly 'font-family-no-missing-generic-family-keyword': Promise; + readonly 'font-weight-notation': Promise; + readonly 'function-allowed-list': Promise; + readonly 'function-calc-no-unspaced-operator': Promise; + readonly 'function-disallowed-list': Promise; + readonly 'function-linear-gradient-no-nonstandard-direction': Promise; + readonly 'function-name-case': Promise; + readonly 'function-no-unknown': Promise; + readonly 'function-url-no-scheme-relative': Promise; + readonly 'function-url-quotes': Promise; + readonly 'function-url-scheme-allowed-list': Promise; + readonly 'function-url-scheme-disallowed-list': Promise; + readonly 'hue-degree-notation': Promise; + readonly 'import-notation': Promise; + readonly 'keyframe-block-no-duplicate-selectors': Promise; + readonly 'keyframe-declaration-no-important': Promise; + readonly 'keyframe-selector-notation': Promise; + readonly 'keyframes-name-pattern': Promise; + readonly 'length-zero-no-unit': Promise; + readonly 'max-nesting-depth': Promise; + readonly 'media-feature-name-allowed-list': Promise; + readonly 'media-feature-name-disallowed-list': Promise; + readonly 'media-feature-name-no-unknown': Promise; + readonly 'media-feature-name-no-vendor-prefix': Promise; + readonly 'media-feature-name-unit-allowed-list': Promise; + readonly 'media-feature-name-value-allowed-list': Promise; + readonly 'media-feature-name-value-no-unknown': Promise; + readonly 'media-feature-range-notation': Promise; + readonly 'media-query-no-invalid': Promise; + readonly 'named-grid-areas-no-invalid': Promise; + readonly 'no-descending-specificity': Promise; + readonly 'no-duplicate-at-import-rules': Promise; + readonly 'no-duplicate-selectors': Promise; + readonly 'no-empty-source': Promise; + readonly 'no-invalid-double-slash-comments': Promise; + readonly 'no-invalid-position-at-import-rule': Promise; + readonly 'no-irregular-whitespace': Promise; + readonly 'no-unknown-animations': Promise; + readonly 'no-unknown-custom-properties': Promise; + readonly 'number-max-precision': Promise; + readonly 'property-allowed-list': Promise; + readonly 'property-disallowed-list': Promise; + readonly 'property-no-unknown': Promise; + readonly 'property-no-vendor-prefix': Promise; + readonly 'rule-empty-line-before': Promise; + readonly 'rule-selector-property-disallowed-list': Promise; + readonly 'selector-anb-no-unmatchable': Promise; + readonly 'selector-attribute-name-disallowed-list': Promise; + readonly 'selector-attribute-operator-allowed-list': Promise; + readonly 'selector-attribute-operator-disallowed-list': Promise; + readonly 'selector-attribute-quotes': Promise; + readonly 'selector-class-pattern': Promise; + readonly 'selector-combinator-allowed-list': Promise; + readonly 'selector-combinator-disallowed-list': Promise; + readonly 'selector-disallowed-list': Promise; + readonly 'selector-id-pattern': Promise; + readonly 'selector-max-attribute': Promise; + readonly 'selector-max-class': Promise; + readonly 'selector-max-combinators': Promise; + readonly 'selector-max-compound-selectors': Promise; + readonly 'selector-max-id': Promise; + readonly 'selector-max-pseudo-class': Promise; + readonly 'selector-max-specificity': Promise; + readonly 'selector-max-type': Promise; + readonly 'selector-max-universal': Promise; + readonly 'selector-nested-pattern': Promise; + readonly 'selector-no-qualifying-type': Promise; + readonly 'selector-no-vendor-prefix': Promise; + readonly 'selector-not-notation': Promise; + readonly 'selector-pseudo-class-allowed-list': Promise; + readonly 'selector-pseudo-class-disallowed-list': Promise; + readonly 'selector-pseudo-class-no-unknown': Promise; + readonly 'selector-pseudo-element-allowed-list': Promise; + readonly 'selector-pseudo-element-colon-notation': Promise; + readonly 'selector-pseudo-element-disallowed-list': Promise; + readonly 'selector-pseudo-element-no-unknown': Promise; + readonly 'selector-type-case': Promise; + readonly 'selector-type-no-unknown': Promise; + readonly 'shorthand-property-no-redundant-values': Promise; + readonly 'string-no-newline': Promise; + readonly 'time-min-milliseconds': Promise; + readonly 'unit-allowed-list': Promise; + readonly 'unit-disallowed-list': Promise; + readonly 'unit-no-unknown': Promise; + readonly 'value-keyword-case': Promise; + readonly 'value-no-vendor-prefix': Promise; +}; + +/** @internal */ +export type GetPostcssOptions = { + code?: string; + codeFilename?: string; + filePath?: string; + customSyntax?: CustomSyntax; +}; - /** @internal */ - type RuleSeverity = Severity | RuleSeverityFunc; +/** @internal */ +export type GetLintSourceOptions = GetPostcssOptions & { + existingPostcssResult?: PostCSS.Result; + cache?: boolean; +}; +/** + * Linter options. + */ +export type LinterOptions = { + files?: string | string[]; + globbyOptions?: GlobbyOptions; + cache?: boolean; + cacheLocation?: string; + cacheStrategy?: string; + code?: string; + codeFilename?: string; + config?: Config; + configFile?: string; + configBasedir?: string; /** - * A rule context. + * The working directory to resolve files from. Defaults to the + * current working directory. */ - type RuleContext = { - configurationComment?: string | undefined; - fix?: boolean | undefined; - newline?: string | undefined; - }; + cwd?: string; + ignoreDisables?: boolean; + ignorePath?: string | string[]; + ignorePattern?: string[]; + reportDescriptionlessDisables?: boolean; + reportNeedlessDisables?: boolean; + reportInvalidScopeDisables?: boolean; + maxWarnings?: number; + customSyntax?: CustomSyntax; + formatter?: FormatterType | Formatter; + disableDefaultIgnores?: boolean; + fix?: boolean; + allowEmptyInput?: boolean; + quiet?: boolean; + quietDeprecationWarnings?: boolean; +}; - /** @internal */ - type RuleBase

= ( - primaryOption: P, - secondaryOptions: Record, - context: RuleContext, - ) => (root: PostCSS.Root, result: PostcssResult) => Promise | void; - - /** @internal */ - type RuleMeta = { - url: string; - deprecated?: boolean; - fixable?: boolean; +/** + * A CSS syntax error. + */ +export type CssSyntaxError = { + file?: string; + input: { + column: number; + file?: string; + line: number; + source: string; }; - /** - * A rule. + * The line of the inclusive start position of the error. */ - type Rule

= RuleBase & { - ruleName: string; - messages: RuleMessages; - primaryOptionArray?: boolean; - meta?: RuleMeta; - }; + line: number; + /** + * The column of the inclusive start position of the error. + */ + column: number; + /** + * The line of the exclusive end position of the error. + */ + endLine?: number; + /** + * The column of the exclusive end position of the error. + */ + endColumn?: number; + message: string; + name: string; + reason: string; + source: string; +}; - /** @internal */ - type BuiltInRules = { - readonly 'alpha-value-notation': Promise; - readonly 'annotation-no-unknown': Promise; - readonly 'at-rule-allowed-list': Promise; - readonly 'at-rule-disallowed-list': Promise; - readonly 'at-rule-empty-line-before': Promise; - readonly 'at-rule-no-unknown': Promise; - readonly 'at-rule-no-vendor-prefix': Promise; - readonly 'at-rule-property-required-list': Promise; - readonly 'block-no-empty': Promise; - readonly 'color-function-notation': Promise; - readonly 'color-hex-alpha': Promise; - readonly 'color-hex-length': Promise; - readonly 'color-named': Promise; - readonly 'color-no-hex': Promise; - readonly 'color-no-invalid-hex': Promise; - readonly 'comment-empty-line-before': Promise; - readonly 'comment-no-empty': Promise; - readonly 'comment-pattern': Promise; - readonly 'comment-whitespace-inside': Promise; - readonly 'comment-word-disallowed-list': Promise; - readonly 'custom-media-pattern': Promise; - readonly 'custom-property-empty-line-before': Promise; - readonly 'custom-property-no-missing-var-function': Promise; - readonly 'custom-property-pattern': Promise; - readonly 'declaration-block-no-duplicate-custom-properties': Promise; - readonly 'declaration-block-no-duplicate-properties': Promise; - readonly 'declaration-block-no-redundant-longhand-properties': Promise; - readonly 'declaration-block-no-shorthand-property-overrides': Promise; - readonly 'declaration-block-single-line-max-declarations': Promise; - readonly 'declaration-empty-line-before': Promise; - readonly 'declaration-no-important': Promise; - readonly 'declaration-property-max-values': Promise; - readonly 'declaration-property-unit-allowed-list': Promise; - readonly 'declaration-property-unit-disallowed-list': Promise; - readonly 'declaration-property-value-allowed-list': Promise; - readonly 'declaration-property-value-disallowed-list': Promise; - readonly 'declaration-property-value-no-unknown': Promise; - readonly 'font-family-name-quotes': Promise; - readonly 'font-family-no-duplicate-names': Promise; - readonly 'font-family-no-missing-generic-family-keyword': Promise; - readonly 'font-weight-notation': Promise; - readonly 'function-allowed-list': Promise; - readonly 'function-calc-no-unspaced-operator': Promise; - readonly 'function-disallowed-list': Promise; - readonly 'function-linear-gradient-no-nonstandard-direction': Promise; - readonly 'function-name-case': Promise; - readonly 'function-no-unknown': Promise; - readonly 'function-url-no-scheme-relative': Promise; - readonly 'function-url-quotes': Promise; - readonly 'function-url-scheme-allowed-list': Promise; - readonly 'function-url-scheme-disallowed-list': Promise; - readonly 'hue-degree-notation': Promise; - readonly 'import-notation': Promise; - readonly 'keyframe-block-no-duplicate-selectors': Promise; - readonly 'keyframe-declaration-no-important': Promise; - readonly 'keyframe-selector-notation': Promise; - readonly 'keyframes-name-pattern': Promise; - readonly 'length-zero-no-unit': Promise; - readonly 'max-nesting-depth': Promise; - readonly 'media-feature-name-allowed-list': Promise; - readonly 'media-feature-name-disallowed-list': Promise; - readonly 'media-feature-name-no-unknown': Promise; - readonly 'media-feature-name-no-vendor-prefix': Promise; - readonly 'media-feature-name-unit-allowed-list': Promise; - readonly 'media-feature-name-value-allowed-list': Promise; - readonly 'media-feature-name-value-no-unknown': Promise; - readonly 'media-feature-range-notation': Promise; - readonly 'media-query-no-invalid': Promise; - readonly 'named-grid-areas-no-invalid': Promise; - readonly 'no-descending-specificity': Promise; - readonly 'no-duplicate-at-import-rules': Promise; - readonly 'no-duplicate-selectors': Promise; - readonly 'no-empty-source': Promise; - readonly 'no-invalid-double-slash-comments': Promise; - readonly 'no-invalid-position-at-import-rule': Promise; - readonly 'no-irregular-whitespace': Promise; - readonly 'no-unknown-animations': Promise; - readonly 'no-unknown-custom-properties': Promise; - readonly 'number-max-precision': Promise; - readonly 'property-allowed-list': Promise; - readonly 'property-disallowed-list': Promise; - readonly 'property-no-unknown': Promise; - readonly 'property-no-vendor-prefix': Promise; - readonly 'rule-empty-line-before': Promise; - readonly 'rule-selector-property-disallowed-list': Promise; - readonly 'selector-anb-no-unmatchable': Promise; - readonly 'selector-attribute-name-disallowed-list': Promise; - readonly 'selector-attribute-operator-allowed-list': Promise; - readonly 'selector-attribute-operator-disallowed-list': Promise; - readonly 'selector-attribute-quotes': Promise; - readonly 'selector-class-pattern': Promise; - readonly 'selector-combinator-allowed-list': Promise; - readonly 'selector-combinator-disallowed-list': Promise; - readonly 'selector-disallowed-list': Promise; - readonly 'selector-id-pattern': Promise; - readonly 'selector-max-attribute': Promise; - readonly 'selector-max-class': Promise; - readonly 'selector-max-combinators': Promise; - readonly 'selector-max-compound-selectors': Promise; - readonly 'selector-max-id': Promise; - readonly 'selector-max-pseudo-class': Promise; - readonly 'selector-max-specificity': Promise; - readonly 'selector-max-type': Promise; - readonly 'selector-max-universal': Promise; - readonly 'selector-nested-pattern': Promise; - readonly 'selector-no-qualifying-type': Promise; - readonly 'selector-no-vendor-prefix': Promise; - readonly 'selector-not-notation': Promise; - readonly 'selector-pseudo-class-allowed-list': Promise; - readonly 'selector-pseudo-class-disallowed-list': Promise; - readonly 'selector-pseudo-class-no-unknown': Promise; - readonly 'selector-pseudo-element-allowed-list': Promise; - readonly 'selector-pseudo-element-colon-notation': Promise; - readonly 'selector-pseudo-element-disallowed-list': Promise; - readonly 'selector-pseudo-element-no-unknown': Promise; - readonly 'selector-type-case': Promise; - readonly 'selector-type-no-unknown': Promise; - readonly 'shorthand-property-no-redundant-values': Promise; - readonly 'string-no-newline': Promise; - readonly 'time-min-milliseconds': Promise; - readonly 'unit-allowed-list': Promise; - readonly 'unit-disallowed-list': Promise; - readonly 'unit-no-unknown': Promise; - readonly 'value-keyword-case': Promise; - readonly 'value-no-vendor-prefix': Promise; - }; +/** + * A lint warning. + */ +export type Warning = { + /** + * The line of the inclusive start position of the warning. + */ + line: number; + /** + * The column of the inclusive start position of the warning. + */ + column: number; + /** + * The line of the exclusive end position of the warning. + */ + endLine?: number; + /** + * The column of the exclusive end position of the warning. + */ + endColumn?: number; + rule: string; + severity: Severity; + text: string; + stylelintType?: string; +}; - /** @internal */ - type GetPostcssOptions = { - code?: string; - codeFilename?: string; - filePath?: string; - customSyntax?: CustomSyntax; - }; +/** + * A lint result. + */ +export type LintResult = { + source?: string; + deprecations: { + text: string; + reference?: string; + }[]; + invalidOptionWarnings: { + text: string; + }[]; + parseErrors: (PostCSS.Warning & { stylelintType: string })[]; + errored?: boolean; + warnings: Warning[]; + ignored?: boolean; + /** + * Internal use only. Do not use or rely on this property. It may + * change at any time. + * @internal + */ + _postcssResult?: PostcssResult; +}; - /** @internal */ - type GetLintSourceOptions = GetPostcssOptions & { - existingPostcssResult?: PostCSS.Result; - cache?: boolean; - }; +/** @internal */ +export type DisableReportRange = { + rule: string; + start: number; + end?: number; +}; +/** + * A linter result. + */ +export type LinterResult = { + /** + * The working directory from which the linter was run when the + * results were generated. + */ + cwd: string; + results: LintResult[]; + errored: boolean; /** - * Linter options. - */ - type LinterOptions = { - files?: string | string[]; - globbyOptions?: GlobbyOptions; - cache?: boolean; - cacheLocation?: string; - cacheStrategy?: string; - code?: string; - codeFilename?: string; - config?: Config; - configFile?: string; - configBasedir?: string; - /** - * The working directory to resolve files from. Defaults to the - * current working directory. - */ - cwd?: string; - ignoreDisables?: boolean; - ignorePath?: string | string[]; - ignorePattern?: string[]; - reportDescriptionlessDisables?: boolean; - reportNeedlessDisables?: boolean; - reportInvalidScopeDisables?: boolean; - maxWarnings?: number; - customSyntax?: CustomSyntax; - formatter?: FormatterType | Formatter; - disableDefaultIgnores?: boolean; - fix?: boolean; - allowEmptyInput?: boolean; - quiet?: boolean; - quietDeprecationWarnings?: boolean; + * @deprecated Use `report` for the formatted problems, or use `code` + * for the autofixed code instead. This will be removed in the next major version. + */ + output: string; + /** @internal To show the deprecation warning. */ + _output?: string; + /** @internal To show the deprecation warning. */ + _outputWarned?: boolean; + /** + * A string that contains the formatted problems. + */ + report: string; + /** + * A string that contains the autofixed code, if the `fix` option is set to `true` + * and the `code` option is provided. + */ + code?: string; + maxWarningsExceeded?: { + maxWarnings: number; + foundWarnings: number; }; + reportedDisables: DisableOptionsReport; + descriptionlessDisables?: DisableOptionsReport; + needlessDisables?: DisableOptionsReport; + invalidScopeDisables?: DisableOptionsReport; + /** + * Each rule metadata by name. + */ + ruleMetadata: { [ruleName: string]: Partial }; +}; +/** + * A lint problem. + */ +export type Problem = { + ruleName: string; + result: PostcssResult; + message: RuleMessage; + messageArgs?: Parameters | undefined; + node: PostCSS.Node; /** - * A CSS syntax error. + * The inclusive start index of the problem, relative to the node's + * source text. */ - type CssSyntaxError = { - file?: string; - input: { - column: number; - file?: string; - line: number; - source: string; - }; - /** - * The line of the inclusive start position of the error. - */ + index?: number; + /** + * The exclusive end index of the problem, relative to the node's + * source text. + */ + endIndex?: number; + /** + * The inclusive start position of the problem, relative to the + * node's source text. If provided, this will be used instead of + * `index`. + */ + start?: { line: number; - /** - * The column of the inclusive start position of the error. - */ column: number; - /** - * The line of the exclusive end position of the error. - */ - endLine?: number; - /** - * The column of the exclusive end position of the error. - */ - endColumn?: number; - message: string; - name: string; - reason: string; - source: string; }; - /** - * A lint warning. + * The exclusive end position of the problem, relative to the + * node's source text. If provided, this will be used instead of + * `endIndex`. */ - type Warning = { - /** - * The line of the inclusive start position of the warning. - */ + end?: { line: number; - /** - * The column of the inclusive start position of the warning. - */ column: number; - /** - * The line of the exclusive end position of the warning. - */ - endLine?: number; - /** - * The column of the exclusive end position of the warning. - */ - endColumn?: number; - rule: string; - severity: Severity; - text: string; - stylelintType?: string; }; - + word?: string; + line?: number; /** - * A lint result. - */ - type LintResult = { - source?: string; - deprecations: { - text: string; - reference?: string; - }[]; - invalidOptionWarnings: { - text: string; - }[]; - parseErrors: (PostCSS.Warning & { stylelintType: string })[]; - errored?: boolean; - warnings: Warning[]; - ignored?: boolean; - /** - * Internal use only. Do not use or rely on this property. It may - * change at any time. - * @internal - */ - _postcssResult?: PostcssResult; - }; - - /** @internal */ - type DisableReportRange = { - rule: string; - start: number; - end?: number; - }; + * Optional severity override for the problem. + */ + severity?: RuleSeverity; +}; +/** @internal */ +export type ShorthandProperties = + | 'animation' + | 'background' + | 'border' + | 'border-block' + | 'border-block-end' + | 'border-block-start' + | 'border-inline' + | 'border-inline-end' + | 'border-inline-start' + | 'border-bottom' + | 'border-color' + | 'border-image' + | 'border-inline-end' + | 'border-inline-start' + | 'border-left' + | 'border-radius' + | 'border-right' + | 'border-style' + | 'border-top' + | 'border-width' + | 'column-rule' + | 'columns' + | 'flex' + | 'flex-flow' + | 'font' + | 'font-synthesis' + | 'gap' + | 'grid' + | 'grid-area' + | 'grid-column' + | 'grid-gap' + | 'grid-row' + | 'grid-template' + | 'inset' + | 'inset-block' + | 'inset-inline' + | 'list-style' + | 'margin' + | 'margin-block' + | 'margin-inline' + | 'mask' + | 'outline' + | 'overflow' + | 'overscroll-behavior' + | 'padding' + | 'padding-block' + | 'padding-inline' + | 'place-content' + | 'place-items' + | 'place-self' + | 'scroll-margin' + | 'scroll-margin-block' + | 'scroll-margin-inline' + | 'scroll-padding' + | 'scroll-padding-block' + | 'scroll-padding-inline' + | 'text-decoration' + | 'text-emphasis' + | 'transition'; + +/** @internal */ +export type LonghandSubPropertiesOfShorthandProperties = ReadonlyMap< + ShorthandProperties, + ReadonlySet +>; + +/** + * Utility functions. + */ +export type Utils = { /** - * A linter result. - */ - type LinterResult = { - /** - * The working directory from which the linter was run when the - * results were generated. - */ - cwd: string; - results: LintResult[]; - errored: boolean; - /** - * @deprecated Use `report` for the formatted problems, or use `code` - * for the autofixed code instead. This will be removed in the next major version. - */ - output: string; - /** @internal To show the deprecation warning. */ - _output?: string; - /** @internal To show the deprecation warning. */ - _outputWarned?: boolean; - /** - * A string that contains the formatted problems. - */ - report: string; - /** - * A string that contains the autofixed code, if the `fix` option is set to `true` - * and the `code` option is provided. - */ - code?: string; - maxWarningsExceeded?: { - maxWarnings: number; - foundWarnings: number; - }; - reportedDisables: DisableOptionsReport; - descriptionlessDisables?: DisableOptionsReport; - needlessDisables?: DisableOptionsReport; - invalidScopeDisables?: DisableOptionsReport; - /** - * Each rule metadata by name. - */ - ruleMetadata: { [ruleName: string]: Partial }; - }; + * Report a problem. + * + * This function accounts for `disabledRanges` attached to the result. + * That is, if the reported problem is within a disabledRange, + * it is ignored. Otherwise, it is attached to the result as a + * postcss warning. + * + * It also accounts for the rule's severity. + * + * You *must* pass *either* a node or a line number. + * + * @param problem - A problem + */ + report: (problem: Problem) => void; /** - * A lint problem. - */ - type Problem = { - ruleName: string; - result: PostcssResult; - message: RuleMessage; - messageArgs?: Parameters | undefined; - node: PostCSS.Node; - /** - * The inclusive start index of the problem, relative to the node's - * source text. - */ - index?: number; - /** - * The exclusive end index of the problem, relative to the node's - * source text. - */ - endIndex?: number; - /** - * The inclusive start position of the problem, relative to the - * node's source text. If provided, this will be used instead of - * `index`. - */ - start?: { - line: number; - column: number; - }; - /** - * The exclusive end position of the problem, relative to the - * node's source text. If provided, this will be used instead of - * `endIndex`. - */ - end?: { - line: number; - column: number; - }; - word?: string; - line?: number; - /** - * Optional severity override for the problem. - */ - severity?: RuleSeverity; - }; - - /** @internal */ - type ShorthandProperties = - | 'animation' - | 'background' - | 'border' - | 'border-block' - | 'border-block-end' - | 'border-block-start' - | 'border-inline' - | 'border-inline-end' - | 'border-inline-start' - | 'border-bottom' - | 'border-color' - | 'border-image' - | 'border-inline-end' - | 'border-inline-start' - | 'border-left' - | 'border-radius' - | 'border-right' - | 'border-style' - | 'border-top' - | 'border-width' - | 'column-rule' - | 'columns' - | 'flex' - | 'flex-flow' - | 'font' - | 'font-synthesis' - | 'gap' - | 'grid' - | 'grid-area' - | 'grid-column' - | 'grid-gap' - | 'grid-row' - | 'grid-template' - | 'inset' - | 'inset-block' - | 'inset-inline' - | 'list-style' - | 'margin' - | 'margin-block' - | 'margin-inline' - | 'mask' - | 'outline' - | 'overflow' - | 'overscroll-behavior' - | 'padding' - | 'padding-block' - | 'padding-inline' - | 'place-content' - | 'place-items' - | 'place-self' - | 'scroll-margin' - | 'scroll-margin-block' - | 'scroll-margin-inline' - | 'scroll-padding' - | 'scroll-padding-block' - | 'scroll-padding-inline' - | 'text-decoration' - | 'text-emphasis' - | 'transition'; - - /** @internal */ - type LonghandSubPropertiesOfShorthandProperties = ReadonlyMap< - ShorthandProperties, - ReadonlySet - >; + * Given an object of problem messages, return another + * that provides the same messages postfixed with the rule + * that has been violated. + * + * @param ruleName - A rule name + * @param messages - An object whose keys are message identifiers + * and values are either message strings or functions that return message strings + * @returns New message object, whose messages will be marked with the rule name + */ + ruleMessages: ( + ruleName: string, + messages: T, + ) => R; /** - * Utility functions. + * Validate a rule's options. + * + * See existing rules for examples. + * + * @param result - PostCSS result + * @param ruleName - A rule name + * @param optionDescriptions - Each optionDescription can have the following properties: + * - `actual` (required): the actual passed option value or object. + * - `possible` (required): a schema representation of what values are + * valid for those options. `possible` should be an object if the + * options are an object, with corresponding keys; if the options are not an + * object, `possible` isn't, either. All `possible` value representations + * should be **arrays of either values or functions**. Values are === checked + * against `actual`. Functions are fed `actual` as an argument and their + * return value is interpreted: truthy = valid, falsy = invalid. + * - `optional` (optional): If this is `true`, `actual` can be undefined. + * @returns Whether or not the options are valid (`true` = valid) */ - type Utils = { - /** - * Report a problem. - * - * This function accounts for `disabledRanges` attached to the result. - * That is, if the reported problem is within a disabledRange, - * it is ignored. Otherwise, it is attached to the result as a - * postcss warning. - * - * It also accounts for the rule's severity. - * - * You *must* pass *either* a node or a line number. - * - * @param problem - A problem - */ - report: (problem: Problem) => void; - - /** - * Given an object of problem messages, return another - * that provides the same messages postfixed with the rule - * that has been violated. - * - * @param ruleName - A rule name - * @param messages - An object whose keys are message identifiers - * and values are either message strings or functions that return message strings - * @returns New message object, whose messages will be marked with the rule name - */ - ruleMessages: ( - ruleName: string, - messages: T, - ) => R; - - /** - * Validate a rule's options. - * - * See existing rules for examples. - * - * @param result - PostCSS result - * @param ruleName - A rule name - * @param optionDescriptions - Each optionDescription can have the following properties: - * - `actual` (required): the actual passed option value or object. - * - `possible` (required): a schema representation of what values are - * valid for those options. `possible` should be an object if the - * options are an object, with corresponding keys; if the options are not an - * object, `possible` isn't, either. All `possible` value representations - * should be **arrays of either values or functions**. Values are === checked - * against `actual`. Functions are fed `actual` as an argument and their - * return value is interpreted: truthy = valid, falsy = invalid. - * - `optional` (optional): If this is `true`, `actual` can be undefined. - * @returns Whether or not the options are valid (`true` = valid) - */ - validateOptions: ( - result: PostcssResult, - ruleName: string, - ...optionDescriptions: RuleOptions[] - ) => boolean; - - /** - * Useful for third-party code (e.g. plugins) to run a PostCSS Root - * against a specific rule and do something with the warnings. - */ - checkAgainstRule: ( - options: { - ruleName: string; - ruleSettings: ConfigRuleSettings; - root: PostCSS.Root; - result?: PostcssResult; - context?: RuleContext; - }, - callback: (warning: PostCSS.Warning) => void, - ) => void; - }; + validateOptions: ( + result: PostcssResult, + ruleName: string, + ...optionDescriptions: RuleOptions[] + ) => boolean; /** - * Internal use only. Do not use or rely on this type. It may change at - * any time. - * @internal + * Useful for third-party code (e.g. plugins) to run a PostCSS Root + * against a specific rule and do something with the warnings. */ - type InternalApi = { - _options: LinterOptions & { cwd: string }; - _extendExplorer: ReturnType; - _specifiedConfigCache: Map>; - _postcssResultCache: Map; - _fileCache: FileCache; - }; + checkAgainstRule: ( + options: { + ruleName: string; + ruleSettings: ConfigRuleSettings; + root: PostCSS.Root; + result?: PostcssResult; + context?: RuleContext; + }, + callback: (warning: PostCSS.Warning) => void, + ) => void; +}; + +/** + * Internal use only. Do not use or rely on this type. It may change at + * any time. + * @internal + */ +export type InternalApi = { + _options: LinterOptions & { cwd: string }; + _extendExplorer: ReturnType; + _specifiedConfigCache: Map>; + _postcssResultCache: Map; + _fileCache: FileCache; +}; - type DisableOptionsReport = DisableReportEntry[]; +/** @internal */ +export type DisableOptionsReport = DisableReportEntry[]; - type PostcssPluginOptions = Omit | Config; -} +/** @internal */ +export type PostcssPluginOptions = Omit | Config; -type PublicApi = PostCSS.PluginCreator & { +/** + * The Stylelint public API. + */ +export type PublicApi = PostCSS.PluginCreator & { /** * Runs Stylelint with the given options and returns a Promise that * resolves to the results. @@ -769,22 +775,22 @@ type PublicApi = PostCSS.PluginCreator & { * @param options - A lint options object * @returns A lint result */ - lint: (options: stylelint.LinterOptions) => Promise; + lint: (options: LinterOptions) => Promise; /** * Available rules. */ - rules: stylelint.BuiltInRules; + rules: BuiltInRules; /** * Result report formatters by name. */ - formatters: stylelint.Formatters; + formatters: Formatters; /** * Creates a Stylelint plugin. */ - createPlugin: (ruleName: string, rule: stylelint.Rule) => stylelint.Plugin; + createPlugin: (ruleName: string, rule: Rule) => Plugin; /** * The Stylelint "internal API" is passed among functions @@ -793,7 +799,7 @@ type PublicApi = PostCSS.PluginCreator & { * * @internal */ - _createLinter: (options: stylelint.LinterOptions) => stylelint.InternalApi; + _createLinter: (options: LinterOptions) => InternalApi; /** * Resolves the effective configuration for a given file. Resolves to @@ -805,22 +811,22 @@ type PublicApi = PostCSS.PluginCreator & { */ resolveConfig: ( filePath: string, - options?: Pick, - ) => Promise; + options?: Pick, + ) => Promise; /** * Utility functions. */ - utils: stylelint.Utils; + utils: Utils; /** * Reference objects. */ reference: { - longhandSubPropertiesOfShorthandProperties: stylelint.LonghandSubPropertiesOfShorthandProperties; + longhandSubPropertiesOfShorthandProperties: LonghandSubPropertiesOfShorthandProperties; }; }; declare const stylelint: PublicApi; -export = stylelint; +export default stylelint; diff --git a/types/stylelint/test.d.ts b/types/stylelint/test.d.ts deleted file mode 100644 index 0c7da105d8..0000000000 --- a/types/stylelint/test.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare var testRule: import('jest-preset-stylelint').TestRule; diff --git a/types/stylelint/type-test.ts b/types/stylelint/type-test.ts index 4a96c10571..b3e0e266dc 100644 --- a/types/stylelint/type-test.ts +++ b/types/stylelint/type-test.ts @@ -16,7 +16,7 @@ import type { RuleMeta, Warning, } from 'stylelint'; -import * as stylelint from 'stylelint'; +import stylelint from 'stylelint'; const options: Partial = { allowEmptyInput: true,