Skip to content

Commit defb53e

Browse files
committed
Fixed eslint for referrer-parser
1 parent 44fbd23 commit defb53e

8 files changed

Lines changed: 49 additions & 146 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"scripts": {
1616
"dev": "echo \"Implement me!\"",
1717
"setup": "yarn install",
18-
"test": "lerna run test",
18+
"test": "lerna run lint && lerna run test",
1919
"lint": "lerna run lint",
2020
"preship": "yarn test",
2121
"ship": "lerna version --git-remote ${GHOST_UPSTREAM:-origin}",

packages/referrer-parser/lib/ReferrerParser.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class ReferrerParser {
4040

4141
/**
4242
* Creates a new referrer parser instance
43-
*
43+
*
4444
* @param options - Configuration options
4545
*/
4646
constructor(options: ParserOptions = {}) {
@@ -50,7 +50,7 @@ export class ReferrerParser {
5050

5151
/**
5252
* Parse a referrer URL to get source, medium and hostname
53-
*
53+
*
5454
* @param referrerUrlStr - URL of the referrer
5555
* @param referrerSource - Source of the referrer
5656
* @param referrerMedium - Medium of the referrer
@@ -89,9 +89,9 @@ export class ReferrerParser {
8989
// If referrer source is available from parameters
9090
if (referrerSource) {
9191
const urlData = this.getDataFromUrl(referrerUrl);
92-
const knownSource = Object.values(knownReferrers as Record<string, ReferrerSourceData>).find(referrer =>
92+
const knownSource = Object.values(knownReferrers as Record<string, ReferrerSourceData>).find(referrer =>
9393
referrer.source.toLowerCase() === referrerSource.toLowerCase());
94-
94+
9595
return {
9696
referrerSource: knownSource?.source || referrerSource,
9797
referrerMedium: knownSource?.medium || referrerMedium || urlData?.medium || null,
@@ -111,7 +111,7 @@ export class ReferrerParser {
111111
referrerUrl: referrerUrl?.hostname ?? null
112112
};
113113
}
114-
114+
115115
// Use the hostname as a source
116116
return {
117117
referrerSource: referrerUrl?.hostname ?? null,
@@ -129,7 +129,7 @@ export class ReferrerParser {
129129

130130
/**
131131
* Fetches referrer data from known external URLs
132-
*
132+
*
133133
* @param url - The URL to match against known referrers
134134
* @returns Matched referrer data or null if not found
135135
*/
@@ -153,25 +153,25 @@ export class ReferrerParser {
153153

154154
/**
155155
* Return URL object for provided URL string
156-
*
156+
*
157157
* @param url - URL string to parse
158158
* @returns Parsed URL object or null if invalid
159159
*/
160160
getUrlFromStr(url: string): URL | null {
161161
if (!url) {
162162
return null;
163163
}
164-
164+
165165
try {
166166
return new URL(url);
167-
} catch (e) {
167+
} catch {
168168
return null;
169169
}
170170
}
171171

172172
/**
173173
* Determine whether the provided URL is a link to the site
174-
*
174+
*
175175
* @param url - URL to check
176176
* @returns True if the URL belongs to the configured site
177177
*/
@@ -189,35 +189,35 @@ export class ReferrerParser {
189189
// Handle subdomain variations (www.example.com vs example.com)
190190
const siteHostname = this.siteUrl.hostname;
191191
const urlHostname = url.hostname;
192-
192+
193193
// Check for exact match first
194194
if (siteHostname === urlHostname) {
195195
if (url.pathname.startsWith(this.siteUrl.pathname)) {
196196
return true;
197197
}
198198
return false;
199199
}
200-
200+
201201
// Check for www subdomain variations
202202
const siteWithoutWww = siteHostname.replace(/^www\./, '');
203203
const urlWithoutWww = urlHostname.replace(/^www\./, '');
204-
204+
205205
if (siteWithoutWww === urlWithoutWww) {
206206
if (url.pathname.startsWith(this.siteUrl.pathname)) {
207207
return true;
208208
}
209209
return false;
210210
}
211-
211+
212212
return false;
213-
} catch (e) {
213+
} catch {
214214
return false;
215215
}
216216
}
217217

218218
/**
219219
* Determine whether referrer is a Ghost newsletter
220-
*
220+
*
221221
* @param deps - Input parameters
222222
* @returns True if the referrer is a Ghost newsletter
223223
*/
@@ -231,7 +231,7 @@ export class ReferrerParser {
231231

232232
/**
233233
* Determine whether referrer is a Ghost.org URL
234-
*
234+
*
235235
* @param referrerUrl - The referrer URL to check
236236
* @returns True if the referrer is from Ghost.org
237237
*/
@@ -244,7 +244,7 @@ export class ReferrerParser {
244244

245245
/**
246246
* Determine whether referrer is Ghost Explore
247-
*
247+
*
248248
* @param deps - Input parameters
249249
* @returns True if the referrer is from Ghost Explore
250250
*/
@@ -270,4 +270,4 @@ export class ReferrerParser {
270270

271271
return false;
272272
}
273-
}
273+
}

packages/referrer-parser/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"@typescript-eslint/eslint-plugin": "8.59.2",
5454
"@typescript-eslint/parser": "8.59.2",
5555
"@vitest/coverage-v8": "4.1.5",
56-
"eslint": "10.3.0",
5756
"should": "13.2.3",
5857
"sinon": "22.0.0",
5958
"typescript": "5.9.3",
File renamed without changes.

packages/referrer-parser/test/ReferrerParser.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import should from 'should';
22
import sinon from 'sinon';
3-
import { describe, it, beforeEach, afterEach } from 'vitest';
4-
import { ReferrerParser, ReferrerData, ParserOptions } from '../lib/ReferrerParser';
3+
import {describe, it, beforeEach, afterEach} from 'vitest';
4+
import {ReferrerParser} from '../lib/ReferrerParser';
55

66
// Helper function to safely assert on properties that might be null
77
function assertPropertyEquals(obj: any, property: string, expectedValue: any) {
88
should.exist(obj);
9-
9+
1010
if (expectedValue === null) {
1111
should.equal(obj[property], null);
1212
} else {
@@ -94,7 +94,7 @@ describe('ReferrerParser', () => {
9494
pathname: '/test',
9595
search: '?utm_source=ghost-explore'
9696
} as URL);
97-
97+
9898
// Stub isGhostExploreRef to return true
9999
sandbox.stub(parser, 'isGhostExploreRef').returns(true);
100100

@@ -108,7 +108,7 @@ describe('ReferrerParser', () => {
108108
it('detects Ghost Explore from admin URL', () => {
109109
// Create a controlled test environment
110110
sandbox.stub(parser, 'isGhostExploreRef').returns(true);
111-
111+
112112
const result = parser.parse('https://admin.example.com/ghost/#/dashboard');
113113
should.exist(result);
114114
assertPropertyEquals(result, 'referrerSource', 'Ghost Explore');
@@ -119,7 +119,7 @@ describe('ReferrerParser', () => {
119119
it('detects Ghost Explore from ghost.org/explore', () => {
120120
// Create a controlled test environment
121121
sandbox.stub(parser, 'isGhostExploreRef').returns(true);
122-
122+
123123
const result = parser.parse('https://ghost.org/explore/test');
124124
should.exist(result);
125125
assertPropertyEquals(result, 'referrerSource', 'Ghost Explore');
@@ -131,7 +131,7 @@ describe('ReferrerParser', () => {
131131
// Create a controlled test environment
132132
sandbox.stub(parser, 'isGhostOrgUrl').returns(true);
133133
sandbox.stub(parser, 'isGhostExploreRef').returns(false);
134-
134+
135135
const result = parser.parse('https://ghost.org/pricing/');
136136
should.exist(result);
137137
assertPropertyEquals(result, 'referrerSource', 'Ghost.org');
@@ -147,7 +147,7 @@ describe('ReferrerParser', () => {
147147
sandbox.stub(parser, 'isGhostOrgUrl').returns(false);
148148
sandbox.stub(parser, 'isGhostExploreRef').returns(false);
149149
sandbox.stub(parser, 'isGhostNewsletter').returns(true);
150-
150+
151151
const result = parser.parse('https://test.com/test?utm_source=test-newsletter');
152152
should.exist(result);
153153
// Now only the -newsletter suffix is replaced with a space
@@ -161,11 +161,11 @@ describe('ReferrerParser', () => {
161161
sandbox.stub(parser, 'isGhostOrgUrl').returns(false);
162162
sandbox.stub(parser, 'isGhostExploreRef').returns(false);
163163
sandbox.stub(parser, 'isGhostNewsletter').returns(false);
164-
164+
165165
// Mock the URL and URLSearchParams
166166
const url = new URL('https://test.com/test?utm_source=twitter&utm_medium=social');
167167
sandbox.stub(parser, 'getUrlFromStr').returns(url);
168-
168+
169169
const result = parser.parse('https://test.com/test?utm_source=twitter&utm_medium=social', 'twitter');
170170
should.exist(result);
171171
assertPropertyEquals(result, 'referrerSource', 'Twitter');
@@ -179,13 +179,13 @@ describe('ReferrerParser', () => {
179179
sandbox.stub(parser, 'isGhostExploreRef').returns(false);
180180
sandbox.stub(parser, 'isGhostNewsletter').returns(false);
181181
sandbox.stub(parser, 'isSiteDomain').returns(false);
182-
182+
183183
// Mock the getDataFromUrl to return known referrer data
184184
sandbox.stub(parser, 'getDataFromUrl').returns({
185185
source: 'Google',
186186
medium: 'search'
187187
});
188-
188+
189189
const result = parser.parse('https://www.google.com/search?q=ghost+cms');
190190
should.exist(result);
191191
assertPropertyEquals(result, 'referrerSource', 'Google');
@@ -199,14 +199,14 @@ describe('ReferrerParser', () => {
199199
sandbox.stub(parser, 'isGhostExploreRef').returns(false);
200200
sandbox.stub(parser, 'isGhostNewsletter').returns(false);
201201
sandbox.stub(parser, 'isSiteDomain').returns(false);
202-
202+
203203
// Mock the getDataFromUrl to return null for unknown referrer
204204
sandbox.stub(parser, 'getDataFromUrl').returns(null);
205-
205+
206206
// Mock URL object
207207
const url = new URL('https://unknown-referrer.com/path');
208208
sandbox.stub(parser, 'getUrlFromStr').returns(url);
209-
209+
210210
const result = parser.parse('https://unknown-referrer.com/path');
211211
should.exist(result);
212212
assertPropertyEquals(result, 'referrerSource', 'unknown-referrer.com');
@@ -220,7 +220,7 @@ describe('ReferrerParser', () => {
220220
sandbox.stub(parser, 'isGhostExploreRef').returns(false);
221221
sandbox.stub(parser, 'isGhostNewsletter').returns(false);
222222
sandbox.stub(parser, 'isSiteDomain').returns(true);
223-
223+
224224
const result = parser.parse('https://example.com/blog');
225225
should.exist(result);
226226
assertPropertyEquals(result, 'referrerSource', null);
@@ -234,7 +234,7 @@ describe('ReferrerParser', () => {
234234
const leverParser = new ReferrerParser({
235235
siteUrl: 'https://www.levernews.com'
236236
});
237-
237+
238238
const result = leverParser.parse('https://levernews.com/article');
239239
should.exist(result);
240240
assertPropertyEquals(result, 'referrerSource', null);
@@ -406,19 +406,19 @@ describe('ReferrerParser', () => {
406406
describe('isGhostNewsletter', () => {
407407
it('returns false for null source', () => {
408408
const parser = new ReferrerParser();
409-
const result = parser.isGhostNewsletter({ referrerSource: null });
409+
const result = parser.isGhostNewsletter({referrerSource: null});
410410
should.equal(result, false);
411411
});
412412

413413
it('returns true for sources ending with -newsletter', () => {
414414
const parser = new ReferrerParser();
415-
const result = parser.isGhostNewsletter({ referrerSource: 'test-newsletter' });
415+
const result = parser.isGhostNewsletter({referrerSource: 'test-newsletter'});
416416
should.equal(result, true);
417417
});
418418

419419
it('returns false for other sources', () => {
420420
const parser = new ReferrerParser();
421-
const result = parser.isGhostNewsletter({ referrerSource: 'test' });
421+
const result = parser.isGhostNewsletter({referrerSource: 'test'});
422422
should.equal(result, false);
423423
});
424424
});
@@ -492,4 +492,4 @@ describe('ReferrerParser', () => {
492492
should.equal(result, true);
493493
});
494494
});
495-
});
495+
});

packages/referrer-parser/test/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import should from 'should';
2-
import { expect, describe, it } from 'vitest';
3-
import { parse, ReferrerParser, ReferrerData } from '../index';
2+
import {describe, it} from 'vitest';
3+
import {parse, ReferrerParser, ReferrerData} from '../index';
44

55
// Helper function to safely assert on properties that might be null
66
function assertPropertyEquals(obj: any, property: string, expectedValue: any) {
77
should.exist(obj);
8-
8+
99
if (expectedValue === null) {
1010
should.equal(obj[property], null);
1111
} else {
@@ -79,4 +79,4 @@ describe('referrer-parser', () => {
7979
assertPropertyEquals(result, 'referrerUrl', 'example.com');
8080
});
8181
});
82-
});
82+
});

0 commit comments

Comments
 (0)