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

Contract Linting #103

Merged
merged 7 commits into from
Sep 13, 2024
Merged

Contract Linting #103

merged 7 commits into from
Sep 13, 2024

Conversation

mujahidkay
Copy link
Member

@mujahidkay mujahidkay commented Sep 12, 2024

Closes: #35

Description

This PR enables typechecking via tsc and fixes lint errors

@mujahidkay mujahidkay marked this pull request as ready for review September 12, 2024 19:01
@mujahidkay mujahidkay self-assigned this Sep 12, 2024
@mujahidkay mujahidkay marked this pull request as draft September 12, 2024 19:02
@mujahidkay mujahidkay marked this pull request as ready for review September 12, 2024 21:30
Comment on lines 29 to 30
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.15.0",
Copy link
Member

Choose a reason for hiding this comment

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

I believe the typescript-eslint dep suffices.

Suggested change
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.15.0",


/**
* @param {ExecutionContext<TestContext>} t
*/

test.only('proposal builder generates compressed bundles less than 1MB', async t => {
Copy link
Member

Choose a reason for hiding this comment

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

drive-by, but please take .only out of the above test. It's already the only test in this module.

@@ -17,7 +38,9 @@ test.only('proposal builder generates compressed bundles less than 1MB', async t

for (const bundle of bundles) {
// eslint-disable-next-line @jessie.js/safe-await-separator
const buffer = await t.context.compressFile(bundle);
const buffer = await /** @type {TestContext} */ (t.context).compressFile(
Copy link
Member

Choose a reason for hiding this comment

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

t.context type should be implied by the type of t. What happens without this cast?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's implied to be undefined. And says t.context is of type unknown

/ava/types/test-fn.d.cts

/** The `t` value passed to test & hook implementations. */
export type ExecutionContext<Context = unknown> = {
	/** Test context, shared with hooks. */
	context: Context;

	/** Title of the test or hook. */
	readonly title: string;
	...
}

Copy link
Member

Choose a reason for hiding this comment

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

That's because test wasn't typed. See 064eb83

Copy link
Member Author

Choose a reason for hiding this comment

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

neat. thanks for this! 🚀

Comment on lines 15 to 17
/**
* @param {ExecutionContext<TestContext>} t
*/
Copy link
Member

Choose a reason for hiding this comment

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

please just type test. the rest will fall out of that.
https://github.com/Agoric/agoric-sdk/blob/136f1caa919428684a88f2213d0cd9b3185f8a33/packages/boot/test/configs.test.js#L20-L24

const test =
  /** @type {import('ava').TestFn<Awaited<ReturnType<typeof makeTestContext>>>}} */ (
    anyTest
  );

contract/test/test-contract.js Show resolved Hide resolved
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

Trusting you'll remove the t.context casts

@@ -59,7 +69,7 @@ test('Install the contract', async t => {
});

test('Start the contract', async t => {
const { zoe, bundle } = t.context;
const { zoe, bundle } = /** @type {TestContext} */ (t.context);
Copy link
Member

Choose a reason for hiding this comment

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

now that test is typed, all these casts of t.context are redundant.

please remove

@mujahidkay mujahidkay merged commit 4111758 into main Sep 13, 2024
3 checks passed
@mujahidkay mujahidkay deleted the contract-linting branch September 13, 2024 17:56
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.

Contract Linting: add lint:types and use @typescript/eslint-parser
2 participants