Socket
Socket
Sign inDemoInstall

@stylistic/eslint-plugin-js

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stylistic/eslint-plugin-js - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

6

dist/arrow-parens.js

@@ -45,4 +45,5 @@ 'use strict';

const tokenBeforeParams = sourceCode.getTokenBefore(node.params[0]);
if (tokenBeforeParams && utils.isOpeningParenToken(tokenBeforeParams) && node.range[0] <= tokenBeforeParams.range[0])
if (tokenBeforeParams && utils.isOpeningParenToken(tokenBeforeParams) && node.range[0] <= tokenBeforeParams.range[0]) {
return tokenBeforeParams;
}
return null;

@@ -85,4 +86,5 @@ }

const closingParen = getClosingParenOfParams(node);
if (tokenBeforeOpeningParen && tokenBeforeOpeningParen.range[1] === openingParen.range[0] && !utils.canTokensBeAdjacent(tokenBeforeOpeningParen, sourceCode.getFirstToken(param)))
if (tokenBeforeOpeningParen && tokenBeforeOpeningParen.range[1] === openingParen.range[0] && !utils.canTokensBeAdjacent(tokenBeforeOpeningParen, sourceCode.getFirstToken(param))) {
yield fixer.insertTextBefore(openingParen, " ");
}
yield fixer.removeRange([openingParen.range[0], param.range[0]]);

@@ -89,0 +91,0 @@ yield fixer.removeRange([param.range[1], closingParen.range[1]]);

@@ -43,4 +43,5 @@ 'use strict';

const lastToken = sourceCode.getTokenBefore(closeBrace, { includeComments: true });
if (openBrace.type !== "Punctuator" || openBrace.value !== "{" || closeBrace.type !== "Punctuator" || closeBrace.value !== "}" || firstToken === closeBrace)
if (openBrace.type !== "Punctuator" || openBrace.value !== "{" || closeBrace.type !== "Punctuator" || closeBrace.value !== "}" || firstToken === closeBrace) {
return;
}
if (!always && firstToken.type === "Line")

@@ -47,0 +48,0 @@ return;

@@ -89,6 +89,8 @@ 'use strict';

const nextToken = tokensAndComments[i + 1];
if (previousToken && !utils.isCommaToken(previousToken) && !commaTokensToIgnore.includes(token) && utils.isTokenOnSameLine(previousToken, token) && options.before !== sourceCode.isSpaceBetweenTokens(previousToken, token))
if (previousToken && !utils.isCommaToken(previousToken) && !commaTokensToIgnore.includes(token) && utils.isTokenOnSameLine(previousToken, token) && options.before !== sourceCode.isSpaceBetweenTokens(previousToken, token)) {
report(token, "before", previousToken);
if (nextToken && !utils.isCommaToken(nextToken) && !utils.isClosingParenToken(nextToken) && !utils.isClosingBracketToken(nextToken) && !utils.isClosingBraceToken(nextToken) && !(!options.after && nextToken.type === "Line") && utils.isTokenOnSameLine(token, nextToken) && options.after !== sourceCode.isSpaceBetweenTokens(token, nextToken))
}
if (nextToken && !utils.isCommaToken(nextToken) && !utils.isClosingParenToken(nextToken) && !utils.isClosingBracketToken(nextToken) && !utils.isClosingBraceToken(nextToken) && !(!options.after && nextToken.type === "Line") && utils.isTokenOnSameLine(token, nextToken) && options.after !== sourceCode.isSpaceBetweenTokens(token, nextToken)) {
report(token, "after", nextToken);
}
});

@@ -95,0 +97,0 @@ },

@@ -613,4 +613,5 @@ 'use strict';

let statement = node.parent && node.parent.parent;
while (statement.type === "UnaryExpression" && ["!", "~", "+", "-"].includes(statement.operator) || statement.type === "AssignmentExpression" || statement.type === "LogicalExpression" || statement.type === "SequenceExpression" || statement.type === "VariableDeclarator")
while (statement.type === "UnaryExpression" && ["!", "~", "+", "-"].includes(statement.operator) || statement.type === "AssignmentExpression" || statement.type === "LogicalExpression" || statement.type === "SequenceExpression" || statement.type === "VariableDeclarator") {
statement = statement.parent;
}
return (statement.type === "ExpressionStatement" || statement.type === "VariableDeclaration") && statement.parent.type === "Program";

