From 73e2df0e6372623735cf7e12fb47cb83b30dbe5b Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:32:41 +0100 Subject: [PATCH 01/14] bump --- package.json | 2 +- packages/eslint-config/package.json | 6 +- packages/eslint-plugin/package.json | 14 +- .../__tests__/process-env-computed.test.ts | 9 +- .../service-type-annotations.test.ts | 11 +- .../unsupported-route-components.test.ts | 9 +- packages/eslint-plugin/src/index.ts | 3 +- .../eslint-plugin/src/process-env-computed.ts | 46 ++- .../src/service-type-annotations.ts | 64 ++--- .../src/unsupported-route-components.ts | 2 +- packages/eslint-plugin/tsconfig.json | 2 + packages/eslint-plugin/vitest.config.mts | 10 + yarn.lock | 271 +++++++++--------- 13 files changed, 222 insertions(+), 227 deletions(-) create mode 100644 packages/eslint-plugin/vitest.config.mts diff --git a/package.json b/package.json index 29deeb177d86..7552963a272b 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "cypress-wait-until": "3.0.1", "dependency-cruiser": "16.2.3", "dotenv": "16.3.1", - "eslint": "8.55.0", + "eslint": "8.57.0", "execa": "5.1.1", "fast-glob": "3.3.2", "fs-extra": "11.2.0", diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 53190269ee19..c4bd1724fc18 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -19,9 +19,9 @@ "@redwoodjs/eslint-plugin": "workspace:*", "@redwoodjs/internal": "workspace:*", "@redwoodjs/project-config": "workspace:*", - "@typescript-eslint/eslint-plugin": "5.62.0", - "@typescript-eslint/parser": "5.62.0", - "eslint": "8.55.0", + "@typescript-eslint/eslint-plugin": "7.3.1", + "@typescript-eslint/parser": "7.3.1", + "eslint": "8.57.0", "eslint-config-prettier": "9.1.0", "eslint-import-resolver-babel-module": "5.3.2", "eslint-plugin-babel": "5.3.1", diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 09d5a4d5a759..84b3fecd322a 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -18,21 +18,23 @@ "build:types": "tsc --build --verbose", "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", - "test": "glob './src/**/__tests__/*.test.ts' --cmd='tsx --no-warnings --test' && echo", - "test:watch": "glob './src/**/__tests__/*.test.ts' --cmd='tsx --no-warnings --test --watch'" + "test": "vitest run", + "test:watch": "vitest watch" }, "dependencies": { - "@typescript-eslint/utils": "5.62.0", - "eslint": "8.55.0" + "@typescript-eslint/utils": "7.3.1", + "eslint": "8.57.0" }, "devDependencies": { "@redwoodjs/framework-tools": "workspace:*", "@types/eslint": "8", "@types/estree": "1.0.5", - "@typescript-eslint/parser": "5.62.0", + "@typescript-eslint/parser": "7.3.1", + "@typescript-eslint/rule-tester": "7.3.1", "glob": "10.3.10", "tsx": "4.6.2", - "typescript": "5.3.3" + "typescript": "5.3.3", + "vitest": "1.3.1" }, "gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1" } diff --git a/packages/eslint-plugin/src/__tests__/process-env-computed.test.ts b/packages/eslint-plugin/src/__tests__/process-env-computed.test.ts index 6696734487d8..6014d8acb8d8 100644 --- a/packages/eslint-plugin/src/__tests__/process-env-computed.test.ts +++ b/packages/eslint-plugin/src/__tests__/process-env-computed.test.ts @@ -1,14 +1,7 @@ -import { describe, it } from 'node:test' - -import { RuleTester } from 'eslint' +import { RuleTester } from '@typescript-eslint/rule-tester' import { processEnvComputedRule } from '../process-env-computed.js' -// @ts-expect-error - Types are wrong -RuleTester.describe = describe -// @ts-expect-error - Types are wrong -RuleTester.it = it - const ruleTester = new RuleTester() ruleTester.run('process-env-computed', processEnvComputedRule, { diff --git a/packages/eslint-plugin/src/__tests__/service-type-annotations.test.ts b/packages/eslint-plugin/src/__tests__/service-type-annotations.test.ts index 44ef5fcfa22d..652f79c37c53 100644 --- a/packages/eslint-plugin/src/__tests__/service-type-annotations.test.ts +++ b/packages/eslint-plugin/src/__tests__/service-type-annotations.test.ts @@ -1,16 +1,9 @@ -import { describe, it } from 'node:test' - -import { RuleTester } from 'eslint' +import { RuleTester } from '@typescript-eslint/rule-tester' import { serviceTypeAnnotations } from '../service-type-annotations.js' -// @ts-expect-error - Types are wrong -RuleTester.describe = describe -// @ts-expect-error - Types are wrong -RuleTester.it = it - const ruleTester = new RuleTester({ - parser: require.resolve('@typescript-eslint/parser'), + parser: '@typescript-eslint/parser', }) ruleTester.run('service-type-annotations', serviceTypeAnnotations, { diff --git a/packages/eslint-plugin/src/__tests__/unsupported-route-components.test.ts b/packages/eslint-plugin/src/__tests__/unsupported-route-components.test.ts index ee94fa42f506..43e1a6d40b6b 100644 --- a/packages/eslint-plugin/src/__tests__/unsupported-route-components.test.ts +++ b/packages/eslint-plugin/src/__tests__/unsupported-route-components.test.ts @@ -1,13 +1,8 @@ -import { describe, it } from 'node:test' - -import { ESLintUtils } from '@typescript-eslint/utils' +import { RuleTester } from '@typescript-eslint/rule-tester' import { unsupportedRouteComponents } from '../unsupported-route-components.js' -ESLintUtils.RuleTester.describe = describe -ESLintUtils.RuleTester.it = it - -const ruleTester = new ESLintUtils.RuleTester({ +const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 'latest', diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts index 7d14933c3ab5..6cbc149157f4 100644 --- a/packages/eslint-plugin/src/index.ts +++ b/packages/eslint-plugin/src/index.ts @@ -2,7 +2,8 @@ import { processEnvComputedRule } from './process-env-computed.js' import { serviceTypeAnnotations } from './service-type-annotations.js' import { unsupportedRouteComponents } from './unsupported-route-components.js' -export const rules = { +// TODO: Use a better type than 'any' for the value of this record +export const rules: Record = { 'process-env-computed': processEnvComputedRule, 'service-type-annotations': serviceTypeAnnotations, 'unsupported-route-components': unsupportedRouteComponents, diff --git a/packages/eslint-plugin/src/process-env-computed.ts b/packages/eslint-plugin/src/process-env-computed.ts index a979fa697967..ffdd113db35f 100644 --- a/packages/eslint-plugin/src/process-env-computed.ts +++ b/packages/eslint-plugin/src/process-env-computed.ts @@ -1,29 +1,18 @@ -import type { Rule } from 'eslint' -import type { Identifier, MemberExpression } from 'estree' +import type { TSESTree } from '@typescript-eslint/utils' +import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils' -function isProcessEnv(node: unknown) { +const createRule = ESLintUtils.RuleCreator.withoutDocs + +function isProcessEnv(node: TSESTree.Node) { return ( - isMemberExpression(node) && + node.type === AST_NODE_TYPES.MemberExpression && hasName(node.object, 'process') && hasName(node.property, 'env') ) } -function isIdentifier(node: unknown): node is Identifier { - return ( - typeof node !== 'undefined' && (node as Identifier).type === 'Identifier' - ) -} - -function isMemberExpression(node: unknown): node is MemberExpression { - return ( - typeof node !== 'undefined' && - (node as MemberExpression).type === 'MemberExpression' - ) -} - -function hasName(node: unknown, name: string) { - return isIdentifier(node) && node.name === name +function hasName(node: TSESTree.Node, name: string) { + return node.type === AST_NODE_TYPES.Identifier && node.name === name } function isTestFile(filename: string) { @@ -46,31 +35,34 @@ function isTestFile(filename: string) { ) } -export const processEnvComputedRule: Rule.RuleModule = { +export const processEnvComputedRule = createRule({ meta: { type: 'problem', docs: { description: 'Find computed member access on process.env', }, - // fixable: 'code', + messages: { + unexpected: + 'Accessing process.env via array syntax will break in production. Use dot notation e.g. process.env.MY_ENV_VAR instead', + }, schema: [], // No additional configuration needed }, + defaultOptions: [], create(context) { return { MemberExpression: function (node) { - if ( + const matches = isProcessEnv(node.object) && node.computed && !isTestFile(context.filename) - ) { + + if (matches) { context.report({ - message: - 'Accessing process.env via array syntax will break in production. Use dot notation e.g. process.env.MY_ENV_VAR instead', + messageId: 'unexpected', node, - // fix(fixer) {}, }) } }, } }, -} +}) diff --git a/packages/eslint-plugin/src/service-type-annotations.ts b/packages/eslint-plugin/src/service-type-annotations.ts index 40dee333ef6f..563aebe22bd4 100644 --- a/packages/eslint-plugin/src/service-type-annotations.ts +++ b/packages/eslint-plugin/src/service-type-annotations.ts @@ -1,20 +1,34 @@ -import { basename } from 'path' +import { basename } from 'node:path' -import type { Identifier } from '@typescript-eslint/types/dist/generated/ast-spec' -import type { Rule } from 'eslint' -import type { - Declaration, - ImportDeclaration, - VariableDeclaration, -} from 'estree' +import type { TSESTree } from '@typescript-eslint/utils' +import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils' -export const serviceTypeAnnotations: Rule.RuleModule = { +const createRule = ESLintUtils.RuleCreator.withoutDocs + +const capitalizeFirstLetter = (str: string) => + str.charAt(0).toUpperCase() + str.slice(1) + +export const serviceTypeAnnotations = createRule({ + meta: { + docs: { + description: + 'Sets the types on a query/mutation resolver function to the correct type', + }, + messages: { + needsType: + 'The query/mutation function ({{name}}) needs a type annotation of {{typeName}}.', + }, + fixable: 'code', + type: 'suggestion', + schema: [], + }, + defaultOptions: [], create(context) { const thisFilename = basename(context.filename) const sansTS = thisFilename.replace('.ts', '') const thisFileCorrespondingImport = `types/${sansTS}` - let importForThisFile: ImportDeclaration | null = null + let importForThisFile: TSESTree.ImportDeclaration | null = null return { // Make sure we have a reference to the import for the relative file // which includes definitions for this service @@ -25,7 +39,10 @@ export const serviceTypeAnnotations: Rule.RuleModule = { // Then start looking at every exported fn/const ExportNamedDeclaration(node) { - if (!node.declaration || !isVariableDeclaration(node.declaration)) { + if ( + !node.declaration || + node.declaration.type !== AST_NODE_TYPES.VariableDeclaration + ) { return } @@ -54,7 +71,7 @@ export const serviceTypeAnnotations: Rule.RuleModule = { } // Switch from the estree type to the typescript-eslint type - const tsID = vd.id as Identifier + const tsID = vd.id as TSESTree.Identifier // If there's no type annotation, then we should add one if (!tsID.typeAnnotation) { @@ -142,25 +159,4 @@ export const serviceTypeAnnotations: Rule.RuleModule = { }, } }, - meta: { - docs: { - description: - 'Sets the types on a query/mutation resolver function to the correct type', - recommended: false, - }, - messages: { - needsType: - 'The query/mutation function ({{name}}) needs a type annotation of {{typeName}}.', - }, - fixable: 'code', - type: 'suggestion', - }, -} - -const capitalizeFirstLetter = (str: string) => - str.charAt(0).toUpperCase() + str.slice(1) - -const isVariableDeclaration = ( - node: Declaration, -): node is VariableDeclaration => - typeof node !== 'undefined' && 'declarations' in node +}) diff --git a/packages/eslint-plugin/src/unsupported-route-components.ts b/packages/eslint-plugin/src/unsupported-route-components.ts index 3bcc8be2ab23..1fa445e42f94 100644 --- a/packages/eslint-plugin/src/unsupported-route-components.ts +++ b/packages/eslint-plugin/src/unsupported-route-components.ts @@ -12,7 +12,7 @@ export const unsupportedRouteComponents = createRule({ type: 'problem', docs: { description: 'Find unsupported route components', - recommended: 'error', + recommended: 'recommended', }, messages: { unexpected: diff --git a/packages/eslint-plugin/tsconfig.json b/packages/eslint-plugin/tsconfig.json index a16ec4441da3..20c254a9dfd8 100644 --- a/packages/eslint-plugin/tsconfig.json +++ b/packages/eslint-plugin/tsconfig.json @@ -1,6 +1,8 @@ { "extends": "../../tsconfig.compilerOption.json", "compilerOptions": { + "moduleResolution": "NodeNext", + "module": "NodeNext", "strict": true, "rootDir": "src", "outDir": "dist", diff --git a/packages/eslint-plugin/vitest.config.mts b/packages/eslint-plugin/vitest.config.mts new file mode 100644 index 000000000000..282c54edab83 --- /dev/null +++ b/packages/eslint-plugin/vitest.config.mts @@ -0,0 +1,10 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + // Globals are enabled for the benefit of '@typescript-eslint/rule-tester' + globals: true + }, +}) + + diff --git a/yarn.lock b/yarn.lock index 2bed0b38634e..c3cda6c6d89f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2986,7 +2986,7 @@ __metadata: languageName: node linkType: hard -"@eslint-community/eslint-utils@npm:^4.2.0": +"@eslint-community/eslint-utils@npm:^4.2.0, @eslint-community/eslint-utils@npm:^4.4.0": version: 4.4.0 resolution: "@eslint-community/eslint-utils@npm:4.4.0" dependencies: @@ -2997,10 +2997,10 @@ __metadata: languageName: node linkType: hard -"@eslint-community/regexpp@npm:^4.4.0, @eslint-community/regexpp@npm:^4.6.1": - version: 4.6.2 - resolution: "@eslint-community/regexpp@npm:4.6.2" - checksum: 10c0/da800788298f8419f4c4e04eaa4e3c97e7f57537e822e7b150de662e420e3d437816b863e490807bd0b00e715b0989f9d8864bf54357cbcfa84e4255b910789d +"@eslint-community/regexpp@npm:^4.5.1, @eslint-community/regexpp@npm:^4.6.1": + version: 4.10.0 + resolution: "@eslint-community/regexpp@npm:4.10.0" + checksum: 10c0/c5f60ef1f1ea7649fa7af0e80a5a79f64b55a8a8fa5086de4727eb4c86c652aedee407a9c143b8995d2c0b2d75c1222bec9ba5d73dbfc1f314550554f0979ef4 languageName: node linkType: hard @@ -3021,10 +3021,10 @@ __metadata: languageName: node linkType: hard -"@eslint/js@npm:8.55.0": - version: 8.55.0 - resolution: "@eslint/js@npm:8.55.0" - checksum: 10c0/88ab9fc57a651becd2b32ec40a3958db27fae133b1ae77bebd733aa5bbd00a92f325bb02f20ad680d31c731fa49b22f060a4777dd52eb3e27da013d940bd978d +"@eslint/js@npm:8.57.0": + version: 8.57.0 + resolution: "@eslint/js@npm:8.57.0" + checksum: 10c0/9a518bb8625ba3350613903a6d8c622352ab0c6557a59fe6ff6178bf882bf57123f9d92aa826ee8ac3ee74b9c6203fe630e9ee00efb03d753962dcf65ee4bd94 languageName: node linkType: hard @@ -4791,14 +4791,14 @@ __metadata: languageName: node linkType: hard -"@humanwhocodes/config-array@npm:^0.11.13": - version: 0.11.13 - resolution: "@humanwhocodes/config-array@npm:0.11.13" +"@humanwhocodes/config-array@npm:^0.11.14": + version: 0.11.14 + resolution: "@humanwhocodes/config-array@npm:0.11.14" dependencies: - "@humanwhocodes/object-schema": "npm:^2.0.1" - debug: "npm:^4.1.1" + "@humanwhocodes/object-schema": "npm:^2.0.2" + debug: "npm:^4.3.1" minimatch: "npm:^3.0.5" - checksum: 10c0/d76ca802d853366094d0e98ff0d0994117fc8eff96649cd357b15e469e428228f597cd2e929d54ab089051684949955f16ee905bb19f7b2f0446fb377157be7a + checksum: 10c0/66f725b4ee5fdd8322c737cb5013e19fac72d4d69c8bf4b7feb192fcb83442b035b92186f8e9497c220e58b2d51a080f28a73f7899bc1ab288c3be172c467541 languageName: node linkType: hard @@ -4809,10 +4809,10 @@ __metadata: languageName: node linkType: hard -"@humanwhocodes/object-schema@npm:^2.0.1": - version: 2.0.1 - resolution: "@humanwhocodes/object-schema@npm:2.0.1" - checksum: 10c0/9dba24e59fdb4041829d92b693aacb778add3b6f612aaa9c0774f3b650c11a378cc64f042a59da85c11dae33df456580a3c36837b953541aed6ff94294f97fac +"@humanwhocodes/object-schema@npm:^2.0.2": + version: 2.0.2 + resolution: "@humanwhocodes/object-schema@npm:2.0.2" + checksum: 10c0/6fd83dc320231d71c4541d0244051df61f301817e9f9da9fd4cb7e44ec8aacbde5958c1665b0c419401ab935114fdf532a6ad5d4e7294b1af2f347dd91a6983f languageName: node linkType: hard @@ -8333,9 +8333,9 @@ __metadata: "@redwoodjs/eslint-plugin": "workspace:*" "@redwoodjs/internal": "workspace:*" "@redwoodjs/project-config": "workspace:*" - "@typescript-eslint/eslint-plugin": "npm:5.62.0" - "@typescript-eslint/parser": "npm:5.62.0" - eslint: "npm:8.55.0" + "@typescript-eslint/eslint-plugin": "npm:7.3.1" + "@typescript-eslint/parser": "npm:7.3.1" + eslint: "npm:8.57.0" eslint-config-prettier: "npm:9.1.0" eslint-import-resolver-babel-module: "npm:5.3.2" eslint-plugin-babel: "npm:5.3.1" @@ -8358,12 +8358,14 @@ __metadata: "@redwoodjs/framework-tools": "workspace:*" "@types/eslint": "npm:8" "@types/estree": "npm:1.0.5" - "@typescript-eslint/parser": "npm:5.62.0" - "@typescript-eslint/utils": "npm:5.62.0" - eslint: "npm:8.55.0" + "@typescript-eslint/parser": "npm:7.3.1" + "@typescript-eslint/rule-tester": "npm:7.3.1" + "@typescript-eslint/utils": "npm:7.3.1" + eslint: "npm:8.57.0" glob: "npm:10.3.10" tsx: "npm:4.6.2" typescript: "npm:5.3.3" + vitest: "npm:1.3.1" languageName: unknown linkType: soft @@ -11190,10 +11192,10 @@ __metadata: languageName: node linkType: hard -"@types/json-schema@npm:*, @types/json-schema@npm:^7.0.5, @types/json-schema@npm:^7.0.8, @types/json-schema@npm:^7.0.9": - version: 7.0.12 - resolution: "@types/json-schema@npm:7.0.12" - checksum: 10c0/2c39946ae321fe42d085c61a85872a81bbee70f9b2054ad344e8811dfc478fdbaf1ebf5f2989bb87c895ba2dfc3b1dcba85db11e467bbcdc023708814207791c +"@types/json-schema@npm:*, @types/json-schema@npm:^7.0.12, @types/json-schema@npm:^7.0.5, @types/json-schema@npm:^7.0.8, @types/json-schema@npm:^7.0.9": + version: 7.0.15 + resolution: "@types/json-schema@npm:7.0.15" + checksum: 10c0/a996a745e6c5d60292f36731dd41341339d4eeed8180bb09226e5c8d23759067692b1d88e5d91d72ee83dfc00d3aca8e7bd43ea120516c17922cbcb7c3e252db languageName: node linkType: hard @@ -11606,10 +11608,10 @@ __metadata: languageName: node linkType: hard -"@types/semver@npm:^7.3.12, @types/semver@npm:^7.3.4": - version: 7.5.0 - resolution: "@types/semver@npm:7.5.0" - checksum: 10c0/ca4ba4642b5972b6e88e73c5bc02bbaceb8d76bce71748d86e3e95042d4e5a44603113a1dcd2cb9b73ad6f91f6e4ab73185eb41bbfc9c73b11f0ed3db3b7443a +"@types/semver@npm:^7.3.4, @types/semver@npm:^7.5.0": + version: 7.5.8 + resolution: "@types/semver@npm:7.5.8" + checksum: 10c0/8663ff927234d1c5fcc04b33062cb2b9fcfbe0f5f351ed26c4d1e1581657deebd506b41ff7fdf89e787e3d33ce05854bc01686379b89e9c49b564c4cfa988efa languageName: node linkType: hard @@ -11794,124 +11796,142 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/eslint-plugin@npm:5.62.0" +"@typescript-eslint/eslint-plugin@npm:7.3.1": + version: 7.3.1 + resolution: "@typescript-eslint/eslint-plugin@npm:7.3.1" dependencies: - "@eslint-community/regexpp": "npm:^4.4.0" - "@typescript-eslint/scope-manager": "npm:5.62.0" - "@typescript-eslint/type-utils": "npm:5.62.0" - "@typescript-eslint/utils": "npm:5.62.0" + "@eslint-community/regexpp": "npm:^4.5.1" + "@typescript-eslint/scope-manager": "npm:7.3.1" + "@typescript-eslint/type-utils": "npm:7.3.1" + "@typescript-eslint/utils": "npm:7.3.1" + "@typescript-eslint/visitor-keys": "npm:7.3.1" debug: "npm:^4.3.4" graphemer: "npm:^1.4.0" - ignore: "npm:^5.2.0" - natural-compare-lite: "npm:^1.4.0" - semver: "npm:^7.3.7" - tsutils: "npm:^3.21.0" + ignore: "npm:^5.2.4" + natural-compare: "npm:^1.4.0" + semver: "npm:^7.5.4" + ts-api-utils: "npm:^1.0.1" peerDependencies: - "@typescript-eslint/parser": ^5.0.0 - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + "@typescript-eslint/parser": ^7.0.0 + eslint: ^8.56.0 peerDependenciesMeta: typescript: optional: true - checksum: 10c0/3f40cb6bab5a2833c3544e4621b9fdacd8ea53420cadc1c63fac3b89cdf5c62be1e6b7bcf56976dede5db4c43830de298ced3db60b5494a3b961ca1b4bff9f2a + checksum: 10c0/446c36801ee434854c935fd09f267bd68d537c1e422cfca87237230313b2ea40b512bb2357bcf489225df10a6d2f14dcd3ac8db80517b982abe0b609dd606c6c languageName: node linkType: hard -"@typescript-eslint/parser@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/parser@npm:5.62.0" +"@typescript-eslint/parser@npm:7.3.1": + version: 7.3.1 + resolution: "@typescript-eslint/parser@npm:7.3.1" dependencies: - "@typescript-eslint/scope-manager": "npm:5.62.0" - "@typescript-eslint/types": "npm:5.62.0" - "@typescript-eslint/typescript-estree": "npm:5.62.0" + "@typescript-eslint/scope-manager": "npm:7.3.1" + "@typescript-eslint/types": "npm:7.3.1" + "@typescript-eslint/typescript-estree": "npm:7.3.1" + "@typescript-eslint/visitor-keys": "npm:7.3.1" debug: "npm:^4.3.4" peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + eslint: ^8.56.0 peerDependenciesMeta: typescript: optional: true - checksum: 10c0/315194b3bf39beb9bd16c190956c46beec64b8371e18d6bb72002108b250983eb1e186a01d34b77eb4045f4941acbb243b16155fbb46881105f65e37dc9e24d4 + checksum: 10c0/c524e7021ea551cb83e19c7f1a697664171a6b227e16e33912243af659905a7effeaf9fc05e3c160cb99d8ba17552fa87e27be38261280daa733d4d4d4876eec languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/scope-manager@npm:5.62.0" +"@typescript-eslint/rule-tester@npm:7.3.1": + version: 7.3.1 + resolution: "@typescript-eslint/rule-tester@npm:7.3.1" + dependencies: + "@typescript-eslint/typescript-estree": "npm:7.3.1" + "@typescript-eslint/utils": "npm:7.3.1" + ajv: "npm:^6.10.0" + lodash.merge: "npm:4.6.2" + semver: "npm:^7.5.4" + peerDependencies: + "@eslint/eslintrc": ">=2" + eslint: ^8.56.0 + checksum: 10c0/85cb4d14207c6c5c98e439929135ce9561c98c7509d04215c0bcbbd9b80b958534042ec5b3de05b9631a9d928a4c12cf08ce56f512382f873a3a249ca97095e5 + languageName: node + linkType: hard + +"@typescript-eslint/scope-manager@npm:7.3.1": + version: 7.3.1 + resolution: "@typescript-eslint/scope-manager@npm:7.3.1" dependencies: - "@typescript-eslint/types": "npm:5.62.0" - "@typescript-eslint/visitor-keys": "npm:5.62.0" - checksum: 10c0/861253235576c1c5c1772d23cdce1418c2da2618a479a7de4f6114a12a7ca853011a1e530525d0931c355a8fd237b9cd828fac560f85f9623e24054fd024726f + "@typescript-eslint/types": "npm:7.3.1" + "@typescript-eslint/visitor-keys": "npm:7.3.1" + checksum: 10c0/08dd466b19445a8e2b093df7fcc59767289843d1cdc423b2f402a2a2c69a53e3cdf52dcc1497311346a45e875d77826a831b5b9a9fb7f709679f221344051c74 languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/type-utils@npm:5.62.0" +"@typescript-eslint/type-utils@npm:7.3.1": + version: 7.3.1 + resolution: "@typescript-eslint/type-utils@npm:7.3.1" dependencies: - "@typescript-eslint/typescript-estree": "npm:5.62.0" - "@typescript-eslint/utils": "npm:5.62.0" + "@typescript-eslint/typescript-estree": "npm:7.3.1" + "@typescript-eslint/utils": "npm:7.3.1" debug: "npm:^4.3.4" - tsutils: "npm:^3.21.0" + ts-api-utils: "npm:^1.0.1" peerDependencies: - eslint: "*" + eslint: ^8.56.0 peerDependenciesMeta: typescript: optional: true - checksum: 10c0/93112e34026069a48f0484b98caca1c89d9707842afe14e08e7390af51cdde87378df29d213d3bbd10a7cfe6f91b228031b56218515ce077bdb62ddea9d9f474 + checksum: 10c0/0e9ad41fe9eac135e1f6b448a2e1660df83e93bd2c370f1aaabe8bbdd376cda0e00d02b884793a3ce3a51c962c1f5cac543bcc1f02e4d1de2af757031aa6cbed languageName: node linkType: hard -"@typescript-eslint/types@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/types@npm:5.62.0" - checksum: 10c0/7febd3a7f0701c0b927e094f02e82d8ee2cada2b186fcb938bc2b94ff6fbad88237afc304cbaf33e82797078bbbb1baf91475f6400912f8b64c89be79bfa4ddf +"@typescript-eslint/types@npm:7.3.1": + version: 7.3.1 + resolution: "@typescript-eslint/types@npm:7.3.1" + checksum: 10c0/d3b579829db901b2ea52000a6e343b7e3814fa06f62ba42711df2533365a247e97699f64fc15482cc433302ff81e8a0eed1ed2b0478d0709171d57910d46bdd5 languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/typescript-estree@npm:5.62.0" +"@typescript-eslint/typescript-estree@npm:7.3.1": + version: 7.3.1 + resolution: "@typescript-eslint/typescript-estree@npm:7.3.1" dependencies: - "@typescript-eslint/types": "npm:5.62.0" - "@typescript-eslint/visitor-keys": "npm:5.62.0" + "@typescript-eslint/types": "npm:7.3.1" + "@typescript-eslint/visitor-keys": "npm:7.3.1" debug: "npm:^4.3.4" globby: "npm:^11.1.0" is-glob: "npm:^4.0.3" - semver: "npm:^7.3.7" - tsutils: "npm:^3.21.0" + minimatch: "npm:9.0.3" + semver: "npm:^7.5.4" + ts-api-utils: "npm:^1.0.1" peerDependenciesMeta: typescript: optional: true - checksum: 10c0/d7984a3e9d56897b2481940ec803cb8e7ead03df8d9cfd9797350be82ff765dfcf3cfec04e7355e1779e948da8f02bc5e11719d07a596eb1cb995c48a95e38cf + checksum: 10c0/52dbfc590b01a43fae906dadd383c185b93fea5c8ac90aa2369f6c36d53a5d465fac02315a903a3b291974626045547ab53f346dc2271e93c8179deaad7a3961 languageName: node linkType: hard -"@typescript-eslint/utils@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/utils@npm:5.62.0" - dependencies: - "@eslint-community/eslint-utils": "npm:^4.2.0" - "@types/json-schema": "npm:^7.0.9" - "@types/semver": "npm:^7.3.12" - "@typescript-eslint/scope-manager": "npm:5.62.0" - "@typescript-eslint/types": "npm:5.62.0" - "@typescript-eslint/typescript-estree": "npm:5.62.0" - eslint-scope: "npm:^5.1.1" - semver: "npm:^7.3.7" +"@typescript-eslint/utils@npm:7.3.1": + version: 7.3.1 + resolution: "@typescript-eslint/utils@npm:7.3.1" + dependencies: + "@eslint-community/eslint-utils": "npm:^4.4.0" + "@types/json-schema": "npm:^7.0.12" + "@types/semver": "npm:^7.5.0" + "@typescript-eslint/scope-manager": "npm:7.3.1" + "@typescript-eslint/types": "npm:7.3.1" + "@typescript-eslint/typescript-estree": "npm:7.3.1" + semver: "npm:^7.5.4" peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - checksum: 10c0/f09b7d9952e4a205eb1ced31d7684dd55cee40bf8c2d78e923aa8a255318d97279825733902742c09d8690f37a50243f4c4d383ab16bd7aefaf9c4b438f785e1 + eslint: ^8.56.0 + checksum: 10c0/1d7b049b2c4de1937832ae8ed681bbcd3b06b0d0b476cce67af96b2f65ff606413cc7dfdaad1e01057d24ba39bf5f6d4ba2923d23dab784d2bed5a217ab7b825 languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:5.62.0": - version: 5.62.0 - resolution: "@typescript-eslint/visitor-keys@npm:5.62.0" +"@typescript-eslint/visitor-keys@npm:7.3.1": + version: 7.3.1 + resolution: "@typescript-eslint/visitor-keys@npm:7.3.1" dependencies: - "@typescript-eslint/types": "npm:5.62.0" - eslint-visitor-keys: "npm:^3.3.0" - checksum: 10c0/7c3b8e4148e9b94d9b7162a596a1260d7a3efc4e65199693b8025c71c4652b8042501c0bc9f57654c1e2943c26da98c0f77884a746c6ae81389fcb0b513d995d + "@typescript-eslint/types": "npm:7.3.1" + eslint-visitor-keys: "npm:^3.4.1" + checksum: 10c0/1765d9ee31adaa1cfaaa72a1acc987bba6cc382b5c6785ffcc2706a776c115e9310ea6761f70fe9b83bc7edf5ecb3cb6814c83704bd2bb807a6a35cf52f36958 languageName: node linkType: hard @@ -12840,7 +12860,7 @@ __metadata: languageName: node linkType: hard -"ajv@npm:^6.1.0, ajv@npm:^6.10.2, ajv@npm:^6.12.4, ajv@npm:^6.12.5": +"ajv@npm:^6.1.0, ajv@npm:^6.10.0, ajv@npm:^6.10.2, ajv@npm:^6.12.4, ajv@npm:^6.12.5": version: 6.12.6 resolution: "ajv@npm:6.12.6" dependencies: @@ -18252,7 +18272,7 @@ __metadata: languageName: node linkType: hard -"eslint-scope@npm:5.1.1, eslint-scope@npm:^5.1.1": +"eslint-scope@npm:5.1.1": version: 5.1.1 resolution: "eslint-scope@npm:5.1.1" dependencies: @@ -18296,15 +18316,15 @@ __metadata: languageName: node linkType: hard -"eslint@npm:8.55.0": - version: 8.55.0 - resolution: "eslint@npm:8.55.0" +"eslint@npm:8.57.0": + version: 8.57.0 + resolution: "eslint@npm:8.57.0" dependencies: "@eslint-community/eslint-utils": "npm:^4.2.0" "@eslint-community/regexpp": "npm:^4.6.1" "@eslint/eslintrc": "npm:^2.1.4" - "@eslint/js": "npm:8.55.0" - "@humanwhocodes/config-array": "npm:^0.11.13" + "@eslint/js": "npm:8.57.0" + "@humanwhocodes/config-array": "npm:^0.11.14" "@humanwhocodes/module-importer": "npm:^1.0.1" "@nodelib/fs.walk": "npm:^1.2.8" "@ungap/structured-clone": "npm:^1.2.0" @@ -18340,7 +18360,7 @@ __metadata: text-table: "npm:^0.2.0" bin: eslint: bin/eslint.js - checksum: 10c0/d28c0b60f19bb7d355cb8393e77b018c8f548dba3f820b799c89bb2e0c436ee26084e700c5e57e1e97e7972ec93065277849141b82e7b0c0d02c2dc1e553a2a1 + checksum: 10c0/00bb96fd2471039a312435a6776fe1fd557c056755eaa2b96093ef3a8508c92c8775d5f754768be6b1dddd09fdd3379ddb231eeb9b6c579ee17ea7d68000a529 languageName: node linkType: hard @@ -24072,7 +24092,7 @@ __metadata: languageName: node linkType: hard -"lodash.merge@npm:^4.6.2": +"lodash.merge@npm:4.6.2, lodash.merge@npm:^4.6.2": version: 4.6.2 resolution: "lodash.merge@npm:4.6.2" checksum: 10c0/402fa16a1edd7538de5b5903a90228aa48eb5533986ba7fa26606a49db2572bf414ff73a2c9f5d5fd36b31c46a5d5c7e1527749c07cbcf965ccff5fbdf32c506 @@ -25729,13 +25749,6 @@ __metadata: languageName: node linkType: hard -"natural-compare-lite@npm:^1.4.0": - version: 1.4.0 - resolution: "natural-compare-lite@npm:1.4.0" - checksum: 10c0/f6cef26f5044515754802c0fc475d81426f3b90fe88c20fabe08771ce1f736ce46e0397c10acb569a4dd0acb84c7f1ee70676122f95d5bfdd747af3a6c6bbaa8 - languageName: node - linkType: hard - "natural-compare@npm:^1.4.0": version: 1.4.0 resolution: "natural-compare@npm:1.4.0" @@ -29989,7 +30002,7 @@ __metadata: cypress-wait-until: "npm:3.0.1" dependency-cruiser: "npm:16.2.3" dotenv: "npm:16.3.1" - eslint: "npm:8.55.0" + eslint: "npm:8.57.0" execa: "npm:5.1.1" fast-glob: "npm:3.3.2" fs-extra: "npm:11.2.0" @@ -32328,6 +32341,15 @@ __metadata: languageName: node linkType: hard +"ts-api-utils@npm:^1.0.1": + version: 1.3.0 + resolution: "ts-api-utils@npm:1.3.0" + peerDependencies: + typescript: ">=4.2.0" + checksum: 10c0/f54a0ba9ed56ce66baea90a3fa087a484002e807f28a8ccb2d070c75e76bde64bd0f6dce98b3802834156306050871b67eec325cb4e918015a360a3f0868c77c + languageName: node + linkType: hard + "ts-dedent@npm:^2.0.0": version: 2.2.0 resolution: "ts-dedent@npm:2.2.0" @@ -32457,7 +32479,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^1.10.0, tslib@npm:^1.13.0, tslib@npm:^1.8.1, tslib@npm:^1.9.0, tslib@npm:^1.9.2": +"tslib@npm:^1.10.0, tslib@npm:^1.13.0, tslib@npm:^1.9.0, tslib@npm:^1.9.2": version: 1.14.1 resolution: "tslib@npm:1.14.1" checksum: 10c0/69ae09c49eea644bc5ebe1bca4fa4cc2c82b7b3e02f43b84bd891504edf66dbc6b2ec0eef31a957042de2269139e4acff911e6d186a258fb14069cd7f6febce2 @@ -32492,17 +32514,6 @@ __metadata: languageName: node linkType: hard -"tsutils@npm:^3.21.0": - version: 3.21.0 - resolution: "tsutils@npm:3.21.0" - dependencies: - tslib: "npm:^1.8.1" - peerDependencies: - typescript: ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - checksum: 10c0/02f19e458ec78ead8fffbf711f834ad8ecd2cc6ade4ec0320790713dccc0a412b99e7fd907c4cda2a1dc602c75db6f12e0108e87a5afad4b2f9e90a24cabd5a2 - languageName: node - linkType: hard - "tsx@npm:4.6.2": version: 4.6.2 resolution: "tsx@npm:4.6.2" From a9769a0e09031cb9f99f8102a107f0fd49949ca2 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:33:09 +0100 Subject: [PATCH 02/14] use 'object' over '{}' --- packages/router/src/skipNav.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/router/src/skipNav.tsx b/packages/router/src/skipNav.tsx index 824883d75cde..636fce209c30 100644 --- a/packages/router/src/skipNav.tsx +++ b/packages/router/src/skipNav.tsx @@ -9,8 +9,9 @@ import * as React from 'react' // Original Code Source @reach/polymorphic // https://github.com/reach/reach-ui/blob/dev/packages/polymorphic/src/reach-polymorphic.ts +// We updated three instances of type "{}" to "object" to avoid linting errors -type Merge = Omit & P2 +type Merge = Omit & P2 type ForwardRefExoticComponent = React.ForwardRefExoticComponent< Merge< @@ -21,7 +22,7 @@ type ForwardRefExoticComponent = React.ForwardRefExoticComponent< interface ForwardRefComponent< IntrinsicElementString, - OwnProps = {}, + OwnProps = object, /* * Extends original type to ensure built in React types play nice with * polymorphic components still e.g. `React.ElementRef` etc. From 62ae5211c336f290b0f73205b406169b0c1ef655 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:48:13 +0100 Subject: [PATCH 03/14] remove unused dev deps --- packages/eslint-plugin/package.json | 2 -- yarn.lock | 2 -- 2 files changed, 4 deletions(-) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 84b3fecd322a..887ec176600e 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -31,8 +31,6 @@ "@types/estree": "1.0.5", "@typescript-eslint/parser": "7.3.1", "@typescript-eslint/rule-tester": "7.3.1", - "glob": "10.3.10", - "tsx": "4.6.2", "typescript": "5.3.3", "vitest": "1.3.1" }, diff --git a/yarn.lock b/yarn.lock index c3cda6c6d89f..392bf4ea8cb6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8362,8 +8362,6 @@ __metadata: "@typescript-eslint/rule-tester": "npm:7.3.1" "@typescript-eslint/utils": "npm:7.3.1" eslint: "npm:8.57.0" - glob: "npm:10.3.10" - tsx: "npm:4.6.2" typescript: "npm:5.3.3" vitest: "npm:1.3.1" languageName: unknown From b78c24eb619b0a9ec1c7bce9090723049f956572 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:30:21 +0000 Subject: [PATCH 04/14] use a better type than any --- packages/eslint-plugin/src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts index 6cbc149157f4..aed5d614dcd3 100644 --- a/packages/eslint-plugin/src/index.ts +++ b/packages/eslint-plugin/src/index.ts @@ -1,9 +1,13 @@ +import type { ESLintUtils } from '@typescript-eslint/utils' + import { processEnvComputedRule } from './process-env-computed.js' import { serviceTypeAnnotations } from './service-type-annotations.js' import { unsupportedRouteComponents } from './unsupported-route-components.js' -// TODO: Use a better type than 'any' for the value of this record -export const rules: Record = { +export const rules: Record< + string, + ESLintUtils.RuleModule +> = { 'process-env-computed': processEnvComputedRule, 'service-type-annotations': serviceTypeAnnotations, 'unsupported-route-components': unsupportedRouteComponents, From efb36f91907276387b35d93627913d880454fb1b Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:42:40 +0000 Subject: [PATCH 05/14] add changeset entry --- .changesets/10266.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .changesets/10266.md diff --git a/.changesets/10266.md b/.changesets/10266.md new file mode 100644 index 000000000000..08aece9a0dfc --- /dev/null +++ b/.changesets/10266.md @@ -0,0 +1,22 @@ +- chore(linting): Update versions and avoid `{}` (#10266) by @Josh-Walker-GM + +This PR updates the versions of the `eslint` and the `@typescript-eslint` packages from v5 to v7. The primary motivation for this change is that you no longer see the: +``` +============= + +WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree. + +You may find that it works just fine, or you may not. + +SUPPORTED TYPESCRIPT VERSIONS: >=3.3.1 <5.2.0 + +YOUR TYPESCRIPT VERSION: 5.3.3 + +Please only submit bug reports when using the officially supported version. + +============= +``` +warning in your terminal when you run `yarn rw lint`. + +This is a major upgrade of the `@typescript-eslint` package and although we think it is unlikely to introduce a breaking change for you we would recommend that you read the associated documentation. The v6 upgrade can be found [here](https://typescript-eslint.io/blog/announcing-typescript-eslint-v6/) and the v7 one [here](https://typescript-eslint.io/blog/announcing-typescript-eslint-v7/). + From dba3edea550cc70ec50f4b0d0a11f2c9c7904497 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:44:38 +0000 Subject: [PATCH 06/14] add back tsx --- packages/eslint-plugin/package.json | 1 + yarn.lock | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 887ec176600e..6ba2c983379a 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -31,6 +31,7 @@ "@types/estree": "1.0.5", "@typescript-eslint/parser": "7.3.1", "@typescript-eslint/rule-tester": "7.3.1", + "tsx": "4.6.2", "typescript": "5.3.3", "vitest": "1.3.1" }, diff --git a/yarn.lock b/yarn.lock index 4399371f132f..b7d2cf70828e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8362,6 +8362,7 @@ __metadata: "@typescript-eslint/rule-tester": "npm:7.3.1" "@typescript-eslint/utils": "npm:7.3.1" eslint: "npm:8.57.0" + tsx: "npm:4.6.2" typescript: "npm:5.3.3" vitest: "npm:1.3.1" languageName: unknown From 62486d272075109fa9ec3a95d5326e54b03915d3 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:02:12 +0000 Subject: [PATCH 07/14] test project fixture patch bump --- __fixtures__/test-project/web/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__fixtures__/test-project/web/package.json b/__fixtures__/test-project/web/package.json index 62e918264c24..47370d3eb84b 100644 --- a/__fixtures__/test-project/web/package.json +++ b/__fixtures__/test-project/web/package.json @@ -24,7 +24,7 @@ "@types/react": "^18.2.55", "@types/react-dom": "^18.2.19", "autoprefixer": "^10.4.18", - "postcss": "^8.4.36", + "postcss": "^8.4.37", "postcss-loader": "^8.1.1", "prettier-plugin-tailwindcss": "^0.5.12", "tailwindcss": "^3.4.1" From ef7f97e500704e46a0a5054f903fbdbdfd89b1b2 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:20:22 +0000 Subject: [PATCH 08/14] tool to see linting config differences --- tasks/linting-diff/.gitignore | 2 + tasks/linting-diff/lintingDiff.mts | 116 +++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 tasks/linting-diff/.gitignore create mode 100644 tasks/linting-diff/lintingDiff.mts diff --git a/tasks/linting-diff/.gitignore b/tasks/linting-diff/.gitignore new file mode 100644 index 000000000000..cd47af8dea81 --- /dev/null +++ b/tasks/linting-diff/.gitignore @@ -0,0 +1,2 @@ +differences.json +log.txt diff --git a/tasks/linting-diff/lintingDiff.mts b/tasks/linting-diff/lintingDiff.mts new file mode 100644 index 000000000000..60d610de63da --- /dev/null +++ b/tasks/linting-diff/lintingDiff.mts @@ -0,0 +1,116 @@ +import { $, glob, spinner, fs, path } from 'zx' +import { cpus } from 'node:os' + +async function getConfigsForFiles(files: string[]) { + const configs = new Map() + + // Batch these in groups because running all of them in parallel is too many + // processes to spawn at once + const batchSize = cpus().length + for (let i = 0; i < files.length; i += batchSize) { + const batch = files.slice(i, i + batchSize) + process.stdout.clearLine(0) + process.stdout.cursorTo(0) + process.stdout.write(`Progress: ${Math.min(i + batchSize, files.length)}/${files.length}`) + const promises = batch.map(async (file) => { + const { stdout } = await $`yarn eslint --print-config ${file}` + configs.set(file, JSON.parse(stdout)) + }) + await Promise.all(promises) + } + process.stdout.write('\n') + + return configs +} + +async function main() { + // We need to be running commands within a redwood project + if (!process.env.RWJS_CWD) { + throw new Error('RWJS_CWD is not set') + } + $.verbose = !!process.env.VERBOSE + $.cwd = process.env.RWJS_CWD + + // Get all the files in the project + const files = await glob('**/*.*', { + ignore: ['node_modules', 'dist', 'yarn.lock'], + cwd: $.cwd, + }) + + // We support a `--sample` flag to only run on a sample of the files + if (process.argv.includes('--sample')) { + const sampleSize = cpus().length + console.log(`Running on a sample of ${sampleSize} files`) + files.sort(() => Math.random() - 0.5).splice(sampleSize) + } + + // Get the configs for the files + console.log("Analyzing existing configs...") + const fileExistingConfig = await getConfigsForFiles(files) + + // Tarsync the framework to the project to apply any changes + console.log("Tarsyncing the framework to the project...") + await spinner('yarn rwfw project:tarsync', () => $`yarn rwfw project:tarsync`) + + // Get the configs for the files again + console.log("Analyzing updated configs...") + const fileUpdatedConfig = await getConfigsForFiles(files) + + // Compare the configs + const differences = new Map() + const logs: string[] = [] + const logAndPrint = (message: string) => { + console.log(message) + logs.push(message) + } + for (const file of files) { + const existingConfig = fileExistingConfig.get(file) + const updatedConfig = fileUpdatedConfig.get(file) + differences.set(file, { existing: existingConfig, updated: updatedConfig }) + + // Check for differences in the more simplistic keys + const simpleChecks = [ + "env", + "globals", + "parser", + "plugins", + "settings", + "ignorePatterns" + ] + for (const key of simpleChecks) { + if (JSON.stringify(existingConfig[key]) !== JSON.stringify(updatedConfig[key])) { + logAndPrint(`${file} has a different ${key} config`) + } + } + + // Check the "rules" key for differences + const allRuleKeys = new Set([...Object.keys(existingConfig.rules), ...Object.keys(updatedConfig.rules)]) + for (const key of allRuleKeys) { + if (!existingConfig.rules[key]) { + logAndPrint(`${file} has a new rule for ${key}`) + } else if (!updatedConfig.rules[key]) { + logAndPrint(`${file} has a removed rule for ${key}`) + } else if (JSON.stringify(existingConfig.rules[key]) !== JSON.stringify(updatedConfig.rules[key])) { + logAndPrint(`${file} has a different rule for ${key}`) + } + } + } + + // Write the output to files for later analysis + console.log("Writing results to files...") + await fs.writeJSON(path.join(import.meta.dirname, 'differences.json'), Object.fromEntries(differences), { spaces: 2 }) + await fs.writeFile(path.join(import.meta.dirname, 'log.txt'), logs.join("\n")) + + // Output the differences + if (differences.size > 0) { + console.log(`Found ${differences.size} files with different configs`) + console.log(`Output written to: ${import.meta.dirname}"`) + } else { + console.log("No differences found") + } + + // Exit with non-zero code if there are differences + process.exitCode ||= differences.size > 0 ? 1 : 0 +} + +await main() From 62362cefccb3ace4cfdb72c17321a14ee77d1d7a Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:21:05 +0000 Subject: [PATCH 09/14] get default config to match --- packages/eslint-config/shared.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/eslint-config/shared.js b/packages/eslint-config/shared.js index e5592df82fae..454c17bbf666 100644 --- a/packages/eslint-config/shared.js +++ b/packages/eslint-config/shared.js @@ -151,6 +151,18 @@ module.exports = { parser: '@typescript-eslint/parser', extends: ['plugin:@typescript-eslint/recommended', 'prettier'], rules: { + // The following are disabled to maintain consistency with previous + // versions of redwoodjs, eslint, @typescript-eslint + 'valid-typeof': 'off', + // 'recommended' rules we alter + '@typescript-eslint/no-explicit-any': 'warn', + '@typescript-eslint/no-duplicate-enum-values': 'off', + '@typescript-eslint/no-unsafe-declaration-merging': 'off', + // Specific 'stylistic' rules we enable + '@typescript-eslint/adjacent-overload-signatures': 'error', + '@typescript-eslint/no-inferrable-types': 'error', + '@typescript-eslint/no-non-null-assertion': 'warn', + '@typescript-eslint/no-var-requires': 'off', '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/no-empty-interface': 'off', From 88148a79dabc7d1970d1a9610a1a51416d832adc Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:38:37 +0000 Subject: [PATCH 10/14] fix possibly undefined --- tasks/linting-diff/lintingDiff.mts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tasks/linting-diff/lintingDiff.mts b/tasks/linting-diff/lintingDiff.mts index 60d610de63da..6aaae6285af3 100644 --- a/tasks/linting-diff/lintingDiff.mts +++ b/tasks/linting-diff/lintingDiff.mts @@ -98,13 +98,14 @@ async function main() { // Write the output to files for later analysis console.log("Writing results to files...") - await fs.writeJSON(path.join(import.meta.dirname, 'differences.json'), Object.fromEntries(differences), { spaces: 2 }) - await fs.writeFile(path.join(import.meta.dirname, 'log.txt'), logs.join("\n")) + const __dirname = import.meta.dirname ?? '.' + await fs.writeJSON(path.join(__dirname, 'differences.json'), Object.fromEntries(differences), { spaces: 2 }) + await fs.writeFile(path.join(__dirname, 'log.txt'), logs.join("\n")) // Output the differences if (differences.size > 0) { console.log(`Found ${differences.size} files with different configs`) - console.log(`Output written to: ${import.meta.dirname}"`) + console.log(`Output written to: ${__dirname}"`) } else { console.log("No differences found") } From 3105b0f8e5dc08731bb8d2e422b3713fa84e9343 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:40:23 +0000 Subject: [PATCH 11/14] reduce config --- packages/eslint-config/shared.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/packages/eslint-config/shared.js b/packages/eslint-config/shared.js index 454c17bbf666..39f00897f5a9 100644 --- a/packages/eslint-config/shared.js +++ b/packages/eslint-config/shared.js @@ -151,34 +151,24 @@ module.exports = { parser: '@typescript-eslint/parser', extends: ['plugin:@typescript-eslint/recommended', 'prettier'], rules: { - // The following are disabled to maintain consistency with previous - // versions of redwoodjs, eslint, @typescript-eslint - 'valid-typeof': 'off', // 'recommended' rules we alter '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-duplicate-enum-values': 'off', '@typescript-eslint/no-unsafe-declaration-merging': 'off', - // Specific 'stylistic' rules we enable - '@typescript-eslint/adjacent-overload-signatures': 'error', - '@typescript-eslint/no-inferrable-types': 'error', - '@typescript-eslint/no-non-null-assertion': 'warn', - '@typescript-eslint/no-var-requires': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/no-empty-interface': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/ban-types': 'warn', - 'no-empty-function': 'off', - '@typescript-eslint/no-empty-function': 'off', - camelcase: 'off', - '@typescript-eslint/camelcase': 'off', - 'no-use-before-define': 'off', - '@typescript-eslint/no-use-before-define': 'off', - '@typescript-eslint/prefer-namespace-keyword': 'off', '@typescript-eslint/no-unused-vars': [ 'error', { varsIgnorePattern: '^_', argsIgnorePattern: '^_' }, ], + // Specific 'stylistic' rules we enable + '@typescript-eslint/adjacent-overload-signatures': 'error', + '@typescript-eslint/no-inferrable-types': 'error', + '@typescript-eslint/no-non-null-assertion': 'warn', + // Other non-grouped rules we alter + 'valid-typeof': 'off', + camelcase: 'off', + '@typescript-eslint/camelcase': 'off', }, }, { From c0dd9772e0558e12cb76f74f4ff411ad6e88d460 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 27 Mar 2024 01:01:25 +0000 Subject: [PATCH 12/14] fix lint error in vscode --- packages/structure/src/x/vscode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/structure/src/x/vscode.ts b/packages/structure/src/x/vscode.ts index e41d3214147d..6e0540d607d4 100644 --- a/packages/structure/src/x/vscode.ts +++ b/packages/structure/src/x/vscode.ts @@ -102,7 +102,7 @@ export class TreeItem2Wrapper { constructor( public item: TreeItem2, public parent?: TreeItem2Wrapper, - public indexInParent: number = 0, + public indexInParent = 0, ) {} @lazy() get keys(): string[] { if (!this.parent) { From 64d0759f9807b19914b32c0a25548e843550533d Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 27 Mar 2024 01:19:24 +0000 Subject: [PATCH 13/14] restore base rule edits --- packages/eslint-config/shared.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-config/shared.js b/packages/eslint-config/shared.js index 39f00897f5a9..ead58de5b889 100644 --- a/packages/eslint-config/shared.js +++ b/packages/eslint-config/shared.js @@ -169,6 +169,9 @@ module.exports = { 'valid-typeof': 'off', camelcase: 'off', '@typescript-eslint/camelcase': 'off', + 'no-empty-function': 'off', + 'no-use-before-define': 'off', + '@typescript-eslint/no-use-before-define': 'off', }, }, { From 5928509c29d62312cfaa994522c6614308100e13 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:42:46 +0000 Subject: [PATCH 14/14] allow the new rules --- packages/eslint-config/shared.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/eslint-config/shared.js b/packages/eslint-config/shared.js index ead58de5b889..9fff3a5b3a92 100644 --- a/packages/eslint-config/shared.js +++ b/packages/eslint-config/shared.js @@ -153,8 +153,6 @@ module.exports = { rules: { // 'recommended' rules we alter '@typescript-eslint/no-explicit-any': 'warn', - '@typescript-eslint/no-duplicate-enum-values': 'off', - '@typescript-eslint/no-unsafe-declaration-merging': 'off', '@typescript-eslint/no-var-requires': 'off', '@typescript-eslint/ban-types': 'warn', '@typescript-eslint/no-unused-vars': [