eslint-plugin-qwik 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +14 -3
- package/package.json +4 -3
package/index.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var B=Object.create;var I=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var Q=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),X=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},L=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of J(t))!W.call(e,i)&&i!==n&&I(e,i,{get:()=>t[i],enumerable:!(r=j(t,i))||r.enumerable});return e};var R=(e,t,n)=>(n=e!=null?B(V(e)):{},L(t||!e||!e.__esModule?I(n,"default",{value:e,enumerable:!0}):n,e)),Z=e=>L(I({},"__esModule",{value:!0}),e);var D=Q((ce,O)=>{"use strict";O.exports=e=>{let t=e.match(/^[ \t]*(?=\S)/gm);return t?t.reduce((n,r)=>Math.min(n,r.length),1/0):0}});var ae={};X(ae,{configs:()=>se,rules:()=>ie});module.exports=Z(ae);var v=require("@typescript-eslint/utils"),w=R(require("typescript"));var q=R(D(),1);function N(e){let t=(0,q.default)(e);if(t===0)return e;let n=new RegExp(`^[ \\t]{${t}}`,"gm");return e.replace(n,"")}function A(e,t=1,n={}){let{indent:r=" ",includeEmptyLines:i=!1}=n;if(typeof e!="string")throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof e}\``);if(typeof t!="number")throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof t}\``);if(t<0)throw new RangeError(`Expected \`count\` to be at least 0, got \`${t}\``);if(typeof r!="string")throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof r}\``);if(t===0)return e;let l=i?/^/gm:/^(?!\s*$)/gm;return e.replace(l,r.repeat(t))}function $(e,t=0,n={}){return A(N(e),t,n)}var G=v.ESLintUtils.RuleCreator(()=>"https://qwik.builder.io/docs/advanced/dollar/"),P=G({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:`Seems like you are referencing "{{varName}}" inside a different scope ({{dollarName}}), when this happens, Qwik needs to serialize the value, however {{reason}}.
|
|
2
|
+
Check out https://qwik.builder.io/docs/advanced/dollar/ for more details.`,invalidJsxDollar:`Seems like you are using "{{varName}}" as an event handler, however functions are not serializable.
|
|
3
|
+
Did you mean to wrap it in \`$()\`?
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
{{solution}}
|
|
6
|
+
Check out https://qwik.builder.io/docs/advanced/dollar/ for more details.`,mutableIdentifier:`Seems like you are mutating the value of ("{{varName}}"), but this is not possible when captured by the ({{dollarName}}) closure, instead create an object and mutate one of its properties.
|
|
7
|
+
Check out https://qwik.builder.io/docs/advanced/dollar/ for more details.`}},create(e){var C;let n={allowAny:((C=e.options[0])==null?void 0:C.allowAny)??!0},r=e.getSourceCode().scopeManager,i=v.ESLintUtils.getParserServices(e),l=i.esTreeNodeToTSNodeMap,o=i.program.getTypeChecker(),s=new Map,c=[];function h(m){m.references.forEach(a=>{var u,g;let y=a.resolved,d=(u=a.resolved)==null?void 0:u.scope;if(y&&d){let b=(g=y.defs.at(0))==null?void 0:g.type;if(b==="Type"||b==="ImportBinding")return;let p=a.from,f;for(;p&&(f=s.get(p),!f);)p=p.upper;if(p&&f){let T=d.type;if(T==="global"||T==="module")return;let S=a.identifier,M=l.get(S),x=d;for(;x&&!s.has(x);)x=x.upper;if(x!==p){S.parent&&S.parent.type==="AssignmentExpression"&&S.parent.left===S&&e.report({messageId:"mutableIdentifier",node:a.identifier,data:{varName:a.identifier.name,dollarName:f}});let k=H(e,o,M,a.identifier,n);k&&e.report({messageId:"referencesOutside",node:a.identifier,data:{varName:a.identifier.name,dollarName:f,reason:K(k)}})}}}}),m.childScopes.forEach(h)}return{CallExpression(m){if(m.callee.type==="Identifier"&&m.callee.name.endsWith("$")){let a=m.arguments.at(0);if(a&&a.type==="ArrowFunctionExpression"){let y=r.acquire(a);y&&s.set(y,m.callee.name)}}},JSXAttribute(m){let a=m.name,y=a.type==="JSXIdentifier"?a.name:a.name.name;if(y.endsWith("$")){let d=m.value;if(d&&d.type==="JSXExpressionContainer"){let u=r.acquire(d.expression);if(u)s.set(u,y);else if(d.expression.type==="Identifier"){let g=l.get(d.expression),b=o.getTypeAtLocation(g);if(!F(b)){if(b.symbol.name==="PropFnInterface")return;e.report({messageId:"invalidJsxDollar",node:d.expression,data:{varName:d.expression.name,solution:`const ${d.expression.name} = $(
|
|
8
|
+
${_(b.symbol,e.getSourceCode().text)}
|
|
9
|
+
);
|
|
10
|
+
`}})}}}}},Program(m){let a=l.get(m),y=o.getSymbolAtLocation(a);y&&(c=o.getExportsOfModule(y))},"Program:exit"(){h(r.globalScope)}}}});function H(e,t,n,r,i){let l=t.getTypeAtLocation(n);return Y(e,t,l,n,r,i,new Set)}function K(e){let t="";return e.location?t+=`"${e.location}" `:t+="it ",t+=`${e.reason}`,t}function Y(e,t,n,r,i,l,o){let s=E(e,t,n,r,l,0,o);if(s){let c=s.location;return c&&(s.location=`${i.name}.${c}`),s}return s}function E(e,t,n,r,i,l,o){if(o.has(n)||(o.add(n),n.getProperty("__no_serialize__")))return;if(n.flags&w.default.TypeFlags.Unknown)return{type:n,typeStr:t.typeToString(n),reason:"is unknown, which could be serializable or not, please make the type for specific"};let c=n.flags&w.default.TypeFlags.Any;if(!i.allowAny&&c)return{type:n,typeStr:t.typeToString(n),reason:"is any, which is not serializable"};if(n.flags&w.default.TypeFlags.BigIntLike)return{type:n,typeStr:t.typeToString(n),reason:"is BigInt and it is not supported yet, use a number instead"};if(n.flags&w.default.TypeFlags.ESSymbolLike)return{type:n,typeStr:t.typeToString(n),reason:"is Symbol, which is not serializable"};if(n.flags&w.default.TypeFlags.EnumLike)return{type:n,typeStr:t.typeToString(n),reason:"is an enum, use an string or a number instead"};if(F(n))return;if(n.getCallSignatures().length>0){if(n.symbol.name==="PropFnInterface")return;let u="is a function, which is not serializable";if(l===0&&w.default.isIdentifier(r)){let g=`const ${r.text} = $(
|
|
11
|
+
${_(n.symbol,e.getSourceCode().text)}
|
|
12
|
+
);`;u+=`.
|
|
13
|
+
Did you mean to wrap it in \`$()\`?
|
|
4
14
|
|
|
5
|
-
|
|
15
|
+
${g}
|
|
16
|
+
`}return{type:n,typeStr:t.typeToString(n),reason:u}}if(n.isUnion()){for(let d of n.types){let u=E(e,t,d,r,i,l+1,o);if(u)return u}return}if((n.flags&w.default.TypeFlags.Object)!==0){let d=te(n,t);if(d)return E(e,t,d,r,i,l+1,o);let u=ne(n,t);if(u){for(let p of u){let f=E(e,t,p,r,i,l+1,o);if(f)return f}return}let g=n.symbol.name;if(n.getProperty("nextElementSibling")||n.getProperty("activeElement")||re[g])return;if(n.isClass())return{type:n,typeStr:t.typeToString(n),reason:`is an instance of the "${n.symbol.name}" class, which is not serializable. Use a simple object literal instead`};let b=n.getProperty("prototype");if(b){let p=t.getTypeOfSymbolAtLocation(b,r);if(p.isClass())return{type:p,typeStr:t.typeToString(p),reason:"is a class constructor, which is not serializable"}}if(!g.startsWith("__")&&n.symbol.valueDeclaration)return{type:n,typeStr:t.typeToString(n),reason:`is an instance of the "${n.symbol.name}" class, which is not serializable`};for(let p of n.getProperties()){let f=ee(e,t,p,r,i,l+1,o);if(f){let T=f.location;return f.location=`${p.name}${T?`.${T}`:""}`,f}}}}function ee(e,t,n,r,i,l,o){let s=t.getTypeOfSymbolAtLocation(n,r);return E(e,t,s,r,i,l,o)}function te(e,t){return t.getElementTypeOfArrayType(e)}function ne(e,t){return t.isTupleType(e)?t.getTypeArguments(e):void 0}function F(e){return!!(e.flags&w.default.TypeFlags.Any)||!!e.getProperty("__brand__QRL__")}function _(e,t){if(e.declarations&&e.declarations.length>0){let n=e.declarations[0],r=t.slice(n.pos,n.end).replace(/^\s*$/gm,"");return $(r,2)}return""}var re={Promise:!0,URL:!0,RegExp:!0,Date:!0,FormData:!0,URLSearchParams:!0,Error:!0};var z={meta:{type:"problem",docs:{description:"Object destructuring is not recommended for component$",category:"Variables",recommended:!0,url:"https://github.com/BuilderIO/qwik"}},create(e){let t=[];return{ArrowFunctionExpression(){t.push({await:!1})},"ArrowFunctionExpression:exit"(){t.pop()},AwaitExpression(){let n=t[t.length-1];n&&(n.await=!0)},"CallExpression[callee.name=/^use[A-Z]/]"(n){let r=t[t.length-1];r&&r.await&&e.report({node:n,message:"Calling use* methods after await is not safe."})}}}};var U={meta:{type:"problem",docs:{description:"Detect declaration location of loader$",recommended:!0,url:"https://github.com/BuilderIO/qwik"},messages:{invalidLoaderLocation:'`{{fnName}}()` can only be declared in `layout.tsx`, `index.tsx` and `plugin.tsx` inside the `src/routes` directory, instead it was declared in "{{path}}".\nPlease check the docs: https://qwik.builder.io/qwikcity/loader',missingExport:"The return of `{{fnName}}()` needs to be exported in the same module, like this\n```\nexport const {{id}} = {{fnName}}(() => { ... });\n```",wrongName:"The named export of `{{fnName}}()` needs to follow the `use*` naming convention. It must start with `use`, like this:\n```\nexport const {{fixed}} = {{fnName}}(() => { ... });\n```\nInstead it was named:\n```\nexport const {{id}} = ...\n```",recommendedValue:"For `{{fnName}}()` it is recommended to inline the arrow function. Instead of:\n```\nexport const {{id}} = {{fnName}}({{arg}});\n```\nDo this:\n```\nexport const {{id}} = {{fnName}}(() => { ...logic here... });\n```\nThis will help the optimizer make sure that no server code is leaked to the client build."}},create(e){let t=oe(e.getFilename()),n=/\/layout(|!|-.+)\.tsx?$/.test(t),r=/\/index(|!|@.+)\.tsx?$/.test(t),l=/\/src\/routes\//.test(t)&&(r||n);return{CallExpression(o){if(o.callee.type!=="Identifier")return;let s=o.callee.name;if(s!=="loader$"&&s!=="action$")return;if(!l&&s==="loader$"){e.report({node:o.callee,messageId:"invalidLoaderLocation",data:{fnName:s,path:t}});return}let c=o.parent;if(c.type!=="VariableDeclarator"){e.report({node:o.callee,messageId:"missingExport",data:{fnName:s,id:"useStuff"}});return}if(c.id.type!=="Identifier"){e.report({node:o.callee,messageId:"missingExport",data:{fnName:s,id:"useStuff"}});return}if(!/^use/.test(c.id.name)){let h="use"+c.id.name[0].toUpperCase()+c.id.name.slice(1);e.report({node:c.id,messageId:"wrongName",data:{fnName:s,id:c.id.name,fixed:h}});return}if(c.parent.parent.type!=="ExportNamedDeclaration"){e.report({node:c.id,messageId:"missingExport",data:{fnName:s,id:c.id.name}});return}if(o.arguments.length>0&&o.arguments[0].type==="Identifier"){e.report({node:o.arguments[0],messageId:"recommendedValue",data:{fnName:s,id:c.id.name,arg:o.arguments[0].name}});return}}}}};function oe(e){let t=/^\\\\\?\\/.test(e),n=/[^\u0000-\u0080]+/.test(e);return t||n||(e=e.replace(/\\/g,"/"),e.endsWith("/")&&(e=e.slice(0,e.length-1))),e}var ie={"no-use-after-await":z,"valid-lexical-scope":P,"loader-location":U},se={recommended:{plugins:["qwik"],rules:{"qwik/no-use-after-await":"error","qwik/valid-lexical-scope":"error","qwik/loader-location":"warn"}},strict:{plugins:["qwik"],rules:{"qwik/valid-lexical-scope":"error","qwik/no-use-after-await":"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.
|
|
3
|
+
"version": "0.19.0",
|
|
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",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"node": ">=16"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/eslint": "8.21.
|
|
30
|
-
"@types/estree": "^1.0.0"
|
|
29
|
+
"@types/eslint": "8.21.1",
|
|
30
|
+
"@types/estree": "^1.0.0",
|
|
31
|
+
"redent": "^4.0.0"
|
|
31
32
|
}
|
|
32
33
|
}
|