@@ -951,4 +952,5 @@ }

NewExpression(node) {
if (node.arguments.length > 0 || utils.isClosingParenToken(sourceCode.getLastToken(node)) && utils.isOpeningParenToken(sourceCode.getLastToken(node, 1)))
if (node.arguments.length > 0 || utils.isClosingParenToken(sourceCode.getLastToken(node)) && utils.isOpeningParenToken(sourceCode.getLastToken(node, 1))) {
addFunctionCallIndent(node);
}
},

@@ -1145,53 +1147,108 @@ Property(node) {

);
return Object.assign(
offsetListeners,
ignoredNodeListeners,
{
"*:exit": function(node) {
if (!KNOWN_NODES.has(node.type))
addToIgnoredNodes(node);
},
"Program:exit": function() {
if (options.ignoreComments) {
sourceCode.getAllComments().forEach((comment) => offsets.ignoreToken(comment));
function getNodeIndent(node, byLastLine = false, excludeCommas = false) {
let src = context.sourceCode.getText(node, node.loc.start.column);
const lines = src.split("\n");
if (byLastLine)
src = lines[lines.length - 1];
else
src = lines[0];
const skip = excludeCommas ? "," : "";
let regExp;
if (indentType === "space")
regExp = new RegExp(`^[ ${skip}]+`);
else
regExp = new RegExp(`^[ ${skip}]+`);
const indent = regExp.exec(src);
return indent ? indent[0].length : 0;
}
function handleJSXTextnode(node) {
if (!node.parent)
return;
if (node.parent.type !== "JSXElement" && node.parent.type !== "JSXFragment")
return;
const value = node.value;
const regExp = indentType === "space" ? /\n( *)[\t ]*\S/g : /\n(\t*)[\t ]*\S/g;
const nodeIndentsPerLine = Array.from(
String(value).matchAll(regExp),
(match) => match[1] ? match[1].length : 0
);
const hasFirstInLineNode = nodeIndentsPerLine.length > 0;
const parentNodeIndent = getNodeIndent(node.parent);
const indent = parentNodeIndent + indentSize;
if (hasFirstInLineNode && !nodeIndentsPerLine.every((actualIndent) => actualIndent === indent)) {
nodeIndentsPerLine.forEach((nodeIndent) => {
context.report({
node,
messageId: "wrongIndentation",
data: createErrorMessageData(indent, nodeIndent, nodeIndent),
fix: getFixerFunction(node, indent)
});
});
}
}
const indentChar = indentType === "space" ? " " : " ";
function getFixerFunction(node, needed) {
const indent = Array(needed + 1).join(indentChar);
return function fix(fixer) {
const regExp = /\n[\t ]*(\S)/g;
const fixedText = node.raw.replace(regExp, (match, p1) => `
${indent}${p1}`);
return fixer.replaceText(node, fixedText);
};
}
return {
// Listeners
...offsetListeners,
// Special handling for JSXText nodes
"JSXText": handleJSXTextnode,
// Ignored nodes
...ignoredNodeListeners,
// Validate indentation of all tokens at the end
"*:exit": function(node) {
if (!KNOWN_NODES.has(node.type))
addToIgnoredNodes(node);
},
"Program:exit": function() {
if (options.ignoreComments) {
sourceCode.getAllComments().forEach((comment) => offsets.ignoreToken(comment));
}
for (let i = 0; i < listenerCallQueue.length; i++) {
const nodeInfo = listenerCallQueue[i];
if (!ignoredNodes.has(nodeInfo.node))
nodeInfo.listener?.(nodeInfo.node);
}
ignoredNodes.forEach(ignoreNode);
addParensIndent(sourceCode.ast.tokens);
const precedingTokens = /* @__PURE__ */ new WeakMap();
for (let i = 0; i < sourceCode.ast.comments.length; i++) {
const comment = sourceCode.ast.comments[i];
const tokenOrCommentBefore = sourceCode.getTokenBefore(comment, { includeComments: true });
const hasToken = precedingTokens.has(tokenOrCommentBefore) ? precedingTokens.get(tokenOrCommentBefore) : tokenOrCommentBefore;
precedingTokens.set(comment, hasToken);
}
for (let i = 1; i < sourceCode.lines.length + 1; i++) {
if (!tokenInfo.firstTokensByLineNumber.has(i)) {
continue;
}
for (let i = 0; i < listenerCallQueue.length; i++) {
const nodeInfo = listenerCallQueue[i];
if (!ignoredNodes.has(nodeInfo.node))
nodeInfo.listener?.(nodeInfo.node);
const firstTokenOfLine = tokenInfo.firstTokensByLineNumber.get(i);
if (firstTokenOfLine.loc.start.line !== i) {
continue;
}
ignoredNodes.forEach(ignoreNode);
addParensIndent(sourceCode.ast.tokens);
const precedingTokens = /* @__PURE__ */ new WeakMap();
for (let i = 0; i < sourceCode.ast.comments.length; i++) {
const comment = sourceCode.ast.comments[i];
const tokenOrCommentBefore = sourceCode.getTokenBefore(comment, { includeComments: true });
const hasToken = precedingTokens.has(tokenOrCommentBefore) ? precedingTokens.get(tokenOrCommentBefore) : tokenOrCommentBefore;
precedingTokens.set(comment, hasToken);
}
for (let i = 1; i < sourceCode.lines.length + 1; i++) {
if (!tokenInfo.firstTokensByLineNumber.has(i)) {
if (utils.isCommentToken(firstTokenOfLine)) {
const tokenBefore = precedingTokens.get(firstTokenOfLine);
const tokenAfter = tokenBefore ? sourceCode.getTokenAfter(tokenBefore) : sourceCode.ast.tokens[0];
const mayAlignWithBefore = tokenBefore && !hasBlankLinesBetween(tokenBefore, firstTokenOfLine);
const mayAlignWithAfter = tokenAfter && !hasBlankLinesBetween(firstTokenOfLine, tokenAfter);
if (tokenAfter && utils.isSemicolonToken(tokenAfter) && !utils.isTokenOnSameLine(firstTokenOfLine, tokenAfter))
offsets.setDesiredOffset(firstTokenOfLine, tokenAfter, 0);
if (mayAlignWithBefore && validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenBefore)) || mayAlignWithAfter && validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenAfter))) {
continue;
}
const firstTokenOfLine = tokenInfo.firstTokensByLineNumber.get(i);
if (firstTokenOfLine.loc.start.line !== i) {
continue;
}
if (utils.isCommentToken(firstTokenOfLine)) {
const tokenBefore = precedingTokens.get(firstTokenOfLine);
const tokenAfter = tokenBefore ? sourceCode.getTokenAfter(tokenBefore) : sourceCode.ast.tokens[0];
const mayAlignWithBefore = tokenBefore && !hasBlankLinesBetween(tokenBefore, firstTokenOfLine);
const mayAlignWithAfter = tokenAfter && !hasBlankLinesBetween(firstTokenOfLine, tokenAfter);
if (tokenAfter && utils.isSemicolonToken(tokenAfter) && !utils.isTokenOnSameLine(firstTokenOfLine, tokenAfter))
offsets.setDesiredOffset(firstTokenOfLine, tokenAfter, 0);
if (mayAlignWithBefore && validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenBefore)) || mayAlignWithAfter && validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenAfter)))
continue;
}
if (validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine)))
continue;
report(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine));
}
if (validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine)))
continue;
report(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine));
}
}
);
};
}

