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

Upgrade to ESLint v9 #10846

Merged
merged 3 commits into from
Jan 23, 2025
Merged

Upgrade to ESLint v9 #10846

merged 3 commits into from
Jan 23, 2025

Conversation

iomekam
Copy link
Contributor

@iomekam iomekam commented Jan 14, 2025

closes: #10642

Description

Updates ESLint to v9. Doing so deprecates the use of .eslintrc and eslintignore and moves all these configuration options into a flat config file, eslint.config.mjs. As part of this change, we also needed to update the github eslint plugin as well as the jessie.js eslint plugin. Most of the rules were migrated successfully, but I had to modify a few rules since ESLint v9 comes with a few default behavior changes.

Security Considerations

N/A

Scaling Considerations

N/A

Documentation Considerations

Here's a breakdown of the breaking changes that come with ESLint v9. https://eslint.org/docs/latest/use/migrate-to-9.0.0#-varsignorepattern-option-of-no-unused-vars-no-longer-applies-to-catch-arguments.

Testing Considerations

I modified our yarn lint command so I could individually run and view the error of each package. Doing so allowed me to debug every single error that occured after the ugprade and make changes to restore expected behavior.

Upgrade Considerations

N/A

Copy link

cloudflare-workers-and-pages bot commented Jan 14, 2025

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6bd3574
Status: ✅  Deploy successful!
Preview URL: https://eae755c1.agoric-sdk.pages.dev
Branch Preview URL: https://iomekam-es-lint-2.agoric-sdk.pages.dev

View logs

@iomekam iomekam changed the title Iomekam es lint 2 Upgrade to ESLint v9 Jan 15, 2025
@iomekam iomekam force-pushed the iomekam-es-lint-2 branch 3 times, most recently from 7775513 to 3d589b1 Compare January 15, 2025 21:17
@iomekam iomekam marked this pull request as ready for review January 15, 2025 21:30
@iomekam iomekam requested a review from a team as a code owner January 15, 2025 21:30
Comment on lines 35 to 37
"packages/cosmic-proto/node_modules/",
"packages/cosmic-proto/coverage/",
"packages/cosmic-proto/dist/",
Copy link
Member

Choose a reason for hiding this comment

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

are these not implied by the simpler globs? we want to ignore these no matter where they are:

  • coverage
  • dist
  • node_modules

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were migrated from all our our current eslintignore files. I do think it makes sense to have these ignored gobally though


export default [{
ignores: [
"coverage/**/*",
Copy link
Member

Choose a reason for hiding this comment

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

does .eslintignore no longer work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's deprecated

eslint.config.mjs Outdated Show resolved Hide resolved

"ava/no-skip-test": "off",
"ava/use-test": "off",
"@jessie.js/safe-await-separator": "off", // Temporarily disabled due to ESLint 9.x compatibility issue
Copy link
Member

Choose a reason for hiding this comment

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

can be re-enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this

eslint.config.mjs Show resolved Hide resolved
@@ -1,9 +1,12 @@
// This file can contain .js-specific Typescript compiler config.
{
"extends": "../../tsconfig.json",
"compilerOptions": {},
Copy link
Member

Choose a reason for hiding this comment

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

what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not needed. I was testing something out and forget to remove this

import { SpawnSyncReturns as NodeSpawnSyncReturns } from 'child_process';

declare module 'child_process' {
export interface SpawnSyncReturns<T> extends NodeSpawnSyncReturns<T> {
Copy link
Member

Choose a reason for hiding this comment

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

why was this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were previously ignoring packages/cosmic-swingset/check-validator.cjs when using our old config. Given that it had check-jessie, so I assume it was meant to be linted. When trying to lint, I got this error:

check-validator.cjs:25:9 - error TS2339: Property 'code' does not exist on type 'SpawnSyncReturns<Buffer<ArrayBufferLike>>'.

25 if (ret.code) {
           ~~~~

check-validator.cjs:26:20 - error TS2339: Property 'code' does not exist on type 'SpawnSyncReturns<Buffer<ArrayBufferLike>>'.

26   process.exit(ret.code);

I added this to get the linting working. I'm open to alternatives

Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure it's a bug. Node docs for spawnSync and the TS defs show a status: number property which I think is what this meant to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch!

const allDeprecated = [...deprecatedForLoanContract, ['loan', 'debt']];

const deprecatedTerminology = Object.fromEntries(
Object.entries({
Copy link
Member

Choose a reason for hiding this comment

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

This isn't formatted correctly. Please make sure this file is included in the format and lint:format selections


"ava/no-skip-test": "off",
"ava/use-test": "off",
"@jessie.js/safe-await-separator": "error", // Temporarily disabled due to ESLint 9.x compatibility issue
Copy link
Member

Choose a reason for hiding this comment

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

comment no longer applicable

Comment on lines 80 to 81
// Include both .js and .ts files for cache package
files: ["packages/cache/**/*.{js,ts,mjs,cjs}"],
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be the glob for all packages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we were previously including *.ts files.

casting and cache both explicilty ran eslint --ext .js,.ts .

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.

almost there.

before I forget to say: before merging the commits will need cleaning up. there aren't any actual fix commits here for the changelog. Just one that updates ESlint and another that fixes the .code bug

'packages/cosmic-proto/src/codegen/',
'packages/cosmic-proto/scripts/',
// Cosmic-swingset specific ignores
'packages/cosmic-swingset/src/bundles/**/*',
Copy link
Member

Choose a reason for hiding this comment

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

this should be a global ignore for bundles at any path

'packages/cosmic-swingset/src/bundles/**/*',
'packages/cosmic-swingset/t[0-9]/**/*',
'packages/cosmic-swingset/t[0-9].*/**/*',
'packages/cosmic-swingset/node_modules/**/*',
Copy link
Member

Choose a reason for hiding this comment

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

ignored above

'packages/cosmic-swingset/t[0-9]/**/*',
'packages/cosmic-swingset/t[0-9].*/**/*',
'packages/cosmic-swingset/node_modules/**/*',
'packages/cosmic-swingset/build/**/*',
Copy link
Member

Choose a reason for hiding this comment

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

this should be another global ignore

export default [
{
ignores: [
'**/coverage/**/*',
Copy link
Member

Choose a reason for hiding this comment

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

all these directory ignores don't need the trailing glob, right?
https://eslint.org/docs/latest/use/configure/ignore#ignoring-directories

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.

🎉

@iomekam iomekam added the automerge:rebase Automatically rebase updates, then merge label Jan 18, 2025
@iomekam iomekam removed the automerge:rebase Automatically rebase updates, then merge label Jan 18, 2025
@turadg turadg added the force:integration Force integration tests to run on PR label Jan 18, 2025
@@ -205,7 +205,6 @@ const main = async () => {
instancePath: [contractName],
callPipe: [['makeDepositInvitation']],
},
// @ts-expect-error 'NatAmount' vs 'AnyAmount'
Copy link
Member

Choose a reason for hiding this comment

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

Why is this eslint change affecting TypeScript?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may be because of some changes to tsconfig, but I couldn't figure out how to keep this line without this error:

scripts/fast-usdc-tool.ts:208:7 - error TS2578: Unused '@ts-expect-error' directive.

208       // @ts-expect-error 'NatAmount' vs 'AnyAmount'
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@@ -3,7 +3,7 @@

import '@endo/init';
import starshipChainInfo from '../starship-chain-info.js';
import { makeAssetInfo } from '../tools/asset-info.ts';
Copy link
Member

Choose a reason for hiding this comment

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

This is a code change, not just lint change. I suspect it will break this test. I've added "force:integration" to check

'import/no-extraneous-dependencies': 'off',
},
},
// Separate config for multichain-testing that doesn't inherit root rules
Copy link
Member

Choose a reason for hiding this comment

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

It's a separate Yarn project so I think we'd be better off giving it a desperate flag confit.

Ie leave its dependencies and source alone. If the eslint config for the root project is affecting multichain-testing, fix only that. (Eg by putting a config file in there so it will get that one instead)

Regardless we need an issue to come and make this other yarn project in the repo lint correctly. Something like #10238

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't have a supported way of doing this. I did some digging and they have an experimental approach to this. We can leverage this as long as we understand it's not a fully released feature yet

Copy link
Member

Choose a reason for hiding this comment

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

That link says the default is to start search from the CWD. Why wouldn't an eslintconfig within multichain-testing already resolve before the one in agoric-sdk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tested and this does indeed work without the flag

},
],
// Disable all other rules
'@typescript-eslint/no-floating-promises': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

I want to see these suppressions omitted but if we do end up keeping them please use "warn" instead of disabling them completely. They should still give notice to developers even if they don't fail CI.

@iomekam iomekam force-pushed the iomekam-es-lint-2 branch 2 times, most recently from 9b673b2 to 675172a Compare January 21, 2025 17:19
@Agoric Agoric deleted a comment from mergify bot Jan 21, 2025
@iomekam iomekam requested a review from turadg January 21, 2025 19:46
@@ -91,29 +91,5 @@
"@agoric/zoe": "portal:../packages/zoe",
"@agoric/zone": "portal:../packages/zone"
},
"eslintConfig": {
Copy link
Member

Choose a reason for hiding this comment

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

please separate multichain-testing changes to another PR. It's complicating this migration of agoric-sdk root project. Let's get that landed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without these changes, linting will fail for multichain-testing as it'll pick up the root config and try to use that

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I just tried it and it seemed to work.

cd multichain-testing
git checkout master .
yarn install
yarn lint

Do you get a different result?

Copy link
Member

Choose a reason for hiding this comment

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

btw, assuming we can punt updating multichain-testing, this PR should no longer be marked as closing 10642

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does work locally. I'll remove the changes and observe CI. It was picking up the new config in CI, but maybe I just observed the wrong thing and chased the wrong path

Copy link
Contributor Author

@iomekam iomekam Jan 21, 2025

Choose a reason for hiding this comment

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

Failing per here. Based on these lines, it should be emulating what we tried locally

Copy link
Contributor Author

@iomekam iomekam Jan 21, 2025

Choose a reason for hiding this comment

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

Going back to this comment, when you ran git checkout master ., I don't think it removed the eslint.config.mjs file that was newly added as part of this change, so when you ran yarn lint, it was still using that file

Copy link
Member

Choose a reason for hiding this comment

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

Very confusing when CI has a different result for yarn lint than the local checkout does. I tried diagnosing why the linked job failed but I couldn't determine what state of this branch it was using and what changes it had to multichain-testing.

So I made a new branch, https://github.com/Agoric/agoric-sdk/tree/ta/eslint-v9, which has the steps I pasted above. It's passing in https://github.com/Agoric/agoric-sdk/actions/runs/12898290669/job/35965066953

Maybe the failing job did not have the master state of multichain-testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even when you reverted the change in the eslint-v9 branch, the new eslint.config.mjs file is still present in the latest version of the branch

Copy link
Member

Choose a reason for hiding this comment

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

Ah. My branch doesn't actually match what I was asking for. And upon closer inspection it looks like it's green because in master the linter is broken in this dir.

So thanks for fixing it!

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.

One small change to make. Before merge please rebase locally to fix the "fixup! fixup!" which automerge won't know how to handle.

@@ -5,7 +5,7 @@
"scripts": {
"build": "exit 0",
"lint": "yarn tsc && yarn eslint .",
"lint-fix": "yarn lint:eslint --fix",
"lint-fix": "yarn lint --fix",
Copy link
Member

Choose a reason for hiding this comment

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

yarn lint just happens to end in eslint. Since we don't have lint: scripts in this package.json this one should call that directly.

Suggested change
"lint-fix": "yarn lint --fix",
"lint-fix": "yarn eslint . --fix",

@@ -91,29 +91,5 @@
"@agoric/zoe": "portal:../packages/zoe",
"@agoric/zone": "portal:../packages/zone"
},
"eslintConfig": {
Copy link
Member

Choose a reason for hiding this comment

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

Ah. My branch doesn't actually match what I was asking for. And upon closer inspection it looks like it's green because in master the linter is broken in this dir.

So thanks for fixing it!

@iomekam iomekam added the automerge:rebase Automatically rebase updates, then merge label Jan 23, 2025
Copy link
Contributor

mergify bot commented Jan 23, 2025

This pull request has been removed from the queue for the following reason: checks failed.

The merge conditions cannot be satisfied due to failing checks:

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@iomekam
Copy link
Contributor Author

iomekam commented Jan 23, 2025

@Mergifyio requeue

Copy link
Contributor

mergify bot commented Jan 23, 2025

requeue

✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically

@mergify mergify bot merged commit c9a663b into master Jan 23, 2025
83 checks passed
@mergify mergify bot deleted the iomekam-es-lint-2 branch January 23, 2025 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge force:integration Force integration tests to run on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

upgrade ESlint to v9
2 participants