Skip to content

Commit

Permalink
Refactor to add function names (#6377)
Browse files Browse the repository at this point in the history
Giving function names (avoiding anonymous) helps debugging.

This refactoring relies on the ESLint `func-names` rule:
https://eslint.org/docs/latest/rules/func-names
  • Loading branch information
ybiquitous committed Sep 30, 2022
1 parent b80548b commit 0bb8cf1
Show file tree
Hide file tree
Showing 67 changed files with 80 additions and 81 deletions.
2 changes: 1 addition & 1 deletion 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 {
Expand Down
2 changes: 1 addition & 1 deletion 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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/createPartialStylelintResult.js
Expand Up @@ -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} */
Expand Down
2 changes: 1 addition & 1 deletion lib/formatters/__tests__/prepareFormatterOutput.js
Expand Up @@ -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: {},
};
Expand Down
7 changes: 3 additions & 4 deletions lib/formatters/compactFormatter.js
Expand Up @@ -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) =>
Expand All @@ -16,5 +16,4 @@ const formatter = (results) =>
),
)
.join('\n');

module.exports = formatter;
};
2 changes: 1 addition & 1 deletion lib/formatters/stringFormatter.js
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions lib/formatters/tapFormatter.js
Expand Up @@ -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()) {
Expand Down Expand Up @@ -37,5 +37,3 @@ const tapFormatter = (results) => {

return lines.join('\n');
};

module.exports = tapFormatter;
4 changes: 1 addition & 3 deletions lib/formatters/unixFormatter.js
Expand Up @@ -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) =>
Expand All @@ -20,5 +20,3 @@ const unixFormatter = (results) => {

return output;
};

module.exports = unixFormatter;
2 changes: 1 addition & 1 deletion lib/reportDisables.js
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/block-closing-brace-space-after/index.js
Expand Up @@ -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: [
Expand Down
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/declaration-block-semicolon-space-after/index.js
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/atRuleParamIndex.js
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/blurComments.js
Expand Up @@ -5,6 +5,6 @@
*
* @returns {string}
*/
module.exports = function (source, blurChar = '`') {
module.exports = function blurComments(source, blurChar = '`') {
return source.replace(/\/\*.*\*\//g, blurChar);
};
2 changes: 1 addition & 1 deletion lib/utils/blurFunctionArguments.js
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/blurInterpolation.js
Expand Up @@ -5,6 +5,6 @@
*
* @returns {string}
*/
module.exports = function (source, blurChar = ' ') {
module.exports = function blurInterpolation(source, blurChar = ' ') {
return source.replace(/[#@{}]+/g, blurChar);
};
2 changes: 1 addition & 1 deletion lib/utils/configurationError.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/getDimension.js
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/getSchemeFromUrl.js
Expand Up @@ -9,7 +9,7 @@ const { URL } = require('url');
*
* @param {string} urlString
*/
module.exports = function (urlString) {
module.exports = function getSchemeFromUrl(urlString) {
let protocol = null;

try {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/hasEmptyBlock.js
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/hasEmptyLine.js
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/hasInterpolation.js
Expand Up @@ -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) ||
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/hasLessInterpolation.js
Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion lib/utils/hasPsvInterpolation.js
Expand Up @@ -5,6 +5,6 @@
*
* @param {string} string
*/
module.exports = function (string) {
module.exports = function hasPsvInterpolation(string) {
return /\$\(.+?\)/.test(string);
};
2 changes: 1 addition & 1 deletion lib/utils/hasScssInterpolation.js
Expand Up @@ -5,6 +5,6 @@
*
* @param {string} string
*/
module.exports = function (string) {
module.exports = function hasScssInterpolation(string) {
return /#\{.+?\}/.test(string);
};
2 changes: 1 addition & 1 deletion lib/utils/hasTplInterpolation.js
Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion lib/utils/isAfterComment.js
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isAfterStandardPropertyDeclaration.js
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isBlocklessAtRuleAfterBlocklessAtRule.js
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isBlocklessAtRuleAfterSameNameBlocklessAtRule.js
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isCounterIncrementCustomIdentValue.js
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isCounterResetCustomIdentValue.js
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isCustomElement.js
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isCustomFunction.js
Expand Up @@ -6,6 +6,6 @@
* @param {string} func
* @returns {boolean}
*/
module.exports = function (func) {
module.exports = function isCustomFunction(func) {
return func.startsWith('--');
};
2 changes: 1 addition & 1 deletion lib/utils/isCustomMediaQuery.js
Expand Up @@ -5,6 +5,6 @@
* @param {string} mediaQuery
* @returns {boolean}
*/
module.exports = function (mediaQuery) {
module.exports = function isCustomMediaQuery(mediaQuery) {
return mediaQuery.startsWith('--');
};
2 changes: 1 addition & 1 deletion lib/utils/isCustomProperty.js
Expand Up @@ -5,6 +5,6 @@
* @param {string} property
* @returns {boolean}
*/
module.exports = function (property) {
module.exports = function isCustomProperty(property) {
return property.startsWith('--');
};
2 changes: 1 addition & 1 deletion lib/utils/isCustomSelector.js
Expand Up @@ -6,6 +6,6 @@
* @param {string} selector
* @returns {boolean}
*/
module.exports = function (selector) {
module.exports = function isCustomSelector(selector) {
return selector.startsWith(':--');
};
2 changes: 1 addition & 1 deletion lib/utils/isFirstNested.js
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isFirstNodeOfRoot.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isKeyframeRule.js
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isKeyframeSelector.js
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isLessVariable.js
Expand Up @@ -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
Expand Down

0 comments on commit 0bb8cf1

Please sign in to comment.