@@ -1198,0 +1255,0 @@ });

@@ -180,4 +180,5 @@ 'use strict';

const firstToken = node && sourceCode.getFirstToken(node);
if (firstToken && (firstToken.type === "Keyword" && firstToken.value === "function" || firstToken.value === "async"))
if (firstToken && (firstToken.type === "Keyword" && firstToken.value === "function" || firstToken.value === "async")) {
checkSpacingBefore(firstToken);
}
}

@@ -184,0 +185,0 @@ function checkSpacingForClass(node) {

@@ -56,4 +56,5 @@ 'use strict';

const line = node.loc.start.line;
if (node.parent && SINGLE_CHILD_ALLOWED.test(node.parent.type) && (!("alternate" in node.parent) || node.parent.alternate !== node))
if (node.parent && SINGLE_CHILD_ALLOWED.test(node.parent.type) && (!("alternate" in node.parent) || node.parent.alternate !== node)) {
return;
}
if (line === lastStatementLine) {

@@ -60,0 +61,0 @@ numberOfStatementsOnThisLine += 1;

@@ -279,6 +279,7 @@ 'use strict';

const tokenBefore = sourceCode.getTokenBefore(comment, { includeComments: true });
if (comment.type === "Line" && index && commentList[index - 1].type === "Line" && tokenBefore && tokenBefore.loc.end.line === comment.loc.start.line - 1 && tokenBefore === commentList[index - 1])
if (comment.type === "Line" && index && commentList[index - 1].type === "Line" && tokenBefore && tokenBefore.loc.end.line === comment.loc.start.line - 1 && tokenBefore === commentList[index - 1]) {
commentGroups.at(-1).push(comment);
else
} else {
commentGroups.push([comment]);
}
return commentGroups;

@@ -285,0 +286,0 @@ }, []).filter((commentGroup) => !(commentGroup.length === 1 && commentGroup[0].loc.start.line === commentGroup[0].loc.end.line)).forEach(commentGroupCheckers[option]);

