ModularVencord/patches/@stylistic__eslint-plugin-js@2.6.4.patch
2024-08-23 20:13:24 -04:00

52 lines
1.9 KiB
Diff

diff --git a/dist/brace-style.js b/dist/brace-style.js
index 023fe9fb129d75d77b0b550ff9564c8185c4020e..0fc762a5bd21bb6ff5ad2e6e9ef6682065b98b78 100644
--- a/dist/brace-style.js
+++ b/dist/brace-style.js
@@ -2,6 +2,38 @@
var utils = require('./utils.js');
+function* getAllCommentRanges(sourceCode) {
+ for (const { loc } of sourceCode.getAllComments())
+ if (loc) yield [loc.start.line, loc.end.line];
+}
+
+function createLineSet(length) {
+ return (1n << BigInt(length)) - 1n;
+}
+
+function isTokenOnSameLine(left, right, sourceCode) {
+ const leftEnd = left?.loc?.end.line;
+ const rightStart = right?.loc?.start.line;
+ if (leftEnd === rightStart) return true;
+ if (leftEnd !== undefined && rightStart !== undefined) {
+ if (rightStart - leftEnd <= 1) {
+ for (const [start, end] of getAllCommentRanges(sourceCode))
+ if (start === leftEnd || end === rightStart) return true;
+ } else {
+ const targetLines = createLineSet(rightStart - leftEnd - 1);
+ let totalLines = 0n;
+ for (let [start, end] of getAllCommentRanges(sourceCode)) {
+ if (start >= rightStart || end <= leftEnd) continue;
+ start = Math.max(start, leftEnd + 1);
+ end = Math.min(rightStart - 1, end);
+ totalLines |= createLineSet(end - start + 1) << BigInt(start - leftEnd - 1);
+ if (totalLines === targetLines) return true;
+ }
+ }
+ }
+ return false;
+}
+
var braceStyle = utils.createRule({
name: "brace-style",
package: "js",
@@ -86,7 +118,7 @@ var braceStyle = utils.createRule({
}
function validateCurlyBeforeKeyword(curlyToken) {
const keywordToken = sourceCode.getTokenAfter(curlyToken);
- if (style === "1tbs" && !utils.isTokenOnSameLine(curlyToken, keywordToken)) {
+ if (style === "1tbs" && !isTokenOnSameLine(curlyToken, keywordToken, sourceCode)) {
context.report({
node: curlyToken,
messageId: "nextLineClose",