Skip to content

Commit

Permalink
[FEI-6012]: Update eslint-{config|plugin}-khan to work with TypeScrip…
Browse files Browse the repository at this point in the history
…t v5.7.x (#1085)

## Summary:
This PR updates all `@typescript-eslint/*` packages to 8.17.0.  Earlier versions of `@typescript-eslint/typescript-estree` would print a warning message when loaded.  This necessitated updating `eslint-jest-plugin` which uses `@typescript-eslint/utils` which uses `@typescript-eslint/typescript-estree` internally.

I also needed to update eslint-plugin-khan's test harness to use `@typescript-eslint/rule-tester` since the old harness broke after the other upgrades.  The plugins themselves needed some tweaking after some of the types changed when updating `@typescript-eslint/utils`.

Issue: FEI-6012

## Test plan:
- yarn lint

Author: kevinb-khan

Reviewers: jeresig, kevinb-khan

Required Reviewers:

Approved By: jeresig

Checks: ✅ Test (macos-latest, 20.x), ✅ CodeQL, ✅ Lint, typecheck, and coverage check (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ gerald, ✅ Analyze (javascript), ⏭️  dependabot

Pull Request URL: #1085
  • Loading branch information
kevinb-khan authored Dec 4, 2024
1 parent b2fc2d0 commit 86caa2d
Show file tree
Hide file tree
Showing 24 changed files with 276 additions and 233 deletions.
6 changes: 6 additions & 0 deletions .changeset/silver-boxes-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/eslint-config": patch
"@khanacademy/eslint-plugin": patch
---

Update @typescript-eslint/\* to versions that work with TypeScript v5.7.x
17 changes: 6 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ module.exports = {
"no-console": "off",
},
},
{
files: [
"**/__tests__/**/*.test.ts",
"utils/*.js",
"config/**",
"build-settings/**",
],
rules: {
"@typescript-eslint/no-var-requires": "off",
},
},
],
rules: {
/**
Expand Down Expand Up @@ -161,5 +150,11 @@ module.exports = {
* monorepo rules
*/
"monorepo/no-internal-import": "error",

/**
* typescript rules
*/
// import/no-common-js covers this already
"@typescript-eslint/no-require-imports": "off",
},
};
4 changes: 4 additions & 0 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,7 @@ jobs:
full: yarn test
limited-trigger: ${{ steps.js-ts-files.outputs.filtered }}
limited: yarn test --findRelatedTests --passWithNoTests {}

- name: Mocha (eslint-plugin-khan)
working-directory: ./packages/eslint-plugin-khan
run: yarn test
1 change: 1 addition & 0 deletions config/jest/test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
resetMocks: true,
testEnvironment: "jest-environment-node",
testMatch: ["<rootDir>/**/*.test.ts"],
testPathIgnorePatterns: ["/eslint-plugin-khan/"],
setupFilesAfterEnv: [
"jest-extended/all",
"<rootDir>/config/jest/test-setup.js",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"@types/jsdom": "^21.1.1",
"@types/superagent": "^4.1.16",
"@types/winston": "^2.4.4",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"@typescript-eslint/eslint-plugin": "8.17.0",
"@typescript-eslint/parser": "8.17.0",
"babel-jest": "^29.7.0",
"babel-watch": "^7.8.1",
"eslint": "^8.52.0",
Expand All @@ -47,7 +47,7 @@
"eslint-plugin-disable": "^2.0.3",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-jest": "28.9.0",
"eslint-plugin-jsdoc": "^48.1.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-monorepo": "^0.3.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-khan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module.exports = {

"@typescript-eslint/no-unused-vars": [
ERROR,
{args: "none", varsIgnorePattern: "^_*$"},
{args: "none", caughtErrors: "none", varsIgnorePattern: "^_*$"},
],

// Require each enum member value to be explicitly initialized.
Expand Down
9 changes: 6 additions & 3 deletions packages/eslint-config-khan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
"license": "MIT",
"peerDependencies": {
"@khanacademy/eslint-plugin": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"eslint": "^8.38.0",
"@typescript-eslint/eslint-plugin": "8.17.0",
"@typescript-eslint/parser": "8.17.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0"
},
"devDependencies": {
"@typescript-eslint/rule-tester": "^8.17.0"
}
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-khan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"@babel/types": "^7.23.0",
"@typescript-eslint/utils": "^5.60.1",
"@typescript-eslint/utils": "8.17.0",
"checksync": "^5.0.5"
}
}
4 changes: 3 additions & 1 deletion packages/eslint-plugin-khan/src/rules/array-type-style.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ESLintUtils} from "@typescript-eslint/utils";