@@ -53,4 +53,5 @@ 'use strict';

if (IGNORE_JSX) {
if (node.parent.type === "JSXElement" || node.parent.type === "JSXFragment" || node.parent.type === "JSXExpressionContainer")
if (node.parent.type === "JSXElement" || node.parent.type === "JSXFragment" || node.parent.type === "JSXExpressionContainer") {
return null;
}
}

@@ -57,0 +58,0 @@ if (!multiline) {

@@ -116,4 +116,5 @@ 'use strict';

if (ruleApplies(node) && isParenthesised(node)) {
if (precedence(node) >= precedenceLowerLimit || isParenthesisedTwice(node))
if (precedence(node) >= precedenceLowerLimit || isParenthesisedTwice(node)) {
return true;
}
}

@@ -127,4 +128,5 @@ return false;

for (let currentNode = node; currentNode; currentNode = currentNode.parent) {
if (currentNode.type === "ReturnStatement" || currentNode.type === "ArrowFunctionExpression" && currentNode.body.type !== "BlockStatement")
if (currentNode.type === "ReturnStatement" || currentNode.type === "ArrowFunctionExpression" && currentNode.body.type !== "BlockStatement") {
return true;
}
}

@@ -142,6 +144,8 @@ return false;

return true;
if (node.type === "ConditionalExpression" && (node.consequent.type === "AssignmentExpression" || node.alternate.type === "AssignmentExpression"))
if (node.type === "ConditionalExpression" && (node.consequent.type === "AssignmentExpression" || node.alternate.type === "AssignmentExpression")) {
return true;
if ("left" in node && (node.left && node.left.type === "AssignmentExpression" || node.right && node.right.type === "AssignmentExpression"))
}
if ("left" in node && (node.left && node.left.type === "AssignmentExpression" || node.right && node.right.type === "AssignmentExpression")) {
return true;
}
return false;

@@ -202,4 +206,5 @@ }

const ignorePattern = new RegExp(ALLOW_PARENS_AFTER_COMMENT_PATTERN, "u");
if (totalCommentsBeforeLeftParenTokenCount > 0 && ignorePattern.test(commentsBeforeLeftParenToken[totalCommentsBeforeLeftParenTokenCount - 1].value))
if (totalCommentsBeforeLeftParenTokenCount > 0 && ignorePattern.test(commentsBeforeLeftParenToken[totalCommentsBeforeLeftParenTokenCount - 1].value)) {
return;
}
}

@@ -246,4 +251,5 @@ }

if (hasDoubleExcessParens(callee) || !(isIIFE(node) || // @ts-expect-error comment above
callee.type === "NewExpression" && !isNewExpressionWithParens(callee) && !(node.type === "NewExpression" && !isNewExpressionWithParens(node)) || node.type === "NewExpression" && callee.type === "MemberExpression" && doesMemberExpressionContainCallExpression(callee) || (!("optional" in node) || !node.optional) && callee.type === "ChainExpression"))
callee.type === "NewExpression" && !isNewExpressionWithParens(callee) && !(node.type === "NewExpression" && !isNewExpressionWithParens(node)) || node.type === "NewExpression" && callee.type === "MemberExpression" && doesMemberExpressionContainCallExpression(callee) || (!("optional" in node) || !node.optional) && callee.type === "ChainExpression")) {
report(node.callee);
}
}

@@ -260,8 +266,10 @@ node.arguments.filter((arg) => hasExcessParensWithPrecedence(arg, PRECEDENCE_OF_ASSIGNMENT_EXPR)).forEach(report);

