Skip to content

Commit c0e15f4

Browse files
authored
Meta: Format TS files with dprint (once) (#9240)
1 parent 321cd93 commit c0e15f4

118 files changed

Lines changed: 1286 additions & 726 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ jobs:
6464
node-version-file: package.json
6565
cache: npm
6666
- run: npm ci
67-
- run: npm run lint
67+
- run: npm run lint:js
68+
- run: npm run lint:css
6869
- uses: codespell-project/actions-codespell@v2
6970
with:
7071
ignore_words_list: eror,usera
@@ -82,6 +83,19 @@ jobs:
8283
- run: npm ci
8384
- run: npm run build:typescript
8485

86+
Format:
87+
runs-on: ubuntu-latest
88+
permissions:
89+
contents: read
90+
steps:
91+
- uses: actions/checkout@v6
92+
- uses: actions/setup-node@v6
93+
with:
94+
node-version-file: package.json
95+
cache: npm
96+
- run: npm ci
97+
- run: npm run format:check
98+
8599
Build:
86100
strategy:
87101
matrix:

build/features.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import fastIgnore from 'fast-ignore';
12
import {existsSync, readdirSync, readFileSync} from 'node:fs';
23
import path from 'node:path';
3-
import {test, describe, assert} from 'vitest';
44
import {regexJoinWithSeparator} from 'regex-join';
5-
import fastIgnore from 'fast-ignore';
5+
import {assert, describe, test} from 'vitest';
66

77
import {isFeaturePrivate} from '../source/helpers/feature-utils.js';
8-
import {getImportedFeatures, getFeaturesMeta} from './readme-parser.js';
8+
import {getFeaturesMeta, getImportedFeatures} from './readme-parser.js';
99

1010
// Re-run tests when these files change https://github.com/vitest-dev/vitest/discussions/5864
1111
void import.meta.glob([
@@ -156,7 +156,10 @@ function validateTsx(file: FeatureFile): void {
156156

157157
assert(/test url/i.test(file.contents().toString()), 'Should have test URLs');
158158

159-
if (/api\.v4|getDefaultBranch|getPrInfo/.test(String(file.contents())) && /observe\(|delegate\(/.test(String(file.contents()))) {
159+
if (
160+
/api\.v4|getDefaultBranch|getPrInfo/.test(String(file.contents()))
161+
&& /observe\(|delegate\(/.test(String(file.contents()))
162+
) {
160163
assert(
161164
/await expectToken|hasToken/.test(String(file.contents())),
162165
`${file.id} uses the v4 API, so it should include \`await expectToken()\` in its init function or, if the token is optional, \`hasToken\` anywhere`,
@@ -216,6 +219,8 @@ describe('features', () => {
216219
return;
217220
}
218221

219-
assert.fail(`The \`/source/features\` folder should only contain .css, .tsx and .gql files. Found \`source/features/${filename}\``);
222+
assert.fail(
223+
`The \`/source/features\` folder should only contain .css, .tsx and .gql files. Found \`source/features/${filename}\``,
224+
);
220225
});
221226
});

build/readme-parser.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import {test, expect} from 'vitest';
1+
import {expect, test} from 'vitest';
22

3-
import {
4-
getFeaturesMeta,
5-
getImportedFeatures,
6-
} from './readme-parser.js';
3+
import {getFeaturesMeta, getImportedFeatures} from './readme-parser.js';
74

85
// Re-run tests when these files change https://github.com/vitest-dev/vitest/discussions/5864
96
void import.meta.glob([

build/readme-parser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/// <reference types="../source/globals.js" />
22

3-
import {regexJoinWithSeparator} from 'regex-join';
43
import {existsSync, readFileSync} from 'node:fs';
4+
import {regexJoinWithSeparator} from 'regex-join';
55
import parseMarkdown from 'snarkdown';
66

77
// Group names must be unique because they will be merged
88
const simpleFeatureRegex = /^- \[\]\(# "(?<simpleId>[^"]+)"\)(?: 🔥)? (?<simpleDescription>.+)$/gm;
9-
const highlightedFeatureRegex = /<p><a title="(?<highlightedId>[^"]+)"><\/a> (?<highlightedDescripion>.+)\n\t+<p><img src="(?<highlightedImage>.+?)">/g;
9+
const highlightedFeatureRegex
10+
= /<p><a title="(?<highlightedId>[^"]+)"><\/a> (?<highlightedDescripion>.+)\n\t+<p><img src="(?<highlightedImage>.+?)">/g;
1011
const featureRegex = regexJoinWithSeparator('|', [simpleFeatureRegex, highlightedFeatureRegex]);
1112
const imageRegex = /\.\w{3}$/; // 3 since .png and .gif have 3 letters
1213
const rghUploadsRegex = /refined-github[/]refined-github[/]assets[/]/;

dprint.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
"plugins": [
44
"./node_modules/dprint-plugin-markup/plugin.wasm",
55
"./node_modules/dprint-plugin-malva/plugin.wasm",
6-
"./node_modules/dprint-plugin-graphql/plugin.wasm"
6+
"./node_modules/dprint-plugin-graphql/plugin.wasm",
7+
"./node_modules/@dprint/json/plugin.wasm"
78
],
89
"includes": [
910
"**/*.svelte",
1011
"**/*.css",
11-
"**/*.gql"
12+
"**/*.gql",
13+
"dprint.json"
1214
],
1315
"useTabs": true,
1416
"markup": {

eslint.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import xo from 'xo';
22
import sveltePlugin from 'eslint-plugin-svelte';
33
import svelteParser from 'svelte-eslint-parser';
4-
import eslintConfigPrettier from 'eslint-config-prettier';
4+
import eslintConfigPrettier from 'eslint-config-prettier/flat';
55
import {includeIgnoreFile} from '@eslint/compat';
66
import {fileURLToPath} from 'node:url';
77

@@ -316,6 +316,8 @@ export default [
316316
location: 'readonly',
317317
},
318318
},
319+
320+
// TODO: Use global `/flat` config. Currently limited to svelte files because dprint is applied to their JS
319321
rules: eslintConfigPrettier.rules,
320322
},
321323
{

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"build": "run-p build:* --continue-on-error",
77
"build:typescript": "tsc --noEmit",
88
"build:bundle": "rollup -c",
9-
"fix": "run-p \"lint:biome -- --write\" \"lint:js -- --fix\" format \"vitest -- --update\" --continue-on-error",
9+
"fix": "run-p format \"lint:css -- --write\" \"lint:js -- --fix\" \"vitest -- --update\" --continue-on-error",
1010
"format": "dprint fmt",
11+
"format:check": "dprint check",
1112
"lint": "run-p lint:* --continue-on-error",
1213
"lint:js": "eslint .",
13-
"lint:biome": "biome lint",
14-
"lint:dprint": "dprint check",
14+
"lint:css": "biome lint",
1515
"new": "bash build/new-feature.sh",
1616
"pack:safari": "xcodebuild -project 'safari/Refined GitHub.xcodeproj' -scheme 'Refined GitHub' -destination 'platform=macOS'",
1717
"prepare:safari": "bash build/prepare-safari-release.sh",
@@ -73,6 +73,7 @@
7373
},
7474
"devDependencies": {
7575
"@biomejs/biome": "^2.3.12",
76+
"@dprint/json": "^0.21.3",
7677
"@eslint-react/eslint-plugin": "^2.7.2",
7778
"@eslint/compat": "^2.0.1",
7879
"@rollup/plugin-alias": "^6.0.0",

source/background.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ if (!isSafari()) {
2727
addReloadWithoutContentScripts();
2828

2929
// Extend the error message for the "No All URLs" bugfix
30-
customizeNoAllUrlsErrorMessage('Refined GitHub is not meant to run on every website. If you’re looking to enable it on GitHub Enterprise, follow the instructions in the Options page.');
30+
customizeNoAllUrlsErrorMessage(
31+
'Refined GitHub is not meant to run on every website. If you’re looking to enable it on GitHub Enterprise, follow the instructions in the Options page.',
32+
);
3133

3234
handleMessages({
3335
async openUrls(urls: string[], {tab}: chrome.runtime.MessageSender) {

source/feature-manager.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
/* eslint-disable no-await-in-loop -- Event loops */
22
import React from 'dom-chef';
3-
import {elementExists} from 'select-dom';
43
import domLoaded from 'dom-loaded';
4+
import * as pageDetect from 'github-url-detection';
5+
import oneEvent from 'one-event';
6+
import {elementExists} from 'select-dom';
57
import stripIndent from 'strip-indent';
68
import type {Promisable} from 'type-fest';
7-
import * as pageDetect from 'github-url-detection';
89
import {isWebPage} from 'webext-detect';
910
import {messageRuntime} from 'webext-msg';
10-
import oneEvent from 'one-event';
1111

12-
import waitFor from './helpers/wait-for.js';
13-
import ArrayMap from './helpers/map-of-arrays.js';
12+
import asyncForEach from './helpers/async-for-each.js';
1413
import bisectFeatures from './helpers/bisect.js';
14+
import {catchErrors, disableErrorLogging} from './helpers/errors.js';
1515
import {
16-
shouldFeatureRun,
17-
isFeaturePrivate,
18-
type RunConditions,
19-
} from './helpers/feature-utils.js';
20-
import optionsStorage, {isFeatureDisabled, type RghOptions} from './options-storage.js';
16+
getFeatureId, listenToAjaxedLoad, log, shortcutMap,
17+
} from './helpers/feature-helpers.js';
18+
import {isFeaturePrivate, type RunConditions, shouldFeatureRun} from './helpers/feature-utils.js';
2119
import {
2220
applyStyleHotfixes,
21+
brokenFeatures,
2322
getLocalHotfixesAsOptions,
2423
preloadSyncLocalStrings,
25-
brokenFeatures,
2624
} from './helpers/hotfix.js';
27-
import asyncForEach from './helpers/async-for-each.js';
28-
import {catchErrors, disableErrorLogging} from './helpers/errors.js';
29-
import {
30-
getFeatureId, listenToAjaxedLoad, log, shortcutMap,
31-
} from './helpers/feature-helpers.js';
25+
import ArrayMap from './helpers/map-of-arrays.js';
26+
import waitFor from './helpers/wait-for.js';
27+
import optionsStorage, {isFeatureDisabled, type RghOptions} from './options-storage.js';
3228
import {contentScriptToggle} from './options/reload-without.js';
3329

3430
type FeatureInitResult = void | false;

0 commit comments

Comments
 (0)