eslint-plugin-sukka 8.0.6 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=require("@eslint-sukka/shared"),r=require("eslint"),n=require("foxts/guard"),o=require("foxts/detect-eol"),s=require("@typescript-eslint/types"),i=require("typescript"),a=require("@typescript-eslint/utils"),l=(e=Object.create(null),i&&Object.keys(i).forEach(function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:function(){return i[t]}})}}),e.default=i,Object.freeze(e));let c=/^\s*(?<directive>eslint-disable(?:-(?:next-)?line)?)/,u=/^eslint-disable(?:-next-line|-line)?(?<ruleId>$|(?:\s+(?:@(?:[\w-]+\/){1,2})?[\w-]+)?)/,p=Symbol("rule-id-no-match");var d=t.createRule({name:"ban-eslint-disable",meta:{type:"problem",docs:{description:"Ban `eslint-disable` comment directive"},schema:[{oneOf:[{type:"boolean"},{type:"string",enum:["allow-with-description"]}]}],messages:{"do-not-use":"Do not use `{{directive}}`","require-description":"Include a description after the `{{directive}}` directive to explain why the `{{directive}}` is necessary.","require-specific-rule":"Enforce specifying rules to disable in `eslint-disable` comments. If you want to disable ESLint on a file altogether, you should ignore it through ESLint configuration."}},create:(e,t="allow-with-description")=>!1===t?{}:{Program(r){if(r.comments&&0!==r.comments.length)for(let n of r.comments){let r=function(e){let t=c.exec(e);return t?.groups?.directive}(n.value);if(r&&("allow-with-description"!==t||!n.value.includes("--"))){let o="allow-with-description"===t?"require-description":"do-not-use";e.report({node:n,data:{directive:r},messageId:o})}let o=function(e){let t=u.exec(e.trim());return t?t.groups?.ruleId:p}(n.value);o===p||o||e.report({node:n,messageId:"require-specific-rule"})}}}});let m=n.nullthrow(new r.Linter({configType:"eslintrc"}).getRules().get("no-return-await"),"[eslint-plugin-sukka] no-return-await rule is removed from ESLint!");var f=t.createRule({...m,meta:{docs:{...m.meta?.docs,recommended:void 0},...m.meta,deprecated:!1}}),g=t.createRule({name:"no-expression-empty-lines",meta:{messages:{unexpectedEmptyLine:"Unexpected empty line before"},docs:{description:"Disallows empty lines inside expressions."},fixable:"whitespace",type:"suggestion",schema:[]},create(e){let t=e.sourceCode.getText(),r=o.detectEol(t);return{MemberExpression(n){let o=n.object.range[1],s=h(t.slice(o));if(s.includes("\n")){var i;let t=r+((h(i=s).split(/\r\n|\n/u).at(-1)??"")+i.trimStart());s!==t&&e.report({fix:()=>({range:[o,o+s.length],text:t}),messageId:"unexpectedEmptyLine",node:n.property})}}}}});function h(e){return e.slice(0,e.length-e.trimStart().length)}var S=t.createRule({name:"object-format",meta:{fixable:"whitespace",schema:[{type:"object",properties:{maxLineLength:{type:"number",default:80},maxObjectSize:{type:"number",default:3}},additionalProperties:!1}],docs:{description:"Requires multiline or single-line object format.",recommended:"stylistic"},messages:{preferMultiline:"Prefer multiline object literal",preferSingleLine:"Prefer single-line object literal"},type:"layout"},create(e,t={}){var r;let n=e.sourceCode.getText(),s=o.detectEol(n),i=`,${s}`,{maxLineLength:a=80,maxObjectSize:l=3}=t,c=(r=n,e=>r.slice(e.range[1]).trimStart().startsWith("//"));return{ObjectExpression(t){let r=t.properties.map(t=>n.slice(Math.min(t.range[0],...e.sourceCode.getCommentsBefore(t).map(e=>e.range[0])),t.range[1]).trim());if(r.length>0){var o;let u,p,d,m,f=e.sourceCode.getText(t),g=r.length>l||r.some(y)||t.properties.some(c),h=y(f),S=!f.includes("\n");g&&S&&e.report({fix:()=>({range:t.range,text:`{${s}${r.join(i)}${s}}`}),messageId:"preferMultiline",node:t}),!g&&h&&(u=e.sourceCode.getLocFromIndex(t.range[0]),p=r.reduce((e,t)=>e+t.length,0),d=2*(r.length-1),m=("number"==typeof(o=t.range[1])?n.slice(o):n.slice(...o.range)).split(/\r\n|\n/u)[0].replace(/^((?: as const)?\S*).*/u,"$1").length,u.column+p+d+4+m<=a)&&e.report({fix:()=>({range:t.range,text:`{${r.join(",")}}`}),messageId:"preferSingleLine",node:t})}}}}});function y(e){return e.includes("\n")}var E=t.createRule({name:"prefer-single-boolean-return",meta:{messages:{replaceIfThenElseByReturn:"Replace this if-then-else flow by a single return statement.",suggest:"Replace with single return statement",suggestCast:'Replace with single return statement using "!!" cast',suggestBoolean:"Replace with single return statement without cast (condition should be boolean!)"},schema:[],type:"suggestion",hasSuggestions:!0,docs:{description:'Return of boolean expressions should not be wrapped into an "if-then-else" statement',recommended:"recommended"}},create:e=>({IfStatement(t){var r,n,o;let i,a,l,c;t.parent.type!==s.AST_NODE_TYPES.IfStatement&&_(t.consequent)&&function(e){if(e.alternate)return _(e.alternate);let{parent:t}=e;if(t.type===s.AST_NODE_TYPES.BlockStatement){let r=t.body.indexOf(e);return T(t.body[r+1])}return!1}(t)&&e.report({messageId:"replaceIfThenElseByReturn",node:t,suggest:(r=t,i=e=>t=>{let n=`return ${e};`;if(r.alternate)return t.replaceText(r,n);let o=r.parent,s=o.body.indexOf(r),i=o.body[s+1],a=[r.range[0],i.range[1]];return t.replaceTextRange(a,n)},a=!1===((n=r.consequent).type===s.AST_NODE_TYPES.BlockStatement?n.body[0]:n).argument.value,l=!(((o=r.test).type===s.AST_NODE_TYPES.UnaryExpression||o.type===s.AST_NODE_TYPES.BinaryExpression)&&["!","==","===","!=","!==","<","<=",">",">=","in","instanceof"].includes(o.operator)),c=e.sourceCode.getText(r.test),a?[{messageId:"suggest",fix:i(`!(${c})`)}]:l?[{messageId:"suggestCast",fix:i(`!!(${c})`)},{messageId:"suggestBoolean",fix:i(c)}]:[{messageId:"suggest",fix:i(c)}])})}})});function T(e){return e?.type===s.AST_NODE_TYPES.ReturnStatement&&e.argument?.type===s.AST_NODE_TYPES.Literal&&"boolean"==typeof e.argument.value}function _(e){return void 0!==e&&(e.type===s.AST_NODE_TYPES.BlockStatement&&1===e.body.length&&T(e.body[0])||T(e))}function v(e,t,r){var n,o;return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>v(e,t[n],r)):!(Array.isArray(e)||Array.isArray(t))&&e.type===t.type&&(n=r.getTokens(e),o=r.getTokens(t),n.length===o.length&&n.every((e,t)=>e.value===o[t].value))}function b(e){let t=!1;return{branches:e.cases.reduce((r,n,o)=>{var i;return n.test||(t=!0),(o===e.cases.length-1||n.consequent.length>0)&&r.push((i=n.consequent).length>0&&i[i.length-1].type===s.AST_NODE_TYPES.BreakStatement?i.slice(0,-1):i),r},[]),endsWithDefault:t}}t.createRule({name:"no-all-duplicated-branches",meta:{messages:{removeOrEditConditionalStructure:"Remove this conditional structure or edit its code blocks so that they're not all the same.",returnsTheSameValue:'This conditional operation returns the same value whether the condition is "true" or "false".'},schema:[],type:"problem",docs:{description:"All branches in a conditional structure should not have exactly the same implementation",recommended:"recommended"}},create(e){return{IfStatement(r){if(r.parent?.type!==s.AST_NODE_TYPES.IfStatement){let{branches:n,endsWithElse:o}=function(e){let t=[e.consequent],r=!1,n=e.alternate;for(;n;)if(n.type===s.AST_NODE_TYPES.IfStatement)t.push(n.consequent),n=n.alternate;else{t.push(n),r=!0;break}return{branches:t,endsWithElse:r}}(r);o&&t(n)&&e.report({messageId:"removeOrEditConditionalStructure",node:r})}},SwitchStatement(r){let{branches:n,endsWithDefault:o}=b(r);o&&t(n)&&e.report({messageId:"removeOrEditConditionalStructure",node:r})},ConditionalExpression(r){t([r.consequent,r.alternate])&&e.report({messageId:"returnsTheSameValue",node:r})}};function t(t){return t.length>1&&t.slice(1).every((r,n)=>v(r,t[n],e.sourceCode))}}});var A=t.createRule({name:"no-duplicated-branches",meta:{schema:[],type:"suggestion",docs:{description:"Two branches in a conditional structure should not have exactly the same implementation",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1871/javascript"},messages:{sameConditionalBlock:"This {{type}}'s code block is the same as the block for the {{type}} on line {{line}}."}},create(e){return{IfStatement(o){!function(o){if(o.parent.type===s.AST_NODE_TYPES.IfStatement)return;let{branches:i,endsWithElse:a}=function(e){let t=[e.consequent],r=!1,n=e.alternate;for(;n;)if(n.type===s.AST_NODE_TYPES.IfStatement)t.push(n.consequent),n=n.alternate;else{t.push(n),r=!0;break}return{branches:t,endsWithElse:r}}(o);if(r(i,a))return i.slice(1).forEach((e,t)=>n(e,i[t],"branch"));for(let r=1;r<i.length;r++)if(t([i[r]]))for(let t=0;t<r&&!function(t,r){let o=D(t,r,e.sourceCode);return o&&"loc"in r&&n(t,r,"branch"),o}(i[r],i[t]);t++);}(o)},SwitchStatement(o){!function(o){let{cases:s}=o,{endsWithDefault:i}=b(o),a=s.filter(e=>P(x(e.consequent)).length>0);if(r(a.map(e=>P(x(e.consequent))),i))return a.slice(1).forEach((e,t)=>n(e,a[t],"case"));for(let r=1;r<s.length;r++){let o=P(x(s[r].consequent));if(t(o)){for(let t=0;t<r;t++)if(D(o,P(x(s[t].consequent)),e.sourceCode)){n(s[r],s[t],"case");break}}}}(o)}};function t(t){if(t.length>0){let r=[...e.sourceCode.getTokens(t[0]),...e.sourceCode.getTokens(t[t.length-1])].filter(e=>"{"!==e.value&&"}"!==e.value);return r.length>0&&r[r.length-1].loc.end.line>r[0].loc.start.line}return!1}function r(t,r){return!r&&t.length>1&&t.slice(1).every((r,n)=>D(r,t[n],e.sourceCode))}function n(t,r,n){let o=r.loc;e.report({messageId:"sameConditionalBlock",data:{type:n,line:String(o.start.line)},node:t})}}});function x(e){if(1===e.length){let t=e[0];if(t.type===s.AST_NODE_TYPES.BlockStatement)return t.body}return e}function D(e,t,r){var n,o;return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>D(e,t[n],r)):!(Array.isArray(e)||Array.isArray(t))&&e.type===t.type&&(n=r.getTokens(e),o=r.getTokens(t),n.length===o.length&&n.every((e,t)=>e.value===o[t].value))}function P(e){return e.length>0&&e[e.length-1].type===s.AST_NODE_TYPES.BreakStatement?e.slice(0,-1):e}var O=t.createRule({name:"comma-or-logical-or-case",meta:{type:"problem",docs:{description:"Comma and logical OR operators should not be used in switch cases",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3616/javascript"},schema:[],messages:{specifyCase:'Explicitly specify {{nesting}} separate cases that fall through; currently this case clause only works for "{{expression}}".'}},create(e){function t(t,r,n){var o;e.report({messageId:"specifyCase",data:{nesting:n.toString(),expression:String((o=r).type===s.AST_NODE_TYPES.Literal?o.value:e.sourceCode.getText(o))},node:t})}return{"SwitchCase > SequenceExpression":function(e){let r=e.expressions;t(e,r[r.length-1],r.length)},"SwitchCase > LogicalExpression":function(r){var n;if((n=function(t){let r=e.sourceCode.getAncestors(t);for(let e=r.length-1;e>=0;e--)if(r[e].type===s.AST_NODE_TYPES.SwitchStatement)return r[e];throw Error("A switch case should have an enclosing switch statement")}(r)).discriminant.type!==s.AST_NODE_TYPES.Literal||!0!==n.discriminant.value){let e=function e(t,r){if("||"===t.operator)return t.left.type===s.AST_NODE_TYPES.LogicalExpression?e(t.left,r+1):[t.left,r+1]}(r,0);e&&t(r,e[0],e[1]+1)}}}}}),w=t.createRule({name:"no-element-overwrite",meta:{schema:[],type:"problem",docs:{description:"Collection elements should not be replaced unconditionally",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4143/javascript"},messages:{verifyIntendedIndex:'Verify this is the index that was intended; "{{index}}" was already set on line {{line}}.'}},create(e){return{SwitchCase(e){t(e.consequent)},BlockStatement(e){t(e.body)},Program(e){t(e.body.filter(e=>{var t;return!((t=e)&&(t.type===s.AST_NODE_TYPES.ImportDeclaration||t.type===s.AST_NODE_TYPES.ExportNamedDeclaration||t.type===s.AST_NODE_TYPES.ExportDefaultDeclaration||t.type===s.AST_NODE_TYPES.ExportAllDeclaration))}))}};function t(t){let r,n=new Map;t.forEach(t=>{let o=function(t){if(t.type===s.AST_NODE_TYPES.ExpressionStatement)return function(t){var r,n,o;if((r=t).type===s.AST_NODE_TYPES.AssignmentExpression&&"="===r.operator&&t.left.type===s.AST_NODE_TYPES.MemberExpression&&t.left.computed){let r,s,{left:i,right:a}=t,l=k(i.property);if(void 0!==l&&(n=i.object,o=a,r=e.sourceCode.getTokens(n),void 0===(s=e.sourceCode.getTokens(o)).find((e,t)=>{if(N(e,r[0]))for(let e=t,n=0;e<s.length&&n<r.length;e++,n++)if(N(s[e],r[n])){if(n===r.length-1)return!0}else break;return!1})))return{collectionNode:i.object,indexOrKey:l,node:t}}}(t.expression)||function(e){if(e.type===s.AST_NODE_TYPES.CallExpression&&e.callee.type===s.AST_NODE_TYPES.MemberExpression){let t=e.callee;if(t.property.type===s.AST_NODE_TYPES.Identifier){let r=t.property.name,n="add"===r&&1===e.arguments.length,o="set"===r&&2===e.arguments.length;if(n||o){let r=k(e.arguments[0]);if(r)return{collectionNode:t.object,indexOrKey:r,node:e}}}}}(t.expression)}(t);if(o){r&&!v(o.collectionNode,r,e.sourceCode)&&n.clear();let t=n.get(o.indexOrKey);t?.node.loc&&e.report({node:o.node,messageId:"verifyIntendedIndex",data:{index:o.indexOrKey,line:t.node.loc.start.line}}),n.set(o.indexOrKey,o),r=o.collectionNode}else n.clear()})}}});function N(e,t){return e.value===t.value}function k(e){if(e.type===s.AST_NODE_TYPES.Literal){let{value:t}=e;return"number"==typeof t||"string"==typeof t?String(t):void 0}if(e.type===s.AST_NODE_TYPES.Identifier)return e.name}var Y=t.createRule({name:"class-prototype",meta:{schema:[],type:"suggestion",docs:{description:'Class methods should be used instead of "prototype" assignments',recommended:"recommended"},messages:{declareClass:'Declare a "{{class}}" class and move this declaration of "{{declaration}}" into it.'}},create(e){let r=e.sourceCode.parserServices,n=t.isParserWithTypeInformation(r)?C:R;return{AssignmentExpression({left:t,right:o}){if(t.type===s.AST_NODE_TYPES.MemberExpression&&n(o,r)){let[r,n]=[t.object,t.property];if(r.type===s.AST_NODE_TYPES.MemberExpression&&n.type===s.AST_NODE_TYPES.Identifier){let[o,i]=[r.object,r.property];o.type===s.AST_NODE_TYPES.Identifier&&i.type===s.AST_NODE_TYPES.Identifier&&"prototype"===i.name&&e.report({messageId:"declareClass",data:{class:o.name,declaration:n.name},node:t})}}}}}});function C(e,r){t.ensureParserWithTypeInformation(r);let n=r.program.getTypeChecker().getTypeAtLocation(r.esTreeNodeToTSNodeMap.get(e));return!!n.symbol&&(n.symbol.flags&i.SymbolFlags.Function)!=0}let I=new Set(["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression"]);function R(e){return I.has(e.type)}var j=t.createRule({name:"bool-param-default",meta:{schema:[],type:"suggestion",docs:{description:"Optional boolean parameters should have default value"},messages:{provideDefault:"Provide a default value for '{{parameter}}' so that the logic of the function is more evident when this parameter is missing. Consider defining another function if providing default value is not possible."}},create:e=>({"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression":t=>{for(let r of t.params)r.type===s.AST_NODE_TYPES.Identifier&&function(e){var t;return(t=e).optional&&!!t.typeAnnotation&&t.typeAnnotation.typeAnnotation.type===s.AST_NODE_TYPES.TSBooleanKeyword||function(e){if(e.typeAnnotation&&e.typeAnnotation.typeAnnotation.type===s.AST_NODE_TYPES.TSUnionType){let t=e.typeAnnotation.typeAnnotation.types;return 2===t.length&&t.some(e=>e.type===s.AST_NODE_TYPES.TSBooleanKeyword)&&t.some(e=>e.type===s.AST_NODE_TYPES.TSUndefinedKeyword)}return!1}(e)}(r)&&e.report({messageId:"provideDefault",data:{parameter:r.name},node:r})}})}),L=t.createRule({name:"call-argument-line",meta:{type:"suggestion",docs:{description:"Function call arguments should not start on new lines",recommended:"recommended"},schema:[],messages:{moveArguments:"Make those call arguments start on line {{line}}.",moveTemplateLiteral:"Make this template literal start on line {{line}}."}},create(e){let t=e.sourceCode;return{CallExpression(r){if(r.callee.type!==s.AST_NODE_TYPES.CallExpression&&1===r.arguments.length){var n;let o=(n=r).typeArguments??n.callee,s=(t.getLastTokenBetween(o,r.arguments[0],M)??t.getLastToken(o)).loc.end.line,{start:i}=t.getTokenAfter(o,q).loc;if(s!==i.line){let{end:n}=t.getLastToken(r).loc;n.line===i.line?e.report({messageId:"moveArguments",data:{line:s.toString()},loc:{start:i,end:n}}):e.report({messageId:"moveArguments",data:{line:s.toString()},loc:i})}}},TaggedTemplateExpression(r){let{quasi:n}=r,o=t.getTokenBefore(n);if(o&&n.loc&&o.loc.end.line!==n.loc.start.line){let t={start:n.loc.start,end:{line:n.loc.start.line,column:n.loc.start.column+1}};e.report({messageId:"moveTemplateLiteral",data:{line:o.loc.start.line.toString()},loc:t})}}}}});function M(e){return e.type===s.AST_TOKEN_TYPES.Punctuator&&")"===e.value}function q(e){return!M(e)}var F=t.createRule({name:"track-todo-fixme-comment",meta:{type:"suggestion",docs:{description:'Track uses of "FIXME" and "TODO" tags',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1134/javascript"},schema:[],messages:{fixme:"Take the required action to fix the issue indicated by this comment.",todo:'Complete the task associated to this "TODO" comment.'}},create(e){function t(t,r){e.sourceCode.getAllComments().forEach(n=>{let o=n.value.toLowerCase();if(o.includes(t)){let s=o.split(/\r\n?|\n/);for(let o=0;o<s.length;o++){let i=s[o].indexOf(t);i>=0&&!function(e,t,r){let n=t+r.length,o=t>0&&B.test(e.charAt(t-1)),s=n<=e.length-1&&B.test(e.charAt(n));return o||s}(s[o],i,t)&&e.report({messageId:r,loc:function(e,t,r,n){let o=r.loc.start.line+e,s=(0===e?r.loc.start.column+2:0)+t;return{start:{line:o,column:s},end:{line:o,column:s+n.length}}}(o,i,n,t)})}}})}return{"Program:exit":()=>{t("fixme","fixme"),t("todo","todo")}}}});let B=/\p{Letter}/u,U=["Array","Map","Set","WeakSet","WeakMap"],W=new Set(["copyWithin","pop","reverse","shift","sort","clear","delete","concat","flat","flatMap","includes","indexOf","join","lastIndexOf","slice","toSource","toString","toLocaleString","get","has","entries","every","filter","find","findIndex","forEach","keys","map","reduce","reduceRight","some","values"]);var V=t.createRule({name:"no-empty-collection",meta:{schema:[],type:"problem",docs:{description:"Empty collections should not be accessed or iterated",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4158/javascript"},messages:{reviewUsageOfIdentifier:'Review this usage of "{{identifierName}}" as it can only be empty here.'}},create(e){let t=t=>{if(t.references.length<=1||t.defs.some(e=>e.type===a.TSESLint.Scope.DefinitionType.Parameter||e.type===a.TSESLint.Scope.DefinitionType.ImportBinding))return;let r=[],n=!1;for(let e of t.references)if(e.isWriteOnly())if(!function(e){let t=K(e.identifier,e=>e.type===s.AST_NODE_TYPES.VariableDeclarator||e.type===s.AST_NODE_TYPES.ExpressionStatement);if(t){if(t.type===s.AST_NODE_TYPES.VariableDeclarator&&t.init)return G(t.init);if(t.type===s.AST_NODE_TYPES.ExpressionStatement){let{expression:r}=t;return r.type===s.AST_NODE_TYPES.AssignmentExpression&&z(e,r.left)&&G(r.right)}}return!1}(e))return;else n=!0;else{var o;if(!(function(e){let{parent:t}=e.identifier;if(t&&t.type===s.AST_NODE_TYPES.MemberExpression){let e=t.parent;if(e&&e.type===s.AST_NODE_TYPES.CallExpression)return X(t.property,...W)}return!1}(o=e)||function(e){let t=K(e.identifier,e=>e.type===s.AST_NODE_TYPES.ForOfStatement||e.type===s.AST_NODE_TYPES.ForInStatement);return t?.right===e.identifier}(o)||function(e){let{parent:t}=e.identifier;return t&&t.type===s.AST_NODE_TYPES.MemberExpression&&t.computed&&!function(e){let t=$(e,new Set),r=t.find(e=>e.type===s.AST_NODE_TYPES.AssignmentExpression);return r?.operator==="="&&[e,...t].includes(r.left)}(t)}(o)))return;r.push(e)}n&&r.forEach(t=>{e.report({messageId:"reviewUsageOfIdentifier",data:{identifierName:t.identifier.name},node:t.identifier})})},r=e=>{e.type!==a.TSESLint.Scope.ScopeType.global&&e.variables.forEach(t),e.childScopes.forEach(r)};return{"Program:exit":t=>{r(e.sourceCode.getScope(t))}}}});function K(e,t){return $(e,new Set).find(t)}function $(e,t){let r=[],n=e.parent;for(;n&&(r.push(n),!t.has(n.type));)n=n.parent;return r}function z(e,t){return t.type===s.AST_NODE_TYPES.Identifier&&t===e.identifier}function G(e){return e&&e.type===s.AST_NODE_TYPES.ArrayExpression?0===e.elements.length:!!e&&(e.type===s.AST_NODE_TYPES.CallExpression||e.type===s.AST_NODE_TYPES.NewExpression)&&X(e.callee,...U)&&0===e.arguments.length}function X(e,...t){return e?.type===s.AST_NODE_TYPES.Identifier&&(0===t.length||t.some(t=>t===e.name))}let H=new Set(["!=","==","!==","==="]),J=new Set(["!==","!="]),Q=new Set(["+=","-="]);var Z=t.createRule({name:"no-equals-in-for-termination",meta:{schema:[],messages:{replaceOperator:"Replace '{{operator}}' operator with one of '<=', '>=', '<', or '>' comparison operators."},type:"suggestion",docs:{description:'Equality operators should not be used in "for" loop termination conditions',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S888/javascript"}},create(e){function t(t,r){if(t.type===s.AST_NODE_TYPES.Identifier){var n;let o=(n=t.name,function(e,t){let r;for(;null==r&&null!=e;)r=e.variables.find(e=>e.name===t),e=e.upper;return r}(e.sourceCode.getScope(t),n)),s=r.range;if(o&&s)return o.references.some(e=>{var t,r;return t=e.identifier,r=s,t.range&&t.range[0]>r[0]&&t.range[1]<r[1]})}return!1}return{ForStatement(r){var n,o;let i,a;if(!r.test||!r.update)return;let l=r.test;(n=l).type===s.AST_NODE_TYPES.BinaryExpression&&H.has(n.operator)&&function e(t){return!!ee(t)||t.type===s.AST_NODE_TYPES.UpdateExpression||t.type===s.AST_NODE_TYPES.SequenceExpression&&t.expressions.every(e)}(r.update)&&(i=(o=r).test,a=[],function e(t,r){let n;ee(t)?n=t.left:t.type===s.AST_NODE_TYPES.UpdateExpression?n=t.argument:t.type===s.AST_NODE_TYPES.SequenceExpression&&t.expressions.forEach(t=>e(t,r)),n&&n.type===s.AST_NODE_TYPES.Identifier&&r.push(n.name)}(o.update,a),!(i.left.type!==s.AST_NODE_TYPES.Identifier||!a.includes(i.left.name)||function(e){let r=e.init,n=e.test;if(r&&et(n)){let o=function(e,r){var n,o;if(n=e,o=r,n.type===s.AST_NODE_TYPES.UpdateExpression&&!t(n.argument,o)||function(e){if(ee(e)){let t=e.right;return t.type===s.AST_NODE_TYPES.Literal&&1===t.value}return!1}(n)&&!t(n.left,o)){if("++"===e.operator||"+="===e.operator)return 1;if("--"===e.operator||"-="===e.operator)return -1}return 0}(e.update,e.body);if(0!==o){let e=er(r),t=er(n);return void 0!==e&&void 0!==t&&o===Math.sign(t-e)}}return!1}(r)))&&e.report({messageId:"replaceOperator",data:{operator:l.operator},node:l})}}}});function ee(e){return e.type===s.AST_NODE_TYPES.AssignmentExpression&&Q.has(e.operator)}function et(e){return e.type===s.AST_NODE_TYPES.BinaryExpression&&J.has(e.operator)}function er(e){var t;return et(e)?en(e.right):(t=e).type===s.AST_NODE_TYPES.VariableDeclaration&&1===t.declarations.length?en(e.declarations[0].init):e.type===s.AST_NODE_TYPES.AssignmentExpression?en(e.right):void 0}function en(e){if(e&&e.type===s.AST_NODE_TYPES.Literal&&"number"==typeof e.value)return e.value}var eo=t.createRule({name:"no-top-level-this",meta:{hasSuggestions:!0,schema:[],messages:{removeThis:'Remove the use of "this".',suggestRemoveThis:'Remove "this"',suggestUseGlobalThis:'Replace "this" with "globalThis" object'},type:"suggestion",docs:{description:'The global "this" object should not be used',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S2990/javascript"},fixable:"code"},create:e=>({'MemberExpression[object.type="ThisExpression"]':t=>{let r=e.sourceCode.getScope(t).variableScope.type,n=e.sourceCode.getAncestors(t).some(e=>e.type===s.AST_NODE_TYPES.ClassDeclaration||e.type===s.AST_NODE_TYPES.ClassExpression);if((r===a.TSESLint.Scope.ScopeType.global||r===a.TSESLint.Scope.ScopeType.module)&&!n){let r=[];if(!t.computed){let n=e.sourceCode.getText(t.property);r.push({messageId:"suggestRemoveThis",fix:e=>e.replaceText(t,n)},{messageId:"suggestUseGlobalThis",fix:e=>e.replaceText(t.object,"globalThis")})}e.report({messageId:"removeThis",node:t.object,suggest:r})}}})}),es=t.createRule({name:"no-invariant-returns",meta:{schema:[],type:"suggestion",docs:{description:"Function returns should not be invariant",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3516/javascript",requiresTypeChecking:!1},messages:{refactorReturn:"Refactor this function to only return once or not always return the same value."}},create(e){let t=[],r=[],n=[],o=r=>{var o,i,a;return o=r,void(!(i=t[t.length-1])||(a=i,n.some(e=>e.reachable)||a.containsReturnWithoutValue||a.returnStatements.length<=1||a.codePath.thrownSegments.length>0)||function(e,t){let r=e[0],n=r?el(r,t):void 0;if(void 0!==n)return e.slice(1).every(e=>el(e,t)===n);if(r?.type===s.AST_NODE_TYPES.Identifier){let n=ei(r.name,t);if(n){let t=new Set(n.variable.references.slice(1).map(e=>e.identifier));return e.every(e=>t.has(e))}}return!1}(i.returnStatements.map(e=>e.argument),e.sourceCode.getScope(o))&&e.report({messageId:"refactorReturn",node:o}))};return{onCodePathStart(e){t.push({codePath:e,containsReturnWithoutValue:!1,returnStatements:[]}),r.push(n),n=[]},onCodePathEnd(){t.pop(),n=r.pop()||[]},onCodePathSegmentStart(e){n.push(e)},onCodePathSegmentEnd(){n.pop()},ReturnStatement(e){if(t.length){let r=t[t.length-1];r.containsReturnWithoutValue=r.containsReturnWithoutValue||!e.argument,r.returnStatements.push(e)}},"FunctionDeclaration:exit":o,"FunctionExpression:exit":o,"ArrowFunctionExpression:exit":o}}});function ei(e,t){let r=t.set.get(e);if(r&&!r.references.slice(1).some(e=>{var t;let r;return e.isWrite()||(r=K((t=e).identifier,e=>e.type===s.AST_NODE_TYPES.ExpressionStatement||R(e)))&&r.type===s.AST_NODE_TYPES.ExpressionStatement&&(ea(r,t)||r.expression.type===s.AST_NODE_TYPES.CallExpression)})){let e=null;return 1===r.defs.length&&r.defs[0].type===a.TSESLint.Scope.DefinitionType.Variable&&(e=r.defs[0].node.init),{variable:r,initExpression:e}}return null}function ea(e,t,r=!0){return e.expression.type===s.AST_NODE_TYPES.AssignmentExpression&&function e(t,r,n=!0){return t.type===s.AST_NODE_TYPES.MemberExpression&&(z(r,t.object)||n&&e(t.object,r,n))}(e.expression.left,t,r)}function el(e,t){if(e){if(e.type===s.AST_NODE_TYPES.Literal)return e.value;if(e.type===s.AST_NODE_TYPES.UnaryExpression){let r=el(e.argument,t);return void 0===r?void 0:function(e,t){switch(e){case"-":return-Number(t);case"+":return Number(t);case"~":return~Number(t);case"!":return!t;case"typeof":return typeof t}}(e.operator,r)}if(e.type===s.AST_NODE_TYPES.Identifier){let r=ei(e.name,t);if(r?.initExpression)return el(r.initExpression,t)}}}function ec(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function eu(e,t){let r=t.variables.find(t=>t.name===e.name);return!r&&t.upper&&(r=t.upper.variables.find(t=>t.name===e.name)),r}class ep extends Set{constructor(...e){super(...e),ec(this,"type","AssignedValues")}}let ed={type:"UnknownValue"};class em{add(e){e.resolved&&this.references.add(e)}propagate(e){this.in.clear(),this.segment.prevSegments.forEach(t=>{this.join(e.get(t.id).out)});let t=new Map;return this.references.forEach(e=>this.updateProgramState(e,t)),!function(e,t){if(e.size!==t.size)return!1;for(let[o,s]of e){var r,n;if(!t.has(o)||(r=t.get(o),n=s,"AssignedValues"===r.type&&"AssignedValues"===n.type?!function(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}(r,n):r!==n))return!1}return!0}(this.out,t)&&(this.out=t,!0)}updateProgramState(e,t){let r=e.resolved;if(!r||!e.isWrite())return;if(!e.writeExpr)return void t.set(r,ed);let n=ef(r,e.writeExpr,t,e.from);t.set(r,n)}join(e){for(let[t,r]of e.entries()){let e=this.in.get(t)??new ep;"AssignedValues"===e.type&&"AssignedValues"===r.type?(r.forEach(t=>e.add(t)),this.in.set(t,e)):this.in.set(t,ed)}}constructor(e){ec(this,"segment",void 0),ec(this,"in",void 0),ec(this,"out",void 0),ec(this,"references",void 0),this.segment=e,this.in=new Map,this.out=new Map,this.references=new Set}}function ef(e,t,r,n){if(!t)return ed;switch(t.type){case s.AST_NODE_TYPES.Literal:return t.raw?new ep([t.raw]):ed;case s.AST_NODE_TYPES.Identifier:{let o=eu(t,n);if(o&&o!==e)return r.get(o)??ed;return ed}default:return ed}}class eg{constructor(e){ec(this,"codePath",void 0),ec(this,"reachingDefinitionsMap",void 0),ec(this,"reachingDefinitionsStack",void 0),ec(this,"segments",void 0),ec(this,"assignmentStack",void 0),this.codePath=e,this.reachingDefinitionsMap=new Map,this.reachingDefinitionsStack=[],this.segments=new Map,this.assignmentStack=[]}}class eh{isRhs(e){return this.node.type===s.AST_NODE_TYPES.AssignmentExpression?this.node.right===e:this.node.init===e}isLhs(e){return this.node.type===s.AST_NODE_TYPES.AssignmentExpression?this.node.left===e:this.node.id===e}add(e){let t=e.identifier;for(;t;){if(this.isLhs(t)){this.lhs.add(e);break}if(this.isRhs(t)){this.rhs.add(e);break}t=t.parent}}constructor(e){ec(this,"node",void 0),ec(this,"lhs",void 0),ec(this,"rhs",void 0),this.node=e,this.lhs=new Set,this.rhs=new Set}}function eS(e){return e[e.length-1]}var ey=t.createRule({name:"no-redundant-assignments",meta:{schema:[],type:"suggestion",docs:{description:"Assignments should not be redundant",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4165/javascript"},messages:{reviewAssignment:'Review this redundant assignment: "{{symbol}}" already holds the assigned value along all execution paths.'}},create(e){let t=[],r=new Map,n=new Map,o=[],i=[];return{AssignmentExpression:c,"VariableDeclarator[init]":c,"AssignmentExpression:exit":l,"VariableDeclarator[init]:exit":l,Identifier(r){var o;r.parent.type===s.AST_NODE_TYPES.TSEnumBody||r.parent.type===s.AST_NODE_TYPES.TSEnumDeclaration||r.parent.type===s.AST_NODE_TYPES.TSEnumMember||(o=r,e.sourceCode.getAncestors(o).some(e=>e.type===s.AST_NODE_TYPES.TSEnumDeclaration)||function(r){var o;let{ref:s,variable:i}=function e(t,r){if(null===r)return{ref:null,variable:null};let n=r.references.find(e=>e.identifier===t);if(n)return{ref:n,variable:n.resolved};let o=r.variables.find(e=>e.defs.find(e=>e.name===t));return o?{ref:null,variable:o}:e(t,r.upper)}(o=r,e.sourceCode.getScope(o));if(s&&p(s),i){let e=eS(t).codePath.id;n.has(i)?n.get(i).add(e):n.set(i,new Set([e]))}}(r))},"Program:exit":()=>{let e=Array.from(r.values(),e=>e.segment);for(;e.length;){let t=e.pop();r.get(t.id).propagate(r)&&t.nextSegments.forEach(t=>e.push(t))}r.forEach(u),r.clear(),n.clear(),t.length=0},onCodePathSegmentStart(e){r.set(e.id,new em(e)),i.push(e)},onCodePathStart(e){var r;r=new eg(e),t.push(r),o.push(i),i.length=0},onCodePathEnd(){t.pop(),o.pop()||(i.length=0)},onCodePathSegmentEnd(){i.pop()}};function l(){let e=eS(t).assignmentStack.pop();e.rhs.forEach(p),e.lhs.forEach(p)}function c(e){eS(t).assignmentStack.push(new eh(e))}function u(t){let r=new Map(t.in);t.references.forEach(t=>{let o=t.resolved;if(!o||!t.isWrite()||!function(e){var t;let r=e.resolved;return r&&(e.identifier.type!==s.AST_NODE_TYPES.Identifier||e.identifier.parent.type!==s.AST_NODE_TYPES.AssignmentPattern)&&!r.name.startsWith("_")&&!function(e){if(e?.parent){let t=e.parent;return t&&t.type===s.AST_NODE_TYPES.AssignmentExpression&&"="!==t.operator}return!1}(e.writeExpr)&&(e.writeExpr?.type!==s.AST_NODE_TYPES.Identifier||e.resolved!==eu(e.writeExpr,e.from))&&!r.defs.some(e=>e.type===a.TSESLint.Scope.DefinitionType.Parameter||e.type===a.TSESLint.Scope.DefinitionType.Variable&&!e.node.init)&&(t=r,!(n.get(t).size>1))}(t))return;let i=r.get(o),l=ef(o,t.writeExpr,r,t.from);if(i?.type==="AssignedValues"&&1===i.size){let[r]=[...i];!function({resolved:t},r,n,o,s){if("UnknownValue"===o.type||1!==o.size)return;let[i]=[...o];t&&1!==t.references.filter(e=>e.isWrite()).length&&n===i&&e.report({node:r,messageId:"reviewAssignment",data:{symbol:s}})}(t,t.writeExpr,r,l,o.name)}r.set(o,l)})}function p(e){let{assignmentStack:n}=eS(t);if(n.length>0)eS(n).add(e);else for(let t=0,n=i.length;t<n;t++)(function(e){let t;return r.has(e.id)?t=r.get(e.id):(t=new em(e),r.set(e.id,t)),t})(i[t]).add(e)}}}),eE=t.createRule({name:"no-same-line-conditional",meta:{schema:[],type:"layout",docs:{description:"Conditionals should start on new lines",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3972/javascript"},fixable:"whitespace",messages:{sameLineCondition:'Move this "if" to a new line or add the missing "else".'}},create(e){function t(t){var r;let{sourceCode:n}=e;(r=t).reduce((e,t,n)=>{let o=r[n-1];return t.type===s.AST_NODE_TYPES.IfStatement&&o&&o.type===s.AST_NODE_TYPES.IfStatement?[{first:o,following:t},...e]:e},[]).forEach(t=>{let r=t.first,o=t.following;if(r.loc&&o.loc&&r.loc.end.line===o.loc.start.line&&r.loc.start.line!==o.loc.end.line){let t=n.getFirstToken(o);e.report({messageId:"sameLineCondition",loc:t.loc,fix:e=>e.replaceTextRange([r.range[1],o.range[0]],"\n"+" ".repeat(r.loc.start.column))})}})}return{Program:e=>t(e.body),BlockStatement:e=>t(e.body),SwitchCase:e=>t(e.consequent)}}}),eT=t.createRule({name:"no-small-switch",meta:{schema:[],messages:{replaceSwitch:'Replace this "switch" statement by "if" statements to increase readability.'},type:"suggestion",docs:{description:'"if" statements should be preferred over "switch" when simpler',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1301/javascript"}},create:e=>({SwitchStatement(t){let{cases:r}=t,n=r.some(e=>!e.test);if(r.length<2||2===r.length&&n){let r=e.sourceCode.getFirstToken(t);r&&e.report({messageId:"replaceSwitch",loc:r.loc})}}})});let e_=["Array","Map","Set","WeakSet","WeakMap"],ev=["copyWithin","fill","pop","push","reverse","set","shift","sort","splice","unshift","add","clear","delete"];var eb=t.createRule({name:"no-unused-collection",meta:{schema:[],messages:{unusedCollection:"Either use this collection's contents or remove the collection."},type:"suggestion",docs:{description:"Collection contents should be used",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4030/javascript",requiresTypeChecking:!1}},create:e=>({"Program:exit":t=>{let r=[];(function e(t,r){t.type!==a.TSESLint.Scope.ScopeType.global&&t.variables.forEach(e=>{(function(e){if(function(e){if(!e.defs.length)return;let t=e.defs[0];return t.node.parent?.parent?.type.startsWith("Export")}(e)||e.references.length<=1)return!1;let t=!1;for(let r of e.references)if(r.isWriteOnly())if(!function(e){let t=K(e.identifier,e=>e.type===s.AST_NODE_TYPES.VariableDeclarator||e.type===s.AST_NODE_TYPES.ExpressionStatement);if(t){if(t.type===s.AST_NODE_TYPES.VariableDeclarator&&t.init)return eA(t.init);if(t.type===s.AST_NODE_TYPES.ExpressionStatement){let{expression:r}=t;return r.type===s.AST_NODE_TYPES.AssignmentExpression&&z(e,r.left)&&eA(r.right)}}return!1}(r))return!1;else t=!0;else if(function(e){let t=K(e.identifier,e=>e.type===s.AST_NODE_TYPES.ExpressionStatement);return!t||!ea(t,e,!1)&&!function(e,t){if(e.expression.type===s.AST_NODE_TYPES.CallExpression){let{callee:r}=e.expression;if(r.type===s.AST_NODE_TYPES.MemberExpression){let{property:e,object:n}=r;return z(t,n)&&X(e,...ev)}}return!1}(t,e)}(r))return!1;return t})(e)&&r.push(e)}),t.childScopes.forEach(t=>{e(t,r)})})(e.sourceCode.getScope(t),r),r.forEach(t=>{e.report({messageId:"unusedCollection",node:t.identifiers[0]})})}})});function eA(e){return!!e&&e.type===s.AST_NODE_TYPES.ArrayExpression||!!e&&(e.type===s.AST_NODE_TYPES.CallExpression||e.type===s.AST_NODE_TYPES.NewExpression)&&X(e.callee,...e_)}var ex=t.createRule({name:"no-useless-plusplus",meta:{schema:[],type:"problem",docs:{description:"Values should not be uselessly incremented",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S2123/javascript"},messages:{removeIncrement:"Remove this {{updateOperator}}rement or correct the code not to waste it."}},create(e){function t(t){let r="++"===t.operator?"inc":"dec";e.report({messageId:"removeIncrement",data:{updateOperator:r},node:t})}return{"ReturnStatement > UpdateExpression":function(r){var n;let o=r.argument;!r.prefix&&o.type===s.AST_NODE_TYPES.Identifier&&(n=o,e.sourceCode.getScope(r).variables.some(e=>e.identifiers.some(e=>e.name===n.name)))&&t(r)},AssignmentExpression(e){let r=e.right;if(r.type===s.AST_NODE_TYPES.UpdateExpression&&!r.prefix){let n=e.left;n.type===s.AST_NODE_TYPES.Identifier&&r.argument.type===s.AST_NODE_TYPES.Identifier&&r.argument.name===n.name&&t(r)}}}}});let eD=new Set(["map","filter","reduce","reduceRight","forEach"]);var eP=t.createRule({name:"no-chain-array-higher-order-functions",meta:{type:"problem",fixable:"code",docs:{description:"Prefer `.reduce` over chaining `.filter`, `.map` methods",recommended:"recommended"},schema:[],messages:{detected:"Detected the chaining of array methods: {{methods}}. Reaplce with `.reduce` to reduce array iterations and improve the performance."}},create:e=>({MemberExpression(t){if(eO(t)){let r=t.parent;eO(r.parent)&&e.report({node:r,messageId:"detected",data:{methods:`arr.${t.property.name}().${r.parent.property.name}()`}})}}})});function eO(e){return e.type===s.AST_NODE_TYPES.MemberExpression&&!e.computed&&e.property.type===s.AST_NODE_TYPES.Identifier&&eD.has(e.property.name)&&e.parent.type===s.AST_NODE_TYPES.CallExpression}var ew=t.createRule({name:"no-export-const-enum",meta:{type:"suggestion",docs:{description:"Disallow using `const enum` expression as it can not be inlined and tree-shaken by swc/esbuild/babel/webpack/rollup/vite/bun/rspack"},messages:{noConstEnum:"Do not use `const enum` expression"},schema:[]},create(e){let t=(t,r)=>{let n=a.ASTUtils.findVariable(e.sourceCode.getScope(t),r);n?.defs.forEach(r=>{r.node.type===s.AST_NODE_TYPES.TSEnumDeclaration&&r.node.const&&e.report({node:t,messageId:"noConstEnum"})})};return{ExportNamedDeclaration(r){let n=r.declaration;if(n?.type===s.AST_NODE_TYPES.TSEnumDeclaration&&n.const)return void e.report({node:r,messageId:"noConstEnum"});if(n?.type===s.AST_NODE_TYPES.VariableDeclaration){let e=n.declarations[0].id;e.type===s.AST_NODE_TYPES.Identifier&&t(r,e)}},ExportDefaultDeclaration(e){let r=e.declaration;r.type===s.AST_NODE_TYPES.Identifier&&t(e,r)}}}}),eN=t.createRule({name:"no-for-in-iterable",meta:{schema:[],type:"suggestion",docs:{description:'"for in" should not be used with iterables',recommended:"strict",url:"https://sonarsource.github.io/rspec/#/rspec/S4139/javascript"},messages:{useForOf:'Use "for...of" to iterate over this "{{iterable}}".'}},create(e){let r=e.sourceCode.parserServices;return{ForInStatement(n){var o,s;t.ensureParserWithTypeInformation(r);let a=ek(n.right,r);if(t.ensureParserWithTypeInformation(r),(o=a).symbol&&eY.has(o.symbol.name)||((s=a).flags&i.TypeFlags.StringLike)>0||s.symbol?.name==="String"||function(e,t){var r,n=t.program.getTypeChecker().getBaseConstraintOfType(e)??e,o=t;for(let e of(r=n).isUnion()?r.types:[r])if(!function(e,t){let r=t.program.getTypeChecker();return"isArrayType"in r&&"function"==typeof r.isArrayType&&r.isArrayType(e)}(e,o))return!1;return!0}(a,r)){let t=a.symbol?a.symbol.name:"String";e.report({messageId:"useForOf",data:{iterable:t},loc:e.sourceCode.getFirstToken(n).loc})}}}}});function ek(e,t){return t.program.getTypeChecker().getTypeAtLocation(t.esTreeNodeToTSNodeMap.get(e))}let eY=new Set(["Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Set","Map"]);var eC=t.createRule({name:"only-await-thenable",meta:{schema:[],type:"suggestion",docs:{description:'"await" should only be used with promises',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4123/javascript"},messages:{refactorAwait:"Refactor this redundant 'await' on a non-promise."}},create(e){let r=e.sourceCode.parserServices;return t.ensureParserWithTypeInformation(r),{AwaitExpression(t){let n,o=ek(t.argument,r);(function(e,t){var r,n;if(e.argument.type!==s.AST_NODE_TYPES.CallExpression)return!1;let o=(r=e.argument,(n=t).program.getTypeChecker().getResolvedSignature(n.esTreeNodeToTSNodeMap.get(r)));return o?.declaration&&function(e){if(!e.jsDoc)return!1;for(let t of e.jsDoc)if(t.tags?.some(e=>eI.has(e.tagName.escapedText.toString())))return!0;return!1}(o.declaration)})(t,r)||(n=o.getProperty("then"),n?.declarations?.some(e=>e.kind===i.SyntaxKind.MethodSignature||e.kind===i.SyntaxKind.MethodDeclaration||e.kind===i.SyntaxKind.PropertyDeclaration))||o.flags&i.TypeFlags.Any||o.flags&i.TypeFlags.Unknown||o.flags&i.TypeFlags.Union||e.report({messageId:"refactorAwait",node:t})}}}});let eI=new Set(["return","returns"]);var eR=t.createRule({name:"no-undefined-optional-parameters",meta:{schema:[],type:"suggestion",docs:{description:'"undefined" should not be passed as the value of optional parameters',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4623/javascript",requiresTypeChecking:!0},fixable:"code",hasSuggestions:!0,messages:{removeUndefined:'Remove this redundant "undefined".',suggestRemoveUndefined:"Remove this redundant argument"}},create(e){let r=e.sourceCode.parserServices;return t.ensureParserWithTypeInformation(r),{CallExpression(t){var n;let{arguments:o}=t;if(0===o.length)return;let i=o[o.length-1];(n=i).type===s.AST_NODE_TYPES.Identifier&&"undefined"===n.name&&function(e,t,r){let n=r.program.getTypeChecker().getResolvedSignature(r.esTreeNodeToTSNodeMap.get(t));if(n){var o;let t=n.declaration;if(t&&(o=t,ej.has(o.kind))){let{parameters:r}=t,n=r[e];return n&&(n.initializer||n.questionToken)}}return!1}(o.length-1,t,r)&&e.report({messageId:"removeUndefined",node:i,suggest:[{messageId:"suggestRemoveUndefined",fix(r){if(1===t.arguments.length){let n=e.sourceCode.getTokenAfter(t.callee),o=e.sourceCode.getLastToken(t),[,s]=n.range,[i]=o.range;return r.removeRange([s,i])}let[,n]=o[o.length-2].range,[,s]=i.range;return r.removeRange([n,s])}}]})}}}});let ej=new Set([i.SyntaxKind.FunctionDeclaration,i.SyntaxKind.FunctionExpression,i.SyntaxKind.ArrowFunction,i.SyntaxKind.MethodDeclaration,i.SyntaxKind.Constructor,i.SyntaxKind.GetAccessor,i.SyntaxKind.SetAccessor]);function eL(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class eM{visit(e,t){let r=e=>{switch(e.type){case s.AST_NODE_TYPES.AwaitExpression:case s.AST_NODE_TYPES.CallExpression:case s.AST_NODE_TYPES.NewExpression:this.callLikeExpressions.push(e);break;case s.AST_NODE_TYPES.FunctionDeclaration:case s.AST_NODE_TYPES.FunctionExpression:case s.AST_NODE_TYPES.ArrowFunctionExpression:return}(function(e,t){let r=[],n=t[e.type];if(n?.length)for(let t of n){let n=e[t];Array.isArray(n)?r.push(...n):r.push(n)}return r.filter(Boolean)})(e,t.sourceCode.visitorKeys).forEach(r)};r(e)}constructor(){eL(this,"callLikeExpressions",[])}}eL(eM,"getCallExpressions",(e,t)=>{let r=new eM;return r.visit(e,t),r.callLikeExpressions});var eq=t.createRule({name:"no-try-promise",meta:{schema:[],type:"problem",docs:{description:'Promise rejections should not be caught by "try" blocks',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4822/javascript",requiresTypeChecking:!0},messages:{addAwait:"Consider using 'await' for the promise{{ending}} inside this 'try' or replace it with 'Promise.prototype.catch(...)' usage{{ending}}.",removeTry:"Consider removing this 'try' statement as promise{{ending}} rejection is already captured by '.catch()' method."}},create(e){let r=e.sourceCode.parserServices;return t.ensureParserWithTypeInformation(r),{TryStatement(t){if(t.handler){let n=[],o=[],a=!1;if(eM.getCallExpressions(t.block,e).forEach(e=>{var t,l,c,u,p,d;let m,f;if(e.type===s.AST_NODE_TYPES.AwaitExpression||(t=e,m=(l=r).esTreeNodeToTSNodeMap.get(t),!(f=l.program.getTypeChecker().getTypeAtLocation(m).getProperty("then"))||!(f.flags&i.SymbolFlags.Method))){a=!0;return}(c=e).parent&&(c.parent.type===s.AST_NODE_TYPES.AwaitExpression||c.parent.type===s.AST_NODE_TYPES.YieldExpression)||(u=e).parent&&u.parent.type===s.AST_NODE_TYPES.MemberExpression&&u.parent.property.type===s.AST_NODE_TYPES.Identifier&&"then"===u.parent.property.name||(p=e).type===s.AST_NODE_TYPES.CallExpression&&p.callee.type===s.AST_NODE_TYPES.MemberExpression&&p.callee.property.type===s.AST_NODE_TYPES.Identifier&&"catch"===p.callee.property.name||((d=e).parent&&d.parent.type===s.AST_NODE_TYPES.MemberExpression&&d.parent.property.type===s.AST_NODE_TYPES.Identifier&&"catch"===d.parent.property.name?o:n).push(e)}),!a){if(n.length>0){let r=n.length>1?"s":"",o=e.sourceCode.getFirstToken(t);e.report({messageId:"addAwait",data:{ending:r},loc:o.loc})}if(0===n.length&&o.length>0){let r=o.length>1?"s":"",n=e.sourceCode.getFirstToken(t);e.report({messageId:"removeTry",data:{ending:r},loc:n.loc})}}}}}}}),eF=t.createRule({name:"no-unthrown-error",meta:{schema:[],type:"problem",docs:{description:"Errors should not be created without being thrown",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3984/javascript",requiresTypeChecking:!1},fixable:"code",hasSuggestions:!0,messages:{throwOrRemoveError:"Throw this error or remove this useless statement.",suggestThrowError:"Throw this error"}},create:e=>({"ExpressionStatement > NewExpression":function(t){var r;let n;if(r=t.callee,(n=e.sourceCode.getText(r)).endsWith("Error")||n.endsWith("Exception")){let r,n=(r=e.sourceCode.getAncestors(t)).length>0?r[r.length-1]:void 0;e.report({messageId:"throwOrRemoveError",node:t,suggest:n?[{messageId:"suggestThrowError",fix:e=>e.insertTextBefore(n,"throw ")}]:[]})}}})}),eB=t.createRule({name:"no-useless-string-operation",meta:{schema:[],messages:{uselessStringOp:"{{symbol}} is an immutable object; you must either store or return the result of the operation."},type:"problem",docs:{description:"Results of operations on strings should not be ignored",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1154/javascript"}},create(e){let r=e.sourceCode.parserServices;return{'ExpressionStatement > CallExpression[callee.type="MemberExpression"]':n=>{let o,{object:i,property:a}=n.callee;t.ensureParserWithTypeInformation(r),(ek(i,r).flags&l.TypeFlags.StringLike)!=0&&a.type===s.AST_NODE_TYPES.Identifier&&e.report({messageId:"uselessStringOp",data:{symbol:((o=e.sourceCode.getText(i)).length>30&&(o="String"),o)},node:a})}}}});let eU={configs:{recommended:{name:"eslint-plugin-sukka/recommended",plugins:{get sukka(){return eU}},rules:{"sukka/ban-eslint-disable":["error","allow-with-description"],"sukka/bool-param-default":"error","sukka/call-argument-line":"error","sukka/class-prototype":"warn","sukka/comma-or-logical-or-case":"error","sukka/no-all-duplicated-branches":"error","sukka/no-chain-array-higher-order-functions":"error","sukka/no-duplicated-branches":"error","sukka/no-element-overwrite":"warn","sukka/no-empty-collection":"warn","sukka/no-equals-in-for-termination":"error","sukka/no-export-const-enum":"error","sukka/no-expression-empty-lines":"error","sukka/no-invariant-returns":"error","sukka/no-redundant-assignments":"warn","no-return-await":"off","sukka/no-return-await":"error","sukka/no-same-line-conditional":"error","sukka/no-small-switch":"error","sukka/no-top-level-this":"error","sukka/no-unthrown-error":"warn","sukka/no-unused-collection":"error","sukka/no-useless-plusplus":"error","sukka/object-format":"off","sukka/prefer-single-boolean-return":"error","sukka/track-todo-fixme-comment":"warn"}},recommended_extra_with_typed_lint:{name:"eslint-plugin-sukka/recommended_extra_with_typed_lint",plugins:{get sukka(){return eU}},rules:{"sukka/no-for-in-iterable":"error","sukka/no-try-promise":"error","sukka/no-undefined-optional-parameters":"warn","sukka/no-useless-string-operation":"warn","sukka/only-await-thenable":"off"}}},rules:{"ban-eslint-disable":d,"no-return-await":f,"no-expression-empty-lines":g,"object-format":S,"prefer-single-boolean-return":E,"no-all-duplicated-branches":A,"no-duplicated-branches":A,"bool-param-default":j,"call-argument-line":L,"class-prototype":Y,"comma-or-logical-or-case":O,"track-todo-fixme-comment":F,"no-element-overwrite":w,"no-empty-collection":V,"no-equals-in-for-termination":Z,"no-top-level-this":eo,"no-invariant-returns":es,"no-redundant-assignments":ey,"no-same-line-conditional":eE,"no-small-switch":eT,"no-unused-collection":eb,"no-useless-plusplus":ex,"no-chain-array-higher-order-functions":eP,"no-export-const-enum":ew,"no-for-in-iterable":eN,"only-await-thenable":eC,"no-undefined-optional-parameters":eR,"no-try-promise":eq,"no-unthrown-error":eF,"no-useless-string-operation":eB}};module.exports=eU;
1
+ "use strict";var e,t=require("@eslint-sukka/shared"),r=require("eslint"),n=require("foxts/guard"),o=require("foxts/detect-eol"),s=require("@typescript-eslint/types"),i=require("typescript"),a=require("@typescript-eslint/utils"),l=(e=Object.create(null),i&&Object.keys(i).forEach(function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:function(){return i[t]}})}}),e.default=i,Object.freeze(e));let c=/^\s*(?<directive>eslint-disable(?:-(?:next-)?line)?)/,u=/^eslint-disable(?:-next-line|-line)?(?<ruleId>$|(?:\s+(?:@(?:[\w-]+\/){1,2})?[\w-]+)?)/,p=Symbol("rule-id-no-match");var d=t.createRule({name:"ban-eslint-disable",meta:{type:"problem",docs:{description:"Ban `eslint-disable` comment directive"},schema:[{oneOf:[{type:"boolean"},{type:"string",enum:["allow-with-description"]}]}],messages:{"do-not-use":"Do not use `{{directive}}`","require-description":"Include a description after the `{{directive}}` directive to explain why the `{{directive}}` is necessary.","require-specific-rule":"Enforce specifying rules to disable in `eslint-disable` comments. If you want to disable ESLint on a file altogether, you should ignore it through ESLint configuration."}},create:(e,t="allow-with-description")=>!1===t?{}:{Program(r){if(r.comments&&0!==r.comments.length)for(let n of r.comments){let r=function(e){let t=c.exec(e);return t?.groups?.directive}(n.value);if(r&&("allow-with-description"!==t||!n.value.includes("--"))){let o="allow-with-description"===t?"require-description":"do-not-use";e.report({node:n,data:{directive:r},messageId:o})}let o=function(e){let t=u.exec(e.trim());return t?t.groups?.ruleId:p}(n.value);o===p||o||e.report({node:n,messageId:"require-specific-rule"})}}}});let m=n.nullthrow(new r.Linter({configType:"eslintrc"}).getRules().get("no-return-await"),"[eslint-plugin-sukka] no-return-await rule is removed from ESLint!");var f=t.createRule({...m,meta:{docs:{...m.meta?.docs,recommended:void 0},...m.meta,deprecated:!1}}),g=t.createRule({name:"no-expression-empty-lines",meta:{messages:{unexpectedEmptyLine:"Unexpected empty line before"},docs:{description:"Disallows empty lines inside expressions."},fixable:"whitespace",type:"suggestion",schema:[]},create(e){let t=e.sourceCode.getText(),r=o.detectEol(t);return{MemberExpression(n){let o=n.object.range[1],s=h(t.slice(o));if(s.includes("\n")){var i;let t=r+((h(i=s).split(/\r\n|\n/u).at(-1)??"")+i.trimStart());s!==t&&e.report({fix:()=>({range:[o,o+s.length],text:t}),messageId:"unexpectedEmptyLine",node:n.property})}}}}});function h(e){return e.slice(0,e.length-e.trimStart().length)}var S=t.createRule({name:"object-format",meta:{fixable:"whitespace",schema:[{type:"object",properties:{maxLineLength:{type:"number",default:80},maxObjectSize:{type:"number",default:3}},additionalProperties:!1}],docs:{description:"Requires multiline or single-line object format.",recommended:"stylistic"},messages:{preferMultiline:"Prefer multiline object literal",preferSingleLine:"Prefer single-line object literal"},type:"layout"},create(e,t={}){var r;let n=e.sourceCode.getText(),s=o.detectEol(n),i=`,${s}`,{maxLineLength:a=80,maxObjectSize:l=3}=t,c=(r=n,e=>r.slice(e.range[1]).trimStart().startsWith("//"));return{ObjectExpression(t){let r=t.properties.map(t=>n.slice(Math.min(t.range[0],...e.sourceCode.getCommentsBefore(t).map(e=>e.range[0])),t.range[1]).trim());if(r.length>0){var o;let u,p,d,m,f=e.sourceCode.getText(t),g=r.length>l||r.some(y)||t.properties.some(c),h=y(f),S=!f.includes("\n");g&&S&&e.report({fix:()=>({range:t.range,text:`{${s}${r.join(i)}${s}}`}),messageId:"preferMultiline",node:t}),!g&&h&&(u=e.sourceCode.getLocFromIndex(t.range[0]),p=r.reduce((e,t)=>e+t.length,0),d=2*(r.length-1),m=("number"==typeof(o=t.range[1])?n.slice(o):n.slice(...o.range)).split(/\r\n|\n/u)[0].replace(/^((?: as const)?\S*).*/u,"$1").length,u.column+p+d+4+m<=a)&&e.report({fix:()=>({range:t.range,text:`{${r.join(",")}}`}),messageId:"preferSingleLine",node:t})}}}}});function y(e){return e.includes("\n")}var E=t.createRule({name:"prefer-single-boolean-return",meta:{messages:{replaceIfThenElseByReturn:"Replace this if-then-else flow by a single return statement.",suggest:"Replace with single return statement",suggestCast:'Replace with single return statement using "!!" cast',suggestBoolean:"Replace with single return statement without cast (condition should be boolean!)"},schema:[],type:"suggestion",hasSuggestions:!0,docs:{description:'Return of boolean expressions should not be wrapped into an "if-then-else" statement',recommended:"recommended"}},create:e=>({IfStatement(t){var r,n,o;let i,a,l,c;t.parent.type!==s.AST_NODE_TYPES.IfStatement&&_(t.consequent)&&function(e){if(e.alternate)return _(e.alternate);let{parent:t}=e;if(t.type===s.AST_NODE_TYPES.BlockStatement){let r=t.body.indexOf(e);return T(t.body[r+1])}return!1}(t)&&e.report({messageId:"replaceIfThenElseByReturn",node:t,suggest:(r=t,i=e=>t=>{let n=`return ${e};`;if(r.alternate)return t.replaceText(r,n);let o=r.parent,s=o.body.indexOf(r),i=o.body[s+1],a=[r.range[0],i.range[1]];return t.replaceTextRange(a,n)},a=!1===((n=r.consequent).type===s.AST_NODE_TYPES.BlockStatement?n.body[0]:n).argument.value,l=!(((o=r.test).type===s.AST_NODE_TYPES.UnaryExpression||o.type===s.AST_NODE_TYPES.BinaryExpression)&&["!","==","===","!=","!==","<","<=",">",">=","in","instanceof"].includes(o.operator)),c=e.sourceCode.getText(r.test),a?[{messageId:"suggest",fix:i(`!(${c})`)}]:l?[{messageId:"suggestCast",fix:i(`!!(${c})`)},{messageId:"suggestBoolean",fix:i(c)}]:[{messageId:"suggest",fix:i(c)}])})}})});function T(e){return e?.type===s.AST_NODE_TYPES.ReturnStatement&&e.argument?.type===s.AST_NODE_TYPES.Literal&&"boolean"==typeof e.argument.value}function _(e){return void 0!==e&&(e.type===s.AST_NODE_TYPES.BlockStatement&&1===e.body.length&&T(e.body[0])||T(e))}function v(e,t,r){var n,o;return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>v(e,t[n],r)):!(Array.isArray(e)||Array.isArray(t))&&e.type===t.type&&(n=r.getTokens(e),o=r.getTokens(t),n.length===o.length&&n.every((e,t)=>e.value===o[t].value))}function b(e){let t=!1;return{branches:e.cases.reduce((r,n,o)=>{var i;return n.test||(t=!0),(o===e.cases.length-1||n.consequent.length>0)&&r.push((i=n.consequent).length>0&&i[i.length-1].type===s.AST_NODE_TYPES.BreakStatement?i.slice(0,-1):i),r},[]),endsWithDefault:t}}t.createRule({name:"no-all-duplicated-branches",meta:{messages:{removeOrEditConditionalStructure:"Remove this conditional structure or edit its code blocks so that they're not all the same.",returnsTheSameValue:'This conditional operation returns the same value whether the condition is "true" or "false".'},schema:[],type:"problem",docs:{description:"All branches in a conditional structure should not have exactly the same implementation",recommended:"recommended"}},create(e){return{IfStatement(r){if(r.parent?.type!==s.AST_NODE_TYPES.IfStatement){let{branches:n,endsWithElse:o}=function(e){let t=[e.consequent],r=!1,n=e.alternate;for(;n;)if(n.type===s.AST_NODE_TYPES.IfStatement)t.push(n.consequent),n=n.alternate;else{t.push(n),r=!0;break}return{branches:t,endsWithElse:r}}(r);o&&t(n)&&e.report({messageId:"removeOrEditConditionalStructure",node:r})}},SwitchStatement(r){let{branches:n,endsWithDefault:o}=b(r);o&&t(n)&&e.report({messageId:"removeOrEditConditionalStructure",node:r})},ConditionalExpression(r){t([r.consequent,r.alternate])&&e.report({messageId:"returnsTheSameValue",node:r})}};function t(t){return t.length>1&&t.slice(1).every((r,n)=>v(r,t[n],e.sourceCode))}}});var A=t.createRule({name:"no-duplicated-branches",meta:{schema:[],type:"suggestion",docs:{description:"Two branches in a conditional structure should not have exactly the same implementation",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1871/javascript"},messages:{sameConditionalBlock:"This {{type}}'s code block is the same as the block for the {{type}} on line {{line}}."}},create(e){return{IfStatement(o){!function(o){if(o.parent.type===s.AST_NODE_TYPES.IfStatement)return;let{branches:i,endsWithElse:a}=function(e){let t=[e.consequent],r=!1,n=e.alternate;for(;n;)if(n.type===s.AST_NODE_TYPES.IfStatement)t.push(n.consequent),n=n.alternate;else{t.push(n),r=!0;break}return{branches:t,endsWithElse:r}}(o);if(r(i,a))return i.slice(1).forEach((e,t)=>n(e,i[t],"branch"));for(let r=1;r<i.length;r++)if(t([i[r]]))for(let t=0;t<r&&!function(t,r){let o=D(t,r,e.sourceCode);return o&&"loc"in r&&n(t,r,"branch"),o}(i[r],i[t]);t++);}(o)},SwitchStatement(o){!function(o){let{cases:s}=o,{endsWithDefault:i}=b(o),a=s.filter(e=>P(x(e.consequent)).length>0);if(r(a.map(e=>P(x(e.consequent))),i))return a.slice(1).forEach((e,t)=>n(e,a[t],"case"));for(let r=1;r<s.length;r++){let o=P(x(s[r].consequent));if(t(o)){for(let t=0;t<r;t++)if(D(o,P(x(s[t].consequent)),e.sourceCode)){n(s[r],s[t],"case");break}}}}(o)}};function t(t){if(t.length>0){let r=[...e.sourceCode.getTokens(t[0]),...e.sourceCode.getTokens(t[t.length-1])].filter(e=>"{"!==e.value&&"}"!==e.value);return r.length>0&&r[r.length-1].loc.end.line>r[0].loc.start.line}return!1}function r(t,r){return!r&&t.length>1&&t.slice(1).every((r,n)=>D(r,t[n],e.sourceCode))}function n(t,r,n){let o=r.loc;e.report({messageId:"sameConditionalBlock",data:{type:n,line:String(o.start.line)},node:t})}}});function x(e){if(1===e.length){let t=e[0];if(t.type===s.AST_NODE_TYPES.BlockStatement)return t.body}return e}function D(e,t,r){var n,o;return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>D(e,t[n],r)):!(Array.isArray(e)||Array.isArray(t))&&e.type===t.type&&(n=r.getTokens(e),o=r.getTokens(t),n.length===o.length&&n.every((e,t)=>e.value===o[t].value))}function P(e){return e.length>0&&e[e.length-1].type===s.AST_NODE_TYPES.BreakStatement?e.slice(0,-1):e}var O=t.createRule({name:"comma-or-logical-or-case",meta:{type:"problem",docs:{description:"Comma and logical OR operators should not be used in switch cases",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3616/javascript"},schema:[],messages:{specifyCase:'Explicitly specify {{nesting}} separate cases that fall through; currently this case clause only works for "{{expression}}".'}},create(e){function t(t,r,n){var o;e.report({messageId:"specifyCase",data:{nesting:n.toString(),expression:String((o=r).type===s.AST_NODE_TYPES.Literal?o.value:e.sourceCode.getText(o))},node:t})}return{"SwitchCase > SequenceExpression":function(e){let r=e.expressions;t(e,r[r.length-1],r.length)},"SwitchCase > LogicalExpression":function(r){var n;if((n=function(t){let r=e.sourceCode.getAncestors(t);for(let e=r.length-1;e>=0;e--)if(r[e].type===s.AST_NODE_TYPES.SwitchStatement)return r[e];throw Error("A switch case should have an enclosing switch statement")}(r)).discriminant.type!==s.AST_NODE_TYPES.Literal||!0!==n.discriminant.value){let e=function e(t,r){if("||"===t.operator)return t.left.type===s.AST_NODE_TYPES.LogicalExpression?e(t.left,r+1):[t.left,r+1]}(r,0);e&&t(r,e[0],e[1]+1)}}}}}),w=t.createRule({name:"no-element-overwrite",meta:{schema:[],type:"problem",docs:{description:"Collection elements should not be replaced unconditionally",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4143/javascript"},messages:{verifyIntendedIndex:'Verify this is the index that was intended; "{{index}}" was already set on line {{line}}.'}},create(e){return{SwitchCase(e){t(e.consequent)},BlockStatement(e){t(e.body)},Program(e){t(e.body.filter(e=>{var t;return!((t=e)&&(t.type===s.AST_NODE_TYPES.ImportDeclaration||t.type===s.AST_NODE_TYPES.ExportNamedDeclaration||t.type===s.AST_NODE_TYPES.ExportDefaultDeclaration||t.type===s.AST_NODE_TYPES.ExportAllDeclaration))}))}};function t(t){let r,n=new Map;t.forEach(t=>{let o=function(t){if(t.type===s.AST_NODE_TYPES.ExpressionStatement)return function(t){var r,n,o;if((r=t).type===s.AST_NODE_TYPES.AssignmentExpression&&"="===r.operator&&t.left.type===s.AST_NODE_TYPES.MemberExpression&&t.left.computed){let r,s,{left:i,right:a}=t,l=k(i.property);if(void 0!==l&&(n=i.object,o=a,r=e.sourceCode.getTokens(n),void 0===(s=e.sourceCode.getTokens(o)).find((e,t)=>{if(N(e,r[0]))for(let e=t,n=0;e<s.length&&n<r.length;e++,n++)if(N(s[e],r[n])){if(n===r.length-1)return!0}else break;return!1})))return{collectionNode:i.object,indexOrKey:l,node:t}}}(t.expression)||function(e){if(e.type===s.AST_NODE_TYPES.CallExpression&&e.callee.type===s.AST_NODE_TYPES.MemberExpression){let t=e.callee;if(t.property.type===s.AST_NODE_TYPES.Identifier){let r=t.property.name,n="add"===r&&1===e.arguments.length,o="set"===r&&2===e.arguments.length;if(n||o){let r=k(e.arguments[0]);if(r)return{collectionNode:t.object,indexOrKey:r,node:e}}}}}(t.expression)}(t);if(o){r&&!v(o.collectionNode,r,e.sourceCode)&&n.clear();let t=n.get(o.indexOrKey);t?.node.loc&&e.report({node:o.node,messageId:"verifyIntendedIndex",data:{index:o.indexOrKey,line:t.node.loc.start.line}}),n.set(o.indexOrKey,o),r=o.collectionNode}else n.clear()})}}});function N(e,t){return e.value===t.value}function k(e){if(e.type===s.AST_NODE_TYPES.Literal){let{value:t}=e;return"number"==typeof t||"string"==typeof t?String(t):void 0}if(e.type===s.AST_NODE_TYPES.Identifier)return e.name}var Y=t.createRule({name:"class-prototype",meta:{schema:[],type:"suggestion",docs:{description:'Class methods should be used instead of "prototype" assignments',recommended:"recommended"},messages:{declareClass:'Declare a "{{class}}" class and move this declaration of "{{declaration}}" into it.'}},create(e){let r=e.sourceCode.parserServices,n=t.isParserWithTypeInformation(r)?C:R;return{AssignmentExpression({left:t,right:o}){if(t.type===s.AST_NODE_TYPES.MemberExpression&&n(o,r)){let[r,n]=[t.object,t.property];if(r.type===s.AST_NODE_TYPES.MemberExpression&&n.type===s.AST_NODE_TYPES.Identifier){let[o,i]=[r.object,r.property];o.type===s.AST_NODE_TYPES.Identifier&&i.type===s.AST_NODE_TYPES.Identifier&&"prototype"===i.name&&e.report({messageId:"declareClass",data:{class:o.name,declaration:n.name},node:t})}}}}}});function C(e,r){t.ensureParserWithTypeInformation(r);let n=r.program.getTypeChecker().getTypeAtLocation(r.esTreeNodeToTSNodeMap.get(e));return!!n.symbol&&(n.symbol.flags&i.SymbolFlags.Function)!=0}let I=new Set(["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression"]);function R(e){return I.has(e.type)}var j=t.createRule({name:"bool-param-default",meta:{schema:[],type:"suggestion",docs:{description:"Optional boolean parameters should have default value"},messages:{provideDefault:"Provide a default value for '{{parameter}}' so that the logic of the function is more evident when this parameter is missing. Consider defining another function if providing default value is not possible."}},create:e=>({"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression":t=>{for(let r of t.params)r.type===s.AST_NODE_TYPES.Identifier&&function(e){var t;return(t=e).optional&&!!t.typeAnnotation&&t.typeAnnotation.typeAnnotation.type===s.AST_NODE_TYPES.TSBooleanKeyword||function(e){if(e.typeAnnotation&&e.typeAnnotation.typeAnnotation.type===s.AST_NODE_TYPES.TSUnionType){let t=e.typeAnnotation.typeAnnotation.types;return 2===t.length&&t.some(e=>e.type===s.AST_NODE_TYPES.TSBooleanKeyword)&&t.some(e=>e.type===s.AST_NODE_TYPES.TSUndefinedKeyword)}return!1}(e)}(r)&&e.report({messageId:"provideDefault",data:{parameter:r.name},node:r})}})}),L=t.createRule({name:"call-argument-line",meta:{type:"suggestion",docs:{description:"Function call arguments should not start on new lines",recommended:"recommended"},schema:[],messages:{moveArguments:"Make those call arguments start on line {{line}}.",moveTemplateLiteral:"Make this template literal start on line {{line}}."}},create(e){let t=e.sourceCode;return{CallExpression(r){if(r.callee.type!==s.AST_NODE_TYPES.CallExpression&&1===r.arguments.length){var n;let o=(n=r).typeArguments??n.callee,s=(t.getLastTokenBetween(o,r.arguments[0],M)??t.getLastToken(o)).loc.end.line,{start:i}=t.getTokenAfter(o,q).loc;if(s!==i.line){let{end:n}=t.getLastToken(r).loc;n.line===i.line?e.report({messageId:"moveArguments",data:{line:s.toString()},loc:{start:i,end:n}}):e.report({messageId:"moveArguments",data:{line:s.toString()},loc:i})}}},TaggedTemplateExpression(r){let{quasi:n}=r,o=t.getTokenBefore(n);if(o&&n.loc&&o.loc.end.line!==n.loc.start.line){let t={start:n.loc.start,end:{line:n.loc.start.line,column:n.loc.start.column+1}};e.report({messageId:"moveTemplateLiteral",data:{line:o.loc.start.line.toString()},loc:t})}}}}});function M(e){return e.type===s.AST_TOKEN_TYPES.Punctuator&&")"===e.value}function q(e){return!M(e)}var F=t.createRule({name:"track-todo-fixme-comment",meta:{type:"suggestion",docs:{description:'Track uses of "FIXME" and "TODO" tags',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1134/javascript"},schema:[],messages:{fixme:"Take the required action to fix the issue indicated by this comment.",todo:'Complete the task associated to this "TODO" comment.'}},create(e){function t(t,r){e.sourceCode.getAllComments().forEach(n=>{let o=n.value.toLowerCase();if(o.includes(t)){let s=o.split(/\r\n?|\n/);for(let o=0;o<s.length;o++){let i=s[o].indexOf(t);i>=0&&!function(e,t,r){let n=t+r.length,o=t>0&&B.test(e.charAt(t-1)),s=n<=e.length-1&&B.test(e.charAt(n));return o||s}(s[o],i,t)&&e.report({messageId:r,loc:function(e,t,r,n){let o=r.loc.start.line+e,s=(0===e?r.loc.start.column+2:0)+t;return{start:{line:o,column:s},end:{line:o,column:s+n.length}}}(o,i,n,t)})}}})}return{"Program:exit":()=>{t("fixme","fixme"),t("todo","todo")}}}});let B=/\p{Letter}/u,U=["Array","Map","Set","WeakSet","WeakMap"],W=new Set(["copyWithin","pop","reverse","shift","sort","clear","delete","concat","flat","flatMap","includes","indexOf","join","lastIndexOf","slice","toSource","toString","toLocaleString","get","has","entries","every","filter","find","findIndex","forEach","keys","map","reduce","reduceRight","some","values"]);var V=t.createRule({name:"no-empty-collection",meta:{schema:[],type:"problem",docs:{description:"Empty collections should not be accessed or iterated",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4158/javascript"},messages:{reviewUsageOfIdentifier:'Review this usage of "{{identifierName}}" as it can only be empty here.'}},create(e){let t=t=>{if(t.references.length<=1||t.defs.some(e=>e.type===a.TSESLint.Scope.DefinitionType.Parameter||e.type===a.TSESLint.Scope.DefinitionType.ImportBinding))return;let r=[],n=!1;for(let e of t.references)if(e.isWriteOnly())if(!function(e){let t=K(e.identifier,e=>e.type===s.AST_NODE_TYPES.VariableDeclarator||e.type===s.AST_NODE_TYPES.ExpressionStatement);if(t){if(t.type===s.AST_NODE_TYPES.VariableDeclarator&&t.init)return G(t.init);if(t.type===s.AST_NODE_TYPES.ExpressionStatement){let{expression:r}=t;return r.type===s.AST_NODE_TYPES.AssignmentExpression&&z(e,r.left)&&G(r.right)}}return!1}(e))return;else n=!0;else{var o;if(!(function(e){let{parent:t}=e.identifier;if(t?.type===s.AST_NODE_TYPES.MemberExpression){let e=t.parent;if(e?.type===s.AST_NODE_TYPES.CallExpression)return X(t.property,...W)}return!1}(o=e)||function(e){let t=K(e.identifier,e=>e.type===s.AST_NODE_TYPES.ForOfStatement||e.type===s.AST_NODE_TYPES.ForInStatement);return t?.right===e.identifier}(o)||function(e){let{parent:t}=e.identifier;return t?.type===s.AST_NODE_TYPES.MemberExpression&&t.computed&&!function(e){let t=$(e,new Set),r=t.find(e=>e.type===s.AST_NODE_TYPES.AssignmentExpression);return r?.operator==="="&&[e,...t].includes(r.left)}(t)}(o)))return;r.push(e)}n&&r.forEach(t=>{e.report({messageId:"reviewUsageOfIdentifier",data:{identifierName:t.identifier.name},node:t.identifier})})},r=e=>{e.type!==a.TSESLint.Scope.ScopeType.global&&e.variables.forEach(t),e.childScopes.forEach(r)};return{"Program:exit":t=>{r(e.sourceCode.getScope(t))}}}});function K(e,t){return $(e,new Set).find(t)}function $(e,t){let r=[],n=e.parent;for(;n&&(r.push(n),!t.has(n.type));)n=n.parent;return r}function z(e,t){return t.type===s.AST_NODE_TYPES.Identifier&&t===e.identifier}function G(e){return e?.type===s.AST_NODE_TYPES.ArrayExpression?0===e.elements.length:!!e&&(e.type===s.AST_NODE_TYPES.CallExpression||e.type===s.AST_NODE_TYPES.NewExpression)&&X(e.callee,...U)&&0===e.arguments.length}function X(e,...t){return e?.type===s.AST_NODE_TYPES.Identifier&&(0===t.length||t.some(t=>t===e.name))}let H=new Set(["!=","==","!==","==="]),J=new Set(["!==","!="]),Q=new Set(["+=","-="]);var Z=t.createRule({name:"no-equals-in-for-termination",meta:{schema:[],messages:{replaceOperator:"Replace '{{operator}}' operator with one of '<=', '>=', '<', or '>' comparison operators."},type:"suggestion",docs:{description:'Equality operators should not be used in "for" loop termination conditions',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S888/javascript"}},create(e){function t(t,r){if(t.type===s.AST_NODE_TYPES.Identifier){var n;let o=(n=t.name,function(e,t){let r;for(;null==r&&null!=e;)r=e.variables.find(e=>e.name===t),e=e.upper;return r}(e.sourceCode.getScope(t),n)),s=r.range;if(o&&s)return o.references.some(e=>{var t,r;return t=e.identifier,r=s,t.range&&t.range[0]>r[0]&&t.range[1]<r[1]})}return!1}return{ForStatement(r){var n,o;let i,a;if(!r.test||!r.update)return;let l=r.test;(n=l).type===s.AST_NODE_TYPES.BinaryExpression&&H.has(n.operator)&&function e(t){return!!ee(t)||t.type===s.AST_NODE_TYPES.UpdateExpression||t.type===s.AST_NODE_TYPES.SequenceExpression&&t.expressions.every(e)}(r.update)&&(i=(o=r).test,a=[],function e(t,r){let n;ee(t)?n=t.left:t.type===s.AST_NODE_TYPES.UpdateExpression?n=t.argument:t.type===s.AST_NODE_TYPES.SequenceExpression&&t.expressions.forEach(t=>e(t,r)),n?.type===s.AST_NODE_TYPES.Identifier&&r.push(n.name)}(o.update,a),!(i.left.type!==s.AST_NODE_TYPES.Identifier||!a.includes(i.left.name)||function(e){let r=e.init,n=e.test;if(r&&et(n)){let o=function(e,r){var n,o;if(n=e,o=r,n.type===s.AST_NODE_TYPES.UpdateExpression&&!t(n.argument,o)||function(e){if(ee(e)){let t=e.right;return t.type===s.AST_NODE_TYPES.Literal&&1===t.value}return!1}(n)&&!t(n.left,o)){if("++"===e.operator||"+="===e.operator)return 1;if("--"===e.operator||"-="===e.operator)return -1}return 0}(e.update,e.body);if(0!==o){let e=er(r),t=er(n);return void 0!==e&&void 0!==t&&o===Math.sign(t-e)}}return!1}(r)))&&e.report({messageId:"replaceOperator",data:{operator:l.operator},node:l})}}}});function ee(e){return e.type===s.AST_NODE_TYPES.AssignmentExpression&&Q.has(e.operator)}function et(e){return e.type===s.AST_NODE_TYPES.BinaryExpression&&J.has(e.operator)}function er(e){var t;return et(e)?en(e.right):(t=e).type===s.AST_NODE_TYPES.VariableDeclaration&&1===t.declarations.length?en(e.declarations[0].init):e.type===s.AST_NODE_TYPES.AssignmentExpression?en(e.right):void 0}function en(e){if(e?.type===s.AST_NODE_TYPES.Literal&&"number"==typeof e.value)return e.value}var eo=t.createRule({name:"no-top-level-this",meta:{hasSuggestions:!0,schema:[],messages:{removeThis:'Remove the use of "this".',suggestRemoveThis:'Remove "this"',suggestUseGlobalThis:'Replace "this" with "globalThis" object'},type:"suggestion",docs:{description:'The global "this" object should not be used',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S2990/javascript"},fixable:"code"},create:e=>({'MemberExpression[object.type="ThisExpression"]':t=>{let r=e.sourceCode.getScope(t).variableScope.type,n=e.sourceCode.getAncestors(t).some(e=>e.type===s.AST_NODE_TYPES.ClassDeclaration||e.type===s.AST_NODE_TYPES.ClassExpression);if((r===a.TSESLint.Scope.ScopeType.global||r===a.TSESLint.Scope.ScopeType.module)&&!n){let r=[];if(!t.computed){let n=e.sourceCode.getText(t.property);r.push({messageId:"suggestRemoveThis",fix:e=>e.replaceText(t,n)},{messageId:"suggestUseGlobalThis",fix:e=>e.replaceText(t.object,"globalThis")})}e.report({messageId:"removeThis",node:t.object,suggest:r})}}})}),es=t.createRule({name:"no-invariant-returns",meta:{schema:[],type:"suggestion",docs:{description:"Function returns should not be invariant",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3516/javascript",requiresTypeChecking:!1},messages:{refactorReturn:"Refactor this function to only return once or not always return the same value."}},create(e){let t=[],r=[],n=[],o=r=>{var o,i,a;return o=r,void(!(i=t[t.length-1])||(a=i,n.some(e=>e.reachable)||a.containsReturnWithoutValue||a.returnStatements.length<=1||a.codePath.thrownSegments.length>0)||function(e,t){let r=e[0],n=r?el(r,t):void 0;if(void 0!==n)return e.slice(1).every(e=>el(e,t)===n);if(r?.type===s.AST_NODE_TYPES.Identifier){let n=ei(r.name,t);if(n){let t=new Set(n.variable.references.slice(1).map(e=>e.identifier));return e.every(e=>t.has(e))}}return!1}(i.returnStatements.map(e=>e.argument),e.sourceCode.getScope(o))&&e.report({messageId:"refactorReturn",node:o}))};return{onCodePathStart(e){t.push({codePath:e,containsReturnWithoutValue:!1,returnStatements:[]}),r.push(n),n=[]},onCodePathEnd(){t.pop(),n=r.pop()||[]},onCodePathSegmentStart(e){n.push(e)},onCodePathSegmentEnd(){n.pop()},ReturnStatement(e){if(t.length){let r=t[t.length-1];r.containsReturnWithoutValue=r.containsReturnWithoutValue||!e.argument,r.returnStatements.push(e)}},"FunctionDeclaration:exit":o,"FunctionExpression:exit":o,"ArrowFunctionExpression:exit":o}}});function ei(e,t){let r=t.set.get(e);if(r&&!r.references.slice(1).some(e=>{var t;let r;return e.isWrite()||(r=K((t=e).identifier,e=>e.type===s.AST_NODE_TYPES.ExpressionStatement||R(e)),r?.type===s.AST_NODE_TYPES.ExpressionStatement&&(ea(r,t)||r.expression.type===s.AST_NODE_TYPES.CallExpression))})){let e=null;return 1===r.defs.length&&r.defs[0].type===a.TSESLint.Scope.DefinitionType.Variable&&(e=r.defs[0].node.init),{variable:r,initExpression:e}}return null}function ea(e,t,r=!0){return e.expression.type===s.AST_NODE_TYPES.AssignmentExpression&&function e(t,r,n=!0){return t.type===s.AST_NODE_TYPES.MemberExpression&&(z(r,t.object)||n&&e(t.object,r,n))}(e.expression.left,t,r)}function el(e,t){if(e){if(e.type===s.AST_NODE_TYPES.Literal)return e.value;if(e.type===s.AST_NODE_TYPES.UnaryExpression){let r=el(e.argument,t);return void 0===r?void 0:function(e,t){switch(e){case"-":return-Number(t);case"+":return Number(t);case"~":return~Number(t);case"!":return!t;case"typeof":return typeof t}}(e.operator,r)}if(e.type===s.AST_NODE_TYPES.Identifier){let r=ei(e.name,t);if(r?.initExpression)return el(r.initExpression,t)}}}function ec(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function eu(e,t){let r=t.variables.find(t=>t.name===e.name);return!r&&t.upper&&(r=t.upper.variables.find(t=>t.name===e.name)),r}class ep extends Set{constructor(...e){super(...e),ec(this,"type","AssignedValues")}}let ed={type:"UnknownValue"};class em{add(e){e.resolved&&this.references.add(e)}propagate(e){this.in.clear(),this.segment.prevSegments.forEach(t=>{this.join(e.get(t.id).out)});let t=new Map;return this.references.forEach(e=>this.updateProgramState(e,t)),!function(e,t){if(e.size!==t.size)return!1;for(let[o,s]of e){var r,n;if(!t.has(o)||(r=t.get(o),n=s,"AssignedValues"===r.type&&"AssignedValues"===n.type?!function(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}(r,n):r!==n))return!1}return!0}(this.out,t)&&(this.out=t,!0)}updateProgramState(e,t){let r=e.resolved;if(!r||!e.isWrite())return;if(!e.writeExpr)return void t.set(r,ed);let n=ef(r,e.writeExpr,t,e.from);t.set(r,n)}join(e){for(let[t,r]of e.entries()){let e=this.in.get(t)??new ep;"AssignedValues"===e.type&&"AssignedValues"===r.type?(r.forEach(t=>e.add(t)),this.in.set(t,e)):this.in.set(t,ed)}}constructor(e){ec(this,"segment",void 0),ec(this,"in",void 0),ec(this,"out",void 0),ec(this,"references",void 0),this.segment=e,this.in=new Map,this.out=new Map,this.references=new Set}}function ef(e,t,r,n){if(!t)return ed;switch(t.type){case s.AST_NODE_TYPES.Literal:return t.raw?new ep([t.raw]):ed;case s.AST_NODE_TYPES.Identifier:{let o=eu(t,n);if(o&&o!==e)return r.get(o)??ed;return ed}default:return ed}}class eg{constructor(e){ec(this,"codePath",void 0),ec(this,"reachingDefinitionsMap",void 0),ec(this,"reachingDefinitionsStack",void 0),ec(this,"segments",void 0),ec(this,"assignmentStack",void 0),this.codePath=e,this.reachingDefinitionsMap=new Map,this.reachingDefinitionsStack=[],this.segments=new Map,this.assignmentStack=[]}}class eh{isRhs(e){return this.node.type===s.AST_NODE_TYPES.AssignmentExpression?this.node.right===e:this.node.init===e}isLhs(e){return this.node.type===s.AST_NODE_TYPES.AssignmentExpression?this.node.left===e:this.node.id===e}add(e){let t=e.identifier;for(;t;){if(this.isLhs(t)){this.lhs.add(e);break}if(this.isRhs(t)){this.rhs.add(e);break}t=t.parent}}constructor(e){ec(this,"node",void 0),ec(this,"lhs",void 0),ec(this,"rhs",void 0),this.node=e,this.lhs=new Set,this.rhs=new Set}}function eS(e){return e[e.length-1]}var ey=t.createRule({name:"no-redundant-assignments",meta:{schema:[],type:"suggestion",docs:{description:"Assignments should not be redundant",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4165/javascript"},messages:{reviewAssignment:'Review this redundant assignment: "{{symbol}}" already holds the assigned value along all execution paths.'}},create(e){let t=[],r=new Map,n=new Map,o=[],i=[];return{AssignmentExpression:c,"VariableDeclarator[init]":c,"AssignmentExpression:exit":l,"VariableDeclarator[init]:exit":l,Identifier(r){var o;r.parent.type===s.AST_NODE_TYPES.TSEnumBody||r.parent.type===s.AST_NODE_TYPES.TSEnumDeclaration||r.parent.type===s.AST_NODE_TYPES.TSEnumMember||(o=r,e.sourceCode.getAncestors(o).some(e=>e.type===s.AST_NODE_TYPES.TSEnumDeclaration)||function(r){var o;let{ref:s,variable:i}=function e(t,r){if(null===r)return{ref:null,variable:null};let n=r.references.find(e=>e.identifier===t);if(n)return{ref:n,variable:n.resolved};let o=r.variables.find(e=>e.defs.find(e=>e.name===t));return o?{ref:null,variable:o}:e(t,r.upper)}(o=r,e.sourceCode.getScope(o));if(s&&p(s),i){let e=eS(t).codePath.id;n.has(i)?n.get(i).add(e):n.set(i,new Set([e]))}}(r))},"Program:exit":()=>{let e=Array.from(r.values(),e=>e.segment);for(;e.length;){let t=e.pop();r.get(t.id).propagate(r)&&t.nextSegments.forEach(t=>e.push(t))}r.forEach(u),r.clear(),n.clear(),t.length=0},onCodePathSegmentStart(e){r.set(e.id,new em(e)),i.push(e)},onCodePathStart(e){var r;r=new eg(e),t.push(r),o.push(i),i.length=0},onCodePathEnd(){t.pop(),o.pop()||(i.length=0)},onCodePathSegmentEnd(){i.pop()}};function l(){let e=eS(t).assignmentStack.pop();e.rhs.forEach(p),e.lhs.forEach(p)}function c(e){eS(t).assignmentStack.push(new eh(e))}function u(t){let r=new Map(t.in);t.references.forEach(t=>{let o=t.resolved;if(!o||!t.isWrite()||!function(e){var t;let r=e.resolved;return r&&(e.identifier.type!==s.AST_NODE_TYPES.Identifier||e.identifier.parent.type!==s.AST_NODE_TYPES.AssignmentPattern)&&!r.name.startsWith("_")&&!function(e){if(e?.parent){let t=e.parent;return t?.type===s.AST_NODE_TYPES.AssignmentExpression&&"="!==t.operator}return!1}(e.writeExpr)&&(e.writeExpr?.type!==s.AST_NODE_TYPES.Identifier||e.resolved!==eu(e.writeExpr,e.from))&&!r.defs.some(e=>e.type===a.TSESLint.Scope.DefinitionType.Parameter||e.type===a.TSESLint.Scope.DefinitionType.Variable&&!e.node.init)&&(t=r,!(n.get(t).size>1))}(t))return;let i=r.get(o),l=ef(o,t.writeExpr,r,t.from);if(i?.type==="AssignedValues"&&1===i.size){let[r]=[...i];!function({resolved:t},r,n,o,s){if("UnknownValue"===o.type||1!==o.size)return;let[i]=[...o];t&&1!==t.references.filter(e=>e.isWrite()).length&&n===i&&e.report({node:r,messageId:"reviewAssignment",data:{symbol:s}})}(t,t.writeExpr,r,l,o.name)}r.set(o,l)})}function p(e){let{assignmentStack:n}=eS(t);if(n.length>0)eS(n).add(e);else for(let t=0,n=i.length;t<n;t++)(function(e){let t;return r.has(e.id)?t=r.get(e.id):(t=new em(e),r.set(e.id,t)),t})(i[t]).add(e)}}}),eE=t.createRule({name:"no-same-line-conditional",meta:{schema:[],type:"layout",docs:{description:"Conditionals should start on new lines",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3972/javascript"},fixable:"whitespace",messages:{sameLineCondition:'Move this "if" to a new line or add the missing "else".'}},create(e){function t(t){var r;let{sourceCode:n}=e;(r=t).reduce((e,t,n)=>{let o=r[n-1];return t.type===s.AST_NODE_TYPES.IfStatement&&o&&o.type===s.AST_NODE_TYPES.IfStatement?[{first:o,following:t},...e]:e},[]).forEach(t=>{let r=t.first,o=t.following;if(r.loc?.end.line===o.loc?.start.line&&r.loc.start.line!==o.loc.end.line){let t=n.getFirstToken(o);e.report({messageId:"sameLineCondition",loc:t.loc,fix:e=>e.replaceTextRange([r.range[1],o.range[0]],"\n"+" ".repeat(r.loc.start.column))})}})}return{Program:e=>t(e.body),BlockStatement:e=>t(e.body),SwitchCase:e=>t(e.consequent)}}}),eT=t.createRule({name:"no-small-switch",meta:{schema:[],messages:{replaceSwitch:'Replace this "switch" statement by "if" statements to increase readability.'},type:"suggestion",docs:{description:'"if" statements should be preferred over "switch" when simpler',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1301/javascript"}},create:e=>({SwitchStatement(t){let{cases:r}=t,n=r.some(e=>!e.test);if(r.length<2||2===r.length&&n){let r=e.sourceCode.getFirstToken(t);r&&e.report({messageId:"replaceSwitch",loc:r.loc})}}})});let e_=["Array","Map","Set","WeakSet","WeakMap"],ev=["copyWithin","fill","pop","push","reverse","set","shift","sort","splice","unshift","add","clear","delete"];var eb=t.createRule({name:"no-unused-collection",meta:{schema:[],messages:{unusedCollection:"Either use this collection's contents or remove the collection."},type:"suggestion",docs:{description:"Collection contents should be used",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4030/javascript",requiresTypeChecking:!1}},create:e=>({"Program:exit":t=>{let r=[];(function e(t,r){t.type!==a.TSESLint.Scope.ScopeType.global&&t.variables.forEach(e=>{(function(e){if(function(e){if(!e.defs.length)return;let t=e.defs[0];return t.node.parent?.parent?.type.startsWith("Export")}(e)||e.references.length<=1)return!1;let t=!1;for(let r of e.references)if(r.isWriteOnly())if(!function(e){let t=K(e.identifier,e=>e.type===s.AST_NODE_TYPES.VariableDeclarator||e.type===s.AST_NODE_TYPES.ExpressionStatement);if(t){if(t.type===s.AST_NODE_TYPES.VariableDeclarator&&t.init)return eA(t.init);if(t.type===s.AST_NODE_TYPES.ExpressionStatement){let{expression:r}=t;return r.type===s.AST_NODE_TYPES.AssignmentExpression&&z(e,r.left)&&eA(r.right)}}return!1}(r))return!1;else t=!0;else if(function(e){let t=K(e.identifier,e=>e.type===s.AST_NODE_TYPES.ExpressionStatement);return!t||!ea(t,e,!1)&&!function(e,t){if(e.expression.type===s.AST_NODE_TYPES.CallExpression){let{callee:r}=e.expression;if(r.type===s.AST_NODE_TYPES.MemberExpression){let{property:e,object:n}=r;return z(t,n)&&X(e,...ev)}}return!1}(t,e)}(r))return!1;return t})(e)&&r.push(e)}),t.childScopes.forEach(t=>{e(t,r)})})(e.sourceCode.getScope(t),r),r.forEach(t=>{e.report({messageId:"unusedCollection",node:t.identifiers[0]})})}})});function eA(e){return e?.type===s.AST_NODE_TYPES.ArrayExpression||!!e&&(e.type===s.AST_NODE_TYPES.CallExpression||e.type===s.AST_NODE_TYPES.NewExpression)&&X(e.callee,...e_)}var ex=t.createRule({name:"no-useless-plusplus",meta:{schema:[],type:"problem",docs:{description:"Values should not be uselessly incremented",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S2123/javascript"},messages:{removeIncrement:"Remove this {{updateOperator}}rement or correct the code not to waste it."}},create(e){function t(t){let r="++"===t.operator?"inc":"dec";e.report({messageId:"removeIncrement",data:{updateOperator:r},node:t})}return{"ReturnStatement > UpdateExpression":function(r){var n;let o=r.argument;!r.prefix&&o.type===s.AST_NODE_TYPES.Identifier&&(n=o,e.sourceCode.getScope(r).variables.some(e=>e.identifiers.some(e=>e.name===n.name)))&&t(r)},AssignmentExpression(e){let r=e.right;if(r.type===s.AST_NODE_TYPES.UpdateExpression&&!r.prefix){let n=e.left;n.type===s.AST_NODE_TYPES.Identifier&&r.argument.type===s.AST_NODE_TYPES.Identifier&&r.argument.name===n.name&&t(r)}}}}});let eD=new Set(["map","filter","reduce","reduceRight","forEach"]);var eP=t.createRule({name:"no-chain-array-higher-order-functions",meta:{type:"problem",fixable:"code",docs:{description:"Prefer `.reduce` over chaining `.filter`, `.map` methods",recommended:"recommended"},schema:[],messages:{detected:"Detected the chaining of array methods: {{methods}}. Reaplce with `.reduce` to reduce array iterations and improve the performance."}},create:e=>({MemberExpression(t){if(eO(t)){let r=t.parent;eO(r.parent)&&e.report({node:r,messageId:"detected",data:{methods:`arr.${t.property.name}().${r.parent.property.name}()`}})}}})});function eO(e){return e.type===s.AST_NODE_TYPES.MemberExpression&&!e.computed&&e.property.type===s.AST_NODE_TYPES.Identifier&&eD.has(e.property.name)&&e.parent.type===s.AST_NODE_TYPES.CallExpression}var ew=t.createRule({name:"no-export-const-enum",meta:{type:"suggestion",docs:{description:"Disallow using `const enum` expression as it can not be inlined and tree-shaken by swc/esbuild/babel/webpack/rollup/vite/bun/rspack"},messages:{noConstEnum:"Do not use `const enum` expression"},schema:[]},create(e){let t=(t,r)=>{let n=a.ASTUtils.findVariable(e.sourceCode.getScope(t),r);n?.defs.forEach(r=>{r.node.type===s.AST_NODE_TYPES.TSEnumDeclaration&&r.node.const&&e.report({node:t,messageId:"noConstEnum"})})};return{ExportNamedDeclaration(r){let n=r.declaration;if(n?.type===s.AST_NODE_TYPES.TSEnumDeclaration&&n.const)return void e.report({node:r,messageId:"noConstEnum"});if(n?.type===s.AST_NODE_TYPES.VariableDeclaration){let e=n.declarations[0].id;e.type===s.AST_NODE_TYPES.Identifier&&t(r,e)}},ExportDefaultDeclaration(e){let r=e.declaration;r.type===s.AST_NODE_TYPES.Identifier&&t(e,r)}}}}),eN=t.createRule({name:"no-for-in-iterable",meta:{schema:[],type:"suggestion",docs:{description:'"for in" should not be used with iterables',recommended:"strict",url:"https://sonarsource.github.io/rspec/#/rspec/S4139/javascript"},messages:{useForOf:'Use "for...of" to iterate over this "{{iterable}}".'}},create(e){let r=e.sourceCode.parserServices;return{ForInStatement(n){var o,s;t.ensureParserWithTypeInformation(r);let a=ek(n.right,r);if(t.ensureParserWithTypeInformation(r),(o=a).symbol&&eY.has(o.symbol.name)||((s=a).flags&i.TypeFlags.StringLike)>0||s.symbol?.name==="String"||function(e,t){var r,n=t.program.getTypeChecker().getBaseConstraintOfType(e)??e,o=t;for(let e of(r=n).isUnion()?r.types:[r])if(!function(e,t){let r=t.program.getTypeChecker();return"isArrayType"in r&&"function"==typeof r.isArrayType&&r.isArrayType(e)}(e,o))return!1;return!0}(a,r)){let t=a.symbol?a.symbol.name:"String";e.report({messageId:"useForOf",data:{iterable:t},loc:e.sourceCode.getFirstToken(n).loc})}}}}});function ek(e,t){return t.program.getTypeChecker().getTypeAtLocation(t.esTreeNodeToTSNodeMap.get(e))}let eY=new Set(["Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Set","Map"]);var eC=t.createRule({name:"only-await-thenable",meta:{schema:[],type:"suggestion",docs:{description:'"await" should only be used with promises',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4123/javascript"},messages:{refactorAwait:"Refactor this redundant 'await' on a non-promise."}},create(e){let r=e.sourceCode.parserServices;return t.ensureParserWithTypeInformation(r),{AwaitExpression(t){let n,o=ek(t.argument,r);(function(e,t){var r,n;if(e.argument.type!==s.AST_NODE_TYPES.CallExpression)return!1;let o=(r=e.argument,(n=t).program.getTypeChecker().getResolvedSignature(n.esTreeNodeToTSNodeMap.get(r)));return o?.declaration&&function(e){if(!e.jsDoc)return!1;for(let t of e.jsDoc)if(t.tags?.some(e=>eI.has(e.tagName.escapedText.toString())))return!0;return!1}(o.declaration)})(t,r)||(n=o.getProperty("then"),n?.declarations?.some(e=>e.kind===i.SyntaxKind.MethodSignature||e.kind===i.SyntaxKind.MethodDeclaration||e.kind===i.SyntaxKind.PropertyDeclaration))||o.flags&i.TypeFlags.Any||o.flags&i.TypeFlags.Unknown||o.flags&i.TypeFlags.Union||e.report({messageId:"refactorAwait",node:t})}}}});let eI=new Set(["return","returns"]);var eR=t.createRule({name:"no-undefined-optional-parameters",meta:{schema:[],type:"suggestion",docs:{description:'"undefined" should not be passed as the value of optional parameters',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4623/javascript",requiresTypeChecking:!0},fixable:"code",hasSuggestions:!0,messages:{removeUndefined:'Remove this redundant "undefined".',suggestRemoveUndefined:"Remove this redundant argument"}},create(e){let r=e.sourceCode.parserServices;return t.ensureParserWithTypeInformation(r),{CallExpression(t){var n;let{arguments:o}=t;if(0===o.length)return;let i=o[o.length-1];(n=i).type===s.AST_NODE_TYPES.Identifier&&"undefined"===n.name&&function(e,t,r){let n=r.program.getTypeChecker().getResolvedSignature(r.esTreeNodeToTSNodeMap.get(t));if(n){var o;let t=n.declaration;if(t&&(o=t,ej.has(o.kind))){let{parameters:r}=t,n=r[e];return n&&(n.initializer||n.questionToken)}}return!1}(o.length-1,t,r)&&e.report({messageId:"removeUndefined",node:i,suggest:[{messageId:"suggestRemoveUndefined",fix(r){if(1===t.arguments.length){let n=e.sourceCode.getTokenAfter(t.callee),o=e.sourceCode.getLastToken(t),[,s]=n.range,[i]=o.range;return r.removeRange([s,i])}let[,n]=o[o.length-2].range,[,s]=i.range;return r.removeRange([n,s])}}]})}}}});let ej=new Set([i.SyntaxKind.FunctionDeclaration,i.SyntaxKind.FunctionExpression,i.SyntaxKind.ArrowFunction,i.SyntaxKind.MethodDeclaration,i.SyntaxKind.Constructor,i.SyntaxKind.GetAccessor,i.SyntaxKind.SetAccessor]);function eL(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class eM{visit(e,t){let r=e=>{switch(e.type){case s.AST_NODE_TYPES.AwaitExpression:case s.AST_NODE_TYPES.CallExpression:case s.AST_NODE_TYPES.NewExpression:this.callLikeExpressions.push(e);break;case s.AST_NODE_TYPES.FunctionDeclaration:case s.AST_NODE_TYPES.FunctionExpression:case s.AST_NODE_TYPES.ArrowFunctionExpression:return}(function(e,t){let r=[],n=t[e.type];if(n?.length)for(let t of n){let n=e[t];Array.isArray(n)?r.push(...n):r.push(n)}return r.filter(Boolean)})(e,t.sourceCode.visitorKeys).forEach(r)};r(e)}constructor(){eL(this,"callLikeExpressions",[])}}eL(eM,"getCallExpressions",(e,t)=>{let r=new eM;return r.visit(e,t),r.callLikeExpressions});var eq=t.createRule({name:"no-try-promise",meta:{schema:[],type:"problem",docs:{description:'Promise rejections should not be caught by "try" blocks',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4822/javascript",requiresTypeChecking:!0},messages:{addAwait:"Consider using 'await' for the promise{{ending}} inside this 'try' or replace it with 'Promise.prototype.catch(...)' usage{{ending}}.",removeTry:"Consider removing this 'try' statement as promise{{ending}} rejection is already captured by '.catch()' method."}},create(e){let r=e.sourceCode.parserServices;return t.ensureParserWithTypeInformation(r),{TryStatement(t){if(t.handler){let n=[],o=[],a=!1;if(eM.getCallExpressions(t.block,e).forEach(e=>{var t,l,c,u,p,d;let m,f;if(e.type===s.AST_NODE_TYPES.AwaitExpression||(t=e,m=(l=r).esTreeNodeToTSNodeMap.get(t),!(f=l.program.getTypeChecker().getTypeAtLocation(m).getProperty("then"))||!(f.flags&i.SymbolFlags.Method))){a=!0;return}(c=e).parent&&(c.parent.type===s.AST_NODE_TYPES.AwaitExpression||c.parent.type===s.AST_NODE_TYPES.YieldExpression)||(u=e,u.parent?.type===s.AST_NODE_TYPES.MemberExpression&&u.parent.property.type===s.AST_NODE_TYPES.Identifier&&"then"===u.parent.property.name)||(p=e).type===s.AST_NODE_TYPES.CallExpression&&p.callee.type===s.AST_NODE_TYPES.MemberExpression&&p.callee.property.type===s.AST_NODE_TYPES.Identifier&&"catch"===p.callee.property.name||((d=e,d.parent?.type===s.AST_NODE_TYPES.MemberExpression&&d.parent.property.type===s.AST_NODE_TYPES.Identifier&&"catch"===d.parent.property.name)?o:n).push(e)}),!a){if(n.length>0){let r=n.length>1?"s":"",o=e.sourceCode.getFirstToken(t);e.report({messageId:"addAwait",data:{ending:r},loc:o.loc})}if(0===n.length&&o.length>0){let r=o.length>1?"s":"",n=e.sourceCode.getFirstToken(t);e.report({messageId:"removeTry",data:{ending:r},loc:n.loc})}}}}}}}),eF=t.createRule({name:"no-unthrown-error",meta:{schema:[],type:"problem",docs:{description:"Errors should not be created without being thrown",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3984/javascript",requiresTypeChecking:!1},fixable:"code",hasSuggestions:!0,messages:{throwOrRemoveError:"Throw this error or remove this useless statement.",suggestThrowError:"Throw this error"}},create:e=>({"ExpressionStatement > NewExpression":function(t){var r;let n;if(r=t.callee,(n=e.sourceCode.getText(r)).endsWith("Error")||n.endsWith("Exception")){let r,n=(r=e.sourceCode.getAncestors(t)).length>0?r[r.length-1]:void 0;e.report({messageId:"throwOrRemoveError",node:t,suggest:n?[{messageId:"suggestThrowError",fix:e=>e.insertTextBefore(n,"throw ")}]:[]})}}})}),eB=t.createRule({name:"no-useless-string-operation",meta:{schema:[],messages:{uselessStringOp:"{{symbol}} is an immutable object; you must either store or return the result of the operation."},type:"problem",docs:{description:"Results of operations on strings should not be ignored",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1154/javascript"}},create(e){let r=e.sourceCode.parserServices;return{'ExpressionStatement > CallExpression[callee.type="MemberExpression"]':n=>{let o,{object:i,property:a}=n.callee;t.ensureParserWithTypeInformation(r),(ek(i,r).flags&l.TypeFlags.StringLike)!=0&&a.type===s.AST_NODE_TYPES.Identifier&&e.report({messageId:"uselessStringOp",data:{symbol:((o=e.sourceCode.getText(i)).length>30&&(o="String"),o)},node:a})}}}});let eU={configs:{recommended:{name:"eslint-plugin-sukka/recommended",plugins:{get sukka(){return eU}},rules:{"sukka/ban-eslint-disable":["error","allow-with-description"],"sukka/bool-param-default":"error","sukka/call-argument-line":"error","sukka/class-prototype":"warn","sukka/comma-or-logical-or-case":"error","sukka/no-all-duplicated-branches":"error","sukka/no-chain-array-higher-order-functions":"error","sukka/no-duplicated-branches":"error","sukka/no-element-overwrite":"warn","sukka/no-empty-collection":"warn","sukka/no-equals-in-for-termination":"error","sukka/no-export-const-enum":"error","sukka/no-expression-empty-lines":"error","sukka/no-invariant-returns":"error","sukka/no-redundant-assignments":"warn","no-return-await":"off","sukka/no-return-await":"error","sukka/no-same-line-conditional":"error","sukka/no-small-switch":"error","sukka/no-top-level-this":"error","sukka/no-unthrown-error":"warn","sukka/no-unused-collection":"error","sukka/no-useless-plusplus":"error","sukka/object-format":"off","sukka/prefer-single-boolean-return":"error","sukka/track-todo-fixme-comment":"warn"}},recommended_extra_with_typed_lint:{name:"eslint-plugin-sukka/recommended_extra_with_typed_lint",plugins:{get sukka(){return eU}},rules:{"sukka/no-for-in-iterable":"error","sukka/no-try-promise":"error","sukka/no-undefined-optional-parameters":"warn","sukka/no-useless-string-operation":"warn","sukka/only-await-thenable":"off"}}},rules:{"ban-eslint-disable":d,"no-return-await":f,"no-expression-empty-lines":g,"object-format":S,"prefer-single-boolean-return":E,"no-all-duplicated-branches":A,"no-duplicated-branches":A,"bool-param-default":j,"call-argument-line":L,"class-prototype":Y,"comma-or-logical-or-case":O,"track-todo-fixme-comment":F,"no-element-overwrite":w,"no-empty-collection":V,"no-equals-in-for-termination":Z,"no-top-level-this":eo,"no-invariant-returns":es,"no-redundant-assignments":ey,"no-same-line-conditional":eE,"no-small-switch":eT,"no-unused-collection":eb,"no-useless-plusplus":ex,"no-chain-array-higher-order-functions":eP,"no-export-const-enum":ew,"no-for-in-iterable":eN,"only-await-thenable":eC,"no-undefined-optional-parameters":eR,"no-try-promise":eq,"no-unthrown-error":eF,"no-useless-string-operation":eB}};module.exports=eU;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createRule as e,isParserWithTypeInformation as t,ensureParserWithTypeInformation as r}from"@eslint-sukka/shared";import{Linter as n}from"eslint";import{nullthrow as o}from"foxts/guard";import{detectEol as s}from"foxts/detect-eol";import{AST_NODE_TYPES as i,AST_TOKEN_TYPES as a}from"@typescript-eslint/types";import*as l from"typescript";import{SymbolFlags as c,TypeFlags as p,SyntaxKind as u}from"typescript";import{TSESLint as d,ASTUtils as m}from"@typescript-eslint/utils";let f=/^\s*(?<directive>eslint-disable(?:-(?:next-)?line)?)/,g=/^eslint-disable(?:-next-line|-line)?(?<ruleId>$|(?:\s+(?:@(?:[\w-]+\/){1,2})?[\w-]+)?)/,h=Symbol("rule-id-no-match");var y=e({name:"ban-eslint-disable",meta:{type:"problem",docs:{description:"Ban `eslint-disable` comment directive"},schema:[{oneOf:[{type:"boolean"},{type:"string",enum:["allow-with-description"]}]}],messages:{"do-not-use":"Do not use `{{directive}}`","require-description":"Include a description after the `{{directive}}` directive to explain why the `{{directive}}` is necessary.","require-specific-rule":"Enforce specifying rules to disable in `eslint-disable` comments. If you want to disable ESLint on a file altogether, you should ignore it through ESLint configuration."}},create:(e,t="allow-with-description")=>!1===t?{}:{Program(r){if(r.comments&&0!==r.comments.length)for(let n of r.comments){let r=function(e){let t=f.exec(e);return t?.groups?.directive}(n.value);if(r&&("allow-with-description"!==t||!n.value.includes("--"))){let o="allow-with-description"===t?"require-description":"do-not-use";e.report({node:n,data:{directive:r},messageId:o})}let o=function(e){let t=g.exec(e.trim());return t?t.groups?.ruleId:h}(n.value);o===h||o||e.report({node:n,messageId:"require-specific-rule"})}}}});let v=o(new n({configType:"eslintrc"}).getRules().get("no-return-await"),"[eslint-plugin-sukka] no-return-await rule is removed from ESLint!");var b=e({...v,meta:{docs:{...v.meta?.docs,recommended:void 0},...v.meta,deprecated:!1}}),x=e({name:"no-expression-empty-lines",meta:{messages:{unexpectedEmptyLine:"Unexpected empty line before"},docs:{description:"Disallows empty lines inside expressions."},fixable:"whitespace",type:"suggestion",schema:[]},create(e){let t=e.sourceCode.getText(),r=s(t);return{MemberExpression(n){let o=n.object.range[1],s=S(t.slice(o));if(s.includes("\n")){var i;let t=r+((S(i=s).split(/\r\n|\n/u).at(-1)??"")+i.trimStart());s!==t&&e.report({fix:()=>({range:[o,o+s.length],text:t}),messageId:"unexpectedEmptyLine",node:n.property})}}}}});function S(e){return e.slice(0,e.length-e.trimStart().length)}var w=e({name:"object-format",meta:{fixable:"whitespace",schema:[{type:"object",properties:{maxLineLength:{type:"number",default:80},maxObjectSize:{type:"number",default:3}},additionalProperties:!1}],docs:{description:"Requires multiline or single-line object format.",recommended:"stylistic"},messages:{preferMultiline:"Prefer multiline object literal",preferSingleLine:"Prefer single-line object literal"},type:"layout"},create(e,t={}){var r;let n=e.sourceCode.getText(),o=s(n),i=`,${o}`,{maxLineLength:a=80,maxObjectSize:l=3}=t,c=(r=n,e=>r.slice(e.range[1]).trimStart().startsWith("//"));return{ObjectExpression(t){let r=t.properties.map(t=>n.slice(Math.min(t.range[0],...e.sourceCode.getCommentsBefore(t).map(e=>e.range[0])),t.range[1]).trim());if(r.length>0){var s;let p,u,d,m,f=e.sourceCode.getText(t),g=r.length>l||r.some(E)||t.properties.some(c),h=E(f),y=!f.includes("\n");g&&y&&e.report({fix:()=>({range:t.range,text:`{${o}${r.join(i)}${o}}`}),messageId:"preferMultiline",node:t}),!g&&h&&(p=e.sourceCode.getLocFromIndex(t.range[0]),u=r.reduce((e,t)=>e+t.length,0),d=2*(r.length-1),m=("number"==typeof(s=t.range[1])?n.slice(s):n.slice(...s.range)).split(/\r\n|\n/u)[0].replace(/^((?: as const)?\S*).*/u,"$1").length,p.column+u+d+4+m<=a)&&e.report({fix:()=>({range:t.range,text:`{${r.join(",")}}`}),messageId:"preferSingleLine",node:t})}}}}});function E(e){return e.includes("\n")}var k=e({name:"prefer-single-boolean-return",meta:{messages:{replaceIfThenElseByReturn:"Replace this if-then-else flow by a single return statement.",suggest:"Replace with single return statement",suggestCast:'Replace with single return statement using "!!" cast',suggestBoolean:"Replace with single return statement without cast (condition should be boolean!)"},schema:[],type:"suggestion",hasSuggestions:!0,docs:{description:'Return of boolean expressions should not be wrapped into an "if-then-else" statement',recommended:"recommended"}},create:e=>({IfStatement(t){var r,n,o;let s,a,l,c;t.parent.type!==i.IfStatement&&C(t.consequent)&&function(e){if(e.alternate)return C(e.alternate);let{parent:t}=e;if(t.type===i.BlockStatement){let r=t.body.indexOf(e);return T(t.body[r+1])}return!1}(t)&&e.report({messageId:"replaceIfThenElseByReturn",node:t,suggest:(r=t,s=e=>t=>{let n=`return ${e};`;if(r.alternate)return t.replaceText(r,n);let o=r.parent,s=o.body.indexOf(r),i=o.body[s+1],a=[r.range[0],i.range[1]];return t.replaceTextRange(a,n)},a=!1===((n=r.consequent).type===i.BlockStatement?n.body[0]:n).argument.value,l=!(((o=r.test).type===i.UnaryExpression||o.type===i.BinaryExpression)&&["!","==","===","!=","!==","<","<=",">",">=","in","instanceof"].includes(o.operator)),c=e.sourceCode.getText(r.test),a?[{messageId:"suggest",fix:s(`!(${c})`)}]:l?[{messageId:"suggestCast",fix:s(`!!(${c})`)},{messageId:"suggestBoolean",fix:s(c)}]:[{messageId:"suggest",fix:s(c)}])})}})});function T(e){return e?.type===i.ReturnStatement&&e.argument?.type===i.Literal&&"boolean"==typeof e.argument.value}function C(e){return void 0!==e&&(e.type===i.BlockStatement&&1===e.body.length&&T(e.body[0])||T(e))}function I(e,t,r){var n,o;return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>I(e,t[n],r)):!(Array.isArray(e)||Array.isArray(t))&&e.type===t.type&&(n=r.getTokens(e),o=r.getTokens(t),n.length===o.length&&n.every((e,t)=>e.value===o[t].value))}function A(e){let t=!1;return{branches:e.cases.reduce((r,n,o)=>{var s;return n.test||(t=!0),(o===e.cases.length-1||n.consequent.length>0)&&r.push((s=n.consequent).length>0&&s[s.length-1].type===i.BreakStatement?s.slice(0,-1):s),r},[]),endsWithDefault:t}}e({name:"no-all-duplicated-branches",meta:{messages:{removeOrEditConditionalStructure:"Remove this conditional structure or edit its code blocks so that they're not all the same.",returnsTheSameValue:'This conditional operation returns the same value whether the condition is "true" or "false".'},schema:[],type:"problem",docs:{description:"All branches in a conditional structure should not have exactly the same implementation",recommended:"recommended"}},create(e){return{IfStatement(r){if(r.parent?.type!==i.IfStatement){let{branches:n,endsWithElse:o}=function(e){let t=[e.consequent],r=!1,n=e.alternate;for(;n;)if(n.type===i.IfStatement)t.push(n.consequent),n=n.alternate;else{t.push(n),r=!0;break}return{branches:t,endsWithElse:r}}(r);o&&t(n)&&e.report({messageId:"removeOrEditConditionalStructure",node:r})}},SwitchStatement(r){let{branches:n,endsWithDefault:o}=A(r);o&&t(n)&&e.report({messageId:"removeOrEditConditionalStructure",node:r})},ConditionalExpression(r){t([r.consequent,r.alternate])&&e.report({messageId:"returnsTheSameValue",node:r})}};function t(t){return t.length>1&&t.slice(1).every((r,n)=>I(r,t[n],e.sourceCode))}}});var j=e({name:"no-duplicated-branches",meta:{schema:[],type:"suggestion",docs:{description:"Two branches in a conditional structure should not have exactly the same implementation",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1871/javascript"},messages:{sameConditionalBlock:"This {{type}}'s code block is the same as the block for the {{type}} on line {{line}}."}},create(e){return{IfStatement(o){!function(o){if(o.parent.type===i.IfStatement)return;let{branches:s,endsWithElse:a}=function(e){let t=[e.consequent],r=!1,n=e.alternate;for(;n;)if(n.type===i.IfStatement)t.push(n.consequent),n=n.alternate;else{t.push(n),r=!0;break}return{branches:t,endsWithElse:r}}(o);if(r(s,a))return s.slice(1).forEach((e,t)=>n(e,s[t],"branch"));for(let r=1;r<s.length;r++)if(t([s[r]]))for(let t=0;t<r&&!function(t,r){let o=D(t,r,e.sourceCode);return o&&"loc"in r&&n(t,r,"branch"),o}(s[r],s[t]);t++);}(o)},SwitchStatement(o){!function(o){let{cases:s}=o,{endsWithDefault:i}=A(o),a=s.filter(e=>R(M(e.consequent)).length>0);if(r(a.map(e=>R(M(e.consequent))),i))return a.slice(1).forEach((e,t)=>n(e,a[t],"case"));for(let r=1;r<s.length;r++){let o=R(M(s[r].consequent));if(t(o)){for(let t=0;t<r;t++)if(D(o,R(M(s[t].consequent)),e.sourceCode)){n(s[r],s[t],"case");break}}}}(o)}};function t(t){if(t.length>0){let r=[...e.sourceCode.getTokens(t[0]),...e.sourceCode.getTokens(t[t.length-1])].filter(e=>"{"!==e.value&&"}"!==e.value);return r.length>0&&r[r.length-1].loc.end.line>r[0].loc.start.line}return!1}function r(t,r){return!r&&t.length>1&&t.slice(1).every((r,n)=>D(r,t[n],e.sourceCode))}function n(t,r,n){let o=r.loc;e.report({messageId:"sameConditionalBlock",data:{type:n,line:String(o.start.line)},node:t})}}});function M(e){if(1===e.length){let t=e[0];if(t.type===i.BlockStatement)return t.body}return e}function D(e,t,r){var n,o;return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>D(e,t[n],r)):!(Array.isArray(e)||Array.isArray(t))&&e.type===t.type&&(n=r.getTokens(e),o=r.getTokens(t),n.length===o.length&&n.every((e,t)=>e.value===o[t].value))}function R(e){return e.length>0&&e[e.length-1].type===i.BreakStatement?e.slice(0,-1):e}var L=e({name:"comma-or-logical-or-case",meta:{type:"problem",docs:{description:"Comma and logical OR operators should not be used in switch cases",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3616/javascript"},schema:[],messages:{specifyCase:'Explicitly specify {{nesting}} separate cases that fall through; currently this case clause only works for "{{expression}}".'}},create(e){function t(t,r,n){var o;e.report({messageId:"specifyCase",data:{nesting:n.toString(),expression:String((o=r).type===i.Literal?o.value:e.sourceCode.getText(o))},node:t})}return{"SwitchCase > SequenceExpression":function(e){let r=e.expressions;t(e,r[r.length-1],r.length)},"SwitchCase > LogicalExpression":function(r){var n;if((n=function(t){let r=e.sourceCode.getAncestors(t);for(let e=r.length-1;e>=0;e--)if(r[e].type===i.SwitchStatement)return r[e];throw Error("A switch case should have an enclosing switch statement")}(r)).discriminant.type!==i.Literal||!0!==n.discriminant.value){let e=function e(t,r){if("||"===t.operator)return t.left.type===i.LogicalExpression?e(t.left,r+1):[t.left,r+1]}(r,0);e&&t(r,e[0],e[1]+1)}}}}}),O=e({name:"no-element-overwrite",meta:{schema:[],type:"problem",docs:{description:"Collection elements should not be replaced unconditionally",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4143/javascript"},messages:{verifyIntendedIndex:'Verify this is the index that was intended; "{{index}}" was already set on line {{line}}.'}},create(e){return{SwitchCase(e){t(e.consequent)},BlockStatement(e){t(e.body)},Program(e){t(e.body.filter(e=>{var t;return!((t=e)&&(t.type===i.ImportDeclaration||t.type===i.ExportNamedDeclaration||t.type===i.ExportDefaultDeclaration||t.type===i.ExportAllDeclaration))}))}};function t(t){let r,n=new Map;t.forEach(t=>{let o=function(t){if(t.type===i.ExpressionStatement)return function(t){var r,n,o;if((r=t).type===i.AssignmentExpression&&"="===r.operator&&t.left.type===i.MemberExpression&&t.left.computed){let r,s,{left:i,right:a}=t,l=q(i.property);if(void 0!==l&&(n=i.object,o=a,r=e.sourceCode.getTokens(n),void 0===(s=e.sourceCode.getTokens(o)).find((e,t)=>{if(P(e,r[0]))for(let e=t,n=0;e<s.length&&n<r.length;e++,n++)if(P(s[e],r[n])){if(n===r.length-1)return!0}else break;return!1})))return{collectionNode:i.object,indexOrKey:l,node:t}}}(t.expression)||function(e){if(e.type===i.CallExpression&&e.callee.type===i.MemberExpression){let t=e.callee;if(t.property.type===i.Identifier){let r=t.property.name,n="add"===r&&1===e.arguments.length,o="set"===r&&2===e.arguments.length;if(n||o){let r=q(e.arguments[0]);if(r)return{collectionNode:t.object,indexOrKey:r,node:e}}}}}(t.expression)}(t);if(o){r&&!I(o.collectionNode,r,e.sourceCode)&&n.clear();let t=n.get(o.indexOrKey);t?.node.loc&&e.report({node:o.node,messageId:"verifyIntendedIndex",data:{index:o.indexOrKey,line:t.node.loc.start.line}}),n.set(o.indexOrKey,o),r=o.collectionNode}else n.clear()})}}});function P(e,t){return e.value===t.value}function q(e){if(e.type===i.Literal){let{value:t}=e;return"number"==typeof t||"string"==typeof t?String(t):void 0}if(e.type===i.Identifier)return e.name}var F=e({name:"class-prototype",meta:{schema:[],type:"suggestion",docs:{description:'Class methods should be used instead of "prototype" assignments',recommended:"recommended"},messages:{declareClass:'Declare a "{{class}}" class and move this declaration of "{{declaration}}" into it.'}},create(e){let r=e.sourceCode.parserServices,n=t(r)?B:V;return{AssignmentExpression({left:t,right:o}){if(t.type===i.MemberExpression&&n(o,r)){let[r,n]=[t.object,t.property];if(r.type===i.MemberExpression&&n.type===i.Identifier){let[o,s]=[r.object,r.property];o.type===i.Identifier&&s.type===i.Identifier&&"prototype"===s.name&&e.report({messageId:"declareClass",data:{class:o.name,declaration:n.name},node:t})}}}}}});function B(e,t){r(t);let n=t.program.getTypeChecker().getTypeAtLocation(t.esTreeNodeToTSNodeMap.get(e));return!!n.symbol&&(n.symbol.flags&c.Function)!=0}let U=new Set(["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression"]);function V(e){return U.has(e.type)}var N=e({name:"bool-param-default",meta:{schema:[],type:"suggestion",docs:{description:"Optional boolean parameters should have default value"},messages:{provideDefault:"Provide a default value for '{{parameter}}' so that the logic of the function is more evident when this parameter is missing. Consider defining another function if providing default value is not possible."}},create:e=>({"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression":t=>{for(let r of t.params)r.type===i.Identifier&&function(e){var t;return(t=e).optional&&!!t.typeAnnotation&&t.typeAnnotation.typeAnnotation.type===i.TSBooleanKeyword||function(e){if(e.typeAnnotation&&e.typeAnnotation.typeAnnotation.type===i.TSUnionType){let t=e.typeAnnotation.typeAnnotation.types;return 2===t.length&&t.some(e=>e.type===i.TSBooleanKeyword)&&t.some(e=>e.type===i.TSUndefinedKeyword)}return!1}(e)}(r)&&e.report({messageId:"provideDefault",data:{parameter:r.name},node:r})}})}),W=e({name:"call-argument-line",meta:{type:"suggestion",docs:{description:"Function call arguments should not start on new lines",recommended:"recommended"},schema:[],messages:{moveArguments:"Make those call arguments start on line {{line}}.",moveTemplateLiteral:"Make this template literal start on line {{line}}."}},create(e){let t=e.sourceCode;return{CallExpression(r){if(r.callee.type!==i.CallExpression&&1===r.arguments.length){var n;let o=(n=r).typeArguments??n.callee,s=(t.getLastTokenBetween(o,r.arguments[0],$)??t.getLastToken(o)).loc.end.line,{start:i}=t.getTokenAfter(o,z).loc;if(s!==i.line){let{end:n}=t.getLastToken(r).loc;n.line===i.line?e.report({messageId:"moveArguments",data:{line:s.toString()},loc:{start:i,end:n}}):e.report({messageId:"moveArguments",data:{line:s.toString()},loc:i})}}},TaggedTemplateExpression(r){let{quasi:n}=r,o=t.getTokenBefore(n);if(o&&n.loc&&o.loc.end.line!==n.loc.start.line){let t={start:n.loc.start,end:{line:n.loc.start.line,column:n.loc.start.column+1}};e.report({messageId:"moveTemplateLiteral",data:{line:o.loc.start.line.toString()},loc:t})}}}}});function $(e){return e.type===a.Punctuator&&")"===e.value}function z(e){return!$(e)}var K=e({name:"track-todo-fixme-comment",meta:{type:"suggestion",docs:{description:'Track uses of "FIXME" and "TODO" tags',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1134/javascript"},schema:[],messages:{fixme:"Take the required action to fix the issue indicated by this comment.",todo:'Complete the task associated to this "TODO" comment.'}},create(e){function t(t,r){e.sourceCode.getAllComments().forEach(n=>{let o=n.value.toLowerCase();if(o.includes(t)){let s=o.split(/\r\n?|\n/);for(let o=0;o<s.length;o++){let i=s[o].indexOf(t);i>=0&&!function(e,t,r){let n=t+r.length,o=t>0&&_.test(e.charAt(t-1)),s=n<=e.length-1&&_.test(e.charAt(n));return o||s}(s[o],i,t)&&e.report({messageId:r,loc:function(e,t,r,n){let o=r.loc.start.line+e,s=(0===e?r.loc.start.column+2:0)+t;return{start:{line:o,column:s},end:{line:o,column:s+n.length}}}(o,i,n,t)})}}})}return{"Program:exit":()=>{t("fixme","fixme"),t("todo","todo")}}}});let _=/\p{Letter}/u,G=["Array","Map","Set","WeakSet","WeakMap"],X=new Set(["copyWithin","pop","reverse","shift","sort","clear","delete","concat","flat","flatMap","includes","indexOf","join","lastIndexOf","slice","toSource","toString","toLocaleString","get","has","entries","every","filter","find","findIndex","forEach","keys","map","reduce","reduceRight","some","values"]);var Y=e({name:"no-empty-collection",meta:{schema:[],type:"problem",docs:{description:"Empty collections should not be accessed or iterated",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4158/javascript"},messages:{reviewUsageOfIdentifier:'Review this usage of "{{identifierName}}" as it can only be empty here.'}},create(e){let t=t=>{if(t.references.length<=1||t.defs.some(e=>e.type===d.Scope.DefinitionType.Parameter||e.type===d.Scope.DefinitionType.ImportBinding))return;let r=[],n=!1;for(let e of t.references)if(e.isWriteOnly())if(!function(e){let t=H(e.identifier,e=>e.type===i.VariableDeclarator||e.type===i.ExpressionStatement);if(t){if(t.type===i.VariableDeclarator&&t.init)return Z(t.init);if(t.type===i.ExpressionStatement){let{expression:r}=t;return r.type===i.AssignmentExpression&&Q(e,r.left)&&Z(r.right)}}return!1}(e))return;else n=!0;else{var o;if(!(function(e){let{parent:t}=e.identifier;if(t&&t.type===i.MemberExpression){let e=t.parent;if(e&&e.type===i.CallExpression)return ee(t.property,...X)}return!1}(o=e)||function(e){let t=H(e.identifier,e=>e.type===i.ForOfStatement||e.type===i.ForInStatement);return t?.right===e.identifier}(o)||function(e){let{parent:t}=e.identifier;return t&&t.type===i.MemberExpression&&t.computed&&!function(e){let t=J(e,new Set),r=t.find(e=>e.type===i.AssignmentExpression);return r?.operator==="="&&[e,...t].includes(r.left)}(t)}(o)))return;r.push(e)}n&&r.forEach(t=>{e.report({messageId:"reviewUsageOfIdentifier",data:{identifierName:t.identifier.name},node:t.identifier})})},r=e=>{e.type!==d.Scope.ScopeType.global&&e.variables.forEach(t),e.childScopes.forEach(r)};return{"Program:exit":t=>{r(e.sourceCode.getScope(t))}}}});function H(e,t){return J(e,new Set).find(t)}function J(e,t){let r=[],n=e.parent;for(;n&&(r.push(n),!t.has(n.type));)n=n.parent;return r}function Q(e,t){return t.type===i.Identifier&&t===e.identifier}function Z(e){return e&&e.type===i.ArrayExpression?0===e.elements.length:!!e&&(e.type===i.CallExpression||e.type===i.NewExpression)&&ee(e.callee,...G)&&0===e.arguments.length}function ee(e,...t){return e?.type===i.Identifier&&(0===t.length||t.some(t=>t===e.name))}let et=new Set(["!=","==","!==","==="]),er=new Set(["!==","!="]),en=new Set(["+=","-="]);var eo=e({name:"no-equals-in-for-termination",meta:{schema:[],messages:{replaceOperator:"Replace '{{operator}}' operator with one of '<=', '>=', '<', or '>' comparison operators."},type:"suggestion",docs:{description:'Equality operators should not be used in "for" loop termination conditions',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S888/javascript"}},create(e){function t(t,r){if(t.type===i.Identifier){var n;let o=(n=t.name,function(e,t){let r;for(;null==r&&null!=e;)r=e.variables.find(e=>e.name===t),e=e.upper;return r}(e.sourceCode.getScope(t),n)),s=r.range;if(o&&s)return o.references.some(e=>{var t,r;return t=e.identifier,r=s,t.range&&t.range[0]>r[0]&&t.range[1]<r[1]})}return!1}return{ForStatement(r){var n,o;let s,a;if(!r.test||!r.update)return;let l=r.test;(n=l).type===i.BinaryExpression&&et.has(n.operator)&&function e(t){return!!es(t)||t.type===i.UpdateExpression||t.type===i.SequenceExpression&&t.expressions.every(e)}(r.update)&&(s=(o=r).test,a=[],function e(t,r){let n;es(t)?n=t.left:t.type===i.UpdateExpression?n=t.argument:t.type===i.SequenceExpression&&t.expressions.forEach(t=>e(t,r)),n&&n.type===i.Identifier&&r.push(n.name)}(o.update,a),!(s.left.type!==i.Identifier||!a.includes(s.left.name)||function(e){let r=e.init,n=e.test;if(r&&ei(n)){let o=function(e,r){var n,o;if(n=e,o=r,n.type===i.UpdateExpression&&!t(n.argument,o)||function(e){if(es(e)){let t=e.right;return t.type===i.Literal&&1===t.value}return!1}(n)&&!t(n.left,o)){if("++"===e.operator||"+="===e.operator)return 1;if("--"===e.operator||"-="===e.operator)return -1}return 0}(e.update,e.body);if(0!==o){let e=ea(r),t=ea(n);return void 0!==e&&void 0!==t&&o===Math.sign(t-e)}}return!1}(r)))&&e.report({messageId:"replaceOperator",data:{operator:l.operator},node:l})}}}});function es(e){return e.type===i.AssignmentExpression&&en.has(e.operator)}function ei(e){return e.type===i.BinaryExpression&&er.has(e.operator)}function ea(e){var t;return ei(e)?el(e.right):(t=e).type===i.VariableDeclaration&&1===t.declarations.length?el(e.declarations[0].init):e.type===i.AssignmentExpression?el(e.right):void 0}function el(e){if(e&&e.type===i.Literal&&"number"==typeof e.value)return e.value}var ec=e({name:"no-top-level-this",meta:{hasSuggestions:!0,schema:[],messages:{removeThis:'Remove the use of "this".',suggestRemoveThis:'Remove "this"',suggestUseGlobalThis:'Replace "this" with "globalThis" object'},type:"suggestion",docs:{description:'The global "this" object should not be used',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S2990/javascript"},fixable:"code"},create:e=>({'MemberExpression[object.type="ThisExpression"]':t=>{let r=e.sourceCode.getScope(t).variableScope.type,n=e.sourceCode.getAncestors(t).some(e=>e.type===i.ClassDeclaration||e.type===i.ClassExpression);if((r===d.Scope.ScopeType.global||r===d.Scope.ScopeType.module)&&!n){let r=[];if(!t.computed){let n=e.sourceCode.getText(t.property);r.push({messageId:"suggestRemoveThis",fix:e=>e.replaceText(t,n)},{messageId:"suggestUseGlobalThis",fix:e=>e.replaceText(t.object,"globalThis")})}e.report({messageId:"removeThis",node:t.object,suggest:r})}}})}),ep=e({name:"no-invariant-returns",meta:{schema:[],type:"suggestion",docs:{description:"Function returns should not be invariant",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3516/javascript",requiresTypeChecking:!1},messages:{refactorReturn:"Refactor this function to only return once or not always return the same value."}},create(e){let t=[],r=[],n=[],o=r=>{var o,s,a;return o=r,void(!(s=t[t.length-1])||(a=s,n.some(e=>e.reachable)||a.containsReturnWithoutValue||a.returnStatements.length<=1||a.codePath.thrownSegments.length>0)||function(e,t){let r=e[0],n=r?em(r,t):void 0;if(void 0!==n)return e.slice(1).every(e=>em(e,t)===n);if(r?.type===i.Identifier){let n=eu(r.name,t);if(n){let t=new Set(n.variable.references.slice(1).map(e=>e.identifier));return e.every(e=>t.has(e))}}return!1}(s.returnStatements.map(e=>e.argument),e.sourceCode.getScope(o))&&e.report({messageId:"refactorReturn",node:o}))};return{onCodePathStart(e){t.push({codePath:e,containsReturnWithoutValue:!1,returnStatements:[]}),r.push(n),n=[]},onCodePathEnd(){t.pop(),n=r.pop()||[]},onCodePathSegmentStart(e){n.push(e)},onCodePathSegmentEnd(){n.pop()},ReturnStatement(e){if(t.length){let r=t[t.length-1];r.containsReturnWithoutValue=r.containsReturnWithoutValue||!e.argument,r.returnStatements.push(e)}},"FunctionDeclaration:exit":o,"FunctionExpression:exit":o,"ArrowFunctionExpression:exit":o}}});function eu(e,t){let r=t.set.get(e);if(r&&!r.references.slice(1).some(e=>{var t;let r;return e.isWrite()||(r=H((t=e).identifier,e=>e.type===i.ExpressionStatement||V(e)))&&r.type===i.ExpressionStatement&&(ed(r,t)||r.expression.type===i.CallExpression)})){let e=null;return 1===r.defs.length&&r.defs[0].type===d.Scope.DefinitionType.Variable&&(e=r.defs[0].node.init),{variable:r,initExpression:e}}return null}function ed(e,t,r=!0){return e.expression.type===i.AssignmentExpression&&function e(t,r,n=!0){return t.type===i.MemberExpression&&(Q(r,t.object)||n&&e(t.object,r,n))}(e.expression.left,t,r)}function em(e,t){if(e){if(e.type===i.Literal)return e.value;if(e.type===i.UnaryExpression){let r=em(e.argument,t);return void 0===r?void 0:function(e,t){switch(e){case"-":return-Number(t);case"+":return Number(t);case"~":return~Number(t);case"!":return!t;case"typeof":return typeof t}}(e.operator,r)}if(e.type===i.Identifier){let r=eu(e.name,t);if(r?.initExpression)return em(r.initExpression,t)}}}function ef(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function eg(e,t){let r=t.variables.find(t=>t.name===e.name);return!r&&t.upper&&(r=t.upper.variables.find(t=>t.name===e.name)),r}class eh extends Set{constructor(...e){super(...e),ef(this,"type","AssignedValues")}}let ey={type:"UnknownValue"};class ev{add(e){e.resolved&&this.references.add(e)}propagate(e){this.in.clear(),this.segment.prevSegments.forEach(t=>{this.join(e.get(t.id).out)});let t=new Map;return this.references.forEach(e=>this.updateProgramState(e,t)),!function(e,t){if(e.size!==t.size)return!1;for(let[o,s]of e){var r,n;if(!t.has(o)||(r=t.get(o),n=s,"AssignedValues"===r.type&&"AssignedValues"===n.type?!function(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}(r,n):r!==n))return!1}return!0}(this.out,t)&&(this.out=t,!0)}updateProgramState(e,t){let r=e.resolved;if(!r||!e.isWrite())return;if(!e.writeExpr)return void t.set(r,ey);let n=eb(r,e.writeExpr,t,e.from);t.set(r,n)}join(e){for(let[t,r]of e.entries()){let e=this.in.get(t)??new eh;"AssignedValues"===e.type&&"AssignedValues"===r.type?(r.forEach(t=>e.add(t)),this.in.set(t,e)):this.in.set(t,ey)}}constructor(e){ef(this,"segment",void 0),ef(this,"in",void 0),ef(this,"out",void 0),ef(this,"references",void 0),this.segment=e,this.in=new Map,this.out=new Map,this.references=new Set}}function eb(e,t,r,n){if(!t)return ey;switch(t.type){case i.Literal:return t.raw?new eh([t.raw]):ey;case i.Identifier:{let o=eg(t,n);if(o&&o!==e)return r.get(o)??ey;return ey}default:return ey}}class ex{constructor(e){ef(this,"codePath",void 0),ef(this,"reachingDefinitionsMap",void 0),ef(this,"reachingDefinitionsStack",void 0),ef(this,"segments",void 0),ef(this,"assignmentStack",void 0),this.codePath=e,this.reachingDefinitionsMap=new Map,this.reachingDefinitionsStack=[],this.segments=new Map,this.assignmentStack=[]}}class eS{isRhs(e){return this.node.type===i.AssignmentExpression?this.node.right===e:this.node.init===e}isLhs(e){return this.node.type===i.AssignmentExpression?this.node.left===e:this.node.id===e}add(e){let t=e.identifier;for(;t;){if(this.isLhs(t)){this.lhs.add(e);break}if(this.isRhs(t)){this.rhs.add(e);break}t=t.parent}}constructor(e){ef(this,"node",void 0),ef(this,"lhs",void 0),ef(this,"rhs",void 0),this.node=e,this.lhs=new Set,this.rhs=new Set}}function ew(e){return e[e.length-1]}var eE=e({name:"no-redundant-assignments",meta:{schema:[],type:"suggestion",docs:{description:"Assignments should not be redundant",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4165/javascript"},messages:{reviewAssignment:'Review this redundant assignment: "{{symbol}}" already holds the assigned value along all execution paths.'}},create(e){let t=[],r=new Map,n=new Map,o=[],s=[];return{AssignmentExpression:l,"VariableDeclarator[init]":l,"AssignmentExpression:exit":a,"VariableDeclarator[init]:exit":a,Identifier(r){var o;r.parent.type===i.TSEnumBody||r.parent.type===i.TSEnumDeclaration||r.parent.type===i.TSEnumMember||(o=r,e.sourceCode.getAncestors(o).some(e=>e.type===i.TSEnumDeclaration)||function(r){var o;let{ref:s,variable:i}=function e(t,r){if(null===r)return{ref:null,variable:null};let n=r.references.find(e=>e.identifier===t);if(n)return{ref:n,variable:n.resolved};let o=r.variables.find(e=>e.defs.find(e=>e.name===t));return o?{ref:null,variable:o}:e(t,r.upper)}(o=r,e.sourceCode.getScope(o));if(s&&p(s),i){let e=ew(t).codePath.id;n.has(i)?n.get(i).add(e):n.set(i,new Set([e]))}}(r))},"Program:exit":()=>{let e=Array.from(r.values(),e=>e.segment);for(;e.length;){let t=e.pop();r.get(t.id).propagate(r)&&t.nextSegments.forEach(t=>e.push(t))}r.forEach(c),r.clear(),n.clear(),t.length=0},onCodePathSegmentStart(e){r.set(e.id,new ev(e)),s.push(e)},onCodePathStart(e){var r;r=new ex(e),t.push(r),o.push(s),s.length=0},onCodePathEnd(){t.pop(),o.pop()||(s.length=0)},onCodePathSegmentEnd(){s.pop()}};function a(){let e=ew(t).assignmentStack.pop();e.rhs.forEach(p),e.lhs.forEach(p)}function l(e){ew(t).assignmentStack.push(new eS(e))}function c(t){let r=new Map(t.in);t.references.forEach(t=>{let o=t.resolved;if(!o||!t.isWrite()||!function(e){var t;let r=e.resolved;return r&&(e.identifier.type!==i.Identifier||e.identifier.parent.type!==i.AssignmentPattern)&&!r.name.startsWith("_")&&!function(e){if(e?.parent){let t=e.parent;return t&&t.type===i.AssignmentExpression&&"="!==t.operator}return!1}(e.writeExpr)&&(e.writeExpr?.type!==i.Identifier||e.resolved!==eg(e.writeExpr,e.from))&&!r.defs.some(e=>e.type===d.Scope.DefinitionType.Parameter||e.type===d.Scope.DefinitionType.Variable&&!e.node.init)&&(t=r,!(n.get(t).size>1))}(t))return;let s=r.get(o),a=eb(o,t.writeExpr,r,t.from);if(s?.type==="AssignedValues"&&1===s.size){let[r]=[...s];!function({resolved:t},r,n,o,s){if("UnknownValue"===o.type||1!==o.size)return;let[i]=[...o];t&&1!==t.references.filter(e=>e.isWrite()).length&&n===i&&e.report({node:r,messageId:"reviewAssignment",data:{symbol:s}})}(t,t.writeExpr,r,a,o.name)}r.set(o,a)})}function p(e){let{assignmentStack:n}=ew(t);if(n.length>0)ew(n).add(e);else for(let t=0,n=s.length;t<n;t++)(function(e){let t;return r.has(e.id)?t=r.get(e.id):(t=new ev(e),r.set(e.id,t)),t})(s[t]).add(e)}}}),ek=e({name:"no-same-line-conditional",meta:{schema:[],type:"layout",docs:{description:"Conditionals should start on new lines",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3972/javascript"},fixable:"whitespace",messages:{sameLineCondition:'Move this "if" to a new line or add the missing "else".'}},create(e){function t(t){var r;let{sourceCode:n}=e;(r=t).reduce((e,t,n)=>{let o=r[n-1];return t.type===i.IfStatement&&o&&o.type===i.IfStatement?[{first:o,following:t},...e]:e},[]).forEach(t=>{let r=t.first,o=t.following;if(r.loc&&o.loc&&r.loc.end.line===o.loc.start.line&&r.loc.start.line!==o.loc.end.line){let t=n.getFirstToken(o);e.report({messageId:"sameLineCondition",loc:t.loc,fix:e=>e.replaceTextRange([r.range[1],o.range[0]],"\n"+" ".repeat(r.loc.start.column))})}})}return{Program:e=>t(e.body),BlockStatement:e=>t(e.body),SwitchCase:e=>t(e.consequent)}}}),eT=e({name:"no-small-switch",meta:{schema:[],messages:{replaceSwitch:'Replace this "switch" statement by "if" statements to increase readability.'},type:"suggestion",docs:{description:'"if" statements should be preferred over "switch" when simpler',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1301/javascript"}},create:e=>({SwitchStatement(t){let{cases:r}=t,n=r.some(e=>!e.test);if(r.length<2||2===r.length&&n){let r=e.sourceCode.getFirstToken(t);r&&e.report({messageId:"replaceSwitch",loc:r.loc})}}})});let eC=["Array","Map","Set","WeakSet","WeakMap"],eI=["copyWithin","fill","pop","push","reverse","set","shift","sort","splice","unshift","add","clear","delete"];var eA=e({name:"no-unused-collection",meta:{schema:[],messages:{unusedCollection:"Either use this collection's contents or remove the collection."},type:"suggestion",docs:{description:"Collection contents should be used",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4030/javascript",requiresTypeChecking:!1}},create:e=>({"Program:exit":t=>{let r=[];(function e(t,r){t.type!==d.Scope.ScopeType.global&&t.variables.forEach(e=>{(function(e){if(function(e){if(!e.defs.length)return;let t=e.defs[0];return t.node.parent?.parent?.type.startsWith("Export")}(e)||e.references.length<=1)return!1;let t=!1;for(let r of e.references)if(r.isWriteOnly())if(!function(e){let t=H(e.identifier,e=>e.type===i.VariableDeclarator||e.type===i.ExpressionStatement);if(t){if(t.type===i.VariableDeclarator&&t.init)return ej(t.init);if(t.type===i.ExpressionStatement){let{expression:r}=t;return r.type===i.AssignmentExpression&&Q(e,r.left)&&ej(r.right)}}return!1}(r))return!1;else t=!0;else if(function(e){let t=H(e.identifier,e=>e.type===i.ExpressionStatement);return!t||!ed(t,e,!1)&&!function(e,t){if(e.expression.type===i.CallExpression){let{callee:r}=e.expression;if(r.type===i.MemberExpression){let{property:e,object:n}=r;return Q(t,n)&&ee(e,...eI)}}return!1}(t,e)}(r))return!1;return t})(e)&&r.push(e)}),t.childScopes.forEach(t=>{e(t,r)})})(e.sourceCode.getScope(t),r),r.forEach(t=>{e.report({messageId:"unusedCollection",node:t.identifiers[0]})})}})});function ej(e){return!!e&&e.type===i.ArrayExpression||!!e&&(e.type===i.CallExpression||e.type===i.NewExpression)&&ee(e.callee,...eC)}var eM=e({name:"no-useless-plusplus",meta:{schema:[],type:"problem",docs:{description:"Values should not be uselessly incremented",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S2123/javascript"},messages:{removeIncrement:"Remove this {{updateOperator}}rement or correct the code not to waste it."}},create(e){function t(t){let r="++"===t.operator?"inc":"dec";e.report({messageId:"removeIncrement",data:{updateOperator:r},node:t})}return{"ReturnStatement > UpdateExpression":function(r){var n;let o=r.argument;!r.prefix&&o.type===i.Identifier&&(n=o,e.sourceCode.getScope(r).variables.some(e=>e.identifiers.some(e=>e.name===n.name)))&&t(r)},AssignmentExpression(e){let r=e.right;if(r.type===i.UpdateExpression&&!r.prefix){let n=e.left;n.type===i.Identifier&&r.argument.type===i.Identifier&&r.argument.name===n.name&&t(r)}}}}});let eD=new Set(["map","filter","reduce","reduceRight","forEach"]);var eR=e({name:"no-chain-array-higher-order-functions",meta:{type:"problem",fixable:"code",docs:{description:"Prefer `.reduce` over chaining `.filter`, `.map` methods",recommended:"recommended"},schema:[],messages:{detected:"Detected the chaining of array methods: {{methods}}. Reaplce with `.reduce` to reduce array iterations and improve the performance."}},create:e=>({MemberExpression(t){if(eL(t)){let r=t.parent;eL(r.parent)&&e.report({node:r,messageId:"detected",data:{methods:`arr.${t.property.name}().${r.parent.property.name}()`}})}}})});function eL(e){return e.type===i.MemberExpression&&!e.computed&&e.property.type===i.Identifier&&eD.has(e.property.name)&&e.parent.type===i.CallExpression}var eO=e({name:"no-export-const-enum",meta:{type:"suggestion",docs:{description:"Disallow using `const enum` expression as it can not be inlined and tree-shaken by swc/esbuild/babel/webpack/rollup/vite/bun/rspack"},messages:{noConstEnum:"Do not use `const enum` expression"},schema:[]},create(e){let t=(t,r)=>{let n=m.findVariable(e.sourceCode.getScope(t),r);n?.defs.forEach(r=>{r.node.type===i.TSEnumDeclaration&&r.node.const&&e.report({node:t,messageId:"noConstEnum"})})};return{ExportNamedDeclaration(r){let n=r.declaration;if(n?.type===i.TSEnumDeclaration&&n.const)return void e.report({node:r,messageId:"noConstEnum"});if(n?.type===i.VariableDeclaration){let e=n.declarations[0].id;e.type===i.Identifier&&t(r,e)}},ExportDefaultDeclaration(e){let r=e.declaration;r.type===i.Identifier&&t(e,r)}}}}),eP=e({name:"no-for-in-iterable",meta:{schema:[],type:"suggestion",docs:{description:'"for in" should not be used with iterables',recommended:"strict",url:"https://sonarsource.github.io/rspec/#/rspec/S4139/javascript"},messages:{useForOf:'Use "for...of" to iterate over this "{{iterable}}".'}},create(e){let t=e.sourceCode.parserServices;return{ForInStatement(n){var o,s;r(t);let i=eq(n.right,t);if(r(t),(o=i).symbol&&eF.has(o.symbol.name)||((s=i).flags&p.StringLike)>0||s.symbol?.name==="String"||function(e,t){var r,n=t.program.getTypeChecker().getBaseConstraintOfType(e)??e,o=t;for(let e of(r=n).isUnion()?r.types:[r])if(!function(e,t){let r=t.program.getTypeChecker();return"isArrayType"in r&&"function"==typeof r.isArrayType&&r.isArrayType(e)}(e,o))return!1;return!0}(i,t)){let t=i.symbol?i.symbol.name:"String";e.report({messageId:"useForOf",data:{iterable:t},loc:e.sourceCode.getFirstToken(n).loc})}}}}});function eq(e,t){return t.program.getTypeChecker().getTypeAtLocation(t.esTreeNodeToTSNodeMap.get(e))}let eF=new Set(["Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Set","Map"]);var eB=e({name:"only-await-thenable",meta:{schema:[],type:"suggestion",docs:{description:'"await" should only be used with promises',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4123/javascript"},messages:{refactorAwait:"Refactor this redundant 'await' on a non-promise."}},create(e){let t=e.sourceCode.parserServices;return r(t),{AwaitExpression(r){let n,o=eq(r.argument,t);(function(e,t){var r,n;if(e.argument.type!==i.CallExpression)return!1;let o=(r=e.argument,(n=t).program.getTypeChecker().getResolvedSignature(n.esTreeNodeToTSNodeMap.get(r)));return o?.declaration&&function(e){if(!e.jsDoc)return!1;for(let t of e.jsDoc)if(t.tags?.some(e=>eU.has(e.tagName.escapedText.toString())))return!0;return!1}(o.declaration)})(r,t)||(n=o.getProperty("then"),n?.declarations?.some(e=>e.kind===u.MethodSignature||e.kind===u.MethodDeclaration||e.kind===u.PropertyDeclaration))||o.flags&p.Any||o.flags&p.Unknown||o.flags&p.Union||e.report({messageId:"refactorAwait",node:r})}}}});let eU=new Set(["return","returns"]);var eV=e({name:"no-undefined-optional-parameters",meta:{schema:[],type:"suggestion",docs:{description:'"undefined" should not be passed as the value of optional parameters',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4623/javascript",requiresTypeChecking:!0},fixable:"code",hasSuggestions:!0,messages:{removeUndefined:'Remove this redundant "undefined".',suggestRemoveUndefined:"Remove this redundant argument"}},create(e){let t=e.sourceCode.parserServices;return r(t),{CallExpression(r){var n;let{arguments:o}=r;if(0===o.length)return;let s=o[o.length-1];(n=s).type===i.Identifier&&"undefined"===n.name&&function(e,t,r){let n=r.program.getTypeChecker().getResolvedSignature(r.esTreeNodeToTSNodeMap.get(t));if(n){var o;let t=n.declaration;if(t&&(o=t,eN.has(o.kind))){let{parameters:r}=t,n=r[e];return n&&(n.initializer||n.questionToken)}}return!1}(o.length-1,r,t)&&e.report({messageId:"removeUndefined",node:s,suggest:[{messageId:"suggestRemoveUndefined",fix(t){if(1===r.arguments.length){let n=e.sourceCode.getTokenAfter(r.callee),o=e.sourceCode.getLastToken(r),[,s]=n.range,[i]=o.range;return t.removeRange([s,i])}let[,n]=o[o.length-2].range,[,i]=s.range;return t.removeRange([n,i])}}]})}}}});let eN=new Set([u.FunctionDeclaration,u.FunctionExpression,u.ArrowFunction,u.MethodDeclaration,u.Constructor,u.GetAccessor,u.SetAccessor]);function eW(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class e${visit(e,t){let r=e=>{switch(e.type){case i.AwaitExpression:case i.CallExpression:case i.NewExpression:this.callLikeExpressions.push(e);break;case i.FunctionDeclaration:case i.FunctionExpression:case i.ArrowFunctionExpression:return}(function(e,t){let r=[],n=t[e.type];if(n?.length)for(let t of n){let n=e[t];Array.isArray(n)?r.push(...n):r.push(n)}return r.filter(Boolean)})(e,t.sourceCode.visitorKeys).forEach(r)};r(e)}constructor(){eW(this,"callLikeExpressions",[])}}eW(e$,"getCallExpressions",(e,t)=>{let r=new e$;return r.visit(e,t),r.callLikeExpressions});var ez=e({name:"no-try-promise",meta:{schema:[],type:"problem",docs:{description:'Promise rejections should not be caught by "try" blocks',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4822/javascript",requiresTypeChecking:!0},messages:{addAwait:"Consider using 'await' for the promise{{ending}} inside this 'try' or replace it with 'Promise.prototype.catch(...)' usage{{ending}}.",removeTry:"Consider removing this 'try' statement as promise{{ending}} rejection is already captured by '.catch()' method."}},create(e){let t=e.sourceCode.parserServices;return r(t),{TryStatement(r){if(r.handler){let n=[],o=[],s=!1;if(e$.getCallExpressions(r.block,e).forEach(e=>{var r,a,l,p,u,d;let m,f;if(e.type===i.AwaitExpression||(r=e,m=(a=t).esTreeNodeToTSNodeMap.get(r),!(f=a.program.getTypeChecker().getTypeAtLocation(m).getProperty("then"))||!(f.flags&c.Method))){s=!0;return}(l=e).parent&&(l.parent.type===i.AwaitExpression||l.parent.type===i.YieldExpression)||(p=e).parent&&p.parent.type===i.MemberExpression&&p.parent.property.type===i.Identifier&&"then"===p.parent.property.name||(u=e).type===i.CallExpression&&u.callee.type===i.MemberExpression&&u.callee.property.type===i.Identifier&&"catch"===u.callee.property.name||((d=e).parent&&d.parent.type===i.MemberExpression&&d.parent.property.type===i.Identifier&&"catch"===d.parent.property.name?o:n).push(e)}),!s){if(n.length>0){let t=n.length>1?"s":"",o=e.sourceCode.getFirstToken(r);e.report({messageId:"addAwait",data:{ending:t},loc:o.loc})}if(0===n.length&&o.length>0){let t=o.length>1?"s":"",n=e.sourceCode.getFirstToken(r);e.report({messageId:"removeTry",data:{ending:t},loc:n.loc})}}}}}}}),eK=e({name:"no-unthrown-error",meta:{schema:[],type:"problem",docs:{description:"Errors should not be created without being thrown",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3984/javascript",requiresTypeChecking:!1},fixable:"code",hasSuggestions:!0,messages:{throwOrRemoveError:"Throw this error or remove this useless statement.",suggestThrowError:"Throw this error"}},create:e=>({"ExpressionStatement > NewExpression":function(t){var r;let n;if(r=t.callee,(n=e.sourceCode.getText(r)).endsWith("Error")||n.endsWith("Exception")){let r,n=(r=e.sourceCode.getAncestors(t)).length>0?r[r.length-1]:void 0;e.report({messageId:"throwOrRemoveError",node:t,suggest:n?[{messageId:"suggestThrowError",fix:e=>e.insertTextBefore(n,"throw ")}]:[]})}}})}),e_=e({name:"no-useless-string-operation",meta:{schema:[],messages:{uselessStringOp:"{{symbol}} is an immutable object; you must either store or return the result of the operation."},type:"problem",docs:{description:"Results of operations on strings should not be ignored",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1154/javascript"}},create(e){let t=e.sourceCode.parserServices;return{'ExpressionStatement > CallExpression[callee.type="MemberExpression"]':n=>{let o,{object:s,property:a}=n.callee;r(t),(eq(s,t).flags&l.TypeFlags.StringLike)!=0&&a.type===i.Identifier&&e.report({messageId:"uselessStringOp",data:{symbol:((o=e.sourceCode.getText(s)).length>30&&(o="String"),o)},node:a})}}}});let eG={configs:{recommended:{name:"eslint-plugin-sukka/recommended",plugins:{get sukka(){return eG}},rules:{"sukka/ban-eslint-disable":["error","allow-with-description"],"sukka/bool-param-default":"error","sukka/call-argument-line":"error","sukka/class-prototype":"warn","sukka/comma-or-logical-or-case":"error","sukka/no-all-duplicated-branches":"error","sukka/no-chain-array-higher-order-functions":"error","sukka/no-duplicated-branches":"error","sukka/no-element-overwrite":"warn","sukka/no-empty-collection":"warn","sukka/no-equals-in-for-termination":"error","sukka/no-export-const-enum":"error","sukka/no-expression-empty-lines":"error","sukka/no-invariant-returns":"error","sukka/no-redundant-assignments":"warn","no-return-await":"off","sukka/no-return-await":"error","sukka/no-same-line-conditional":"error","sukka/no-small-switch":"error","sukka/no-top-level-this":"error","sukka/no-unthrown-error":"warn","sukka/no-unused-collection":"error","sukka/no-useless-plusplus":"error","sukka/object-format":"off","sukka/prefer-single-boolean-return":"error","sukka/track-todo-fixme-comment":"warn"}},recommended_extra_with_typed_lint:{name:"eslint-plugin-sukka/recommended_extra_with_typed_lint",plugins:{get sukka(){return eG}},rules:{"sukka/no-for-in-iterable":"error","sukka/no-try-promise":"error","sukka/no-undefined-optional-parameters":"warn","sukka/no-useless-string-operation":"warn","sukka/only-await-thenable":"off"}}},rules:{"ban-eslint-disable":y,"no-return-await":b,"no-expression-empty-lines":x,"object-format":w,"prefer-single-boolean-return":k,"no-all-duplicated-branches":j,"no-duplicated-branches":j,"bool-param-default":N,"call-argument-line":W,"class-prototype":F,"comma-or-logical-or-case":L,"track-todo-fixme-comment":K,"no-element-overwrite":O,"no-empty-collection":Y,"no-equals-in-for-termination":eo,"no-top-level-this":ec,"no-invariant-returns":ep,"no-redundant-assignments":eE,"no-same-line-conditional":ek,"no-small-switch":eT,"no-unused-collection":eA,"no-useless-plusplus":eM,"no-chain-array-higher-order-functions":eR,"no-export-const-enum":eO,"no-for-in-iterable":eP,"only-await-thenable":eB,"no-undefined-optional-parameters":eV,"no-try-promise":ez,"no-unthrown-error":eK,"no-useless-string-operation":e_}};export{eG as default};
1
+ import{createRule as e,isParserWithTypeInformation as t,ensureParserWithTypeInformation as r}from"@eslint-sukka/shared";import{Linter as n}from"eslint";import{nullthrow as o}from"foxts/guard";import{detectEol as s}from"foxts/detect-eol";import{AST_NODE_TYPES as i,AST_TOKEN_TYPES as a}from"@typescript-eslint/types";import*as l from"typescript";import{SymbolFlags as c,TypeFlags as p,SyntaxKind as u}from"typescript";import{TSESLint as d,ASTUtils as m}from"@typescript-eslint/utils";let f=/^\s*(?<directive>eslint-disable(?:-(?:next-)?line)?)/,g=/^eslint-disable(?:-next-line|-line)?(?<ruleId>$|(?:\s+(?:@(?:[\w-]+\/){1,2})?[\w-]+)?)/,h=Symbol("rule-id-no-match");var y=e({name:"ban-eslint-disable",meta:{type:"problem",docs:{description:"Ban `eslint-disable` comment directive"},schema:[{oneOf:[{type:"boolean"},{type:"string",enum:["allow-with-description"]}]}],messages:{"do-not-use":"Do not use `{{directive}}`","require-description":"Include a description after the `{{directive}}` directive to explain why the `{{directive}}` is necessary.","require-specific-rule":"Enforce specifying rules to disable in `eslint-disable` comments. If you want to disable ESLint on a file altogether, you should ignore it through ESLint configuration."}},create:(e,t="allow-with-description")=>!1===t?{}:{Program(r){if(r.comments&&0!==r.comments.length)for(let n of r.comments){let r=function(e){let t=f.exec(e);return t?.groups?.directive}(n.value);if(r&&("allow-with-description"!==t||!n.value.includes("--"))){let o="allow-with-description"===t?"require-description":"do-not-use";e.report({node:n,data:{directive:r},messageId:o})}let o=function(e){let t=g.exec(e.trim());return t?t.groups?.ruleId:h}(n.value);o===h||o||e.report({node:n,messageId:"require-specific-rule"})}}}});let v=o(new n({configType:"eslintrc"}).getRules().get("no-return-await"),"[eslint-plugin-sukka] no-return-await rule is removed from ESLint!");var b=e({...v,meta:{docs:{...v.meta?.docs,recommended:void 0},...v.meta,deprecated:!1}}),x=e({name:"no-expression-empty-lines",meta:{messages:{unexpectedEmptyLine:"Unexpected empty line before"},docs:{description:"Disallows empty lines inside expressions."},fixable:"whitespace",type:"suggestion",schema:[]},create(e){let t=e.sourceCode.getText(),r=s(t);return{MemberExpression(n){let o=n.object.range[1],s=S(t.slice(o));if(s.includes("\n")){var i;let t=r+((S(i=s).split(/\r\n|\n/u).at(-1)??"")+i.trimStart());s!==t&&e.report({fix:()=>({range:[o,o+s.length],text:t}),messageId:"unexpectedEmptyLine",node:n.property})}}}}});function S(e){return e.slice(0,e.length-e.trimStart().length)}var w=e({name:"object-format",meta:{fixable:"whitespace",schema:[{type:"object",properties:{maxLineLength:{type:"number",default:80},maxObjectSize:{type:"number",default:3}},additionalProperties:!1}],docs:{description:"Requires multiline or single-line object format.",recommended:"stylistic"},messages:{preferMultiline:"Prefer multiline object literal",preferSingleLine:"Prefer single-line object literal"},type:"layout"},create(e,t={}){var r;let n=e.sourceCode.getText(),o=s(n),i=`,${o}`,{maxLineLength:a=80,maxObjectSize:l=3}=t,c=(r=n,e=>r.slice(e.range[1]).trimStart().startsWith("//"));return{ObjectExpression(t){let r=t.properties.map(t=>n.slice(Math.min(t.range[0],...e.sourceCode.getCommentsBefore(t).map(e=>e.range[0])),t.range[1]).trim());if(r.length>0){var s;let p,u,d,m,f=e.sourceCode.getText(t),g=r.length>l||r.some(E)||t.properties.some(c),h=E(f),y=!f.includes("\n");g&&y&&e.report({fix:()=>({range:t.range,text:`{${o}${r.join(i)}${o}}`}),messageId:"preferMultiline",node:t}),!g&&h&&(p=e.sourceCode.getLocFromIndex(t.range[0]),u=r.reduce((e,t)=>e+t.length,0),d=2*(r.length-1),m=("number"==typeof(s=t.range[1])?n.slice(s):n.slice(...s.range)).split(/\r\n|\n/u)[0].replace(/^((?: as const)?\S*).*/u,"$1").length,p.column+u+d+4+m<=a)&&e.report({fix:()=>({range:t.range,text:`{${r.join(",")}}`}),messageId:"preferSingleLine",node:t})}}}}});function E(e){return e.includes("\n")}var k=e({name:"prefer-single-boolean-return",meta:{messages:{replaceIfThenElseByReturn:"Replace this if-then-else flow by a single return statement.",suggest:"Replace with single return statement",suggestCast:'Replace with single return statement using "!!" cast',suggestBoolean:"Replace with single return statement without cast (condition should be boolean!)"},schema:[],type:"suggestion",hasSuggestions:!0,docs:{description:'Return of boolean expressions should not be wrapped into an "if-then-else" statement',recommended:"recommended"}},create:e=>({IfStatement(t){var r,n,o;let s,a,l,c;t.parent.type!==i.IfStatement&&C(t.consequent)&&function(e){if(e.alternate)return C(e.alternate);let{parent:t}=e;if(t.type===i.BlockStatement){let r=t.body.indexOf(e);return T(t.body[r+1])}return!1}(t)&&e.report({messageId:"replaceIfThenElseByReturn",node:t,suggest:(r=t,s=e=>t=>{let n=`return ${e};`;if(r.alternate)return t.replaceText(r,n);let o=r.parent,s=o.body.indexOf(r),i=o.body[s+1],a=[r.range[0],i.range[1]];return t.replaceTextRange(a,n)},a=!1===((n=r.consequent).type===i.BlockStatement?n.body[0]:n).argument.value,l=!(((o=r.test).type===i.UnaryExpression||o.type===i.BinaryExpression)&&["!","==","===","!=","!==","<","<=",">",">=","in","instanceof"].includes(o.operator)),c=e.sourceCode.getText(r.test),a?[{messageId:"suggest",fix:s(`!(${c})`)}]:l?[{messageId:"suggestCast",fix:s(`!!(${c})`)},{messageId:"suggestBoolean",fix:s(c)}]:[{messageId:"suggest",fix:s(c)}])})}})});function T(e){return e?.type===i.ReturnStatement&&e.argument?.type===i.Literal&&"boolean"==typeof e.argument.value}function C(e){return void 0!==e&&(e.type===i.BlockStatement&&1===e.body.length&&T(e.body[0])||T(e))}function I(e,t,r){var n,o;return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>I(e,t[n],r)):!(Array.isArray(e)||Array.isArray(t))&&e.type===t.type&&(n=r.getTokens(e),o=r.getTokens(t),n.length===o.length&&n.every((e,t)=>e.value===o[t].value))}function A(e){let t=!1;return{branches:e.cases.reduce((r,n,o)=>{var s;return n.test||(t=!0),(o===e.cases.length-1||n.consequent.length>0)&&r.push((s=n.consequent).length>0&&s[s.length-1].type===i.BreakStatement?s.slice(0,-1):s),r},[]),endsWithDefault:t}}e({name:"no-all-duplicated-branches",meta:{messages:{removeOrEditConditionalStructure:"Remove this conditional structure or edit its code blocks so that they're not all the same.",returnsTheSameValue:'This conditional operation returns the same value whether the condition is "true" or "false".'},schema:[],type:"problem",docs:{description:"All branches in a conditional structure should not have exactly the same implementation",recommended:"recommended"}},create(e){return{IfStatement(r){if(r.parent?.type!==i.IfStatement){let{branches:n,endsWithElse:o}=function(e){let t=[e.consequent],r=!1,n=e.alternate;for(;n;)if(n.type===i.IfStatement)t.push(n.consequent),n=n.alternate;else{t.push(n),r=!0;break}return{branches:t,endsWithElse:r}}(r);o&&t(n)&&e.report({messageId:"removeOrEditConditionalStructure",node:r})}},SwitchStatement(r){let{branches:n,endsWithDefault:o}=A(r);o&&t(n)&&e.report({messageId:"removeOrEditConditionalStructure",node:r})},ConditionalExpression(r){t([r.consequent,r.alternate])&&e.report({messageId:"returnsTheSameValue",node:r})}};function t(t){return t.length>1&&t.slice(1).every((r,n)=>I(r,t[n],e.sourceCode))}}});var j=e({name:"no-duplicated-branches",meta:{schema:[],type:"suggestion",docs:{description:"Two branches in a conditional structure should not have exactly the same implementation",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1871/javascript"},messages:{sameConditionalBlock:"This {{type}}'s code block is the same as the block for the {{type}} on line {{line}}."}},create(e){return{IfStatement(o){!function(o){if(o.parent.type===i.IfStatement)return;let{branches:s,endsWithElse:a}=function(e){let t=[e.consequent],r=!1,n=e.alternate;for(;n;)if(n.type===i.IfStatement)t.push(n.consequent),n=n.alternate;else{t.push(n),r=!0;break}return{branches:t,endsWithElse:r}}(o);if(r(s,a))return s.slice(1).forEach((e,t)=>n(e,s[t],"branch"));for(let r=1;r<s.length;r++)if(t([s[r]]))for(let t=0;t<r&&!function(t,r){let o=D(t,r,e.sourceCode);return o&&"loc"in r&&n(t,r,"branch"),o}(s[r],s[t]);t++);}(o)},SwitchStatement(o){!function(o){let{cases:s}=o,{endsWithDefault:i}=A(o),a=s.filter(e=>R(M(e.consequent)).length>0);if(r(a.map(e=>R(M(e.consequent))),i))return a.slice(1).forEach((e,t)=>n(e,a[t],"case"));for(let r=1;r<s.length;r++){let o=R(M(s[r].consequent));if(t(o)){for(let t=0;t<r;t++)if(D(o,R(M(s[t].consequent)),e.sourceCode)){n(s[r],s[t],"case");break}}}}(o)}};function t(t){if(t.length>0){let r=[...e.sourceCode.getTokens(t[0]),...e.sourceCode.getTokens(t[t.length-1])].filter(e=>"{"!==e.value&&"}"!==e.value);return r.length>0&&r[r.length-1].loc.end.line>r[0].loc.start.line}return!1}function r(t,r){return!r&&t.length>1&&t.slice(1).every((r,n)=>D(r,t[n],e.sourceCode))}function n(t,r,n){let o=r.loc;e.report({messageId:"sameConditionalBlock",data:{type:n,line:String(o.start.line)},node:t})}}});function M(e){if(1===e.length){let t=e[0];if(t.type===i.BlockStatement)return t.body}return e}function D(e,t,r){var n,o;return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>D(e,t[n],r)):!(Array.isArray(e)||Array.isArray(t))&&e.type===t.type&&(n=r.getTokens(e),o=r.getTokens(t),n.length===o.length&&n.every((e,t)=>e.value===o[t].value))}function R(e){return e.length>0&&e[e.length-1].type===i.BreakStatement?e.slice(0,-1):e}var L=e({name:"comma-or-logical-or-case",meta:{type:"problem",docs:{description:"Comma and logical OR operators should not be used in switch cases",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3616/javascript"},schema:[],messages:{specifyCase:'Explicitly specify {{nesting}} separate cases that fall through; currently this case clause only works for "{{expression}}".'}},create(e){function t(t,r,n){var o;e.report({messageId:"specifyCase",data:{nesting:n.toString(),expression:String((o=r).type===i.Literal?o.value:e.sourceCode.getText(o))},node:t})}return{"SwitchCase > SequenceExpression":function(e){let r=e.expressions;t(e,r[r.length-1],r.length)},"SwitchCase > LogicalExpression":function(r){var n;if((n=function(t){let r=e.sourceCode.getAncestors(t);for(let e=r.length-1;e>=0;e--)if(r[e].type===i.SwitchStatement)return r[e];throw Error("A switch case should have an enclosing switch statement")}(r)).discriminant.type!==i.Literal||!0!==n.discriminant.value){let e=function e(t,r){if("||"===t.operator)return t.left.type===i.LogicalExpression?e(t.left,r+1):[t.left,r+1]}(r,0);e&&t(r,e[0],e[1]+1)}}}}}),O=e({name:"no-element-overwrite",meta:{schema:[],type:"problem",docs:{description:"Collection elements should not be replaced unconditionally",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4143/javascript"},messages:{verifyIntendedIndex:'Verify this is the index that was intended; "{{index}}" was already set on line {{line}}.'}},create(e){return{SwitchCase(e){t(e.consequent)},BlockStatement(e){t(e.body)},Program(e){t(e.body.filter(e=>{var t;return!((t=e)&&(t.type===i.ImportDeclaration||t.type===i.ExportNamedDeclaration||t.type===i.ExportDefaultDeclaration||t.type===i.ExportAllDeclaration))}))}};function t(t){let r,n=new Map;t.forEach(t=>{let o=function(t){if(t.type===i.ExpressionStatement)return function(t){var r,n,o;if((r=t).type===i.AssignmentExpression&&"="===r.operator&&t.left.type===i.MemberExpression&&t.left.computed){let r,s,{left:i,right:a}=t,l=q(i.property);if(void 0!==l&&(n=i.object,o=a,r=e.sourceCode.getTokens(n),void 0===(s=e.sourceCode.getTokens(o)).find((e,t)=>{if(P(e,r[0]))for(let e=t,n=0;e<s.length&&n<r.length;e++,n++)if(P(s[e],r[n])){if(n===r.length-1)return!0}else break;return!1})))return{collectionNode:i.object,indexOrKey:l,node:t}}}(t.expression)||function(e){if(e.type===i.CallExpression&&e.callee.type===i.MemberExpression){let t=e.callee;if(t.property.type===i.Identifier){let r=t.property.name,n="add"===r&&1===e.arguments.length,o="set"===r&&2===e.arguments.length;if(n||o){let r=q(e.arguments[0]);if(r)return{collectionNode:t.object,indexOrKey:r,node:e}}}}}(t.expression)}(t);if(o){r&&!I(o.collectionNode,r,e.sourceCode)&&n.clear();let t=n.get(o.indexOrKey);t?.node.loc&&e.report({node:o.node,messageId:"verifyIntendedIndex",data:{index:o.indexOrKey,line:t.node.loc.start.line}}),n.set(o.indexOrKey,o),r=o.collectionNode}else n.clear()})}}});function P(e,t){return e.value===t.value}function q(e){if(e.type===i.Literal){let{value:t}=e;return"number"==typeof t||"string"==typeof t?String(t):void 0}if(e.type===i.Identifier)return e.name}var F=e({name:"class-prototype",meta:{schema:[],type:"suggestion",docs:{description:'Class methods should be used instead of "prototype" assignments',recommended:"recommended"},messages:{declareClass:'Declare a "{{class}}" class and move this declaration of "{{declaration}}" into it.'}},create(e){let r=e.sourceCode.parserServices,n=t(r)?B:V;return{AssignmentExpression({left:t,right:o}){if(t.type===i.MemberExpression&&n(o,r)){let[r,n]=[t.object,t.property];if(r.type===i.MemberExpression&&n.type===i.Identifier){let[o,s]=[r.object,r.property];o.type===i.Identifier&&s.type===i.Identifier&&"prototype"===s.name&&e.report({messageId:"declareClass",data:{class:o.name,declaration:n.name},node:t})}}}}}});function B(e,t){r(t);let n=t.program.getTypeChecker().getTypeAtLocation(t.esTreeNodeToTSNodeMap.get(e));return!!n.symbol&&(n.symbol.flags&c.Function)!=0}let U=new Set(["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression"]);function V(e){return U.has(e.type)}var N=e({name:"bool-param-default",meta:{schema:[],type:"suggestion",docs:{description:"Optional boolean parameters should have default value"},messages:{provideDefault:"Provide a default value for '{{parameter}}' so that the logic of the function is more evident when this parameter is missing. Consider defining another function if providing default value is not possible."}},create:e=>({"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression":t=>{for(let r of t.params)r.type===i.Identifier&&function(e){var t;return(t=e).optional&&!!t.typeAnnotation&&t.typeAnnotation.typeAnnotation.type===i.TSBooleanKeyword||function(e){if(e.typeAnnotation&&e.typeAnnotation.typeAnnotation.type===i.TSUnionType){let t=e.typeAnnotation.typeAnnotation.types;return 2===t.length&&t.some(e=>e.type===i.TSBooleanKeyword)&&t.some(e=>e.type===i.TSUndefinedKeyword)}return!1}(e)}(r)&&e.report({messageId:"provideDefault",data:{parameter:r.name},node:r})}})}),W=e({name:"call-argument-line",meta:{type:"suggestion",docs:{description:"Function call arguments should not start on new lines",recommended:"recommended"},schema:[],messages:{moveArguments:"Make those call arguments start on line {{line}}.",moveTemplateLiteral:"Make this template literal start on line {{line}}."}},create(e){let t=e.sourceCode;return{CallExpression(r){if(r.callee.type!==i.CallExpression&&1===r.arguments.length){var n;let o=(n=r).typeArguments??n.callee,s=(t.getLastTokenBetween(o,r.arguments[0],$)??t.getLastToken(o)).loc.end.line,{start:i}=t.getTokenAfter(o,z).loc;if(s!==i.line){let{end:n}=t.getLastToken(r).loc;n.line===i.line?e.report({messageId:"moveArguments",data:{line:s.toString()},loc:{start:i,end:n}}):e.report({messageId:"moveArguments",data:{line:s.toString()},loc:i})}}},TaggedTemplateExpression(r){let{quasi:n}=r,o=t.getTokenBefore(n);if(o&&n.loc&&o.loc.end.line!==n.loc.start.line){let t={start:n.loc.start,end:{line:n.loc.start.line,column:n.loc.start.column+1}};e.report({messageId:"moveTemplateLiteral",data:{line:o.loc.start.line.toString()},loc:t})}}}}});function $(e){return e.type===a.Punctuator&&")"===e.value}function z(e){return!$(e)}var K=e({name:"track-todo-fixme-comment",meta:{type:"suggestion",docs:{description:'Track uses of "FIXME" and "TODO" tags',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1134/javascript"},schema:[],messages:{fixme:"Take the required action to fix the issue indicated by this comment.",todo:'Complete the task associated to this "TODO" comment.'}},create(e){function t(t,r){e.sourceCode.getAllComments().forEach(n=>{let o=n.value.toLowerCase();if(o.includes(t)){let s=o.split(/\r\n?|\n/);for(let o=0;o<s.length;o++){let i=s[o].indexOf(t);i>=0&&!function(e,t,r){let n=t+r.length,o=t>0&&_.test(e.charAt(t-1)),s=n<=e.length-1&&_.test(e.charAt(n));return o||s}(s[o],i,t)&&e.report({messageId:r,loc:function(e,t,r,n){let o=r.loc.start.line+e,s=(0===e?r.loc.start.column+2:0)+t;return{start:{line:o,column:s},end:{line:o,column:s+n.length}}}(o,i,n,t)})}}})}return{"Program:exit":()=>{t("fixme","fixme"),t("todo","todo")}}}});let _=/\p{Letter}/u,G=["Array","Map","Set","WeakSet","WeakMap"],X=new Set(["copyWithin","pop","reverse","shift","sort","clear","delete","concat","flat","flatMap","includes","indexOf","join","lastIndexOf","slice","toSource","toString","toLocaleString","get","has","entries","every","filter","find","findIndex","forEach","keys","map","reduce","reduceRight","some","values"]);var Y=e({name:"no-empty-collection",meta:{schema:[],type:"problem",docs:{description:"Empty collections should not be accessed or iterated",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4158/javascript"},messages:{reviewUsageOfIdentifier:'Review this usage of "{{identifierName}}" as it can only be empty here.'}},create(e){let t=t=>{if(t.references.length<=1||t.defs.some(e=>e.type===d.Scope.DefinitionType.Parameter||e.type===d.Scope.DefinitionType.ImportBinding))return;let r=[],n=!1;for(let e of t.references)if(e.isWriteOnly())if(!function(e){let t=H(e.identifier,e=>e.type===i.VariableDeclarator||e.type===i.ExpressionStatement);if(t){if(t.type===i.VariableDeclarator&&t.init)return Z(t.init);if(t.type===i.ExpressionStatement){let{expression:r}=t;return r.type===i.AssignmentExpression&&Q(e,r.left)&&Z(r.right)}}return!1}(e))return;else n=!0;else{var o;if(!(function(e){let{parent:t}=e.identifier;if(t?.type===i.MemberExpression){let e=t.parent;if(e?.type===i.CallExpression)return ee(t.property,...X)}return!1}(o=e)||function(e){let t=H(e.identifier,e=>e.type===i.ForOfStatement||e.type===i.ForInStatement);return t?.right===e.identifier}(o)||function(e){let{parent:t}=e.identifier;return t?.type===i.MemberExpression&&t.computed&&!function(e){let t=J(e,new Set),r=t.find(e=>e.type===i.AssignmentExpression);return r?.operator==="="&&[e,...t].includes(r.left)}(t)}(o)))return;r.push(e)}n&&r.forEach(t=>{e.report({messageId:"reviewUsageOfIdentifier",data:{identifierName:t.identifier.name},node:t.identifier})})},r=e=>{e.type!==d.Scope.ScopeType.global&&e.variables.forEach(t),e.childScopes.forEach(r)};return{"Program:exit":t=>{r(e.sourceCode.getScope(t))}}}});function H(e,t){return J(e,new Set).find(t)}function J(e,t){let r=[],n=e.parent;for(;n&&(r.push(n),!t.has(n.type));)n=n.parent;return r}function Q(e,t){return t.type===i.Identifier&&t===e.identifier}function Z(e){return e?.type===i.ArrayExpression?0===e.elements.length:!!e&&(e.type===i.CallExpression||e.type===i.NewExpression)&&ee(e.callee,...G)&&0===e.arguments.length}function ee(e,...t){return e?.type===i.Identifier&&(0===t.length||t.some(t=>t===e.name))}let et=new Set(["!=","==","!==","==="]),er=new Set(["!==","!="]),en=new Set(["+=","-="]);var eo=e({name:"no-equals-in-for-termination",meta:{schema:[],messages:{replaceOperator:"Replace '{{operator}}' operator with one of '<=', '>=', '<', or '>' comparison operators."},type:"suggestion",docs:{description:'Equality operators should not be used in "for" loop termination conditions',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S888/javascript"}},create(e){function t(t,r){if(t.type===i.Identifier){var n;let o=(n=t.name,function(e,t){let r;for(;null==r&&null!=e;)r=e.variables.find(e=>e.name===t),e=e.upper;return r}(e.sourceCode.getScope(t),n)),s=r.range;if(o&&s)return o.references.some(e=>{var t,r;return t=e.identifier,r=s,t.range&&t.range[0]>r[0]&&t.range[1]<r[1]})}return!1}return{ForStatement(r){var n,o;let s,a;if(!r.test||!r.update)return;let l=r.test;(n=l).type===i.BinaryExpression&&et.has(n.operator)&&function e(t){return!!es(t)||t.type===i.UpdateExpression||t.type===i.SequenceExpression&&t.expressions.every(e)}(r.update)&&(s=(o=r).test,a=[],function e(t,r){let n;es(t)?n=t.left:t.type===i.UpdateExpression?n=t.argument:t.type===i.SequenceExpression&&t.expressions.forEach(t=>e(t,r)),n?.type===i.Identifier&&r.push(n.name)}(o.update,a),!(s.left.type!==i.Identifier||!a.includes(s.left.name)||function(e){let r=e.init,n=e.test;if(r&&ei(n)){let o=function(e,r){var n,o;if(n=e,o=r,n.type===i.UpdateExpression&&!t(n.argument,o)||function(e){if(es(e)){let t=e.right;return t.type===i.Literal&&1===t.value}return!1}(n)&&!t(n.left,o)){if("++"===e.operator||"+="===e.operator)return 1;if("--"===e.operator||"-="===e.operator)return -1}return 0}(e.update,e.body);if(0!==o){let e=ea(r),t=ea(n);return void 0!==e&&void 0!==t&&o===Math.sign(t-e)}}return!1}(r)))&&e.report({messageId:"replaceOperator",data:{operator:l.operator},node:l})}}}});function es(e){return e.type===i.AssignmentExpression&&en.has(e.operator)}function ei(e){return e.type===i.BinaryExpression&&er.has(e.operator)}function ea(e){var t;return ei(e)?el(e.right):(t=e).type===i.VariableDeclaration&&1===t.declarations.length?el(e.declarations[0].init):e.type===i.AssignmentExpression?el(e.right):void 0}function el(e){if(e?.type===i.Literal&&"number"==typeof e.value)return e.value}var ec=e({name:"no-top-level-this",meta:{hasSuggestions:!0,schema:[],messages:{removeThis:'Remove the use of "this".',suggestRemoveThis:'Remove "this"',suggestUseGlobalThis:'Replace "this" with "globalThis" object'},type:"suggestion",docs:{description:'The global "this" object should not be used',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S2990/javascript"},fixable:"code"},create:e=>({'MemberExpression[object.type="ThisExpression"]':t=>{let r=e.sourceCode.getScope(t).variableScope.type,n=e.sourceCode.getAncestors(t).some(e=>e.type===i.ClassDeclaration||e.type===i.ClassExpression);if((r===d.Scope.ScopeType.global||r===d.Scope.ScopeType.module)&&!n){let r=[];if(!t.computed){let n=e.sourceCode.getText(t.property);r.push({messageId:"suggestRemoveThis",fix:e=>e.replaceText(t,n)},{messageId:"suggestUseGlobalThis",fix:e=>e.replaceText(t.object,"globalThis")})}e.report({messageId:"removeThis",node:t.object,suggest:r})}}})}),ep=e({name:"no-invariant-returns",meta:{schema:[],type:"suggestion",docs:{description:"Function returns should not be invariant",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3516/javascript",requiresTypeChecking:!1},messages:{refactorReturn:"Refactor this function to only return once or not always return the same value."}},create(e){let t=[],r=[],n=[],o=r=>{var o,s,a;return o=r,void(!(s=t[t.length-1])||(a=s,n.some(e=>e.reachable)||a.containsReturnWithoutValue||a.returnStatements.length<=1||a.codePath.thrownSegments.length>0)||function(e,t){let r=e[0],n=r?em(r,t):void 0;if(void 0!==n)return e.slice(1).every(e=>em(e,t)===n);if(r?.type===i.Identifier){let n=eu(r.name,t);if(n){let t=new Set(n.variable.references.slice(1).map(e=>e.identifier));return e.every(e=>t.has(e))}}return!1}(s.returnStatements.map(e=>e.argument),e.sourceCode.getScope(o))&&e.report({messageId:"refactorReturn",node:o}))};return{onCodePathStart(e){t.push({codePath:e,containsReturnWithoutValue:!1,returnStatements:[]}),r.push(n),n=[]},onCodePathEnd(){t.pop(),n=r.pop()||[]},onCodePathSegmentStart(e){n.push(e)},onCodePathSegmentEnd(){n.pop()},ReturnStatement(e){if(t.length){let r=t[t.length-1];r.containsReturnWithoutValue=r.containsReturnWithoutValue||!e.argument,r.returnStatements.push(e)}},"FunctionDeclaration:exit":o,"FunctionExpression:exit":o,"ArrowFunctionExpression:exit":o}}});function eu(e,t){let r=t.set.get(e);if(r&&!r.references.slice(1).some(e=>{var t;let r;return e.isWrite()||(r=H((t=e).identifier,e=>e.type===i.ExpressionStatement||V(e)),r?.type===i.ExpressionStatement&&(ed(r,t)||r.expression.type===i.CallExpression))})){let e=null;return 1===r.defs.length&&r.defs[0].type===d.Scope.DefinitionType.Variable&&(e=r.defs[0].node.init),{variable:r,initExpression:e}}return null}function ed(e,t,r=!0){return e.expression.type===i.AssignmentExpression&&function e(t,r,n=!0){return t.type===i.MemberExpression&&(Q(r,t.object)||n&&e(t.object,r,n))}(e.expression.left,t,r)}function em(e,t){if(e){if(e.type===i.Literal)return e.value;if(e.type===i.UnaryExpression){let r=em(e.argument,t);return void 0===r?void 0:function(e,t){switch(e){case"-":return-Number(t);case"+":return Number(t);case"~":return~Number(t);case"!":return!t;case"typeof":return typeof t}}(e.operator,r)}if(e.type===i.Identifier){let r=eu(e.name,t);if(r?.initExpression)return em(r.initExpression,t)}}}function ef(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function eg(e,t){let r=t.variables.find(t=>t.name===e.name);return!r&&t.upper&&(r=t.upper.variables.find(t=>t.name===e.name)),r}class eh extends Set{constructor(...e){super(...e),ef(this,"type","AssignedValues")}}let ey={type:"UnknownValue"};class ev{add(e){e.resolved&&this.references.add(e)}propagate(e){this.in.clear(),this.segment.prevSegments.forEach(t=>{this.join(e.get(t.id).out)});let t=new Map;return this.references.forEach(e=>this.updateProgramState(e,t)),!function(e,t){if(e.size!==t.size)return!1;for(let[o,s]of e){var r,n;if(!t.has(o)||(r=t.get(o),n=s,"AssignedValues"===r.type&&"AssignedValues"===n.type?!function(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}(r,n):r!==n))return!1}return!0}(this.out,t)&&(this.out=t,!0)}updateProgramState(e,t){let r=e.resolved;if(!r||!e.isWrite())return;if(!e.writeExpr)return void t.set(r,ey);let n=eb(r,e.writeExpr,t,e.from);t.set(r,n)}join(e){for(let[t,r]of e.entries()){let e=this.in.get(t)??new eh;"AssignedValues"===e.type&&"AssignedValues"===r.type?(r.forEach(t=>e.add(t)),this.in.set(t,e)):this.in.set(t,ey)}}constructor(e){ef(this,"segment",void 0),ef(this,"in",void 0),ef(this,"out",void 0),ef(this,"references",void 0),this.segment=e,this.in=new Map,this.out=new Map,this.references=new Set}}function eb(e,t,r,n){if(!t)return ey;switch(t.type){case i.Literal:return t.raw?new eh([t.raw]):ey;case i.Identifier:{let o=eg(t,n);if(o&&o!==e)return r.get(o)??ey;return ey}default:return ey}}class ex{constructor(e){ef(this,"codePath",void 0),ef(this,"reachingDefinitionsMap",void 0),ef(this,"reachingDefinitionsStack",void 0),ef(this,"segments",void 0),ef(this,"assignmentStack",void 0),this.codePath=e,this.reachingDefinitionsMap=new Map,this.reachingDefinitionsStack=[],this.segments=new Map,this.assignmentStack=[]}}class eS{isRhs(e){return this.node.type===i.AssignmentExpression?this.node.right===e:this.node.init===e}isLhs(e){return this.node.type===i.AssignmentExpression?this.node.left===e:this.node.id===e}add(e){let t=e.identifier;for(;t;){if(this.isLhs(t)){this.lhs.add(e);break}if(this.isRhs(t)){this.rhs.add(e);break}t=t.parent}}constructor(e){ef(this,"node",void 0),ef(this,"lhs",void 0),ef(this,"rhs",void 0),this.node=e,this.lhs=new Set,this.rhs=new Set}}function ew(e){return e[e.length-1]}var eE=e({name:"no-redundant-assignments",meta:{schema:[],type:"suggestion",docs:{description:"Assignments should not be redundant",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4165/javascript"},messages:{reviewAssignment:'Review this redundant assignment: "{{symbol}}" already holds the assigned value along all execution paths.'}},create(e){let t=[],r=new Map,n=new Map,o=[],s=[];return{AssignmentExpression:l,"VariableDeclarator[init]":l,"AssignmentExpression:exit":a,"VariableDeclarator[init]:exit":a,Identifier(r){var o;r.parent.type===i.TSEnumBody||r.parent.type===i.TSEnumDeclaration||r.parent.type===i.TSEnumMember||(o=r,e.sourceCode.getAncestors(o).some(e=>e.type===i.TSEnumDeclaration)||function(r){var o;let{ref:s,variable:i}=function e(t,r){if(null===r)return{ref:null,variable:null};let n=r.references.find(e=>e.identifier===t);if(n)return{ref:n,variable:n.resolved};let o=r.variables.find(e=>e.defs.find(e=>e.name===t));return o?{ref:null,variable:o}:e(t,r.upper)}(o=r,e.sourceCode.getScope(o));if(s&&p(s),i){let e=ew(t).codePath.id;n.has(i)?n.get(i).add(e):n.set(i,new Set([e]))}}(r))},"Program:exit":()=>{let e=Array.from(r.values(),e=>e.segment);for(;e.length;){let t=e.pop();r.get(t.id).propagate(r)&&t.nextSegments.forEach(t=>e.push(t))}r.forEach(c),r.clear(),n.clear(),t.length=0},onCodePathSegmentStart(e){r.set(e.id,new ev(e)),s.push(e)},onCodePathStart(e){var r;r=new ex(e),t.push(r),o.push(s),s.length=0},onCodePathEnd(){t.pop(),o.pop()||(s.length=0)},onCodePathSegmentEnd(){s.pop()}};function a(){let e=ew(t).assignmentStack.pop();e.rhs.forEach(p),e.lhs.forEach(p)}function l(e){ew(t).assignmentStack.push(new eS(e))}function c(t){let r=new Map(t.in);t.references.forEach(t=>{let o=t.resolved;if(!o||!t.isWrite()||!function(e){var t;let r=e.resolved;return r&&(e.identifier.type!==i.Identifier||e.identifier.parent.type!==i.AssignmentPattern)&&!r.name.startsWith("_")&&!function(e){if(e?.parent){let t=e.parent;return t?.type===i.AssignmentExpression&&"="!==t.operator}return!1}(e.writeExpr)&&(e.writeExpr?.type!==i.Identifier||e.resolved!==eg(e.writeExpr,e.from))&&!r.defs.some(e=>e.type===d.Scope.DefinitionType.Parameter||e.type===d.Scope.DefinitionType.Variable&&!e.node.init)&&(t=r,!(n.get(t).size>1))}(t))return;let s=r.get(o),a=eb(o,t.writeExpr,r,t.from);if(s?.type==="AssignedValues"&&1===s.size){let[r]=[...s];!function({resolved:t},r,n,o,s){if("UnknownValue"===o.type||1!==o.size)return;let[i]=[...o];t&&1!==t.references.filter(e=>e.isWrite()).length&&n===i&&e.report({node:r,messageId:"reviewAssignment",data:{symbol:s}})}(t,t.writeExpr,r,a,o.name)}r.set(o,a)})}function p(e){let{assignmentStack:n}=ew(t);if(n.length>0)ew(n).add(e);else for(let t=0,n=s.length;t<n;t++)(function(e){let t;return r.has(e.id)?t=r.get(e.id):(t=new ev(e),r.set(e.id,t)),t})(s[t]).add(e)}}}),ek=e({name:"no-same-line-conditional",meta:{schema:[],type:"layout",docs:{description:"Conditionals should start on new lines",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3972/javascript"},fixable:"whitespace",messages:{sameLineCondition:'Move this "if" to a new line or add the missing "else".'}},create(e){function t(t){var r;let{sourceCode:n}=e;(r=t).reduce((e,t,n)=>{let o=r[n-1];return t.type===i.IfStatement&&o&&o.type===i.IfStatement?[{first:o,following:t},...e]:e},[]).forEach(t=>{let r=t.first,o=t.following;if(r.loc?.end.line===o.loc?.start.line&&r.loc.start.line!==o.loc.end.line){let t=n.getFirstToken(o);e.report({messageId:"sameLineCondition",loc:t.loc,fix:e=>e.replaceTextRange([r.range[1],o.range[0]],"\n"+" ".repeat(r.loc.start.column))})}})}return{Program:e=>t(e.body),BlockStatement:e=>t(e.body),SwitchCase:e=>t(e.consequent)}}}),eT=e({name:"no-small-switch",meta:{schema:[],messages:{replaceSwitch:'Replace this "switch" statement by "if" statements to increase readability.'},type:"suggestion",docs:{description:'"if" statements should be preferred over "switch" when simpler',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1301/javascript"}},create:e=>({SwitchStatement(t){let{cases:r}=t,n=r.some(e=>!e.test);if(r.length<2||2===r.length&&n){let r=e.sourceCode.getFirstToken(t);r&&e.report({messageId:"replaceSwitch",loc:r.loc})}}})});let eC=["Array","Map","Set","WeakSet","WeakMap"],eI=["copyWithin","fill","pop","push","reverse","set","shift","sort","splice","unshift","add","clear","delete"];var eA=e({name:"no-unused-collection",meta:{schema:[],messages:{unusedCollection:"Either use this collection's contents or remove the collection."},type:"suggestion",docs:{description:"Collection contents should be used",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4030/javascript",requiresTypeChecking:!1}},create:e=>({"Program:exit":t=>{let r=[];(function e(t,r){t.type!==d.Scope.ScopeType.global&&t.variables.forEach(e=>{(function(e){if(function(e){if(!e.defs.length)return;let t=e.defs[0];return t.node.parent?.parent?.type.startsWith("Export")}(e)||e.references.length<=1)return!1;let t=!1;for(let r of e.references)if(r.isWriteOnly())if(!function(e){let t=H(e.identifier,e=>e.type===i.VariableDeclarator||e.type===i.ExpressionStatement);if(t){if(t.type===i.VariableDeclarator&&t.init)return ej(t.init);if(t.type===i.ExpressionStatement){let{expression:r}=t;return r.type===i.AssignmentExpression&&Q(e,r.left)&&ej(r.right)}}return!1}(r))return!1;else t=!0;else if(function(e){let t=H(e.identifier,e=>e.type===i.ExpressionStatement);return!t||!ed(t,e,!1)&&!function(e,t){if(e.expression.type===i.CallExpression){let{callee:r}=e.expression;if(r.type===i.MemberExpression){let{property:e,object:n}=r;return Q(t,n)&&ee(e,...eI)}}return!1}(t,e)}(r))return!1;return t})(e)&&r.push(e)}),t.childScopes.forEach(t=>{e(t,r)})})(e.sourceCode.getScope(t),r),r.forEach(t=>{e.report({messageId:"unusedCollection",node:t.identifiers[0]})})}})});function ej(e){return e?.type===i.ArrayExpression||!!e&&(e.type===i.CallExpression||e.type===i.NewExpression)&&ee(e.callee,...eC)}var eM=e({name:"no-useless-plusplus",meta:{schema:[],type:"problem",docs:{description:"Values should not be uselessly incremented",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S2123/javascript"},messages:{removeIncrement:"Remove this {{updateOperator}}rement or correct the code not to waste it."}},create(e){function t(t){let r="++"===t.operator?"inc":"dec";e.report({messageId:"removeIncrement",data:{updateOperator:r},node:t})}return{"ReturnStatement > UpdateExpression":function(r){var n;let o=r.argument;!r.prefix&&o.type===i.Identifier&&(n=o,e.sourceCode.getScope(r).variables.some(e=>e.identifiers.some(e=>e.name===n.name)))&&t(r)},AssignmentExpression(e){let r=e.right;if(r.type===i.UpdateExpression&&!r.prefix){let n=e.left;n.type===i.Identifier&&r.argument.type===i.Identifier&&r.argument.name===n.name&&t(r)}}}}});let eD=new Set(["map","filter","reduce","reduceRight","forEach"]);var eR=e({name:"no-chain-array-higher-order-functions",meta:{type:"problem",fixable:"code",docs:{description:"Prefer `.reduce` over chaining `.filter`, `.map` methods",recommended:"recommended"},schema:[],messages:{detected:"Detected the chaining of array methods: {{methods}}. Reaplce with `.reduce` to reduce array iterations and improve the performance."}},create:e=>({MemberExpression(t){if(eL(t)){let r=t.parent;eL(r.parent)&&e.report({node:r,messageId:"detected",data:{methods:`arr.${t.property.name}().${r.parent.property.name}()`}})}}})});function eL(e){return e.type===i.MemberExpression&&!e.computed&&e.property.type===i.Identifier&&eD.has(e.property.name)&&e.parent.type===i.CallExpression}var eO=e({name:"no-export-const-enum",meta:{type:"suggestion",docs:{description:"Disallow using `const enum` expression as it can not be inlined and tree-shaken by swc/esbuild/babel/webpack/rollup/vite/bun/rspack"},messages:{noConstEnum:"Do not use `const enum` expression"},schema:[]},create(e){let t=(t,r)=>{let n=m.findVariable(e.sourceCode.getScope(t),r);n?.defs.forEach(r=>{r.node.type===i.TSEnumDeclaration&&r.node.const&&e.report({node:t,messageId:"noConstEnum"})})};return{ExportNamedDeclaration(r){let n=r.declaration;if(n?.type===i.TSEnumDeclaration&&n.const)return void e.report({node:r,messageId:"noConstEnum"});if(n?.type===i.VariableDeclaration){let e=n.declarations[0].id;e.type===i.Identifier&&t(r,e)}},ExportDefaultDeclaration(e){let r=e.declaration;r.type===i.Identifier&&t(e,r)}}}}),eP=e({name:"no-for-in-iterable",meta:{schema:[],type:"suggestion",docs:{description:'"for in" should not be used with iterables',recommended:"strict",url:"https://sonarsource.github.io/rspec/#/rspec/S4139/javascript"},messages:{useForOf:'Use "for...of" to iterate over this "{{iterable}}".'}},create(e){let t=e.sourceCode.parserServices;return{ForInStatement(n){var o,s;r(t);let i=eq(n.right,t);if(r(t),(o=i).symbol&&eF.has(o.symbol.name)||((s=i).flags&p.StringLike)>0||s.symbol?.name==="String"||function(e,t){var r,n=t.program.getTypeChecker().getBaseConstraintOfType(e)??e,o=t;for(let e of(r=n).isUnion()?r.types:[r])if(!function(e,t){let r=t.program.getTypeChecker();return"isArrayType"in r&&"function"==typeof r.isArrayType&&r.isArrayType(e)}(e,o))return!1;return!0}(i,t)){let t=i.symbol?i.symbol.name:"String";e.report({messageId:"useForOf",data:{iterable:t},loc:e.sourceCode.getFirstToken(n).loc})}}}}});function eq(e,t){return t.program.getTypeChecker().getTypeAtLocation(t.esTreeNodeToTSNodeMap.get(e))}let eF=new Set(["Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Set","Map"]);var eB=e({name:"only-await-thenable",meta:{schema:[],type:"suggestion",docs:{description:'"await" should only be used with promises',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4123/javascript"},messages:{refactorAwait:"Refactor this redundant 'await' on a non-promise."}},create(e){let t=e.sourceCode.parserServices;return r(t),{AwaitExpression(r){let n,o=eq(r.argument,t);(function(e,t){var r,n;if(e.argument.type!==i.CallExpression)return!1;let o=(r=e.argument,(n=t).program.getTypeChecker().getResolvedSignature(n.esTreeNodeToTSNodeMap.get(r)));return o?.declaration&&function(e){if(!e.jsDoc)return!1;for(let t of e.jsDoc)if(t.tags?.some(e=>eU.has(e.tagName.escapedText.toString())))return!0;return!1}(o.declaration)})(r,t)||(n=o.getProperty("then"),n?.declarations?.some(e=>e.kind===u.MethodSignature||e.kind===u.MethodDeclaration||e.kind===u.PropertyDeclaration))||o.flags&p.Any||o.flags&p.Unknown||o.flags&p.Union||e.report({messageId:"refactorAwait",node:r})}}}});let eU=new Set(["return","returns"]);var eV=e({name:"no-undefined-optional-parameters",meta:{schema:[],type:"suggestion",docs:{description:'"undefined" should not be passed as the value of optional parameters',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4623/javascript",requiresTypeChecking:!0},fixable:"code",hasSuggestions:!0,messages:{removeUndefined:'Remove this redundant "undefined".',suggestRemoveUndefined:"Remove this redundant argument"}},create(e){let t=e.sourceCode.parserServices;return r(t),{CallExpression(r){var n;let{arguments:o}=r;if(0===o.length)return;let s=o[o.length-1];(n=s).type===i.Identifier&&"undefined"===n.name&&function(e,t,r){let n=r.program.getTypeChecker().getResolvedSignature(r.esTreeNodeToTSNodeMap.get(t));if(n){var o;let t=n.declaration;if(t&&(o=t,eN.has(o.kind))){let{parameters:r}=t,n=r[e];return n&&(n.initializer||n.questionToken)}}return!1}(o.length-1,r,t)&&e.report({messageId:"removeUndefined",node:s,suggest:[{messageId:"suggestRemoveUndefined",fix(t){if(1===r.arguments.length){let n=e.sourceCode.getTokenAfter(r.callee),o=e.sourceCode.getLastToken(r),[,s]=n.range,[i]=o.range;return t.removeRange([s,i])}let[,n]=o[o.length-2].range,[,i]=s.range;return t.removeRange([n,i])}}]})}}}});let eN=new Set([u.FunctionDeclaration,u.FunctionExpression,u.ArrowFunction,u.MethodDeclaration,u.Constructor,u.GetAccessor,u.SetAccessor]);function eW(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class e${visit(e,t){let r=e=>{switch(e.type){case i.AwaitExpression:case i.CallExpression:case i.NewExpression:this.callLikeExpressions.push(e);break;case i.FunctionDeclaration:case i.FunctionExpression:case i.ArrowFunctionExpression:return}(function(e,t){let r=[],n=t[e.type];if(n?.length)for(let t of n){let n=e[t];Array.isArray(n)?r.push(...n):r.push(n)}return r.filter(Boolean)})(e,t.sourceCode.visitorKeys).forEach(r)};r(e)}constructor(){eW(this,"callLikeExpressions",[])}}eW(e$,"getCallExpressions",(e,t)=>{let r=new e$;return r.visit(e,t),r.callLikeExpressions});var ez=e({name:"no-try-promise",meta:{schema:[],type:"problem",docs:{description:'Promise rejections should not be caught by "try" blocks',recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S4822/javascript",requiresTypeChecking:!0},messages:{addAwait:"Consider using 'await' for the promise{{ending}} inside this 'try' or replace it with 'Promise.prototype.catch(...)' usage{{ending}}.",removeTry:"Consider removing this 'try' statement as promise{{ending}} rejection is already captured by '.catch()' method."}},create(e){let t=e.sourceCode.parserServices;return r(t),{TryStatement(r){if(r.handler){let n=[],o=[],s=!1;if(e$.getCallExpressions(r.block,e).forEach(e=>{var r,a,l,p,u,d;let m,f;if(e.type===i.AwaitExpression||(r=e,m=(a=t).esTreeNodeToTSNodeMap.get(r),!(f=a.program.getTypeChecker().getTypeAtLocation(m).getProperty("then"))||!(f.flags&c.Method))){s=!0;return}(l=e).parent&&(l.parent.type===i.AwaitExpression||l.parent.type===i.YieldExpression)||(p=e,p.parent?.type===i.MemberExpression&&p.parent.property.type===i.Identifier&&"then"===p.parent.property.name)||(u=e).type===i.CallExpression&&u.callee.type===i.MemberExpression&&u.callee.property.type===i.Identifier&&"catch"===u.callee.property.name||((d=e,d.parent?.type===i.MemberExpression&&d.parent.property.type===i.Identifier&&"catch"===d.parent.property.name)?o:n).push(e)}),!s){if(n.length>0){let t=n.length>1?"s":"",o=e.sourceCode.getFirstToken(r);e.report({messageId:"addAwait",data:{ending:t},loc:o.loc})}if(0===n.length&&o.length>0){let t=o.length>1?"s":"",n=e.sourceCode.getFirstToken(r);e.report({messageId:"removeTry",data:{ending:t},loc:n.loc})}}}}}}}),eK=e({name:"no-unthrown-error",meta:{schema:[],type:"problem",docs:{description:"Errors should not be created without being thrown",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S3984/javascript",requiresTypeChecking:!1},fixable:"code",hasSuggestions:!0,messages:{throwOrRemoveError:"Throw this error or remove this useless statement.",suggestThrowError:"Throw this error"}},create:e=>({"ExpressionStatement > NewExpression":function(t){var r;let n;if(r=t.callee,(n=e.sourceCode.getText(r)).endsWith("Error")||n.endsWith("Exception")){let r,n=(r=e.sourceCode.getAncestors(t)).length>0?r[r.length-1]:void 0;e.report({messageId:"throwOrRemoveError",node:t,suggest:n?[{messageId:"suggestThrowError",fix:e=>e.insertTextBefore(n,"throw ")}]:[]})}}})}),e_=e({name:"no-useless-string-operation",meta:{schema:[],messages:{uselessStringOp:"{{symbol}} is an immutable object; you must either store or return the result of the operation."},type:"problem",docs:{description:"Results of operations on strings should not be ignored",recommended:"recommended",url:"https://sonarsource.github.io/rspec/#/rspec/S1154/javascript"}},create(e){let t=e.sourceCode.parserServices;return{'ExpressionStatement > CallExpression[callee.type="MemberExpression"]':n=>{let o,{object:s,property:a}=n.callee;r(t),(eq(s,t).flags&l.TypeFlags.StringLike)!=0&&a.type===i.Identifier&&e.report({messageId:"uselessStringOp",data:{symbol:((o=e.sourceCode.getText(s)).length>30&&(o="String"),o)},node:a})}}}});let eG={configs:{recommended:{name:"eslint-plugin-sukka/recommended",plugins:{get sukka(){return eG}},rules:{"sukka/ban-eslint-disable":["error","allow-with-description"],"sukka/bool-param-default":"error","sukka/call-argument-line":"error","sukka/class-prototype":"warn","sukka/comma-or-logical-or-case":"error","sukka/no-all-duplicated-branches":"error","sukka/no-chain-array-higher-order-functions":"error","sukka/no-duplicated-branches":"error","sukka/no-element-overwrite":"warn","sukka/no-empty-collection":"warn","sukka/no-equals-in-for-termination":"error","sukka/no-export-const-enum":"error","sukka/no-expression-empty-lines":"error","sukka/no-invariant-returns":"error","sukka/no-redundant-assignments":"warn","no-return-await":"off","sukka/no-return-await":"error","sukka/no-same-line-conditional":"error","sukka/no-small-switch":"error","sukka/no-top-level-this":"error","sukka/no-unthrown-error":"warn","sukka/no-unused-collection":"error","sukka/no-useless-plusplus":"error","sukka/object-format":"off","sukka/prefer-single-boolean-return":"error","sukka/track-todo-fixme-comment":"warn"}},recommended_extra_with_typed_lint:{name:"eslint-plugin-sukka/recommended_extra_with_typed_lint",plugins:{get sukka(){return eG}},rules:{"sukka/no-for-in-iterable":"error","sukka/no-try-promise":"error","sukka/no-undefined-optional-parameters":"warn","sukka/no-useless-string-operation":"warn","sukka/only-await-thenable":"off"}}},rules:{"ban-eslint-disable":y,"no-return-await":b,"no-expression-empty-lines":x,"object-format":w,"prefer-single-boolean-return":k,"no-all-duplicated-branches":j,"no-duplicated-branches":j,"bool-param-default":N,"call-argument-line":W,"class-prototype":F,"comma-or-logical-or-case":L,"track-todo-fixme-comment":K,"no-element-overwrite":O,"no-empty-collection":Y,"no-equals-in-for-termination":eo,"no-top-level-this":ec,"no-invariant-returns":ep,"no-redundant-assignments":eE,"no-same-line-conditional":ek,"no-small-switch":eT,"no-unused-collection":eA,"no-useless-plusplus":eM,"no-chain-array-higher-order-functions":eR,"no-export-const-enum":eO,"no-for-in-iterable":eP,"only-await-thenable":eB,"no-undefined-optional-parameters":eV,"no-try-promise":ez,"no-unthrown-error":eK,"no-useless-string-operation":e_}};export{eG as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-sukka",
3
- "version": "8.0.6",
3
+ "version": "8.2.0",
4
4
  "homepage": "https://github.com/SukkaW/eslint-config-sukka",
5
5
  "repository": {
6
6
  "url": "https://github.com/SukkaW/eslint-config-sukka",
@@ -23,15 +23,15 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@typescript-eslint/type-utils": "^8.49.0",
27
- "@typescript-eslint/types": "^8.49.0",
28
- "@typescript-eslint/utils": "^8.49.0",
29
- "foxts": "^5.0.3",
30
- "@eslint-sukka/shared": "8.0.6"
26
+ "@typescript-eslint/type-utils": "^8.53.0",
27
+ "@typescript-eslint/types": "^8.53.0",
28
+ "@typescript-eslint/utils": "^8.53.0",
29
+ "foxts": "^5.0.4",
30
+ "@eslint-sukka/shared": "8.2.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@masknet/eslint-plugin": "^0.4.1",
34
- "@eslint-sukka/rollup-config": "8.0.6"
34
+ "@eslint-sukka/rollup-config": "8.2.0"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "eslint": "*",