From fb7a45a934a29ebfe2f213d95a211414abea41b1 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 9 Jun 2025 20:30:32 -0700 Subject: [PATCH] sort-imports: ESLint Suppression Comments (#51881) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51881 Switches the suppression of ESLint for the generated `sort-imports` lint rule definition to using in-file comments instead of `.eslintignore`. This makes the suppression more portable. If the path to the lint rule definition changes, we don't have to remember to update `.eslintignore`. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D76152973 fbshipit-source-id: 7cc41282931788c9e347712e7ce8bf7fefb53858 --- .eslintignore | 1 - .eslintrc.js | 1 + tools/eslint/rules/sort-imports.js | 5 ++++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.eslintignore b/.eslintignore index ca22506f6c8..e16e0140326 100644 --- a/.eslintignore +++ b/.eslintignore @@ -13,7 +13,6 @@ packages/*/dist packages/*/types_generated packages/debugger-frontend/dist/**/* packages/react-native-codegen/lib -tools/eslint/rules/sort-imports.js **/Pods/* **/*.macos.js **/*.windows.js diff --git a/.eslintrc.js b/.eslintrc.js index 6c1f336d268..829535a3520 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -28,6 +28,7 @@ module.exports = { files: ['*.js', '*.js.flow', '*.jsx'], parser: 'hermes-eslint', rules: { + 'eslint-comments/no-unlimited-disable': 0, 'ft-flow/require-valid-file-annotation': [2, 'always'], 'no-extra-boolean-cast': 0, 'no-void': 0, diff --git a/tools/eslint/rules/sort-imports.js b/tools/eslint/rules/sort-imports.js index a061c4e1dea..618bf01efd1 100644 --- a/tools/eslint/rules/sort-imports.js +++ b/tools/eslint/rules/sort-imports.js @@ -6,7 +6,10 @@ * * To regenerate this file, please run this command on Meta's monorepo: * @codegen-command : xplat/js/tools/sort-imports/scripts/build.sh - * @generated SignedSource<<374df066e2e1e673cc452314636d8dd8>> + * @generated SignedSource<<7b842f046d041c0d5d44b62d0f8244e1>> * @nolint */ + +/* eslint-disable */ + "use strict";var e,t,n=require("path");function r(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}function o(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function a(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function l(){if(t)return e;t=1;const r=n,o=__dirname.split(r.sep).includes("xplat");function i(e){if(("Literal"===e.type||"JSXText"===e.type)&&"string"==typeof e.value)return e.value;if("BinaryExpression"===e.type&&"+"===e.operator){const t=i(e.left),n=i(e.right);if(null!=t&&null!=n)return t+n}return null}function a(e){if("Identifier"===e.type)return e.name;if("ThisExpression"===e.type)return"this";if("MemberExpression"===e.type){const t=a(e.object),n=e.computed?i(e.property):a(e.property);if(null!=t&&null!=n)return t+"."+n}else if("TypeCastExpression"===e.type||"AsExpression"===e.type)return a(e.expression);return null}function l(e){return e.callee?a(e.callee):null}function s(e,t,n){const r=e.getSourceCode().getText(),o=function(e,t){if(t.line<1)throw new RangeError("Line number "+t.line+" is before the start of file");const n=/\r\n|\r|\n|\u2028|\u2029/g;let r={index:0};for(let o=1;o=e.length)throw new RangeError("computed offset "+t+" is past the end of file");const n=/\r\n|\r|\n|\u2028|\u2029/g;let r,o={index:0},i=0;do{r=o,o=n.exec(e),++i}while(o&&o.index"string"==typeof e&&e.charCodeAt(0)>=97,p=e=>"string"==typeof e&&e.charCodeAt(0)<=90;function f(e){return null!=e&&"VariableDeclaration"===e.type&&"Program"===e.parent.type&&1===e.declarations.length&&null!=e.declarations[0].init&&d(e.declarations[0].init)}function m(e){return null!=e&&"VariableDeclarator"===e.type&&"VariableDeclaration"===e.parent.type&&"Program"===e.parent.parent.type&&1===e.parent.declarations.length&&d(e.init)}function d(e){return null!=e&&(y(e)||h(e)||x(e))}function g(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"requireNUX"===e.callee.name&&2===e.arguments.length&&"Literal"===e.arguments[0].type}function y(e){return"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"require"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type}function h(e){return"CallExpression"===e.type&&"Identifier"===e.callee.type&&"requireDeferred"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function x(e){return"CallExpression"===e.type&&"Identifier"===e.callee.type&&"requireDeferredForDisplay"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function b(e){return"ImportDeclaration"===e.type&&(null==e.importKind||"value"===e.importKind)}function C(e){return"ImportDeclaration"===e.type&&("type"===e.importKind||"typeof"===e.importKind)}function S(e){return b(e)||C(e)}function v(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"JSResource"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type}function E(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"JSResourceForInteraction"===e.callee.name&&2===e.arguments.length&&"Literal"===e.arguments[0].type}function I(e){return null!=e&&"CallExpression"===e.type&&"Identifier"===e.callee.type&&"ClientJSResource"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function D(e){if(null==e||"CallExpression"!==e.type||null==e.callee)return!1;let t;return"Identifier"===e.callee.type&&(t=e.callee),"MemberExpression"===e.callee.type&&"Identifier"===e.callee.object.type&&(t=e.callee.object),null!=t&&"requireCond"===t.name&&e.arguments.length>0}function T(e){return 0===e.indexOf("m#")?e.substring(2):e}function R(e,t,n=1){return"CallExpression"!==e.type||e.arguments.length!==n||null!=t&&"string"==typeof t&&l(e)!==t||"Literal"!==e.arguments[0].type||"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value)}function w(e,t,n){const r=e.arguments;return D(e)?3!==r.length?null:(null==t||r[0]&&"Literal"===r[0].type&&r[0].value===t)&&(null==n||r[1]&&"Literal"===r[1].type&&r[1].value===n)?r[2]&&"ObjectExpression"===r[2].type?r[2].properties.reduce(((e,t)=>{if("Property"===t.type&&"Literal"===t.value.type){let n;if("Identifier"===t.key.type)n=t.key.name;else{if("Literal"!==t.key.type)return e;n=String(t.key.value)}e[n]="string"==typeof t.value.value?T(t.value.value):null}return e}),{}):r[2]&&"Literal"===r[2].type&&"string"==typeof r[2].value?T(r[2].value):null:null:null}function O(e){return R(e,"JSResource")}function N(e){return R(e,"JSResourceForInteraction",2)}function k(e){return null==e?null:d(e)?"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value):null}function q(e){return g(e)?2!==e.arguments.length||"string"!=typeof e.arguments[1].value?null:T(e.arguments[1].value):null}function j(e,t){const n=e.getSourceCode().ast.body.find((e=>"VariableDeclaration"===e.type&&1===e.declarations.length&&"VariableDeclarator"===e.declarations[0].type&&null!=e.declarations[0].init&&k(e.declarations[0].init)===t));return n||null}function P(e){let t=e;for(;"TypeCastExpression"===t.type||"AsExpression"===t.type;)t=t.expression;return t}function L(e){if(0===e.specifiers.length)return!1;if("value"!==e.importKind)return!0;return e.specifiers.every((e=>"ImportSpecifier"===e.type&&("type"===e.importKind||"typeof"===e.importKind)))}function F(e,t){const n=e.getSourceCode().ast.body.find((e=>"ImportDeclaration"===e.type&&e.source.value===t&&!L(e)));return n||null}return e={asAnyKindOfRequireCall:function(e){return d(e)?e:null},asAnyKindOfRequireVariableDeclaration:function(e){return f(e)?e:null},asAnyKindOfRequireVariableDeclarator:function(e){return m(e)?e:null},getAnyRequiredModuleName:function(e,t=Object.freeze({})){const n=k(e)||O(e)||N(e)||q(e);return null!=n?n:w(e,t.condType,t.condition)},getBaseNode:function(e){let t=e;for(;"MemberExpression"===t.type;)t=t.object;return t},getBinding:u,getBootloadedModuleNames:function(e){return"ExpressionStatement"===e.type&&e.expression&&"CallExpression"===e.expression.type&&e.expression.callee&&"MemberExpression"===e.expression.callee.type&&e.expression.callee.object&&"Bootloader"===e.expression.callee.object.name&&e.expression.callee.property&&"loadModules"===e.expression.callee.property.name&&e.expression.arguments.length>0&&"ArrayExpression"===e.expression.arguments[0].type&&e.expression.arguments[0].elements.length>0?e.expression.arguments[0].elements.map((e=>"Literal"===e.type&&"string"==typeof e.value?T(e.value):null)).filter(Boolean):null},getCalleeName:l,getConstantStringExpression:i,getCurrentClassName:function(e){const t=e.getAncestors().find((e=>"ClassDeclaration"===e.type));return t&&"ClassDeclaration"===t.type&&null!=t.id?t.id.name:null},getEnglishForNth:function(e){return["first","second","third","fourth","fifth","sixth"][e]},getFullyQualifiedIdentifier:a,getJSResourceModuleName:O,getJSXMemberOrNamespaceRoot:function(e){let t=e;for(;"JSXIdentifier"!==t.type;)if("JSXMemberExpression"===t.type)t=t.object;else{if("JSXNamespacedName"!==t.type)throw new Error("unexpected "+t.type);t=t.namespace}return t},getLocOffset:function(e,t,n){return s(e,t.loc.start,n)},getLocOffsetOfLoc:s,getName:function(e){const t=P(e);return"Identifier"===t.type?t.name:"Literal"===t.type?String(t.value):null},getObjectPropertyName:function(e){if("Property"!==e.type&&"PropertyDefinition"!==e.type&&"MethodDefinition"!==e.type)return null;const t=e.key;return"Identifier"!==t.type||e.computed?function(e){switch(e.type){case"Literal":switch(e.literalType){case"bigint":return e.bigint;case"null":return"null";case"regexp":return`/${e.regex.pattern}/${e.regex.flags}`;default:return String(e.value)}case"TemplateLiteral":if(0===e.expressions.length&&1===e.quasis.length)return e.quasis[0].value.cooked}return null}(t):t.name},getParamComments:function(e,t){return t.params.map((function(t){const n=e.getSourceCode().getCommentsBefore(t);return n[n.length-1]}))},getPropertyName:function(e){return"MemberExpression"!==e.type?null:e.computed?i(e.property):"Identifier"!==e.property.type?null:e.property.name},getPropTokens:function(e,t){const n=e.getSourceCode().getTokens(t),r=[];return n.forEach(((e,t,n)=>{"JSXIdentifier"===e.type&&"Punctuator"===n[t+1].type&&"="===n[t+1].value&&r.push(e)})),r},getRequireCondModules:w,getRequireModuleName:k,getRequireModuleNode:j,getReturnComment:function(e,t){return e.getSourceCode().getCommentsBefore(t.body)[0]},getValueImportNode:F,getValueImportVariables:function(e,t){const n=[];for(const r of e.getSourceCode().ast.body)"ImportDeclaration"!==r.type||r.source.value!==t||L(r)||r.specifiers.filter((e=>{null!=e.importKind&&"value"!==e.importKind||n.push(e.local.name)}));return n},hasValueImport:function(e){return e.getSourceCode().ast.body.some((e=>"ImportDeclaration"===e.type&&!L(e)))},getVariable:function(e,t){let n=t;for(;n;){const t=n.set.get(e);if(t)return t;n=n.upper}return null},insertRequireStatement:function(e,t,n,r=""){if(""===n)throw new Error("Name must be a string with length larger than 0");const o=`const ${n} = require('${n}${r}');`,i=[];e.getSourceCode().ast.body.forEach((e=>{if("VariableDeclaration"===e.type&&1===e.declarations.length&&"VariableDeclarator"===e.declarations[0].type&&e.declarations[0].init){const t=k(e.declarations[0].init);null!=t&&i.push({name:t,node:e})}}));const a=i.find((e=>e.name>=n));if(a){if(a.name.replace(r,"")===n)return[];const e=i[0];if(c(a.name)&&p(n)){if(e!==a){const e=a.node.range[0];return[t.removeRange([e-1,e-1]),t.insertTextBefore(a.node,o+"\n\n")]}return[t.insertTextBefore(a.node,o+"\n\n")]}return[t.insertTextBefore(a.node,o+"\n")]}if(i.length>0){const e=i[i.length-1],r=p(e.name)&&c(n)?"\n":"";return[t.insertTextAfter(e.node,"\n"+o+r)]}{const n=e.getSourceCode().ast.body,r=n[0];return"ExpressionStatement"===r.type&&"Literal"===r.expression.type&&"use strict"===r.expression.value?[t.insertTextBefore(n[1],o+"\n")]:[t.insertTextBefore(n[0],o+"\n")]}},insertValueImportStatement:function(e,t,n,r="",o){if(""===n)throw new Error("Name must be a string with length larger than 0");const i=`import ${o??n} from '${n}${r}';`,a=[];e.getSourceCode().ast.body.forEach((e=>{if(b(e)){const t=function(e){if(d(e))return"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value);if(S(e))return e.source.value;return null}(e);null!=t&&a.push({name:t,node:e})}}));const l=a.find((e=>e.name>=n));if(l){if(l.name.replace(r,"")===n)return[];const e=a[0];if(c(l.name)&&p(n)){if(e!==l){const e=l.node.range[0];return[t.removeRange([e-1,e-1]),t.insertTextBefore(l.node,i+"\n\n")]}return[t.insertTextBefore(l.node,i+"\n\n")]}return[t.insertTextBefore(l.node,i+"\n")]}if(a.length>0){const e=a[a.length-1],r=p(e.name)&&c(n)?"\n":"";return[t.insertTextAfter(e.node,"\n"+i+r)]}{const n=e.getSourceCode().ast.body,r=n[0];return"ExpressionStatement"===r.type&&"Literal"===r.expression.type&&"use strict"===r.expression.value?[t.insertTextBefore(n[1],i+"\n")]:[t.insertTextBefore(n[0],i+"\n")]}},isAnyKindOfImport:S,isAnyKindOfModuleCall:function(e){return d(e)||D(e)||v(e)||E(e)||I(e)||g(e)},isAnyKindOfRequireCall:d,isAnyKindOfRequireVariableDeclaration:f,isAnyKindOfRequireVariableDeclarator:m,isClientJSResource:I,isFbSourceRepo:o,isGraphQLTemplate:function(e){return"Identifier"===e.tag.type&&"graphql"===e.tag.name&&1===e.quasi.quasis.length},isInsideMethod:function(e,t){return e.getAncestors().some((e=>"MethodDefinition"===e.type&&"Identifier"===e.key.type&&e.key.name===t))},isJSResource:v,isJSResourceForInteraction:E,isModuleRef:function(e){return"Literal"===e.type&&"string"==typeof e.value&&e.value.startsWith("m#")},isNodeInsideFunctionBody:function e(t){return null!=t.parent&&("ArrowFunctionExpression"===t.parent.type||"FunctionDeclaration"===t.parent.type||"FunctionExpression"===t.parent.type||"HookDeclaration"===t.parent.type||"ComponentDeclaration"===t.parent.type||e(t.parent))},isNodeInsideNode:function(e,t){return e.range[0]>=t.range[0]&&e.range[1]<=t.range[1]},isOnlyTypeImport:L,isOnlyTypeExport:function(e){return"type"===e.exportKind},isReferenced:function(e){const t=e.parent;switch(t.type){case"MemberExpression":case"JSXMemberExpression":return t.property===e&&!0===t.computed||t.object===e;case"MetaProperty":case"ImportDefaultSpecifier":case"ImportNamespaceSpecifier":case"ImportSpecifier":case"LabeledStatement":case"RestElement":case"ObjectPattern":case"ArrayPattern":return!1;case"Property":case"MethodDefinition":return t.key===e&&t.computed;case"VariableDeclarator":case"ClassDeclaration":case"ClassExpression":return t.id!==e;case"ArrowFunctionExpression":case"FunctionDeclaration":case"HookDeclaration":case"FunctionExpression":for(let n=0;ne.writeExpr));return null!=o?o.writeExpr:null},resolveModuleSource:function(e,t){const n=u(e.getScope(),t);if(null==n)return null;const r=n.defs[0];switch(r.node.type){case"VariableDeclarator":{const e=r.node.init;if(null!=e)return k(e)||O(e)||N(e)||q(e);break}case"ImportNamespaceSpecifier":case"ImportSpecifier":case"ImportDefaultSpecifier":return r.node.parent.source.value}return null},stripModuleRef:T,uncast:P},e}var s,u,c,p,f,m,d,g,y,h,x=a(o({__proto__:null,isCommaOrSemiToken:function(e){return"Punctuator"===e.type&&(","===e.value||";"===e.value)}},[r(require("hermes-estree"))]));function b(){if(u)return s;u=1;const{isCommaOrSemiToken:e}=x;return s={getInlineComments:function(t,n,r=e){const o=t.ast.comments.filter((e=>e.loc.start.line===n.loc.end.line&&e.range[0]>n.range[1])).sort(((e,t)=>e.range[0]-t.range[0])),i=[];let a=n;for(const e of o){const n=t.getTokensBetween(a,e);if(n.length>0){if(!r)break;if(!n.every(r))break}i.push(e),a=e}return i},getLeadingComments:function(e,t,n){const r=e.getCommentsBefore(t),o=[];let i=t;for(let t=r.length-1;t>=0;t-=1){const a=r[t];if(a===n)break;if(a.loc.end.line===i.loc.start.line){o.unshift(a),i=a;continue}if(a.loc.end.line!==i.loc.start.line-1)break;const l=e.getTokenBefore(a);if(l&&l.loc.end.line===a.loc.start.line)break;o.unshift(a),i=a}return o}}}function C(){if(g)return d;g=1;const e=l(),{getInlineComments:t,getLeadingComments:n}=b(),r=p?c:(p=1,c=function(e){const t=e.getSourceCode().ast;return t.docblock?.comment}),{compareNames:o}=function(){if(m)return f;m=1;const{getInlineComments:e,getLeadingComments:t}=b(),{isCommaOrSemiToken:n}=x;function r(e){return"@"===e[0]||":"===e[0]}const o=/\d{1,3}(\.\d+)?%/;function i(e){switch(typeof e){case"number":return{isSafeNumericString:!0,isPercentage:!1};case"boolean":return{isSafeNumericString:!1,isPercentage:!1}}return isNaN(e)||isNaN(parseFloat(e))?o.test(e)?{isSafeNumericString:!0,isPercentage:!0}:{isSafeNumericString:!1,isPercentage:!1}:{isSafeNumericString:!0,isPercentage:!1}}function a(e){return e.reduce((([e,t],[n,r])=>[Math.min(e,n),Math.max(t,r)]),[Number.MAX_SAFE_INTEGER,0])}return f={compareNames:function(e,t,n=!1){if("number"==typeof e&&"number"==typeof t)return e-t;const o=String(e),a=String(t);if(""===o&&""!==a)return-1;if(""!==o&&""===a)return 1;if(""===o&&""===a)return 0;const{isSafeNumericString:l,isPercentage:s}=i(o),{isSafeNumericString:u,isPercentage:c}=i(a);if(l&&u){const e=Number.parseFloat(o),t=Number.parseFloat(a);if(e===t){if(!s&&c)return-1;if(s&&!c)return 1}return e-t}if(n){const e=r(o),t=r(a);if(!e&&t)return-1;if(e&&!t)return 1}const p=l||o[0].toLowerCase()===o[0].toUpperCase(),f=u||a[0].toLowerCase()===a[0].toUpperCase();if(!p&&f)return 1;if(p&&!f)return-1;if(!p&&!f){const e=o[0].toLowerCase()===o[0],t=a[0].toLowerCase()===a[0];if(!e&&t)return-1;if(e&&!t)return 1}return o.localeCompare(a,"en",{caseFirst:"upper",sensitivity:"base"})},getEncompassingRange:a,getNodeTextWithComments:function(r,o,i,{shouldIncludeNextTokenInRange:l=n,ensureTextFollowsNode:s,inlineCommentIgnoreToken:u}={}){const c=e(r,o,u),p=[...t(r,o,i).map((({range:e})=>e)),o.range,...c.map((({range:e})=>e))],f=r.getTokenAfter(o);f&&!0===l?.(f)&&p.push(f.range);const m=a(p);let d=r.text.slice(m[0],m[1]);const g=o.range[1]-m[0];if(null!=s){const e=r.getTokenAfter(o);e?.value!==s&&(d=d.slice(0,g)+s+d.slice(g))}return{range:m,text:d}},isComma:function(e){return"Punctuator"===e.type&&","===e.value}}}(),i=0,a={default:1,namespace:2,named:3},s={default:4,namespace:5,named:6},u={default:7,namespace:8,named:9},y=0,h=1,C=2,S=3,v=99;return d={meta:{fixable:"code",messages:{incorrectOrder:"Requires should be sorted alphabetically, with at least one line between imports/requires and code"}},create(l){const c=l.getSourceCode(),p=function(e){const t=r(e);if(null!=t)return t;const n=e.getSourceCode().ast,o=n.body.length>0?n.body[0]:n,i=e.getSourceCode().getCommentsBefore(o)[0];return i&&"Block"===i.type?i:null}(l);if(p&&(p.value.includes("* @generated")||p.value.includes("* @partially-generated")))return{};const f=Object.freeze({typeImport:{priority:10,uppercase:[],lowercase:[],tiebreakFunction:b},valueImport:{priority:20,uppercase:[],lowercase:[],tiebreakFunction:b},requiresUsedByOtherRequires:{priority:30,uppercase:[],lowercase:[],tiebreakFunction:E},require:{priority:40,uppercase:[],lowercase:[],tiebreakFunction:E}}),m=[];let d=null,g=null;const x=new Set;return{Program(e){for(const t of e.body)switch(t.type){case"ImportDeclaration":if("type"===t.importKind||"typeof"===t.importKind)w(f.typeImport,t,t.source.value,!0);else{const e=c.getLastToken(t.source,(e=>"from"===e.value));0===t.specifiers.length&&null==e?O(t):w(f.valueImport,t,t.source.value)}break;case"VariableDeclaration":{const e=t.declarations[0]?.init;if(1!==t.declarations.length||null==e){O(t);break}T(e,t);break}default:O(t)}const t=[];for(const e of Object.keys(f)){const n=f[e];t.push({priority:n.priority,nodes:n.uppercase.sort(((e,t)=>I(e,t,n.tiebreakFunction)))}),t.push({priority:n.priority+5,nodes:n.lowercase.sort(((e,t)=>I(e,t,n.tiebreakFunction)))})}function n(e){return[e.leadingComments.length?e.leadingComments.map((e=>c.getText(e))).join("\n")+"\n":"",e.inlineComments.length?" "+e.inlineComments.map((e=>c.getText(e))).join(" "):""]}let r=t.filter((e=>0!==e.nodes.length)).sort(((e,t)=>e.priority-t.priority)).map((e=>e.nodes.map((e=>{const[t,r]=n(e),i=function(e,t){const n=t.node,r=e.getText(n),i=(()=>{if("ImportDeclaration"===n.type&&null!=n.specifiers.find((e=>"ImportSpecifier"===e.type))){const t=e.getFirstToken(n,(e=>"Punctuator"===e.type&&"{"===e.value)),r=e.getFirstToken(n,(e=>"Punctuator"===e.type&&"}"===e.value));return null==t||null==r?null:e.getText().substring(t.range[0],r.range[1])}if("VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type){const t=n.declarations[0].id.typeAnnotation,r=e.getText(n.declarations[0].id);return t?r.substr(0,t.range[0]-n.declarations[0].id.range[0]):r}return null})();if(null==i)return r;let a=[],l=null;"ImportDeclaration"===n.type?a=n.specifiers.map((t=>"ImportDefaultSpecifier"===t.type||"ImportNamespaceSpecifier"===t.type?null:{leadingComments:e.getCommentsBefore(t),name:t.imported.name,node:t})).filter(Boolean):"VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type&&(a=n.declarations[0].id.properties.map((t=>{if("ExperimentalRestProperty"===t.type||"RestElement"===t.type)return l=t,null;const n=t.key,r="Literal"===n.type?String(n.value):"Identifier"===n.type?t.computed?null:n.name:null;return null==r?null:{leadingComments:e.getCommentsBefore(t),name:r,node:t}})).filter(Boolean));if(a.length<=1)return r;const s=i.indexOf("\n")>=0,u=a.sort(((e,t)=>o(e.name,t.name))).map((e=>e.node));null!=l&&u.push(l);const c=u.map((t=>{const n=e.getCommentsBefore(t).map((t=>e.getText(t))),r=n.length?n.join(""):"";return s?(r?" "+r+"\n":"")+" "+e.getText(t):(r?r+" ":"")+e.getText(t)})),p=(()=>{const t=[];if("ImportDeclaration"===n.type){if(t.push(...e.getCommentsBefore(n.source)),s&&null!=n.specifiers.find((e=>"ImportSpecifier"===e.type))){const r=e.getTokenBefore(n.source,(e=>"Punctuator"===e.type&&"}"===e.value));null!=r&&t.push(...e.getCommentsBefore(r))}}else if("VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type){const r=e.getLastToken(n.declarations[0].id);null!=r&&t.push(...e.getCommentsBefore(r))}return t})(),f=s&&p.length?p.map((t=>" "+e.getText(t))).join("\n")+"\n":"",m=s?"\n"+c.map((e=>e.includes("...")?`${e}\n`:`${e},\n`)).join("")+f:c.join(", ");return r.replace(i,(()=>`{${m}}`))}(c,e);return t+i+r})).join("\n"))).join("\n\n");const i=d;if(null==i||null==g)return;const a=i.leadingComments.length?i.leadingComments[0].range[0]:i.node.range[0],s=g.inlineComments.length>0?g.inlineComments[g.inlineComments.length-1].range[1]:g.node.range[1],u=c.getText(i.node,i.node.range[0]-a,s-i.node.range[1]),p=g?.node;if(null!=p){const t=e.body.indexOf(p),n=e.body[t+1];null!=n&&n.loc.start.line-p.loc.end.line===1&&(r+="\n")}u!==r&&l.report({node:i.node,messageId:"incorrectOrder",fix(e){const t=m.filter((({node:e})=>e.range[0]>=a&&e.range[1]<=s)).map((e=>{const[t,r]=n(e),o=c.getText(e.node);return{range:e.node.range,text:t+o+r}})).flat().concat(c.getAllComments().filter((e=>e.range[0]>=a&&e.range[1]<=s&&!x.has(e))).map((e=>({range:e.range,text:c.getText(e)})))).sort(((e,t)=>e.range[0]-t.range[0]||e.range[1]-t.range[1])).map((({text:e})=>e)).join("\n");return e.replaceTextRange([a,s],[r,t].filter(Boolean).join("\n\n"))}})}};function b(e){if(0===e.specifiers.length)return i;const t=(()=>{switch(e.importKind){default:case"value":return a;case"type":return s;case"typeof":return u}})();return e.specifiers.find((e=>"ImportDefaultSpecifier"===e.type))?t.default:e.specifiers.find((e=>"ImportNamespaceSpecifier"===e.type))?t.namespace:t.named}function E(e){if("ExpressionStatement"===e.type)return y;switch(e.declarations[0].id.type){case"Identifier":return h;case"ObjectPattern":return C;case"ArrayPattern":return S}return v}function I(e,t,n){const r=o(e.moduleName,t.moduleName);if(0!==r)return r;const i=n(e.node)-n(t.node);return 0!==i?i:e.node.loc.start.line-t.node.loc.start.line}function D(e,t){if(null==e)throw new Error("Missing required module name");return null!=t?`${e}_${t}`:e}function T(t,n,r){const o=e.getRequireModuleName(t);if(e.isRequire(t)){const e=D(o,r);w("requireCond"===e||"requireDeferred"===e||"requireDeferredForDisplay"===e?f.requiresUsedByOtherRequires:f.require,n,D(o,r))}else if(e.isRequireDeferred(t)||e.isRequireDeferredForDisplay(t))w(f.require,n,D(o,r));else{if(e.isRequireCond(t)){if("VariableDeclaration"===n.type){const e=c.getText(n.declarations[0].id);return void w(f.require,n,D(e,r))}}else{if("MemberExpression"===t.type)return void T(t.object,n,D(c.getText(t.property),r));if("CallExpression"===t.type)return void T(t.callee,n,r)}O(n)}}function R(e){e.leadingComments.forEach((e=>x.add(e))),e.inlineComments.forEach((e=>x.add(e)));c.getCommentsInside(e.node).forEach((e=>x.add(e)))}function w(e,r,o,i=!1){const a={inlineComments:t(c,r),leadingComments:n(c,r,p),moduleName:o,node:r};if(i)e.uppercase.push(a);else{const t=o[0]||"";t.toLowerCase()===t?e.lowercase.push(a):e.uppercase.push(a)}null==d&&(d=a),g=a,R(a)}function O(e){const r={inlineComments:t(c,e),leadingComments:n(c,e,p),node:e};m.push(r),R(r)}}},d}var S=i(function(){if(h)return y;h=1;const e=C();return y=e}());module.exports=S;