Skip to content

Commit 7dc983e

Browse files
Copilotfregante
andcommitted
Configure xo v1.x using inline comments instead of config file
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
1 parent 1d53659 commit 7dc983e

4 files changed

Lines changed: 4019 additions & 2982 deletions

File tree

demo/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global document */
12
import shortenUrl from '../index.js';
23
import {urls} from '../fixtures/urls.js';
34

index.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
/* global document */
12
import reservedNames from 'github-reserved-names/reserved-names.json' with { type: 'json' };
23

3-
const patchDiffRegex = /[.](patch|diff)$/;
4-
const releaseRegex = /^releases[/]tag[/]([^/]+)/;
5-
const labelRegex = /^labels[/]([^/]+)/;
6-
const compareRegex = /^compare[/]([^/]+)/;
7-
const pullRegex = /^pull[/](?<pull>\d+)(?:[/](?<pullPage>[^/]+))?(?:[/](?<pullPartialStart>[\da-f]{40})[.][.](?<pullPartialEnd>[\da-f]{40}))?$/;
8-
const issueRegex = /^issues[/](\d+)$/;
9-
const commitRegex = /^commit[/]([\da-f]{40})$/;
10-
const releaseArchiveRegex = /^archive[/](.+)([.]zip|[.]tar[.]gz)/;
11-
const releaseDownloadRegex = /^releases[/]download[/]([^/]+)[/](.+)/;
12-
const dependentsRegex = /^network[/]dependents[/]?$/;
13-
const dependenciesRegex = /^network[/]dependencies[/]?$/;
14-
const wikiRegex = /^wiki[/](.+)$/;
4+
const patchDiffRegex = /\.(patch|diff)$/;
5+
const releaseRegex = /^releases\/tag\/([^/]+)/;
6+
const labelRegex = /^labels\/([^/]+)/;
7+
const compareRegex = /^compare\/([^/]+)/;
8+
const pullRegex = /^pull\/(?<pull>\d+)(?:\/(?<pullPage>[^/]+))?(?:\/(?<pullPartialStart>[\da-f]{40})\.\.(?<pullPartialEnd>[\da-f]{40}))?$/;
9+
const issueRegex = /^issues\/(\d+)$/;
10+
const commitRegex = /^commit\/([\da-f]{40})$/;
11+
const releaseArchiveRegex = /^archive\/(.+)(\.zip|\.tar\.gz)/;
12+
const releaseDownloadRegex = /^releases\/download\/([^/]+)\/(.+)/;
13+
const dependentsRegex = /^network\/dependents\/?$/;
14+
const dependenciesRegex = /^network\/dependencies\/?$/;
15+
const wikiRegex = /^wiki\/(.+)$/;
1516

1617
/** @type {(searchParameters: URLSearchParams, pathname: string) => string} */
1718
function pullQueryOut(searchParameters, pathname) {
@@ -40,7 +41,7 @@ function styleRevision(revision) {
4041
}
4142

4243
revision = revision.replace(patchDiffRegex, '');
43-
if (/^[0-9a-f]{40}$/.test(revision)) {
44+
if (/^[\da-f]{40}$/.test(revision)) {
4445
revision = revision.slice(0, 7);
4546
}
4647

@@ -72,6 +73,7 @@ function joinValues(array, delimiter = '/') {
7273
* @param href {string}
7374
* @param currentUrl {string}
7475
*/
76+
/* eslint-disable complexity */
7577
function shortenRepoUrl(href, currentUrl = 'https://github.com') {
7678
if (!href) {
7779
return;
@@ -159,10 +161,10 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
159161
if (isReserved || pathname === '/' || (!isLocal && !isRaw && !isRedirection)) {
160162
const cleanHref = [
161163
origin
162-
.replace(/^https:[/][/]/, '')
163-
.replace(/^www[.]/, ''),
164+
.replace(/^https:\/\//, '')
165+
.replace(/^www\./, ''),
164166
pathname
165-
.replace(/[/]$/, ''),
167+
.replace(/\/$/, ''),
166168
];
167169

168170
if (['issues', 'pulls'].includes(user) && !repo) {
@@ -273,8 +275,9 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
273275
}
274276

275277
// Drop leading and trailing slash of relative path
276-
return pathname.replaceAll(/^[/]|[/]$/g, '') + url.search + hash + query;
278+
return pathname.replaceAll(/^\/|\/$/g, '') + url.search + hash + query;
277279
}
280+
/* eslint-enable complexity */
278281

279282
/**
280283
* Without this, <a>%%</a> would throw an error

index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global document */
12
import {test, expect} from 'vitest';
23
import {Window} from 'happy-dom';
34
import {urls} from './fixtures/urls.js';

0 commit comments

Comments
 (0)