Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra(typescript-eslint): strict-type-checked #2467

Merged
merged 13 commits into from Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc.js
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
Expand Up @@ -821,7 +821,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
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/filterWordListByLength.ts
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
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
@@ -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
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