Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contract): linting and typedefs #26

Closed
wants to merge 13 commits into from
Closed

Conversation

0xpatrickdev
Copy link
Member

@0xpatrickdev 0xpatrickdev commented Dec 30, 2023

Testing

Tested generated bundle sizes with both yarn install and agoric install. I also tested the case described in #28:

Installation Method Dependency Scenario File Name Bundle Size
Yarn Install Without assertIssuerKeywords b1-a8760...8f376.json 1.3M
b1-ede66...0121fe.json 1.3M
With assertIssuerKeywords b1-b1249...04c22.json 3.4M
b1-e507d...928b9.json 1.3M
Agoric Install Without assertIssuerKeywords b1-08392...9bb07.json 1.1M
b1-0888e...617e8.json 966K
With assertIssuerKeywords b1-c1d41...09dbd2.json 1.5M
b1-0888e...617e8.json 966K

@0xpatrickdev 0xpatrickdev requested review from turadg and dckc December 30, 2023 00:49
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see several important things...

"lint-fix": "eslint --fix '**/*.{js,ts}'",
"lint-fix-jessie": "eslint -c '.eslintrc-jessie.js' --fix '**/*.js'",
"lint-jessie": "eslint -c '.eslintrc-jessie.js' '**/*.js'",
"typecheck": "tsc"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not critical:

elsewhere this is called lint:types and we have lint:eslint and lint does both.

see the PR linked from Agoric/agoric-sdk#8274 (reply in thread)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, didn't want to change lint-* as a part of this, but agree it should standardized.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see 3ce6458

"@endo/bundle-source": "^2.8.0",
"@endo/eslint-plugin": "^0.5.2",
"@endo/init": "^0.5.60",
"@endo/promise-kit": "^1.0.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important
That version smells like trouble. We need to keep the endo versions consistent, and I'm pretty sure this dapp is not up to the 1.x stuff yet.

cf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated to 0.2.56

