@khanacademy/eslint-plugin
Advanced tools
Comparing version 3.1.0 to 3.1.1
# @khanacademy/eslint-plugin | ||
## 3.1.1 | ||
### Patch Changes | ||
- afc8d77: Update error message for `aphrodite-add-style-variable-name` rule | ||
## 3.1.0 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import{ESLintUtils as e,AST_NODE_TYPES as t}from"@typescript-eslint/utils";import*as r from"path";import*as n from"fs";import{execSync as a}from"child_process";import*as o from"@babel/types";var s=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"array-type-style",meta:{docs:{description:"Prefer Array<T> to T[]",recommended:!1},fixable:"code",messages:{errorString:"Shorthand syntax for array types can appear ambiguous. Please use the long-form: Array<>"},schema:[],type:"problem"},create(e){var t=e.getSourceCode();return{TSArrayType(r){e.report({fix(e){var n=r.elementType,a=t.text.slice(...n.range),o="Array<".concat(a,">");return e.replaceText(r,o)},node:r,messageId:"errorString"})}}},defaultOptions:[]}),i=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md"))),c=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(null==e)return!1;var n=e.arguments[r];if(n&&(n.type===t.ArrowFunctionExpression||n.type===t.FunctionExpression)&&n.body.type===t.BlockStatement)for(var a of n.body.body)if(a.type===t.ExpressionStatement){var o=a.expression;if(o.type===t.CallExpression&&o.callee.type===t.MemberExpression){var{object:s,property:i}=o.callee;if(s.type===t.Identifier&&"jest"===s.name&&i.type===t.Identifier&&"useRealTimers"===i.name)return!0}}return!1},l=i({name:"jest-async-use-real-timers",meta:{docs:{description:"Require a call to jest.useRealTimers() before or in all async tests.",recommended:!1},messages:{errorString:"Async tests require jest.useRealTimers()."},schema:[],type:"problem"},create(e){var r=[];return{CallExpression(n){var a;n.callee.type===t.Identifier&&"describe"===n.callee.name?r.push(c((e=>{var r=e.arguments[1];if(r&&(r.type===t.ArrowFunctionExpression||r.type===t.FunctionExpression)&&r.body.type===t.BlockStatement)for(var n of r.body.body)if(n.type===t.ExpressionStatement){var a=n.expression;if(a.type===t.CallExpression&&a.callee.type===t.Identifier&&"beforeEach"===a.callee.name)return a}return null})(n),0)):n.callee.type===t.Identifier&&"it"===n.callee.name&&((a=n.arguments[1]).type===t.ArrowFunctionExpression&&a.async||a.type===t.FunctionExpression&&a.async)&&r.length>0&&(r.some(Boolean)||c(n,1)||e.report({node:n,messageId:"errorString"}))},"CallExpression:exit"(e){e.callee.type===t.Identifier&&"describe"===e.callee.name&&r.pop()}}},defaultOptions:[]}),p=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md"))),m=e=>(null==e?void 0:e.type)!==t.MemberExpression?[]:e.property.type===t.Identifier?[e.property.name,...m(e.parent)]:[],d=e=>{var r;return(null==e?void 0:e.type)===t.Program?null:(null==e||null===(r=e.parent)||void 0===r?void 0:r.type)===t.CallExpression?e.parent:d(null==e?void 0:e.parent)},u=["resolves","rejects","toResolve","toReject"],g=p({name:"jest-await-async-matchers",meta:{docs:{description:"",recommended:!1},messages:{asyncMatchers:"Assertions using `{{matchers}}` should be awaited."},fixable:"code",schema:[{type:"object",properties:{matchers:{type:"array",items:{type:"string"}}},additionalProperties:!1}],type:"problem"},create(e,r){var[{matchers:n}]=r,a=[...u,...n];return{CallExpression(r){var n,o;if(r.callee.type===t.Identifier&&"expect"===r.callee.name&&(null===(n=r.parent)||void 0===n?void 0:n.type)===t.MemberExpression&&r.parent.property.type===t.Identifier){var s,i=m(r.parent),c=(s=a,i.filter((e=>s.includes(e))));if(0!==c.length){var l=d(r);l&&(null==l||null===(o=l.parent)||void 0===o?void 0:o.type)!==t.AwaitExpression&&e.report({node:l,messageId:"asyncMatchers",data:{matchers:c},fix:e=>e.insertTextBefore(l,"await ")})}}}}},defaultOptions:[{matchers:[]}]}),f=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"no-one-tuple",meta:{docs:{description:"Disallow one-tuple",recommended:!1},fixable:"code",messages:{errorString:"One-tuples can be confused with shorthand syntax for array types. Using Array<> avoids this confusion."},schema:[],type:"problem"},create(e){var t=e.getSourceCode();return{TSTupleType(r){1===r.elementTypes.length&&e.report({fix(e){var n=r.elementTypes[0],a=t.text.slice(...n.range),o="Array<".concat(a,">");return e.replaceText(r,o)},node:r,messageId:"errorString"})}}},defaultOptions:[]}),y=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"react-no-method-jsx-attribute",meta:{docs:{description:"Ensure that methods aren't used as jsx attributes",recommended:!1},messages:{errorMessage:"Methods cannot be passed as props, use a class property instead."},schema:[],type:"problem"},create(e){var r=new Map,n=new Map;return{ClassDeclaration(e){for(var a of e.body.body)a.type===t.PropertyDefinition&&"Identifier"===a.key.type?n.set(a.key.name,a):"MethodDefinition"===a.type&&"method"===a.kind&&"Identifier"===a.key.type&&r.set(a.key.name,a)},"ClassDeclaration:exit"(e){for(var a of e.body.body)a.type===t.PropertyDefinition&&"Identifier"===a.key.type?n.delete(a.key.name):"MethodDefinition"===a.type&&"method"===a.kind&&"Identifier"===a.key.type&&r.delete(a.key.name)},JSXAttribute(t){var{value:n}=t;if(n&&"JSXExpressionContainer"===n.type){var{expression:a}=n;if("MemberExpression"===a.type){var{object:o,property:s}=a;if("ThisExpression"===o.type&&"Identifier"===s.type){var{name:i}=s;r.has(i)&&e.report({node:r.get(i),messageId:"errorMessage"})}}}}}},defaultOptions:[]});function h(e,r){return!!e&&e.type===t.Identifier}function v(e,r){return r?(null==e?void 0:e.type)===t.JSXIdentifier&&e.name===r.name:(null==e?void 0:e.type)===t.JSXIdentifier}var b=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md"))),x=["then","catch","addEventListener","setTimeout","setInterval"],E=["constructor","componentWillMount"],w=b({name:"react-no-subscriptions-before-mount",meta:{docs:{description:"Avoid subscriptions in `constructor` and `componentWillMount`",recommended:!1},messages:{errorMessage:"Subscriptions (eg. event listeners) should not be set before the component has mounted. This is to avoid firing them on the server, as well as to ensure compatibility with React 16.\n\nPlease consider moving this subscription to `componentDidMount`."},schema:[],type:"problem"},create:e=>({CallExpression(r){var n=function(e){return(null==e?void 0:e.type)===t.MemberExpression}(r.callee)?r.callee.property:r.callee;if(h(n)&&x.includes(n.name)){var a=e.getAncestors().reverse().find((e=>"MethodDefinition"===e.type));if(a)return h(a.key)&&E.includes(a.key.name)?e.report({node:r,messageId:"errorMessage"}):void 0}}}),defaultOptions:[]}),S=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"react-svg-path-precision",meta:{docs:{description:"Ensure that SVG paths don't use too many decimal places",recommended:!1},fixable:"code",messages:{errorMessage:"This path contains numbers with too many decimal places."},schema:[{type:"object",properties:{precision:{type:"number"}},additionalProperties:!1}],type:"problem"},create(e,r){var[{precision:n}]=r,a="\\d*\\.\\d{".concat(n,",}\\d+"),o=new RegExp(a,"g");return{JSXAttribute(r){if(function(e){return(null==e?void 0:e.type)===t.JSXAttribute}(r)&&v(r.name,{name:"d"})&&function(e){return(null==e?void 0:e.type)===t.JSXOpeningElement}(r.parent)&&v(r.parent.name,{name:"path"})&&function(e){return(null==e?void 0:e.type)===t.Literal}(r.value)){var a=r.value,s=a.value;o.test(s)&&e.report({fix(e){var t=s.replace(o,(e=>parseFloat(e).toFixed(n)));return e.replaceText(a,'"'.concat(t,'"'))},node:r,messageId:"errorMessage"})}}}},defaultOptions:[{precision:2}]}),k=new Map;const I="No such marker found from given starting location";var T=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md"))),j=function e(t,a){return function(e,t){if(!r.isAbsolute(e))throw new Error("From path must be absolute");const a=[];let o=null;for(;null==o;){const s=`${e}:${t}`;a.push(s);const i=k.get(s);if(null!=i){o=i;continue}if(k.has(s))throw new Error(I);const c=r.dirname(e);if(c===e||null==c){for(const e of a)k.set(e,null);throw new Error(I)}const l=r.join(c,t);if(n.existsSync(l)){for(const e of a)k.set(e,c);o=c}else e=c}return o}(t=t||e(__dirname),a=a||"package.json")}(__dirname),C=r.join(j,"node_modules",".bin","checksync"),M=(e,t,r,n)=>{if(e.reason&&e.location)if(e.fix){var a=e.fix,o=n.find((e=>e.loc.start.line===a.line));o&&r.report({node:o,messageId:"reason",data:{reason:e.reason},fix:e=>((e,t)=>{var{tagToFix:r,fix:n}=t;switch(n.type){case"replace":return e.replaceText(r,n.text);case"delete":return e.remove(r);default:throw new Error("Unknown fix type ".concat(n.type))}})(e,{tagToFix:o,fix:a})})}else{var s=e.location,i=n.find((e=>e.loc.start.line===s.line));i&&r.report({node:i,messageId:"reason",data:{reason:e.reason}})}else e.message?r.report({node:t,messageId:"reasonAndReminder",data:{reason:e.reason,reminder:"If necessary, check the sync-tag target and make relevant changes before updating the checksum."}}):console.error("Unknown item type ".concat(e.type))},F=(e,t)=>{var{configFile:n,ignoreFiles:o,rootDir:s}=e,i=((e,t)=>{var{configFile:n,ignoreFiles:a,rootDir:o}=e,s=a?"--ignore-files ".concat(a):"",i=n?"--config ".concat(r.join(o,n)):"";return"".concat(C," ").concat(t," ").concat(i," ").concat(s," --json")})({configFile:n,ignoreFiles:o,rootDir:s},t);try{return a(i,{cwd:s,encoding:"utf-8"})}catch(e){if(3===e.status)return e.stdout;throw e}},A=T({name:"sync-tag",meta:{docs:{description:"Ensure sync tags are valid",recommended:!1},fixable:"code",messages:{reason:"{{reason}}",reasonAndReminder:"{{reason}} {{reminder}}"},schema:[{type:"object",properties:{ignoreFiles:{type:"array",items:{type:"string"}},rootDir:{type:"string"},configFile:{type:"string"}}}],type:"problem"},create(e){var t=e.options[0].configFile,n=(e.options[0].ignoreFiles||[]).join(","),a=e.options[0].rootDir;if(!a)throw new Error("rootDir must be set");return{Program(o){var s,i,c=null!==(s=null===(i=o.comments)||void 0===i?void 0:i.filter((e=>e.value.trim().startsWith("sync-start:"))))&&void 0!==s?s:[];if(c.length>0){var l=r.relative(a,e.getFilename()),p=F({configFile:t,ignoreFiles:n,rootDir:a},l);try{var m=JSON.parse(p),d=Object.keys(m.files).find((e=>l.endsWith(e)));d&&((e,t,r,n)=>{for(var a of e)M(a,t,r,n)})(m.files[d],o,e,c)}catch(e){return void console.error(e)}}}}},defaultOptions:[{ignoreFiles:[],configFile:"",rootDir:""}]});var R={"array-type-style":s,"jest-async-use-real-timers":l,"jest-await-async-matchers":g,"no-one-tuple":f,"ts-no-error-suppressions":e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"ts-no-error-suppressions",meta:{docs:{description:"Disallow @ts-expect-error and @ts-ignore certain node types",recommended:!1},fixable:"code",messages:{errorString:"{{type}} not allowed on JSXAttributes"},schema:[],type:"problem"},create(e){var t;return{Program(e){var r;t=(null!==(r=e.comments)&&void 0!==r?r:[]).filter((e=>e.value.trim().startsWith("@ts-")))},JSXOpeningElement(r){var n=function(t){if(r.range[0]<t.range[0]&&r.range[1]>t.range[1]&&r.attributes.every((e=>function(e,t){var[r,n]=e,[a,o]=t;return n<a||r>o}(e.range,t.range)))){var n=t.value.match(/@ts-[a-zA-Z-]+/);e.report({fix(e){var[r,n]=t.range;return e.removeRange([r,n+1])},node:t,messageId:"errorString",data:{type:null!=n?n:"TypeScript error suppression"}})}};for(var a of t)n(a)}}},defaultOptions:[]}),"react-no-method-jsx-attribute":y,"react-no-subscriptions-before-mount":w,"react-svg-path-precision":S,"sync-tag":A,"jest-enzyme-matchers":{meta:{docs:{description:"Requires the use more of enzyme matchers where appropriate.",category:"jest",recommended:!1},fixable:!0},create:e=>({CallExpression(t){if(o.isIdentifier(t.callee,{name:"expect"})&&o.isCallExpression(t.arguments[0])&&o.isMemberExpression(t.arguments[0].callee)&&o.isMemberExpression(t.parent)&&o.isIdentifier(t.parent.property)&&o.isCallExpression(t.parent.parent)){var{property:r}=t.arguments[0].callee,n=t.parent.property.name;if("toEqual"===n){if(o.isIdentifier(r,{name:"prop"})){var a=e.getSource(),s=t.arguments[0].arguments[0],i=a.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toHaveProp(".concat(s.raw,", ").concat(i,") instead."),fix(e){var r=a.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toHaveProp(").concat(s.raw,", ").concat(i,")");return e.replaceText(t.parent.parent,n)}})}else if(o.isIdentifier(r,{name:"state"})){var c=e.getSource(),l=t.arguments[0].arguments[0],p=c.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toHaveState(".concat(l.raw,", ").concat(p,") instead."),fix(e){var r=c.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toHaveState(").concat(l.raw,", ").concat(p,")");return e.replaceText(t.parent.parent,n)}})}else if(o.isIdentifier(r,{name:"text"})){var m=e.getSource(),d=m.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toHaveText(".concat(d,") instead."),fix(e){var r=m.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toHaveText(").concat(d,")");return e.replaceText(t.parent.parent,n)}})}else if(o.isIdentifier(r,{name:"html"})){var u=e.getSource(),g=u.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toHaveHTML(".concat(g,") instead."),fix(e){var r=u.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toHaveHTML(").concat(g,")");return e.replaceText(t.parent.parent,n)}})}}else if("toBeTrue"===n||"toBeTruthy"===n){if(o.isIdentifier(r,{name:"exists"}))if(0===t.arguments[0].arguments.length){var f=e.getSource();e.report({node:t,message:"Use .toExist() instead.",fix(e){var r=f.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toExist()");return e.replaceText(t.parent.parent,n)}})}else{var y=e.getSource(),h=y.slice(...t.arguments[0].arguments[0].range);e.report({node:t,message:"Use .toContainMatchingElement(".concat(h,") instead."),fix(e){var r=y.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toContainMatchingElement(").concat(h,")");return e.replaceText(t.parent.parent,n)}})}}else if("toBeFalse"===n||"toBeFalsy"===n){if(o.isIdentifier(r,{name:"exists"}))if(0===t.arguments[0].arguments.length){var v=e.getSource();e.report({node:t,message:"Use .not.toExist() instead.",fix(e){var r=v.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").not.toExist()");return e.replaceText(t.parent.parent,n)}})}else{var b=e.getSource(),x=b.slice(...t.arguments[0].arguments[0].range);e.report({node:t,message:"Use .not.toContainMatchingElement(".concat(x,") instead."),fix(e){var r=b.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").not.toContainMatchingElement(").concat(x,")");return e.replaceText(t.parent.parent,n)}})}}else if("toHaveLength"===n&&o.isIdentifier(r,{name:"find"})){var E=e.getSource(),w=E.slice(...t.arguments[0].arguments[0].range),S=E.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toContainMatchingElements(".concat(S,", ").concat(w,") instead."),fix(e){var r=E.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toContainMatchingElements(").concat(S,", ").concat(w,")");return e.replaceText(t.parent.parent,n)}})}}}})},"aphrodite-add-style-variable-name":e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"aphrodite-add-style-variable-name",meta:{docs:{description:"Variable name should match the tag name passed into addStyle and follow the format: StyledTag (ie. StyledDiv, StyledImg)",recommended:!0},messages:{errorString:'Variable name "{{ variableName }}" does not match tag name "{{ tagName }}". Variable name should be "{{ expectedName }}"'},schema:[],type:"problem"},defaultOptions:[],create:e=>({VariableDeclarator(r){var n;if((null===(n=r.init)||void 0===n?void 0:n.type)===t.CallExpression&&r.init.callee.type===t.Identifier&&"addStyle"===r.init.callee.name){var a=r.id.type===t.Identifier?r.id.name:null;if(null!==a){var o=r.init.arguments[0];if((null==o?void 0:o.type)===t.Literal&&"string"==typeof o.value){var s,i=o.value,c="Styled".concat(/^[A-Z][a-zA-Z]*$/.test(s=i)?s:s.split(/[_\-\s]+/).map((e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""));a!==c&&e.report({node:r.id,messageId:"errorString",data:{variableName:a,tagName:i,expectedName:c}})}}}}})})};export{R as rules}; | ||
import{ESLintUtils as e,AST_NODE_TYPES as t}from"@typescript-eslint/utils";import*as r from"path";import*as n from"fs";import{execSync as a}from"child_process";import*as o from"@babel/types";var s=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"array-type-style",meta:{docs:{description:"Prefer Array<T> to T[]",recommended:!1},fixable:"code",messages:{errorString:"Shorthand syntax for array types can appear ambiguous. Please use the long-form: Array<>"},schema:[],type:"problem"},create(e){var t=e.getSourceCode();return{TSArrayType(r){e.report({fix(e){var n=r.elementType,a=t.text.slice(...n.range),o="Array<".concat(a,">");return e.replaceText(r,o)},node:r,messageId:"errorString"})}}},defaultOptions:[]}),i=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md"))),c=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(null==e)return!1;var n=e.arguments[r];if(n&&(n.type===t.ArrowFunctionExpression||n.type===t.FunctionExpression)&&n.body.type===t.BlockStatement)for(var a of n.body.body)if(a.type===t.ExpressionStatement){var o=a.expression;if(o.type===t.CallExpression&&o.callee.type===t.MemberExpression){var{object:s,property:i}=o.callee;if(s.type===t.Identifier&&"jest"===s.name&&i.type===t.Identifier&&"useRealTimers"===i.name)return!0}}return!1},l=i({name:"jest-async-use-real-timers",meta:{docs:{description:"Require a call to jest.useRealTimers() before or in all async tests.",recommended:!1},messages:{errorString:"Async tests require jest.useRealTimers()."},schema:[],type:"problem"},create(e){var r=[];return{CallExpression(n){var a;n.callee.type===t.Identifier&&"describe"===n.callee.name?r.push(c((e=>{var r=e.arguments[1];if(r&&(r.type===t.ArrowFunctionExpression||r.type===t.FunctionExpression)&&r.body.type===t.BlockStatement)for(var n of r.body.body)if(n.type===t.ExpressionStatement){var a=n.expression;if(a.type===t.CallExpression&&a.callee.type===t.Identifier&&"beforeEach"===a.callee.name)return a}return null})(n),0)):n.callee.type===t.Identifier&&"it"===n.callee.name&&((a=n.arguments[1]).type===t.ArrowFunctionExpression&&a.async||a.type===t.FunctionExpression&&a.async)&&r.length>0&&(r.some(Boolean)||c(n,1)||e.report({node:n,messageId:"errorString"}))},"CallExpression:exit"(e){e.callee.type===t.Identifier&&"describe"===e.callee.name&&r.pop()}}},defaultOptions:[]}),p=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md"))),m=e=>(null==e?void 0:e.type)!==t.MemberExpression?[]:e.property.type===t.Identifier?[e.property.name,...m(e.parent)]:[],d=e=>{var r;return(null==e?void 0:e.type)===t.Program?null:(null==e||null===(r=e.parent)||void 0===r?void 0:r.type)===t.CallExpression?e.parent:d(null==e?void 0:e.parent)},u=["resolves","rejects","toResolve","toReject"],g=p({name:"jest-await-async-matchers",meta:{docs:{description:"",recommended:!1},messages:{asyncMatchers:"Assertions using `{{matchers}}` should be awaited."},fixable:"code",schema:[{type:"object",properties:{matchers:{type:"array",items:{type:"string"}}},additionalProperties:!1}],type:"problem"},create(e,r){var[{matchers:n}]=r,a=[...u,...n];return{CallExpression(r){var n,o;if(r.callee.type===t.Identifier&&"expect"===r.callee.name&&(null===(n=r.parent)||void 0===n?void 0:n.type)===t.MemberExpression&&r.parent.property.type===t.Identifier){var s,i=m(r.parent),c=(s=a,i.filter((e=>s.includes(e))));if(0!==c.length){var l=d(r);l&&(null==l||null===(o=l.parent)||void 0===o?void 0:o.type)!==t.AwaitExpression&&e.report({node:l,messageId:"asyncMatchers",data:{matchers:c},fix:e=>e.insertTextBefore(l,"await ")})}}}}},defaultOptions:[{matchers:[]}]}),f=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"no-one-tuple",meta:{docs:{description:"Disallow one-tuple",recommended:!1},fixable:"code",messages:{errorString:"One-tuples can be confused with shorthand syntax for array types. Using Array<> avoids this confusion."},schema:[],type:"problem"},create(e){var t=e.getSourceCode();return{TSTupleType(r){1===r.elementTypes.length&&e.report({fix(e){var n=r.elementTypes[0],a=t.text.slice(...n.range),o="Array<".concat(a,">");return e.replaceText(r,o)},node:r,messageId:"errorString"})}}},defaultOptions:[]}),y=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"react-no-method-jsx-attribute",meta:{docs:{description:"Ensure that methods aren't used as jsx attributes",recommended:!1},messages:{errorMessage:"Methods cannot be passed as props, use a class property instead."},schema:[],type:"problem"},create(e){var r=new Map,n=new Map;return{ClassDeclaration(e){for(var a of e.body.body)a.type===t.PropertyDefinition&&"Identifier"===a.key.type?n.set(a.key.name,a):"MethodDefinition"===a.type&&"method"===a.kind&&"Identifier"===a.key.type&&r.set(a.key.name,a)},"ClassDeclaration:exit"(e){for(var a of e.body.body)a.type===t.PropertyDefinition&&"Identifier"===a.key.type?n.delete(a.key.name):"MethodDefinition"===a.type&&"method"===a.kind&&"Identifier"===a.key.type&&r.delete(a.key.name)},JSXAttribute(t){var{value:n}=t;if(n&&"JSXExpressionContainer"===n.type){var{expression:a}=n;if("MemberExpression"===a.type){var{object:o,property:s}=a;if("ThisExpression"===o.type&&"Identifier"===s.type){var{name:i}=s;r.has(i)&&e.report({node:r.get(i),messageId:"errorMessage"})}}}}}},defaultOptions:[]});function h(e,r){return!!e&&e.type===t.Identifier}function v(e,r){return r?(null==e?void 0:e.type)===t.JSXIdentifier&&e.name===r.name:(null==e?void 0:e.type)===t.JSXIdentifier}var b=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md"))),x=["then","catch","addEventListener","setTimeout","setInterval"],E=["constructor","componentWillMount"],w=b({name:"react-no-subscriptions-before-mount",meta:{docs:{description:"Avoid subscriptions in `constructor` and `componentWillMount`",recommended:!1},messages:{errorMessage:"Subscriptions (eg. event listeners) should not be set before the component has mounted. This is to avoid firing them on the server, as well as to ensure compatibility with React 16.\n\nPlease consider moving this subscription to `componentDidMount`."},schema:[],type:"problem"},create:e=>({CallExpression(r){var n=function(e){return(null==e?void 0:e.type)===t.MemberExpression}(r.callee)?r.callee.property:r.callee;if(h(n)&&x.includes(n.name)){var a=e.getAncestors().reverse().find((e=>"MethodDefinition"===e.type));if(a)return h(a.key)&&E.includes(a.key.name)?e.report({node:r,messageId:"errorMessage"}):void 0}}}),defaultOptions:[]}),S=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"react-svg-path-precision",meta:{docs:{description:"Ensure that SVG paths don't use too many decimal places",recommended:!1},fixable:"code",messages:{errorMessage:"This path contains numbers with too many decimal places."},schema:[{type:"object",properties:{precision:{type:"number"}},additionalProperties:!1}],type:"problem"},create(e,r){var[{precision:n}]=r,a="\\d*\\.\\d{".concat(n,",}\\d+"),o=new RegExp(a,"g");return{JSXAttribute(r){if(function(e){return(null==e?void 0:e.type)===t.JSXAttribute}(r)&&v(r.name,{name:"d"})&&function(e){return(null==e?void 0:e.type)===t.JSXOpeningElement}(r.parent)&&v(r.parent.name,{name:"path"})&&function(e){return(null==e?void 0:e.type)===t.Literal}(r.value)){var a=r.value,s=a.value;o.test(s)&&e.report({fix(e){var t=s.replace(o,(e=>parseFloat(e).toFixed(n)));return e.replaceText(a,'"'.concat(t,'"'))},node:r,messageId:"errorMessage"})}}}},defaultOptions:[{precision:2}]}),k=new Map;const I="No such marker found from given starting location";var T=e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md"))),j=function e(t,a){return function(e,t){if(!r.isAbsolute(e))throw new Error("From path must be absolute");const a=[];let o=null;for(;null==o;){const s=`${e}:${t}`;a.push(s);const i=k.get(s);if(null!=i){o=i;continue}if(k.has(s))throw new Error(I);const c=r.dirname(e);if(c===e||null==c){for(const e of a)k.set(e,null);throw new Error(I)}const l=r.join(c,t);if(n.existsSync(l)){for(const e of a)k.set(e,c);o=c}else e=c}return o}(t=t||e(__dirname),a=a||"package.json")}(__dirname),C=r.join(j,"node_modules",".bin","checksync"),M=(e,t,r,n)=>{if(e.reason&&e.location)if(e.fix){var a=e.fix,o=n.find((e=>e.loc.start.line===a.line));o&&r.report({node:o,messageId:"reason",data:{reason:e.reason},fix:e=>((e,t)=>{var{tagToFix:r,fix:n}=t;switch(n.type){case"replace":return e.replaceText(r,n.text);case"delete":return e.remove(r);default:throw new Error("Unknown fix type ".concat(n.type))}})(e,{tagToFix:o,fix:a})})}else{var s=e.location,i=n.find((e=>e.loc.start.line===s.line));i&&r.report({node:i,messageId:"reason",data:{reason:e.reason}})}else e.message?r.report({node:t,messageId:"reasonAndReminder",data:{reason:e.reason,reminder:"If necessary, check the sync-tag target and make relevant changes before updating the checksum."}}):console.error("Unknown item type ".concat(e.type))},F=(e,t)=>{var{configFile:n,ignoreFiles:o,rootDir:s}=e,i=((e,t)=>{var{configFile:n,ignoreFiles:a,rootDir:o}=e,s=a?"--ignore-files ".concat(a):"",i=n?"--config ".concat(r.join(o,n)):"";return"".concat(C," ").concat(t," ").concat(i," ").concat(s," --json")})({configFile:n,ignoreFiles:o,rootDir:s},t);try{return a(i,{cwd:s,encoding:"utf-8"})}catch(e){if(3===e.status)return e.stdout;throw e}},A=T({name:"sync-tag",meta:{docs:{description:"Ensure sync tags are valid",recommended:!1},fixable:"code",messages:{reason:"{{reason}}",reasonAndReminder:"{{reason}} {{reminder}}"},schema:[{type:"object",properties:{ignoreFiles:{type:"array",items:{type:"string"}},rootDir:{type:"string"},configFile:{type:"string"}}}],type:"problem"},create(e){var t=e.options[0].configFile,n=(e.options[0].ignoreFiles||[]).join(","),a=e.options[0].rootDir;if(!a)throw new Error("rootDir must be set");return{Program(o){var s,i,c=null!==(s=null===(i=o.comments)||void 0===i?void 0:i.filter((e=>e.value.trim().startsWith("sync-start:"))))&&void 0!==s?s:[];if(c.length>0){var l=r.relative(a,e.getFilename()),p=F({configFile:t,ignoreFiles:n,rootDir:a},l);try{var m=JSON.parse(p),d=Object.keys(m.files).find((e=>l.endsWith(e)));d&&((e,t,r,n)=>{for(var a of e)M(a,t,r,n)})(m.files[d],o,e,c)}catch(e){return void console.error(e)}}}}},defaultOptions:[{ignoreFiles:[],configFile:"",rootDir:""}]});var R={"array-type-style":s,"jest-async-use-real-timers":l,"jest-await-async-matchers":g,"no-one-tuple":f,"ts-no-error-suppressions":e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"ts-no-error-suppressions",meta:{docs:{description:"Disallow @ts-expect-error and @ts-ignore certain node types",recommended:!1},fixable:"code",messages:{errorString:"{{type}} not allowed on JSXAttributes"},schema:[],type:"problem"},create(e){var t;return{Program(e){var r;t=(null!==(r=e.comments)&&void 0!==r?r:[]).filter((e=>e.value.trim().startsWith("@ts-")))},JSXOpeningElement(r){var n=function(t){if(r.range[0]<t.range[0]&&r.range[1]>t.range[1]&&r.attributes.every((e=>function(e,t){var[r,n]=e,[a,o]=t;return n<a||r>o}(e.range,t.range)))){var n=t.value.match(/@ts-[a-zA-Z-]+/);e.report({fix(e){var[r,n]=t.range;return e.removeRange([r,n+1])},node:t,messageId:"errorString",data:{type:null!=n?n:"TypeScript error suppression"}})}};for(var a of t)n(a)}}},defaultOptions:[]}),"react-no-method-jsx-attribute":y,"react-no-subscriptions-before-mount":w,"react-svg-path-precision":S,"sync-tag":A,"jest-enzyme-matchers":{meta:{docs:{description:"Requires the use more of enzyme matchers where appropriate.",category:"jest",recommended:!1},fixable:!0},create:e=>({CallExpression(t){if(o.isIdentifier(t.callee,{name:"expect"})&&o.isCallExpression(t.arguments[0])&&o.isMemberExpression(t.arguments[0].callee)&&o.isMemberExpression(t.parent)&&o.isIdentifier(t.parent.property)&&o.isCallExpression(t.parent.parent)){var{property:r}=t.arguments[0].callee,n=t.parent.property.name;if("toEqual"===n){if(o.isIdentifier(r,{name:"prop"})){var a=e.getSource(),s=t.arguments[0].arguments[0],i=a.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toHaveProp(".concat(s.raw,", ").concat(i,") instead."),fix(e){var r=a.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toHaveProp(").concat(s.raw,", ").concat(i,")");return e.replaceText(t.parent.parent,n)}})}else if(o.isIdentifier(r,{name:"state"})){var c=e.getSource(),l=t.arguments[0].arguments[0],p=c.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toHaveState(".concat(l.raw,", ").concat(p,") instead."),fix(e){var r=c.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toHaveState(").concat(l.raw,", ").concat(p,")");return e.replaceText(t.parent.parent,n)}})}else if(o.isIdentifier(r,{name:"text"})){var m=e.getSource(),d=m.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toHaveText(".concat(d,") instead."),fix(e){var r=m.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toHaveText(").concat(d,")");return e.replaceText(t.parent.parent,n)}})}else if(o.isIdentifier(r,{name:"html"})){var u=e.getSource(),g=u.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toHaveHTML(".concat(g,") instead."),fix(e){var r=u.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toHaveHTML(").concat(g,")");return e.replaceText(t.parent.parent,n)}})}}else if("toBeTrue"===n||"toBeTruthy"===n){if(o.isIdentifier(r,{name:"exists"}))if(0===t.arguments[0].arguments.length){var f=e.getSource();e.report({node:t,message:"Use .toExist() instead.",fix(e){var r=f.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toExist()");return e.replaceText(t.parent.parent,n)}})}else{var y=e.getSource(),h=y.slice(...t.arguments[0].arguments[0].range);e.report({node:t,message:"Use .toContainMatchingElement(".concat(h,") instead."),fix(e){var r=y.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toContainMatchingElement(").concat(h,")");return e.replaceText(t.parent.parent,n)}})}}else if("toBeFalse"===n||"toBeFalsy"===n){if(o.isIdentifier(r,{name:"exists"}))if(0===t.arguments[0].arguments.length){var v=e.getSource();e.report({node:t,message:"Use .not.toExist() instead.",fix(e){var r=v.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").not.toExist()");return e.replaceText(t.parent.parent,n)}})}else{var b=e.getSource(),x=b.slice(...t.arguments[0].arguments[0].range);e.report({node:t,message:"Use .not.toContainMatchingElement(".concat(x,") instead."),fix(e){var r=b.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").not.toContainMatchingElement(").concat(x,")");return e.replaceText(t.parent.parent,n)}})}}else if("toHaveLength"===n&&o.isIdentifier(r,{name:"find"})){var E=e.getSource(),w=E.slice(...t.arguments[0].arguments[0].range),S=E.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:"Use .toContainMatchingElements(".concat(S,", ").concat(w,") instead."),fix(e){var r=E.slice(...t.arguments[0].callee.object.range),n="expect(".concat(r,").toContainMatchingElements(").concat(S,", ").concat(w,")");return e.replaceText(t.parent.parent,n)}})}}}})},"aphrodite-add-style-variable-name":e.RuleCreator((e=>"https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/".concat(e,".md")))({name:"aphrodite-add-style-variable-name",meta:{docs:{description:"Variable name should match the tag name passed into addStyle and follow the format: StyledTag (ie. StyledDiv, StyledImg)",recommended:!0},messages:{errorString:'Variable name "{{ variableName }}" does not match the expected naming convention. Expected: "{{ expectedName }}"'},schema:[],type:"problem"},defaultOptions:[],create:e=>({VariableDeclarator(r){var n;if((null===(n=r.init)||void 0===n?void 0:n.type)===t.CallExpression&&r.init.callee.type===t.Identifier&&"addStyle"===r.init.callee.name){var a=r.id.type===t.Identifier?r.id.name:null;if(null!==a){var o=r.init.arguments[0];if((null==o?void 0:o.type)===t.Literal&&"string"==typeof o.value){var s,i=o.value,c="Styled".concat(/^[A-Z][a-zA-Z]*$/.test(s=i)?s:s.split(/[_\-\s]+/).map((e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join(""));a!==c&&e.report({node:r.id,messageId:"errorString",data:{variableName:a,expectedName:c}})}}}}})})};export{R as rules}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var e=require("@typescript-eslint/utils"),t=require("path"),r=require("fs"),n=require("child_process"),s=require("@babel/types");function a(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var o=a(t),i=a(r),c=a(s);var l=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"array-type-style",meta:{docs:{description:"Prefer Array<T> to T[]",recommended:!1},fixable:"code",messages:{errorString:"Shorthand syntax for array types can appear ambiguous. Please use the long-form: Array<>"},schema:[],type:"problem"},create(e){const t=e.getSourceCode();return{TSArrayType(r){e.report({fix(e){const n=r.elementType,s=`Array<${t.text.slice(...n.range)}>`;return e.replaceText(r,s)},node:r,messageId:"errorString"})}}},defaultOptions:[]});const p=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`)),m=(t,r=0)=>{if(null==t)return!1;const n=t.arguments[r];if(n&&(n.type===e.AST_NODE_TYPES.ArrowFunctionExpression||n.type===e.AST_NODE_TYPES.FunctionExpression)&&n.body.type===e.AST_NODE_TYPES.BlockStatement)for(const t of n.body.body)if(t.type===e.AST_NODE_TYPES.ExpressionStatement){const r=t.expression;if(r.type===e.AST_NODE_TYPES.CallExpression&&r.callee.type===e.AST_NODE_TYPES.MemberExpression){const{object:t,property:n}=r.callee;if(t.type===e.AST_NODE_TYPES.Identifier&&"jest"===t.name&&n.type===e.AST_NODE_TYPES.Identifier&&"useRealTimers"===n.name)return!0}}return!1};var d=p({name:"jest-async-use-real-timers",meta:{docs:{description:"Require a call to jest.useRealTimers() before or in all async tests.",recommended:!1},messages:{errorString:"Async tests require jest.useRealTimers()."},schema:[],type:"problem"},create(t){const r=[];return{CallExpression(n){n.callee.type===e.AST_NODE_TYPES.Identifier&&"describe"===n.callee.name?r.push(m((t=>{const r=t.arguments[1];if(r&&(r.type===e.AST_NODE_TYPES.ArrowFunctionExpression||r.type===e.AST_NODE_TYPES.FunctionExpression)&&r.body.type===e.AST_NODE_TYPES.BlockStatement)for(const t of r.body.body)if(t.type===e.AST_NODE_TYPES.ExpressionStatement){const r=t.expression;if(r.type===e.AST_NODE_TYPES.CallExpression&&r.callee.type===e.AST_NODE_TYPES.Identifier&&"beforeEach"===r.callee.name)return r}return null})(n),0)):n.callee.type===e.AST_NODE_TYPES.Identifier&&"it"===n.callee.name&&(t=>{const r=t.arguments[1];return r.type===e.AST_NODE_TYPES.ArrowFunctionExpression&&r.async||r.type===e.AST_NODE_TYPES.FunctionExpression&&r.async})(n)&&r.length>0&&(r.some(Boolean)||m(n,1)||t.report({node:n,messageId:"errorString"}))},"CallExpression:exit"(t){t.callee.type===e.AST_NODE_TYPES.Identifier&&"describe"===t.callee.name&&r.pop()}}},defaultOptions:[]});const u=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`)),g=t=>t?.type!==e.AST_NODE_TYPES.MemberExpression?[]:t.property.type===e.AST_NODE_TYPES.Identifier?[t.property.name,...g(t.parent)]:[],f=t=>t?.type===e.AST_NODE_TYPES.Program?null:t?.parent?.type===e.AST_NODE_TYPES.CallExpression?t.parent:f(t?.parent),y=["resolves","rejects","toResolve","toReject"];var h=u({name:"jest-await-async-matchers",meta:{docs:{description:"",recommended:!1},messages:{asyncMatchers:"Assertions using `{{matchers}}` should be awaited."},fixable:"code",schema:[{type:"object",properties:{matchers:{type:"array",items:{type:"string"}}},additionalProperties:!1}],type:"problem"},create(t,[{matchers:r}]){const n=[...y,...r];return{CallExpression(r){if(r.callee.type!==e.AST_NODE_TYPES.Identifier||"expect"!==r.callee.name)return;if(r.parent?.type!==e.AST_NODE_TYPES.MemberExpression)return;if(r.parent.property.type!==e.AST_NODE_TYPES.Identifier)return;const s=g(r.parent),a=(o=n,s.filter((e=>o.includes(e))));var o;if(0===a.length)return;const i=f(r);i&&i?.parent?.type!==e.AST_NODE_TYPES.AwaitExpression&&t.report({node:i,messageId:"asyncMatchers",data:{matchers:a},fix:e=>e.insertTextBefore(i,"await ")})}}},defaultOptions:[{matchers:[]}]});var E=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"no-one-tuple",meta:{docs:{description:"Disallow one-tuple",recommended:!1},fixable:"code",messages:{errorString:"One-tuples can be confused with shorthand syntax for array types. Using Array<> avoids this confusion."},schema:[],type:"problem"},create(e){const t=e.getSourceCode();return{TSTupleType(r){1===r.elementTypes.length&&e.report({fix(e){const n=r.elementTypes[0],s=`Array<${t.text.slice(...n.range)}>`;return e.replaceText(r,s)},node:r,messageId:"errorString"})}}},defaultOptions:[]});var S=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"react-no-method-jsx-attribute",meta:{docs:{description:"Ensure that methods aren't used as jsx attributes",recommended:!1},messages:{errorMessage:"Methods cannot be passed as props, use a class property instead."},schema:[],type:"problem"},create(t){const r=new Map,n=new Map;return{ClassDeclaration(t){for(const s of t.body.body)s.type===e.AST_NODE_TYPES.PropertyDefinition&&"Identifier"===s.key.type?n.set(s.key.name,s):"MethodDefinition"===s.type&&"method"===s.kind&&"Identifier"===s.key.type&&r.set(s.key.name,s)},"ClassDeclaration:exit"(t){for(const s of t.body.body)s.type===e.AST_NODE_TYPES.PropertyDefinition&&"Identifier"===s.key.type?n.delete(s.key.name):"MethodDefinition"===s.type&&"method"===s.kind&&"Identifier"===s.key.type&&r.delete(s.key.name)},JSXAttribute(e){const{value:n}=e;if(n&&"JSXExpressionContainer"===n.type){const{expression:e}=n;if("MemberExpression"===e.type){const{object:n,property:s}=e;if("ThisExpression"===n.type&&"Identifier"===s.type){const{name:e}=s;r.has(e)&&t.report({node:r.get(e),messageId:"errorMessage"})}}}}}},defaultOptions:[]});function b(t,r){return!!t&&t.type===e.AST_NODE_TYPES.Identifier}function T(t,r){return r?t?.type===e.AST_NODE_TYPES.JSXIdentifier&&t.name===r.name:t?.type===e.AST_NODE_TYPES.JSXIdentifier}const x=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`)),_=["then","catch","addEventListener","setTimeout","setInterval"],A=["constructor","componentWillMount"];var D=x({name:"react-no-subscriptions-before-mount",meta:{docs:{description:"Avoid subscriptions in `constructor` and `componentWillMount`",recommended:!1},messages:{errorMessage:"Subscriptions (eg. event listeners) should not be set before the component has mounted. This is to avoid firing them on the server, as well as to ensure compatibility with React 16.\n\nPlease consider moving this subscription to `componentDidMount`."},schema:[],type:"problem"},create:t=>({CallExpression(r){const n=function(t){return t?.type===e.AST_NODE_TYPES.MemberExpression}(r.callee)?r.callee.property:r.callee;if(!b(n)||!_.includes(n.name))return;const s=t.getAncestors().reverse().find((e=>"MethodDefinition"===e.type));return s&&b(s.key)&&A.includes(s.key.name)?t.report({node:r,messageId:"errorMessage"}):void 0}}),defaultOptions:[]});var O=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"react-svg-path-precision",meta:{docs:{description:"Ensure that SVG paths don't use too many decimal places",recommended:!1},fixable:"code",messages:{errorMessage:"This path contains numbers with too many decimal places."},schema:[{type:"object",properties:{precision:{type:"number"}},additionalProperties:!1}],type:"problem"},create(t,[{precision:r}]){const n=new RegExp(`\\d*\\.\\d{${r},}\\d+`,"g");return{JSXAttribute(s){if(function(t){return t?.type===e.AST_NODE_TYPES.JSXAttribute}(s)&&T(s.name,{name:"d"})&&function(t){return t?.type===e.AST_NODE_TYPES.JSXOpeningElement}(s.parent)&&T(s.parent.name,{name:"path"})&&function(t){return t?.type===e.AST_NODE_TYPES.Literal}(s.value)){const e=s.value,a=e.value;n.test(a)&&t.report({fix(t){const s=a.replace(n,(e=>parseFloat(e).toFixed(r)));return t.replaceText(e,`"${s}"`)},node:s,messageId:"errorMessage"})}}}},defaultOptions:[{precision:2}]}),v=new Map;const $="No such marker found from given starting location";const P=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`)),w=function e(t,r){return function(e,t){if(!o.isAbsolute(e))throw new Error("From path must be absolute");const r=[];let n=null;for(;null==n;){const s=`${e}:${t}`;r.push(s);const a=v.get(s);if(null!=a){n=a;continue}if(v.has(s))throw new Error($);const c=o.dirname(e);if(c===e||null==c){for(const e of r)v.set(e,null);throw new Error($)}const l=o.join(c,t);if(i.existsSync(l)){for(const e of r)v.set(e,c);n=c}else e=c}return n}(t=t||e(__dirname),r=r||"package.json")}(__dirname),N=o.join(w,"node_modules",".bin","checksync"),k=(e,t,r,n)=>{if(e.reason&&e.location)if(e.fix){const t=e.fix,s=n.find((e=>e.loc.start.line===t.line));s&&r.report({node:s,messageId:"reason",data:{reason:e.reason},fix:e=>((e,{tagToFix:t,fix:r})=>{switch(r.type){case"replace":return e.replaceText(t,r.text);case"delete":return e.remove(t);default:throw new Error(`Unknown fix type ${r.type}`)}})(e,{tagToFix:s,fix:t})})}else{const t=e.location,s=n.find((e=>e.loc.start.line===t.line));s&&r.report({node:s,messageId:"reason",data:{reason:e.reason}})}else e.message?r.report({node:t,messageId:"reasonAndReminder",data:{reason:e.reason,reminder:"If necessary, check the sync-tag target and make relevant changes before updating the checksum."}}):console.error(`Unknown item type ${e.type}`)},I=({configFile:e,ignoreFiles:t,rootDir:r},s)=>{const a=(({configFile:e,ignoreFiles:t,rootDir:r},n)=>{const s=t?`--ignore-files ${t}`:"",a=e?`--config ${o.join(r,e)}`:"";return`${N} ${n} ${a} ${s} --json`})({configFile:e,ignoreFiles:t,rootDir:r},s);try{return n.execSync(a,{cwd:r,encoding:"utf-8"})}catch(e){if(3===e.status)return e.stdout;throw e}};var j=P({name:"sync-tag",meta:{docs:{description:"Ensure sync tags are valid",recommended:!1},fixable:"code",messages:{reason:"{{reason}}",reasonAndReminder:"{{reason}} {{reminder}}"},schema:[{type:"object",properties:{ignoreFiles:{type:"array",items:{type:"string"}},rootDir:{type:"string"},configFile:{type:"string"}}}],type:"problem"},create(e){const t=e.options[0].configFile,r=(e.options[0].ignoreFiles||[]).join(","),n=e.options[0].rootDir;if(!n)throw new Error("rootDir must be set");return{Program(s){const a=s.comments?.filter((e=>e.value.trim().startsWith("sync-start:")))??[];if(a.length>0){const i=o.relative(n,e.getFilename()),c=I({configFile:t,ignoreFiles:r,rootDir:n},i);try{const t=JSON.parse(c),r=Object.keys(t.files).find((e=>i.endsWith(e)));r&&((e,t,r,n)=>{for(const s of e)k(s,t,r,n)})(t.files[r],s,e,a)}catch(e){return void console.error(e)}}}}},defaultOptions:[{ignoreFiles:[],configFile:"",rootDir:""}]});function Y(e,t){const[r,n]=e,[s,a]=t;return n<s||r>a}var C={"array-type-style":l,"jest-async-use-real-timers":d,"jest-await-async-matchers":h,"no-one-tuple":E,"ts-no-error-suppressions":e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"ts-no-error-suppressions",meta:{docs:{description:"Disallow @ts-expect-error and @ts-ignore certain node types",recommended:!1},fixable:"code",messages:{errorString:"{{type}} not allowed on JSXAttributes"},schema:[],type:"problem"},create(e){let t;return{Program(e){t=(e.comments??[]).filter((e=>e.value.trim().startsWith("@ts-")))},JSXOpeningElement(r){for(const n of t)if(r.range[0]<n.range[0]&&r.range[1]>n.range[1]&&r.attributes.every((e=>Y(e.range,n.range)))){const t=n.value.match(/@ts-[a-zA-Z-]+/);e.report({fix(e){const[t,r]=n.range;return e.removeRange([t,r+1])},node:n,messageId:"errorString",data:{type:t??"TypeScript error suppression"}})}}}},defaultOptions:[]}),"react-no-method-jsx-attribute":S,"react-no-subscriptions-before-mount":D,"react-svg-path-precision":O,"sync-tag":j,"jest-enzyme-matchers":{meta:{docs:{description:"Requires the use more of enzyme matchers where appropriate.",category:"jest",recommended:!1},fixable:!0},create:e=>({CallExpression(t){if(c.isIdentifier(t.callee,{name:"expect"})&&c.isCallExpression(t.arguments[0])&&c.isMemberExpression(t.arguments[0].callee)&&c.isMemberExpression(t.parent)&&c.isIdentifier(t.parent.property)&&c.isCallExpression(t.parent.parent)){const{property:r}=t.arguments[0].callee,n=t.parent.property.name;if("toEqual"===n){if(c.isIdentifier(r,{name:"prop"})){const r=e.getSource(),n=t.arguments[0].arguments[0],s=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toHaveProp(${n.raw}, ${s}) instead.`,fix(e){const a=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toHaveProp(${n.raw}, ${s})`;return e.replaceText(t.parent.parent,a)}})}else if(c.isIdentifier(r,{name:"state"})){const r=e.getSource(),n=t.arguments[0].arguments[0],s=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toHaveState(${n.raw}, ${s}) instead.`,fix(e){const a=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toHaveState(${n.raw}, ${s})`;return e.replaceText(t.parent.parent,a)}})}else if(c.isIdentifier(r,{name:"text"})){const r=e.getSource(),n=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toHaveText(${n}) instead.`,fix(e){const s=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toHaveText(${n})`;return e.replaceText(t.parent.parent,s)}})}else if(c.isIdentifier(r,{name:"html"})){const r=e.getSource(),n=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toHaveHTML(${n}) instead.`,fix(e){const s=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toHaveHTML(${n})`;return e.replaceText(t.parent.parent,s)}})}}else if("toBeTrue"===n||"toBeTruthy"===n){if(c.isIdentifier(r,{name:"exists"}))if(0===t.arguments[0].arguments.length){const r=e.getSource();e.report({node:t,message:"Use .toExist() instead.",fix(e){const n=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toExist()`;return e.replaceText(t.parent.parent,n)}})}else{const r=e.getSource(),n=r.slice(...t.arguments[0].arguments[0].range);e.report({node:t,message:`Use .toContainMatchingElement(${n}) instead.`,fix(e){const s=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toContainMatchingElement(${n})`;return e.replaceText(t.parent.parent,s)}})}}else if("toBeFalse"===n||"toBeFalsy"===n){if(c.isIdentifier(r,{name:"exists"}))if(0===t.arguments[0].arguments.length){const r=e.getSource();e.report({node:t,message:"Use .not.toExist() instead.",fix(e){const n=`expect(${r.slice(...t.arguments[0].callee.object.range)}).not.toExist()`;return e.replaceText(t.parent.parent,n)}})}else{const r=e.getSource(),n=r.slice(...t.arguments[0].arguments[0].range);e.report({node:t,message:`Use .not.toContainMatchingElement(${n}) instead.`,fix(e){const s=`expect(${r.slice(...t.arguments[0].callee.object.range)}).not.toContainMatchingElement(${n})`;return e.replaceText(t.parent.parent,s)}})}}else if("toHaveLength"===n&&c.isIdentifier(r,{name:"find"})){const r=e.getSource(),n=r.slice(...t.arguments[0].arguments[0].range),s=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toContainMatchingElements(${s}, ${n}) instead.`,fix(e){const a=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toContainMatchingElements(${s}, ${n})`;return e.replaceText(t.parent.parent,a)}})}}}})},"aphrodite-add-style-variable-name":e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"aphrodite-add-style-variable-name",meta:{docs:{description:"Variable name should match the tag name passed into addStyle and follow the format: StyledTag (ie. StyledDiv, StyledImg)",recommended:!0},messages:{errorString:'Variable name "{{ variableName }}" does not match tag name "{{ tagName }}". Variable name should be "{{ expectedName }}"'},schema:[],type:"problem"},defaultOptions:[],create:t=>({VariableDeclarator(r){if(r.init?.type!==e.AST_NODE_TYPES.CallExpression)return;if(r.init.callee.type!==e.AST_NODE_TYPES.Identifier||"addStyle"!==r.init.callee.name)return;const n=r.id.type===e.AST_NODE_TYPES.Identifier?r.id.name:null;if(null===n)return;const s=r.init.arguments[0];if(s?.type!==e.AST_NODE_TYPES.Literal||"string"!=typeof s.value)return;const a=s.value,o=`Styled${i=a,/^[A-Z][a-zA-Z]*$/.test(i)?i:i.split(/[_\-\s]+/).map((e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join("")}`;var i;n!==o&&t.report({node:r.id,messageId:"errorString",data:{variableName:n,tagName:a,expectedName:o}})}})})};exports.rules=C; | ||
"use strict";var e=require("@typescript-eslint/utils"),t=require("path"),r=require("fs"),n=require("child_process"),s=require("@babel/types");function a(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var o=a(t),i=a(r),c=a(s);var p=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"array-type-style",meta:{docs:{description:"Prefer Array<T> to T[]",recommended:!1},fixable:"code",messages:{errorString:"Shorthand syntax for array types can appear ambiguous. Please use the long-form: Array<>"},schema:[],type:"problem"},create(e){const t=e.getSourceCode();return{TSArrayType(r){e.report({fix(e){const n=r.elementType,s=`Array<${t.text.slice(...n.range)}>`;return e.replaceText(r,s)},node:r,messageId:"errorString"})}}},defaultOptions:[]});const l=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`)),m=(t,r=0)=>{if(null==t)return!1;const n=t.arguments[r];if(n&&(n.type===e.AST_NODE_TYPES.ArrowFunctionExpression||n.type===e.AST_NODE_TYPES.FunctionExpression)&&n.body.type===e.AST_NODE_TYPES.BlockStatement)for(const t of n.body.body)if(t.type===e.AST_NODE_TYPES.ExpressionStatement){const r=t.expression;if(r.type===e.AST_NODE_TYPES.CallExpression&&r.callee.type===e.AST_NODE_TYPES.MemberExpression){const{object:t,property:n}=r.callee;if(t.type===e.AST_NODE_TYPES.Identifier&&"jest"===t.name&&n.type===e.AST_NODE_TYPES.Identifier&&"useRealTimers"===n.name)return!0}}return!1};var d=l({name:"jest-async-use-real-timers",meta:{docs:{description:"Require a call to jest.useRealTimers() before or in all async tests.",recommended:!1},messages:{errorString:"Async tests require jest.useRealTimers()."},schema:[],type:"problem"},create(t){const r=[];return{CallExpression(n){n.callee.type===e.AST_NODE_TYPES.Identifier&&"describe"===n.callee.name?r.push(m((t=>{const r=t.arguments[1];if(r&&(r.type===e.AST_NODE_TYPES.ArrowFunctionExpression||r.type===e.AST_NODE_TYPES.FunctionExpression)&&r.body.type===e.AST_NODE_TYPES.BlockStatement)for(const t of r.body.body)if(t.type===e.AST_NODE_TYPES.ExpressionStatement){const r=t.expression;if(r.type===e.AST_NODE_TYPES.CallExpression&&r.callee.type===e.AST_NODE_TYPES.Identifier&&"beforeEach"===r.callee.name)return r}return null})(n),0)):n.callee.type===e.AST_NODE_TYPES.Identifier&&"it"===n.callee.name&&(t=>{const r=t.arguments[1];return r.type===e.AST_NODE_TYPES.ArrowFunctionExpression&&r.async||r.type===e.AST_NODE_TYPES.FunctionExpression&&r.async})(n)&&r.length>0&&(r.some(Boolean)||m(n,1)||t.report({node:n,messageId:"errorString"}))},"CallExpression:exit"(t){t.callee.type===e.AST_NODE_TYPES.Identifier&&"describe"===t.callee.name&&r.pop()}}},defaultOptions:[]});const u=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`)),g=t=>t?.type!==e.AST_NODE_TYPES.MemberExpression?[]:t.property.type===e.AST_NODE_TYPES.Identifier?[t.property.name,...g(t.parent)]:[],f=t=>t?.type===e.AST_NODE_TYPES.Program?null:t?.parent?.type===e.AST_NODE_TYPES.CallExpression?t.parent:f(t?.parent),y=["resolves","rejects","toResolve","toReject"];var h=u({name:"jest-await-async-matchers",meta:{docs:{description:"",recommended:!1},messages:{asyncMatchers:"Assertions using `{{matchers}}` should be awaited."},fixable:"code",schema:[{type:"object",properties:{matchers:{type:"array",items:{type:"string"}}},additionalProperties:!1}],type:"problem"},create(t,[{matchers:r}]){const n=[...y,...r];return{CallExpression(r){if(r.callee.type!==e.AST_NODE_TYPES.Identifier||"expect"!==r.callee.name)return;if(r.parent?.type!==e.AST_NODE_TYPES.MemberExpression)return;if(r.parent.property.type!==e.AST_NODE_TYPES.Identifier)return;const s=g(r.parent),a=(o=n,s.filter((e=>o.includes(e))));var o;if(0===a.length)return;const i=f(r);i&&i?.parent?.type!==e.AST_NODE_TYPES.AwaitExpression&&t.report({node:i,messageId:"asyncMatchers",data:{matchers:a},fix:e=>e.insertTextBefore(i,"await ")})}}},defaultOptions:[{matchers:[]}]});var E=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"no-one-tuple",meta:{docs:{description:"Disallow one-tuple",recommended:!1},fixable:"code",messages:{errorString:"One-tuples can be confused with shorthand syntax for array types. Using Array<> avoids this confusion."},schema:[],type:"problem"},create(e){const t=e.getSourceCode();return{TSTupleType(r){1===r.elementTypes.length&&e.report({fix(e){const n=r.elementTypes[0],s=`Array<${t.text.slice(...n.range)}>`;return e.replaceText(r,s)},node:r,messageId:"errorString"})}}},defaultOptions:[]});var S=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"react-no-method-jsx-attribute",meta:{docs:{description:"Ensure that methods aren't used as jsx attributes",recommended:!1},messages:{errorMessage:"Methods cannot be passed as props, use a class property instead."},schema:[],type:"problem"},create(t){const r=new Map,n=new Map;return{ClassDeclaration(t){for(const s of t.body.body)s.type===e.AST_NODE_TYPES.PropertyDefinition&&"Identifier"===s.key.type?n.set(s.key.name,s):"MethodDefinition"===s.type&&"method"===s.kind&&"Identifier"===s.key.type&&r.set(s.key.name,s)},"ClassDeclaration:exit"(t){for(const s of t.body.body)s.type===e.AST_NODE_TYPES.PropertyDefinition&&"Identifier"===s.key.type?n.delete(s.key.name):"MethodDefinition"===s.type&&"method"===s.kind&&"Identifier"===s.key.type&&r.delete(s.key.name)},JSXAttribute(e){const{value:n}=e;if(n&&"JSXExpressionContainer"===n.type){const{expression:e}=n;if("MemberExpression"===e.type){const{object:n,property:s}=e;if("ThisExpression"===n.type&&"Identifier"===s.type){const{name:e}=s;r.has(e)&&t.report({node:r.get(e),messageId:"errorMessage"})}}}}}},defaultOptions:[]});function b(t,r){return!!t&&t.type===e.AST_NODE_TYPES.Identifier}function T(t,r){return r?t?.type===e.AST_NODE_TYPES.JSXIdentifier&&t.name===r.name:t?.type===e.AST_NODE_TYPES.JSXIdentifier}const x=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`)),_=["then","catch","addEventListener","setTimeout","setInterval"],A=["constructor","componentWillMount"];var v=x({name:"react-no-subscriptions-before-mount",meta:{docs:{description:"Avoid subscriptions in `constructor` and `componentWillMount`",recommended:!1},messages:{errorMessage:"Subscriptions (eg. event listeners) should not be set before the component has mounted. This is to avoid firing them on the server, as well as to ensure compatibility with React 16.\n\nPlease consider moving this subscription to `componentDidMount`."},schema:[],type:"problem"},create:t=>({CallExpression(r){const n=function(t){return t?.type===e.AST_NODE_TYPES.MemberExpression}(r.callee)?r.callee.property:r.callee;if(!b(n)||!_.includes(n.name))return;const s=t.getAncestors().reverse().find((e=>"MethodDefinition"===e.type));return s&&b(s.key)&&A.includes(s.key.name)?t.report({node:r,messageId:"errorMessage"}):void 0}}),defaultOptions:[]});var D=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"react-svg-path-precision",meta:{docs:{description:"Ensure that SVG paths don't use too many decimal places",recommended:!1},fixable:"code",messages:{errorMessage:"This path contains numbers with too many decimal places."},schema:[{type:"object",properties:{precision:{type:"number"}},additionalProperties:!1}],type:"problem"},create(t,[{precision:r}]){const n=new RegExp(`\\d*\\.\\d{${r},}\\d+`,"g");return{JSXAttribute(s){if(function(t){return t?.type===e.AST_NODE_TYPES.JSXAttribute}(s)&&T(s.name,{name:"d"})&&function(t){return t?.type===e.AST_NODE_TYPES.JSXOpeningElement}(s.parent)&&T(s.parent.name,{name:"path"})&&function(t){return t?.type===e.AST_NODE_TYPES.Literal}(s.value)){const e=s.value,a=e.value;n.test(a)&&t.report({fix(t){const s=a.replace(n,(e=>parseFloat(e).toFixed(r)));return t.replaceText(e,`"${s}"`)},node:s,messageId:"errorMessage"})}}}},defaultOptions:[{precision:2}]}),O=new Map;const $="No such marker found from given starting location";const P=e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`)),w=function e(t,r){return function(e,t){if(!o.isAbsolute(e))throw new Error("From path must be absolute");const r=[];let n=null;for(;null==n;){const s=`${e}:${t}`;r.push(s);const a=O.get(s);if(null!=a){n=a;continue}if(O.has(s))throw new Error($);const c=o.dirname(e);if(c===e||null==c){for(const e of r)O.set(e,null);throw new Error($)}const p=o.join(c,t);if(i.existsSync(p)){for(const e of r)O.set(e,c);n=c}else e=c}return n}(t=t||e(__dirname),r=r||"package.json")}(__dirname),N=o.join(w,"node_modules",".bin","checksync"),k=(e,t,r,n)=>{if(e.reason&&e.location)if(e.fix){const t=e.fix,s=n.find((e=>e.loc.start.line===t.line));s&&r.report({node:s,messageId:"reason",data:{reason:e.reason},fix:e=>((e,{tagToFix:t,fix:r})=>{switch(r.type){case"replace":return e.replaceText(t,r.text);case"delete":return e.remove(t);default:throw new Error(`Unknown fix type ${r.type}`)}})(e,{tagToFix:s,fix:t})})}else{const t=e.location,s=n.find((e=>e.loc.start.line===t.line));s&&r.report({node:s,messageId:"reason",data:{reason:e.reason}})}else e.message?r.report({node:t,messageId:"reasonAndReminder",data:{reason:e.reason,reminder:"If necessary, check the sync-tag target and make relevant changes before updating the checksum."}}):console.error(`Unknown item type ${e.type}`)},I=({configFile:e,ignoreFiles:t,rootDir:r},s)=>{const a=(({configFile:e,ignoreFiles:t,rootDir:r},n)=>{const s=t?`--ignore-files ${t}`:"",a=e?`--config ${o.join(r,e)}`:"";return`${N} ${n} ${a} ${s} --json`})({configFile:e,ignoreFiles:t,rootDir:r},s);try{return n.execSync(a,{cwd:r,encoding:"utf-8"})}catch(e){if(3===e.status)return e.stdout;throw e}};var j=P({name:"sync-tag",meta:{docs:{description:"Ensure sync tags are valid",recommended:!1},fixable:"code",messages:{reason:"{{reason}}",reasonAndReminder:"{{reason}} {{reminder}}"},schema:[{type:"object",properties:{ignoreFiles:{type:"array",items:{type:"string"}},rootDir:{type:"string"},configFile:{type:"string"}}}],type:"problem"},create(e){const t=e.options[0].configFile,r=(e.options[0].ignoreFiles||[]).join(","),n=e.options[0].rootDir;if(!n)throw new Error("rootDir must be set");return{Program(s){const a=s.comments?.filter((e=>e.value.trim().startsWith("sync-start:")))??[];if(a.length>0){const i=o.relative(n,e.getFilename()),c=I({configFile:t,ignoreFiles:r,rootDir:n},i);try{const t=JSON.parse(c),r=Object.keys(t.files).find((e=>i.endsWith(e)));r&&((e,t,r,n)=>{for(const s of e)k(s,t,r,n)})(t.files[r],s,e,a)}catch(e){return void console.error(e)}}}}},defaultOptions:[{ignoreFiles:[],configFile:"",rootDir:""}]});function Y(e,t){const[r,n]=e,[s,a]=t;return n<s||r>a}var C={"array-type-style":p,"jest-async-use-real-timers":d,"jest-await-async-matchers":h,"no-one-tuple":E,"ts-no-error-suppressions":e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"ts-no-error-suppressions",meta:{docs:{description:"Disallow @ts-expect-error and @ts-ignore certain node types",recommended:!1},fixable:"code",messages:{errorString:"{{type}} not allowed on JSXAttributes"},schema:[],type:"problem"},create(e){let t;return{Program(e){t=(e.comments??[]).filter((e=>e.value.trim().startsWith("@ts-")))},JSXOpeningElement(r){for(const n of t)if(r.range[0]<n.range[0]&&r.range[1]>n.range[1]&&r.attributes.every((e=>Y(e.range,n.range)))){const t=n.value.match(/@ts-[a-zA-Z-]+/);e.report({fix(e){const[t,r]=n.range;return e.removeRange([t,r+1])},node:n,messageId:"errorString",data:{type:t??"TypeScript error suppression"}})}}}},defaultOptions:[]}),"react-no-method-jsx-attribute":S,"react-no-subscriptions-before-mount":v,"react-svg-path-precision":D,"sync-tag":j,"jest-enzyme-matchers":{meta:{docs:{description:"Requires the use more of enzyme matchers where appropriate.",category:"jest",recommended:!1},fixable:!0},create:e=>({CallExpression(t){if(c.isIdentifier(t.callee,{name:"expect"})&&c.isCallExpression(t.arguments[0])&&c.isMemberExpression(t.arguments[0].callee)&&c.isMemberExpression(t.parent)&&c.isIdentifier(t.parent.property)&&c.isCallExpression(t.parent.parent)){const{property:r}=t.arguments[0].callee,n=t.parent.property.name;if("toEqual"===n){if(c.isIdentifier(r,{name:"prop"})){const r=e.getSource(),n=t.arguments[0].arguments[0],s=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toHaveProp(${n.raw}, ${s}) instead.`,fix(e){const a=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toHaveProp(${n.raw}, ${s})`;return e.replaceText(t.parent.parent,a)}})}else if(c.isIdentifier(r,{name:"state"})){const r=e.getSource(),n=t.arguments[0].arguments[0],s=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toHaveState(${n.raw}, ${s}) instead.`,fix(e){const a=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toHaveState(${n.raw}, ${s})`;return e.replaceText(t.parent.parent,a)}})}else if(c.isIdentifier(r,{name:"text"})){const r=e.getSource(),n=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toHaveText(${n}) instead.`,fix(e){const s=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toHaveText(${n})`;return e.replaceText(t.parent.parent,s)}})}else if(c.isIdentifier(r,{name:"html"})){const r=e.getSource(),n=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toHaveHTML(${n}) instead.`,fix(e){const s=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toHaveHTML(${n})`;return e.replaceText(t.parent.parent,s)}})}}else if("toBeTrue"===n||"toBeTruthy"===n){if(c.isIdentifier(r,{name:"exists"}))if(0===t.arguments[0].arguments.length){const r=e.getSource();e.report({node:t,message:"Use .toExist() instead.",fix(e){const n=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toExist()`;return e.replaceText(t.parent.parent,n)}})}else{const r=e.getSource(),n=r.slice(...t.arguments[0].arguments[0].range);e.report({node:t,message:`Use .toContainMatchingElement(${n}) instead.`,fix(e){const s=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toContainMatchingElement(${n})`;return e.replaceText(t.parent.parent,s)}})}}else if("toBeFalse"===n||"toBeFalsy"===n){if(c.isIdentifier(r,{name:"exists"}))if(0===t.arguments[0].arguments.length){const r=e.getSource();e.report({node:t,message:"Use .not.toExist() instead.",fix(e){const n=`expect(${r.slice(...t.arguments[0].callee.object.range)}).not.toExist()`;return e.replaceText(t.parent.parent,n)}})}else{const r=e.getSource(),n=r.slice(...t.arguments[0].arguments[0].range);e.report({node:t,message:`Use .not.toContainMatchingElement(${n}) instead.`,fix(e){const s=`expect(${r.slice(...t.arguments[0].callee.object.range)}).not.toContainMatchingElement(${n})`;return e.replaceText(t.parent.parent,s)}})}}else if("toHaveLength"===n&&c.isIdentifier(r,{name:"find"})){const r=e.getSource(),n=r.slice(...t.arguments[0].arguments[0].range),s=r.slice(...t.parent.parent.arguments[0].range);e.report({node:t,message:`Use .toContainMatchingElements(${s}, ${n}) instead.`,fix(e){const a=`expect(${r.slice(...t.arguments[0].callee.object.range)}).toContainMatchingElements(${s}, ${n})`;return e.replaceText(t.parent.parent,a)}})}}}})},"aphrodite-add-style-variable-name":e.ESLintUtils.RuleCreator((e=>`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${e}.md`))({name:"aphrodite-add-style-variable-name",meta:{docs:{description:"Variable name should match the tag name passed into addStyle and follow the format: StyledTag (ie. StyledDiv, StyledImg)",recommended:!0},messages:{errorString:'Variable name "{{ variableName }}" does not match the expected naming convention. Expected: "{{ expectedName }}"'},schema:[],type:"problem"},defaultOptions:[],create:t=>({VariableDeclarator(r){if(r.init?.type!==e.AST_NODE_TYPES.CallExpression)return;if(r.init.callee.type!==e.AST_NODE_TYPES.Identifier||"addStyle"!==r.init.callee.name)return;const n=r.id.type===e.AST_NODE_TYPES.Identifier?r.id.name:null;if(null===n)return;const s=r.init.arguments[0];if(s?.type!==e.AST_NODE_TYPES.Literal||"string"!=typeof s.value)return;const a=s.value,o=`Styled${i=a,/^[A-Z][a-zA-Z]*$/.test(i)?i:i.split(/[_\-\s]+/).map((e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join("")}`;var i;n!==o&&t.report({node:r.id,messageId:"errorString",data:{variableName:n,expectedName:o}})}})})};exports.rules=C; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@khanacademy/eslint-plugin", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "ESLint plugin that applies Khan Academy's custom rules", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
186786