-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from all commits
4a7fdbd
a6496a0
7e3d0ed
f2d6dfc
a78ea8f
fdae180
799e40f
647f561
454c8c7
3ce6458
ad81605
f0a60ba
ca54045
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
_agstate/yarn-links |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,23 +11,32 @@ | |
"docker:make": "docker compose exec agd make -C /workspace/contract", | ||
"make:help": "make list", | ||
"start": "yarn docker:make clean start-contract print-key", | ||
"build": "exit 0", | ||
"build": "node_modules/.bin/agoric run scripts/build-game1-start.js", | ||
"test": "ava --verbose", | ||
"lint": "eslint '**/*.{js,jsx}'", | ||
"lint-fix": "eslint --fix '**/*.{js,jsx}'", | ||
"lint-fix-jessie": "eslint -c '.eslintrc-jessie.js' --fix '**/*.{js,jsx}'", | ||
"lint-jessie": "eslint -c '.eslintrc-jessie.js' '**/*.{js,jsx}'" | ||
"lint": "yarn lint:eslint # && yarn lint:types", | ||
"lint:eslint": "eslint '**/*.{js,ts}'", | ||
"lint:fix": "eslint --fix '**/*.{js,ts}'", | ||
"lint:types": "tsc" | ||
}, | ||
"dependencies": { | ||
"@agoric/ertp": "0.16.3-u13.0", | ||
"@agoric/zoe": "0.26.3-u13.0", | ||
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
"@endo/far": "0.2.18", | ||
"@endo/marshal": "0.8.5", | ||
"@endo/patterns": "0.2.2" | ||
}, | ||
"devDependencies": { | ||
"agoric": "^0.21.2-u12.0", | ||
"@agoric/deploy-script-support": "^0.10.4-u12.0", | ||
"@endo/bundle-source": "^2.8.0", | ||
"@agoric/deploy-script-support": "^0.10.4-u13.0", | ||
"@agoric/eslint-config": "dev", | ||
"@endo/bundle-source": "2.5.2-upstream-rollup", | ||
"@endo/eslint-plugin": "^0.5.2", | ||
"@endo/init": "^0.5.60", | ||
"@endo/promise-kit": "0.2.56", | ||
"@endo/ses-ava": "^0.2.44", | ||
"@jessie.js/eslint-plugin": "^0.4.0", | ||
"@typescript-eslint/eslint-plugin": "^6.7.0", | ||
"@typescript-eslint/parser": "^6.7.0", | ||
"agoric": "^0.22.0-u13.0", | ||
"ava": "^5.3.0", | ||
"eslint": "^8.47.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
|
@@ -41,20 +50,8 @@ | |
"import-meta-resolve": "^2.2.1", | ||
"prettier": "^3.0.3", | ||
"prettier-plugin-jsdoc": "^1.0.0", | ||
"type-coverage": "^2.26.3", | ||
"typescript": "~5.2.2" | ||
}, | ||
"resolutions": { | ||
"@babel/code-frame": "7.18.6", | ||
"@babel/highlight": "7.22.5" | ||
}, | ||
"dependencies": { | ||
"@agoric/zoe": "^0.26.3-u12.0", | ||
"@agoric/ertp": "^0.16.3-u12.0", | ||
"@endo/far": "^0.2.22", | ||
"@endo/marshal": "^0.8.9", | ||
"@endo/patterns": "^0.2.5" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"test/**/test-*.js" | ||
|
@@ -73,8 +70,45 @@ | |
}, | ||
"homepage": "https://github.com/agoric-labs/dapp-join-game#readme", | ||
"eslintConfig": { | ||
"env": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 -
Here would be the updated directions from the current answer:
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
"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": "^_"
+ }
+ ]
+ },
}
+{
+ "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"]
+}
|
||
"node": true | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "./tsconfig.json", | ||
"sourceType": "module", | ||
"ecmaVersion": 2020 | ||
}, | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"@agoric" | ||
], | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"prettier" | ||
], | ||
"rules": { | ||
"@typescript-eslint/prefer-ts-expect-error": "warn", | ||
"@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": "^_" | ||
} | ||
] | ||
}, | ||
"ignorePatterns": [ | ||
"bundles" | ||
] | ||
}, | ||
"prettier": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import { E } from '@endo/far'; | ||
import { makeMarshal } from '@endo/marshal'; | ||
import { AmountMath } from '@agoric/ertp/src/amountMath.js'; | ||
import '@agoric/zoe/exported.js'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These bloat bundles. Ugh. Please add an important |
||
|
||
console.warn('start-game1-proposal.js module evaluating'); | ||
|
||
|
@@ -26,6 +27,11 @@ const makeBoardAuxNode = async (chainStorage, boardId) => { | |
return E(boardAux).makeChildNode(boardId); | ||
}; | ||
|
||
/** | ||
* @param {ERef<StorageNode>} chainStorage | ||
* @param {ERef<import('@agoric/vats/src/types').Board>} board | ||
* @param {ERef<Brand>} brand | ||
*/ | ||
const publishBrandInfo = async (chainStorage, board, brand) => { | ||
const [id, displayInfo] = await Promise.all([ | ||
E(board).getId(brand), | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. importing the ambient for side-effects should work. |
||
* @param {import('@agoric/vats/src/core/types').BootstrapPowers} permittedPowers | ||
*/ | ||
export const startGameContract = async permittedPowers => { | ||
console.error('startGameContract()...'); | ||
const { | ||
consume: { board, chainStorage, startUpgradable, zoe }, | ||
brand: { | ||
consume: { IST: istBrandP }, | ||
// @ts-expect-error dynamic extension to promise space | ||
produce: { Place: producePlaceBrand }, | ||
}, | ||
issuer: { | ||
consume: { IST: istIssuerP }, | ||
// @ts-expect-error dynamic extension to promise space | ||
produce: { Place: producePlaceIssuer }, | ||
}, | ||
installation: { | ||
consume: { game1: game1InstallationP }, | ||
}, | ||
instance: { | ||
// @ts-expect-error dynamic extension to promise space | ||
produce: { game1: produceInstance }, | ||
}, | ||
} = permittedPowers; | ||
|
@@ -117,6 +120,10 @@ const gameManifest = { | |
}; | ||
harden(gameManifest); | ||
|
||
/** | ||
* @param {{restoreRef: (ref: unknown) => Promise<unknown> }} r | ||
* @param {{ game1Ref: unknown }} g | ||
*/ | ||
export const getManifestForGame1 = ({ restoreRef }, { game1Ref }) => { | ||
return harden({ | ||
manifest: gameManifest, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,8 +78,9 @@ test('Start the contract', async t => { | |
* | ||
* @param {import('ava').ExecutionContext} t | ||
* @param {ZoeService} zoe | ||
* @param {ERef<import('@agoric/zoe/src/zoeService/utils').Instance<GameContractFn>} instance | ||
* @param {Purse} purse | ||
* @param {import('@agoric/zoe/src/zoeService/utils').Instance<GameContractFn>} instance | ||
* @param {Purse<"nat">} purse | ||
0xpatrickdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param {string[]} choices | ||
*/ | ||
const alice = async ( | ||
t, | ||
|
@@ -89,7 +90,7 @@ const alice = async ( | |
choices = ['Park Place', 'Boardwalk'], | ||
) => { | ||
const publicFacet = E(zoe).getPublicFacet(instance); | ||
// @ts-expect-error Promise<Instance> seems to work | ||
/** @type {import('../src/gameAssetContract.js').GamePlacesTerms} */ | ||
const terms = await E(zoe).getTerms(instance); | ||
const { issuers, brands, joinPrice } = terms; | ||
|
||
|
@@ -187,6 +188,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>>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* issuerKeywordRecord: IssuerKeywordRecord; | ||
* label: string; | ||
* terms: import('../src/gameAssetContract.js').GamePlacesTerms; | ||
* }} opts | ||
*/ | ||
const startUpgradable = async ({ | ||
installation, | ||
issuerKeywordRecord, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"target": "esnext", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"skipLibCheck": true, | ||
// Don't check by default because that includes node_modules in JS | ||
"checkJs": false, | ||
// Features implied with jsconfig.json that have to be explicit in tsconfig.json | ||
"allowJs": true, | ||
"allowSyntheticDefaultImports": true, | ||
"maxNodeModuleJsDepth": 2, | ||
"strict": true | ||
}, | ||
"include": ["**/*.js", "**/*.ts"], | ||
"exclude": ["bundles"] | ||
} |
There was a problem hiding this comment.
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.