@@ -73,13 +76,47 @@
},
"homepage": "https://github.com/agoric-labs/dapp-join-game#readme",
"eslintConfig": {
"env": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever knowledge you have learned about lint config, would you please contribute it to...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let me gather some feedback here first to make sure the approach is correct. The main changes are -

  1. use typescript as the eslint parser
  2. add no-void and no-floating-promises rules
  3. reimplement _ignore patterns for unused-vars, as @typescript-eslint also checks for this (curious - can we dedupe no-unused-vars and @typescript-eslint/no-usused-vars. Both are effectively doing the same thing)?

Here would be the updated directions from the current answer:

  1. Run:
yarn add -D \
 eslint \
 @agoric/eslint-config@dev \
 @endo/eslint-plugin \
 @jessie.js/eslint-plugin \
  eslint-config-airbnb-base \
 eslint-plugin-jsdoc \
 eslint-config-prettier \
 eslint-plugin-import \
- eslint-plugin-github 
+ eslint-plugin-github \
+ @typescript-eslint/eslint-plugin
+ @typescript-eslint/parser
+ typescript
  1. Add the following to your package.json
 "eslintConfig" : {
+  "env": {
+    "node": true
+  },
+  "parser": "@typescript-eslint/parser",
   "parserOptions": {
-      "sourceType": "module",
-      "ecmaVersion": 6
+    "project": "./tsconfig.json",
+    "sourceType": "module",
+    "ecmaVersion": 2020
   },
   "extends": [
+    "plugin:@typescript-eslint/recommended",
     "@agoric"
   ],
+  "plugins": [
+    "@typescript-eslint",
+    "prettier"
+  ],
+  "rules": {
+    "@typescript-eslint/no-floating-promises": "warn",
+    "no-void": [
+      "error",
+      {
+        "allowAsStatement": true
+      }
+    ],
+    "prettier/prettier": "warn",
+    "@typescript-eslint/no-unused-vars": [
+      "error",
+      {
+        "vars": "all",
+        "args": "all",
+        "argsIgnorePattern": "^_",
+        "varsIgnorePattern": "^_"
+      }
+    ]
+  },
 }
  1. Add a tsconfig.json file (new)
+{
+  "compilerOptions": {
+    "noEmit": true,
+    "target": "esnext",
+    "module": "esnext",
+    "moduleResolution": "node",
+    "skipLibCheck": true,
+    "checkJs": false,
+    "allowJs": true,
+    "allowSyntheticDefaultImports": true,
+    "maxNodeModuleJsDepth": 2,
+    "strict": true
+  },
+  "include": ["**/*.js", "**/*.ts"],
+  "exclude": ["bundles"]
+}
  1. Run yarn eslint '**/*.{js,ts}' (or specify other files/directory globs). Run yarn tsc to lint types.

},
"prettier": {
"trailingComma": "all",
"arrowParens": "avoid",
"singleQuote": true
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no newline at end?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier mishap, should be fixed now

@@ -23,8 +23,9 @@ const bagValueSize = amt => {
return total;
};

/** @typedef {StandardTerms & { joinPrice: Amount<'nat'> }} GamePlacesTerms */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important: Why constrain it to nat amounts?

StandardTerms is redundant here. The parameter to the ZCF<...> type is custom terms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StandardTerms is redundant here. The parameter to the ZCF<...> type is custom terms.

Agree/ack. This was added in an attempt to get const terms = await E(zoe).getTerms(instance); inside test-contract.js to not complain Property 'brands' does not exist on type 'GamePlacesTerms'..

Open to hints for getting StandardTerms recognized properly in the testing context.

Comment on lines 11 to 12
import { E, passStyleOf } from '@endo/far';
import { E } from '@endo/eventual-send';
import { passStyleOf } from '@endo/far';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls revert

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added since anytime E is imported from @endo/far, instead of @endo/eventual-send, typescript will complain that This expression is not callable. Type 'never' has no call signatures
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a bug in @endo/far's type exports. Hopefully fixed in subsequent releases.

Either way, eventual-send is the source: https://github.com/endojs/endo/blob/2179108cb9247e9499c1f319de907d7cd365f314/packages/far/src/index.js#L1

@endo/far is just for convience. https://github.com/endojs/endo/blob/master/packages/far/README.md#L6

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as noted above, @endo/far is the norm / convention. It started a couple years ago. I'm not in a position to approve a migration away from it on my own.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking this here #31 to keep this PR moving

contract/test/test-contract.js Outdated Show resolved Hide resolved
contract/test/test-contract.js Show resolved Hide resolved
@@ -187,6 +189,14 @@ test('use the code that will go on chain to start the contract', async t => {
});

const { zoe } = t.context;
/**
* @param {{
* installation: ERef<Installation<GameContractFn>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GameContractFn seems overly specific here. But perhaps the relevant generic type is a pain.

yarn.lock Outdated
@@ -6168,6 +6185,13 @@ ses@^0.18.4, ses@^0.18.5, ses@^0.18.8:
dependencies:
"@endo/env-options" "^0.1.4"

ses@^1.0.1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more problematic endo/ses versions

@@ -38,28 +44,25 @@ const publishBrandInfo = async (chainStorage, board, brand) => {

/**
* Core eval script to start contract
*
* @param {BootstrapPowers} permittedPowers
* XXX FIXME File '~/agoric-sdk/packages/vats/src/core/types.js' is not a module
Copy link
Member

@turadg turadg Dec 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- _agstate/yarn-links/**/* will be present if consumers use 'agoric install'
- contract is not dependent on @babel/code-frame or @babel/highlight, only @vitejs/react-plugin is
- '&& yarn lint:types' is commented until lint:types passes
- add script to bundle contract and build proposal. currently, build only happens in docker
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's getting hard for me to keep this whole thing in my head

I don't think I should approve the version changes without checking it out and testing it pretty thoroughly. (We should of course have the machines do that in ci...)

"build": "exit 0",
"build": "node_modules/agoric/bin/agoric run scripts/build-game1-start.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is node_modules/agoric/bin/agoric necessary? Doesn't yarn arrange for agoric to work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scope of this PR seems to be expanding :)

Do you plan to keep the commits separate or squash?

"lint:fix": "eslint --fix '**/*.{js,ts}'",
"lint:types": "tsc"
},
"dependencies": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving the "dependencies" section makes this diff hard to read.

Comment on lines +22 to +23
"@agoric/ertp": "0.16.3-u13.0",
"@agoric/zoe": "0.26.3-u13.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked that the resulting bundle is a reasonable size? that we have just 1 version of each endo package?

@@ -470,6 +509,19 @@
"@endo/nat" "4.1.27"
better-sqlite3 "^8.2.0"

"@agoric/swing-store@^0.9.2-u13.0":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have whole new packages here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants