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: configure lint rule array-type #1793

Merged
merged 6 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module.exports = defineConfig({
eqeqeq: ['error', 'always', { null: 'ignore' }],
'prefer-template': 'error',

'@typescript-eslint/array-type': [
'error',
{ default: 'array-simple', readonly: 'generic' },
],
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
Expand Down
4 changes: 2 additions & 2 deletions scripts/apidoc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolve } from 'node:path';
// Types

export type Page = { text: string; link: string };
export type PageIndex = Array<Page>;
export type PageIndex = Page[];

// Paths

Expand All @@ -14,7 +14,7 @@ export const pathOutputDir = resolve(pathDocsDir, 'api');
// Functions

export function mapByName<T extends { name: string }, V>(
input: Array<T>,
input: T[],
valueExtractor: (item: T) => V
): Record<string, V> {
return input.reduce(
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/science.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export type ScienceDefinitions = LocaleEntry<{
/**
* Some science units.
*/
unit: readonly Unit[];
unit: ReadonlyArray<Unit>;

/**
* Some periodic table element information.
*/
chemicalElement: readonly ChemicalElement[];
chemicalElement: ReadonlyArray<ChemicalElement>;
}>;
4 changes: 2 additions & 2 deletions src/modules/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class HelpersModule {
* @since 2.0.1
*/
shuffle<T>(
list: readonly T[],
list: ReadonlyArray<T>,
options?: {
/**
* Whether to shuffle the array in place or return a new array.
Expand Down Expand Up @@ -351,7 +351,7 @@ export class HelpersModule {
*
* @since 6.0.0
*/
uniqueArray<T>(source: readonly T[] | (() => T), length: number): T[] {
uniqueArray<T>(source: ReadonlyArray<T> | (() => T), length: number): T[] {
if (Array.isArray(source)) {
const set = new Set<T>(source);
const array = Array.from(set);
Expand Down
6 changes: 2 additions & 4 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class InternetModule {
const {
types = Object.keys(
this.faker.definitions.internet.http_status_code
) as Array<HTTPStatusCodeType>,
) as HTTPStatusCodeType[],
} = options;
const httpStatusCodeType = this.faker.helpers.arrayElement(types);
return this.faker.helpers.arrayElement(
Expand Down Expand Up @@ -627,9 +627,7 @@ export class InternetModule {
} = {}
): string {
const {
types = Object.keys(
this.faker.definitions.internet.emoji
) as Array<EmojiType>,
types = Object.keys(this.faker.definitions.internet.emoji) as EmojiType[],
} = options;
const emojiType = this.faker.helpers.arrayElement(types);
return this.faker.helpers.arrayElement(
Expand Down
6 changes: 3 additions & 3 deletions src/modules/random/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class RandomModule {
*
* @default []
*/
bannedChars?: readonly LiteralUnion<AlphaChar>[] | string;
bannedChars?: ReadonlyArray<LiteralUnion<AlphaChar>> | string;
} = {}
): string {
deprecated({
Expand Down Expand Up @@ -274,7 +274,7 @@ export class RandomModule {
*
* @default []
*/
bannedChars?: readonly LiteralUnion<AlphaNumericChar>[] | string;
bannedChars?: ReadonlyArray<LiteralUnion<AlphaNumericChar>> | string;
} = {}
): string {
deprecated({
Expand Down Expand Up @@ -325,7 +325,7 @@ export class RandomModule {
*
* @default []
*/
bannedDigits?: readonly LiteralUnion<NumericChar>[] | string;
bannedDigits?: ReadonlyArray<LiteralUnion<NumericChar>> | string;
} = {}
): string {
deprecated({
Expand Down
16 changes: 10 additions & 6 deletions src/modules/string/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import type { LiteralUnion } from '../../utils/types';

export type Casing = 'upper' | 'lower' | 'mixed';

const UPPER_CHARS: readonly string[] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
const LOWER_CHARS: readonly string[] = 'abcdefghijklmnopqrstuvwxyz'.split('');
const DIGIT_CHARS: readonly string[] = '0123456789'.split('');
const UPPER_CHARS: ReadonlyArray<string> = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(
''
);
const LOWER_CHARS: ReadonlyArray<string> = 'abcdefghijklmnopqrstuvwxyz'.split(
''
);
const DIGIT_CHARS: ReadonlyArray<string> = '0123456789'.split('');
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved

export type LowerAlphaChar =
| 'a'
Expand Down Expand Up @@ -200,7 +204,7 @@ export class StringModule {
*
* @default []
*/
exclude?: readonly LiteralUnion<AlphaChar>[] | string;
exclude?: ReadonlyArray<LiteralUnion<AlphaChar>> | string;
} = {}
): string {
if (typeof options === 'number') {
Expand Down Expand Up @@ -290,7 +294,7 @@ export class StringModule {
*
* @default []
*/
exclude?: readonly LiteralUnion<AlphaNumericChar>[] | string;
exclude?: ReadonlyArray<LiteralUnion<AlphaNumericChar>> | string;
} = {}
): string {
if (typeof options === 'number') {
Expand Down Expand Up @@ -567,7 +571,7 @@ export class StringModule {
*
* @default []
*/
exclude?: readonly LiteralUnion<NumericChar>[] | string;
exclude?: ReadonlyArray<LiteralUnion<NumericChar>> | string;
} = {}
): string {
if (typeof options === 'number') {
Expand Down
2 changes: 1 addition & 1 deletion test/faker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('faker', () => {
});

it('should not log anything on startup', () => {
const spies: Array<SpyInstance> = Object.keys(console)
const spies: SpyInstance[] = Object.keys(console)
.filter((key) => typeof console[key] === 'function')
.map((methodName) =>
vi.spyOn(console, methodName as keyof typeof console)
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/apidoc/examplesAndDeprecations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ beforeAll(initMarkdownRenderer);
describe('examples and deprecations', () => {
const modules = loadProjectModules();

const consoleSpies: Array<SpyInstance> = Object.keys(console)
const consoleSpies: SpyInstance[] = Object.keys(console)
.filter((key) => typeof console[key] === 'function')
.map((methodName) => vi.spyOn(console, methodName as keyof typeof console));

Expand Down
8 changes: 4 additions & 4 deletions test/scripts/apidoc/signature.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ export class SignatureTest {
literalUnionParamMethod(
value: LiteralUnion<'a' | 'b'>,
namedValue: LiteralUnion<AB>,
array: readonly LiteralUnion<'a' | 'b'>[],
namedArray: readonly LiteralUnion<AB>[],
mixed: LiteralUnion<'a' | 'b'> | readonly LiteralUnion<'a' | 'b'>[],
namedMixed: readonly LiteralUnion<AB>[] | LiteralUnion<AB>
array: ReadonlyArray<LiteralUnion<'a' | 'b'>>,
namedArray: ReadonlyArray<LiteralUnion<AB>>,
mixed: LiteralUnion<'a' | 'b'> | ReadonlyArray<LiteralUnion<'a' | 'b'>>,
namedMixed: ReadonlyArray<LiteralUnion<AB>> | LiteralUnion<AB>
): string {
return (
value +
Expand Down