eslint-plugin-qwik 2.0.0-beta.34 → 2.0.0-beta.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -406,4 +406,4 @@ export default component$(() => {
|
|
|
406
406
|
|
|
407
407
|
return <div>{myClass.count}</div>;
|
|
408
408
|
});`.trim();var Rp={meta:{type:"suggestion",docs:{description:"Detect preventDefault in $(()=>{}) Async Functions.",recommended:!0,url:"https://qwik.dev/docs/components/events/#preventdefault--stoppropagation"},messages:{noAsyncPreventDefault:`This is an asynchronous function and does not support preventDefault.
|
|
409
|
-
Use preventDefault attributes instead`}},create(r){return{"CallExpression[callee.property.name='preventDefault']"(e){let t=e.parent;for(;t;){if(t.type==="CallExpression"&&t.callee&&t.callee.type==="Identifier"&&t.callee.name==="$"){r.report({node:e,messageId:"noAsyncPreventDefault"});break}t=t.parent}}}}};var Pb=new Set(["useTask$","useTaskQrl"]);function kb(r){return r.callee.type==="Identifier"&&Pb.has(r.callee.name)}function Ib(r){let e=r.arguments[0];return e?.type==="ArrowFunctionExpression"||e?.type==="FunctionExpression"?e:null}function Fn(r){return r?r.type==="AssignmentPattern"?Fn(r.right):r.type==="Literal"&&r.value===!1?!0:r.type==="TSAsExpression"?Fn(r.expression):!1:!1}function Ob(r){let e=r.arguments[1];if(!e||e.type!=="ObjectExpression")return!1;for(let t of e.properties){if(t.type!=="Property"||t.computed)continue;let n=t.key;if((n.type==="Identifier"?n.name:n.type==="Literal"?String(n.value):null)==="deferUpdates"&&Fn(t.value))return!0}return!1}function jp(r){let e=new Set,t=[r];for(;t.length;){let n=t.pop();n.type==="VariableDeclarator"&&n.id.type==="Identifier"&&n.init&&n.init.type==="CallExpression"&&n.init.callee.type==="Identifier"&&n.init.callee.name==="useNavigate"&&e.add(n.id.name);for(let o of Object.keys(n)){if(o==="parent")continue;let i=n[o];if(Array.isArray(i))for(let a of i)a&&typeof a=="object"&&a!==null&&"type"in a&&t.push(a);else i&&typeof i=="object"&&"type"in i&&t.push(i)}}return e}function Cb(r){let e=new Set,t=r.parent;for(;t;){if(t.type==="ArrowFunctionExpression"||t.type==="FunctionExpression"){let n=t.parent;if(n?.type==="CallExpression"&&n.callee.type==="Identifier"&&n.callee.name==="component$")for(let o of jp(t))e.add(o)}if(t.type==="Program"){for(let n of jp(t))e.add(n);break}t=t.parent}return e}function $b(r,e,t){let n=[e];for(;n.length;){let o=n.pop();if(o.type==="AwaitExpression"){let i=o.argument;i.type==="CallExpression"&&i.callee.type==="Identifier"&&t.has(i.callee.name)&&r.report({node:o,messageId:"noAwaitBlocking",data:{name:i.callee.name}})}for(let i of Object.keys(o)){if(i==="parent")continue;let a=o[i];if(Array.isArray(a))for(let l of a)l&&typeof l=="object"&&l!==null&&"type"in l&&n.push(l);else a&&typeof a=="object"&&"type"in a&&n.push(a)}}}var Mp={meta:{type:"problem",docs:{description:"Disallow awaiting the function returned by `useNavigate()` inside blocking `useTask$` callbacks.",recommended:!0,url:"https://qwik.dev/docs/advanced/eslint/"},messages:{noAwaitBlocking:"Awaiting `{{name}}()` from `useNavigate()` inside a blocking `useTask$` can deadlock. Remove `await`, or pass `{ deferUpdates: false }` as the second argument to `useTask$`."}},create(r){return{CallExpression(e){if(!kb(e)||Ob(e))return;let t=Ib(e);if(!t)return;let n=Cb(e);n.size&&$b(r,t.body,n)}}}};var Nn={name:"eslint-plugin-qwik",description:"An Open-Source sub-framework designed with a focus on server-side-rendering, lazy-loading, and styling/animation.",version:"2.0.0-beta.34",author:"Qwik Team",bugs:"https://github.com/QwikDev/qwik/issues",dependencies:{"@typescript-eslint/utils":"^8.56.1","jsx-ast-utils":"^3.3.5"},devDependencies:{"@qwik.dev/core":"workspace:*","@qwik.dev/router":"workspace:*","@types/estree":"1.0.8","@typescript-eslint/rule-tester":"8.56.1",redent:"4.0.0"},engines:{node:"^18.17.0 || ^20.3.0 || >=21.0.0"},files:["README.md","dist"],homepage:"https://github.com/QwikDev/qwik#readme",keywords:["eslint","qwik"],license:"MIT",main:"dist/index.js",peerDependencies:{eslint:"^8.57.0 || ^9.0.0 || ^10.0.0"},repository:{type:"git",url:"https://github.com/QwikDev/qwik.git",directory:"packages/eslint-rules"},scripts:{test:"cd ../..; ./node_modules/.bin/vitest packages/eslint-plugin-qwik/qwik.unit.ts"}};var A=require("@typescript-eslint/utils"),Fb="isServer",Lp=["process","__dirname","__filename","module"],Dp=["fs","os","path","child_process","http","https","Buffer"];function Rn(r,e){if(!e)return!1;let t=r.parent;for(;t;){if(t===e)return!0;t=t.parent}return!1}var Vp={meta:{type:"problem",docs:{description:"Disallow direct or indirect (via one-level function call) Node.js API usage in useTask$ without a server guard (e.g., isServer).",category:"Best Practices",recommended:!0,url:""},fixable:void 0,schema:[{type:"object",properties:{forbiddenApis:{type:"array",items:{type:"string"},default:Dp}},additionalProperties:!1}],messages:{unsafeApiUsage:"Node.js API '{{apiName}}' should only be used inside an '{{guardName}}' block within useTask$. Example: if ({{guardName}}) { {{apiName}}.call(); }",unsafeApiUsageInCalledFunction:"Node.js API '{{apiName}}' used in function '{{calledFunctionName}}' (called from useTask$) needs '{{guardName}}' protection. Either guard the call site or protect the API usage within '{{calledFunctionName}}'."}},create(r){let e=r.options[0]||{},t=new Set(e.forbiddenApis||Dp.concat(Lp)),n=Fb,o=r.sourceCode,i=null;function a(u,f){let m=u.parent;for(;m&&m!==f.body&&m!==f;){if(m.type===A.AST_NODE_TYPES.IfStatement){let y=m;if(Rn(u,y.consequent)||u===y.consequent){let d=y.test;if(d.type===A.AST_NODE_TYPES.Identifier&&d.name===n||d.type===A.AST_NODE_TYPES.BinaryExpression&&d.operator==="==="&&(d.left.type===A.AST_NODE_TYPES.Identifier&&d.left.name===n&&d.right.type===A.AST_NODE_TYPES.Literal&&d.right.value===!0||d.right.type===A.AST_NODE_TYPES.Identifier&&d.right.name===n&&d.left.type===A.AST_NODE_TYPES.Literal&&d.left.value===!0)||d.type===A.AST_NODE_TYPES.UnaryExpression&&d.operator==="!"&&d.argument.type===A.AST_NODE_TYPES.UnaryExpression&&d.argument.operator==="!"&&d.argument.argument.type===A.AST_NODE_TYPES.Identifier&&d.argument.argument.name===n)return!0}}m=m.parent}return!1}function l(u){let f=o.getScope(u),m=null,y=f;if(!Lp.includes(u.name))return!0;for(;y;){let d=y.variables.find(v=>v.name===u.name);if(d){m=d;break}if(y.type==="global"){m=y.variables.find(v=>v.name===u.name);break}y=y.upper}return!m||m.defs.length===0?!1:m.defs.some(d=>d.type==="Variable"||d.type==="Parameter"||d.type==="FunctionName"||d.type==="ClassName"||d.type==="ImportBinding")}function p(u,f,m){function y(d){if(!d)return!1;if(d.type===A.AST_NODE_TYPES.Identifier&&t.has(d.name)&&!l(d)&&!a(d,f))return r.report({node:m,messageId:"unsafeApiUsageInCalledFunction",data:{apiName:d.name,calledFunctionName:f.id?.name||(m.type===A.AST_NODE_TYPES.Identifier?m.name:"[anonymous]"),guardName:n}}),!0;for(let v in d){if(v==="parent"||v==="range"||v==="loc")continue;let c=d[v];if(Array.isArray(c)){for(let g of c)if(g&&typeof g=="object"&&"type"in g&&y(g))return!0}else if(c&&typeof c=="object"&&"type"in c&&y(c))return!0}return!1}y(u)}return{":function"(u){let f=u.parent;f&&f.type===A.AST_NODE_TYPES.CallExpression&&f.callee.type===A.AST_NODE_TYPES.Identifier&&f.callee.name==="useTask$"&&f.arguments.length>0&&f.arguments[0]===u&&(i=u)},":function:exit"(u){i===u&&(i=null)},Identifier(u){if(i&&!(i.body!==u&&!Rn(u,i.body))&&!(u.parent&&u.parent.type===A.AST_NODE_TYPES.CallExpression&&u.parent.callee===u)&&t.has(u.name)){if(l(u))return;a(u,i)||r.report({node:u,messageId:"unsafeApiUsage",data:{apiName:u.name,guardName:n}})}},CallExpression(u){if(i&&Rn(u,i.body)&&!a(u,i)&&u.callee.type===A.AST_NODE_TYPES.Identifier){let f=u.callee,m=o.getScope(f),y=null,d=m.references.find(c=>c.identifier===f);if(d&&d.resolved)y=d.resolved;else{let c=m;for(;c;){let g=c.variables.find(b=>b.name===f.name);if(g&&g.defs.length>0){y=g;break}if(c.type==="global"&&!g){let b=c.type==="global"?c.variables.find(w=>w.name===f.name):null;b&&(y=b);break}if(!c.upper)break;c=c.upper}}let v=y;if(v&&v.defs.length>0){let c=v.defs[0],g=null;if(c.node.type===A.AST_NODE_TYPES.FunctionDeclaration?g=c.node:c.node.type===A.AST_NODE_TYPES.VariableDeclarator&&c.node.init&&(c.node.init.type===A.AST_NODE_TYPES.FunctionExpression||c.node.init.type===A.AST_NODE_TYPES.ArrowFunctionExpression)&&(g=c.node.init),g){let b=(g.body.type===A.AST_NODE_TYPES.BlockStatement,g.body);p(b,g,u)}}}}}}};var x=require("@typescript-eslint/utils"),z=ee(require("typescript"));function jn(r){return r?.defs?.some(e=>{if(e.type!=="ImportBinding")return!1;let t=e.parent.source.value;return t.startsWith("@qwik.dev/core")||t.startsWith("@qwik.dev/router")||t.startsWith("@builder.io/qwik")||t.startsWith("@builder.io/qwik-city")})}function Le(r,e){let t=r.sourceCode.getScope(e),n=t.references.find(i=>i.identifier===e);if(n&&n.resolved)return n.resolved;let o=t;for(;o;){let i=o.variables.find(a=>a.name===e.name);if(i)return i;o=o.upper}return null}function Nb(r,e){if(!e||e.type!==x.AST_NODE_TYPES.Identifier||!e.name.endsWith("$"))return!1;let t=Le(r,e);return jn(t)}function Rb(r){let e=r.body[0];if(!e||e.type!==x.AST_NODE_TYPES.ExpressionStatement)return null;let t=e.expression;return t.type===x.AST_NODE_TYPES.MemberExpression&&!t.computed&&t.property.type===x.AST_NODE_TYPES.Identifier&&t.property.name==="value"?e:null}function jb(r,e){let t=Le(r,e);if(!t||t.defs&&t.defs.length===0)return!1;let n=r.sourceCode.parserServices,o=n?.program?.getTypeChecker(),i=n?.esTreeNodeToTSNodeMap;function a(l){if(!l)return!1;if(z.default.isVariableDeclaration(l)&&l.initializer&&z.default.isCallExpression(l.initializer)){let p=l.initializer.expression;if(z.default.isIdentifier(p)){let u=p.text;return u==="createAsync$"||u==="useAsync$"||u==="routeLoader$"}}return z.default.isExportSpecifier(l)||z.default.isImportSpecifier(l),!1}for(let l of t.defs){if(l.type==="Variable"&&l.node.type===x.AST_NODE_TYPES.VariableDeclarator){let p=l.node.init;if(p&&p.type===x.AST_NODE_TYPES.CallExpression){let u=p.callee;if(u.type===x.AST_NODE_TYPES.Identifier){let f=u.name;if((f==="useAsync$"||f==="createAsync$"||f==="routeLoader$")&&jn(Le(r,u)))return!0;let m=Le(r,u);if(m&&m.defs){for(let y of m.defs)if(y.type==="Variable"&&y.node.type===x.AST_NODE_TYPES.VariableDeclarator){let d=y.node.init;if(d&&d.type===x.AST_NODE_TYPES.CallExpression){let v=d.callee;if(v.type===x.AST_NODE_TYPES.Identifier&&v.name==="routeLoader$"&&jn(Le(r,v)))return!0}}}}}}if(l.type==="ImportBinding"&&o&&i)try{let p=i.get(e);if(p){let u=o.getSymbolAtLocation(p);if(u&&u.flags&z.default.SymbolFlags.Alias&&(u=o.getAliasedSymbol(u)),u){for(let y of u.declarations??[]){if(a(y))return!0;if(z.default.isVariableStatement(y)){for(let d of y.declarationList.declarations)if(a(d))return!0}}let f=o.getTypeOfSymbolAtLocation(u,p),m=o.typeToString(f.getNonNullableType());if(/Async/i.test(m))return!0}}}catch{}}if(o&&i)try{let l=i.get(e),p=o.getTypeAtLocation(l),u=o.typeToString(p.getNonNullableType());if(/Async|LoaderSignal/i.test(u))return!0}catch{}return!1}function Mb(r,e,t){for(let n of r.body){if(n===e)break;if(n.type!==x.AST_NODE_TYPES.ExpressionStatement)continue;let o=n.expression;if(o.type!==x.AST_NODE_TYPES.AwaitExpression)continue;let i=o.argument;if(i.type===x.AST_NODE_TYPES.CallExpression&&(i=i.callee),i.type===x.AST_NODE_TYPES.MemberExpression&&!i.computed&&i.object.type===x.AST_NODE_TYPES.Identifier&&i.object.name===t&&i.property.type===x.AST_NODE_TYPES.Identifier&&i.property.name==="promise")return!0}return!1}function Lb(r){let e=r;for(;e;){if(e.type===x.AST_NODE_TYPES.FunctionDeclaration||e.type===x.AST_NODE_TYPES.FunctionExpression||e.type===x.AST_NODE_TYPES.ArrowFunctionExpression)return e;e=e.parent}return null}function Db(r,e,t){let n=e.parent;if(n&&n.type===x.AST_NODE_TYPES.CallExpression&&n.callee.type===x.AST_NODE_TYPES.Identifier&&Nb(r,n.callee)){for(let o of n.arguments)if(o===e)return!0}if(e.async){for(let o of e.params)if(o.type===x.AST_NODE_TYPES.Identifier&&o.name===t.name)return!0}return!1}var Up={meta:{type:"problem",docs:{description:"Warn when an async computed signal '.value' is read not at the top of a QRL callback.",recommended:!1,url:""},schema:[],messages:{asyncComputedNotTop:"Async computed '{{name}}.value' must be first, or use 'await {{name}}.promise()' beforehand."}},create(r){return{MemberExpression(e){if(e.computed||e.property.type!==x.AST_NODE_TYPES.Identifier||e.property.name!=="value")return;let t=e.object;if(t.type!==x.AST_NODE_TYPES.Identifier||!jb(r,t))return;let n=Lb(e);if(!n||!Db(r,n,t))return;let o=e.parent;if(!o||o.type!==x.AST_NODE_TYPES.ExpressionStatement&&o.type!==x.AST_NODE_TYPES.ReturnStatement)return;let i=n.body&&n.body.type===x.AST_NODE_TYPES.BlockStatement?n.body:null;if(!i)return n.body.type===x.AST_NODE_TYPES.MemberExpression&&n.body===e,void 0;o.parent!==i||i.body[0]===o||Rb(i)===o||(o.type===x.AST_NODE_TYPES.ExpressionStatement||o.type===x.AST_NODE_TYPES.ReturnStatement)&&Mb(i,o,t.name)||r.report({node:e,messageId:"asyncComputedNotTop",data:{name:t.name}})}}}};var Bp={"valid-lexical-scope":Cp,"use-method-usage":Op,"no-react-props":Ap,"loader-location":Tp,"prefer-classlist":kp,"jsx-no-script-url":wp,"jsx-key":xp,"unused-server":Ip,"jsx-img":Hn,"jsx-a":Wn,"no-use-visible-task":Pp,"serializer-signal-usage":Np,"scope-use-task":Vp,"use-async-top":Up,"no-async-prevent-default":Rp,"no-await-navigate-in-use-task":Mp},Jp={"qwik/valid-lexical-scope":"error","qwik/use-method-usage":"error","qwik/no-react-props":"error","qwik/loader-location":"warn","qwik/prefer-classlist":"warn","qwik/jsx-no-script-url":"warn","qwik/jsx-key":"warn","qwik/unused-server":"error","qwik/jsx-img":"warn","qwik/jsx-a":"warn","qwik/no-use-visible-task":"warn","qwik/serializer-signal-usage":"error","qwik/scope-use-task":"error","qwik/use-async-top":"warn","qwik/no-async-prevent-default":"warn","qwik/no-await-navigate-in-use-task":"warn"},Wp={"qwik/valid-lexical-scope":"error","qwik/use-method-usage":"error","qwik/no-react-props":"error","qwik/loader-location":"error","qwik/prefer-classlist":"error","qwik/jsx-no-script-url":"error","qwik/jsx-key":"error","qwik/unused-server":"error","qwik/jsx-img":"error","qwik/jsx-a":"error","qwik/no-use-visible-task":"warn","qwik/serializer-signal-usage":"error","qwik/scope-use-task":"error","qwik/use-async-top":"warn","qwik/no-async-prevent-default":"warn","qwik/no-await-navigate-in-use-task":"warn"},Vb={recommended:{plugins:["qwik"],rules:Jp},strict:{plugins:["qwik"],rules:Wp}},Mn={configs:{get recommended(){return Ub},get strict(){return Bb}},meta:{name:Nn.name,version:Nn.version},rules:Bp},Ub=[{plugins:{qwik:Mn},rules:Jp}],Bb=[{plugins:{qwik:Mn},rules:Wp}];0&&(module.exports={configs,qwikEslint9Plugin,rules});
|
|
409
|
+
Use preventDefault attributes instead`}},create(r){return{"CallExpression[callee.property.name='preventDefault']"(e){let t=e.parent;for(;t;){if(t.type==="CallExpression"&&t.callee&&t.callee.type==="Identifier"&&t.callee.name==="$"){r.report({node:e,messageId:"noAsyncPreventDefault"});break}t=t.parent}}}}};var Pb=new Set(["useTask$","useTaskQrl"]);function kb(r){return r.callee.type==="Identifier"&&Pb.has(r.callee.name)}function Ib(r){let e=r.arguments[0];return e?.type==="ArrowFunctionExpression"||e?.type==="FunctionExpression"?e:null}function Fn(r){return r?r.type==="AssignmentPattern"?Fn(r.right):r.type==="Literal"&&r.value===!1?!0:r.type==="TSAsExpression"?Fn(r.expression):!1:!1}function Ob(r){let e=r.arguments[1];if(!e||e.type!=="ObjectExpression")return!1;for(let t of e.properties){if(t.type!=="Property"||t.computed)continue;let n=t.key;if((n.type==="Identifier"?n.name:n.type==="Literal"?String(n.value):null)==="deferUpdates"&&Fn(t.value))return!0}return!1}function jp(r){let e=new Set,t=[r];for(;t.length;){let n=t.pop();n.type==="VariableDeclarator"&&n.id.type==="Identifier"&&n.init&&n.init.type==="CallExpression"&&n.init.callee.type==="Identifier"&&n.init.callee.name==="useNavigate"&&e.add(n.id.name);for(let o of Object.keys(n)){if(o==="parent")continue;let i=n[o];if(Array.isArray(i))for(let a of i)a&&typeof a=="object"&&a!==null&&"type"in a&&t.push(a);else i&&typeof i=="object"&&"type"in i&&t.push(i)}}return e}function Cb(r){let e=new Set,t=r.parent;for(;t;){if(t.type==="ArrowFunctionExpression"||t.type==="FunctionExpression"){let n=t.parent;if(n?.type==="CallExpression"&&n.callee.type==="Identifier"&&n.callee.name==="component$")for(let o of jp(t))e.add(o)}if(t.type==="Program"){for(let n of jp(t))e.add(n);break}t=t.parent}return e}function $b(r,e,t){let n=[e];for(;n.length;){let o=n.pop();if(o.type==="AwaitExpression"){let i=o.argument;i.type==="CallExpression"&&i.callee.type==="Identifier"&&t.has(i.callee.name)&&r.report({node:o,messageId:"noAwaitBlocking",data:{name:i.callee.name}})}for(let i of Object.keys(o)){if(i==="parent")continue;let a=o[i];if(Array.isArray(a))for(let l of a)l&&typeof l=="object"&&l!==null&&"type"in l&&n.push(l);else a&&typeof a=="object"&&"type"in a&&n.push(a)}}}var Mp={meta:{type:"problem",docs:{description:"Disallow awaiting the function returned by `useNavigate()` inside blocking `useTask$` callbacks.",recommended:!0,url:"https://qwik.dev/docs/advanced/eslint/"},messages:{noAwaitBlocking:"Awaiting `{{name}}()` from `useNavigate()` inside a blocking `useTask$` can deadlock. Remove `await`, or pass `{ deferUpdates: false }` as the second argument to `useTask$`."}},create(r){return{CallExpression(e){if(!kb(e)||Ob(e))return;let t=Ib(e);if(!t)return;let n=Cb(e);n.size&&$b(r,t.body,n)}}}};var Nn={name:"eslint-plugin-qwik",description:"An Open-Source sub-framework designed with a focus on server-side-rendering, lazy-loading, and styling/animation.",version:"2.0.0-beta.35",author:"Qwik Team",bugs:"https://github.com/QwikDev/qwik/issues",dependencies:{"@typescript-eslint/utils":"^8.56.1","jsx-ast-utils":"^3.3.5"},devDependencies:{"@qwik.dev/core":"workspace:*","@qwik.dev/router":"workspace:*","@types/estree":"1.0.8","@typescript-eslint/rule-tester":"8.56.1",redent:"4.0.0"},engines:{node:"^18.17.0 || ^20.3.0 || >=21.0.0"},files:["README.md","dist"],homepage:"https://github.com/QwikDev/qwik#readme",keywords:["eslint","qwik"],license:"MIT",main:"dist/index.js",peerDependencies:{eslint:"^8.57.0 || ^9.0.0 || ^10.0.0"},repository:{type:"git",url:"https://github.com/QwikDev/qwik.git",directory:"packages/eslint-rules"},scripts:{test:"cd ../..; ./node_modules/.bin/vitest packages/eslint-plugin-qwik/qwik.unit.ts"}};var A=require("@typescript-eslint/utils"),Fb="isServer",Lp=["process","__dirname","__filename","module"],Dp=["fs","os","path","child_process","http","https","Buffer"];function Rn(r,e){if(!e)return!1;let t=r.parent;for(;t;){if(t===e)return!0;t=t.parent}return!1}var Vp={meta:{type:"problem",docs:{description:"Disallow direct or indirect (via one-level function call) Node.js API usage in useTask$ without a server guard (e.g., isServer).",category:"Best Practices",recommended:!0,url:""},fixable:void 0,schema:[{type:"object",properties:{forbiddenApis:{type:"array",items:{type:"string"},default:Dp}},additionalProperties:!1}],messages:{unsafeApiUsage:"Node.js API '{{apiName}}' should only be used inside an '{{guardName}}' block within useTask$. Example: if ({{guardName}}) { {{apiName}}.call(); }",unsafeApiUsageInCalledFunction:"Node.js API '{{apiName}}' used in function '{{calledFunctionName}}' (called from useTask$) needs '{{guardName}}' protection. Either guard the call site or protect the API usage within '{{calledFunctionName}}'."}},create(r){let e=r.options[0]||{},t=new Set(e.forbiddenApis||Dp.concat(Lp)),n=Fb,o=r.sourceCode,i=null;function a(u,f){let m=u.parent;for(;m&&m!==f.body&&m!==f;){if(m.type===A.AST_NODE_TYPES.IfStatement){let y=m;if(Rn(u,y.consequent)||u===y.consequent){let d=y.test;if(d.type===A.AST_NODE_TYPES.Identifier&&d.name===n||d.type===A.AST_NODE_TYPES.BinaryExpression&&d.operator==="==="&&(d.left.type===A.AST_NODE_TYPES.Identifier&&d.left.name===n&&d.right.type===A.AST_NODE_TYPES.Literal&&d.right.value===!0||d.right.type===A.AST_NODE_TYPES.Identifier&&d.right.name===n&&d.left.type===A.AST_NODE_TYPES.Literal&&d.left.value===!0)||d.type===A.AST_NODE_TYPES.UnaryExpression&&d.operator==="!"&&d.argument.type===A.AST_NODE_TYPES.UnaryExpression&&d.argument.operator==="!"&&d.argument.argument.type===A.AST_NODE_TYPES.Identifier&&d.argument.argument.name===n)return!0}}m=m.parent}return!1}function l(u){let f=o.getScope(u),m=null,y=f;if(!Lp.includes(u.name))return!0;for(;y;){let d=y.variables.find(v=>v.name===u.name);if(d){m=d;break}if(y.type==="global"){m=y.variables.find(v=>v.name===u.name);break}y=y.upper}return!m||m.defs.length===0?!1:m.defs.some(d=>d.type==="Variable"||d.type==="Parameter"||d.type==="FunctionName"||d.type==="ClassName"||d.type==="ImportBinding")}function p(u,f,m){function y(d){if(!d)return!1;if(d.type===A.AST_NODE_TYPES.Identifier&&t.has(d.name)&&!l(d)&&!a(d,f))return r.report({node:m,messageId:"unsafeApiUsageInCalledFunction",data:{apiName:d.name,calledFunctionName:f.id?.name||(m.type===A.AST_NODE_TYPES.Identifier?m.name:"[anonymous]"),guardName:n}}),!0;for(let v in d){if(v==="parent"||v==="range"||v==="loc")continue;let c=d[v];if(Array.isArray(c)){for(let g of c)if(g&&typeof g=="object"&&"type"in g&&y(g))return!0}else if(c&&typeof c=="object"&&"type"in c&&y(c))return!0}return!1}y(u)}return{":function"(u){let f=u.parent;f&&f.type===A.AST_NODE_TYPES.CallExpression&&f.callee.type===A.AST_NODE_TYPES.Identifier&&f.callee.name==="useTask$"&&f.arguments.length>0&&f.arguments[0]===u&&(i=u)},":function:exit"(u){i===u&&(i=null)},Identifier(u){if(i&&!(i.body!==u&&!Rn(u,i.body))&&!(u.parent&&u.parent.type===A.AST_NODE_TYPES.CallExpression&&u.parent.callee===u)&&t.has(u.name)){if(l(u))return;a(u,i)||r.report({node:u,messageId:"unsafeApiUsage",data:{apiName:u.name,guardName:n}})}},CallExpression(u){if(i&&Rn(u,i.body)&&!a(u,i)&&u.callee.type===A.AST_NODE_TYPES.Identifier){let f=u.callee,m=o.getScope(f),y=null,d=m.references.find(c=>c.identifier===f);if(d&&d.resolved)y=d.resolved;else{let c=m;for(;c;){let g=c.variables.find(b=>b.name===f.name);if(g&&g.defs.length>0){y=g;break}if(c.type==="global"&&!g){let b=c.type==="global"?c.variables.find(w=>w.name===f.name):null;b&&(y=b);break}if(!c.upper)break;c=c.upper}}let v=y;if(v&&v.defs.length>0){let c=v.defs[0],g=null;if(c.node.type===A.AST_NODE_TYPES.FunctionDeclaration?g=c.node:c.node.type===A.AST_NODE_TYPES.VariableDeclarator&&c.node.init&&(c.node.init.type===A.AST_NODE_TYPES.FunctionExpression||c.node.init.type===A.AST_NODE_TYPES.ArrowFunctionExpression)&&(g=c.node.init),g){let b=(g.body.type===A.AST_NODE_TYPES.BlockStatement,g.body);p(b,g,u)}}}}}}};var x=require("@typescript-eslint/utils"),z=ee(require("typescript"));function jn(r){return r?.defs?.some(e=>{if(e.type!=="ImportBinding")return!1;let t=e.parent.source.value;return t.startsWith("@qwik.dev/core")||t.startsWith("@qwik.dev/router")||t.startsWith("@builder.io/qwik")||t.startsWith("@builder.io/qwik-city")})}function Le(r,e){let t=r.sourceCode.getScope(e),n=t.references.find(i=>i.identifier===e);if(n&&n.resolved)return n.resolved;let o=t;for(;o;){let i=o.variables.find(a=>a.name===e.name);if(i)return i;o=o.upper}return null}function Nb(r,e){if(!e||e.type!==x.AST_NODE_TYPES.Identifier||!e.name.endsWith("$"))return!1;let t=Le(r,e);return jn(t)}function Rb(r){let e=r.body[0];if(!e||e.type!==x.AST_NODE_TYPES.ExpressionStatement)return null;let t=e.expression;return t.type===x.AST_NODE_TYPES.MemberExpression&&!t.computed&&t.property.type===x.AST_NODE_TYPES.Identifier&&t.property.name==="value"?e:null}function jb(r,e){let t=Le(r,e);if(!t||t.defs&&t.defs.length===0)return!1;let n=r.sourceCode.parserServices,o=n?.program?.getTypeChecker(),i=n?.esTreeNodeToTSNodeMap;function a(l){if(!l)return!1;if(z.default.isVariableDeclaration(l)&&l.initializer&&z.default.isCallExpression(l.initializer)){let p=l.initializer.expression;if(z.default.isIdentifier(p)){let u=p.text;return u==="createAsync$"||u==="useAsync$"||u==="routeLoader$"}}return z.default.isExportSpecifier(l)||z.default.isImportSpecifier(l),!1}for(let l of t.defs){if(l.type==="Variable"&&l.node.type===x.AST_NODE_TYPES.VariableDeclarator){let p=l.node.init;if(p&&p.type===x.AST_NODE_TYPES.CallExpression){let u=p.callee;if(u.type===x.AST_NODE_TYPES.Identifier){let f=u.name;if((f==="useAsync$"||f==="createAsync$"||f==="routeLoader$")&&jn(Le(r,u)))return!0;let m=Le(r,u);if(m&&m.defs){for(let y of m.defs)if(y.type==="Variable"&&y.node.type===x.AST_NODE_TYPES.VariableDeclarator){let d=y.node.init;if(d&&d.type===x.AST_NODE_TYPES.CallExpression){let v=d.callee;if(v.type===x.AST_NODE_TYPES.Identifier&&v.name==="routeLoader$"&&jn(Le(r,v)))return!0}}}}}}if(l.type==="ImportBinding"&&o&&i)try{let p=i.get(e);if(p){let u=o.getSymbolAtLocation(p);if(u&&u.flags&z.default.SymbolFlags.Alias&&(u=o.getAliasedSymbol(u)),u){for(let y of u.declarations??[]){if(a(y))return!0;if(z.default.isVariableStatement(y)){for(let d of y.declarationList.declarations)if(a(d))return!0}}let f=o.getTypeOfSymbolAtLocation(u,p),m=o.typeToString(f.getNonNullableType());if(/Async/i.test(m))return!0}}}catch{}}if(o&&i)try{let l=i.get(e),p=o.getTypeAtLocation(l),u=o.typeToString(p.getNonNullableType());if(/Async|LoaderSignal/i.test(u))return!0}catch{}return!1}function Mb(r,e,t){for(let n of r.body){if(n===e)break;if(n.type!==x.AST_NODE_TYPES.ExpressionStatement)continue;let o=n.expression;if(o.type!==x.AST_NODE_TYPES.AwaitExpression)continue;let i=o.argument;if(i.type===x.AST_NODE_TYPES.CallExpression&&(i=i.callee),i.type===x.AST_NODE_TYPES.MemberExpression&&!i.computed&&i.object.type===x.AST_NODE_TYPES.Identifier&&i.object.name===t&&i.property.type===x.AST_NODE_TYPES.Identifier&&i.property.name==="promise")return!0}return!1}function Lb(r){let e=r;for(;e;){if(e.type===x.AST_NODE_TYPES.FunctionDeclaration||e.type===x.AST_NODE_TYPES.FunctionExpression||e.type===x.AST_NODE_TYPES.ArrowFunctionExpression)return e;e=e.parent}return null}function Db(r,e,t){let n=e.parent;if(n&&n.type===x.AST_NODE_TYPES.CallExpression&&n.callee.type===x.AST_NODE_TYPES.Identifier&&Nb(r,n.callee)){for(let o of n.arguments)if(o===e)return!0}if(e.async){for(let o of e.params)if(o.type===x.AST_NODE_TYPES.Identifier&&o.name===t.name)return!0}return!1}var Up={meta:{type:"problem",docs:{description:"Warn when an async computed signal '.value' is read not at the top of a QRL callback.",recommended:!1,url:""},schema:[],messages:{asyncComputedNotTop:"Async computed '{{name}}.value' must be first, or use 'await {{name}}.promise()' beforehand."}},create(r){return{MemberExpression(e){if(e.computed||e.property.type!==x.AST_NODE_TYPES.Identifier||e.property.name!=="value")return;let t=e.object;if(t.type!==x.AST_NODE_TYPES.Identifier||!jb(r,t))return;let n=Lb(e);if(!n||!Db(r,n,t))return;let o=e.parent;if(!o||o.type!==x.AST_NODE_TYPES.ExpressionStatement&&o.type!==x.AST_NODE_TYPES.ReturnStatement)return;let i=n.body&&n.body.type===x.AST_NODE_TYPES.BlockStatement?n.body:null;if(!i)return n.body.type===x.AST_NODE_TYPES.MemberExpression&&n.body===e,void 0;o.parent!==i||i.body[0]===o||Rb(i)===o||(o.type===x.AST_NODE_TYPES.ExpressionStatement||o.type===x.AST_NODE_TYPES.ReturnStatement)&&Mb(i,o,t.name)||r.report({node:e,messageId:"asyncComputedNotTop",data:{name:t.name}})}}}};var Bp={"valid-lexical-scope":Cp,"use-method-usage":Op,"no-react-props":Ap,"loader-location":Tp,"prefer-classlist":kp,"jsx-no-script-url":wp,"jsx-key":xp,"unused-server":Ip,"jsx-img":Hn,"jsx-a":Wn,"no-use-visible-task":Pp,"serializer-signal-usage":Np,"scope-use-task":Vp,"use-async-top":Up,"no-async-prevent-default":Rp,"no-await-navigate-in-use-task":Mp},Jp={"qwik/valid-lexical-scope":"error","qwik/use-method-usage":"error","qwik/no-react-props":"error","qwik/loader-location":"warn","qwik/prefer-classlist":"warn","qwik/jsx-no-script-url":"warn","qwik/jsx-key":"warn","qwik/unused-server":"error","qwik/jsx-img":"warn","qwik/jsx-a":"warn","qwik/no-use-visible-task":"warn","qwik/serializer-signal-usage":"error","qwik/scope-use-task":"error","qwik/use-async-top":"warn","qwik/no-async-prevent-default":"warn","qwik/no-await-navigate-in-use-task":"warn"},Wp={"qwik/valid-lexical-scope":"error","qwik/use-method-usage":"error","qwik/no-react-props":"error","qwik/loader-location":"error","qwik/prefer-classlist":"error","qwik/jsx-no-script-url":"error","qwik/jsx-key":"error","qwik/unused-server":"error","qwik/jsx-img":"error","qwik/jsx-a":"error","qwik/no-use-visible-task":"warn","qwik/serializer-signal-usage":"error","qwik/scope-use-task":"error","qwik/use-async-top":"warn","qwik/no-async-prevent-default":"warn","qwik/no-await-navigate-in-use-task":"warn"},Vb={recommended:{plugins:["qwik"],rules:Jp},strict:{plugins:["qwik"],rules:Wp}},Mn={configs:{get recommended(){return Ub},get strict(){return Bb}},meta:{name:Nn.name,version:Nn.version},rules:Bp},Ub=[{plugins:{qwik:Mn},rules:Jp}],Bb=[{plugins:{qwik:Mn},rules:Wp}];0&&(module.exports={configs,qwikEslint9Plugin,rules});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-qwik",
|
|
3
3
|
"description": "An Open-Source sub-framework designed with a focus on server-side-rendering, lazy-loading, and styling/animation.",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.35",
|
|
5
5
|
"author": "Qwik Team",
|
|
6
6
|
"bugs": "https://github.com/QwikDev/qwik/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"@types/estree": "1.0.8",
|
|
13
13
|
"@typescript-eslint/rule-tester": "8.56.1",
|
|
14
14
|
"redent": "4.0.0",
|
|
15
|
-
"@qwik.dev/core": "2.0.0-beta.
|
|
16
|
-
"@qwik.dev/router": "2.0.0-beta.
|
|
15
|
+
"@qwik.dev/core": "2.0.0-beta.35",
|
|
16
|
+
"@qwik.dev/router": "2.0.0-beta.35"
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|