solhint-plugin-mud 1.42.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/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present Lattice Labs Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # solhint-plugin-mud
2
+
3
+ Solhint plugin for MUD-based projects
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
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
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "solhint-plugin-mud",
3
+ "version": "1.42.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/latticexyz/mud.git",
7
+ "directory": "packages/solhint-plugin-mud"
8
+ },
9
+ "license": "MIT",
10
+ "exports": {
11
+ ".": "./dist/index.js"
12
+ },
13
+ "types": "./src/index.ts",
14
+ "dependencies": {
15
+ "@solidity-parser/parser": "^0.16.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^18.15.11",
19
+ "tsup": "^6.7.0"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f",
25
+ "scripts": {
26
+ "build": "pnpm run build:js",
27
+ "build:js": "tsup",
28
+ "clean": "pnpm run clean:js",
29
+ "clean:js": "rimraf dist"
30
+ }
31
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { NoMsgSender } from "./rules/NoMsgSender";
2
+ import { SystemFileName } from "./rules/SystemFileName";
3
+
4
+ export = [NoMsgSender, SystemFileName];
@@ -0,0 +1,36 @@
1
+ import type { ContractDefinition, MemberAccess } from "@solidity-parser/parser/dist/src/ast-types";
2
+ import { SolhintRule } from "../solhintTypes";
3
+
4
+ export class NoMsgSender implements SolhintRule {
5
+ ruleId = "no-msg-sender";
6
+ reporter: any;
7
+ config: any;
8
+
9
+ isSystemOrLibrary = false;
10
+
11
+ constructor(reporter: any, config: any) {
12
+ this.reporter = reporter;
13
+ this.config = config;
14
+ }
15
+
16
+ ContractDefinition(node: ContractDefinition) {
17
+ const { name, kind } = node;
18
+
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
+ );
34
+ }
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
+ }
@@ -0,0 +1,5 @@
1
+ export interface SolhintRule {
2
+ ruleId: string;
3
+ reporter: any;
4
+ config: any;
5
+ }