From 0bb8cf18df1b08a66e849b36b4aaebf78ff1e978 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Fri, 30 Sep 2022 17:07:46 +0900 Subject: [PATCH] Refactor to add function names (#6377) Giving function names (avoiding anonymous) helps debugging. This refactoring relies on the ESLint `func-names` rule: https://eslint.org/docs/latest/rules/func-names --- lib/__tests__/fixtures/processor-fenced-blocks.js | 2 +- .../fixtures/processor-triple-question-marks.js | 2 +- lib/createPartialStylelintResult.js | 2 +- lib/formatters/__tests__/prepareFormatterOutput.js | 2 +- lib/formatters/compactFormatter.js | 7 +++---- lib/formatters/stringFormatter.js | 2 +- lib/formatters/tapFormatter.js | 4 +--- lib/formatters/unixFormatter.js | 4 +--- lib/reportDisables.js | 2 +- lib/rules/block-closing-brace-space-after/index.js | 2 +- .../declaration-block-semicolon-newline-before/index.js | 2 +- .../declaration-block-semicolon-space-after/index.js | 2 +- lib/utils/atRuleParamIndex.js | 2 +- lib/utils/blurComments.js | 2 +- lib/utils/blurFunctionArguments.js | 2 +- lib/utils/blurInterpolation.js | 2 +- lib/utils/configurationError.js | 2 +- lib/utils/getDimension.js | 2 +- lib/utils/getSchemeFromUrl.js | 2 +- lib/utils/hasEmptyBlock.js | 2 +- lib/utils/hasEmptyLine.js | 2 +- lib/utils/hasInterpolation.js | 2 +- lib/utils/hasLessInterpolation.js | 2 +- lib/utils/hasPsvInterpolation.js | 2 +- lib/utils/hasScssInterpolation.js | 2 +- lib/utils/hasTplInterpolation.js | 2 +- lib/utils/isAfterComment.js | 2 +- lib/utils/isAfterStandardPropertyDeclaration.js | 2 +- lib/utils/isBlocklessAtRuleAfterBlocklessAtRule.js | 2 +- .../isBlocklessAtRuleAfterSameNameBlocklessAtRule.js | 2 +- lib/utils/isCounterIncrementCustomIdentValue.js | 2 +- lib/utils/isCounterResetCustomIdentValue.js | 2 +- lib/utils/isCustomElement.js | 2 +- lib/utils/isCustomFunction.js | 2 +- lib/utils/isCustomMediaQuery.js | 2 +- lib/utils/isCustomProperty.js | 2 +- lib/utils/isCustomSelector.js | 2 +- lib/utils/isFirstNested.js | 2 +- lib/utils/isFirstNodeOfRoot.js | 2 +- lib/utils/isKeyframeRule.js | 2 +- lib/utils/isKeyframeSelector.js | 2 +- lib/utils/isLessVariable.js | 2 +- lib/utils/isOnlyWhitespace.js | 9 +++------ lib/utils/isRangeContextMediaFeature.js | 2 +- lib/utils/isScssVariable.js | 2 +- lib/utils/isSingleLineString.js | 2 +- lib/utils/isStandardSyntaxAtRule.js | 2 +- lib/utils/isStandardSyntaxCombinator.js | 2 +- lib/utils/isStandardSyntaxDeclaration.js | 2 +- lib/utils/isStandardSyntaxFunction.js | 2 +- lib/utils/isStandardSyntaxMediaFeature.js | 2 +- lib/utils/isStandardSyntaxMediaFeatureName.js | 2 +- lib/utils/isStandardSyntaxProperty.js | 2 +- lib/utils/isStandardSyntaxRule.js | 2 +- lib/utils/isStandardSyntaxSelector.js | 2 +- lib/utils/isStandardSyntaxTypeSelector.js | 2 +- lib/utils/isStandardSyntaxUrl.js | 2 +- lib/utils/isStandardSyntaxValue.js | 2 +- lib/utils/isValidFontSize.js | 2 +- lib/utils/isValidHex.js | 2 +- lib/utils/isVariable.js | 2 +- lib/utils/isWhitespace.js | 2 +- lib/utils/putIfAbsent.js | 2 +- lib/utils/rawNodeString.js | 2 +- lib/validateDisableSettings.js | 2 +- lib/writeOutputFile.js | 9 +++++---- package.json | 6 ++++++ 67 files changed, 80 insertions(+), 81 deletions(-) diff --git a/lib/__tests__/fixtures/processor-fenced-blocks.js b/lib/__tests__/fixtures/processor-fenced-blocks.js index b155cfddd4..c400f6e7bf 100644 --- a/lib/__tests__/fixtures/processor-fenced-blocks.js +++ b/lib/__tests__/fixtures/processor-fenced-blocks.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function (options = {}) { +module.exports = function processorFencedBlocks(options = {}) { const specialMessage = options.specialMessage || 'was processed'; return { diff --git a/lib/__tests__/fixtures/processor-triple-question-marks.js b/lib/__tests__/fixtures/processor-triple-question-marks.js index 7f9c1de458..b26563a022 100644 --- a/lib/__tests__/fixtures/processor-triple-question-marks.js +++ b/lib/__tests__/fixtures/processor-triple-question-marks.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function () { +module.exports = function processorTripleQuestionMarks() { let found = false; return { diff --git a/lib/createPartialStylelintResult.js b/lib/createPartialStylelintResult.js index d62aec68d8..171dfc9d8f 100644 --- a/lib/createPartialStylelintResult.js +++ b/lib/createPartialStylelintResult.js @@ -8,7 +8,7 @@ * @param {import('stylelint').CssSyntaxError} [cssSyntaxError] * @return {StylelintResult} */ -module.exports = function (postcssResult, cssSyntaxError) { +module.exports = function createPartialStylelintResult(postcssResult, cssSyntaxError) { /** @type {StylelintResult} */ let stylelintResult; /** @type {string | undefined} */ diff --git a/lib/formatters/__tests__/prepareFormatterOutput.js b/lib/formatters/__tests__/prepareFormatterOutput.js index 00da5e02d5..e6e17197ca 100644 --- a/lib/formatters/__tests__/prepareFormatterOutput.js +++ b/lib/formatters/__tests__/prepareFormatterOutput.js @@ -9,7 +9,7 @@ symbolConversions.set('✔', '√'); symbolConversions.set('⚠', '‼'); symbolConversions.set('✖', '×'); -module.exports = function (results, formatter, returnValue) { +module.exports = function prepareFormatterOutput(results, formatter, returnValue) { returnValue = returnValue || { ruleMetadata: {}, }; diff --git a/lib/formatters/compactFormatter.js b/lib/formatters/compactFormatter.js index 667c3b52e7..609dbbdd9b 100644 --- a/lib/formatters/compactFormatter.js +++ b/lib/formatters/compactFormatter.js @@ -3,8 +3,8 @@ /** * @type {import('stylelint').Formatter} */ -const formatter = (results) => - results +module.exports = function compactFormatter(results) { + return results .flatMap((result) => result.warnings.map( (warning) => @@ -16,5 +16,4 @@ const formatter = (results) => ), ) .join('\n'); - -module.exports = formatter; +}; diff --git a/lib/formatters/stringFormatter.js b/lib/formatters/stringFormatter.js index 66fda74afe..ca2c479d57 100644 --- a/lib/formatters/stringFormatter.js +++ b/lib/formatters/stringFormatter.js @@ -247,7 +247,7 @@ function formatter(messages, source, cwd) { /** * @type {import('stylelint').Formatter} */ -module.exports = function (results, returnValue) { +module.exports = function stringFormatter(results, returnValue) { let output = invalidOptionsFormatter(results); output += deprecationsFormatter(results); diff --git a/lib/formatters/tapFormatter.js b/lib/formatters/tapFormatter.js index 01340f82e7..1ef868ca58 100644 --- a/lib/formatters/tapFormatter.js +++ b/lib/formatters/tapFormatter.js @@ -3,7 +3,7 @@ /** * @type {import('stylelint').Formatter} */ -const tapFormatter = (results) => { +module.exports = function tapFormatter(results) { const lines = [`TAP version 13\n1..${results.length}`]; for (const [index, result] of results.entries()) { @@ -37,5 +37,3 @@ const tapFormatter = (results) => { return lines.join('\n'); }; - -module.exports = tapFormatter; diff --git a/lib/formatters/unixFormatter.js b/lib/formatters/unixFormatter.js index 6a362874ba..9db80e0dea 100644 --- a/lib/formatters/unixFormatter.js +++ b/lib/formatters/unixFormatter.js @@ -3,7 +3,7 @@ /** * @type {import('stylelint').Formatter} */ -const unixFormatter = (results) => { +module.exports = function unixFormatter(results) { const lines = results.flatMap((result) => result.warnings.map( (warning) => @@ -20,5 +20,3 @@ const unixFormatter = (results) => { return output; }; - -module.exports = unixFormatter; diff --git a/lib/reportDisables.js b/lib/reportDisables.js index daf26dfc78..e0fe313d97 100644 --- a/lib/reportDisables.js +++ b/lib/reportDisables.js @@ -11,7 +11,7 @@ * * @param {StylelintResult[]} results */ -module.exports = function (results) { +module.exports = function reportDisables(results) { for (const result of results) { // File with `CssSyntaxError` don't have `_postcssResult`s. if (!result._postcssResult) { diff --git a/lib/rules/block-closing-brace-space-after/index.js b/lib/rules/block-closing-brace-space-after/index.js index 2adc2554ce..7acb1b4f43 100644 --- a/lib/rules/block-closing-brace-space-after/index.js +++ b/lib/rules/block-closing-brace-space-after/index.js @@ -27,7 +27,7 @@ const meta = { const rule = (primary) => { const checker = whitespaceChecker('space', primary, messages); - return function (root, result) { + return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary, possible: [ diff --git a/lib/rules/declaration-block-semicolon-newline-before/index.js b/lib/rules/declaration-block-semicolon-newline-before/index.js index 8156c380e4..fdca076c22 100644 --- a/lib/rules/declaration-block-semicolon-newline-before/index.js +++ b/lib/rules/declaration-block-semicolon-newline-before/index.js @@ -24,7 +24,7 @@ const meta = { const rule = (primary) => { const checker = whitespaceChecker('newline', primary, messages); - return function (root, result) { + return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary, possible: ['always', 'always-multi-line', 'never-multi-line'], diff --git a/lib/rules/declaration-block-semicolon-space-after/index.js b/lib/rules/declaration-block-semicolon-space-after/index.js index 9e74b7a8cf..caf1ba9048 100644 --- a/lib/rules/declaration-block-semicolon-space-after/index.js +++ b/lib/rules/declaration-block-semicolon-space-after/index.js @@ -28,7 +28,7 @@ const meta = { const rule = (primary, _secondaryOptions, context) => { const checker = whitespaceChecker('space', primary, messages); - return function (root, result) { + return (root, result) => { const validOptions = validateOptions(result, ruleName, { actual: primary, possible: ['always', 'never', 'always-single-line', 'never-single-line'], diff --git a/lib/utils/atRuleParamIndex.js b/lib/utils/atRuleParamIndex.js index 0df7fa57fd..a820dc9faf 100644 --- a/lib/utils/atRuleParamIndex.js +++ b/lib/utils/atRuleParamIndex.js @@ -4,7 +4,7 @@ * @param {import('postcss').AtRule} atRule * @returns {number} */ -module.exports = function (atRule) { +module.exports = function atRuleParamIndex(atRule) { // Initial 1 is for the `@` let index = 1 + atRule.name.length; diff --git a/lib/utils/blurComments.js b/lib/utils/blurComments.js index 6959da5241..bcc6d5b188 100644 --- a/lib/utils/blurComments.js +++ b/lib/utils/blurComments.js @@ -5,6 +5,6 @@ * * @returns {string} */ -module.exports = function (source, blurChar = '`') { +module.exports = function blurComments(source, blurChar = '`') { return source.replace(/\/\*.*\*\//g, blurChar); }; diff --git a/lib/utils/blurFunctionArguments.js b/lib/utils/blurFunctionArguments.js index 0f64378e0b..520e0f20c9 100644 --- a/lib/utils/blurFunctionArguments.js +++ b/lib/utils/blurFunctionArguments.js @@ -17,7 +17,7 @@ const balancedMatch = require('balanced-match'); * @param {string} functionName * @return {string} - The result string, with the function arguments "blurred" */ -module.exports = function (source, functionName, blurChar = '`') { +module.exports = function blurFunctionArguments(source, functionName, blurChar = '`') { const nameWithParen = `${functionName.toLowerCase()}(`; const lowerCaseSource = source.toLowerCase(); diff --git a/lib/utils/blurInterpolation.js b/lib/utils/blurInterpolation.js index ff6dee89d2..4225c7df53 100644 --- a/lib/utils/blurInterpolation.js +++ b/lib/utils/blurInterpolation.js @@ -5,6 +5,6 @@ * * @returns {string} */ -module.exports = function (source, blurChar = ' ') { +module.exports = function blurInterpolation(source, blurChar = ' ') { return source.replace(/[#@{}]+/g, blurChar); }; diff --git a/lib/utils/configurationError.js b/lib/utils/configurationError.js index 1e190c4a5e..4b3b308a65 100644 --- a/lib/utils/configurationError.js +++ b/lib/utils/configurationError.js @@ -7,7 +7,7 @@ * @param {string} text * @returns {ConfigurationError} */ -module.exports = function (text) { +module.exports = function configurationError(text) { const err = /** @type {ConfigurationError} */ (new Error(text)); err.code = 78; diff --git a/lib/utils/getDimension.js b/lib/utils/getDimension.js index f583542486..2cacd79f1c 100644 --- a/lib/utils/getDimension.js +++ b/lib/utils/getDimension.js @@ -12,7 +12,7 @@ const valueParser = require('postcss-value-parser'); * * @returns {{unit: null, number: null} | valueParser.Dimension} */ -module.exports = function (node) { +module.exports = function getDimension(node) { if (!node || !node.value) { return { unit: null, diff --git a/lib/utils/getSchemeFromUrl.js b/lib/utils/getSchemeFromUrl.js index d62b8da0d4..fc0d8c6e71 100644 --- a/lib/utils/getSchemeFromUrl.js +++ b/lib/utils/getSchemeFromUrl.js @@ -9,7 +9,7 @@ const { URL } = require('url'); * * @param {string} urlString */ -module.exports = function (urlString) { +module.exports = function getSchemeFromUrl(urlString) { let protocol = null; try { diff --git a/lib/utils/hasEmptyBlock.js b/lib/utils/hasEmptyBlock.js index 4c0c6bb760..0bea60bbeb 100644 --- a/lib/utils/hasEmptyBlock.js +++ b/lib/utils/hasEmptyBlock.js @@ -6,7 +6,7 @@ * @param {import('postcss').Rule | import('postcss').AtRule} statement - postcss rule or at-rule node * @return {boolean} True if the statement has a block and it is empty */ -module.exports = function (statement) { +module.exports = function hasEmptyBlock(statement) { return ( statement.nodes !== undefined && statement.nodes.length === 0 // has block ); // and is empty diff --git a/lib/utils/hasEmptyLine.js b/lib/utils/hasEmptyLine.js index 5f3780bc5c..3dff0708f6 100644 --- a/lib/utils/hasEmptyLine.js +++ b/lib/utils/hasEmptyLine.js @@ -6,7 +6,7 @@ * @param {string | undefined} string * @returns {boolean} */ -module.exports = function (string) { +module.exports = function hasEmptyLine(string) { if (string === '' || string === undefined) return false; return /\n[\r\t ]*\n/.test(string); diff --git a/lib/utils/hasInterpolation.js b/lib/utils/hasInterpolation.js index 610c9442e5..4329a7fc6c 100644 --- a/lib/utils/hasInterpolation.js +++ b/lib/utils/hasInterpolation.js @@ -11,7 +11,7 @@ const hasTplInterpolation = require('../utils/hasTplInterpolation'); * @param {string} string * @return {boolean} If `true`, a string has interpolation */ -module.exports = function (string) { +module.exports = function hasInterpolation(string) { // SCSS or Less interpolation if ( hasLessInterpolation(string) || diff --git a/lib/utils/hasLessInterpolation.js b/lib/utils/hasLessInterpolation.js index c8012aa716..b03cced9c0 100644 --- a/lib/utils/hasLessInterpolation.js +++ b/lib/utils/hasLessInterpolation.js @@ -6,6 +6,6 @@ * @param {string} string * @return {boolean} If `true`, a string has less interpolation */ -module.exports = function (string) { +module.exports = function hasLessInterpolation(string) { return /@\{.+?\}/.test(string); }; diff --git a/lib/utils/hasPsvInterpolation.js b/lib/utils/hasPsvInterpolation.js index 5b3e58979e..003294182f 100644 --- a/lib/utils/hasPsvInterpolation.js +++ b/lib/utils/hasPsvInterpolation.js @@ -5,6 +5,6 @@ * * @param {string} string */ -module.exports = function (string) { +module.exports = function hasPsvInterpolation(string) { return /\$\(.+?\)/.test(string); }; diff --git a/lib/utils/hasScssInterpolation.js b/lib/utils/hasScssInterpolation.js index ce80eb79df..dd0781edfa 100644 --- a/lib/utils/hasScssInterpolation.js +++ b/lib/utils/hasScssInterpolation.js @@ -5,6 +5,6 @@ * * @param {string} string */ -module.exports = function (string) { +module.exports = function hasScssInterpolation(string) { return /#\{.+?\}/.test(string); }; diff --git a/lib/utils/hasTplInterpolation.js b/lib/utils/hasTplInterpolation.js index 440319bd12..06b1f397d5 100644 --- a/lib/utils/hasTplInterpolation.js +++ b/lib/utils/hasTplInterpolation.js @@ -6,6 +6,6 @@ * @param {string} string * @return {boolean} If `true`, a string has template literal interpolation */ -module.exports = function (string) { +module.exports = function hasTplInterpolation(string) { return /\{.+?\}/.test(string); }; diff --git a/lib/utils/isAfterComment.js b/lib/utils/isAfterComment.js index 7522600eec..eb3a8b53b5 100644 --- a/lib/utils/isAfterComment.js +++ b/lib/utils/isAfterComment.js @@ -5,7 +5,7 @@ const isSharedLineComment = require('./isSharedLineComment'); /** * @param {import('postcss').Node} node */ -module.exports = function (node) { +module.exports = function isAfterComment(node) { const previousNode = node.prev(); if (!previousNode || previousNode.type !== 'comment') { diff --git a/lib/utils/isAfterStandardPropertyDeclaration.js b/lib/utils/isAfterStandardPropertyDeclaration.js index 05d5a2cd5b..e118b43463 100644 --- a/lib/utils/isAfterStandardPropertyDeclaration.js +++ b/lib/utils/isAfterStandardPropertyDeclaration.js @@ -8,7 +8,7 @@ const { isDeclaration } = require('./typeGuards'); /** * @param {import('postcss').Node} node */ -module.exports = function (node) { +module.exports = function isAfterStandardPropertyDeclaration(node) { const prevNode = getPreviousNonSharedLineCommentNode(node); return ( diff --git a/lib/utils/isBlocklessAtRuleAfterBlocklessAtRule.js b/lib/utils/isBlocklessAtRuleAfterBlocklessAtRule.js index b21e55bdee..1f9e3bb8d4 100644 --- a/lib/utils/isBlocklessAtRuleAfterBlocklessAtRule.js +++ b/lib/utils/isBlocklessAtRuleAfterBlocklessAtRule.js @@ -8,7 +8,7 @@ const { isAtRule } = require('./typeGuards'); * @param {import('postcss').AtRule} atRule * @returns {boolean} */ -module.exports = function (atRule) { +module.exports = function isBlocklessAtRuleAfterBlocklessAtRule(atRule) { if (atRule.type !== 'atrule') { return false; } diff --git a/lib/utils/isBlocklessAtRuleAfterSameNameBlocklessAtRule.js b/lib/utils/isBlocklessAtRuleAfterSameNameBlocklessAtRule.js index c731db4217..503d8739cc 100644 --- a/lib/utils/isBlocklessAtRuleAfterSameNameBlocklessAtRule.js +++ b/lib/utils/isBlocklessAtRuleAfterSameNameBlocklessAtRule.js @@ -8,7 +8,7 @@ const { isAtRule } = require('./typeGuards'); * @param {import('postcss').AtRule} atRule * @returns {boolean} */ -module.exports = function (atRule) { +module.exports = function isBlocklessAtRuleAfterSameNameBlocklessAtRule(atRule) { if (!isBlocklessAtRuleAfterBlocklessAtRule(atRule)) { return false; } diff --git a/lib/utils/isCounterIncrementCustomIdentValue.js b/lib/utils/isCounterIncrementCustomIdentValue.js index 180999b406..ee425bf051 100644 --- a/lib/utils/isCounterIncrementCustomIdentValue.js +++ b/lib/utils/isCounterIncrementCustomIdentValue.js @@ -7,7 +7,7 @@ const { counterIncrementKeywords } = require('../reference/keywords'); * * @param {string} value */ -module.exports = function (value) { +module.exports = function isCounterIncrementCustomIdentValue(value) { const valueLowerCase = value.toLowerCase(); if ( diff --git a/lib/utils/isCounterResetCustomIdentValue.js b/lib/utils/isCounterResetCustomIdentValue.js index 5de6e72150..2afc9f3fab 100644 --- a/lib/utils/isCounterResetCustomIdentValue.js +++ b/lib/utils/isCounterResetCustomIdentValue.js @@ -7,7 +7,7 @@ const { counterResetKeywords } = require('../reference/keywords'); * * @param {string} value */ -module.exports = function (value) { +module.exports = function isCounterResetCustomIdentValue(value) { const valueLowerCase = value.toLowerCase(); if ( diff --git a/lib/utils/isCustomElement.js b/lib/utils/isCustomElement.js index d43d13826f..e777249cfe 100644 --- a/lib/utils/isCustomElement.js +++ b/lib/utils/isCustomElement.js @@ -10,7 +10,7 @@ const svgTags = require('svg-tags'); * @param {string} selector * @returns {boolean} */ -module.exports = function (selector) { +module.exports = function isCustomElement(selector) { if (!/^[a-z]/.test(selector)) { return false; } diff --git a/lib/utils/isCustomFunction.js b/lib/utils/isCustomFunction.js index d8d53d349e..0f0f0b1e95 100644 --- a/lib/utils/isCustomFunction.js +++ b/lib/utils/isCustomFunction.js @@ -6,6 +6,6 @@ * @param {string} func * @returns {boolean} */ -module.exports = function (func) { +module.exports = function isCustomFunction(func) { return func.startsWith('--'); }; diff --git a/lib/utils/isCustomMediaQuery.js b/lib/utils/isCustomMediaQuery.js index 7e9ec7bdf2..18a068618d 100644 --- a/lib/utils/isCustomMediaQuery.js +++ b/lib/utils/isCustomMediaQuery.js @@ -5,6 +5,6 @@ * @param {string} mediaQuery * @returns {boolean} */ -module.exports = function (mediaQuery) { +module.exports = function isCustomMediaQuery(mediaQuery) { return mediaQuery.startsWith('--'); }; diff --git a/lib/utils/isCustomProperty.js b/lib/utils/isCustomProperty.js index fcc6cb05f7..b4a33c7c2d 100644 --- a/lib/utils/isCustomProperty.js +++ b/lib/utils/isCustomProperty.js @@ -5,6 +5,6 @@ * @param {string} property * @returns {boolean} */ -module.exports = function (property) { +module.exports = function isCustomProperty(property) { return property.startsWith('--'); }; diff --git a/lib/utils/isCustomSelector.js b/lib/utils/isCustomSelector.js index 1b58a8a7eb..4cc3c86c9f 100644 --- a/lib/utils/isCustomSelector.js +++ b/lib/utils/isCustomSelector.js @@ -6,6 +6,6 @@ * @param {string} selector * @returns {boolean} */ -module.exports = function (selector) { +module.exports = function isCustomSelector(selector) { return selector.startsWith(':--'); }; diff --git a/lib/utils/isFirstNested.js b/lib/utils/isFirstNested.js index 16758f2099..2aa3788e00 100644 --- a/lib/utils/isFirstNested.js +++ b/lib/utils/isFirstNested.js @@ -6,7 +6,7 @@ const { isComment, hasSource } = require('./typeGuards'); * @param {import('postcss').Node} statement * @returns {boolean} */ -module.exports = function (statement) { +module.exports = function isFirstNested(statement) { const parentNode = statement.parent; if (parentNode === undefined || parentNode.type === 'root') { diff --git a/lib/utils/isFirstNodeOfRoot.js b/lib/utils/isFirstNodeOfRoot.js index 96df1a7913..dbdf4911fa 100644 --- a/lib/utils/isFirstNodeOfRoot.js +++ b/lib/utils/isFirstNodeOfRoot.js @@ -6,7 +6,7 @@ const { isRoot } = require('./typeGuards'); * @param {import('postcss').Node} node * @returns {boolean} */ -module.exports = function (node) { +module.exports = function isFirstNodeOfRoot(node) { if (isRoot(node)) return false; const parentNode = node.parent; diff --git a/lib/utils/isKeyframeRule.js b/lib/utils/isKeyframeRule.js index c9f62b36fd..015ea4ecaf 100644 --- a/lib/utils/isKeyframeRule.js +++ b/lib/utils/isKeyframeRule.js @@ -8,7 +8,7 @@ const { isAtRule } = require('./typeGuards'); * @param {import('postcss').Rule} rule * @returns {boolean} */ -module.exports = function (rule) { +module.exports = function isKeyframeRule(rule) { const parent = rule.parent; if (!parent) { diff --git a/lib/utils/isKeyframeSelector.js b/lib/utils/isKeyframeSelector.js index a8734b2456..70ca5d64d0 100644 --- a/lib/utils/isKeyframeSelector.js +++ b/lib/utils/isKeyframeSelector.js @@ -8,7 +8,7 @@ const { keyframeSelectorKeywords } = require('../reference/keywords'); * @param {string} selector * @returns {boolean} */ -module.exports = function (selector) { +module.exports = function isKeyframeSelector(selector) { if (keyframeSelectorKeywords.has(selector)) { return true; } diff --git a/lib/utils/isLessVariable.js b/lib/utils/isLessVariable.js index aeb8ce3969..ccf889d5c3 100644 --- a/lib/utils/isLessVariable.js +++ b/lib/utils/isLessVariable.js @@ -6,7 +6,7 @@ const hasBlock = require('./hasBlock'); * @param {import('postcss').AtRule | import('postcss-less').AtRule} atRule * @returns {boolean} */ -module.exports = function (atRule) { +module.exports = function isLessVariable(atRule) { return ( (atRule.type === 'atrule' && 'variable' in atRule && atRule.variable && !hasBlock(atRule)) || false diff --git a/lib/utils/isOnlyWhitespace.js b/lib/utils/isOnlyWhitespace.js index fd47d214ac..8c63969c63 100644 --- a/lib/utils/isOnlyWhitespace.js +++ b/lib/utils/isOnlyWhitespace.js @@ -8,15 +8,12 @@ const isWhitespace = require('./isWhitespace'); * @param {string} input * @returns {boolean} */ -module.exports = function (input) { - let isOnlyWhitespace = true; - +module.exports = function isOnlyWhitespace(input) { for (const element of input) { if (!isWhitespace(element)) { - isOnlyWhitespace = false; - break; + return false; } } - return isOnlyWhitespace; + return true; }; diff --git a/lib/utils/isRangeContextMediaFeature.js b/lib/utils/isRangeContextMediaFeature.js index 8e1e1e5d25..822a5928b4 100644 --- a/lib/utils/isRangeContextMediaFeature.js +++ b/lib/utils/isRangeContextMediaFeature.js @@ -6,6 +6,6 @@ * @param {string} mediaFeature feature * @return {boolean} If `true`, media feature is a range context one */ -module.exports = function (mediaFeature) { +module.exports = function isRangeContextMediaFeature(mediaFeature) { return mediaFeature.includes('=') || mediaFeature.includes('<') || mediaFeature.includes('>'); }; diff --git a/lib/utils/isScssVariable.js b/lib/utils/isScssVariable.js index fbc938a723..f7012e6295 100644 --- a/lib/utils/isScssVariable.js +++ b/lib/utils/isScssVariable.js @@ -6,7 +6,7 @@ * @param {string} property * @returns {boolean} */ -module.exports = function (property) { +module.exports = function isScssVariable(property) { // SCSS var (e.g. $var: x), list (e.g. $list: (x)) or map (e.g. $map: (key:value)) if (property.startsWith('$')) { return true; diff --git a/lib/utils/isSingleLineString.js b/lib/utils/isSingleLineString.js index 88fbdeb57c..152be8cc99 100644 --- a/lib/utils/isSingleLineString.js +++ b/lib/utils/isSingleLineString.js @@ -7,6 +7,6 @@ * @param {string} input * @return {boolean} */ -module.exports = function (input) { +module.exports = function isSingleLineString(input) { return !/[\n\r]/.test(input); }; diff --git a/lib/utils/isStandardSyntaxAtRule.js b/lib/utils/isStandardSyntaxAtRule.js index a874f40549..7ee34c2f2b 100644 --- a/lib/utils/isStandardSyntaxAtRule.js +++ b/lib/utils/isStandardSyntaxAtRule.js @@ -6,7 +6,7 @@ * @param {import('postcss').AtRule | import('postcss-less').AtRule} atRule postcss at-rule node * @return {boolean} If `true`, the declaration is standard */ -module.exports = function (atRule) { +module.exports = function isStandardSyntaxAtRule(atRule) { // Ignore scss `@content` inside mixins if (!atRule.nodes && atRule.params === '') { return false; diff --git a/lib/utils/isStandardSyntaxCombinator.js b/lib/utils/isStandardSyntaxCombinator.js index 76e1d4215c..171096dd39 100644 --- a/lib/utils/isStandardSyntaxCombinator.js +++ b/lib/utils/isStandardSyntaxCombinator.js @@ -6,7 +6,7 @@ * @param {import('postcss-selector-parser').Combinator} node postcss-selector-parser node (of type combinator) * @return {boolean} If `true`, the combinator is standard */ -module.exports = function (node) { +module.exports = function isStandardSyntaxCombinator(node) { // if it's not a combinator, then it's not a standard combinator if (node.type !== 'combinator') { return false; diff --git a/lib/utils/isStandardSyntaxDeclaration.js b/lib/utils/isStandardSyntaxDeclaration.js index d8291befef..2f1f8b5787 100644 --- a/lib/utils/isStandardSyntaxDeclaration.js +++ b/lib/utils/isStandardSyntaxDeclaration.js @@ -15,7 +15,7 @@ function isStandardSyntaxLang(lang) { * * @param {import('postcss').Declaration | import('postcss-less').Declaration} decl */ -module.exports = function (decl) { +module.exports = function isStandardSyntaxDeclaration(decl) { const prop = decl.prop; const parent = decl.parent; diff --git a/lib/utils/isStandardSyntaxFunction.js b/lib/utils/isStandardSyntaxFunction.js index 83db8b26bc..d2f465fae1 100644 --- a/lib/utils/isStandardSyntaxFunction.js +++ b/lib/utils/isStandardSyntaxFunction.js @@ -6,7 +6,7 @@ * @param {import('postcss-value-parser').Node} node * @returns {boolean} */ -module.exports = function (node) { +module.exports = function isStandardSyntaxFunction(node) { // Function nodes without names are things in parentheses like Sass lists if (!node.value) { return false; diff --git a/lib/utils/isStandardSyntaxMediaFeature.js b/lib/utils/isStandardSyntaxMediaFeature.js index 6ae86e63ec..6b6a867244 100644 --- a/lib/utils/isStandardSyntaxMediaFeature.js +++ b/lib/utils/isStandardSyntaxMediaFeature.js @@ -8,7 +8,7 @@ const hasInterpolation = require('../utils/hasInterpolation'); * @param {string} mediaFeature * @returns {boolean} */ -module.exports = function (mediaFeature) { +module.exports = function isStandardSyntaxMediaFeature(mediaFeature) { // Remove outside parens mediaFeature = mediaFeature.slice(1, -1); diff --git a/lib/utils/isStandardSyntaxMediaFeatureName.js b/lib/utils/isStandardSyntaxMediaFeatureName.js index 7576bada02..9022b18d12 100644 --- a/lib/utils/isStandardSyntaxMediaFeatureName.js +++ b/lib/utils/isStandardSyntaxMediaFeatureName.js @@ -6,7 +6,7 @@ * @param {string} mediaFeatureName * @returns {boolean} */ -module.exports = function (mediaFeatureName) { +module.exports = function isStandardSyntaxMediaFeatureName(mediaFeatureName) { // SCSS interpolation if (/#\{.+?\}|\$.+/.test(mediaFeatureName)) { return false; diff --git a/lib/utils/isStandardSyntaxProperty.js b/lib/utils/isStandardSyntaxProperty.js index a42bf8a06e..373f681b19 100644 --- a/lib/utils/isStandardSyntaxProperty.js +++ b/lib/utils/isStandardSyntaxProperty.js @@ -9,7 +9,7 @@ const isScssVariable = require('./isScssVariable'); * @param {string} property * @returns {boolean} */ -module.exports = function (property) { +module.exports = function isStandardSyntaxProperty(property) { // SCSS var if (isScssVariable(property)) { return false; diff --git a/lib/utils/isStandardSyntaxRule.js b/lib/utils/isStandardSyntaxRule.js index cc28563494..995d368797 100644 --- a/lib/utils/isStandardSyntaxRule.js +++ b/lib/utils/isStandardSyntaxRule.js @@ -8,7 +8,7 @@ const isStandardSyntaxSelector = require('../utils/isStandardSyntaxSelector'); * @param {import('postcss').Rule | import('postcss-less').Rule} rule * @returns {boolean} */ -module.exports = function (rule) { +module.exports = function isStandardSyntaxRule(rule) { if (rule.type !== 'rule') { return false; } diff --git a/lib/utils/isStandardSyntaxSelector.js b/lib/utils/isStandardSyntaxSelector.js index d4b0bcfee8..0e6e3af735 100644 --- a/lib/utils/isStandardSyntaxSelector.js +++ b/lib/utils/isStandardSyntaxSelector.js @@ -8,7 +8,7 @@ const hasInterpolation = require('../utils/hasInterpolation'); * @param {string} selector * @returns {boolean} */ -module.exports = function (selector) { +module.exports = function isStandardSyntaxSelector(selector) { // SCSS or Less interpolation if (hasInterpolation(selector)) { return false; diff --git a/lib/utils/isStandardSyntaxTypeSelector.js b/lib/utils/isStandardSyntaxTypeSelector.js index 69c7d2513a..c415cb469b 100644 --- a/lib/utils/isStandardSyntaxTypeSelector.js +++ b/lib/utils/isStandardSyntaxTypeSelector.js @@ -13,7 +13,7 @@ const { * @param {import('postcss-selector-parser').Tag} node postcss-selector-parser node (of type tag) * @return {boolean} If `true`, the type selector is standard */ -module.exports = function (node) { +module.exports = function isStandardSyntaxTypeSelector(node) { // postcss-selector-parser includes the arguments to nth-child() functions // as "tags", so we need to ignore them ourselves. // The fake-tag's "parent" is actually a selector node, whose parent diff --git a/lib/utils/isStandardSyntaxUrl.js b/lib/utils/isStandardSyntaxUrl.js index b4b9326e11..b21ec20ddb 100644 --- a/lib/utils/isStandardSyntaxUrl.js +++ b/lib/utils/isStandardSyntaxUrl.js @@ -11,7 +11,7 @@ const hasTplInterpolation = require('../utils/hasTplInterpolation'); * @param {string} url * @returns {boolean} */ -module.exports = function (url) { +module.exports = function isStandardSyntaxUrl(url) { if (url.length === 0) { return true; } diff --git a/lib/utils/isStandardSyntaxValue.js b/lib/utils/isStandardSyntaxValue.js index 561f5e1560..d19100b83a 100644 --- a/lib/utils/isStandardSyntaxValue.js +++ b/lib/utils/isStandardSyntaxValue.js @@ -8,7 +8,7 @@ const hasInterpolation = require('../utils/hasInterpolation'); * @param {string} value * @returns {boolean} */ -module.exports = function (value) { +module.exports = function isStandardSyntaxValue(value) { let normalizedValue = value; // Ignore operators before variables (example -$variable) diff --git a/lib/utils/isValidFontSize.js b/lib/utils/isValidFontSize.js index 5c622741b1..eff6f28018 100644 --- a/lib/utils/isValidFontSize.js +++ b/lib/utils/isValidFontSize.js @@ -10,7 +10,7 @@ const valueParser = require('postcss-value-parser'); * @param {string} word * @returns {boolean} */ -module.exports = function (word) { +module.exports = function isValidFontSize(word) { if (!word) { return false; } diff --git a/lib/utils/isValidHex.js b/lib/utils/isValidHex.js index 310a12d10f..56df6adecc 100644 --- a/lib/utils/isValidHex.js +++ b/lib/utils/isValidHex.js @@ -6,6 +6,6 @@ * @param {string} value * @returns {boolean} */ -module.exports = function (value) { +module.exports = function isValidHex(value) { return /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value); }; diff --git a/lib/utils/isVariable.js b/lib/utils/isVariable.js index c893b7e3b5..76d6b3c9a0 100644 --- a/lib/utils/isVariable.js +++ b/lib/utils/isVariable.js @@ -6,6 +6,6 @@ * @param {string} word * @returns {boolean} */ -module.exports = function (word) { +module.exports = function isVariable(word) { return word.toLowerCase().startsWith('var('); }; diff --git a/lib/utils/isWhitespace.js b/lib/utils/isWhitespace.js index a79c6577ce..c88ec1958a 100644 --- a/lib/utils/isWhitespace.js +++ b/lib/utils/isWhitespace.js @@ -6,6 +6,6 @@ * @param {string} char * @returns {boolean} */ -module.exports = function (char) { +module.exports = function isWhitespace(char) { return [' ', '\n', '\t', '\r', '\f'].includes(char); }; diff --git a/lib/utils/putIfAbsent.js b/lib/utils/putIfAbsent.js index aeb9eed5fd..94057000cc 100644 --- a/lib/utils/putIfAbsent.js +++ b/lib/utils/putIfAbsent.js @@ -11,7 +11,7 @@ * @param {() => V} callback * @returns {V} */ -module.exports = function (map, key, callback) { +module.exports = function putIfAbsent(map, key, callback) { if (map.has(key)) return /** @type {V} */ (map.get(key)); const value = callback(); diff --git a/lib/utils/rawNodeString.js b/lib/utils/rawNodeString.js index eba152ffff..efb0e7c8f0 100644 --- a/lib/utils/rawNodeString.js +++ b/lib/utils/rawNodeString.js @@ -7,7 +7,7 @@ * * @returns {string} */ -module.exports = function (node) { +module.exports = function rawNodeString(node) { let result = ''; if (node.raws.before) { diff --git a/lib/validateDisableSettings.js b/lib/validateDisableSettings.js index 76850d95b4..9f093b40c9 100644 --- a/lib/validateDisableSettings.js +++ b/lib/validateDisableSettings.js @@ -23,7 +23,7 @@ const { isRegExp, isString } = require('./utils/validateTypes'); * @param {DisablePropertyName} field * @return {[boolean, Required, StylelintPostcssResult] | null} */ -module.exports = function (result, field) { +module.exports = function validateDisableSettings(result, field) { // Files with `CssSyntaxError`s don't have `_postcssResult`s. if (!result) return null; diff --git a/lib/writeOutputFile.js b/lib/writeOutputFile.js index 40590d7e0b..d77ee36d79 100644 --- a/lib/writeOutputFile.js +++ b/lib/writeOutputFile.js @@ -10,7 +10,8 @@ const writeFileAtomic = require('write-file-atomic'); * @param {string} filePath * @returns {Promise} */ -module.exports = (content, filePath) => - mkdir(path.dirname(filePath), { recursive: true }).then(() => - writeFileAtomic(path.normalize(filePath), stripAnsi(content)), - ); +module.exports = async function writeOutputFile(content, filePath) { + await mkdir(path.dirname(filePath), { recursive: true }); + + await writeFileAtomic(path.normalize(filePath), stripAnsi(content)); +}; diff --git a/package.json b/package.json index 22dffb8818..dba99035a0 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,12 @@ "extends": [ "stylelint" ], + "rules": { + "func-names": [ + "error", + "as-needed" + ] + }, "globals": { "__dirname": true, "module": true,