Skip to content

Commit

Permalink
upgrade biome
Browse files Browse the repository at this point in the history
  • Loading branch information
sqs committed Jul 31, 2024
1 parent 7f2e5dc commit e8ec987
Show file tree
Hide file tree
Showing 189 changed files with 664 additions and 743 deletions.
2 changes: 1 addition & 1 deletion .config/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"resolveJsonModule": true,
"composite": true,
"isolatedModules": true,
"outDir": "dist",
"outDir": "dist"
}
}
6 changes: 3 additions & 3 deletions bin/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ function printItems(items: Item[]): void {
console.log(
` - hover.text: ${truncate(
item.ui.hover?.text.trim().replace(/(\s|\n)+/g, ' '),
100
)}`
100,
)}`,
)
}
if (item.ai?.content) {
Expand Down Expand Up @@ -157,7 +157,7 @@ try {
config = loadConfig()
} catch (e) {
usageFatal(
'Error: invalid OPENCTX_CONFIG env var. Must be one of:\n- JSON object of config\n- Path to JSON config\n- Provider URI\n- Path to provider bundle'
'Error: invalid OPENCTX_CONFIG env var. Must be one of:\n- JSON object of config\n- Path to JSON config\n- Provider URI\n- Path to provider bundle',
)
}

Expand Down
4 changes: 1 addition & 3 deletions bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"bin": {
"openctx": "dist/cli.mjs"
},
"files": [
"dist/cli.mjs"
],
"files": ["dist/cli.mjs"],
"scripts": {
"openctx": "pnpm run --silent bundle && node --no-warnings=ExperimentalWarning --experimental-network-imports dist/cli.mjs",
"bundle": "tsc --build && esbuild --log-level=error --platform=node --bundle --outdir=dist --format=esm --out-extension:.js=.mjs cli.mts",
Expand Down
45 changes: 34 additions & 11 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
"rules": {
"recommended": true,
"nursery": {
"useExportType": "error",
"useImportType": "error",
"useGroupedTypeImport": "error",
"noUnusedImports": "error",
"noUnusedPrivateClassMembers": "error",
"noInvalidUseBeforeDeclaration": "error",
"noUselessTernary": "error",
"noDuplicateJsonKeys": "error"
},
"correctness": {
"noUnusedImports": "error",
"noUnusedPrivateClassMembers": "error"
},
"suspicious": {
"noExplicitAny": "off"
"noExplicitAny": "off",
"noExportsInTest": "off"
},
"style": {
"noNonNullAssertion": "off",
Expand All @@ -38,15 +36,40 @@
"semicolons": "asNeeded",
"quoteStyle": "single",
"arrowParentheses": "asNeeded",
"trailingComma": "es5"
"trailingCommas": "all"
}
},
"json": {
"parser": {
"allowComments": true,
"allowTrailingCommas": true
}
},
"css": {
"parser": {
"cssModules": true
},
"formatter": {
"enabled": true
},
"linter": {
"enabled": true
}
},
"files": {
"ignore": ["node_modules/", "out/", "dist/", "testdata/", ".vscode-test/", ".vscode-test-web/"]
"ignore": [
"node_modules/",
"out/",
"dist/",
"testdata/",
".vscode-test/",
".vscode-test-web/",
"package.json"
]
},
"overrides": [
{
"include": [".vscode/*.json"],
"include": ["./.vscode/*.json", "tsconfig.json"],
"json": {
"parser": {
"allowComments": true,
Expand Down
6 changes: 3 additions & 3 deletions client/browser/src/background/background.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function getBuiltinProvider(uri: string): Provider {
if (!mod) {
throw new Error(
`Only HTTP endpoint providers and the following built-in providers are supported: ${Object.keys(
BUILTIN_PROVIDER_MODULES
).join(', ')}. See https://openctx.org/docs/clients/browser-extension#known-issues.`
BUILTIN_PROVIDER_MODULES,
).join(', ')}. See https://openctx.org/docs/clients/browser-extension#known-issues.`,
)
}
return mod
Expand All @@ -44,7 +44,7 @@ function main(): void {
subscriptions.add(
addMessageListenersForBackgroundApi({
annotationsChanges: (...args) => client.annotationsChanges(...args),
})
}),
)

