From f2610523311f3ee1dfaf6707617ec59b2c4a8f0d Mon Sep 17 00:00:00 2001 From: Bauke Date: Tue, 18 Oct 2022 22:21:55 +0200 Subject: [PATCH] Don't use type as a variable name as it is a TS keyword. --- source/redirect/base.ts | 10 +++++----- source/redirect/exports.ts | 6 +++--- source/redirect/hostname.ts | 2 +- source/redirect/simple.ts | 2 +- tests/redirect.test.ts | 8 ++++---- tests/snapshots/tests/redirect.test.ts.md | 4 ++-- tests/snapshots/tests/redirect.test.ts.snap | Bin 513 -> 516 bytes 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/source/redirect/base.ts b/source/redirect/base.ts index 0046116..ec03ac3 100644 --- a/source/redirect/base.ts +++ b/source/redirect/base.ts @@ -4,12 +4,12 @@ export const redirectTypes = ['hostname', 'simple'] as const; export type MatcherType = typeof matcherTypes[number]; export type RedirectType = typeof redirectTypes[number]; -export function narrowMatchType(type: string): type is MatcherType { - return matcherTypes.includes(type as MatcherType); +export function narrowMatchType(value: string): value is MatcherType { + return matcherTypes.includes(value as MatcherType); } -export function narrowRedirectType(type: string): type is RedirectType { - return redirectTypes.includes(type as RedirectType); +export function narrowRedirectType(value: string): value is RedirectType { + return redirectTypes.includes(value as RedirectType); } export type Matcher = { @@ -18,7 +18,7 @@ export type Matcher = { }; export type RedirectParameters = { - type: RedirectType; + redirectType: RedirectType; }; export abstract class Redirect

{ diff --git a/source/redirect/exports.ts b/source/redirect/exports.ts index 092ddb9..57a7d8a 100644 --- a/source/redirect/exports.ts +++ b/source/redirect/exports.ts @@ -10,13 +10,13 @@ export type Redirects = HostnameRedirect | SimpleRedirect; export function parseRedirect

( parameters: P, ): Redirects | undefined { - const type = parameters?.type; + const redirectType = parameters?.redirectType; - if (type === 'hostname') { + if (redirectType === 'hostname') { return new HostnameRedirect(parameters); } - if (type === 'simple') { + if (redirectType === 'simple') { return new SimpleRedirect(parameters); } } diff --git a/source/redirect/hostname.ts b/source/redirect/hostname.ts index 6eaf570..809075d 100644 --- a/source/redirect/hostname.ts +++ b/source/redirect/hostname.ts @@ -2,7 +2,7 @@ import {Redirect} from './base.js'; export type HostnameParameters = { hostname: string; - type: 'hostname'; + redirectType: 'hostname'; }; export class HostnameRedirect extends Redirect { diff --git a/source/redirect/simple.ts b/source/redirect/simple.ts index e739a1a..ffb76d6 100644 --- a/source/redirect/simple.ts +++ b/source/redirect/simple.ts @@ -2,7 +2,7 @@ import {Redirect} from './base.js'; export type SimpleParameters = { target: string; - type: 'simple'; + redirectType: 'simple'; }; export class SimpleRedirect extends Redirect { diff --git a/tests/redirect.test.ts b/tests/redirect.test.ts index eeaa61b..4867b3e 100644 --- a/tests/redirect.test.ts +++ b/tests/redirect.test.ts @@ -19,14 +19,14 @@ const hostnameParameters: HostnameRedirect['parameters'] = { hostname: 'example.org', matcherType: 'hostname', toMatch: 'example.com', - type: 'hostname', + redirectType: 'hostname', }; const simpleParameters: SimpleRedirect['parameters'] = { matcherType: 'hostname', target: 'https://example.org/simple', toMatch: 'example.com', - type: 'simple', + redirectType: 'simple', }; test('parseRedirect', (t) => { @@ -101,6 +101,6 @@ test('Redirect.isMatch', (t) => { test('Narrow match & redirect types', (t) => { t.false(narrowMatchType('invalid')); t.false(narrowRedirectType('invalid')); - t.true(matcherTypes.every((type) => narrowMatchType(type))); - t.true(redirectTypes.every((type) => narrowRedirectType(type))); + t.true(matcherTypes.every((value) => narrowMatchType(value))); + t.true(redirectTypes.every((value) => narrowRedirectType(value))); }); diff --git a/tests/snapshots/tests/redirect.test.ts.md b/tests/snapshots/tests/redirect.test.ts.md index 80edd98..692af26 100644 --- a/tests/snapshots/tests/redirect.test.ts.md +++ b/tests/snapshots/tests/redirect.test.ts.md @@ -12,8 +12,8 @@ Generated by [AVA](https://avajs.dev). parameters: { hostname: 'example.org', matcherType: 'hostname', + redirectType: 'hostname', toMatch: 'example.com', - type: 'hostname', }, } @@ -22,9 +22,9 @@ Generated by [AVA](https://avajs.dev). SimpleRedirect { parameters: { matcherType: 'hostname', + redirectType: 'simple', target: 'https://example.org/simple', toMatch: 'example.com', - type: 'simple', }, } diff --git a/tests/snapshots/tests/redirect.test.ts.snap b/tests/snapshots/tests/redirect.test.ts.snap index 50f6b83982e344164c8b8bc71fc39d59a04567b1..904e77a06966a9ffce62c72bb4818ceb4c92e7a2 100644 GIT binary patch literal 516 zcmV+f0{i_zRzVbrKoEvK2}ux-kcbqB3PeLict{8#9z_}o5E4)Xx=pgg z20M0k2LvUE4pAUZ08}*G0C52hg2W{lV=oG8hk!_drP12EGr#xyXKwc^wp%@v=XV?} zw7KIkA^8@sS%O#5k`3lb(?vS3)flo}C?$=I;Xlv|i3M6$D25@OhuoSgvB8|rYJfbX zH!BD9n#<)37&HJ3$O7z9Ndb}ur1H>5KcpJuLi&=aD>}QOc&2!x7=cheRDwiAw8wxU z%1J26UNgLi+UVye%<*hK<%+tN+wU-}nq2IhdOT9E?g??bT@qI$Q`P#!);dK z_HoH(QjY1aDWlh0jh?43UYA{=E4C|0|Wv!-9U5nS$Rw2%sfK*JknXB?k9K%@`7$##FiXKCA!er81Z60xP zx{O?6XRwHr4;CjC!p^jVefVDu`(~B{5^q)?&Vb`Fj-%NHj*)gv>juo62J;S3JPDI* G1^@t%aOj2r literal 513 zcmV+c0{;C$RzVn&|ADqn(HU5qMoDw5JIw z+b$72OCO5}00000000BclD$sDFc8OcEwmMg(yA3gOdu8}%7=syp92gm2niSpo7F=Pj@oHWvg|3L;4i!`oL6d;v{+?Fe`!JO~Y0C`C5 zRF3I4m&+M2WB?eD1vsQ5MMxUZpN9dukj@|%(wFSNp}jkbSBiIv5eVf&B}ha>`wSSS zoP?6hnBhaz!XQ6qj%V{}SJbuKL5E@02?3R03^R6X)K6{rPHW8m~p+rma~s`<2tH2YOhi}GVzDUx$E`u%Pjnq$#2B=m-K zg;lp2%vK8p-G?aEfO;0Msik6^djYAK>CjK*w>XB29xzPBFqAxo=A_A_x!yeGqP2=# z;@@BqDIY9ODukWw1pD;A3ieC82PEE{-kbr)a~wyr2OOiFiq;F5c@5?h45!g+Tm}FD Do*C|s