Skip to content

Commit

Permalink
chore: Upgrade to ESlint 9 and forbid import cycles (#4897)
Browse files Browse the repository at this point in the history
### Description

- Upgrade from eslint 8 -> 9
- Forbid import cycles and self imports
- Fix lint errors caught by v9 but not v8
- Include utils package in CI linting

**No semantic changes, just some shuffling of things around to avoid
cycles**

Fixes #4898


https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-cycle.md

https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-self-import.md
  • Loading branch information
jmrossy authored Nov 26, 2024
1 parent d518157 commit fa6d5f5
Show file tree
Hide file tree
Showing 122 changed files with 1,341 additions and 1,039 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-pumpkins-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/utils': minor
---

Add toUpperCamelCase and deepFind functionss
5 changes: 5 additions & 0 deletions .changeset/yellow-baboons-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': minor
---

Add decodeIsmMetadata function
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

65 changes: 0 additions & 65 deletions .eslintrc

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ jobs:
.yarn
key: ${{ runner.os }}-yarn-4.5.1-cache-${{ hashFiles('./yarn.lock') }}
fail-on-cache-miss: true

# Build required before linting or the intra-monorepo package cycle checking won't work
- name: yarn-build
uses: ./.github/actions/yarn-build-with-cache
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: lint
run: yarn lint
Expand Down
115 changes: 115 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import importPlugin from 'eslint-plugin-import';
import jest from 'eslint-plugin-jest';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
{
ignores: [
'**/node_modules',
'**/dist',
'**/coverage',
'**/*.cjs',
'**/*.cts',
'**/*.mjs',
'jest.config.js',
],
},
...compat.extends(
'eslint:recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'prettier',
),
{
plugins: {
import: importPlugin,
'@typescript-eslint': typescriptEslint,
jest,
},

languageOptions: {
globals: {
...globals.node,
...globals.browser,
},

parser: tsParser,
ecmaVersion: 12,
sourceType: 'module',

parserOptions: {
project: './tsconfig.json',
},
},

settings: {
'import/resolver': {
typescript: true,
node: true,
},
},

rules: {
'guard-for-in': ['error'],
'import/no-cycle': ['error'],
'import/no-self-import': ['error'],
'import/no-named-as-default-member': ['off'],
'no-console': ['error'],
'no-eval': ['error'],
'no-extra-boolean-cast': ['error'],
'no-ex-assign': ['error'],
'no-constant-condition': ['off'],
'no-return-await': ['error'],

'no-restricted-imports': [
'error',
{
name: 'console',
message: 'Please use a logger and/or the utils package assert',
},
{
name: 'fs',
message: 'Avoid use of node-specific libraries',
},
],

'@typescript-eslint/ban-ts-comment': ['off'],
'@typescript-eslint/explicit-module-boundary-types': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-floating-promises': ['error'],
'@typescript-eslint/no-non-null-assertion': ['off'],
'@typescript-eslint/no-require-imports': ['warn'],
'@typescript-eslint/no-unused-expressions': ['off'],
'@typescript-eslint/no-empty-object-type': ['off'],
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],

'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/valid-expect': 'error',
},
},
];
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"description": "A yarn workspace of core Hyperlane packages",
"version": "0.0.0",
"devDependencies": {
"@eslint/js": "^9.15.0",
"@trivago/prettier-plugin-sort-imports": "^4.2.1",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"eslint": "^8.57.0",
"@typescript-eslint/eslint-plugin": "^8.1.6",
"@typescript-eslint/parser": "^8.1.6",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.2.0",
"husky": "^8.0.0",
"lint-staged": "^12.4.3",
Expand Down Expand Up @@ -41,6 +44,7 @@
"async": "^2.6.4",
"fetch-ponyfill": "^7.1",
"flat": "^5.0.2",
"globals": "^14.0.0",
"lodash": "^4.17.21",
"recursive-readdir": "^2.2.3",
"underscore": "^1.13",
Expand Down
6 changes: 0 additions & 6 deletions typescript/ccip-server/.eslintrc

This file was deleted.

17 changes: 17 additions & 0 deletions typescript/ccip-server/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import MonorepoDefaults from '../../eslint.config.mjs';

export default [
...MonorepoDefaults,
{
files: ['./src/**/*.ts'],
},
{
rules: {
'no-console': ['off'],
'no-restricted-imports': ['off'],
},
},
{
ignores: ['**/__mocks__/*','**/tests/*',]
}
];
3 changes: 3 additions & 0 deletions typescript/ccip-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
"node": ">=16"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "tsx src/server.ts",
"dev": "nodemon src/server.ts",
"test": "jest",
"lint": "eslint -c ./eslint.config.mjs",
"prettier": "prettier --write ./src/* ./tests/"
},
"author": "brolee",
"license": "Apache-2.0",
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/node": "^16.9.1",
"eslint": "^9.15.0",
"jest": "^29.7.0",
"nodemon": "^3.0.3",
"prettier": "^2.8.8",
Expand Down
14 changes: 8 additions & 6 deletions typescript/ccip-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { ProofsService } from './services/ProofsService';