self.addEventListener('unload', () => subscriptions.unsubscribe(), { once: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ExtensionStorageSubject<T extends keyof LocalStorageItems>
{
constructor(
private key: T,
defaultValue: LocalStorageItems[T]
defaultValue: LocalStorageItems[T],
) {
super(subscriber => {
subscriber.next(this.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Observable } from 'rxjs'
* The handler will always return `void`.
*/
export const fromBrowserEvent = <F extends (...args: any[]) => void>(
emitter: browser.CallbackEventEmitter<F>
emitter: browser.CallbackEventEmitter<F>,
): Observable<Parameters<F>> =>
// Do not use fromEventPattern() because of https://github.com/ReactiveX/rxjs/issues/4736
new Observable(subscriber => {
Expand Down
6 changes: 3 additions & 3 deletions client/browser/src/browser-extension/web-extension-api/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ function callBackgroundMethodReturningObservable(method: string, args: unknown[]
* Create a proxy for an Observable-returning background API method.
*/
export function proxyBackgroundMethodReturningObservable<M extends keyof BackgroundApi>(
method: M
method: M,
): BackgroundApi[M] {
if (isBackground) {
throw new Error(
'tried to call background service worker function from background service worker itself'
'tried to call background service worker function from background service worker itself',
)
}
return (...args: any[]) =>
Expand All @@ -108,7 +108,7 @@ export function addMessageListenersForBackgroundApi(api: BackgroundApi): Unsubsc

const handler = (
{ streamId, method, args }: RequestMessage,
sender: browser.runtime.MessageSender
sender: browser.runtime.MessageSender,
): Promise<void> => {
if (streamId === undefined) {
throw new Error('non-Observable-returning RPC calls are not yet implemented')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const storage: {
onChanged: browser.CallbackEventEmitter<
(
changes: browser.storage.ChangeDict<ExtensionStorageItems[typeof areaName]>,
areaName: browser.storage.AreaName
areaName: browser.storage.AreaName,
) => void
>
} = globalThis.browser && browser.storage
Expand All @@ -28,7 +28,7 @@ export const observeStorageKey = <
K extends keyof ExtensionStorageItems[A],
>(
areaName: A,
key: K
key: K,
): Observable<ExtensionStorageItems[A][K] | undefined> => {
if (platform !== 'chrome-extension' && areaName === 'managed') {
// Accessing managed storage throws an error on Firefox and on Safari.
Expand All @@ -38,21 +38,21 @@ export const observeStorageKey = <
// Start with current value of the item
defer(() =>
from(
(storage[areaName] as browser.storage.StorageArea<ExtensionStorageItems[A]>).get(key)
).pipe(map(items => (items as ExtensionStorageItems[A])[key]))
(storage[areaName] as browser.storage.StorageArea<ExtensionStorageItems[A]>).get(key),
).pipe(map(items => (items as ExtensionStorageItems[A])[key])),
),
// Emit every new value from change events that affect that item
fromBrowserEvent(storage.onChanged).pipe(
filter(([, name]) => areaName === name),
map(([changes]) => changes),
filter(
(
changes
changes,
): changes is {
[k in K]: browser.storage.StorageChange<ExtensionStorageItems[A][K]>
} => Object.prototype.hasOwnProperty.call(changes, key)
} => Object.prototype.hasOwnProperty.call(changes, key),
),
map(changes => changes[key].newValue)
)
map(changes => changes[key].newValue),
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ export interface BackgroundApi extends Pick<Client<Range>, 'annotationsChanges'>
export type BackgroundApiHandlers = {
[M in keyof BackgroundApi]: (
args: Parameters<BackgroundApi[M]>,
sender: browser.runtime.MessageSender
sender: browser.runtime.MessageSender,
) => ReturnType<BackgroundApi[M]>
}
6 changes: 3 additions & 3 deletions client/browser/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ const DEFAULT_CONFIG: ClientConfiguration = {

export const configurationStringChanges: Observable<string> = observeStorageKey(
'sync',
'configuration'
'configuration',
).pipe(
map(c => c ?? { jsonc: JSON.stringify(DEFAULT_CONFIG, null, 2) }),
map(({ jsonc: jsoncStr }) => jsoncStr)
map(({ jsonc: jsoncStr }) => jsoncStr),
)

export const configurationChanges: Observable<ClientConfiguration> = configurationStringChanges.pipe(
Expand All @@ -67,5 +67,5 @@ export const configurationChanges: Observable<ClientConfiguration> = configurati
console.error('Error parsing configuration (as JSONC):', errors)
}
return obj
})
}),
)
4 changes: 2 additions & 2 deletions client/browser/src/contentScript/contentScript.main.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
font-family: system-ui, sans-serif;
}

html[data-color-mode='light'] {
html[data-color-mode="light"] {
& .octx-chip {
background: #00000011;
border: solid 1px #00000019;
Expand All @@ -24,7 +24,7 @@ html[data-color-mode='light'] {
}
}

html[data-color-mode='dark'] {
html[data-color-mode="dark"] {
& .octx-chip {
background: #ffffff3a;
border: solid 1px #ffffff55;
Expand Down
6 changes: 3 additions & 3 deletions client/browser/src/contentScript/contentScript.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const INJECTORS: Injector[] = [injectOnGitHubCodeView, injectOnGitHubPullRequest
const subscription = locationChanges
.pipe(
mergeMap(location =>
combineLatest(INJECTORS.map(injector => injector(location, annotationsChanges)))
)
combineLatest(INJECTORS.map(injector => injector(location, annotationsChanges))),
),
)
.subscribe()
window.addEventListener('unload', () => subscription.unsubscribe())
Expand All @@ -38,6 +38,6 @@ function annotationsChanges(params: AnnotationsParams): Observable<Annotation[]>
console.count('itemsChanges count')
console.log(items)
console.groupEnd()
})
}),
)
}
16 changes: 8 additions & 8 deletions client/browser/src/contentScript/github/codeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { LINE_CHIPS_CLASSNAME, annsByLine, styledChipListParams } from '../openC
*/
export function injectOnGitHubCodeView(
location: URL,
annotationsChanges: (params: AnnotationsParams) => Observable<Annotation[]>
annotationsChanges: (params: AnnotationsParams) => Observable<Annotation[]>,
): Observable<void> {
// All GitHub code view URLs contain `/blob/` in the path. (But not all URLs with `/blob/` are code
// views, so we still need to check for the presence of DOM elements below. For example, there
Expand Down Expand Up @@ -57,7 +57,7 @@ export function injectOnGitHubCodeView(
console.count('significantCodeViewChanges count')
console.log(viewState)
console.groupEnd()
})
}),
),
]).pipe(
tap(([anns]) => {
Expand All @@ -70,9 +70,9 @@ export function injectOnGitHubCodeView(
console.timeEnd('redraw')
}
}),
map(() => undefined)
map(() => undefined),
)
})
}),
)
}

