aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinigami <[email protected]>2023-02-01 14:04:18 +0100
committerGitHub <[email protected]>2023-02-01 14:04:18 +0100
commit5b705d4b047640e91b690566d6e0fdbae17bb842 (patch)
treea179a77cca1b72e2c730607def2786a5531b531f
parentbe77179faf097383763eaa6414cf7b6a1a8b131a (diff)
downloadfaker-5b705d4b047640e91b690566d6e0fdbae17bb842.tar.xz
faker-5b705d4b047640e91b690566d6e0fdbae17bb842.zip
infra: configure lint rule array-type (#1793)
-rw-r--r--.eslintrc.js4
-rw-r--r--scripts/apidoc/utils.ts4
-rw-r--r--src/definitions/science.ts4
-rw-r--r--src/modules/helpers/index.ts4
-rw-r--r--src/modules/internet/index.ts6
-rw-r--r--src/modules/random/index.ts6
-rw-r--r--src/modules/string/index.ts16
-rw-r--r--test/faker.spec.ts2
-rw-r--r--test/scripts/apidoc/examplesAndDeprecations.spec.ts2
-rw-r--r--test/scripts/apidoc/signature.example.ts8
10 files changed, 31 insertions, 25 deletions
diff --git a/.eslintrc.js b/.eslintrc.js
index 6b295a6c..8ab899ae 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -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',
diff --git a/scripts/apidoc/utils.ts b/scripts/apidoc/utils.ts
index 7939adb1..f480c0b1 100644
--- a/scripts/apidoc/utils.ts
+++ b/scripts/apidoc/utils.ts
@@ -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
@@ -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(
diff --git a/src/definitions/science.ts b/src/definitions/science.ts
index 29e4f59e..b63767f6 100644
--- a/src/definitions/science.ts
+++ b/src/definitions/science.ts
@@ -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>;
}>;
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts
index a4ecdf71..c22a3612 100644
--- a/src/modules/helpers/index.ts
+++ b/src/modules/helpers/index.ts
@@ -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.
@@ -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);
diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts
index f07ab973..3287e404 100644
--- a/src/modules/internet/index.ts
+++ b/src/modules/internet/index.ts
@@ -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(
@@ -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(
diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts
index d558e24b..4936fe80 100644
--- a/src/modules/random/index.ts
+++ b/src/modules/random/index.ts
@@ -221,7 +221,7 @@ export class RandomModule {
*
* @default []
*/
- bannedChars?: readonly LiteralUnion<AlphaChar>[] | string;
+ bannedChars?: ReadonlyArray<LiteralUnion<AlphaChar>> | string;
} = {}
): string {
deprecated({
@@ -274,7 +274,7 @@ export class RandomModule {
*
* @default []
*/
- bannedChars?: readonly LiteralUnion<AlphaNumericChar>[] | string;
+ bannedChars?: ReadonlyArray<LiteralUnion<AlphaNumericChar>> | string;
} = {}
): string {
deprecated({
@@ -325,7 +325,7 @@ export class RandomModule {
*
* @default []
*/
- bannedDigits?: readonly LiteralUnion<NumericChar>[] | string;
+ bannedDigits?: ReadonlyArray<LiteralUnion<NumericChar>> | string;
} = {}
): string {
deprecated({
diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts
index 8f62788a..6240184c 100644
--- a/src/modules/string/index.ts
+++ b/src/modules/string/index.ts
@@ -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('');
export type LowerAlphaChar =
| 'a'
@@ -200,7 +204,7 @@ export class StringModule {
*
* @default []
*/
- exclude?: readonly LiteralUnion<AlphaChar>[] | string;
+ exclude?: ReadonlyArray<LiteralUnion<AlphaChar>> | string;
} = {}
): string {
if (typeof options === 'number') {
@@ -290,7 +294,7 @@ export class StringModule {
*
* @default []
*/
- exclude?: readonly LiteralUnion<AlphaNumericChar>[] | string;
+ exclude?: ReadonlyArray<LiteralUnion<AlphaNumericChar>> | string;
} = {}
): string {
if (typeof options === 'number') {
@@ -567,7 +571,7 @@ export class StringModule {
*
* @default []
*/
- exclude?: readonly LiteralUnion<NumericChar>[] | string;
+ exclude?: ReadonlyArray<LiteralUnion<NumericChar>> | string;
} = {}
): string {
if (typeof options === 'number') {
diff --git a/test/faker.spec.ts b/test/faker.spec.ts
index 75d515f7..12121b9d 100644
--- a/test/faker.spec.ts
+++ b/test/faker.spec.ts
@@ -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)
diff --git a/test/scripts/apidoc/examplesAndDeprecations.spec.ts b/test/scripts/apidoc/examplesAndDeprecations.spec.ts
index ac73244c..8d6124e0 100644
--- a/test/scripts/apidoc/examplesAndDeprecations.spec.ts
+++ b/test/scripts/apidoc/examplesAndDeprecations.spec.ts
@@ -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));
diff --git a/test/scripts/apidoc/signature.example.ts b/test/scripts/apidoc/signature.example.ts
index e9925626..26c35923 100644
--- a/test/scripts/apidoc/signature.example.ts
+++ b/test/scripts/apidoc/signature.example.ts
@@ -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 +