solhint-plugin-mud 2.0.0-alpha.1.192 → 2.0.0-alpha.1.193

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 CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var o=require("@solidity-parser/parser"),e=class{ruleId="no-msg-sender";reporter;config;constructor(r,t,s,i){this.reporter=r,this.config=t}ContractDefinition(r){let{name:t,kind:s}=r,i=this.reporter,c=this.ruleId;(s==="library"||s==="contract"&&t.endsWith("System"))&&(0,o.visit)(r,{MemberAccess(n){let{expression:m,memberName:a}=n;m.type==="Identifier"&&a==="sender"&&i.error(n,c,'Systems and their libraries should use "_msgSender()" or "_world()" instead of "msg.sender".')}})}};module.exports=[e];
1
+ "use strict";var l=Object.create;var a=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var u=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of y(t))!S.call(r,s)&&s!==e&&a(r,s,{get:()=>t[s],enumerable:!(i=h(t,s))||i.enumerable});return r};var C=(r,t,e)=>(e=r!=null?l(d(r)):{},u(t||!r||!r.__esModule?a(e,"default",{value:r,enumerable:!0}):e,r));var n=class{ruleId="no-msg-sender";reporter;config;isSystemOrLibrary=!1;constructor(t,e){this.reporter=t,this.config=e}ContractDefinition(t){let{name:e,kind:i}=t;this.isSystemOrLibrary=i==="library"||i==="contract"&&e.endsWith("System")}"ContractDefinition:exit"(){this.isSystemOrLibrary=!1}MemberAccess(t){let{expression:e,memberName:i}=t;e.type==="Identifier"&&i==="sender"&&this.reporter.error(t,this.ruleId,'Systems and their libraries should use "_msgSender()" or "_world()" instead of "msg.sender".')}};var c=C(require("path")),m=require("@solidity-parser/parser"),o=class{ruleId="system-file-name";reporter;config;expectedContractName;isSystemFile=!1;constructor(t,e,i,s){this.reporter=t,this.config=e,this.expectedContractName=c.default.basename(s,".sol"),this.expectedContractName.endsWith("System")&&this.expectedContractName!=="System"&&!this.expectedContractName.match(/^I[A-Z]/)&&(this.isSystemFile=!0)}SourceUnit(t){if(!this.isSystemFile)return;let e=this.expectedContractName,i=!1;(0,m.visit)(t,{ContractDefinition(s){let{name:p,kind:f}=s;f==="contract"&&p===e&&(i=!0)}}),i||this.reporter.error(t,this.ruleId,`System file must contain a contract with a matching name "${e}"`)}};module.exports=[n,o];
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/rules/NoMsgSender.ts","../src/index.ts"],"sourcesContent":["import { visit } from \"@solidity-parser/parser\";\nimport type { ContractDefinition, MemberAccess } from \"@solidity-parser/parser/dist/src/ast-types\";\nimport { SolhintRule } from \"../solhintTypes\";\n\nexport class NoMsgSender implements SolhintRule {\n ruleId = \"no-msg-sender\";\n reporter: any;\n config: any;\n\n constructor(reporter: any, config: any, inputSrc: string, fileName: string) {\n this.reporter = reporter;\n this.config = config;\n }\n\n ContractDefinition(node: ContractDefinition) {\n const { name, kind } = node;\n const reporter = this.reporter;\n const ruleId = this.ruleId;\n\n if (kind === \"library\" || (kind === \"contract\" && name.endsWith(\"System\"))) {\n visit(node, {\n MemberAccess(node: MemberAccess) {\n const { expression, memberName } = node;\n if (expression.type === \"Identifier\" && memberName === \"sender\") {\n reporter.error(\n node,\n ruleId,\n `Systems and their libraries should use \"_msgSender()\" or \"_world()\" instead of \"msg.sender\".`\n );\n }\n },\n });\n }\n }\n}\n","import { NoMsgSender } from \"./rules/NoMsgSender\";\n\nexport = [NoMsgSender];\n"],"mappings":"aAAA,IAAAA,EAAsB,mCAITC,EAAN,KAAyC,CAC9C,OAAS,gBACT,SACA,OAEA,YAAYC,EAAeC,EAAaC,EAAkBC,EAAkB,CAC1E,KAAK,SAAWH,EAChB,KAAK,OAASC,CAChB,CAEA,mBAAmBG,EAA0B,CAC3C,GAAM,CAAE,KAAAC,EAAM,KAAAC,CAAK,EAAIF,EACjBJ,EAAW,KAAK,SAChBO,EAAS,KAAK,QAEhBD,IAAS,WAAcA,IAAS,YAAcD,EAAK,SAAS,QAAQ,OACtE,SAAMD,EAAM,CACV,aAAaA,EAAoB,CAC/B,GAAM,CAAE,WAAAI,EAAY,WAAAC,CAAW,EAAIL,EAC/BI,EAAW,OAAS,cAAgBC,IAAe,UACrDT,EAAS,MACPI,EACAG,EACA,8FACF,CAEJ,CACF,CAAC,CAEL,CACF,EChCA,eAAS,CAACG,CAAW","names":["import_parser","NoMsgSender","reporter","config","inputSrc","fileName","node","name","kind","ruleId","expression","memberName","NoMsgSender"]}
1
+ {"version":3,"sources":["../src/rules/NoMsgSender.ts","../src/rules/SystemFileName.ts","../src/index.ts"],"sourcesContent":["import type { ContractDefinition, MemberAccess } from \"@solidity-parser/parser/dist/src/ast-types\";\nimport { SolhintRule } from \"../solhintTypes\";\n\nexport class NoMsgSender implements SolhintRule {\n ruleId = \"no-msg-sender\";\n reporter: any;\n config: any;\n\n isSystemOrLibrary = false;\n\n constructor(reporter: any, config: any) {\n this.reporter = reporter;\n this.config = config;\n }\n\n ContractDefinition(node: ContractDefinition) {\n const { name, kind } = node;\n\n this.isSystemOrLibrary = kind === \"library\" || (kind === \"contract\" && name.endsWith(\"System\"));\n }\n\n \"ContractDefinition:exit\"() {\n this.isSystemOrLibrary = false;\n }\n\n MemberAccess(node: MemberAccess) {\n const { expression, memberName } = node;\n if (expression.type === \"Identifier\" && memberName === \"sender\") {\n this.reporter.error(\n node,\n this.ruleId,\n `Systems and their libraries should use \"_msgSender()\" or \"_world()\" instead of \"msg.sender\".`\n );\n }\n }\n}\n","import path from \"path\";\nimport { visit } from \"@solidity-parser/parser\";\nimport type { ContractDefinition, SourceUnit } from \"@solidity-parser/parser/dist/src/ast-types\";\nimport { SolhintRule } from \"../solhintTypes\";\n\nexport class SystemFileName implements SolhintRule {\n ruleId = \"system-file-name\";\n reporter: any;\n config: any;\n\n expectedContractName: string;\n isSystemFile = false;\n\n constructor(reporter: any, config: any, inputSrc: string, fileName: string) {\n this.reporter = reporter;\n this.config = config;\n\n this.expectedContractName = path.basename(fileName, \".sol\");\n if (\n this.expectedContractName.endsWith(\"System\") &&\n this.expectedContractName !== \"System\" &&\n !this.expectedContractName.match(/^I[A-Z]/)\n ) {\n this.isSystemFile = true;\n }\n }\n\n SourceUnit(node: SourceUnit) {\n // only systems need a matching contract\n if (!this.isSystemFile) return;\n const expectedContractName = this.expectedContractName;\n\n // search the source file for a matching contract name\n let withMatchingContract = false;\n visit(node, {\n ContractDefinition(node: ContractDefinition) {\n const { name, kind } = node;\n\n if (kind === \"contract\" && name === expectedContractName) {\n withMatchingContract = true;\n }\n },\n });\n\n if (!withMatchingContract) {\n this.reporter.error(\n node,\n this.ruleId,\n `System file must contain a contract with a matching name \"${expectedContractName}\"`\n );\n }\n }\n}\n","import { NoMsgSender } from \"./rules/NoMsgSender\";\nimport { SystemFileName } from \"./rules/SystemFileName\";\n\nexport = [NoMsgSender, SystemFileName];\n"],"mappings":"wdAGO,IAAMA,EAAN,KAAyC,CAC9C,OAAS,gBACT,SACA,OAEA,kBAAoB,GAEpB,YAAYC,EAAeC,EAAa,CACtC,KAAK,SAAWD,EAChB,KAAK,OAASC,CAChB,CAEA,mBAAmBC,EAA0B,CAC3C,GAAM,CAAE,KAAAC,EAAM,KAAAC,CAAK,EAAIF,EAEvB,KAAK,kBAAoBE,IAAS,WAAcA,IAAS,YAAcD,EAAK,SAAS,QAAQ,CAC/F,CAEA,2BAA4B,CAC1B,KAAK,kBAAoB,EAC3B,CAEA,aAAaD,EAAoB,CAC/B,GAAM,CAAE,WAAAG,EAAY,WAAAC,CAAW,EAAIJ,EAC/BG,EAAW,OAAS,cAAgBC,IAAe,UACrD,KAAK,SAAS,MACZJ,EACA,KAAK,OACL,8FACF,CAEJ,CACF,ECnCA,IAAAK,EAAiB,mBACjBC,EAAsB,mCAITC,EAAN,KAA4C,CACjD,OAAS,mBACT,SACA,OAEA,qBACA,aAAe,GAEf,YAAYC,EAAeC,EAAaC,EAAkBC,EAAkB,CAC1E,KAAK,SAAWH,EAChB,KAAK,OAASC,EAEd,KAAK,qBAAuB,EAAAG,QAAK,SAASD,EAAU,MAAM,EAExD,KAAK,qBAAqB,SAAS,QAAQ,GAC3C,KAAK,uBAAyB,UAC9B,CAAC,KAAK,qBAAqB,MAAM,SAAS,IAE1C,KAAK,aAAe,GAExB,CAEA,WAAWE,EAAkB,CAE3B,GAAI,CAAC,KAAK,aAAc,OACxB,IAAMC,EAAuB,KAAK,qBAG9BC,EAAuB,MAC3B,SAAMF,EAAM,CACV,mBAAmBA,EAA0B,CAC3C,GAAM,CAAE,KAAAG,EAAM,KAAAC,CAAK,EAAIJ,EAEnBI,IAAS,YAAcD,IAASF,IAClCC,EAAuB,GAE3B,CACF,CAAC,EAEIA,GACH,KAAK,SAAS,MACZF,EACA,KAAK,OACL,6DAA6DC,IAC/D,CAEJ,CACF,ECjDA,eAAS,CAACI,EAAaC,CAAc","names":["NoMsgSender","reporter","config","node","name","kind","expression","memberName","import_path","import_parser","SystemFileName","reporter","config","inputSrc","fileName","path","node","expectedContractName","withMatchingContract","name","kind","NoMsgSender","SystemFileName"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solhint-plugin-mud",
3
- "version": "2.0.0-alpha.1.192+966b379d",
3
+ "version": "2.0.0-alpha.1.193+a18fb753",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/latticexyz/mud.git",
@@ -21,10 +21,11 @@
21
21
  "@solidity-parser/parser": "^0.16.0"
22
22
  },
23
23
  "devDependencies": {
24
+ "@types/node": "^18.15.11",
24
25
  "tsup": "^6.7.0"
25
26
  },
26
27
  "publishConfig": {
27
28
  "access": "public"
28
29
  },
29
- "gitHead": "966b379d6331ff7d9f176d098a0b51f022d442d7"
30
+ "gitHead": "a18fb753aefc74519f4345ee35b04802e1057309"
30
31
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { NoMsgSender } from "./rules/NoMsgSender";
2
+ import { SystemFileName } from "./rules/SystemFileName";
2
3
 
3
- export = [NoMsgSender];
4
+ export = [NoMsgSender, SystemFileName];
@@ -1,4 +1,3 @@
1
- import { visit } from "@solidity-parser/parser";
2
1
  import type { ContractDefinition, MemberAccess } from "@solidity-parser/parser/dist/src/ast-types";
3
2
  import { SolhintRule } from "../solhintTypes";
4
3
 
@@ -7,29 +6,31 @@ export class NoMsgSender implements SolhintRule {
7
6
  reporter: any;
8
7
  config: any;
9
8
 
10
- constructor(reporter: any, config: any, inputSrc: string, fileName: string) {
9
+ isSystemOrLibrary = false;
10
+
11
+ constructor(reporter: any, config: any) {
11
12
  this.reporter = reporter;
12
13
  this.config = config;
13
14
  }
14
15
 
15
16
  ContractDefinition(node: ContractDefinition) {
16
17
  const { name, kind } = node;
17
- const reporter = this.reporter;
18
- const ruleId = this.ruleId;
19
18
 
20
- if (kind === "library" || (kind === "contract" && name.endsWith("System"))) {
21
- visit(node, {
22
- MemberAccess(node: MemberAccess) {
23
- const { expression, memberName } = node;
24
- if (expression.type === "Identifier" && memberName === "sender") {
25
- reporter.error(
26
- node,
27
- ruleId,
28
- `Systems and their libraries should use "_msgSender()" or "_world()" instead of "msg.sender".`
29
- );
30
- }
31
- },
32
- });
19
+ this.isSystemOrLibrary = kind === "library" || (kind === "contract" && name.endsWith("System"));
20
+ }
21
+
22
+ "ContractDefinition:exit"() {
23
+ this.isSystemOrLibrary = false;
24
+ }
25
+
26
+ MemberAccess(node: MemberAccess) {
27
+ const { expression, memberName } = node;
28
+ if (expression.type === "Identifier" && memberName === "sender") {
29
+ this.reporter.error(
30
+ node,
31
+ this.ruleId,
32
+ `Systems and their libraries should use "_msgSender()" or "_world()" instead of "msg.sender".`
33
+ );
33
34
  }
34
35
  }
35
36
  }
@@ -0,0 +1,53 @@
1
+ import path from "path";
2
+ import { visit } from "@solidity-parser/parser";
3
+ import type { ContractDefinition, SourceUnit } from "@solidity-parser/parser/dist/src/ast-types";
4
+ import { SolhintRule } from "../solhintTypes";
5
+
6
+ export class SystemFileName implements SolhintRule {
7
+ ruleId = "system-file-name";
8
+ reporter: any;
9
+ config: any;
10
+
11
+ expectedContractName: string;
12
+ isSystemFile = false;
13
+
14
+ constructor(reporter: any, config: any, inputSrc: string, fileName: string) {
15
+ this.reporter = reporter;
16
+ this.config = config;
17
+
18
+ this.expectedContractName = path.basename(fileName, ".sol");
19
+ if (
20
+ this.expectedContractName.endsWith("System") &&
21
+ this.expectedContractName !== "System" &&
22
+ !this.expectedContractName.match(/^I[A-Z]/)
23
+ ) {
24
+ this.isSystemFile = true;
25
+ }
26
+ }
27
+
28
+ SourceUnit(node: SourceUnit) {
29
+ // only systems need a matching contract
30
+ if (!this.isSystemFile) return;
31
+ const expectedContractName = this.expectedContractName;
32
+
33
+ // search the source file for a matching contract name
34
+ let withMatchingContract = false;
35
+ visit(node, {
36
+ ContractDefinition(node: ContractDefinition) {
37
+ const { name, kind } = node;
38
+
39
+ if (kind === "contract" && name === expectedContractName) {
40
+ withMatchingContract = true;
41
+ }
42
+ },
43
+ });
44
+
45
+ if (!withMatchingContract) {
46
+ this.reporter.error(
47
+ node,
48
+ this.ruleId,
49
+ `System file must contain a contract with a matching name "${expectedContractName}"`
50
+ );
51
+ }
52
+ }
53
+ }