if (!shouldSkipLeft && hasExcessParens(node.left)) {
if (!(["AwaitExpression", "UnaryExpression"].includes(node.left.type) && isExponentiation) && !utils.isMixedLogicalAndCoalesceExpressions(node.left, node) && (leftPrecedence > prec || leftPrecedence === prec && !isExponentiation) || isParenthesisedTwice(node.left))
if (!(["AwaitExpression", "UnaryExpression"].includes(node.left.type) && isExponentiation) && !utils.isMixedLogicalAndCoalesceExpressions(node.left, node) && (leftPrecedence > prec || leftPrecedence === prec && !isExponentiation) || isParenthesisedTwice(node.left)) {
report(node.left);
}
}
if (!shouldSkipRight && hasExcessParens(node.right)) {
if (!utils.isMixedLogicalAndCoalesceExpressions(node.right, node) && (rightPrecedence > prec || rightPrecedence === prec && isExponentiation) || isParenthesisedTwice(node.right))
if (!utils.isMixedLogicalAndCoalesceExpressions(node.right, node) && (rightPrecedence > prec || rightPrecedence === prec && isExponentiation) || isParenthesisedTwice(node.right)) {
report(node.right);
}
}

@@ -285,4 +293,5 @@ }

const tokenAfterClosingParens = secondToken ? sourceCode.getTokenAfter(secondToken, utils.isNotClosingParenToken) : null;
if (utils.isOpeningParenToken(firstToken) && (utils.isOpeningBraceToken(secondToken) || secondToken.type === "Keyword" && (secondToken.value === "function" || secondToken.value === "class" || secondToken.value === "let" && tokenAfterClosingParens && (utils.isOpeningBracketToken(tokenAfterClosingParens) || tokenAfterClosingParens.type === "Identifier")) || secondToken && secondToken.type === "Identifier" && secondToken.value === "async" && thirdToken && thirdToken.type === "Keyword" && thirdToken.value === "function"))
if (utils.isOpeningParenToken(firstToken) && (utils.isOpeningBraceToken(secondToken) || secondToken.type === "Keyword" && (secondToken.value === "function" || secondToken.value === "class" || secondToken.value === "let" && tokenAfterClosingParens && (utils.isOpeningBracketToken(tokenAfterClosingParens) || tokenAfterClosingParens.type === "Identifier")) || secondToken && secondToken.type === "Identifier" && secondToken.value === "async" && thirdToken && thirdToken.type === "Keyword" && thirdToken.value === "function")) {
tokensToIgnore.add(secondToken);
}
const hasExtraParens = node.parent.type === "ExportDefaultDeclaration" ? hasExcessParensWithPrecedence(node, PRECEDENCE_OF_ASSIGNMENT_EXPR) : hasExcessParens(node);

@@ -379,4 +388,5 @@ if (hasExtraParens)

