Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump eslint-config-stylelint from 13.1.1 to 14.0.0 #5536

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/__tests__/standalone-syntax.test.js
Expand Up @@ -20,7 +20,7 @@ it('standalone with postcss-safe-parser', () => {

expect(results).toHaveLength(6);

const safeParserExtensionsTest = /\.(css|pcss|postcss)$/i;
const safeParserExtensionsTest = /\.(?:css|pcss|postcss)$/i;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See regexp/no-unused-capturing-group - ?: creates a non-capturing group.


results
.filter((result) => !safeParserExtensionsTest.test(result.source))
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/color-hex-alpha/index.js
Expand Up @@ -13,7 +13,7 @@ const messages = ruleMessages(ruleName, {
unexpected: (hex) => `Unexpected alpha channel in "${hex}"`,
});

const HEX = /^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i;
const HEX = /^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i;

/** @type {import('stylelint').StylelintRule} */
const rule = (primary) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/declaration-colon-newline-after/index.js
Expand Up @@ -64,7 +64,7 @@ const rule = (primary, _secondaryOptions, context) => {
const betweenBefore = between.slice(0, sliceIndex);
const betweenAfter = between.slice(sliceIndex);

if (/^\s*\r?\n/.test(betweenAfter)) {
if (/^\s*\n/.test(betweenAfter)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See regexp/optimal-quantifier-concatenation - \s* includes \r? already.

decl.raws.between = betweenBefore + betweenAfter.replace(/^[^\S\r\n]*/, '');
} else {
decl.raws.between = betweenBefore + context.newline + betweenAfter;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/font-family-name-quotes/index.js
Expand Up @@ -52,7 +52,7 @@ function quotesRecommended(family) {
*/
function quotesRequired(family) {
return family.split(/\s+/).some((word) => {
return /^(-?\d|--)/.test(word) || !/^[-_a-zA-Z0-9\u{00A0}-\u{10FFFF}]+$/u.test(word);
return /^(?:-?\d|--)/.test(word) || !/^[-\w\u{00A0}-\u{10FFFF}]+$/u.test(word);
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/function-calc-no-unspaced-operator/index.js
Expand Up @@ -241,7 +241,7 @@ function insertCharAtIndex(str, index, char) {
* @param {string} source
*/
function blurVariables(source) {
return source.replace(/[$@][^)\s]+|#{.+?}/g, '0');
return source.replace(/[$@][^)\s]+|#\{.+?\}/g, '0');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

/**
Expand Down
10 changes: 6 additions & 4 deletions lib/rules/indentation/index.js
Expand Up @@ -303,13 +303,13 @@ const rule = (primary, secondaryOptions = {}, context) => {
parentheticalDepth += 1;
}

const followsOpeningBrace = /{[ \t]*$/.test(source.slice(0, newlineIndex));
const followsOpeningBrace = /\{[ \t]*$/.test(source.slice(0, newlineIndex));

if (followsOpeningBrace) {
parentheticalDepth += 1;
}

const startingClosingBrace = /^[ \t]*}/.test(source.slice(match.startIndex + 1));
const startingClosingBrace = /^[ \t]*\}/.test(source.slice(match.startIndex + 1));

if (startingClosingBrace) {
parentheticalDepth -= 1;
Expand Down Expand Up @@ -607,8 +607,10 @@ function inferRootIndentLevel(root, baseIndentLevel, indentSize) {
let source = root.source.input.css;

source = source.replace(/^[^\r\n]+/, (firstLine) => {
if (/(?:^|\n)([ \t]*)$/.test(root.raws.beforeStart)) {
return RegExp.$1 + firstLine;
const matched = /(?:^|\n)([ \t]*)$/.exec(root.raws.beforeStart);

if (matched) {
return matched[1] + firstLine;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See regexp/no-legacy-features - RegExp.$1 -> matched[1]

}

return '';
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/max-empty-lines/index.js
Expand Up @@ -161,7 +161,7 @@ const rule = (primary, secondaryOptions, context) => {
const emptyLFLines = '\n'.repeat(repeatTimes);
const emptyCRLFLines = '\r\n'.repeat(repeatTimes);

return /(\r\n)+/g.test(str)
return /(?:\r\n)+/.test(str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See regexp/no-useless-flag - g flag is useless for .test()

? str.replace(/(\r\n)+/g, ($1) => {
if ($1.length / 2 > repeatTimes) {
return emptyCRLFLines;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/media-query-list-comma-newline-after/index.js
Expand Up @@ -65,7 +65,7 @@ const rule = (primary, _secondaryOptions, context) => {
const afterComma = params.slice(index + 1);

if (primary.startsWith('always')) {
params = /^\s*\r?\n/.test(afterComma)
params = /^\s*\n/.test(afterComma)
? beforeComma + afterComma.replace(/^[^\S\r\n]*/, '')
: beforeComma + context.newline + afterComma;
} else if (primary.startsWith('never')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/mediaQueryListCommaWhitespaceChecker.js
Expand Up @@ -29,7 +29,7 @@ module.exports = function mediaQueryListCommaWhitespaceChecker(opts) {
index += execResult[0].length;
}

if ((execResult = /^([^\S\r\n]*\/\/([\s\S]*?))\r?\n/.exec(params.slice(index + 1)))) {
if ((execResult = /^([^\S\r\n]*\/\/[\s\S]*?)\r?\n/.exec(params.slice(index + 1)))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index += execResult[1].length;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/number-no-trailing-zeros/index.js
Expand Up @@ -52,7 +52,7 @@ function rule(actual, secondary, context) {
return;
}

const match = /\.(\d*?)(0+)(?:\D|$)/.exec(valueNode.value);
const match = /\.(\d{0,100}?)(0+)(?:\D|$)/.exec(valueNode.value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See regexp/no-super-linear-backtracking - * can be potential ReDoS, so it changes to {0,100}


// match[1] is any numbers between the decimal and our trailing zero, could be empty
// match[2] is our trailing zero(s)
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/selector-disallowed-list/__tests__/index.js
Expand Up @@ -4,7 +4,7 @@ const { messages, ruleName } = require('..');

testRule({
ruleName,
config: ['a > .foo', /\[data-.+]/],
config: ['a > .foo', /\[data-.+\]/],

accept: [
{
Expand Down Expand Up @@ -60,7 +60,7 @@ testRule({

testRule({
ruleName,
config: [/\.foo.*>.*\.bar/],
config: [/\.foo[^\n\r>\u2028\u2029]*>.*\.bar/],

accept: [
{
Expand Down
18 changes: 13 additions & 5 deletions lib/rules/string-no-newline/index.js
Expand Up @@ -12,7 +12,7 @@ const validateOptions = require('../../utils/validateOptions');
const valueParser = require('postcss-value-parser');

const ruleName = 'string-no-newline';
const reNewLine = /(\r?\n)/;
const reNewLine = /\r?\n/;

const messages = ruleMessages(ruleName, {
rejected: 'Unexpected newline in string',
Expand Down Expand Up @@ -52,7 +52,9 @@ function rule(actual) {

parseSelector(ruleNode.selector, result, ruleNode, (selectorTree) => {
selectorTree.walkAttributes((attributeNode) => {
if (!reNewLine.test(attributeNode.value)) {
const match = reNewLine.exec(attributeNode.value);

if (!match) {
return;
}

Expand All @@ -62,7 +64,7 @@ function rule(actual) {
// length of our operator , ie '='
attributeNode.operator,
// length of the contents before newline
RegExp.leftContext,
match.input.slice(0, match.index),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

].reduce(
(index, str) => index + str.length,
// index of the start of our attribute node in our source
Expand All @@ -88,15 +90,21 @@ function rule(actual) {
}

valueParser(value).walk((valueNode) => {
if (valueNode.type !== 'string' || !reNewLine.test(valueNode.value)) {
if (valueNode.type !== 'string') {
return;
}

const match = reNewLine.exec(valueNode.value);

if (!match) {
return;
}

const openIndex = [
// length of the quote
valueNode.quote,
// length of the contents before newline
RegExp.leftContext,
match.input.slice(0, match.index),
].reduce((index, str) => index + str.length, valueNode.sourceIndex);

report({
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/unit-disallowed-list/index.js
Expand Up @@ -25,7 +25,7 @@ const messages = ruleMessages(ruleName, {
const getMediaFeatureName = (mediaFeatureNode) => {
const value = mediaFeatureNode.value.toLowerCase();

return /((-?\w*)*)/i.exec(value)[1];
return /((?:-?\w*)*)/.exec(value)[1];
};

function rule(listInput, options) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/hasLessInterpolation.js
Expand Up @@ -7,5 +7,5 @@
* @return {boolean} If `true`, a string has less interpolation
*/
module.exports = function (string) {
return /@{.+?}/.test(string);
return /@\{.+?\}/.test(string);
};
2 changes: 1 addition & 1 deletion lib/utils/hasScssInterpolation.js
Expand Up @@ -6,5 +6,5 @@
* @param {string} string
*/
module.exports = function (string) {
return /#{.+?}/.test(string);
return /#\{.+?\}/.test(string);
};
2 changes: 1 addition & 1 deletion lib/utils/hasTplInterpolation.js
Expand Up @@ -7,5 +7,5 @@
* @return {boolean} If `true`, a string has template literal interpolation
*/
module.exports = function (string) {
return /{.+?}/.test(string);
return /\{.+?\}/.test(string);
};
2 changes: 1 addition & 1 deletion lib/utils/isKeyframeSelector.js
Expand Up @@ -14,7 +14,7 @@ module.exports = function (selector) {
}

// Percentages
if (/^(?:\d+\.?\d*|\d*\.?\d+)%$/.test(selector)) {
if (/^(?:\d+|\d*\.\d+)%$/.test(selector)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isStandardSyntaxMediaFeatureName.js
Expand Up @@ -8,7 +8,7 @@
*/
module.exports = function (mediaFeatureName) {
// SCSS interpolation
if (/#{.+?}|\$.+?/.test(mediaFeatureName)) {
if (/#\{.+?\}|\$.+/.test(mediaFeatureName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/utils/isStandardSyntaxSelector.js
Expand Up @@ -25,12 +25,12 @@ module.exports = function (selector) {
}

// Less :extend()
if (/:extend(\(.*?\))?/.test(selector)) {
if (/:extend(?:\(.*?\))?/.test(selector)) {
return false;
}

// Less mixin with resolved nested selectors (e.g. .foo().bar or .foo(@a, @b)[bar])
if (/\.[\w-]+\(.*\).+/i.test(selector)) {
if (/\.[\w-]+\(.*\).+/.test(selector)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isStandardSyntaxUrl.js
Expand Up @@ -40,7 +40,7 @@ module.exports = function (url) {
// In url without quotes scss variable can be everywhere
// But in this case it is allowed to use only specific characters
// Also forbidden "/" at the end of url
if (url.includes('$') && /^[$\s\w+-/*'"/]+$/.test(url) && !url.endsWith('/')) {
if (url.includes('$') && /^[$\s\w+\-,./*'"]+$/.test(url) && !url.endsWith('/')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See regexp/no-obscure-range and regexp/no-dupe-characters-character-class - [+-/] means a range between between + (index 43) and / (index 47). It is the same as [+,-./].

return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/removeEmptyLinesAfter.js
Expand Up @@ -9,7 +9,7 @@
* @returns {T}
*/
module.exports = function removeEmptyLinesAfter(node, newline) {
node.raws.after = node.raws.after ? node.raws.after.replace(/(\r?\n\s*\r?\n)+/g, newline) : '';
node.raws.after = node.raws.after ? node.raws.after.replace(/(\r?\n\s*\n)+/g, newline) : '';

return node;
};
2 changes: 1 addition & 1 deletion lib/utils/removeEmptyLinesBefore.js
Expand Up @@ -9,7 +9,7 @@
* @returns {T}
*/
module.exports = function removeEmptyLinesBefore(node, newline) {
node.raws.before = node.raws.before ? node.raws.before.replace(/(\r?\n\s*\r?\n)+/g, newline) : '';
node.raws.before = node.raws.before ? node.raws.before.replace(/(\r?\n\s*\n)+/g, newline) : '';

return node;
};