Skip to content

Commit 01249e0

Browse files
committed
Meta: exclude test exports from page-detect autocompletion
Autocompleting `features.isP | ` Before: features.isPR features.isPRTest features.isPRCommit features.isPRCommitTest features.isPRList features.isPRListTest After: features.isPR features.isPRCommit features.isPRList Exports starting with _ are pushed to the end of the autocomplete list
1 parent bb98cce commit 01249e0

File tree

2 files changed

+55
-55
lines changed

2 files changed

+55
-55
lines changed

source/index.ts

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ const skip = 'skip'; // To be used only to skip tests of combined functions, i.e
99
const domBased = 'skip'; // To be used only to skip tests that are DOM-based rather than URL-based
1010

1111
export const is404 = (): boolean => document.title === 'Page not found · GitHub';
12-
export const is404Test = domBased; // They're specified in page-detect.ts
12+
export const _is404 = domBased; // They're specified in page-detect.ts
1313

1414
export const is500 = (): boolean => document.title === 'Server Error · GitHub' || document.title === 'Unicorn! · GitHub';
15-
export const is500Test = domBased; // They're specified in page-detect.ts
15+
export const _is500 = domBased; // They're specified in page-detect.ts
1616

1717
export const isBlame = (): boolean => /^blame\//.test(getRepoPath()!);
18-
export const isBlameTest = [
18+
export const _isBlame = [
1919
'https://github.com/sindresorhus/refined-github/blame/master/package.json'
2020
];
2121

2222
export const isCommit = (): boolean => isSingleCommit() || isPRCommit();
23-
export const isCommitTest = [
23+
export const _isCommit = [
2424
'https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f',
2525
'https://github.com/sindresorhus/refined-github/commit/5b614',
2626
'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85',
2727
'https://github.com/sindresorhus/refined-github/pull/148/commits/00196'
2828
];
2929

3030
export const isCommitList = (): boolean => /^commits\//.test(getRepoPath()!);
31-
export const isCommitListTest = [
31+
export const _isCommitList = [
3232
'https://github.com/sindresorhus/refined-github/commits/master?page=2',
3333
'https://github.com/sindresorhus/refined-github/commits/test-branch',
3434
'https://github.com/sindresorhus/refined-github/commits/0.13.0',
@@ -37,7 +37,7 @@ export const isCommitListTest = [
3737
];
3838

3939
export const isCompare = (): boolean => /^compare/.test(getRepoPath()!);
40-
export const isCompareTest = [
40+
export const _isCompare = [
4141
'https://github.com/sindresorhus/refined-github/compare',
4242
'https://github.com/sindresorhus/refined-github/compare/',
4343
'https://github.com/sindresorhus/refined-github/compare/master...branch-name',
@@ -47,7 +47,7 @@ export const isCompareTest = [
4747
];
4848

4949
export const isDashboard = (): boolean => !isGist() && /^$|^(orgs[/][^/]+[/])?dashboard([/]|$)/.test(getCleanPathname());
50-
export const isDashboardTest = [
50+
export const _isDashboard = [
5151
'https://github.com/',
5252
'https://github.com',
5353
'https://github.com/orgs/test/dashboard',
@@ -60,23 +60,23 @@ export const isDashboardTest = [
6060
];
6161

6262
export const isEnterprise = (): boolean => location.hostname !== 'github.com' && location.hostname !== 'gist.github.com';
63-
export const isEnterpriseTest = [
63+
export const _isEnterprise = [
6464
'https://github.big-corp.com/',
6565
'https://not-github.com/',
6666
'https://my-little-hub.com/',
6767
'https://my-little-hub.com/gist'
6868
];
6969

7070
export const isGist = (): boolean => location.hostname.startsWith('gist.') || location.pathname.split('/', 2)[1] === 'gist';
71-
export const isGistTest = [
71+
export const _isGist = [
7272
'https://gist.github.com',
7373
'http://gist.github.com',
7474
'https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064',
7575
'https://my-little-hub.com/gist'
7676
];
7777

7878
export const isGlobalDiscussionList = (): boolean => ['issues', 'pulls'].includes(location.pathname.split('/', 2)[1]);
79-
export const isGlobalDiscussionListTest = [
79+
export const _isGlobalDiscussionList = [
8080
'https://github.com/issues',
8181
'https://github.com/issues?q=is%3Apr+is%3Aopen',
8282
'https://github.com/issues/assigned',
@@ -89,75 +89,75 @@ export const isGlobalDiscussionListTest = [
8989
];
9090

9191
export const isGlobalSearchResults = (): boolean => location.pathname === '/search' && new URLSearchParams(location.search).get('q') !== null;
92-
export const isGlobalSearchResultsTest = [
92+
export const _isGlobalSearchResults = [
9393
'https://github.com/search?q=refined-github&ref=opensearch'
9494
];
9595

9696
export const isIssue = (): boolean => /^issues\/\d+/.test(getRepoPath()!);
97-
export const isIssueTest = [
97+
export const _isIssue = [
9898
'https://github.com/sindresorhus/refined-github/issues/146'
9999
];
100100

101101
export const isDiscussionList = (): boolean => isGlobalDiscussionList() || isRepoDiscussionList();
102-
export const isDiscussionListTest = skip;
102+
export const _isDiscussionList = skip;
103103

104104
export const isLabelList = (): boolean => getRepoPath() === 'labels';
105-
export const isLabelListTest = [
105+
export const _isLabelList = [
106106
'https://github.com/sindresorhus/refined-github/labels'
107107
];
108108

109109
export const isMilestone = (): boolean => /^milestone\/\d+/.test(getRepoPath()!);
110-
export const isMilestoneTest = [
110+
export const _isMilestone = [
111111
'https://github.com/sindresorhus/refined-github/milestone/12'
112112
];
113113

114114
export const isMilestoneList = (): boolean => getRepoPath() === 'milestones';
115-
export const isMilestoneListTest = [
115+
export const _isMilestoneList = [
116116
'https://github.com/sindresorhus/refined-github/milestones'
117117
];
118118

119119
export const isNewIssue = (): boolean => /^issues\/new/.test(getRepoPath()!);
120-
export const isNewIssueTest = [
120+
export const _isNewIssue = [
121121
'https://github.com/sindresorhus/refined-github/issues/new'
122122
];
123123

124124
export const isNewRelease = (): boolean => /^releases\/new/.test(getRepoPath()!);
125-
export const isNewReleaseTest = [
125+
export const _isNewRelease = [
126126
'https://github.com/sindresorhus/refined-github/releases/new'
127127
];
128128

129129
export const isNotifications = (): boolean => /^([^/]+[/][^/]+\/)?notifications/.test(getCleanPathname());
130-
export const isNotificationsTest = [
130+
export const _isNotifications = [
131131
'https://github.com/notifications',
132132
'https://github.com/notifications/participating',
133133
'https://github.com/sindresorhus/notifications/notifications',
134134
'https://github.com/notifications?all=1'
135135
];
136136

137137
export const isOrganizationProfile = (): boolean => select.exists('.orghead');
138-
export const isOrganizationProfileTest = domBased;
138+
export const _isOrganizationProfile = domBased;
139139

140140
export const isOrganizationDiscussion = (): boolean => /^orgs\/[^/]+\/teams\/[^/]+($|\/discussions)/.test(getCleanPathname());
141-
export const isOrganizationDiscussionTest = [
141+
export const _isOrganizationDiscussion = [
142142
'https://github.com/orgs/refined-github/teams/core-team/discussions?pinned=1',
143143
'https://github.com/orgs/refined-github/teams/core-team/discussions/1',
144144
'https://github.com/orgs/refined-github/teams/core-team'
145145
];
146146

147147
export const isOwnUserProfile = (): boolean => getCleanPathname() === getUsername();
148-
export const isOwnUserProfileTest = domBased;
148+
export const _isOwnUserProfile = domBased;
149149

150150
// If there's a Report Abuse link, we're not part of the org
151151
export const isOwnOrganizationProfile = (): boolean => isOrganizationProfile() && !select.exists('[href*="contact/report-abuse?report="]');
152-
export const isOwnOrganizationProfileTest = domBased;
152+
export const _isOwnOrganizationProfile = domBased;
153153

154154
export const isProject = (): boolean => /^projects\/\d+/.test(getRepoPath()!);
155-
export const isProjectTest = [
155+
export const _isProject = [
156156
'https://github.com/sindresorhus/refined-github/projects/3'
157157
];
158158

159159
export const isPR = (): boolean => /^pull\/\d+/.test(getRepoPath()!);
160-
export const isPRTest = [
160+
export const _isPR = [
161161
'https://github.com/sindresorhus/refined-github/pull/148',
162162
'https://github.com/sindresorhus/refined-github/pull/148/files',
163163
'https://github.com/sindresorhus/refined-github/pull/148/conflicts',
@@ -166,12 +166,12 @@ export const isPRTest = [
166166
];
167167

168168
export const isConflict = (): boolean => /^pull\/\d+\/conflicts/.test(getRepoPath()!);
169-
export const isConflictTest = [
169+
export const _isConflict = [
170170
'https://github.com/sindresorhus/refined-github/pull/148/conflicts'
171171
];
172172

173173
export const isPRList = (): boolean => location.pathname === '/pulls' || getRepoPath() === 'pulls';
174-
export const isPRListTest = [
174+
export const _isPRList = [
175175
'https://github.com/pulls',
176176
'https://github.com/pulls?q=issues',
177177
'https://github.com/sindresorhus/refined-github/pulls',
@@ -181,23 +181,23 @@ export const isPRListTest = [
181181
];
182182

183183
export const isPRCommit = (): boolean => /^pull\/\d+\/commits\/[0-9a-f]{5,40}/.test(getRepoPath()!);
184-
export const isPRCommitTest = [
184+
export const _isPRCommit = [
185185
'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85',
186186
'https://github.com/sindresorhus/refined-github/pull/148/commits/00196'
187187
];
188188

189189
export const isPRConversation = (): boolean => /^pull\/\d+$/.test(getRepoPath()!);
190-
export const isPRConversationTest = [
190+
export const _isPRConversation = [
191191
'https://github.com/sindresorhus/refined-github/pull/148'
192192
];
193193

194194
export const isPRFiles = (): boolean => /^pull\/\d+\/files/.test(getRepoPath()!);
195-
export const isPRFilesTest = [
195+
export const _isPRFiles = [
196196
'https://github.com/sindresorhus/refined-github/pull/148/files'
197197
];
198198

199199
export const isQuickPR = (): boolean => isCompare() && /[?&]quick_pull=1(&|$)/.test(location.search);
200-
export const isQuickPRTest = [
200+
export const _isQuickPR = [
201201
'https://github.com/sindresorhus/refined-github/compare/master...branch-name?quick_pull=1',
202202
'https://github.com/sindresorhus/refined-github/compare/branch-1...branch-2?quick_pull=1',
203203
'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1'
@@ -208,15 +208,15 @@ export const isReleasesOrTags = (): boolean => {
208208
return /^(releases|tags)$/.test(parts[0]) && parts[1] !== 'new';
209209
};
210210

211-
export const isReleasesOrTagsTest = [
211+
export const _isReleasesOrTags = [
212212
'https://github.com/sindresorhus/refined-github/releases',
213213
'https://github.com/sindresorhus/refined-github/tags',
214214
'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4',
215215
'https://github.com/sindresorhus/refined-github/releases/tag/0.2.1'
216216
];
217217

218218
export const isEditingFile = (): boolean => /^edit/.test(getRepoPath()!);
219-
export const isEditingFileTest = [
219+
export const _isEditingFile = [
220220
'https://github.com/sindresorhus/refined-github/edit/master/readme.md',
221221
'https://github.com/sindresorhus/refined-github/edit/ghe-injection/source/background.ts'
222222
];
@@ -227,19 +227,19 @@ export const isRepo = (): boolean => /^[^/]+\/[^/]+/.test(getCleanPathname()) &&
227227
!isDashboard() &&
228228
!isGist() &&
229229
!isRepoSearch();
230-
export const isRepoTest = [
230+
export const _isRepo = [
231231
'https://github.com/sindresorhus/refined-github/blame/master/package.json',
232232
'https://github.com/sindresorhus/refined-github/issues/146',
233233
'https://github.com/sindresorhus/notifications/',
234234
'https://github.com/sindresorhus/refined-github/pull/148'
235235
];
236-
export const isRepoTestSkipNegatives = true;
236+
export const _isRepoSkipNegatives = true;
237237

238238
export const isRepoDiscussionList = (): boolean =>
239239
isRepoPRList() ||
240240
isRepoIssueList() ||
241241
/^labels\/.+/.test(getRepoPath()!);
242-
export const isRepoDiscussionListTest = [
242+
export const _isRepoDiscussionList = [
243243
'http://github.com/sindresorhus/ava/issues',
244244
'https://github.com/sindresorhus/refined-github/pulls',
245245
'https://github.com/sindresorhus/refined-github/pulls/',
@@ -253,7 +253,7 @@ export const isRepoDiscussionListTest = [
253253
];
254254

255255
export const isRepoPRList = (): boolean => (getRepoPath() || '').startsWith('pulls');
256-
export const isRepoPRListTest = [
256+
export const _isRepoPRList = [
257257
'https://github.com/sindresorhus/refined-github/pulls',
258258
'https://github.com/sindresorhus/refined-github/pulls/',
259259
'https://github.com/sindresorhus/refined-github/pulls/fregante',
@@ -266,15 +266,15 @@ export const isRepoIssueList = (): boolean => {
266266
return parts[0] === 'issues' && parts[1] !== 'new' && !/\d/.test(parts[1]); // `issues/fregante` is a list but `issues/1` isn't
267267
};
268268

269-
export const isRepoIssueListTest = [
269+
export const _isRepoIssueList = [
270270
'http://github.com/sindresorhus/ava/issues',
271271
'https://github.com/sindresorhus/refined-github/issues',
272272
'https://github.com/sindresorhus/refined-github/issues/fregante',
273273
'https://github.com/sindresorhus/refined-github/issues?q=is%3Aclosed+sort%3Aupdated-desc'
274274
];
275275

276276
export const isRepoRoot = (): boolean => /^(tree[/][^/]+)?$/.test(getRepoPath()!);
277-
export const isRepoRootTest = [
277+
export const _isRepoRoot = [
278278
// Some tests are here only as "gotchas" for other tests that may misidentify their pages
279279
'https://github.com/sindresorhus/edit',
280280
'https://github.com/sindresorhus/search',
@@ -291,71 +291,71 @@ export const isRepoRootTest = [
291291
];
292292

293293
export const isRepoSearch = (): boolean => location.pathname.slice(1).split('/')[2] === 'search';
294-
export const isRepoSearchTest = [
294+
export const _isRepoSearch = [
295295
'https://github.com/sindresorhus/refined-github/search?q=diff',
296296
'https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues',
297297
'https://github.com/sindresorhus/refined-github/search'
298298
];
299299

300300
export const isRepoSettings = (): boolean => /^settings/.test(getRepoPath()!);
301-
export const isRepoSettingsTest = [
301+
export const _isRepoSettings = [
302302
'https://github.com/sindresorhus/refined-github/settings',
303303
'https://github.com/sindresorhus/refined-github/settings/branches'
304304
];
305305

306306
export const isRepoTree = (): boolean => isRepoRoot() || /^tree\//.test(getRepoPath()!);
307-
export const isRepoTreeTest = [
307+
export const _isRepoTree = [
308308
'https://github.com/sindresorhus/refined-github/tree/master/distribution',
309309
'https://github.com/sindresorhus/refined-github/tree/0.13.0/distribution',
310310
'https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/distribution'
311-
].concat(isRepoRootTest);
311+
].concat(_isRepoRoot);
312312

313313
export const isRepoWithAccess = (): boolean => isRepo() && select.exists('.reponav-item[href$="/settings"]');
314-
export const isRepoWithAccessTest = domBased;
314+
export const _isRepoWithAccess = domBased;
315315

316316
export const isSingleCommit = (): boolean => /^commit\/[0-9a-f]{5,40}/.test(getRepoPath()!);
317-
export const isSingleCommitTest = [
317+
export const _isSingleCommit = [
318318
'https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f',
319319
'https://github.com/sindresorhus/refined-github/commit/5b614'
320320
];
321321

322322
export const isSingleFile = (): boolean => /^blob\//.test(getRepoPath()!);
323-
export const isSingleFileTest = [
323+
export const _isSingleFile = [
324324
'https://github.com/sindresorhus/refined-github/blob/master/.gitattributes',
325325
'https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css',
326326
'https://github.com/sindresorhus/refined-github/blob/master/edit.txt'
327327
];
328328

329329
export const isTrending = (): boolean => location.pathname === '/trending' || location.pathname.startsWith('/trending/');
330-
export const isTrendingTest = [
330+
export const _isTrending = [
331331
'https://github.com/trending',
332332
'https://github.com/trending/developers',
333333
'https://github.com/trending/unknown'
334334
];
335335

336336
export const isUserProfile = (): boolean => select.exists('.user-profile-nav');
337-
export const isUserProfileTest = domBased;
337+
export const _isUserProfile = domBased;
338338

339339
export const isSingleTagPage = (): boolean => /^(releases\/tag)/.test(getRepoPath()!);
340-
export const isSingleTagPageTest = [
340+
export const _isSingleTagPage = [
341341
'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4',
342342
'https://github.com/sindresorhus/refined-github/releases/tag/0.2.1'
343343
];
344344

345-
export const hasCommentsTest = skip;
345+
export const _hasComments = skip;
346346
export const hasComments = (): boolean =>
347347
isPR() ||
348348
isIssue() ||
349349
isCommit() ||
350350
isOrganizationDiscussion();
351351

352-
export const hasRichTextEditorTest = skip;
352+
export const _hasRichTextEditor = skip;
353353
export const hasRichTextEditor = (): boolean =>
354354
hasComments() ||
355355
isNewIssue() ||
356356
isCompare();
357357

358-
export const hasCodeTest = skip;
358+
export const _hasCode = skip;
359359
export const hasCode = (): boolean => // Static code, not the editor
360360
hasComments() ||
361361
isRepoTree() || // Readme files

test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ for (const imported of Object.values(pageDetect)) {
1212
}
1313

1414
for (const [key, detect] of Object.entries(pageDetect)) {
15-
if (key.endsWith('Test') || typeof detect !== 'function') {
15+
if (key.startsWith('_') || typeof detect !== 'function') {
1616
continue;
1717
}
1818

19-
const testsKey = key + 'Test';
19+
const testsKey = '_' + key;
2020
// @ts-ignore `import-all` has no index signature https://github.com/Microsoft/TypeScript/issues/16248
2121
const validURLs = pageDetect[testsKey] as string[] | string;
2222

@@ -37,7 +37,7 @@ for (const [key, detect] of Object.entries(pageDetect)) {
3737
}
3838

3939
// @ts-ignore `import-all` has no index signature https://github.com/Microsoft/TypeScript/issues/16248
40-
if (pageDetect[key + 'TestSkipNegatives']) {
40+
if (pageDetect[testsKey + 'SkipNegatives']) {
4141
continue;
4242
}
4343

0 commit comments

Comments
 (0)