Skip to content

Commit

Permalink
infra(typescript-eslint): strict-type-checked (#2467)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Nov 4, 2023
1 parent 22003bb commit 358572d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = defineConfig({
reportUnusedDisableDirectives: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/strict-type-checked',
'plugin:prettier/recommended',
'plugin:deprecation/recommended',
'plugin:jsdoc/recommended-typescript-error',
Expand Down Expand Up @@ -91,6 +91,7 @@ module.exports = defineConfig({
'error',
{ ignoreParameters: true },
],
'@typescript-eslint/no-unnecessary-condition': 'off', // requires `strictNullChecks` to be enabled
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
Expand All @@ -104,6 +105,11 @@ module.exports = defineConfig({
{ allowNumber: true, allowBoolean: true },
],
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/unified-signatures': 'off', // incompatible with our api docs generation

// TODO @ST-DDT 2023-10-10: The following rules currently conflict with our code.
// Each rule should be checked whether it should be enabled/configured and the problems fixed, or stay disabled permanently.
'@typescript-eslint/no-confusing-void-expression': 'off',

'jsdoc/require-jsdoc': 'off', // Enabled only for src/**/*.ts
'jsdoc/require-returns': 'off',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ export class FinanceModule {
const normalizedIssuer = issuer.toLowerCase();
if (normalizedIssuer in localeFormat) {
format = this.faker.helpers.arrayElement(localeFormat[normalizedIssuer]);
} else if (/#/.test(issuer)) {
} else if (issuer.includes('#')) {
// The user chose an optional scheme
format = issuer;
} else {
Expand Down
7 changes: 3 additions & 4 deletions src/modules/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,16 @@ export class ImageModule {
length: { min: 5, max: 10 },
})}/${width}/${height}`;

const hasValidGrayscale = grayscale === true;
const hasValidBlur = typeof blur === 'number' && blur >= 1 && blur <= 10;

if (hasValidGrayscale || hasValidBlur) {
if (grayscale || hasValidBlur) {
url += '?';

if (hasValidGrayscale) {
if (grayscale) {
url += `grayscale`;
}

if (hasValidGrayscale && hasValidBlur) {
if (grayscale && hasValidBlur) {
url += '&';
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/word/filter-word-list-by-length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const STRATEGIES = {
wordList: ReadonlyArray<string>,
length: { min: number; max: number }
): string[] => {
const wordsByLength = wordList.reduce(
const wordsByLength = wordList.reduce<Record<number, string[]>>(
(data, word) => {
(data[word.length] = data[word.length] ?? []).push(word);
return data;
},
{} as Record<number, string[]>
{}
);

const lengths = Object.keys(wordsByLength).map(Number);
Expand Down
2 changes: 2 additions & 0 deletions test/modules/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('helpers', () => {
enum MixedFoo {
Foo = 0,
Bar = 1,
// eslint-disable-next-line @typescript-eslint/no-mixed-enums
FooName = 'Foo',
BarName = 'Bar',
}
Expand Down Expand Up @@ -256,6 +257,7 @@ describe('helpers', () => {
enum FooMixedEnum {
Foo = 0,
Bar = 1,
// eslint-disable-next-line @typescript-eslint/no-mixed-enums
StrFoo = 'FOO',
StrBar = 'BAR',
}
Expand Down
2 changes: 2 additions & 0 deletions test/scripts/apidoc/module.example.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-extraneous-class -- required for tests */

/**
* A simple module without anything special.
*/
Expand Down
8 changes: 4 additions & 4 deletions test/scripts/apidoc/verify-jsdoc-tags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ describe('verify JSDoc tags', () => {
}

const allowedReferences = new Set(
Object.values(modules).reduce((acc, [module, methods]) => {
Object.values(modules).reduce<string[]>((acc, [module, methods]) => {
const moduleFieldName = extractModuleFieldName(module);
return [
...acc,
...Object.keys(methods).map(
(methodName) => `faker.${moduleFieldName}.${methodName}`
),
];
}, [] as string[])
}, [])
);
const allowedLinks = new Set(
Object.values(modules).reduce((acc, [module, methods]) => {
Object.values(modules).reduce<string[]>((acc, [module, methods]) => {
const moduleFieldName = extractModuleFieldName(module);
return [
...acc,
Expand All @@ -68,7 +68,7 @@ describe('verify JSDoc tags', () => {
`/api/${moduleFieldName}.html#${methodName.toLowerCase()}`
),
];
}, [] as string[])
}, [])
);

function assertDescription(description: string, isHtml: boolean): void {
Expand Down

0 comments on commit 358572d

Please sign in to comment.