const createRule = ESLintUtils.RuleCreator(
import type {MyPluginDocs} from "../types";

const createRule = ESLintUtils.RuleCreator<MyPluginDocs>(
(name) =>
`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${name}.md`,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ESLintUtils, TSESTree, AST_NODE_TYPES} from "@typescript-eslint/utils";

const createRule = ESLintUtils.RuleCreator(
import type {MyPluginDocs} from "../types";

const createRule = ESLintUtils.RuleCreator<MyPluginDocs>(
(name) =>
`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${name}.md`,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ESLintUtils, TSESTree, AST_NODE_TYPES} from "@typescript-eslint/utils";

const createRule = ESLintUtils.RuleCreator(
import type {MyPluginDocs} from "../types";

const createRule = ESLintUtils.RuleCreator<MyPluginDocs>(
(name) =>
`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${name}.md`,
);
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-plugin-khan/src/rules/no-one-tuple.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ESLintUtils} from "@typescript-eslint/utils";

const createRule = ESLintUtils.RuleCreator(
import type {MyPluginDocs} from "../types";

const createRule = ESLintUtils.RuleCreator<MyPluginDocs>(
(name) =>
`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${name}.md`,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ESLintUtils, TSESTree, AST_NODE_TYPES} from "@typescript-eslint/utils";

const createRule = ESLintUtils.RuleCreator(
import type {MyPluginDocs} from "../types";

const createRule = ESLintUtils.RuleCreator<MyPluginDocs>(
(name) =>
`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${name}.md`,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {ESLintUtils, TSESTree} from "@typescript-eslint/utils";

import * as t from "../ast-utils";
import type {MyPluginDocs} from "../types";

const createRule = ESLintUtils.RuleCreator(
const createRule = ESLintUtils.RuleCreator<MyPluginDocs>(
(name) =>
`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${name}.md`,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {ESLintUtils, TSESTree, AST_NODE_TYPES} from "@typescript-eslint/utils";

import * as t from "../ast-utils";
import type {MyPluginDocs} from "../types";

const createRule = ESLintUtils.RuleCreator(
const createRule = ESLintUtils.RuleCreator<MyPluginDocs>(
(name) =>
`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${name}.md`,
);
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-khan/src/rules/sync-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import ancesdir from "ancesdir";
import {ESLintUtils, TSESTree, TSESLint} from "@typescript-eslint/utils";

import * as util from "../util";
import type {MyPluginDocs} from "../types";

const createRule = ESLintUtils.RuleCreator(
const createRule = ESLintUtils.RuleCreator<MyPluginDocs>(
(name) =>
`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${name}.md`,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ESLintUtils, TSESTree} from "@typescript-eslint/utils";

const createRule = ESLintUtils.RuleCreator(
import type {MyPluginDocs} from "../types";

const createRule = ESLintUtils.RuleCreator<MyPluginDocs>(
(name) =>
`https://github.com/Khan/wonder-stuff/blob/main/packages/eslint-plugin-khan/docs/${name}.md`,
);
Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-plugin-khan/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// We need to define our own PluginDocs type in order for us to be
// able to set the `recommended` field in meta.docs when calling
// `createRule`. For more info, see:
// https://typescript-eslint.io/developers/custom-rules/#extra-rule-docs-types
export interface MyPluginDocs {
recommended: boolean;
}
18 changes: 9 additions & 9 deletions packages/eslint-plugin-khan/test/RuleTester.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {ESLintUtils} from "@typescript-eslint/utils";
import * as path from "path";

function getFixturesRootDir(): string {
return path.join(__dirname, "fixtures");
}

const {batchedSingleLineTests, RuleTester, noFormat} = ESLintUtils;
export {
RuleTester,
RunTests,
ValidTestCase,
InvalidTestCase,
} from "@typescript-eslint/utils/dist/eslint-utils/rule-tester/RuleTester";
ValidTestCase,
noFormat,
} from "@typescript-eslint/rule-tester";

function getFixturesRootDir(): string {
return path.join(__dirname, "fixtures");
}

export {batchedSingleLineTests, getFixturesRootDir, noFormat, RuleTester};
export {getFixturesRootDir};
2 changes: 1 addition & 1 deletion packages/wonder-stuff-core/src/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const entries: {
}
| ArrayLike<T>,
): [string, T][];
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
(obj: {}): [string, any][];
} = (obj: any) => Object.entries(obj);
2 changes: 1 addition & 1 deletion packages/wonder-stuff-core/src/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const values: {
}
| ArrayLike<T>,
): T[];
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
(obj: {}): any[];
} = (obj: any) => Object.values(obj);
4 changes: 2 additions & 2 deletions packages/wonder-stuff-server/src/get-agent-for-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export const getAgentForURL = (url: URL): HttpAgent | HttpsAgent => {
const agentOptions = {keepAlive: true} as const;
switch (url.protocol) {
case "http:":
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const http = require("http");
return new http.Agent(agentOptions);

case "https:":
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const https = require("https");
return new https.Agent(agentOptions);

Expand Down
1 change: 0 additions & 1 deletion utils/pre-publish-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-commonjs */
/* eslint-disable no-console */
/**
* Pre-publish utilities to verify that our publish will go smoothly.
Expand Down
Loading

0 comments on commit 86caa2d

Please sign in to comment.