Skip to content

Commit

Permalink
feat: upgrade eslint dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonC committed Jul 26, 2023
1 parent 3bcfbf1 commit c58e32c
Show file tree
Hide file tree
Showing 34 changed files with 905 additions and 300 deletions.
668 changes: 617 additions & 51 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"audit": "tablecheck-frontend-audit",
"audit:ci": "npx tablecheck-frontend-audit --ci",
"lint": "nx affected --target=lint && prettier -c .",
"format": "nx affected --target=lint:format && prettier -w .",
"format": "nx affected --target=lint:format && prettier -w --loglevel warn .",
"test": "nx affected --target=test",
"test:watch": "nx run-many --target=test:watch",
"start": "start-storybook -p 6006",
Expand Down
28 changes: 15 additions & 13 deletions packages/audit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function updateWhitelist(rootPath: string) {
reject: false,
},
);
type ReportDependency = {
interface ReportDependency {
description: string;
coordinates: string;
reference: string;
Expand All @@ -75,7 +75,7 @@ async function updateWhitelist(rootPath: string) {
cvssVector: string;
description: string;
}[];
};
}
const report = JSON.parse(auditjsExec.stdout) as ReportDependency[];
const updatePackages: `${string}@${string}`[] = [];
interface AuditjsConfig {
Expand Down Expand Up @@ -195,9 +195,9 @@ ${this.getVectorMetrics(vector)
}

getVectorMetrics(vector: DetailedVectorObject): string[] {
let scopeKey = 'changed';
if (vector.metrics.S && vector.metrics.S.value) {
scopeKey = vector.metrics.S.value.toLowerCase();
let scopeKey: 'changed' | 'unchanged' = 'changed';
if (vector.metrics.S?.value) {
scopeKey = vector.metrics.S.value.toLowerCase() as typeof scopeKey;
}
return (
Object.keys(vector.metrics) as (keyof (typeof vector)['metrics'])[]
Expand All @@ -207,27 +207,29 @@ ${this.getVectorMetrics(vector)
}

getVectorMetricScore(
scopeKey: string,
scopeKey: 'changed' | 'unchanged',
{ fullName, value, abbr, valueAbbr }: VectorMetric,
): string {
const metricDefinition = findMetric(abbr);
const valueDefinition = metricDefinition.metrics.find(
const valueDefinition = metricDefinition?.metrics.find(
(def) => def.abbr === valueAbbr,
);
if (!valueDefinition) {
return colouredByScore(99, `${chalk.bold(`${fullName}:`)} ${value}`);
}
let score = (
valueDefinition as Extract<
(typeof metricDefinition)['metrics'][number],
const scoreDefinition = (
valueDefinition as never as Extract<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Extract<typeof metricDefinition, { metrics: any }>['metrics'][number],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
{ numerical: any }
>
).numerical;
if (typeof score === 'object') {
score = score[scopeKey] * 10;
let score;
if (typeof scoreDefinition === 'object') {
score = scoreDefinition[scopeKey] * 10;
} else {
score *= 10;
score = scoreDefinition * 10;
}
return colouredByScore(score, `${chalk.bold(`${fullName}:`)} ${value}`);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"@nx/eslint-plugin": "^16.5.0",
"@tablecheck/eslint-plugin": "^1.2.2",
"@tablecheck/frontend-utils": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.61.0",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^8.8.0",
"eslint-formatter-pretty": "^5.0.0",
"eslint-import-resolver-babel-module": "^5.3.2",
Expand All @@ -42,7 +42,7 @@
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react": "^7.33.0",
"eslint-plugin-react-hooks": "^4.6.0",
"fs-extra": "^11.1.1",
"queue-microtask": "^1.2.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let reactVersion = '17'; // set to 17 for legacy reasons or to not error if reac
const packageJsonPath = path.resolve(path.join(process.cwd(), 'package.json'));
if (fs.existsSync(packageJsonPath)) {
const pkg = fs.readJsonSync(packageJsonPath) as PackageJson;
if (pkg.dependencies && pkg.dependencies.react) {
if (pkg.dependencies?.react) {
const versionOnly = pkg.dependencies.react
.replace(/^[^0-9]+/gi, '')
.replace(/\..+$/gi, '');
Expand Down
15 changes: 13 additions & 2 deletions packages/eslint-config/src/overrides/buildBaseTypescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export function buildBaseTypescript(
parser: '@typescript-eslint/parser',
extends: [
'airbnb-typescript',
'plugin:@typescript-eslint/eslint-plugin/eslint-recommended',
'plugin:@typescript-eslint/eslint-plugin/recommended-requiring-type-checking',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:eslint-comments/recommended',
'prettier',
'plugin:react-hooks/recommended',
Expand All @@ -70,6 +70,17 @@ export function buildBaseTypescript(
...rules,
...eslintTypescriptRules,
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/prefer-nullish-coalescing': [
'error',
{
ignoreConditionalTests: true,
ignoreMixedLogicalExpressions: true,
ignorePrimitives: {
string: true,
boolean: true,
},
},
],
...forcedRules,
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/overrides/configurable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Linter } from 'eslint';
export const configurableRuleOverrides: Linter.ConfigOverride[] = [];

void import('@tablecheck/frontend-utils').then(({ userConfig }) => {
const projectTypes = userConfig?.quality?.projectType || 'default';
const projectTypes = userConfig?.quality?.projectType ?? 'default';

const projectMaps =
typeof projectTypes === 'string'
Expand Down
76 changes: 38 additions & 38 deletions packages/eslint-config/src/overrides/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@ import { mergeDeep as merge } from '../utils/merge';
import { testOverrides as testRules } from './tests';
import { typescriptOverrides } from './typescript';

const testOverrides = Object.keys(testRules.rules).reduce(
const testOverrides = Object.keys(testRules.rules ?? {}).reduce(
(result, ruleKey) => ({ ...result, [ruleKey]: 'off' }),
{},
);

export const cypressOverrides: Linter.ConfigOverride = typescriptOverrides
? merge(typescriptOverrides, {
files: ['**/cypress/**/*', '**/*.cypress.ts', '**/*.cypress.tsx'],
parserOptions: {
ecmaVersion: 9,
sourceType: 'module',
// defining both of these to prevent a bug in precommit staged linter from failing in some cases
project: ['./cypress/tsconfig.json', './tsconfig.json'],
},
env: {
'cypress/globals': true,
},
rules: {
...testOverrides,
'promise/catch-or-return': 'off',
'promise/always-return': 'off',
'import/no-import-module-exports': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/naming-convention': (
['error'] as Linter.RuleLevelAndOptions
).concat(
(
namingRules[
'@typescript-eslint/naming-convention'
] as Linter.RuleLevelAndOptions
).slice(1),
[
{
selector: 'memberLike',
format: null,
},
],
) as Linter.RuleLevelAndOptions,
},
})
: undefined;
export const cypressOverrides: Linter.ConfigOverride | undefined =
typescriptOverrides
? merge(typescriptOverrides, {
files: ['**/cypress/**/*', '**/*.cypress.ts', '**/*.cypress.tsx'],
parserOptions: {
ecmaVersion: 9,
sourceType: 'module',
project: './cypress/tsconfig.json',
},
env: {
'cypress/globals': true,
},
rules: {
...testOverrides,
'promise/catch-or-return': 'off',
'promise/always-return': 'off',
'import/no-import-module-exports': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/naming-convention': (
['error'] as Linter.RuleLevelAndOptions
).concat(
(
namingRules[
'@typescript-eslint/naming-convention'
] as Linter.RuleLevelAndOptions
).slice(1),
[
{
selector: 'memberLike',
format: null,
},
],
) as Linter.RuleLevelAndOptions,
},
})
: undefined;
1 change: 0 additions & 1 deletion packages/eslint-config/src/rules/namingConvention.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Linter } from 'eslint';
import type {} from '@typescript-eslint/eslint-plugin';

export const namingRules: Linter.RulesRecord = {
camelcase: 'off',
Expand Down
28 changes: 14 additions & 14 deletions packages/eslint-config/src/utils/merge.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* Simple object check.
* @param item
* @returns {boolean}
*/
function isObject(item) {
function assertsIsObject(
item: unknown,
): asserts item is Record<string, unknown> {}
function isObject(item: unknown) {
return item && typeof item === 'object' && !Array.isArray(item);
}

Expand All @@ -15,18 +13,20 @@ function isObject(item) {
export function mergeDeep<T>(targetArg: T, ...sources: T[]): T {
if (!sources.length) return targetArg;
const target = { ...targetArg };
for (let i = 0; i < sources.length; i += 1) {
const source = sources[i];
for (const source of sources) {
if (isObject(target) && isObject(source)) {
const keys = Object.keys(source);
for (let k = 0; k < keys.length; k += 1) {
const key = keys[k];
assertsIsObject(target);
assertsIsObject(source);
const keys = Object.keys(source as Record<string, unknown>);
for (const key of keys) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} } as T);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
target[key] = mergeDeep(target[key], source[key]);

(target as never as Record<string, unknown>)[key] = mergeDeep(
target[key],
source[key],
);
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Object.assign(target, { [key]: source[key] } as T);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ESLintUtils } from '@typescript-eslint/utils';
import { RuleTester } from '@typescript-eslint/rule-tester';

import {
consistentReactImport as rule,
messageId,
} from '../src/consistentReactImport';

const ruleTester = new ESLintUtils.RuleTester({
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.test.json',
Expand Down
5 changes: 3 additions & 2 deletions packages/eslint-plugin/__tests__/forbiddenImports.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { TSESLint, ESLintUtils } from '@typescript-eslint/utils';
import { RuleTester } from '@typescript-eslint/rule-tester';
import { TSESLint } from '@typescript-eslint/utils';

import { forbiddenImports as rule, messageId } from '../src/forbiddenImports';

const ruleTester = new ESLintUtils.RuleTester({
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.test.json',
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/__tests__/shortestImport.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ESLintUtils } from '@typescript-eslint/utils';
import { RuleTester } from '@typescript-eslint/rule-tester';

import { shortestImport as rule, messageId } from '../src/shortestImport';

const ruleTester = new ESLintUtils.RuleTester({
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.test.json',
Expand Down
9 changes: 5 additions & 4 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
"eslint": "^8"
},
"devDependencies": {
"@typescript-eslint/parser": "^5.61.0",
"@typescript-eslint/types": "^5.61.0",
"@typescript-eslint/typescript-estree": "^5.61.0",
"@typescript-eslint/utils": "^5.61.0",
"@typescript-eslint/parser": "^6.2.0",
"@typescript-eslint/rule-tester": "^6.2.0",
"@typescript-eslint/types": "^6.2.0",
"@typescript-eslint/typescript-estree": "^6.2.0",
"@typescript-eslint/utils": "^6.2.0",
"fs-extra": "11.1.1",
"type-fest": "4.0.0",
"typescript": "5.1.6",
Expand Down
Loading

0 comments on commit c58e32c

Please sign in to comment.