return;
if (node.body.type === "ConditionalExpression" && IGNORE_ARROW_CONDITIONALS)
if (node.body.type === "ConditionalExpression" && IGNORE_ARROW_CONDITIONALS) {
return;
}
if (node.body.type !== "BlockStatement") {

@@ -392,4 +402,5 @@ const firstBodyToken = sourceCode.getFirstToken(node.body, utils.isNotOpeningParenToken);

AssignmentExpression(node) {
if (canBeAssignmentTarget(node.left) && hasExcessParens(node.left) && (!isAnonymousFunctionAssignmentException(node) || isParenthesisedTwice(node.left)))
if (canBeAssignmentTarget(node.left) && hasExcessParens(node.left) && (!isAnonymousFunctionAssignmentException(node) || isParenthesisedTwice(node.left))) {
report(node.left);
}
if (!isReturnAssignException(node) && hasExcessParensWithPrecedence(node.right, precedence(node)))

@@ -408,8 +419,11 @@ report(node.right);

const availableTypes = /* @__PURE__ */ new Set(["BinaryExpression", "LogicalExpression"]);
if (!(EXCEPT_COND_TERNARY && availableTypes.has(node.test.type)) && !isCondAssignException(node) && hasExcessParensWithPrecedence(node.test, precedence({ type: "LogicalExpression", operator: "||" })))
if (!(EXCEPT_COND_TERNARY && availableTypes.has(node.test.type)) && !isCondAssignException(node) && hasExcessParensWithPrecedence(node.test, precedence({ type: "LogicalExpression", operator: "||" }))) {
report(node.test);
if (!(EXCEPT_COND_TERNARY && availableTypes.has(node.consequent.type)) && hasExcessParensWithPrecedence(node.consequent, PRECEDENCE_OF_ASSIGNMENT_EXPR))
}
if (!(EXCEPT_COND_TERNARY && availableTypes.has(node.consequent.type)) && hasExcessParensWithPrecedence(node.consequent, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
report(node.consequent);
if (!(EXCEPT_COND_TERNARY && availableTypes.has(node.alternate.type)) && hasExcessParensWithPrecedence(node.alternate, PRECEDENCE_OF_ASSIGNMENT_EXPR))
}
if (!(EXCEPT_COND_TERNARY && availableTypes.has(node.alternate.type)) && hasExcessParensWithPrecedence(node.alternate, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
report(node.alternate);
}
},

@@ -515,10 +529,14 @@ DoWhileStatement(node) {

const nodeObjHasExcessParens = shouldAllowWrapOnce ? hasDoubleExcessParens(node.object) : hasExcessParens(node.object) && !(isImmediateFunctionPrototypeMethodCall(node.parent) && "callee" in node.parent && node.parent.callee === node && IGNORE_FUNCTION_PROTOTYPE_METHODS);
if (nodeObjHasExcessParens && precedence(node.object) >= precedence(node) && (node.computed || !(utils.isDecimalInteger(node.object) || node.object.type === "Literal" && "regex" in node.object && node.object.regex)))
if (nodeObjHasExcessParens && precedence(node.object) >= precedence(node) && (node.computed || !(utils.isDecimalInteger(node.object) || node.object.type === "Literal" && "regex" in node.object && node.object.regex))) {
report(node.object);
if (nodeObjHasExcessParens && node.object.type === "CallExpression")
}
if (nodeObjHasExcessParens && node.object.type === "CallExpression") {
report(node.object);
if (nodeObjHasExcessParens && !IGNORE_NEW_IN_MEMBER_EXPR && node.object.type === "NewExpression" && isNewExpressionWithParens(node.object))
}
if (nodeObjHasExcessParens && !IGNORE_NEW_IN_MEMBER_EXPR && node.object.type === "NewExpression" && isNewExpressionWithParens(node.object)) {
report(node.object);
if (nodeObjHasExcessParens && node.optional && node.object.type === "ChainExpression")
}
if (nodeObjHasExcessParens && node.optional && node.object.type === "ChainExpression") {
report(node.object);
}
if (node.computed && hasExcessParens(node.property))

@@ -563,4 +581,5 @@ report(node.property);

return;
if (node.argument && returnToken && hasExcessParensNoLineTerminator(returnToken, node.argument) && !(node.argument.type === "Literal" && "regex" in node.argument && node.argument.regex))
if (node.argument && returnToken && hasExcessParensNoLineTerminator(returnToken, node.argument) && !(node.argument.type === "Literal" && "regex" in node.argument && node.argument.regex)) {
report(node.argument);
}
},

@@ -601,4 +620,5 @@ SequenceExpression(node) {

VariableDeclarator(node) {
if (node.init && hasExcessParensWithPrecedence(node.init, PRECEDENCE_OF_ASSIGNMENT_EXPR) && !(node.init.type === "Literal" && "regex" in node.init && node.init.regex))
if (node.init && hasExcessParensWithPrecedence(node.init, PRECEDENCE_OF_ASSIGNMENT_EXPR) && !(node.init.type === "Literal" && "regex" in node.init && node.init.regex)) {
report(node.init);
}
},

@@ -616,4 +636,5 @@ WhileStatement(node) {

const yieldToken = sourceCode.getFirstToken(node);
if (precedence(node.argument) >= precedence(node) && yieldToken && hasExcessParensNoLineTerminator(yieldToken, node.argument) || hasDoubleExcessParens(node.argument))
if (precedence(node.argument) >= precedence(node) && yieldToken && hasExcessParensNoLineTerminator(yieldToken, node.argument) || hasDoubleExcessParens(node.argument)) {
report(node.argument);
}
}

@@ -620,0 +641,0 @@ },

@@ -120,4 +120,5 @@ 'use strict';

function check(node) {
if (TARGET_NODE_TYPE.test(node.parent.type) && isMixedWithParent(node) && !shouldIgnore(node))
if (TARGET_NODE_TYPE.test(node.parent.type) && isMixedWithParent(node) && !shouldIgnore(node)) {
reportBothOperators(node);
}
}

@@ -124,0 +125,0 @@ return {

@@ -61,6 +61,8 @@ 'use strict';

const rightToken = tokensAndComments[leftIndex + 1];
if (!spacesRe.test(sourceCode.text.slice(leftToken.range[1], rightToken.range[0])) || leftToken.loc.end.line < rightToken.loc.start.line)
if (!spacesRe.test(sourceCode.text.slice(leftToken.range[1], rightToken.range[0])) || leftToken.loc.end.line < rightToken.loc.start.line) {
return;
if (ignoreEOLComments && utils.isCommentToken(rightToken) && (leftIndex === tokensAndComments.length - 2 || rightToken.loc.end.line < tokensAndComments[leftIndex + 2].loc.start.line))
}
if (ignoreEOLComments && utils.isCommentToken(rightToken) && (leftIndex === tokensAndComments.length - 2 || rightToken.loc.end.line < tokensAndComments[leftIndex + 2].loc.start.line)) {
return;
}
if (hasExceptions) {

@@ -67,0 +69,0 @@ const parentNode = sourceCode.getNodeByRangeIndex(rightToken.range[0] - 1);

@@ -114,4 +114,5 @@ 'use strict';

const options = normalizedOptions[node.type];
if (node.type === "ImportDeclaration" && !node.specifiers.some((specifier) => specifier.type === "ImportSpecifier") || node.type === "ExportNamedDeclaration" && !node.specifiers.some((specifier) => specifier.type === "ExportSpecifier"))
if (node.type === "ImportDeclaration" && !node.specifiers.some((specifier) => specifier.type === "ImportSpecifier") || node.type === "ExportNamedDeclaration" && !node.specifiers.some((specifier) => specifier.type === "ExportSpecifier")) {
return;
}
const openBrace = sourceCode.getFirstToken(node, (token) => token.value === "{");

@@ -118,0 +119,0 @@ let closeBrace;

@@ -66,4 +66,5 @@ 'use strict';

if (hasLinebreakBefore !== hasLinebreakAfter && desiredStyle !== "none") {
if (sourceCode.getTokenBefore(operatorToken, { includeComments: true }) !== tokenBefore && sourceCode.getTokenAfter(operatorToken, { includeComments: true }) !== tokenAfter)
if (sourceCode.getTokenBefore(operatorToken, { includeComments: true }) !== tokenBefore && sourceCode.getTokenAfter(operatorToken, { includeComments: true }) !== tokenAfter) {
return null;
}
newTextBefore = textAfter;

@@ -70,0 +71,0 @@ newTextAfter = textBefore;

@@ -69,2 +69,5 @@ 'use strict';

type: "boolean"
},
ignoreStringLiterals: {
type: "boolean"
}

@@ -86,2 +89,3 @@ },

const allowTemplateLiterals = options && typeof options === "object" && options.allowTemplateLiterals === true;
const ignoreStringLiterals = options && typeof options === "object" && options.ignoreStringLiterals === true;
const sourceCode = context.sourceCode;

@@ -156,2 +160,4 @@ let avoidEscape = options && typeof options === "object" && options.avoidEscape === true;

Literal(node) {
if (ignoreStringLiterals)
return;
const val = node.value;

@@ -181,4 +187,7 @@ const rawVal = node.raw;

TemplateLiteral(node) {
if (allowTemplateLiterals || quoteOption === "backtick" || isUsingFeatureOfTemplateLiteral(node))
if (allowTemplateLiterals || quoteOption === "backtick" || isUsingFeatureOfTemplateLiteral(node)) {
return;
}
if (avoidEscape && sourceCode.getText(node).includes(settings.quote))
return;
context.report({

@@ -185,0 +194,0 @@ node,

@@ -22,4 +22,5 @@ 'use strict';

const t = node.type;
if (t === "BlockStatement" || t === "StaticBlock" || t === "Program" || t === "ClassBody")
if (t === "BlockStatement" || t === "StaticBlock" || t === "Program" || t === "ClassBody") {
return node.body;
}
if (t === "SwitchCase")

@@ -26,0 +27,0 @@ return node.consequent;

@@ -127,4 +127,5 @@ 'use strict';

const t = node.type;
if (t === "DoWhileStatement" || t === "BreakStatement" || t === "ContinueStatement" || t === "DebuggerStatement" || t === "ImportDeclaration" || t === "ExportAllDeclaration")
if (t === "DoWhileStatement" || t === "BreakStatement" || t === "ContinueStatement" || t === "DebuggerStatement" || t === "ImportDeclaration" || t === "ExportAllDeclaration") {
return false;
}
if (t === "ReturnStatement")

@@ -150,4 +151,5 @@ return Boolean(node.argument);

return false;
if (node.type !== "PropertyDefinition" && beforeStatementContinuationChars === "never" && !maybeAsiHazardAfter(node))
if (node.type !== "PropertyDefinition" && beforeStatementContinuationChars === "never" && !maybeAsiHazardAfter(node)) {
return true;
}
const nextToken = sourceCode.getTokenAfter(node);

@@ -185,6 +187,7 @@ if (!maybeAsiHazardBefore(nextToken))

const nextToken = sourceCode.getTokenAfter(node);
if (isSemi && canRemoveSemicolon(node))
if (isSemi && canRemoveSemicolon(node)) {
report(node, true);
else if (!isSemi && beforeStatementContinuationChars === "always" && node.type !== "PropertyDefinition" && maybeAsiHazardBefore(nextToken))
} else if (!isSemi && beforeStatementContinuationChars === "always" && node.type !== "PropertyDefinition" && maybeAsiHazardBefore(nextToken)) {
report(node);
}
} else {

@@ -202,4 +205,5 @@ const oneLinerBlock = exceptOneLine && isLastInOneLinerBlock(node);

const parent = node.parent;
if ((parent.type !== "ForStatement" || parent.init !== node) && (!/^For(?:In|Of)Statement/u.test(parent.type) || parent.left !== node))
if ((parent.type !== "ForStatement" || parent.init !== node) && (!/^For(?:In|Of)Statement/u.test(parent.type) || parent.left !== node)) {
checkForSemicolon(node);
}
}

@@ -206,0 +210,0 @@ return {

@@ -101,4 +101,5 @@ 'use strict';

const rightToken = sourceCode.getTokenAfter(operatorToken);
if (!sourceCode.isSpaceBetweenTokens(leftToken, operatorToken) || !sourceCode.isSpaceBetweenTokens(operatorToken, rightToken))
if (!sourceCode.isSpaceBetweenTokens(leftToken, operatorToken) || !sourceCode.isSpaceBetweenTokens(operatorToken, rightToken)) {
report(node, operatorToken);
}
}

@@ -105,0 +106,0 @@ };

@@ -12,3 +12,3 @@ 'use strict';

const DECIMAL_INTEGER_PATTERN = /^(?:0|0[0-7]*[89]\d*|[1-9](?:_?\d)*)$/u;
const OCTAL_OR_NON_OCTAL_DECIMAL_ESCAPE_PATTERN = /^(?:[^\\]|\\.)*\\(?:[1-9]|0[0-9])/su;
const OCTAL_OR_NON_OCTAL_DECIMAL_ESCAPE_PATTERN = /^(?:[^\\]|\\.)*\\(?:[1-9]|0\d)/su;
function createGlobalLinebreakMatcher() {

@@ -15,0 +15,0 @@ return new RegExp(LINEBREAK_MATCHER.source, "gu");

@@ -53,4 +53,5 @@ 'use strict';

return callee;
if (includeFunctionPrototypeMethods && callee.type === "MemberExpression" && callee.object.type === "FunctionExpression" && (utils.getStaticPropertyName(callee) === "call" || utils.getStaticPropertyName(callee) === "apply"))
if (includeFunctionPrototypeMethods && callee.type === "MemberExpression" && callee.object.type === "FunctionExpression" && (utils.getStaticPropertyName(callee) === "call" || utils.getStaticPropertyName(callee) === "apply")) {
return callee.object;
}
return null;

@@ -57,0 +58,0 @@ }

{
"name": "@stylistic/eslint-plugin-js",
"version": "2.1.0",
"version": "2.2.0",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",

@@ -119,3 +119,3 @@ "license": "MIT",

"@eslint-community/eslint-utils": "^4.4.0",
"@typescript-eslint/parser": "^7.8.0",
"@typescript-eslint/parser": "^7.12.0",
"escape-string-regexp": "^5.0.0"

@@ -122,0 +122,0 @@ },

@@ -10,2 +10,3 @@ /* GENERATED, DO NOT EDIT DIRECTLY */

allowTemplateLiterals?: boolean
ignoreStringLiterals?: boolean
}

@@ -12,0 +13,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc