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

Update to ESLint 9.0 #6562

Open
buffalojoec opened this issue Apr 10, 2024 · 13 comments
Open

Update to ESLint 9.0 #6562

buffalojoec opened this issue Apr 10, 2024 · 13 comments
Labels

Comments

@buffalojoec
Copy link
Contributor

Problem

The new ESLint 9.0 update is out, and Dependabot has tried upgrading SPL to it, but it has many breaking changes.

For example, ESLint 9 uses a new config file structure, as well as some different CLI flags and configuration keys.

https://eslint.org/docs/latest/use/migrate-to-9.0.0

Solution

Go through the migration guide and upgrade SPL to ES Lint 9.0!

@13550501

This comment was marked as spam.

@andiz2
Copy link

andiz2 commented Apr 15, 2024

Hi @buffalojoec I can take care of this.
Would take a look at migration guide and come back with updates. 😄

@buffalojoec
Copy link
Contributor Author

@andiz2 Thank you!!

@andiz2
Copy link

andiz2 commented Apr 17, 2024

Currently struggleing with the build..
Seems to be some dependency issues but I already updated rustc
beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ cargo build-sbf
error: package solana-program v1.18.2 cannot be built because it requires rustc 1.72.0 or newer, while the currently active rustc version is 1.68.0-dev
Either upgrade to rustc 1.72.0 or newer, or use
cargo update -p [email protected] --precise ver
where ver is the latest version of solana-program supporting rustc 1.68.0-dev
beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ rustup update
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: checking for self-update

stable-x86_64-unknown-linux-gnu unchanged - rustc 1.77.2 (25ef9e3d8 2024-04-09)
nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.79.0-nightly (1cec373f6 2024-04-16)

info: cleaning up downloads & tmp directories
beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ rustc --version
rustc 1.77.2 (25ef9e3d8 2024-04-09)
beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ cargo --version
cargo 1.77.2 (e52e36006 2024-03-26)
beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ cargo clean
Removed 0 files
beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ cargo build-sbf
error: package toml_edit v0.21.1 cannot be built because it requires rustc 1.69 or newer, while the currently active rustc version is 1.68.0-dev
Either upgrade to rustc 1.69 or newer, or use
cargo update -p [email protected] --precise ver
where ver is the latest version of toml_edit supporting rustc 1.68.0-dev
beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ cargo update -p toml_edit --precise ver
error: invalid version format for precise version ver

Caused by:
unexpected character 'v' while parsing major version number
beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ cargo update -p toml_edit@
-bash: syntax error near unexpected token newline' beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ cargo update -p toml_edit@<version> -bash: syntax error near unexpected token newline'
beast@DESKTOP-TFSG0II:/mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library$ cargo update -p [email protected]
error: package ID specification [email protected] did not match any packages

    Did you mean `toml_edit`?

@buffalojoec
Copy link
Contributor Author

@andiz2 What caused this originally? You shouldn't need to mess with Cargo to work with JS, unless you're trying to run the e2e tests, which aren't really necessary for testing the linter. Ideally you just need to get pnpm lint working.

In any case, your solana CLI version is out-of-date. cargo build-sbf uses the Solana-forked rustc compiler and whatever CLI version you're running has rustc 1.680-dev. Try upgrading your CLI to 1.18.

@andiz2
Copy link

andiz2 commented Apr 18, 2024

I will ignore Cargo and make pnpm lint work for the new version. If I'll have further Q I'll let you know.

@andiz2
Copy link

andiz2 commented Apr 20, 2024

I've used pnpm lint with the current version and I've encountered some issues..
`@solana/spl-account-compression:lint: + eslint . --ext .js,.ts
@solana/spl-account-compression:lint:
@solana/spl-account-compression:lint: /mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library/account-compression/sdk/src/constants/index.ts
@solana/spl-account-compression:lint: 13:5 error Expected interface keys to be in ascending order. 'maxBufferSize' should be before 'maxDepth' typescript-sort-keys/interface
@solana/spl-account-compression:lint: 64:22 error Expected interface keys to be in ascending order. 'maxBufferSize' should be before 'maxDepth' typescript-sort-keys/interface
@solana/spl-account-compression:lint: 65:22 error Expected interface keys to be in ascending order. 'maxBufferSize' should be before 'maxDepth' typescript-sort-keys/interface
@solana/spl-account-compression:lint: 66:22 error Expected interface keys to be in ascending order. 'maxBufferSize' should be before 'maxDepth' typescript-sort-keys/interface
@solana/spl-account-compression:lint: 67:22 error Expected interface keys to

@solana/spl-account-compression:lint: /mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library/account-compression/sdk/src/generated/instructions/append.ts
@solana/spl-account-compression:lint: 47:5 error Expected interface keys to be in ascending order. 'authority' should be before 'merkleTree' typescript-sort-keys/interface
@solana/spl-account-compression:lint: 49:5 error Expected interface keys to be in ascending order. 'anchorRemainingAccounts' should be before 'noop' typescript-sort-keys/interface
@solana/spl-account-compression:lint:
@solana/spl-account-compression:lint: /mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library/account-compression/sdk/src/generated/instructions/closeEmptyTree.ts
@solana/spl-account-compression:lint: 31:5 error Expected interface keys to be in ascending order. 'authority' should be before 'merkleTree' typescript-sort-keys/interface
@solana/spl-account-compression:lint: 33:5 error Expected interface keys to be in ascending order. 'anchorRemainingAccounts' should be before 'recipient' typescript-sort-keys/interface
@solana/spl-account-compression:lint:
@solana/spl-account-compression:lint: /mnt/c/Users/admin/Documents/code js/spl-fork/solana-program-library/account-compression/sdk/src/generated/instructions/initEmptyMerkleTree.ts
@solana/spl-account-compression:lint: 18:5 error Expected interface keys to be in ascending order. 'maxBufferSize' should be before 'maxDepth' typescript-sort-keys/interface
@solana/spl-account-compression:lint: 49:5 error Expected interface keys to be in ascending order. 'authority' should be before 'merkleTree' `

Am I doing something wrong?

@andiz2
Copy link

andiz2 commented Apr 20, 2024

From what I've researched lately SPL have this ESLint config dependency: "@solana/eslint-config-solana": "^3.0.3",
and package.json of this config https://github.com/solana-labs/eslint-config-solana/blob/main/package.json
uses eslint 8.45.0..

...btw..
I am still curious why when I've ran pnpm lint on the actual code it brings lots of errors...
#6562 (comment)

@buffalojoec
Copy link
Contributor Author

I don't think spl-account-compression has ever been passing lint. It looks like we skip it in CI.

# pnpm lint # re-enable when lints are fixed

I've added a PR to update this! #6613

There's some more linting issues I noticed. For example, some packages (like name-service) don't ignore the lib directory when linting. I've also added a PR for this! #6614

@steveluscher
Copy link
Contributor

I took a crack at this today:

// ./libraries/type-length-value/js/eslint.config.cjs
const js = require('@eslint/js');
const PrettierPlugin = require('eslint-plugin-prettier');
const TypeScriptPlugin = require('@typescript-eslint/eslint-plugin');
const TypeScriptParser = require('@typescript-eslint/parser');
const RequireExtensionsPlugin = require('eslint-plugin-require-extensions');

/** @type {import('eslint').Linter.FlatConfig[]} */
module.exports = [
    js.configs.recommended,
    TypeScriptPlugin.configs.recommended,
    PrettierPlugin.configs.recommended,
    RequireExtensionsPlugin.configs.recommended,
    {
        ignores: ['docs', 'lib', 'test-ledger', 'package-lock.json'],
        languageOptions: {
            parser: TypeScriptParser,
        },
        plugins: {
            '@typescript-eslint': TypeScriptPlugin,
            prettier: PrettierPlugin,
            'require-extensions': RequireExtensionsPlugin,
        },
        rules: {
            '@typescript-eslint/ban-ts-comment': 'off',
            '@typescript-eslint/no-explicit-any': 'off',
            '@typescript-eslint/no-unused-vars': 'off',
            '@typescript-eslint/no-empty-interface': 'off',
            '@typescript-eslint/consistent-type-imports': 'error',
        },
    },
    {
        files: ['examples/**/*', 'test/**/*'],
        rules: {
            'require-extensions/require-extensions': 'off',
            'require-extensions/require-index': 'off',
        },
    },
];

Until all of the plugins (@typescript-eslint, Prettier, require-extensions-eslint-plugin) are updated for ESLint 9, this project is dead in the water.

@steveluscher
Copy link
Contributor

steveluscher commented Apr 22, 2024

I mean, I guess we could just set ESLINT_USE_FLAT_CONFIG to false and punt it down the road, but we'd be toast once ESLint 10 comes around.

@buffalojoec
Copy link
Contributor Author

I mean, I guess we could just set ESLINT_USE_FLAT_CONFIG to false and punt it down the road, but we'd be toast once ESLint 10 comes around.

Yeah I definitely didn't want to upgrade to 9 without using flat config.

@andiz2
Copy link

andiz2 commented Apr 27, 2024

I'll put this on hold until further news

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

No branches or pull requests

4 participants