diff --git a/CHANGELOG.md b/CHANGELOG.md index f1ebd45c50..8bead6b71a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project are documented in this file. - Added: `ignoreFunctions: []` to `length-zero-no-unit` ([#5314](https://github.com/stylelint/stylelint/pull/5314)). - Added: `ignoreAtRules: []` to `no-invalid-position-at-import` ([#5520](https://github.com/stylelint/stylelint/pull/5520)). - Added: `ignoreProperties: []` to `number-max-precision` ([#5421](https://github.com/stylelint/stylelint/pull/5421)). +- Added: TypeScript type definitions ([#5582](https://github.com/stylelint/stylelint/pull/5582)). - Fixed: "No files matching the pattern" when using backslash paths on Windows ([#5386](https://github.com/stylelint/stylelint/pull/5386)). - Fixed: `function-url-quotes` violation messages to be consistent with other `*-quotes` rules ([#5488](https://github.com/stylelint/stylelint/pull/5488)). - Fixed: `length-zero-no-unit` false positives for `flex` property ([#5315](https://github.com/stylelint/stylelint/pull/5315)). diff --git a/docs/developer-guide/formatters.md b/docs/developer-guide/formatters.md index a0261ea239..ee1b6f3d56 100644 --- a/docs/developer-guide/formatters.md +++ b/docs/developer-guide/formatters.md @@ -45,7 +45,7 @@ Where the first argument (`results`) is an array of Stylelint result objects (ty } ``` -And the second argument (`returnValue`) is an object (type `StylelintStandaloneReturnValue`) with one or more of the following keys: +And the second argument (`returnValue`) is an object (type `LinterResult`) with one or more of the following keys: ```js { diff --git a/docs/migration-guide/to-14.md b/docs/migration-guide/to-14.md index 46934f71ef..c01f795a59 100644 --- a/docs/migration-guide/to-14.md +++ b/docs/migration-guide/to-14.md @@ -108,10 +108,11 @@ The `function-calc-no-invalid` has be removed. You should remove it from your co ## Plugin authors -There are two changes that may affect you: +There are three changes that may affect you: - version 8 of PostCSS is now used in stylelint - a [`disableFix` secondary option](../user-guide/configure.md#disableFix) was added +- TypeScript type definitions were added to the package ### PostCSS 8 @@ -130,3 +131,7 @@ Even though version 8 of PostCSS is used in stylelint, you can't use the [new Vi ### `disableFix` secondary option We previously suggested plugin authors provide this option. It is now available in Stylelint itself, and you should remove the option from your plugin. + +### Built-in TypeScript definitions + +The `stylelint` package exports its own TypeScript type definitions now. If you are using the `@types/stylelint` package, you should remove it from your dependencies. diff --git a/lib/augmentConfig.js b/lib/augmentConfig.js index 4ede872588..295173138f 100644 --- a/lib/augmentConfig.js +++ b/lib/augmentConfig.js @@ -8,14 +8,14 @@ const normalizeAllRuleSettings = require('./normalizeAllRuleSettings'); const normalizePath = require('normalize-path'); const path = require('path'); -/** @typedef {import('stylelint').StylelintConfigPlugins} StylelintConfigPlugins */ -/** @typedef {import('stylelint').StylelintConfigProcessor} StylelintConfigProcessor */ -/** @typedef {import('stylelint').StylelintConfigProcessors} StylelintConfigProcessors */ -/** @typedef {import('stylelint').StylelintConfigRules} StylelintConfigRules */ -/** @typedef {import('stylelint').StylelintConfigOverride} StylelintConfigOverride */ -/** @typedef {import('stylelint').StylelintInternalApi} StylelintInternalApi */ -/** @typedef {import('stylelint').StylelintConfig} StylelintConfig */ -/** @typedef {import('stylelint').StylelintCosmiconfigResult} StylelintCosmiconfigResult */ +/** @typedef {import('stylelint').ConfigPlugins} StylelintConfigPlugins */ +/** @typedef {import('stylelint').ConfigProcessor} StylelintConfigProcessor */ +/** @typedef {import('stylelint').ConfigProcessors} StylelintConfigProcessors */ +/** @typedef {import('stylelint').ConfigRules} StylelintConfigRules */ +/** @typedef {import('stylelint').ConfigOverride} StylelintConfigOverride */ +/** @typedef {import('stylelint').InternalApi} StylelintInternalApi */ +/** @typedef {import('stylelint').Config} StylelintConfig */ +/** @typedef {import('stylelint').CosmiconfigResult} StylelintCosmiconfigResult */ /** * - Merges config and stylelint options diff --git a/lib/createPartialStylelintResult.js b/lib/createPartialStylelintResult.js index 3be8afc338..97234b2c4b 100644 --- a/lib/createPartialStylelintResult.js +++ b/lib/createPartialStylelintResult.js @@ -1,11 +1,11 @@ 'use strict'; /** @typedef {import('stylelint').PostcssResult} PostcssResult */ -/** @typedef {import('stylelint').StylelintResult} StylelintResult */ +/** @typedef {import('stylelint').LintResult} StylelintResult */ /** * @param {PostcssResult} [postcssResult] - * @param {import('stylelint').StylelintCssSyntaxError} [cssSyntaxError] + * @param {import('stylelint').CssSyntaxError} [cssSyntaxError] * @return {StylelintResult} */ module.exports = function (postcssResult, cssSyntaxError) { diff --git a/lib/createPlugin.js b/lib/createPlugin.js index 5e9ff6b25f..8a12480f55 100644 --- a/lib/createPlugin.js +++ b/lib/createPlugin.js @@ -1,15 +1,17 @@ 'use strict'; -/** @typedef {import('stylelint').StylelintRule} StylelintRule */ +/** @typedef {import('stylelint').Rule} StylelintRule */ /** * @param {string} ruleName * @param {StylelintRule} rule * @returns {{ruleName: string, rule: StylelintRule}} */ -module.exports = function (ruleName, rule) { +function createPlugin(ruleName, rule) { return { ruleName, rule, }; -}; +} + +module.exports = /** @type {typeof import('stylelint').createPlugin} */ (createPlugin); diff --git a/lib/createStylelint.js b/lib/createStylelint.js index 13dc6740b7..4a0b48639d 100644 --- a/lib/createStylelint.js +++ b/lib/createStylelint.js @@ -11,19 +11,19 @@ const { cosmiconfig } = require('cosmiconfig'); const IS_TEST = process.env.NODE_ENV === 'test'; const STOP_DIR = IS_TEST ? process.cwd() : undefined; -/** @typedef {import('stylelint').StylelintInternalApi} StylelintInternalApi */ +/** @typedef {import('stylelint').InternalApi} StylelintInternalApi */ /** * The stylelint "internal API" is passed among functions * so that methods on a stylelint instance can invoke * each other while sharing options and caches. * - * @param {import('stylelint').StylelintStandaloneOptions} options + * @param {import('stylelint').LinterOptions} options * @returns {StylelintInternalApi} */ -module.exports = function createStylelint(options = {}) { +function createStylelint(options = {}) { /** @type {StylelintInternalApi} */ - // @ts-expect-error -- TS2740: Type '{ _options: StylelintStandaloneOptions; }' is missing the following properties from type 'StylelintInternalApi' + // @ts-expect-error -- TS2740: Type '{ _options: LinterOptions; }' is missing the following properties from type 'InternalApi' const stylelint = { _options: options }; stylelint._extendExplorer = cosmiconfig('', { @@ -41,4 +41,6 @@ module.exports = function createStylelint(options = {}) { stylelint.isPathIgnored = isPathIgnored.bind(null, stylelint); return stylelint; -}; +} + +module.exports = /** @type {typeof import('stylelint').createLinter} */ (createStylelint); diff --git a/lib/createStylelintResult.js b/lib/createStylelintResult.js index 6990ae1202..25d9d3d9fe 100644 --- a/lib/createStylelintResult.js +++ b/lib/createStylelintResult.js @@ -3,13 +3,13 @@ const createPartialStylelintResult = require('./createPartialStylelintResult'); /** @typedef {import('stylelint').PostcssResult} PostcssResult */ -/** @typedef {import('stylelint').StylelintResult} StylelintResult */ +/** @typedef {import('stylelint').LintResult} StylelintResult */ /** - * @param {import('stylelint').StylelintInternalApi} stylelint + * @param {import('stylelint').InternalApi} stylelint * @param {PostcssResult} [postcssResult] * @param {string} [filePath] - * @param {import('stylelint').StylelintCssSyntaxError} [cssSyntaxError] + * @param {import('stylelint').CssSyntaxError} [cssSyntaxError] * @return {Promise} */ module.exports = async function createStylelintResult( diff --git a/lib/descriptionlessDisables.js b/lib/descriptionlessDisables.js index 8da3559676..004120fe9b 100644 --- a/lib/descriptionlessDisables.js +++ b/lib/descriptionlessDisables.js @@ -6,10 +6,10 @@ const validateDisableSettings = require('./validateDisableSettings'); /** @typedef {import('postcss').Comment} PostcssComment */ /** @typedef {import('stylelint').RangeType} RangeType */ /** @typedef {import('stylelint').DisableReportRange} DisableReportRange */ -/** @typedef {import('stylelint').StylelintDisableOptionsReport} StylelintDisableOptionsReport */ +/** @typedef {import('stylelint').DisableOptionsReport} StylelintDisableOptionsReport */ /** - * @param {import('stylelint').StylelintResult[]} results + * @param {import('stylelint').LintResult[]} results */ module.exports = function descriptionlessDisables(results) { results.forEach((result) => { diff --git a/lib/formatters/index.js b/lib/formatters/index.js index 82d47372ce..170f9d4fed 100644 --- a/lib/formatters/index.js +++ b/lib/formatters/index.js @@ -2,7 +2,8 @@ const importLazy = require('import-lazy'); -module.exports = { +/** @type {typeof import('stylelint').formatters} */ +const formatters = { compact: importLazy(() => require('./compactFormatter'))('compactFormatter'), json: importLazy(() => require('./jsonFormatter'))('jsonFormatter'), string: importLazy(() => require('./stringFormatter'))('stringFormatter'), @@ -10,3 +11,5 @@ module.exports = { unix: importLazy(() => require('./unixFormatter'))('unixFormatter'), verbose: importLazy(() => require('./verboseFormatter'))('verboseFormatter'), }; + +module.exports = formatters; diff --git a/lib/formatters/stringFormatter.js b/lib/formatters/stringFormatter.js index dab08e7ea8..9e7eb8216a 100644 --- a/lib/formatters/stringFormatter.js +++ b/lib/formatters/stringFormatter.js @@ -30,7 +30,7 @@ const symbols = { }; /** - * @param {import('stylelint').StylelintResult[]} results + * @param {import('stylelint').LintResult[]} results * @returns {string} */ function deprecationsFormatter(results) { @@ -60,7 +60,7 @@ function deprecationsFormatter(results) { } /** - * @param {import('stylelint').StylelintResult[]} results + * @param {import('stylelint').LintResult[]} results * @return {string} */ function invalidOptionsFormatter(results) { @@ -108,7 +108,7 @@ function getMessageWidth(columnWidths) { } /** - * @param {import('stylelint').StylelintWarning[]} messages + * @param {import('stylelint').Warning[]} messages * @param {string} source * @return {string} */ @@ -161,7 +161,7 @@ function formatter(messages, source) { } /** - * @param {import('stylelint').StylelintWarning} message + * @param {import('stylelint').Warning} message * @return {string} */ function formatMessageText(message) { diff --git a/lib/formatters/verboseFormatter.js b/lib/formatters/verboseFormatter.js index 8b9e57ce3f..bd59b5a196 100644 --- a/lib/formatters/verboseFormatter.js +++ b/lib/formatters/verboseFormatter.js @@ -4,7 +4,7 @@ const stringFormatter = require('./stringFormatter'); const { underline, red, yellow, dim, green } = require('picocolors'); /** @typedef {import('stylelint').Formatter} Formatter */ -/** @typedef {import('stylelint').StylelintWarning} StylelintWarning */ +/** @typedef {import('stylelint').Warning} StylelintWarning */ /** * @type {Formatter} diff --git a/lib/getConfigForFile.js b/lib/getConfigForFile.js index 9e2ca7af8c..d602fbdd48 100644 --- a/lib/getConfigForFile.js +++ b/lib/getConfigForFile.js @@ -8,9 +8,9 @@ const { cosmiconfig } = require('cosmiconfig'); const IS_TEST = process.env.NODE_ENV === 'test'; const STOP_DIR = IS_TEST ? process.cwd() : undefined; -/** @typedef {import('stylelint').StylelintInternalApi} StylelintInternalApi */ -/** @typedef {import('stylelint').StylelintConfig} StylelintConfig */ -/** @typedef {import('stylelint').StylelintCosmiconfigResult} StylelintCosmiconfigResult */ +/** @typedef {import('stylelint').InternalApi} StylelintInternalApi */ +/** @typedef {import('stylelint').Config} StylelintConfig */ +/** @typedef {import('stylelint').CosmiconfigResult} StylelintCosmiconfigResult */ /** * @param {StylelintInternalApi} stylelint diff --git a/lib/getPostcssResult.js b/lib/getPostcssResult.js index 6a98d254e7..fe48734af9 100644 --- a/lib/getPostcssResult.js +++ b/lib/getPostcssResult.js @@ -9,7 +9,7 @@ const { promises: fs } = require('fs'); /** @typedef {import('postcss').Syntax} Syntax */ /** @typedef {import('stylelint').CustomSyntax} CustomSyntax */ /** @typedef {import('stylelint').GetPostcssOptions} GetPostcssOptions */ -/** @typedef {import('stylelint').StylelintInternalApi} StylelintInternalApi */ +/** @typedef {import('stylelint').InternalApi} StylelintInternalApi */ const postcssProcessor = postcss(); diff --git a/lib/index.js b/lib/index.js index e96423e2c9..f8bca2f451 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,20 +11,19 @@ const rules = require('./rules'); const standalone = require('./standalone'); const validateOptions = require('./utils/validateOptions'); -/** - * @type {import('postcss').PluginCreator & import('stylelint').StylelintPublicAPI} - */ -module.exports = postcssPlugin; +/** @type {import('stylelint').PublicApi} */ +const stylelint = Object.assign(postcssPlugin, { + lint: standalone, + rules, + formatters, + createPlugin, + createLinter: createStylelint, + utils: { + report, + ruleMessages, + validateOptions, + checkAgainstRule, + }, +}); -module.exports.utils = { - report, - ruleMessages, - validateOptions, - checkAgainstRule, -}; - -module.exports.lint = standalone; -module.exports.rules = rules; -module.exports.formatters = formatters; -module.exports.createPlugin = createPlugin; -module.exports.createLinter = createStylelint; +module.exports = stylelint; diff --git a/lib/invalidScopeDisables.js b/lib/invalidScopeDisables.js index 099ccdcc94..dec9f829f7 100644 --- a/lib/invalidScopeDisables.js +++ b/lib/invalidScopeDisables.js @@ -6,7 +6,7 @@ const validateDisableSettings = require('./validateDisableSettings'); /** @typedef {import('stylelint').RangeType} RangeType */ /** - * @param {import('stylelint').StylelintResult[]} results + * @param {import('stylelint').LintResult[]} results */ module.exports = function invalidScopeDisables(results) { results.forEach((result) => { diff --git a/lib/isPathIgnored.js b/lib/isPathIgnored.js index ffa84b7049..b3c05d3e27 100644 --- a/lib/isPathIgnored.js +++ b/lib/isPathIgnored.js @@ -10,7 +10,7 @@ const path = require('path'); * To find out if a path is ignored, we need to load the config, * which may have an ignoreFiles property. We then check the path * against these. - * @param {import('stylelint').StylelintInternalApi} stylelint + * @param {import('stylelint').InternalApi} stylelint * @param {string} [filePath] * @return {Promise} */ diff --git a/lib/lintPostcssResult.js b/lib/lintPostcssResult.js index 541f839461..d55b01afaf 100644 --- a/lib/lintPostcssResult.js +++ b/lib/lintPostcssResult.js @@ -5,12 +5,12 @@ const getOsEol = require('./utils/getOsEol'); const reportUnknownRuleNames = require('./reportUnknownRuleNames'); const rulesOrder = require('./rules'); -/** @typedef {import('stylelint').StylelintStandaloneOptions} StylelintStandaloneOptions */ +/** @typedef {import('stylelint').LinterOptions} LinterOptions */ /** @typedef {import('stylelint').PostcssResult} PostcssResult */ -/** @typedef {import('stylelint').StylelintConfig} StylelintConfig */ +/** @typedef {import('stylelint').Config} StylelintConfig */ /** - * @param {StylelintStandaloneOptions} stylelintOptions + * @param {LinterOptions} stylelintOptions * @param {PostcssResult} postcssResult * @param {StylelintConfig} config * @returns {Promise} diff --git a/lib/lintSource.js b/lib/lintSource.js index 3d8d6301a0..7682d52908 100644 --- a/lib/lintSource.js +++ b/lib/lintSource.js @@ -4,7 +4,7 @@ const isPathNotFoundError = require('./utils/isPathNotFoundError'); const lintPostcssResult = require('./lintPostcssResult'); const path = require('path'); -/** @typedef {import('stylelint').StylelintInternalApi} StylelintInternalApi */ +/** @typedef {import('stylelint').InternalApi} StylelintInternalApi */ /** @typedef {import('stylelint').GetLintSourceOptions} Options */ /** @typedef {import('postcss').Result} Result */ /** @typedef {import('stylelint').PostcssResult} PostcssResult */ diff --git a/lib/needlessDisables.js b/lib/needlessDisables.js index 295bc5cd69..ccd2bb9e12 100644 --- a/lib/needlessDisables.js +++ b/lib/needlessDisables.js @@ -10,7 +10,7 @@ const validateDisableSettings = require('./validateDisableSettings'); /** @typedef {import('stylelint').DisableReportRange} DisableReportRange */ /** - * @param {import('stylelint').StylelintResult[]} results + * @param {import('stylelint').LintResult[]} results */ module.exports = function needlessDisables(results) { results.forEach((result) => { diff --git a/lib/normalizeAllRuleSettings.js b/lib/normalizeAllRuleSettings.js index 4740d7c948..9f2adb198b 100644 --- a/lib/normalizeAllRuleSettings.js +++ b/lib/normalizeAllRuleSettings.js @@ -3,8 +3,8 @@ const normalizeRuleSettings = require('./normalizeRuleSettings'); const rules = require('./rules'); -/** @typedef {import('stylelint').StylelintConfigRules} StylelintConfigRules */ -/** @typedef {import('stylelint').StylelintConfig} StylelintConfig */ +/** @typedef {import('stylelint').ConfigRules} StylelintConfigRules */ +/** @typedef {import('stylelint').Config} StylelintConfig */ /** * @param {StylelintConfig} config diff --git a/lib/normalizeRuleSettings.js b/lib/normalizeRuleSettings.js index cbcaaceadc..83a3bb8956 100644 --- a/lib/normalizeRuleSettings.js +++ b/lib/normalizeRuleSettings.js @@ -18,7 +18,7 @@ const { isPlainObject } = require('is-plain-object'); * null is returned * @template T * @template {Object} O - * @param {import('stylelint').StylelintConfigRuleSettings} rawSettings + * @param {import('stylelint').ConfigRuleSettings} rawSettings * @param {string} ruleName * @param {boolean} [primaryOptionArray] If primaryOptionArray is not provided, we try to get it from the rules themselves, which will not work for plugins * @return {[T] | [T, O] | null} diff --git a/lib/postcssPlugin.js b/lib/postcssPlugin.js index 6d3a26eefb..fed318110f 100644 --- a/lib/postcssPlugin.js +++ b/lib/postcssPlugin.js @@ -4,7 +4,7 @@ const createStylelint = require('./createStylelint'); const path = require('path'); /** @typedef {import('stylelint').PostcssPluginOptions} PostcssPluginOptions */ -/** @typedef {import('stylelint').StylelintConfig} StylelintConfig */ +/** @typedef {import('stylelint').Config} StylelintConfig */ /** * @type {import('postcss').PluginCreator} diff --git a/lib/prepareReturnValue.js b/lib/prepareReturnValue.js index 650f5dfeb5..f97e311b48 100644 --- a/lib/prepareReturnValue.js +++ b/lib/prepareReturnValue.js @@ -6,16 +6,16 @@ const needlessDisables = require('./needlessDisables'); const reportDisables = require('./reportDisables'); /** @typedef {import('stylelint').Formatter} Formatter */ -/** @typedef {import('stylelint').StylelintResult} StylelintResult */ -/** @typedef {import('stylelint').StylelintStandaloneOptions["maxWarnings"]} maxWarnings */ -/** @typedef {import('stylelint').StylelintStandaloneReturnValue} StylelintStandaloneReturnValue */ +/** @typedef {import('stylelint').LintResult} StylelintResult */ +/** @typedef {import('stylelint').LinterOptions["maxWarnings"]} maxWarnings */ +/** @typedef {import('stylelint').LinterResult} LinterResult */ /** * @param {StylelintResult[]} stylelintResults * @param {maxWarnings} maxWarnings * @param {Formatter} formatter * - * @returns {StylelintStandaloneReturnValue} + * @returns {LinterResult} */ function prepareReturnValue(stylelintResults, maxWarnings, formatter) { reportDisables(stylelintResults); @@ -30,7 +30,7 @@ function prepareReturnValue(stylelintResults, maxWarnings, formatter) { result.warnings.some((warning) => warning.severity === 'error'), ); - /** @type {StylelintStandaloneReturnValue} */ + /** @type {LinterResult} */ const returnValue = { errored, results: [], diff --git a/lib/printConfig.js b/lib/printConfig.js index c19776bbc1..ad25bdf9b6 100644 --- a/lib/printConfig.js +++ b/lib/printConfig.js @@ -4,10 +4,10 @@ const createStylelint = require('./createStylelint'); const globby = require('globby'); const path = require('path'); -/** @typedef {import('stylelint').StylelintConfig} StylelintConfig */ +/** @typedef {import('stylelint').Config} StylelintConfig */ /** - * @param {import('stylelint').StylelintStandaloneOptions} options + * @param {import('stylelint').LinterOptions} options * @returns {Promise} */ module.exports = function printConfig({ diff --git a/lib/reportDisables.js b/lib/reportDisables.js index 8b1219056e..9e75d8fedf 100644 --- a/lib/reportDisables.js +++ b/lib/reportDisables.js @@ -2,8 +2,8 @@ /** @typedef {import('stylelint').RangeType} RangeType */ /** @typedef {import('stylelint').DisableReportRange} DisabledRange */ -/** @typedef {import('stylelint').StylelintResult} StylelintResult */ -/** @typedef {import('stylelint').StylelintConfigRuleSettings} StylelintConfigRuleSettings */ +/** @typedef {import('stylelint').LintResult} StylelintResult */ +/** @typedef {import('stylelint').ConfigRuleSettings} StylelintConfigRuleSettings */ /** * Returns a report describing which `results` (if any) contain disabled ranges diff --git a/lib/rules/alpha-value-notation/index.js b/lib/rules/alpha-value-notation/index.js index 5c4dcf0ae9..a0cef72682 100644 --- a/lib/rules/alpha-value-notation/index.js +++ b/lib/rules/alpha-value-notation/index.js @@ -21,7 +21,7 @@ const messages = ruleMessages(ruleName, { const ALPHA_PROPS = new Set(['opacity', 'shape-image-threshold']); const ALPHA_FUNCS = new Set(['hsl', 'hsla', 'hwb', 'lab', 'lch', 'rgb', 'rgba']); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/at-rule-allowed-list/index.js b/lib/rules/at-rule-allowed-list/index.js index f0c1d481f9..1353c60aa5 100644 --- a/lib/rules/at-rule-allowed-list/index.js +++ b/lib/rules/at-rule-allowed-list/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejected: (name) => `Unexpected at-rule "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { // To allow for just a string as a parameter (not only arrays of strings) const primaryValues = [primary].flat(); diff --git a/lib/rules/at-rule-disallowed-list/index.js b/lib/rules/at-rule-disallowed-list/index.js index f57dd8d50d..f587af1ad2 100644 --- a/lib/rules/at-rule-disallowed-list/index.js +++ b/lib/rules/at-rule-disallowed-list/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejected: (name) => `Unexpected at-rule "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { // To allow for just a string as a parameter (not only arrays of strings) const primaryValues = [primary].flat(); diff --git a/lib/rules/at-rule-empty-line-before/index.js b/lib/rules/at-rule-empty-line-before/index.js index 17fdedb7f6..9e9eabf9de 100644 --- a/lib/rules/at-rule-empty-line-before/index.js +++ b/lib/rules/at-rule-empty-line-before/index.js @@ -23,7 +23,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected empty line before at-rule', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/at-rule-name-case/index.js b/lib/rules/at-rule-name-case/index.js index 994b28678d..e38ea7668d 100644 --- a/lib/rules/at-rule-name-case/index.js +++ b/lib/rules/at-rule-name-case/index.js @@ -11,7 +11,7 @@ const messages = ruleMessages(ruleName, { expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondary, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/at-rule-name-newline-after/index.js b/lib/rules/at-rule-name-newline-after/index.js index b207339c5e..c5901ee660 100644 --- a/lib/rules/at-rule-name-newline-after/index.js +++ b/lib/rules/at-rule-name-newline-after/index.js @@ -11,7 +11,7 @@ const messages = ruleMessages(ruleName, { expectedAfter: (name) => `Expected newline after at-rule name "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/at-rule-name-space-after/index.js b/lib/rules/at-rule-name-space-after/index.js index c413312aad..35dc9a2858 100644 --- a/lib/rules/at-rule-name-space-after/index.js +++ b/lib/rules/at-rule-name-space-after/index.js @@ -11,7 +11,7 @@ const messages = ruleMessages(ruleName, { expectedAfter: (name) => `Expected single space after at-rule name "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondary, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/at-rule-no-unknown/index.js b/lib/rules/at-rule-no-unknown/index.js index 7a776a1ccb..8a1cd76128 100644 --- a/lib/rules/at-rule-no-unknown/index.js +++ b/lib/rules/at-rule-no-unknown/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejected: (atRule) => `Unexpected unknown at-rule "${atRule}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/at-rule-no-vendor-prefix/index.js b/lib/rules/at-rule-no-vendor-prefix/index.js index 2c61eca940..143f585703 100644 --- a/lib/rules/at-rule-no-vendor-prefix/index.js +++ b/lib/rules/at-rule-no-vendor-prefix/index.js @@ -12,7 +12,7 @@ const messages = ruleMessages(ruleName, { rejected: (p) => `Unexpected vendor-prefixed at-rule "@${p}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondary, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/at-rule-property-required-list/index.js b/lib/rules/at-rule-property-required-list/index.js index d9b8c5095d..fd6afcd8cc 100644 --- a/lib/rules/at-rule-property-required-list/index.js +++ b/lib/rules/at-rule-property-required-list/index.js @@ -12,7 +12,7 @@ const messages = ruleMessages(ruleName, { expected: (property, atRule) => `Expected property "${property}" for at-rule "${atRule}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/at-rule-semicolon-newline-after/index.js b/lib/rules/at-rule-semicolon-newline-after/index.js index c193d0eab7..a57bf4f7f5 100644 --- a/lib/rules/at-rule-semicolon-newline-after/index.js +++ b/lib/rules/at-rule-semicolon-newline-after/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { expectedAfter: () => 'Expected newline after ";"', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondary, context) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/at-rule-semicolon-space-before/index.js b/lib/rules/at-rule-semicolon-space-before/index.js index 710de60d99..f3ce2179ee 100644 --- a/lib/rules/at-rule-semicolon-space-before/index.js +++ b/lib/rules/at-rule-semicolon-space-before/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejectedBefore: () => 'Unexpected whitespace before ";"', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/block-closing-brace-empty-line-before/index.js b/lib/rules/block-closing-brace-empty-line-before/index.js index ee0d6bc721..05de09d6a4 100644 --- a/lib/rules/block-closing-brace-empty-line-before/index.js +++ b/lib/rules/block-closing-brace-empty-line-before/index.js @@ -19,7 +19,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected empty line before closing brace', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/block-closing-brace-newline-after/index.js b/lib/rules/block-closing-brace-newline-after/index.js index cab53d4af2..8b28900c61 100644 --- a/lib/rules/block-closing-brace-newline-after/index.js +++ b/lib/rules/block-closing-brace-newline-after/index.js @@ -20,7 +20,7 @@ const messages = ruleMessages(ruleName, { rejectedAfterMultiLine: () => 'Unexpected whitespace after "}" of a multi-line block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/block-closing-brace-newline-before/index.js b/lib/rules/block-closing-brace-newline-before/index.js index ba6597c548..c0861cc7d0 100644 --- a/lib/rules/block-closing-brace-newline-before/index.js +++ b/lib/rules/block-closing-brace-newline-before/index.js @@ -16,7 +16,7 @@ const messages = ruleMessages(ruleName, { rejectedBeforeMultiLine: 'Unexpected whitespace before "}" of a multi-line block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/block-closing-brace-space-after/index.js b/lib/rules/block-closing-brace-space-after/index.js index 8e872d6217..83bbb8536b 100644 --- a/lib/rules/block-closing-brace-space-after/index.js +++ b/lib/rules/block-closing-brace-space-after/index.js @@ -19,7 +19,7 @@ const messages = ruleMessages(ruleName, { rejectedAfterMultiLine: () => 'Unexpected whitespace after "}" of a multi-line block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/block-closing-brace-space-before/index.js b/lib/rules/block-closing-brace-space-before/index.js index fd714ee5e0..23c6b7c06d 100644 --- a/lib/rules/block-closing-brace-space-before/index.js +++ b/lib/rules/block-closing-brace-space-before/index.js @@ -19,7 +19,7 @@ const messages = ruleMessages(ruleName, { rejectedBeforeMultiLine: () => 'Unexpected whitespace before "}" of a multi-line block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/block-no-empty/index.js b/lib/rules/block-no-empty/index.js index 438deee732..c66437e988 100644 --- a/lib/rules/block-no-empty/index.js +++ b/lib/rules/block-no-empty/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected empty block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/block-opening-brace-newline-after/index.js b/lib/rules/block-opening-brace-newline-after/index.js index d5bbc5883f..e7e8a88819 100644 --- a/lib/rules/block-opening-brace-newline-after/index.js +++ b/lib/rules/block-opening-brace-newline-after/index.js @@ -18,7 +18,7 @@ const messages = ruleMessages(ruleName, { rejectedAfterMultiLine: () => 'Unexpected whitespace after "{" of a multi-line block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/block-opening-brace-newline-before/index.js b/lib/rules/block-opening-brace-newline-before/index.js index f5d70fc899..c5be40220b 100644 --- a/lib/rules/block-opening-brace-newline-before/index.js +++ b/lib/rules/block-opening-brace-newline-before/index.js @@ -19,7 +19,7 @@ const messages = ruleMessages(ruleName, { rejectedBeforeMultiLine: () => 'Unexpected whitespace before "{" of a multi-line block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/block-opening-brace-space-after/index.js b/lib/rules/block-opening-brace-space-after/index.js index fb80c9ecfa..5d368b1535 100644 --- a/lib/rules/block-opening-brace-space-after/index.js +++ b/lib/rules/block-opening-brace-space-after/index.js @@ -20,7 +20,7 @@ const messages = ruleMessages(ruleName, { rejectedAfterMultiLine: () => 'Unexpected whitespace after "{" of a multi-line block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/block-opening-brace-space-before/index.js b/lib/rules/block-opening-brace-space-before/index.js index df5f64b135..dceaca220c 100644 --- a/lib/rules/block-opening-brace-space-before/index.js +++ b/lib/rules/block-opening-brace-space-before/index.js @@ -22,7 +22,7 @@ const messages = ruleMessages(ruleName, { rejectedBeforeMultiLine: () => 'Unexpected whitespace before "{" of a multi-line block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/color-function-notation/index.js b/lib/rules/color-function-notation/index.js index d48e7f289a..5563c5317c 100644 --- a/lib/rules/color-function-notation/index.js +++ b/lib/rules/color-function-notation/index.js @@ -18,7 +18,7 @@ const messages = ruleMessages(ruleName, { const LEGACY_FUNCS = new Set(['rgba', 'hsla']); const LEGACY_NOTATION_FUNCS = new Set(['rgb', 'rgba', 'hsl', 'hsla']); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/color-hex-alpha/index.js b/lib/rules/color-hex-alpha/index.js index b8dd8c0098..4de66e91d1 100644 --- a/lib/rules/color-hex-alpha/index.js +++ b/lib/rules/color-hex-alpha/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { const HEX = /^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i; -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/color-hex-case/index.js b/lib/rules/color-hex-case/index.js index a99d484081..19a2f4c534 100644 --- a/lib/rules/color-hex-case/index.js +++ b/lib/rules/color-hex-case/index.js @@ -18,7 +18,7 @@ const messages = ruleMessages(ruleName, { const HEX = /^#[0-9A-Za-z]+/; const IGNORED_FUNCTIONS = new Set(['url']); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/color-hex-length/index.js b/lib/rules/color-hex-length/index.js index 1b75a1e001..3a99cbb3c4 100644 --- a/lib/rules/color-hex-length/index.js +++ b/lib/rules/color-hex-length/index.js @@ -18,7 +18,7 @@ const messages = ruleMessages(ruleName, { const HEX = /^#[0-9A-Za-z]+/; const IGNORED_FUNCTIONS = new Set(['url']); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/color-named/index.js b/lib/rules/color-named/index.js index 8473ac98a5..a5f11527b5 100644 --- a/lib/rules/color-named/index.js +++ b/lib/rules/color-named/index.js @@ -25,7 +25,7 @@ const messages = ruleMessages(ruleName, { // Todo tested on case insensitivity const NODE_TYPES = new Set(['word', 'function']); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/color-no-hex/index.js b/lib/rules/color-no-hex/index.js index 65e49aa3f9..c9d46c9ad9 100644 --- a/lib/rules/color-no-hex/index.js +++ b/lib/rules/color-no-hex/index.js @@ -17,7 +17,7 @@ const messages = ruleMessages(ruleName, { const HEX = /^#[0-9A-Za-z]+/; const IGNORED_FUNCTIONS = new Set(['url']); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/color-no-invalid-hex/index.js b/lib/rules/color-no-invalid-hex/index.js index e4a353f9d7..94fb9a2ad1 100644 --- a/lib/rules/color-no-invalid-hex/index.js +++ b/lib/rules/color-no-invalid-hex/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejected: (hex) => `Unexpected invalid hex color "${hex}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/comment-empty-line-before/index.js b/lib/rules/comment-empty-line-before/index.js index 7f6eeea032..68f6237335 100644 --- a/lib/rules/comment-empty-line-before/index.js +++ b/lib/rules/comment-empty-line-before/index.js @@ -23,7 +23,7 @@ const messages = ruleMessages(ruleName, { const stylelintCommandPrefix = 'stylelint-'; -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/comment-no-empty/index.js b/lib/rules/comment-no-empty/index.js index 57a9ebcf27..4f14286852 100644 --- a/lib/rules/comment-no-empty/index.js +++ b/lib/rules/comment-no-empty/index.js @@ -11,7 +11,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected empty comment', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/comment-pattern/index.js b/lib/rules/comment-pattern/index.js index aacb46708e..bb1946bba7 100644 --- a/lib/rules/comment-pattern/index.js +++ b/lib/rules/comment-pattern/index.js @@ -11,7 +11,7 @@ const messages = ruleMessages(ruleName, { expected: (pattern) => `Expected comment to match pattern "${pattern}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/comment-whitespace-inside/index.js b/lib/rules/comment-whitespace-inside/index.js index e895a8ab38..b5dccb67c8 100644 --- a/lib/rules/comment-whitespace-inside/index.js +++ b/lib/rules/comment-whitespace-inside/index.js @@ -37,7 +37,7 @@ function addWhitespaceAfter(comment) { } } -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/comment-word-disallowed-list/index.js b/lib/rules/comment-word-disallowed-list/index.js index c1802c33cf..f6fa3be794 100644 --- a/lib/rules/comment-word-disallowed-list/index.js +++ b/lib/rules/comment-word-disallowed-list/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejected: (pattern) => `Unexpected word matching pattern "${pattern}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/custom-media-pattern/index.js b/lib/rules/custom-media-pattern/index.js index 05c3fa538c..1340c955c9 100644 --- a/lib/rules/custom-media-pattern/index.js +++ b/lib/rules/custom-media-pattern/index.js @@ -12,7 +12,7 @@ const messages = ruleMessages(ruleName, { expected: (pattern) => `Expected custom media query name to match pattern "${pattern}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/custom-property-empty-line-before/index.js b/lib/rules/custom-property-empty-line-before/index.js index 7193c19b90..d813ddd388 100644 --- a/lib/rules/custom-property-empty-line-before/index.js +++ b/lib/rules/custom-property-empty-line-before/index.js @@ -23,7 +23,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected empty line before custom property', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/custom-property-no-missing-var-function/index.js b/lib/rules/custom-property-no-missing-var-function/index.js index 17fe13d828..ce08cb0de2 100644 --- a/lib/rules/custom-property-no-missing-var-function/index.js +++ b/lib/rules/custom-property-no-missing-var-function/index.js @@ -14,7 +14,7 @@ const messages = ruleMessages(ruleName, { rejected: (customProperty) => `Unexpected missing var function for "${customProperty}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/custom-property-pattern/index.js b/lib/rules/custom-property-pattern/index.js index 2cb82808ea..ee1399ccd6 100644 --- a/lib/rules/custom-property-pattern/index.js +++ b/lib/rules/custom-property-pattern/index.js @@ -12,7 +12,7 @@ const messages = ruleMessages(ruleName, { expected: (pattern) => `Expected custom property name to match pattern "${pattern}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/declaration-bang-space-after/index.js b/lib/rules/declaration-bang-space-after/index.js index e02e04cde3..94ce0411b7 100644 --- a/lib/rules/declaration-bang-space-after/index.js +++ b/lib/rules/declaration-bang-space-after/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejectedAfter: () => 'Unexpected whitespace after "!"', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/declaration-bang-space-before/index.js b/lib/rules/declaration-bang-space-before/index.js index 1adf6266cb..5cd79808a7 100644 --- a/lib/rules/declaration-bang-space-before/index.js +++ b/lib/rules/declaration-bang-space-before/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejectedBefore: () => 'Unexpected whitespace before "!"', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/declaration-block-no-duplicate-custom-properties/index.js b/lib/rules/declaration-block-no-duplicate-custom-properties/index.js index e73819a0a0..fcb9b7fe73 100644 --- a/lib/rules/declaration-block-no-duplicate-custom-properties/index.js +++ b/lib/rules/declaration-block-no-duplicate-custom-properties/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejected: (property) => `Unexpected duplicate "${property}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/declaration-block-no-duplicate-properties/index.js b/lib/rules/declaration-block-no-duplicate-properties/index.js index 71ade3a9a9..b6a0ae4441 100644 --- a/lib/rules/declaration-block-no-duplicate-properties/index.js +++ b/lib/rules/declaration-block-no-duplicate-properties/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejected: (property) => `Unexpected duplicate "${property}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/declaration-block-no-redundant-longhand-properties/index.js b/lib/rules/declaration-block-no-redundant-longhand-properties/index.js index 794a0e6049..2a1a359cc9 100644 --- a/lib/rules/declaration-block-no-redundant-longhand-properties/index.js +++ b/lib/rules/declaration-block-no-redundant-longhand-properties/index.js @@ -16,7 +16,7 @@ const messages = ruleMessages(ruleName, { expected: (props) => `Expected shorthand property "${props}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/declaration-block-no-shorthand-property-overrides/index.js b/lib/rules/declaration-block-no-shorthand-property-overrides/index.js index ef07bed496..bf27f2463b 100644 --- a/lib/rules/declaration-block-no-shorthand-property-overrides/index.js +++ b/lib/rules/declaration-block-no-shorthand-property-overrides/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejected: (shorthand, original) => `Unexpected shorthand "${shorthand}" after "${original}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/declaration-block-semicolon-newline-after/index.js b/lib/rules/declaration-block-semicolon-newline-after/index.js index b09081196d..3ad4c40417 100644 --- a/lib/rules/declaration-block-semicolon-newline-after/index.js +++ b/lib/rules/declaration-block-semicolon-newline-after/index.js @@ -17,7 +17,7 @@ const messages = ruleMessages(ruleName, { rejectedAfterMultiLine: () => 'Unexpected newline after ";" in a multi-line declaration block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/declaration-block-semicolon-newline-before/index.js b/lib/rules/declaration-block-semicolon-newline-before/index.js index c8d10a85e7..7f844bb692 100644 --- a/lib/rules/declaration-block-semicolon-newline-before/index.js +++ b/lib/rules/declaration-block-semicolon-newline-before/index.js @@ -16,7 +16,7 @@ const messages = ruleMessages(ruleName, { 'Unexpected whitespace before ";" in a multi-line declaration block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/declaration-block-semicolon-space-after/index.js b/lib/rules/declaration-block-semicolon-space-after/index.js index c661c4ee0c..be6fc20b2c 100644 --- a/lib/rules/declaration-block-semicolon-space-after/index.js +++ b/lib/rules/declaration-block-semicolon-space-after/index.js @@ -19,7 +19,7 @@ const messages = ruleMessages(ruleName, { 'Unexpected whitespace after ";" in a single-line declaration block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/declaration-block-semicolon-space-before/index.js b/lib/rules/declaration-block-semicolon-space-before/index.js index f3eaa222e9..bcb9216b1a 100644 --- a/lib/rules/declaration-block-semicolon-space-before/index.js +++ b/lib/rules/declaration-block-semicolon-space-before/index.js @@ -20,7 +20,7 @@ const messages = ruleMessages(ruleName, { 'Unexpected whitespace before ";" in a single-line declaration block', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/declaration-block-single-line-max-declarations/index.js b/lib/rules/declaration-block-single-line-max-declarations/index.js index 845cfa7b98..9c40a51da0 100644 --- a/lib/rules/declaration-block-single-line-max-declarations/index.js +++ b/lib/rules/declaration-block-single-line-max-declarations/index.js @@ -14,7 +14,7 @@ const messages = ruleMessages(ruleName, { expected: (max) => `Expected no more than ${max} ${max === 1 ? 'declaration' : 'declarations'}`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/declaration-block-trailing-semicolon/index.js b/lib/rules/declaration-block-trailing-semicolon/index.js index 8719a79f06..ed8ba1fb15 100644 --- a/lib/rules/declaration-block-trailing-semicolon/index.js +++ b/lib/rules/declaration-block-trailing-semicolon/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected trailing semicolon', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/declaration-colon-newline-after/index.js b/lib/rules/declaration-colon-newline-after/index.js index 4b003e68e6..899cf5e9e4 100644 --- a/lib/rules/declaration-colon-newline-after/index.js +++ b/lib/rules/declaration-colon-newline-after/index.js @@ -14,7 +14,7 @@ const messages = ruleMessages(ruleName, { expectedAfterMultiLine: () => 'Expected newline after ":" with a multi-line declaration', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/declaration-colon-space-after/index.js b/lib/rules/declaration-colon-space-after/index.js index 91b235fb63..fdf73df1b8 100644 --- a/lib/rules/declaration-colon-space-after/index.js +++ b/lib/rules/declaration-colon-space-after/index.js @@ -14,7 +14,7 @@ const messages = ruleMessages(ruleName, { expectedAfterSingleLine: () => 'Expected single space after ":" with a single-line declaration', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/declaration-colon-space-before/index.js b/lib/rules/declaration-colon-space-before/index.js index d9cce89917..8baab38bea 100644 --- a/lib/rules/declaration-colon-space-before/index.js +++ b/lib/rules/declaration-colon-space-before/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejectedBefore: () => 'Unexpected whitespace before ":"', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/declaration-empty-line-before/index.js b/lib/rules/declaration-empty-line-before/index.js index bf0512cd6c..43e971c8e9 100644 --- a/lib/rules/declaration-empty-line-before/index.js +++ b/lib/rules/declaration-empty-line-before/index.js @@ -24,7 +24,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected empty line before declaration', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/declaration-no-important/index.js b/lib/rules/declaration-no-important/index.js index 0fd42bee69..0e0e74bdb4 100644 --- a/lib/rules/declaration-no-important/index.js +++ b/lib/rules/declaration-no-important/index.js @@ -10,7 +10,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected !important', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/declaration-property-unit-allowed-list/index.js b/lib/rules/declaration-property-unit-allowed-list/index.js index 9b35001fbf..3e08c649db 100644 --- a/lib/rules/declaration-property-unit-allowed-list/index.js +++ b/lib/rules/declaration-property-unit-allowed-list/index.js @@ -17,7 +17,7 @@ const messages = ruleMessages(ruleName, { rejected: (property, unit) => `Unexpected unit "${unit}" for property "${property}"`, }); -/** @type {import('stylelint').StylelintRule>} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/declaration-property-unit-disallowed-list/index.js b/lib/rules/declaration-property-unit-disallowed-list/index.js index c2113686f3..b6a31c2116 100644 --- a/lib/rules/declaration-property-unit-disallowed-list/index.js +++ b/lib/rules/declaration-property-unit-disallowed-list/index.js @@ -16,7 +16,7 @@ const messages = ruleMessages(ruleName, { rejected: (property, unit) => `Unexpected unit "${unit}" for property "${property}"`, }); -/** @type {import('stylelint').StylelintRule>} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/declaration-property-value-allowed-list/index.js b/lib/rules/declaration-property-value-allowed-list/index.js index 7177e31be6..ff3acfbc58 100644 --- a/lib/rules/declaration-property-value-allowed-list/index.js +++ b/lib/rules/declaration-property-value-allowed-list/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejected: (property, value) => `Unexpected value "${value}" for property "${property}"`, }); -/** @type {import('stylelint').StylelintRule>} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/declaration-property-value-disallowed-list/index.js b/lib/rules/declaration-property-value-disallowed-list/index.js index 77af31eff2..b59713ceb1 100644 --- a/lib/rules/declaration-property-value-disallowed-list/index.js +++ b/lib/rules/declaration-property-value-disallowed-list/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejected: (property, value) => `Unexpected value "${value}" for property "${property}"`, }); -/** @type {import('stylelint').StylelintRule>} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/font-family-name-quotes/index.js b/lib/rules/font-family-name-quotes/index.js index 54dc750e82..9e507908e6 100644 --- a/lib/rules/font-family-name-quotes/index.js +++ b/lib/rules/font-family-name-quotes/index.js @@ -56,7 +56,7 @@ function quotesRequired(family) { .some((word) => /^(?:-?\d|--)/.test(word) || !/^[-\w\u{00A0}-\u{10FFFF}]+$/u.test(word)); } -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/font-family-no-duplicate-names/index.js b/lib/rules/font-family-no-duplicate-names/index.js index 25f759f9d7..4e8b1af87b 100644 --- a/lib/rules/font-family-no-duplicate-names/index.js +++ b/lib/rules/font-family-no-duplicate-names/index.js @@ -21,7 +21,7 @@ const messages = ruleMessages(ruleName, { const isFamilyNameKeyword = (node) => !('quote' in node) && keywordSets.fontFamilyKeywords.has(node.value.toLowerCase()); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/font-family-no-missing-generic-family-keyword/index.js b/lib/rules/font-family-no-missing-generic-family-keyword/index.js index 4c4124ce71..02ddfe8a45 100644 --- a/lib/rules/font-family-no-missing-generic-family-keyword/index.js +++ b/lib/rules/font-family-no-missing-generic-family-keyword/index.js @@ -36,7 +36,7 @@ const isLastFontFamilyVariable = (value) => { return lastValue != null && (isVariable(lastValue) || !isStandardSyntaxValue(lastValue)); }; -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/font-weight-notation/index.js b/lib/rules/font-weight-notation/index.js index 7c7aa2f134..c741f4db56 100644 --- a/lib/rules/font-weight-notation/index.js +++ b/lib/rules/font-weight-notation/index.js @@ -24,7 +24,7 @@ const INITIAL_KEYWORD = 'initial'; const NORMAL_KEYWORD = 'normal'; const WEIGHTS_WITH_KEYWORD_EQUIVALENTS = new Set(['400', '700']); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/function-allowed-list/index.js b/lib/rules/function-allowed-list/index.js index 5ac3b71108..e96b8486c3 100644 --- a/lib/rules/function-allowed-list/index.js +++ b/lib/rules/function-allowed-list/index.js @@ -16,7 +16,7 @@ const messages = ruleMessages(ruleName, { rejected: (name) => `Unexpected function "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { const list = [primary].flat(); diff --git a/lib/rules/function-calc-no-unspaced-operator/index.js b/lib/rules/function-calc-no-unspaced-operator/index.js index 100026d998..5a7323db35 100644 --- a/lib/rules/function-calc-no-unspaced-operator/index.js +++ b/lib/rules/function-calc-no-unspaced-operator/index.js @@ -18,7 +18,7 @@ const messages = ruleMessages(ruleName, { /** @typedef {{ index: number, insert: boolean }} SymbolToFix */ -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/function-comma-newline-after/index.js b/lib/rules/function-comma-newline-after/index.js index 876528e585..2d25452258 100644 --- a/lib/rules/function-comma-newline-after/index.js +++ b/lib/rules/function-comma-newline-after/index.js @@ -14,7 +14,7 @@ const messages = ruleMessages(ruleName, { rejectedAfterMultiLine: () => 'Unexpected whitespace after "," in a multi-line function', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/function-comma-newline-before/index.js b/lib/rules/function-comma-newline-before/index.js index 35d2a4257c..cb4e80e595 100644 --- a/lib/rules/function-comma-newline-before/index.js +++ b/lib/rules/function-comma-newline-before/index.js @@ -14,7 +14,7 @@ const messages = ruleMessages(ruleName, { rejectedBeforeMultiLine: () => 'Unexpected whitespace before "," in a multi-line function', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/function-comma-space-after/index.js b/lib/rules/function-comma-space-after/index.js index a61962c63c..9d16340f7a 100644 --- a/lib/rules/function-comma-space-after/index.js +++ b/lib/rules/function-comma-space-after/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejectedAfterSingleLine: () => 'Unexpected whitespace after "," in a single-line function', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/function-comma-space-before/index.js b/lib/rules/function-comma-space-before/index.js index 1e077032fb..0daac1a589 100644 --- a/lib/rules/function-comma-space-before/index.js +++ b/lib/rules/function-comma-space-before/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejectedBeforeSingleLine: () => 'Unexpected whitespace before "," in a single-line function', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/function-disallowed-list/index.js b/lib/rules/function-disallowed-list/index.js index 93a5d0361a..1e040545e9 100644 --- a/lib/rules/function-disallowed-list/index.js +++ b/lib/rules/function-disallowed-list/index.js @@ -16,7 +16,7 @@ const messages = ruleMessages(ruleName, { rejected: (name) => `Unexpected function "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/function-linear-gradient-no-nonstandard-direction/index.js b/lib/rules/function-linear-gradient-no-nonstandard-direction/index.js index 000823c53f..ae7b786c5b 100644 --- a/lib/rules/function-linear-gradient-no-nonstandard-direction/index.js +++ b/lib/rules/function-linear-gradient-no-nonstandard-direction/index.js @@ -42,7 +42,7 @@ function isStandardDirection(source, withToPrefix) { return false; } -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/function-max-empty-lines/index.js b/lib/rules/function-max-empty-lines/index.js index e27e7062d2..71431727a5 100644 --- a/lib/rules/function-max-empty-lines/index.js +++ b/lib/rules/function-max-empty-lines/index.js @@ -23,7 +23,7 @@ function placeIndexOnValueStart(decl) { return decl.prop.length + decl.raws.between.length - 1; } -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const maxAdjacentNewlines = primary + 1; diff --git a/lib/rules/function-name-case/index.js b/lib/rules/function-name-case/index.js index 3056875add..e446046411 100644 --- a/lib/rules/function-name-case/index.js +++ b/lib/rules/function-name-case/index.js @@ -24,7 +24,7 @@ keywordSets.camelCaseFunctionNames.forEach((func) => { mapLowercaseFunctionNamesToCamelCase.set(func.toLowerCase(), func); }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/function-parentheses-newline-inside/index.js b/lib/rules/function-parentheses-newline-inside/index.js index c1c2179251..2dc9acd768 100644 --- a/lib/rules/function-parentheses-newline-inside/index.js +++ b/lib/rules/function-parentheses-newline-inside/index.js @@ -21,7 +21,7 @@ const messages = ruleMessages(ruleName, { rejectedClosingMultiLine: 'Unexpected whitespace before ")" in a multi-line function', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/function-parentheses-space-inside/index.js b/lib/rules/function-parentheses-space-inside/index.js index 77ef2c8200..e799aae3cf 100644 --- a/lib/rules/function-parentheses-space-inside/index.js +++ b/lib/rules/function-parentheses-space-inside/index.js @@ -23,7 +23,7 @@ const messages = ruleMessages(ruleName, { rejectedClosingSingleLine: 'Unexpected whitespace before ")" in a single-line function', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/function-url-no-scheme-relative/index.js b/lib/rules/function-url-no-scheme-relative/index.js index 4b4bd5d166..1a7c2b2518 100644 --- a/lib/rules/function-url-no-scheme-relative/index.js +++ b/lib/rules/function-url-no-scheme-relative/index.js @@ -12,7 +12,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected scheme-relative url', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/function-url-quotes/index.js b/lib/rules/function-url-quotes/index.js index 2e5c0d28c0..fe3d0f2dae 100644 --- a/lib/rules/function-url-quotes/index.js +++ b/lib/rules/function-url-quotes/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejected: (functionName) => `Unexpected quotes around "${functionName}" function argument`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/function-url-scheme-allowed-list/index.js b/lib/rules/function-url-scheme-allowed-list/index.js index 52ca450213..93384270b0 100644 --- a/lib/rules/function-url-scheme-allowed-list/index.js +++ b/lib/rules/function-url-scheme-allowed-list/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejected: (scheme) => `Unexpected URL scheme "${scheme}:"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/function-url-scheme-disallowed-list/index.js b/lib/rules/function-url-scheme-disallowed-list/index.js index 308f83402e..65875b3ebe 100644 --- a/lib/rules/function-url-scheme-disallowed-list/index.js +++ b/lib/rules/function-url-scheme-disallowed-list/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejected: (scheme) => `Unexpected URL scheme "${scheme}:"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/function-whitespace-after/index.js b/lib/rules/function-whitespace-after/index.js index 36219f5c44..0465be7d94 100644 --- a/lib/rules/function-whitespace-after/index.js +++ b/lib/rules/function-whitespace-after/index.js @@ -19,7 +19,7 @@ const messages = ruleMessages(ruleName, { const ACCEPTABLE_AFTER_CLOSING_PAREN = new Set([')', ',', '}', ':', '/', undefined]); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/hue-degree-notation/index.js b/lib/rules/hue-degree-notation/index.js index 88e0f6b415..f6f00346cd 100644 --- a/lib/rules/hue-degree-notation/index.js +++ b/lib/rules/hue-degree-notation/index.js @@ -20,7 +20,7 @@ const HUE_FIRST_ARG_FUNCS = ['hsl', 'hsla', 'hwb']; const HUE_THIRD_ARG_FUNCS = ['lch']; const HUE_FUNCS = new Set([...HUE_FIRST_ARG_FUNCS, ...HUE_THIRD_ARG_FUNCS]); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/indentation/index.js b/lib/rules/indentation/index.js index c7fdb30fa4..f5d7d4af6c 100644 --- a/lib/rules/indentation/index.js +++ b/lib/rules/indentation/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { expected: (x) => `Expected indentation of ${x}`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions = {}, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/index.js b/lib/rules/index.js index c140ce59c3..1a5cb09e28 100644 --- a/lib/rules/index.js +++ b/lib/rules/index.js @@ -4,9 +4,7 @@ const importLazy = require('import-lazy'); -/** @typedef {import('stylelint').StylelintRule} StylelintRule */ - -/** @type {{[k: string]: StylelintRule}} */ +/** @type {typeof import('stylelint').rules} */ const rules = { 'alpha-value-notation': importLazy(() => require('./alpha-value-notation'))(), 'at-rule-allowed-list': importLazy(() => require('./at-rule-allowed-list'))(), diff --git a/lib/rules/keyframe-declaration-no-important/index.js b/lib/rules/keyframe-declaration-no-important/index.js index 1449d031aa..ee883b0f3b 100644 --- a/lib/rules/keyframe-declaration-no-important/index.js +++ b/lib/rules/keyframe-declaration-no-important/index.js @@ -10,7 +10,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected !important', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/keyframes-name-pattern/index.js b/lib/rules/keyframes-name-pattern/index.js index 33ccc3a0a4..0b0cd6b973 100644 --- a/lib/rules/keyframes-name-pattern/index.js +++ b/lib/rules/keyframes-name-pattern/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { `Expected keyframe name "${keyframeName}" to match pattern "${pattern}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/length-zero-no-unit/index.js b/lib/rules/length-zero-no-unit/index.js index cbc9e8ca03..4cb3625ec7 100644 --- a/lib/rules/length-zero-no-unit/index.js +++ b/lib/rules/length-zero-no-unit/index.js @@ -24,7 +24,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected unit', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/linebreaks/index.js b/lib/rules/linebreaks/index.js index 7763fb337c..21beee5a1f 100644 --- a/lib/rules/linebreaks/index.js +++ b/lib/rules/linebreaks/index.js @@ -11,7 +11,7 @@ const messages = ruleMessages(ruleName, { expected: (linebreak) => `Expected linebreak to be ${linebreak}`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/max-empty-lines/index.js b/lib/rules/max-empty-lines/index.js index 678a39b488..88242ea323 100644 --- a/lib/rules/max-empty-lines/index.js +++ b/lib/rules/max-empty-lines/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { expected: (max) => `Expected no more than ${max} empty ${max === 1 ? 'line' : 'lines'}`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { let emptyLines = 0; let lastIndex = -1; diff --git a/lib/rules/max-line-length/index.js b/lib/rules/max-line-length/index.js index 8dc1c9cc43..ea22b10af3 100644 --- a/lib/rules/max-line-length/index.js +++ b/lib/rules/max-line-length/index.js @@ -19,7 +19,7 @@ const messages = ruleMessages(ruleName, { `Expected line length to be no more than ${max} ${max === 1 ? 'character' : 'characters'}`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/max-nesting-depth/index.js b/lib/rules/max-nesting-depth/index.js index 4f8aa3f749..0670c9aafa 100644 --- a/lib/rules/max-nesting-depth/index.js +++ b/lib/rules/max-nesting-depth/index.js @@ -16,7 +16,7 @@ const messages = ruleMessages(ruleName, { expected: (depth) => `Expected nesting depth to be no more than ${depth}`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { /** * @param {import('postcss').Node} node diff --git a/lib/rules/media-feature-colon-space-after/index.js b/lib/rules/media-feature-colon-space-after/index.js index 849b308277..987f1e0149 100644 --- a/lib/rules/media-feature-colon-space-after/index.js +++ b/lib/rules/media-feature-colon-space-after/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejectedAfter: () => 'Unexpected whitespace after ":"', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/media-feature-colon-space-before/index.js b/lib/rules/media-feature-colon-space-before/index.js index 6d871aa941..ea7f5dde36 100644 --- a/lib/rules/media-feature-colon-space-before/index.js +++ b/lib/rules/media-feature-colon-space-before/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejectedBefore: () => 'Unexpected whitespace before ":"', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/media-feature-name-allowed-list/index.js b/lib/rules/media-feature-name-allowed-list/index.js index 080b401a09..702f74ef64 100644 --- a/lib/rules/media-feature-name-allowed-list/index.js +++ b/lib/rules/media-feature-name-allowed-list/index.js @@ -18,7 +18,7 @@ const messages = ruleMessages(ruleName, { rejected: (name) => `Unexpected media feature name "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/media-feature-name-case/index.js b/lib/rules/media-feature-name-case/index.js index a18f55bc21..326774653e 100644 --- a/lib/rules/media-feature-name-case/index.js +++ b/lib/rules/media-feature-name-case/index.js @@ -16,7 +16,7 @@ const messages = ruleMessages(ruleName, { expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/media-feature-name-disallowed-list/index.js b/lib/rules/media-feature-name-disallowed-list/index.js index ad9f41bb71..68b36246d3 100644 --- a/lib/rules/media-feature-name-disallowed-list/index.js +++ b/lib/rules/media-feature-name-disallowed-list/index.js @@ -18,7 +18,7 @@ const messages = ruleMessages(ruleName, { rejected: (name) => `Unexpected media feature name "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/media-feature-name-no-unknown/index.js b/lib/rules/media-feature-name-no-unknown/index.js index 72c744262e..4652bf03c3 100644 --- a/lib/rules/media-feature-name-no-unknown/index.js +++ b/lib/rules/media-feature-name-no-unknown/index.js @@ -20,7 +20,7 @@ const messages = ruleMessages(ruleName, { rejected: (mediaFeatureName) => `Unexpected unknown media feature name "${mediaFeatureName}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/media-feature-name-no-vendor-prefix/index.js b/lib/rules/media-feature-name-no-vendor-prefix/index.js index c5b1447fe9..9a4fe60aa1 100644 --- a/lib/rules/media-feature-name-no-vendor-prefix/index.js +++ b/lib/rules/media-feature-name-no-vendor-prefix/index.js @@ -11,7 +11,7 @@ const messages = ruleMessages(ruleName, { rejected: 'Unexpected vendor-prefix', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/media-feature-name-value-allowed-list/index.js b/lib/rules/media-feature-name-value-allowed-list/index.js index 293112f5a1..be936dd15e 100644 --- a/lib/rules/media-feature-name-value-allowed-list/index.js +++ b/lib/rules/media-feature-name-value-allowed-list/index.js @@ -17,7 +17,7 @@ const messages = ruleMessages(ruleName, { rejected: (name, value) => `Unexpected value "${value}" for name "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/media-feature-parentheses-space-inside/index.js b/lib/rules/media-feature-parentheses-space-inside/index.js index 8701180acf..d3b8096216 100644 --- a/lib/rules/media-feature-parentheses-space-inside/index.js +++ b/lib/rules/media-feature-parentheses-space-inside/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejectedClosing: 'Unexpected whitespace before ")"', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/media-feature-range-operator-space-after/index.js b/lib/rules/media-feature-range-operator-space-after/index.js index daf2dfeebc..16036d6662 100644 --- a/lib/rules/media-feature-range-operator-space-after/index.js +++ b/lib/rules/media-feature-range-operator-space-after/index.js @@ -14,7 +14,7 @@ const messages = ruleMessages(ruleName, { rejectedAfter: () => 'Unexpected whitespace after range operator', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/media-feature-range-operator-space-before/index.js b/lib/rules/media-feature-range-operator-space-before/index.js index c4a271bc0a..2a2a5f6b91 100644 --- a/lib/rules/media-feature-range-operator-space-before/index.js +++ b/lib/rules/media-feature-range-operator-space-before/index.js @@ -14,7 +14,7 @@ const messages = ruleMessages(ruleName, { rejectedBefore: () => 'Unexpected whitespace before range operator', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/media-query-list-comma-newline-after/index.js b/lib/rules/media-query-list-comma-newline-after/index.js index 2ef965529c..01c627d3c4 100644 --- a/lib/rules/media-query-list-comma-newline-after/index.js +++ b/lib/rules/media-query-list-comma-newline-after/index.js @@ -14,7 +14,7 @@ const messages = ruleMessages(ruleName, { rejectedAfterMultiLine: () => 'Unexpected whitespace after "," in a multi-line list', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/media-query-list-comma-newline-before/index.js b/lib/rules/media-query-list-comma-newline-before/index.js index 9d7163faa6..f9035fff15 100644 --- a/lib/rules/media-query-list-comma-newline-before/index.js +++ b/lib/rules/media-query-list-comma-newline-before/index.js @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, { rejectedBeforeMultiLine: () => 'Unexpected whitespace before "," in a multi-line list', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { const checker = whitespaceChecker('newline', primary, messages); diff --git a/lib/rules/media-query-list-comma-space-after/index.js b/lib/rules/media-query-list-comma-space-after/index.js index 3d60735642..94d82632f4 100644 --- a/lib/rules/media-query-list-comma-space-after/index.js +++ b/lib/rules/media-query-list-comma-space-after/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejectedAfterSingleLine: () => 'Unexpected whitespace after "," in a single-line list', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/media-query-list-comma-space-before/index.js b/lib/rules/media-query-list-comma-space-before/index.js index ebed744e23..04697cffaf 100644 --- a/lib/rules/media-query-list-comma-space-before/index.js +++ b/lib/rules/media-query-list-comma-space-before/index.js @@ -15,7 +15,7 @@ const messages = ruleMessages(ruleName, { rejectedBeforeSingleLine: () => 'Unexpected whitespace before "," in a single-line list', }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); diff --git a/lib/rules/named-grid-areas-no-invalid/index.js b/lib/rules/named-grid-areas-no-invalid/index.js index 91e5c3e0ae..4e9bd08f8b 100644 --- a/lib/rules/named-grid-areas-no-invalid/index.js +++ b/lib/rules/named-grid-areas-no-invalid/index.js @@ -16,7 +16,7 @@ const messages = ruleMessages(ruleName, { expectedRectangle: (name) => `Expected single filled-in rectangle for "${name}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/no-descending-specificity/index.js b/lib/rules/no-descending-specificity/index.js index 7fa214022a..75eb28534d 100644 --- a/lib/rules/no-descending-specificity/index.js +++ b/lib/rules/no-descending-specificity/index.js @@ -19,7 +19,7 @@ const messages = ruleMessages(ruleName, { rejected: (b, a) => `Expected selector "${b}" to come before selector "${a}"`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/rules/no-duplicate-at-import-rules/index.js b/lib/rules/no-duplicate-at-import-rules/index.js index de4d5c7340..6c4bb6a2a6 100644 --- a/lib/rules/no-duplicate-at-import-rules/index.js +++ b/lib/rules/no-duplicate-at-import-rules/index.js @@ -12,7 +12,7 @@ const messages = ruleMessages(ruleName, { rejected: (atImport) => `Unexpected duplicate @import rule ${atImport}`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary }); diff --git a/lib/rules/no-duplicate-selectors/index.js b/lib/rules/no-duplicate-selectors/index.js index 2cd702f9b4..6bdf52d0d4 100644 --- a/lib/rules/no-duplicate-selectors/index.js +++ b/lib/rules/no-duplicate-selectors/index.js @@ -18,7 +18,7 @@ const messages = ruleMessages(ruleName, { `Unexpected duplicate selector "${selector}", first used at line ${firstDuplicateLine}`, }); -/** @type {import('stylelint').StylelintRule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = validateOptions( diff --git a/lib/standalone.js b/lib/standalone.js index 76d015dd89..10371313c4 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -23,17 +23,18 @@ const DEFAULT_IGNORE_FILENAME = '.stylelintignore'; const ALWAYS_IGNORED_GLOBS = ['**/node_modules/**']; const writeFileAtomic = require('write-file-atomic'); -/** @typedef {import('stylelint').StylelintStandaloneOptions} StylelintStandaloneOptions */ -/** @typedef {import('stylelint').StylelintStandaloneReturnValue} StylelintStandaloneReturnValue */ -/** @typedef {import('stylelint').StylelintResult} StylelintResult */ +/** @typedef {import('stylelint').LinterOptions} LinterOptions */ +/** @typedef {import('stylelint').LinterResult} LinterResult */ +/** @typedef {import('stylelint').LintResult} StylelintResult */ /** @typedef {import('stylelint').Formatter} Formatter */ -/** @typedef {import('stylelint').FormatterIdentifier} FormatterIdentifier */ +/** @typedef {import('stylelint').FormatterType} FormatterType */ /** - * @param {StylelintStandaloneOptions} options - * @returns {Promise} + * + * @param {LinterOptions} options + * @returns {Promise} */ -module.exports = async function standalone({ +async function standalone({ allowEmptyInput = false, cache: useCache = false, cacheLocation, @@ -269,10 +270,10 @@ module.exports = async function standalone({ debug(`Linting complete in ${Date.now() - startTime}ms`); return result; -}; +} /** - * @param {FormatterIdentifier | undefined} selected + * @param {FormatterType | Formatter | undefined} selected * @returns {Formatter} */ function getFormatterFunction(selected) { @@ -297,7 +298,7 @@ function getFormatterFunction(selected) { } /** - * @param {import('stylelint').StylelintInternalApi} stylelint + * @param {import('stylelint').InternalApi} stylelint * @param {any} error * @param {string} [filePath] * @return {Promise} @@ -309,3 +310,5 @@ function handleError(stylelint, error, filePath = undefined) { throw error; } + +module.exports = /** @type {typeof import('stylelint').lint} */ (standalone); diff --git a/lib/utils/checkAgainstRule.js b/lib/utils/checkAgainstRule.js index 75c3415ccc..494569e236 100644 --- a/lib/utils/checkAgainstRule.js +++ b/lib/utils/checkAgainstRule.js @@ -11,13 +11,13 @@ const rules = require('../rules'); * @template {Object} O * @param {{ ruleName: string, - ruleSettings: import('stylelint').StylelintConfigRuleSettings, + ruleSettings: import('stylelint').ConfigRuleSettings, root: import('postcss').Root, }} options * @param {(warning: import('postcss').Warning) => void} callback * @returns {void} */ -module.exports = function checkAgainstRule(options, callback) { +function checkAgainstRule(options, callback) { if (!options) throw new Error( "checkAgainstRule requires an options object with 'ruleName', 'ruleSettings', and 'root' properties", @@ -49,4 +49,8 @@ module.exports = function checkAgainstRule(options, callback) { {}, )(options.root, tmpPostcssResult); tmpPostcssResult.warnings().forEach(callback); -}; +} + +module.exports = /** @type {typeof import('stylelint').utils.checkAgainstRule} */ ( + checkAgainstRule +); diff --git a/lib/utils/getFileIgnorer.js b/lib/utils/getFileIgnorer.js index b412b4ea4e..3f9ecb557c 100644 --- a/lib/utils/getFileIgnorer.js +++ b/lib/utils/getFileIgnorer.js @@ -9,7 +9,7 @@ const isPathNotFoundError = require('./isPathNotFoundError'); const DEFAULT_IGNORE_FILENAME = '.stylelintignore'; -/** @typedef {import('stylelint').StylelintStandaloneOptions} StylelintOptions */ +/** @typedef {import('stylelint').LinterOptions} StylelintOptions */ /** * @param {StylelintOptions} options diff --git a/lib/utils/report.js b/lib/utils/report.js index ce025d07fb..4b6de44e2c 100644 --- a/lib/utils/report.js +++ b/lib/utils/report.js @@ -1,14 +1,6 @@ 'use strict'; -/** @typedef {{ - ruleName: string, - result: import('stylelint').PostcssResult, - message: string, - node: import('postcss').Node, - index?: number, - word?: string, - line?: number -}} Violation */ +/** @typedef {import('stylelint').Violation} Violation */ /** * Report a violation. @@ -22,8 +14,9 @@ * * You *must* pass *either* a node or a line number. * @param {Violation} violation + * @returns {void} */ -module.exports = function report(violation) { +function report(violation) { const ruleName = violation.ruleName; const result = violation.result; const message = violation.message; @@ -86,7 +79,7 @@ module.exports = function report(violation) { result.stylelint.stylelintError = true; } - /** @type {import('stylelint').StylelintWarningOptions} */ + /** @type {import('stylelint').WarningOptions} */ const warningProperties = { severity, rule: ruleName, @@ -108,4 +101,6 @@ module.exports = function report(violation) { (result.stylelint.customMessages && result.stylelint.customMessages[ruleName]) || message; result.warn(warningMessage, warningProperties); -}; +} + +module.exports = /** @type {typeof import('stylelint').utils.report} */ (report); diff --git a/lib/utils/ruleMessages.js b/lib/utils/ruleMessages.js index 1c7ed5be37..a3d39bf245 100644 --- a/lib/utils/ruleMessages.js +++ b/lib/utils/ruleMessages.js @@ -5,26 +5,28 @@ * that provides the same messages postfixed with the rule * that has been violated. * - * @template {import('stylelint').StylelintRuleMessages} T + * @template {import('stylelint').RuleMessages} T + * @template {{[K in keyof T]: T[K]}} R * @param {string} ruleName * @param {T} messages - Object whose keys are message identifiers * and values are either message strings or functions that return message strings - * @returns {T} New message object, whose messages will be marked with the rule name + * @returns {R} New message object, whose messages will be marked with the rule name */ -module.exports = function ruleMessages(ruleName, messages) { - /** @type {T} */ - // @ts-expect-error -- TS2322: Type '{}' is not assignable to type 'T'. - const newMessages = {}; +function ruleMessages(ruleName, messages) { + /** @typedef {keyof T} K */ + const newMessages = /** @type {R} */ ({}); - for (const [messageId, messageText] of Object.entries(messages)) { + for (const [messageId, messageText] of /** @type {[K, T[K]][]} */ (Object.entries(messages))) { if (typeof messageText === 'string') { - // @ts-expect-error -- TS2536: Type 'string' cannot be used to index type 'T'. - newMessages[messageId] = `${messageText} (${ruleName})`; + newMessages[messageId] = /** @type {R[K]} */ (`${messageText} (${ruleName})`); } else { - // @ts-expect-error -- TS2536: Type 'string' cannot be used to index type 'T'. - newMessages[messageId] = (...args) => `${messageText(...args)} (${ruleName})`; + newMessages[messageId] = /** @type {R[K]} */ ( + (...args) => `${messageText(...args)} (${ruleName})` + ); } } return newMessages; -}; +} + +module.exports = /** @type {typeof import('stylelint').utils.ruleMessages} */ (ruleMessages); diff --git a/lib/utils/validateOptions.js b/lib/utils/validateOptions.js index ddf45acb13..12cc1393a6 100644 --- a/lib/utils/validateOptions.js +++ b/lib/utils/validateOptions.js @@ -5,11 +5,9 @@ const { isPlainObject } = require('is-plain-object'); const IGNORED_OPTIONS = new Set(['severity', 'message', 'reportDisables', 'disableFix']); -/** @typedef {(value: unknown) => boolean} PossibleFunc */ - -/** @typedef {boolean | number | string | PossibleFunc} Possible */ - -/** @typedef {{possible?: (undefined | PossibleFunc | Possible[] | Record), actual: unknown, optional?: boolean}} Options */ +/** @typedef {import('stylelint').RuleOptions} RuleOptions */ +/** @typedef {import('stylelint').RuleOptionsPossible} Possible */ +/** @typedef {import('stylelint').RuleOptionsPossibleFunc} PossibleFunc */ /** * Validate a rule's options. @@ -18,7 +16,7 @@ const IGNORED_OPTIONS = new Set(['severity', 'message', 'reportDisables', 'disab * * @param {import('stylelint').PostcssResult} result - postcss result * @param {string} ruleName - * @param {...Options} optionDescriptions - Each optionDescription can + * @param {...RuleOptions} 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 @@ -31,7 +29,7 @@ const IGNORED_OPTIONS = new Set(['severity', 'message', 'reportDisables', 'disab * - `optional` (optional): If this is `true`, `actual` can be undefined. * @return {boolean} Whether or not the options are valid (true = valid) */ -module.exports = function validateOptions(result, ruleName, ...optionDescriptions) { +function validateOptions(result, ruleName, ...optionDescriptions) { let noErrors = true; optionDescriptions.forEach((optionDescription) => { @@ -55,10 +53,10 @@ module.exports = function validateOptions(result, ruleName, ...optionDescription } return noErrors; -}; +} /** - * @param {Options} opts + * @param {RuleOptions} opts * @param {string} ruleName * @param {(message: string) => void} complain */ @@ -173,3 +171,5 @@ function isValid(possible, actual) { return false; } + +module.exports = /** @type {typeof import('stylelint').utils.validateOptions} */ (validateOptions); diff --git a/package-lock.json b/package-lock.json index 237507adf8..1e592b11e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60,6 +60,7 @@ "@types/global-modules": "^2.0.0", "@types/globjoin": "^0.1.0", "@types/imurmurhash": "^0.1.1", + "@types/jest": "^27.0.2", "@types/micromatch": "^4.0.2", "@types/normalize-path": "^3.0.0", "@types/postcss-less": "^4.0.1", @@ -1418,6 +1419,16 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/jest": { + "version": "27.0.2", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-27.0.2.tgz", + "integrity": "sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA==", + "dev": true, + "dependencies": { + "jest-diff": "^27.0.0", + "pretty-format": "^27.0.0" + } + }, "node_modules/@types/js-yaml": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.3.tgz", @@ -14098,6 +14109,16 @@ "@types/istanbul-lib-report": "*" } }, + "@types/jest": { + "version": "27.0.2", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-27.0.2.tgz", + "integrity": "sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA==", + "dev": true, + "requires": { + "jest-diff": "^27.0.0", + "pretty-format": "^27.0.0" + } + }, "@types/js-yaml": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.3.tgz", diff --git a/package.json b/package.json index 08239f6794..ea1d9fd0a9 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "bin": { "stylelint": "bin/stylelint.js" }, + "types": "types/stylelint/index.d.ts", "files": [ "bin", "CHANGELOG.md", @@ -34,7 +35,8 @@ "docs", "lib", "!**/__tests__", - "!lib/testUtils" + "!lib/testUtils", + "types/stylelint/index.d.ts" ], "scripts": { "benchmark-rule": "node scripts/benchmark-rule.js", @@ -158,6 +160,7 @@ "@types/global-modules": "^2.0.0", "@types/globjoin": "^0.1.0", "@types/imurmurhash": "^0.1.1", + "@types/jest": "^27.0.2", "@types/micromatch": "^4.0.2", "@types/normalize-path": "^3.0.0", "@types/postcss-less": "^4.0.1", diff --git a/types/stylelint/index.d.ts b/types/stylelint/index.d.ts index 6522858f96..9aba4d6b41 100644 --- a/types/stylelint/index.d.ts +++ b/types/stylelint/index.d.ts @@ -1,326 +1,385 @@ declare module 'stylelint' { - import { Comment, Result, Message, Root, Syntax, WarningOptions, Warning } from 'postcss'; - import { GlobbyOptions } from 'globby'; - import { cosmiconfig } from 'cosmiconfig'; - - export type Severity = 'warning' | 'error'; - - export type StylelintConfigExtends = string | Array; - export type StylelintConfigPlugins = string | Array; - export type StylelintConfigProcessor = string | [string, Object]; - export type StylelintConfigProcessors = string | Array; - export type StylelintConfigIgnoreFiles = string | Array; - export type StylelintConfigRuleSettings = - | null - | undefined - | NonNullable - | [NonNullable] - | [NonNullable, O]; - export type StylelintConfigRules = { - [ruleName: string]: StylelintConfigRuleSettings; - }; - export type StylelintConfigOverride = Pick< - StylelintConfig, - | 'plugins' - | 'pluginFunctions' - | 'processors' - | 'processorFunctions' - | 'rules' - | 'defaultSeverity' - > & { - files: string | string[]; - }; - - export type DisableOptions = { - except?: Array; - severity?: Severity; - }; - export type DisableSettings = StylelintConfigRuleSettings; - - export type StylelintConfig = { - extends?: StylelintConfigExtends; - plugins?: StylelintConfigPlugins; - pluginFunctions?: { - [pluginName: string]: Function; + import type * as PostCSS from 'postcss'; + import type { GlobbyOptions } from 'globby'; + import type { cosmiconfig } from 'cosmiconfig'; + + namespace stylelint { + export type Severity = 'warning' | 'error'; + + export type ConfigExtends = string | string[]; + export type ConfigPlugins = string | string[]; + export type ConfigProcessor = string | [string, Object]; + export type ConfigProcessors = string | ConfigProcessor[]; + export type ConfigIgnoreFiles = string | string[]; + export type ConfigRuleSettings = + | null + | undefined + | NonNullable + | [NonNullable] + | [NonNullable, O]; + export type ConfigRules = { + [ruleName: string]: ConfigRuleSettings; }; - processors?: StylelintConfigProcessors; - processorFunctions?: Array; - ignoreFiles?: StylelintConfigIgnoreFiles; - ignorePatterns?: string; - rules?: StylelintConfigRules; - codeProcessors?: Array; - resultProcessors?: Array; - quiet?: boolean; - defaultSeverity?: Severity; - ignoreDisables?: DisableSettings; - reportNeedlessDisables?: DisableSettings; - reportInvalidScopeDisables?: DisableSettings; - reportDescriptionlessDisables?: DisableSettings; - overrides?: StylelintConfigOverride[]; - customSyntax?: CustomSyntax; - }; - - // A meta-type that returns a union over all properties of `T` whose values - // have type `U`. - type PropertyNamesOfType = { - [K in keyof T]-?: T[K] extends U ? K : never; - }[keyof T]; - export type DisablePropertyName = PropertyNamesOfType; - - // This type has the same properties as `CosmiconfigResult` from `cosmiconfig`. - export type StylelintCosmiconfigResult = { - config: StylelintConfig; - filepath: string; - isEmpty?: boolean; - } | null; - - export type DisabledRange = { - comment: Comment; - start: number; - strictStart: boolean; - end?: number; - strictEnd?: boolean; - rules?: string[]; - description?: string; - }; - - export type DisabledRangeObject = { - [ruleName: string]: Array; - }; - - export type DisabledWarning = { line: number; rule: string }; - - export type StylelintPostcssResult = { - ruleSeverities: { [k: string]: Severity }; - customMessages: { [k: string]: any }; - quiet?: boolean; - disabledRanges: DisabledRangeObject; - disabledWarnings?: DisabledWarning[]; - ignored?: boolean; - stylelintError?: boolean; - disableWritingFix?: boolean; - config?: StylelintConfig; - ruleDisableFix?: boolean; - }; - - type EmptyResult = { - root: { - nodes?: undefined; - source: { - lang?: undefined; - input: { - file?: string; + export type ConfigOverride = Omit & { + files: string | string[]; + }; + + export type DisableOptions = { + except?: (string | RegExp)[]; + severity?: Severity; + }; + export type DisableSettings = ConfigRuleSettings; + + export type Config = { + extends?: ConfigExtends; + plugins?: ConfigPlugins; + pluginFunctions?: { + [pluginName: string]: Function; + }; + processors?: ConfigProcessors; + processorFunctions?: Function[]; + ignoreFiles?: ConfigIgnoreFiles; + ignorePatterns?: string; + rules?: ConfigRules; + codeProcessors?: Function[]; + resultProcessors?: Function[]; + quiet?: boolean; + defaultSeverity?: Severity; + ignoreDisables?: DisableSettings; + reportNeedlessDisables?: DisableSettings; + reportInvalidScopeDisables?: DisableSettings; + reportDescriptionlessDisables?: DisableSettings; + overrides?: ConfigOverride[]; + customSyntax?: CustomSyntax; + }; + + // A meta-type that returns a union over all properties of `T` whose values + // have type `U`. + type PropertyNamesOfType = { + [K in keyof T]-?: T[K] extends U ? K : never; + }[keyof T]; + export type DisablePropertyName = PropertyNamesOfType; + + // This type has the same properties as `CosmiconfigResult` from `cosmiconfig`. + export type CosmiconfigResult = { + config: Config; + filepath: string; + isEmpty?: boolean; + } | null; + + export type DisabledRange = { + comment: PostCSS.Comment; + start: number; + strictStart: boolean; + end?: number; + strictEnd?: boolean; + rules?: string[]; + description?: string; + }; + + export type DisabledRangeObject = { + [ruleName: string]: DisabledRange[]; + }; + + export type DisabledWarning = { line: number; rule: string }; + + export type StylelintPostcssResult = { + ruleSeverities: { [k: string]: Severity }; + customMessages: { [k: string]: any }; + quiet?: boolean; + disabledRanges: DisabledRangeObject; + disabledWarnings?: DisabledWarning[]; + ignored?: boolean; + stylelintError?: boolean; + disableWritingFix?: boolean; + config?: Config; + ruleDisableFix?: boolean; + }; + + type EmptyResult = { + root: { + nodes?: undefined; + source: { + lang?: undefined; + input: { + file?: string; + }; }; }; + messages: PostCSS.Message[]; + opts: undefined; + }; + + export type WarningOptions = PostCSS.WarningOptions & { + stylelintType?: string; + severity?: Severity; + rule?: string; }; - messages: Message[]; - opts: undefined; - }; - - export type StylelintWarningOptions = WarningOptions & { - stylelintType?: string; - severity?: Severity; - rule?: string; - }; - - export type PostcssResult = (Result | EmptyResult) & { - stylelint: StylelintPostcssResult; - warn(message: string, options?: StylelintWarningOptions): void; - }; - - export type Formatter = ( - results: Array, - returnValue?: StylelintStandaloneReturnValue, - ) => string; - - export type FormatterIdentifier = - | 'compact' - | 'json' - | 'string' - | 'tap' - | 'unix' - | 'verbose' - | Formatter; - - export type CustomSyntax = string | Syntax; - - export type StylelintOptions = { - config?: StylelintConfig; - configFile?: string; - configBasedir?: string; - ignoreDisables?: boolean; - ignorePath?: string; - reportInvalidScopeDisables?: boolean; - reportNeedlessDisables?: boolean; - reportDescriptionlessDisables?: boolean; - syntax?: string; - customSyntax?: CustomSyntax; - fix?: boolean; - }; - - export type StylelintPluginContext = { - fix?: boolean | undefined; - newline?: string | undefined; - }; - - export type StylelintRuleMessages = Record string)>; - - export type StylelintRule

= (( - primaryOption: P, - secondaryOptions: Record, - context: StylelintPluginContext, - ) => (root: Root, result: PostcssResult) => Promise | void) & { - ruleName: string; - messages: StylelintRuleMessages; - primaryOptionArray?: boolean; - }; - - export type GetPostcssOptions = { - code?: string; - codeFilename?: string; - filePath?: string; - codeProcessors?: Array; - syntax?: string; - customSyntax?: CustomSyntax; - }; - - export type GetLintSourceOptions = GetPostcssOptions & { existingPostcssResult?: Result }; - - export type StylelintInternalApi = { - _options: StylelintStandaloneOptions; - _extendExplorer: ReturnType; - _specifiedConfigCache: Map>; - _postcssResultCache: Map; - - _getPostcssResult: (options?: GetPostcssOptions) => Promise; - _lintSource: (options: GetLintSourceOptions) => Promise; - _createStylelintResult: ( - postcssResult: PostcssResult, - filePath?: string, - ) => Promise; - - getConfigForFile: ( - searchPath?: string, - filePath?: string, - ) => Promise; - isPathIgnored: (s?: string) => Promise; - }; - - export type StylelintStandaloneOptions = { - files?: string | Array; - globbyOptions?: GlobbyOptions; - cache?: boolean; - cacheLocation?: string; - code?: string; - codeFilename?: string; - config?: StylelintConfig; - configFile?: string; - configBasedir?: string; - ignoreDisables?: boolean; - ignorePath?: string; - ignorePattern?: string[]; - reportDescriptionlessDisables?: boolean; - reportNeedlessDisables?: boolean; - reportInvalidScopeDisables?: boolean; - maxWarnings?: number; - /** @deprecated Use `customSyntax` instead. */ - syntax?: string; - customSyntax?: CustomSyntax; - formatter?: FormatterIdentifier; - disableDefaultIgnores?: boolean; - fix?: boolean; - allowEmptyInput?: boolean; - quiet?: boolean; - }; - - export type StylelintCssSyntaxError = { - column: number; - file?: string; - input: { + + export type PostcssResult = (PostCSS.Result | EmptyResult) & { + stylelint: StylelintPostcssResult; + warn(message: string, options?: WarningOptions): void; + }; + + export type Formatter = (results: LintResult[], returnValue?: LinterResult) => string; + + export type FormatterType = 'compact' | 'json' | 'string' | 'tap' | 'unix' | 'verbose'; + + export type CustomSyntax = string | PostCSS.Syntax; + + export type PluginContext = { + fix?: boolean | undefined; + newline?: string | undefined; + }; + + export type RuleMessages = { [message: string]: string | ((...args: any[]) => string) }; + + export type RuleOptionsPossibleFunc = (value: unknown) => boolean; + + export type RuleOptionsPossible = boolean | number | string | RuleOptionsPossibleFunc; + + export type RuleOptions = { + actual: unknown; + possible?: + | RuleOptionsPossibleFunc + | RuleOptionsPossible[] + | Record; + optional?: boolean; + }; + + export type RuleBase

= ( + primaryOption: P, + secondaryOptions: Record, + context: PluginContext, + ) => (root: PostCSS.Root, result: PostcssResult) => Promise | void; + + export type Rule

= RuleBase & { + ruleName: string; + messages: RuleMessages; + primaryOptionArray?: boolean; + }; + + export type Plugin

= RuleBase; + + export type GetPostcssOptions = { + code?: string; + codeFilename?: string; + filePath?: string; + codeProcessors?: Function[]; + syntax?: string; + customSyntax?: CustomSyntax; + }; + + export type GetLintSourceOptions = GetPostcssOptions & { + existingPostcssResult?: PostCSS.Result; + }; + + export type LinterOptions = { + files?: string | string[]; + globbyOptions?: GlobbyOptions; + cache?: boolean; + cacheLocation?: string; + code?: string; + codeFilename?: string; + config?: Config; + configFile?: string; + configBasedir?: string; + ignoreDisables?: boolean; + ignorePath?: string; + ignorePattern?: string[]; + reportDescriptionlessDisables?: boolean; + reportNeedlessDisables?: boolean; + reportInvalidScopeDisables?: boolean; + maxWarnings?: number; + /** @deprecated Use `customSyntax` instead. Using this option will result in an error. */ + syntax?: string; + customSyntax?: CustomSyntax; + formatter?: FormatterType | Formatter; + disableDefaultIgnores?: boolean; + fix?: boolean; + allowEmptyInput?: boolean; + quiet?: boolean; + }; + + export type CssSyntaxError = { column: number; file?: string; + input: { + column: number; + file?: string; + line: number; + source: string; + }; line: number; + message: string; + name: string; + reason: string; source: string; }; - line: number; - message: string; - name: string; - reason: string; - source: string; - }; - - export type StylelintWarning = { - line: number; - column: number; - rule: string; - severity: Severity; - text: string; - stylelintType?: string; - }; - - export type StylelintResult = { - source?: string; - deprecations: Array<{ - text: string; - reference: string; - }>; - invalidOptionWarnings: Array<{ + + export type Warning = { + line: number; + column: number; + rule: string; + severity: Severity; text: string; - }>; - parseErrors: Array; - errored?: boolean; - warnings: Array; - ignored?: boolean; - _postcssResult?: PostcssResult; - }; - - export type DisableReportRange = { - rule: string; - start: number; - end?: number; - }; - - export type RangeType = DisabledRange & { used?: boolean }; - - export type StylelintDisableReportEntry = { - source?: string; - ranges: Array; - }; - - export type StylelintStandaloneReturnValue = { - results: Array; - errored: boolean; - output: any; - maxWarningsExceeded?: { - maxWarnings: number; - foundWarnings: number; + stylelintType?: string; + }; + + 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; + }; + + export type DisableReportRange = { + rule: string; + start: number; + end?: number; + }; + + export type RangeType = DisabledRange & { used?: boolean }; + + export type DisableReportEntry = { + source?: string; + ranges: DisableReportRange[]; }; - reportedDisables: StylelintDisableOptionsReport; - descriptionlessDisables?: StylelintDisableOptionsReport; - needlessDisables?: StylelintDisableOptionsReport; - invalidScopeDisables?: StylelintDisableOptionsReport; - }; - - export type StylelintPublicAPI = { - lint: Function; - rules: { [k: string]: StylelintRule }; - formatters: { [k: string]: Formatter }; - createPlugin: ( - ruleName: string, - rule: StylelintRule, - ) => { ruleName: string; rule: StylelintRule }; - createLinter: Function; - utils: { - report: Function; - ruleMessages: Function; - validateOptions: Function; - checkAgainstRule: Function; + + export type LinterResult = { + results: LintResult[]; + errored: boolean; + output: any; + maxWarningsExceeded?: { + maxWarnings: number; + foundWarnings: number; + }; + reportedDisables: DisableOptionsReport; + descriptionlessDisables?: DisableOptionsReport; + needlessDisables?: DisableOptionsReport; + invalidScopeDisables?: DisableOptionsReport; + }; + + export type Violation = { + ruleName: string; + result: PostcssResult; + message: string; + node: PostCSS.Node; + index?: number; + word?: string; + line?: number; }; - }; - export type StylelintDisableOptionsReport = Array; + export type PublicApi = PostCSS.PluginCreator & { + /** + * Runs stylelint with the given options and returns a Promise that + * resolves to the results. + */ + lint: (options: LinterOptions) => Promise; + /** + * Available rules. + */ + rules: { [k: string]: Rule }; + /** + * Result report formatters by name. + */ + formatters: { [k: string]: Formatter }; + /** + * Creates a Stylelint plugin. + */ + createPlugin: (ruleName: string, plugin: Plugin) => { ruleName: string; rule: Rule }; + /** + * Internal use only. Do not use or rely on this method. It may + * change at any time. + * @internal + */ + createLinter: (options: LinterOptions) => InternalApi; + utils: { + /** + * Report a violation. + * + * This function accounts for `disabledRanges` attached to the result. + * That is, if the reported violation 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. + */ + report: (violation: Violation) => void; + /** + * Given an object of violation messages, return another + * that provides the same messages postfixed with the rule + * that has been violated. + */ + ruleMessages: ( + ruleName: string, + messages: T, + ) => R; + /** + * Validate a rule's options. + * + * See existing rules for examples. + */ + 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 }, + 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; + _extendExplorer: ReturnType; + _specifiedConfigCache: Map>; + _postcssResultCache: Map; + + _getPostcssResult: (options?: GetPostcssOptions) => Promise; + _lintSource: (options: GetLintSourceOptions) => Promise; + _createStylelintResult: ( + postcssResult: PostcssResult, + filePath?: string, + ) => Promise; + + getConfigForFile: (searchPath?: string, filePath?: string) => Promise; + isPathIgnored: (s?: string) => Promise; + }; + + export type DisableOptionsReport = DisableReportEntry[]; + + export type PostcssPluginOptions = Omit | Config; + } + + const stylelint: stylelint.PublicApi; - export type PostcssPluginOptions = - | Omit - | StylelintConfig; + export = stylelint; } diff --git a/types/stylelint/type-test.ts b/types/stylelint/type-test.ts new file mode 100644 index 0000000000..edc3482fb6 --- /dev/null +++ b/types/stylelint/type-test.ts @@ -0,0 +1,93 @@ +/** + * This file is never executed. It's just here to check that the type + * definitions for this package are correct when the lint:types script is run. + * + * If the type definitions are correct, the script should pass. If they are not, + * it should fail. + */ + +import type { + LinterOptions, + FormatterType, + LintResult, + LinterResult, + Plugin, + Warning, +} from 'stylelint'; +import stylelint from 'stylelint'; + +const options: Partial = { + allowEmptyInput: true, + code: 'div { color: red }', + files: ['**/**.scss'], + formatter: 'json', + globbyOptions: { + cwd: './', + }, + cache: true, + cacheLocation: './stylelint.cache.json', + ignoreDisables: true, + reportDescriptionlessDisables: true, + reportInvalidScopeDisables: true, + reportNeedlessDisables: true, + ignorePath: 'foo', + customSyntax: 'postcss-scss', + syntax: 'scss', // Removed but still accepted in type definition + config: { + overrides: [ + { + files: ['**/*.scss'], + customSyntax: 'postcss-scss', + }, + ], + }, +}; + +stylelint.lint(options).then((x: LinterResult) => { + const err: boolean = x.errored; + const output: string = x.output; + const results: LintResult[] = x.results; + if (results.length > 0) { + const warnings: Warning[] = results[0].warnings; + } +}); + +const formatter: FormatterType = 'json'; + +const ruleName = 'sample-rule'; +const messages = stylelint.utils.ruleMessages(ruleName, { + violation: 'This a rule violation message', + warning: (reason: string) => `This is not allowed because ${reason}`, +}); +const violationMessage: string = messages.violation; +const violationFunc: (reason: string) => string = messages.warning; + +const testPlugin: Plugin = (options) => { + return (root, result) => { + const validOptions = stylelint.utils.validateOptions(result, ruleName, { actual: options }); + if (!validOptions) { + return; + } + + stylelint.utils.checkAgainstRule( + { + ruleName: 'at-rule-empty-line-before', + ruleSettings: ['always'], + root, + }, + (warning) => { + stylelint.utils.report({ + ruleName, + result, + message: messages.warning(warning.text), + node: root, + index: 1, + word: 'foo', + line: 2, + }); + }, + ); + }; +}; + +stylelint.createPlugin(ruleName, testPlugin);