eslint-plugin-vue-2-object-reactivity
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -1,1 +0,1 @@ | ||
var M=Object.create;var b=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var N=e=>b(e,"__esModule",{value:!0});var U=(e,s,c)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of P(s))!q.call(e,o)&&o!=="default"&&b(e,o,{get:()=>s[o],enumerable:!(c=V(s,o))||c.enumerable});return e},S=e=>U(N(b(e!=null?M(R(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var T=typeof document=="undefined"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var g=S(require("@typescript-eslint/experimental-utils")),t=S(require("eslint-etc")),u=S(require("typescript")),p=e=>process.env.DEBUG&&console.log(e),v=g.ESLintUtils.RuleCreator(()=>"https://github.com/Maxim-Mazurok/eslint-plugin-vue-2-object-reactivity")({name:"require-vue-set",meta:{type:"problem",docs:{description:"Require `Vue.set()` for object changes",category:"Possible Errors",recommended:"error"},messages:{useVueSet:"Use `Vue.set()` for changing objects in state"},schema:[]},defaultOptions:[],create:e=>{let{esTreeNodeToTSNodeMap:s,tsNodeToESTreeNodeMap:c}=g.ESLintUtils.getParserServices(e);function o(h){let E=s.get(h.value);(0,u.isObjectLiteralExpression)(E)&&E.properties.map(i=>{if((0,u.isMethodDeclaration)(i)&&(p(`Mutation name: ${i.name.getText()}`),i.parameters.length>=1)){let m=i.parameters[0].name.getText();p(`State parameter name: ${m}`);let y=i.body;if(y!==void 0){let x=e.getScope(),k=c.get(y),d=x.childScopes.find(a=>(0,t.isFunctionExpression)(a.block)&&a.block.body===k);if(d!==void 0){let a=d.variables.find(j=>j.name===m);a!==void 0&&d.references.filter(f=>f.resolved===a).find(f=>{let l=f.identifier.parent;if(l!==void 0&&(0,t.isMemberExpression)(l)){let n=l.parent;n!==void 0&&(0,t.isCallExpression)(n)&&(0,t.isMemberExpression)(n.callee)&&(0,t.isIdentifier)(n.callee.object)&&(0,t.isIdentifier)(n.callee.property)&&(n.callee.object.name==="Vue"&&n.callee.property.name,p("Yay, Vue.set(state) found!"));let r=l;do{if(r.parent===void 0)break;r=r.parent}while(r!==null&&!(0,t.isAssignmentExpression)(r));r!==null&&(0,t.isAssignmentExpression)(r)&&(0,t.isMemberExpression)(r.left)&&(0,t.isMemberExpression)(r.left.object)&&(0,t.isIdentifier)(r.left.object.object)&&r.left.object.object.name===m&&(p("Oh-oh, state.object.something = ... found!"),e.report({node:h,messageId:"useVueSet"}))}})}}}})}return{'Property[key.name="mutations"][value.type="ObjectExpression"][value.properties.length!=0]':o}}});module.exports={rules:{"require-vue-set":v}}; | ||
var f=require("@typescript-eslint/experimental-utils"),e=require("eslint-etc"),p=require("typescript"),l=s=>process.env.DEBUG&&console.log(s),E=f.ESLintUtils.RuleCreator(()=>"https://github.com/Maxim-Mazurok/eslint-plugin-vue-2-object-reactivity")({name:"require-vue-set",meta:{type:"problem",docs:{description:"Require `Vue.set()` for object changes",category:"Possible Errors",recommended:"error"},messages:{useVueSet:"Use `Vue.set()` for changing objects in state"},schema:[]},defaultOptions:[],create:s=>{let{esTreeNodeToTSNodeMap:b,tsNodeToESTreeNodeMap:h}=f.ESLintUtils.getParserServices(s),S=(r,n)=>{(0,p.isObjectLiteralExpression)(r)&&r.properties.map(a=>{if((0,p.isMethodDeclaration)(a)&&(l(`Mutation name: ${a.name.getText()}`),a.parameters.length>=1)){let u=a.parameters[0].name.getText();l(`State parameter name: ${u}`);let g=a.body;if(g!==void 0){let V=s.getScope(),v=h.get(g),d=V.childScopes.find(i=>(0,e.isFunctionExpression)(i.block)&&i.block.body===v);if(d!==void 0){let i=d.variables.find(T=>T.name===u);i!==void 0&&d.references.filter(m=>m.resolved===i).find(m=>{let c=m.identifier.parent;if(c!==void 0&&(0,e.isMemberExpression)(c)){let o=c.parent;o!==void 0&&(0,e.isCallExpression)(o)&&(0,e.isMemberExpression)(o.callee)&&(0,e.isIdentifier)(o.callee.object)&&(0,e.isIdentifier)(o.callee.property)&&(o.callee.object.name==="Vue"&&o.callee.property.name,l("Yay, Vue.set(state) found!"));let t=c;do{if(t.parent===void 0)break;t=t.parent}while(t!==null&&!(0,e.isAssignmentExpression)(t));t!==null&&(0,e.isAssignmentExpression)(t)&&(0,e.isMemberExpression)(t.left)&&(0,e.isMemberExpression)(t.left.object)&&(0,e.isIdentifier)(t.left.object.object)&&t.left.object.object.name===u&&(l("Oh-oh, state.object.something = ... found!"),s.report({node:n,messageId:"useVueSet"}))}})}}}})};function y(r){let n=b.get(r.value);S(n,r)}function j(r){let n=b.get(r.init);S(n,r)}return{'Property[key.name="mutations"][value.type="ObjectExpression"][value.properties.length!=0]':y,"VariableDeclaration > [id.name=mutations]":j}}});module.exports={rules:{"require-vue-set":E}}; |
{ | ||
"name": "eslint-plugin-vue-2-object-reactivity", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "These rules aim to solve the problem with Vue 2 Object Reactivity", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -7,2 +7,26 @@ # eslint-plugin-vue-2-object-reactivity | ||
### What does it catch | ||
1. When `mutations` is a property, for example: | ||
```ts | ||
export default new Vuex.Store<{ object: { [key: string]: string } }>({ | ||
//... | ||
mutations: { | ||
setPropOnObject(state, { prop, val }: { prop: string; val: string }) { | ||
state.object[prop] = val; // <== this will be reported as error | ||
Vue.set(state.object, prop, val); // <== this is correct/expected | ||
}, | ||
}, | ||
}); | ||
``` | ||
2. When `mutations` is a variable (not necessarily used in `Vuex.Store`, just searching for the name "mutations"), for example: | ||
```ts | ||
const mutations: { | ||
setPropOnObject(state, { prop, val }: { prop: string; val: string }) { | ||
state.object[prop] = val; // <== this will be reported as error | ||
Vue.set(state.object, prop, val); // <== this is correct/expected | ||
}, | ||
}; | ||
``` | ||
### Users | ||
@@ -9,0 +33,0 @@ |
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
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
14152
103
8
1