// Initialize Services
const proofsService = new ProofsService(
config.LIGHT_CLIENT_ADDR,
config.RPC_ADDRESS,
config.STEP_FN_ID,
config.CHAIN_ID,
config.SUCCINCT_PLATFORM_URL,
config.SUCCINCT_API_KEY,
{
lightClientAddress: config.LIGHT_CLIENT_ADDR,
stepFunctionId: config.STEP_FN_ID,
platformUrl: config.SUCCINCT_PLATFORM_URL,
apiKey: config.SUCCINCT_API_KEY,
},
{ url: config.RPC_ADDRESS, chainId: config.CHAIN_ID },
{ url: `${config.SERVER_URL_PREFIX}:${config.SERVER_PORT}` },
);

// Initialize Server and add Service handlers
Expand Down
4 changes: 2 additions & 2 deletions typescript/ccip-server/src/services/LightClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class LightClientService {
* @param slot
* @returns
*/
async getSyncCommitteePoseidons(slot: bigint): Promise<string> {
return await this.lightClientContract.syncCommitteePoseidons(
getSyncCommitteePoseidons(slot: bigint): Promise<string> {
return this.lightClientContract.syncCommitteePoseidons(
this.getSyncCommitteePeriod(slot),
);
}
Expand Down
8 changes: 2 additions & 6 deletions typescript/ccip-server/src/services/ProofsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { TelepathyCcipReadIsmAbi } from '../abis/TelepathyCcipReadIsmAbi';

import { HyperlaneService } from './HyperlaneService';
import { LightClientService, SuccinctConfig } from './LightClientService';
import { RPCService } from './RPCService';
import { ProofResult } from './RPCService';
import { ProofResult, RPCService } from './RPCService';
import { ProofStatus } from './common/ProofStatusEnum';

type RPCConfig = {
Expand Down Expand Up @@ -100,10 +99,7 @@ class ProofsService {
);
const slot = await this.lightClientService.calculateSlot(BigInt(timestamp));
const syncCommitteePoseidon = ''; // TODO get from LC
return await this.lightClientService.requestProof(
syncCommitteePoseidon,
slot,
);
return this.lightClientService.requestProof(syncCommitteePoseidon, slot);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions typescript/ccip-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/",
"rootDir": "./src"
},
"exclude": ["./node_modules/", "./dist/"],
"include": ["./src/*.ts"]
}
2 changes: 0 additions & 2 deletions typescript/cli/.eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions typescript/cli/.eslintrc

This file was deleted.

20 changes: 20 additions & 0 deletions typescript/cli/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import MonorepoDefaults from '../../eslint.config.mjs';

export default [
...MonorepoDefaults,
{
files: ['./src/**/*.ts', './cli.ts', './env.ts'],
},
{
rules: {
'no-console': ['off'],
'no-restricted-imports': ['off'],
},
},
{
ignores: ['./src/tests/**/*.ts'],
rules: {
'import/no-cycle': ['off'],
},
},
];
Loading

0 comments on commit fa6d5f5

Please sign in to comment.