Expand All @@ -98,7 +98,7 @@ function redraw(anns: Annotation[]): void {
if (!lineNumberStr) {
throw new Error('unable to determine line number')
}
const line = parseInt(lineNumberStr, 10) - 1
const line = Number.parseInt(lineNumberStr, 10) - 1

const lineAnns = byLine.find(i => i.line === line)?.anns
if (lineAnns !== undefined) {
Expand All @@ -123,7 +123,7 @@ function redraw(anns: Annotation[]): void {
const chipList = createChipList(
styledChipListParams({
annotations: anns,
})
}),
)
lineEl.append(chipList)
}
Expand Down Expand Up @@ -194,13 +194,13 @@ function isElementInViewport(el: HTMLElement): boolean {

function lineNumbersFromReactFileLines(reactFileLineEls: HTMLElement[]): number[] {
return reactFileLineEls
.map(el => (el.dataset.lineNumber ? parseInt(el.dataset.lineNumber, 10) - 1 : null))
.map(el => (el.dataset.lineNumber ? Number.parseInt(el.dataset.lineNumber, 10) - 1 : null))
.filter((line): line is number => line !== null)
}

function getReactFileLine(lineNumber: number): HTMLDivElement {
const el = document.querySelector<HTMLDivElement>(
`.react-file-line[data-line-number="${lineNumber + 1}"]`
`.react-file-line[data-line-number="${lineNumber + 1}"]`,
)
if (!el) {
throw new Error(`no .react-file-line for line number ${lineNumber}`)
Expand Down
Loading

0 comments on commit e8ec987

Please sign in to comment.