eslint-plugin-qwik 0.17.1 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +1 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var D=Object.create;var x=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var M=(t,e)=>{for(var o in e)x(t,o,{get:e[o],enumerable:!0})},L=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _(e))!j.call(t,i)&&i!==o&&x(t,i,{get:()=>e[i],enumerable:!(n=X(e,i))||n.enumerable});return t};var U=(t,e,o)=>(o=t!=null?D(P(t)):{},L(e||!t||!t.__esModule?x(o,"default",{value:t,enumerable:!0}):o,t)),z=t=>L(x({},"__esModule",{value:!0}),t);var te={};M(te,{configs:()=>ee,rules:()=>K});module.exports=z(te);var C=require("@typescript-eslint/utils"),g=U(require("typescript")),B=C.ESLintUtils.RuleCreator(t=>`https://typescript-eslint.io/rules/${t}`),k=B({name:"valid-lexical-scope",defaultOptions:[{allowAny:!0}],meta:{type:"problem",docs:{description:"Used the tsc typechecker to detect the capture of unserializable data in dollar ($) scopes.",recommended:"error"},schema:[{type:"object",properties:{allowAny:{type:"boolean"}},default:{allowAny:!0}}],messages:{referencesOutside:'Identifier ("{{varName}}") can not be captured inside the scope ({{dollarName}}) because {{reason}}. Check out https://qwik.builder.io/docs/advanced/dollar/ for more details.',unvalidJsxDollar:"JSX attributes that end with $ can only take an inlined arrow function of a QRL identifier. Make sure the value is created using $()",mutableIdentifier:'The value of the identifier ("{{varName}}") can not be changed once it is captured the scope ({{dollarName}}). Check out https://qwik.builder.io/docs/advanced/dollar/ for more details.'}},create(t){var N;let o={allowAny:((N=t.options[0])==null?void 0:N.allowAny)??!0},n=t.getSourceCode().scopeManager,i=C.ESLintUtils.getParserServices(t),s=i.esTreeNodeToTSNodeMap,l=i.program.getTypeChecker(),m=new Map,A=[];function E(u){u.references.forEach(r=>{var y,b;let a=r.resolved,c=(y=r.resolved)==null?void 0:y.scope;if(a&&c){let d=(b=a.defs.at(0))==null?void 0:b.type;if(d==="Type"||d==="ImportBinding")return;let p=r.from,f;for(;p&&(f=m.get(p),!f);)p=p.upper;if(p&&f){let I=c.type;if(I==="global")return;if(I==="module"){let w=a.identifiers.length===1?a.identifiers[0]:r.identifier,q=s.get(w),R=l.getSymbolAtLocation(q);if(R&&A.includes(R))return;t.report({messageId:"referencesOutside",node:r.identifier,data:{varName:r.identifier.name,dollarName:f,reason:"it's declared at the root of the module and it is not exported. Add export"}});return}let h=r.identifier,$=s.get(h),S=c;for(;S&&!m.has(S);)S=S.upper;if(S!==p){h.parent&&h.parent.type==="AssignmentExpression"&&h.parent.left===h&&t.report({messageId:"mutableIdentifier",node:r.identifier,data:{varName:r.identifier.name,dollarName:f}});let w=Q(l,$,r.identifier,o);w&&t.report({messageId:"referencesOutside",node:r.identifier,data:{varName:r.identifier.name,dollarName:f,reason:W(w)}})}}}}),u.childScopes.forEach(E)}return{CallExpression(u){if(u.callee.type==="Identifier"&&u.callee.name.endsWith("$")){let r=u.arguments.at(0);if(r&&r.type==="ArrowFunctionExpression"){let a=n.acquire(r);a&&m.set(a,u.callee.name)}}},JSXAttribute(u){let r=u.name,a=r.type==="JSXIdentifier"?r.name:r.name.name;if(a.endsWith("$")){let c=u.value;if(c&&c.type==="JSXExpressionContainer"){let y=n.acquire(c.expression);if(y)m.set(y,a);else if(c.expression.type==="Identifier"){let b=s.get(c.expression),d=l.getTypeAtLocation(b);v(d)||t.report({messageId:"unvalidJsxDollar",node:c.expression})}}}},Program(u){let r=s.get(u),a=l.getSymbolAtLocation(r);a&&(A=l.getExportsOfModule(a))},"Program:exit"(){E(n.globalScope)}}}});function Q(t,e,o,n){let i=t.getTypeAtLocation(e);return V(t,i,e,o,n,new Set)}function W(t){let e="";return t.location?e+=`"${t.location}" `:e+="it ",e+=`${t.reason}`,e}function V(t,e,o,n,i,s){let l=T(t,e,o,i,0,s);if(l){let m=l.location;return m&&(l.location=`${n.name}.${m}`),l}return l}function T(t,e,o,n,i,s){if(s.has(e)||(s.add(e),e.getProperty("__no_serialize__")))return;if(e.flags&g.default.TypeFlags.Unknown)return{type:e,typeStr:t.typeToString(e),reason:"is unknown, which is not serializable"};let m=e.flags&g.default.TypeFlags.Any;if(!n.allowAny&&m)return{type:e,typeStr:t.typeToString(e),reason:"is any, which is not serializable"};if(e.flags&g.default.TypeFlags.BigIntLike)return{type:e,typeStr:t.typeToString(e),reason:"is BigInt and it is not supported yet, use a number instead"};if(e.flags&g.default.TypeFlags.ESSymbolLike)return{type:e,typeStr:t.typeToString(e),reason:"is Symbol, which is not serializable"};if(e.flags&g.default.TypeFlags.EnumLike)return{type:e,typeStr:t.typeToString(e),reason:"is an enum, use an string or a number instead"};if(v(e))return;if(e.getCallSignatures().length>0)return e.symbol.name==="PropFnInterface"?void 0:{type:e,typeStr:t.typeToString(e),reason:"is a function, which is not serializable"};if(e.isUnion()){for(let a of e.types){let c=T(t,a,o,n,i+1,s);if(c)return c}return}if((e.flags&g.default.TypeFlags.Object)!==0){let a=Z(e,t);if(a)return T(t,a,o,n,i+1,s);let c=G(e,t);if(c){for(let d of c){let p=T(t,d,o,n,i+1,s);if(p)return p}return}let y=e.symbol.name;if(e.getProperty("nextElementSibling")||e.getProperty("activeElement")||H[y])return;if(e.isClass())return{type:e,typeStr:t.typeToString(e),reason:`is an instance of the "${e.symbol.name}" class, which is not serializable. Use a simple object literal instead`};let b=e.getProperty("prototype");if(b){let d=t.getTypeOfSymbolAtLocation(b,o);if(d.isClass())return{type:d,typeStr:t.typeToString(d),reason:"is a class constructor, which is not serializable"}}if(!y.startsWith("__")&&e.symbol.valueDeclaration)return{type:e,typeStr:t.typeToString(e),reason:`is an instance of the "${e.symbol.name}" class, which is not serializable`};for(let d of e.getProperties()){let p=Y(t,d,o,n,i+1,s);if(p){let f=p.location;return p.location=`${d.name}${f?`.${f}`:""}`,p}}}}function Y(t,e,o,n,i,s){let l=t.getTypeOfSymbolAtLocation(e,o);return T(t,l,o,n,i,s)}function Z(t,e){return e.getElementTypeOfArrayType(t)}function G(t,e){return e.isTupleType(t)?e.getTypeArguments(t):void 0}function v(t){return!!(t.flags&g.default.TypeFlags.Any)||!!t.getProperty("__brand__QRL__")}var H={Promise:!0,URL:!0,RegExp:!0,Date:!0,FormData:!0,URLSearchParams:!0,Error:!0};var O={meta:{type:"problem",docs:{description:"Object destructuring is not recommended for component$",category:"Variables",recommended:!0,url:"https://github.com/BuilderIO/qwik"}},create(t){let e=[];return{ArrowFunctionExpression(){e.push({await:!1})},"ArrowFunctionExpression:exit"(){e.pop()},AwaitExpression(){let o=e[e.length-1];o&&(o.await=!0)},"CallExpression[callee.name=/^use[A-Z]/]"(o){let n=e[e.length-1];n&&n.await&&t.report({node:o,message:"Calling use* methods after await is not safe."})}}}};var F={meta:{type:"problem",docs:{description:"Detect multiple JSX roots inside a component",recommended:!0,url:"https://github.com/BuilderIO/qwik"},messages:{multipleJsxRoots:"Components in Qwik must have a single JSX root element. Your component has multiple roots on lines: {{lines}}. Rewrite your component with a single root such as (`return <>{...}</>`.) and keep all JSX within"}},create(t){let e=[];return{ArrowFunctionExpression(){e.push({rootNodes:[],depth:0})},"ArrowFunctionExpression:exit"(){let o=e[e.length-1];if(o&&o.rootNodes.length>1){let n=o.rootNodes.map(i=>{var s;return((s=i.loc)==null?void 0:s.start.line)??0}).join(", ");t.report({node:o.rootNodes[0],messageId:"multipleJsxRoots",data:{lines:n}})}e.pop()},FunctionDeclaration(){e.push({rootNodes:[],depth:0})},"FunctionDeclaration:exit"(){e.pop()},"JSXElement,JSXFragment"(o){let n=e[e.length-1];n&&(n.depth===0&&n.rootNodes.push(o),n.depth++)},"JSXElement:exit"(){let o=e[e.length-1];o&&o.depth--},"JSXFragment:exit"(){let o=e[e.length-1];o&&o.depth--}}}};var J={meta:{type:"problem",docs:{description:"Detect declaration location of loader$",recommended:!0,url:"https://github.com/BuilderIO/qwik"},messages:{invalidLoaderLocation:'loader$() can only be declared in `layout.tsx`, `index.tsx` and `plugin.tsx` inside the `src/routes` directory, instead it was declared in "{{path}}". Please check the docs: https://qwik.builder.io/qwikcity/loader'}},create(t){let e=t.getFilename(),o=/\/layout(|!|-.+)\.tsx?$/.test(e),n=/\/index(|!|@.+)\.tsx?$/.test(e),s=/\/src\/routes\//.test(e)&&(n||o);return{CallExpression(l){!s&&l.callee.type==="Identifier"&&l.callee.name==="loader$"&&t.report({node:l.callee,messageId:"invalidLoaderLocation",data:{path:e}})}}}};var K={"no-use-after-await":O,"valid-lexical-scope":k,"single-jsx-root":F,"loader-location":J},ee={recommended:{plugins:["qwik"],rules:{"qwik/no-use-after-await":"error","qwik/valid-lexical-scope":"error","qwik/loader-location":"error","qwik/single-jsx-root":"warn"}},strict:{plugins:["qwik"],rules:{"qwik/valid-lexical-scope":"error","qwik/no-use-after-await":"error","qwik/single-jsx-root":"error","qwik/loader-location":"error"}}};0&&(module.exports={configs,rules});
1
+ "use strict";var D=Object.create;var x=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var z=(t,e)=>{for(var o in e)x(t,o,{get:e[o],enumerable:!0})},R=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of X(e))!j.call(t,i)&&i!==o&&x(t,i,{get:()=>e[i],enumerable:!(n=P(e,i))||n.enumerable});return t};var M=(t,e,o)=>(o=t!=null?D(_(t)):{},R(e||!t||!t.__esModule?x(o,"default",{value:t,enumerable:!0}):o,t)),U=t=>R(x({},"__esModule",{value:!0}),t);var oe={};z(oe,{configs:()=>te,rules:()=>ee});module.exports=U(oe);var C=require("@typescript-eslint/utils"),y=M(require("typescript")),B=C.ESLintUtils.RuleCreator(t=>`https://typescript-eslint.io/rules/${t}`),k=B({name:"valid-lexical-scope",defaultOptions:[{allowAny:!0}],meta:{type:"problem",docs:{description:"Used the tsc typechecker to detect the capture of unserializable data in dollar ($) scopes.",recommended:"error"},schema:[{type:"object",properties:{allowAny:{type:"boolean"}},default:{allowAny:!0}}],messages:{referencesOutside:'Identifier ("{{varName}}") can not be captured inside the scope ({{dollarName}}) because {{reason}}. Check out https://qwik.builder.io/docs/advanced/dollar/ for more details.',unvalidJsxDollar:"JSX attributes that end with $ can only take an inlined arrow function of a QRL identifier. Make sure the value is created using $()",mutableIdentifier:'The value of the identifier ("{{varName}}") can not be changed once it is captured the scope ({{dollarName}}). Check out https://qwik.builder.io/docs/advanced/dollar/ for more details.'}},create(t){var N;let o={allowAny:((N=t.options[0])==null?void 0:N.allowAny)??!0},n=t.getSourceCode().scopeManager,i=C.ESLintUtils.getParserServices(t),s=i.esTreeNodeToTSNodeMap,l=i.program.getTypeChecker(),m=new Map,A=[];function E(u){u.references.forEach(r=>{var g,b;let a=r.resolved,c=(g=r.resolved)==null?void 0:g.scope;if(a&&c){let d=(b=a.defs.at(0))==null?void 0:b.type;if(d==="Type"||d==="ImportBinding")return;let p=r.from,f;for(;p&&(f=m.get(p),!f);)p=p.upper;if(p&&f){let I=c.type;if(I==="global")return;if(I==="module"){let w=a.identifiers.length===1?a.identifiers[0]:r.identifier,q=s.get(w),L=l.getSymbolAtLocation(q);if(L&&A.includes(L))return;t.report({messageId:"referencesOutside",node:r.identifier,data:{varName:r.identifier.name,dollarName:f,reason:"it's declared at the root of the module and it is not exported. Add export"}});return}let S=r.identifier,$=s.get(S),h=c;for(;h&&!m.has(h);)h=h.upper;if(h!==p){S.parent&&S.parent.type==="AssignmentExpression"&&S.parent.left===S&&t.report({messageId:"mutableIdentifier",node:r.identifier,data:{varName:r.identifier.name,dollarName:f}});let w=W(l,$,r.identifier,o);w&&t.report({messageId:"referencesOutside",node:r.identifier,data:{varName:r.identifier.name,dollarName:f,reason:Q(w)}})}}}}),u.childScopes.forEach(E)}return{CallExpression(u){if(u.callee.type==="Identifier"&&u.callee.name.endsWith("$")){let r=u.arguments.at(0);if(r&&r.type==="ArrowFunctionExpression"){let a=n.acquire(r);a&&m.set(a,u.callee.name)}}},JSXAttribute(u){let r=u.name,a=r.type==="JSXIdentifier"?r.name:r.name.name;if(a.endsWith("$")){let c=u.value;if(c&&c.type==="JSXExpressionContainer"){let g=n.acquire(c.expression);if(g)m.set(g,a);else if(c.expression.type==="Identifier"){let b=s.get(c.expression),d=l.getTypeAtLocation(b);v(d)||t.report({messageId:"unvalidJsxDollar",node:c.expression})}}}},Program(u){let r=s.get(u),a=l.getSymbolAtLocation(r);a&&(A=l.getExportsOfModule(a))},"Program:exit"(){E(n.globalScope)}}}});function W(t,e,o,n){let i=t.getTypeAtLocation(e);return V(t,i,e,o,n,new Set)}function Q(t){let e="";return t.location?e+=`"${t.location}" `:e+="it ",e+=`${t.reason}`,e}function V(t,e,o,n,i,s){let l=T(t,e,o,i,0,s);if(l){let m=l.location;return m&&(l.location=`${n.name}.${m}`),l}return l}function T(t,e,o,n,i,s){if(s.has(e)||(s.add(e),e.getProperty("__no_serialize__")))return;if(e.flags&y.default.TypeFlags.Unknown)return{type:e,typeStr:t.typeToString(e),reason:"is unknown, which is not serializable"};let m=e.flags&y.default.TypeFlags.Any;if(!n.allowAny&&m)return{type:e,typeStr:t.typeToString(e),reason:"is any, which is not serializable"};if(e.flags&y.default.TypeFlags.BigIntLike)return{type:e,typeStr:t.typeToString(e),reason:"is BigInt and it is not supported yet, use a number instead"};if(e.flags&y.default.TypeFlags.ESSymbolLike)return{type:e,typeStr:t.typeToString(e),reason:"is Symbol, which is not serializable"};if(e.flags&y.default.TypeFlags.EnumLike)return{type:e,typeStr:t.typeToString(e),reason:"is an enum, use an string or a number instead"};if(v(e))return;if(e.getCallSignatures().length>0)return e.symbol.name==="PropFnInterface"?void 0:{type:e,typeStr:t.typeToString(e),reason:"is a function, which is not serializable"};if(e.isUnion()){for(let a of e.types){let c=T(t,a,o,n,i+1,s);if(c)return c}return}if((e.flags&y.default.TypeFlags.Object)!==0){let a=Z(e,t);if(a)return T(t,a,o,n,i+1,s);let c=G(e,t);if(c){for(let d of c){let p=T(t,d,o,n,i+1,s);if(p)return p}return}let g=e.symbol.name;if(e.getProperty("nextElementSibling")||e.getProperty("activeElement")||H[g])return;if(e.isClass())return{type:e,typeStr:t.typeToString(e),reason:`is an instance of the "${e.symbol.name}" class, which is not serializable. Use a simple object literal instead`};let b=e.getProperty("prototype");if(b){let d=t.getTypeOfSymbolAtLocation(b,o);if(d.isClass())return{type:d,typeStr:t.typeToString(d),reason:"is a class constructor, which is not serializable"}}if(!g.startsWith("__")&&e.symbol.valueDeclaration)return{type:e,typeStr:t.typeToString(e),reason:`is an instance of the "${e.symbol.name}" class, which is not serializable`};for(let d of e.getProperties()){let p=Y(t,d,o,n,i+1,s);if(p){let f=p.location;return p.location=`${d.name}${f?`.${f}`:""}`,p}}}}function Y(t,e,o,n,i,s){let l=t.getTypeOfSymbolAtLocation(e,o);return T(t,l,o,n,i,s)}function Z(t,e){return e.getElementTypeOfArrayType(t)}function G(t,e){return e.isTupleType(t)?e.getTypeArguments(t):void 0}function v(t){return!!(t.flags&y.default.TypeFlags.Any)||!!t.getProperty("__brand__QRL__")}var H={Promise:!0,URL:!0,RegExp:!0,Date:!0,FormData:!0,URLSearchParams:!0,Error:!0};var O={meta:{type:"problem",docs:{description:"Object destructuring is not recommended for component$",category:"Variables",recommended:!0,url:"https://github.com/BuilderIO/qwik"}},create(t){let e=[];return{ArrowFunctionExpression(){e.push({await:!1})},"ArrowFunctionExpression:exit"(){e.pop()},AwaitExpression(){let o=e[e.length-1];o&&(o.await=!0)},"CallExpression[callee.name=/^use[A-Z]/]"(o){let n=e[e.length-1];n&&n.await&&t.report({node:o,message:"Calling use* methods after await is not safe."})}}}};var F={meta:{type:"problem",docs:{description:"Detect multiple JSX roots inside a component",recommended:!0,url:"https://github.com/BuilderIO/qwik"},messages:{multipleJsxRoots:"Components in Qwik must have a single JSX root element. Your component has multiple roots on lines: {{lines}}. Rewrite your component with a single root such as (`return <>{...}</>`.) and keep all JSX within"}},create(t){let e=[];return{ArrowFunctionExpression(){e.push({rootNodes:[],depth:0})},"ArrowFunctionExpression:exit"(){let o=e[e.length-1];if(o&&o.rootNodes.length>1){let n=o.rootNodes.map(i=>{var s;return((s=i.loc)==null?void 0:s.start.line)??0}).join(", ");t.report({node:o.rootNodes[0],messageId:"multipleJsxRoots",data:{lines:n}})}e.pop()},FunctionDeclaration(){e.push({rootNodes:[],depth:0})},"FunctionDeclaration:exit"(){e.pop()},"JSXElement,JSXFragment"(o){let n=e[e.length-1];n&&(n.depth===0&&n.rootNodes.push(o),n.depth++)},"JSXElement:exit"(){let o=e[e.length-1];o&&o.depth--},"JSXFragment:exit"(){let o=e[e.length-1];o&&o.depth--}}}};var J={meta:{type:"problem",docs:{description:"Detect declaration location of loader$",recommended:!0,url:"https://github.com/BuilderIO/qwik"},messages:{invalidLoaderLocation:'loader$() can only be declared in `layout.tsx`, `index.tsx` and `plugin.tsx` inside the `src/routes` directory, instead it was declared in "{{path}}". Please check the docs: https://qwik.builder.io/qwikcity/loader'}},create(t){let e=K(t.getFilename()),o=/\/layout(|!|-.+)\.tsx?$/.test(e),n=/\/index(|!|@.+)\.tsx?$/.test(e),s=/\/src\/routes\//.test(e)&&(n||o);return{CallExpression(l){!s&&l.callee.type==="Identifier"&&l.callee.name==="loader$"&&t.report({node:l.callee,messageId:"invalidLoaderLocation",data:{path:e}})}}}};function K(t){let e=/^\\\\\?\\/.test(t),o=/[^\u0000-\u0080]+/.test(t);return e||o||(t=t.replace(/\\/g,"/"),t.endsWith("/")&&(t=t.slice(0,t.length-1))),t}var ee={"no-use-after-await":O,"valid-lexical-scope":k,"single-jsx-root":F,"loader-location":J},te={recommended:{plugins:["qwik"],rules:{"qwik/no-use-after-await":"error","qwik/valid-lexical-scope":"error","qwik/loader-location":"error","qwik/single-jsx-root":"warn"}},strict:{plugins:["qwik"],rules:{"qwik/valid-lexical-scope":"error","qwik/no-use-after-await":"error","qwik/single-jsx-root":"error","qwik/loader-location":"error"}}};0&&(module.exports={configs,rules});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-qwik",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "description": "An Open-Source sub-framework designed with a focus on server-side-rendering, lazy-loading, and styling/animation.",
5
5
  "main": "index.js",
6
6
  "author": "Builder Team",