update eslint, ts-for-gir

This commit is contained in:
Aylur
2024-07-20 14:05:47 +02:00
parent a1f9272f45
commit 1c9377ec69
13 changed files with 1045 additions and 524 deletions
-96
View File
@@ -1,96 +0,0 @@
env:
es2021: true
extends:
- "eslint:recommended"
- "plugin:@typescript-eslint/recommended"
parser: "@typescript-eslint/parser"
parserOptions:
ecmaVersion: 2022
sourceType: "module"
project: "./tsconfig.json"
warnOnUnsupportedTypeScriptVersion: false
root: true
plugins:
- "@typescript-eslint"
rules:
"@typescript-eslint/ban-ts-comment": error
"@typescript-eslint/no-explicit-any": off
"@typescript-eslint/no-non-null-assertion": off
arrow-parens:
- error
- as-needed
comma-dangle:
- error
- always-multiline
comma-spacing:
- error
- before: false
after: true
comma-style:
- error
- last
curly:
- error
- multi-or-nest
- consistent
dot-location:
- error
- property
eol-last:
- error
indent:
- error
- 4
- SwitchCase: 1
keyword-spacing:
- error
- before: true
lines-between-class-members:
- error
- always
- exceptAfterSingleLine: true
padded-blocks:
- error
- never
- allowSingleLineBlocks: false
prefer-const:
- error
quotes:
- error
- double
- avoidEscape: true
semi:
- error
- never
nonblock-statement-body-position:
- error
- below
no-trailing-spaces:
- error
no-useless-escape:
- off
max-len:
- error
- code: 100
func-call-spacing:
- error
array-bracket-spacing:
- error
space-before-function-paren:
- error
- anonymous: never
named: never
asyncArrow: ignore
space-before-blocks:
- error
key-spacing:
- error
object-curly-spacing:
- error
- always
globals:
globalThis: readonly
imports: readonly
print: readonly
printerr: readonly
console: readonly
-7
View File
@@ -1,7 +0,0 @@
export default {
"verbose": true,
"environments": ["gjs"],
"outdir": "node_modules/@girs",
"package": true,
"generateAlias": true,
}
+18
View File
@@ -0,0 +1,18 @@
import eslint from "@eslint/js"
import tseslint from "typescript-eslint"
import stylistic from "@stylistic/eslint-plugin"
export default tseslint.config({
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
stylistic.configs.customize({
semi: false,
indent: 4,
quotes: "double",
}),
],
rules: {
"@typescript-eslint/no-explicit-any": "off",
},
})
+895 -295
View File
File diff suppressed because it is too large Load Diff
+9 -7
View File
@@ -31,14 +31,16 @@
],
"publishConfig": {},
"devDependencies": {
"@ts-for-gir/cli": "^3.3.0",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"eslint": "^8.42.0",
"typescript": "^5.1.0"
"@eslint/js": "^9.7.0",
"@stylistic/eslint-plugin": "latest",
"@ts-for-gir/cli": "latest",
"@types/eslint__js": "^8.42.3",
"eslint": "^8.57.0",
"typescript": "^5.5.3",
"typescript-eslint": "^7.16.1"
},
"scripts": {
"lint": "eslint .",
"types": "ts-for-gir generate"
"lint": "eslint . --fix",
"types": "ts-for-gir generate -o node_modules/@girs --package"
}
}
+6 -5
View File
@@ -33,7 +33,8 @@ class AstalJS extends Astal.Application {
fn()()
.then(res)
.catch(rej)
} catch (error) {
}
catch (error) {
rej(error)
}
})
@@ -43,12 +44,13 @@ class AstalJS extends Astal.Application {
vfunc_request(msg: string, conn: Gio.SocketConnection): void {
if (typeof this.requestHandler === "function") {
this.requestHandler(msg, response => {
this.requestHandler(msg, (response) => {
Astal.write_sock(conn, String(response), (_, res) =>
Astal.write_sock_finish(res),
)
})
} else {
}
else {
super.vfunc_request(msg, conn)
}
}
@@ -68,7 +70,6 @@ class AstalJS extends Astal.Application {
this.requestHandler = requestHandler
this.connect("activate", () => {
// @ts-expect-error missing url type
const path: string[] = import.meta.url.split("/").slice(3)
const file = path.at(-1)!.replace(".js", ".css")
const css = `/${path.slice(0, -1).join("/")}/${file}`
@@ -92,4 +93,4 @@ class AstalJS extends Astal.Application {
}
}
export default new AstalJS
export default new AstalJS()
+37 -39
View File
@@ -71,14 +71,15 @@ function setProp(obj: any, prop: string, value: any) {
if (Object.hasOwn(obj, prop))
return (obj[prop] = value)
} catch (error) {
}
catch (error) {
console.error(`could not set property "${prop}" on ${obj}:`, error)
}
console.error(`could not set property "${prop}" on ${obj}`)
}
export type Widget<C extends { new(...args: any): Gtk.Widget }> = InstanceType<C> & {
export type Widget<C extends InstanceType<typeof Gtk.Widget>> = C & {
className: string
css: string
cursor: Cursor
@@ -170,7 +171,7 @@ function ctor(self: any, config: any = {}, children: any = []) {
children = mergeBindings(children.flat(Infinity))
if (children instanceof Binding) {
setChildren(self, children.get())
self.connect("destroy", children.subscribe(v => {
self.connect("destroy", children.subscribe((v) => {
setChildren(self, v)
}))
}
@@ -184,60 +185,58 @@ function ctor(self: any, config: any = {}, children: any = []) {
}
function proxify<
C extends { new(...args: any[]): any },
C extends typeof Gtk.Widget,
>(klass: C) {
klass.prototype.hook = function (obj: any, sig: any, callback: any) {
return hook(this, obj, sig, callback)
}
klass.prototype.toggleClassName = function (name: string, on = true) {
Astal.widget_toggle_class_name(this, name, on)
}
Object.defineProperty(klass.prototype, "className", {
get() { return Astal.widget_get_class_names(this).join(" ") },
set(v) { Astal.widget_set_class_names(this, v.split(/\s+/)) },
})
klass.prototype.set_class_name = function (name: string) {
this.className = name
}
Object.defineProperty(klass.prototype, "css", {
get() { return Astal.widget_get_css(this) },
set(v) { Astal.widget_set_css(this, v) },
})
klass.prototype.set_css = function (css: string) {
this.css = css
}
Object.defineProperty(klass.prototype, "cursor", {
get() { return Astal.widget_get_cursor(this) },
set(v) { Astal.widget_set_cursor(this, v) },
})
klass.prototype.set_cursor = function (cursor: string) {
this.cursor = cursor
}
Object.defineProperty(klass.prototype, "clickThrough", {
get() { return Astal.widget_get_click_through(this) },
set(v) { Astal.widget_set_click_through(this, v) },
})
klass.prototype.set_click_through = function (clickThrough: boolean) {
this.clickThrough = clickThrough
}
Object.assign(klass.prototype, {
hook: function (obj: any, sig: any, callback: any) {
return hook(this as InstanceType<C>, obj, sig, callback)
},
set_class_name: function (name: string) {
// @ts-expect-error unknown key
this.className = name
},
set_css: function (css: string) {
// @ts-expect-error unknown key
this.css = css
},
set_cursor: function (cursor: string) {
// @ts-expect-error unknown key
this.cursor = cursor
},
set_click_through: function (clickThrough: boolean) {
// @ts-expect-error unknown key
this.clickThrough = clickThrough
},
})
const proxy = new Proxy(klass, {
construct(_, [conf, ...children]) {
const self = new klass
return ctor(self, conf, children)
// @ts-expect-error abstract class
return ctor(new klass(), conf, children)
},
apply(_t, _a, [conf, ...children]) {
const self = new klass
return ctor(self, conf, children)
// @ts-expect-error abstract class
return ctor(new klass(), conf, children)
},
})
@@ -251,33 +250,32 @@ export default function astalify<
>(klass: C) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type Astal<N> = Omit<C, "new"> & {
new(props?: P, ...children: Gtk.Widget[]): Widget<C>
(props?: P, ...children: Gtk.Widget[]): Widget<C>
new(props?: P, ...children: Gtk.Widget[]): Widget<InstanceType<C>>
(props?: P, ...children: Gtk.Widget[]): Widget<InstanceType<C>>
}
return proxify(klass) as unknown as Astal<N>
}
type BindableProps<T> = {
[K in keyof T]: Binding<T[K]> | T[K];
}
type SigHandler<
W extends { new(...args: any): Gtk.Widget },
W extends InstanceType<typeof Gtk.Widget>,
Args extends Array<unknown>,
> = ((self: Widget<W>, ...args: Args) => unknown) | string | string[]
export type ConstructProps<
Self extends { new(...args: any[]): any },
Props = unknown,
Signals extends Record<`on${string}`, Array<unknown>> = Record<`on${string}`, any[]>
Self extends InstanceType<typeof Gtk.Widget>,
Props extends Gtk.Widget.ConstructorProps,
Signals extends Record<`on${string}`, Array<unknown>> = Record<`on${string}`, any[]>,
> = Partial<{
// @ts-expect-error can't assign to unknown, but it works as expected though
[S in keyof Signals]: SigHandler<Self, Signals[S]>
}> & Partial<{
[Key in `on${string}`]: SigHandler<Self, any[]>
}> & BindableProps<Props & {
}> & BindableProps<Partial<Props> & {
className?: string
css?: string
cursor?: string
+4 -2
View File
@@ -9,7 +9,8 @@ export function readFileAsync(path: string): Promise<string> {
Astal.read_file_async(path, (_, res) => {
try {
resolve(Astal.read_file_finish(res) || "")
} catch (error) {
}
catch (error) {
reject(error)
}
})
@@ -25,7 +26,8 @@ export function writeFileAsync(path: string, content: string): Promise<void> {
Astal.write_file_async(path, content, (_, res) => {
try {
resolve(Astal.write_file_finish(res))
} catch (error) {
}
catch (error) {
reject(error)
}
})
+31 -30
View File
@@ -27,30 +27,31 @@ export function jsx(
if (isArrowFunction(ctor))
return ctor(props)
// @ts-expect-error can be class or function
return new ctor(props)
}
const ctors = {
"box": Widget.Box,
"button": Widget.Button,
"centerbox": Widget.CenterBox,
box: Widget.Box,
button: Widget.Button,
centerbox: Widget.CenterBox,
// TODO: circularprogress
"drawingarea": Widget.DrawingArea,
"entry": Widget.Entry,
"eventbox": Widget.EventBox,
drawingarea: Widget.DrawingArea,
entry: Widget.Entry,
eventbox: Widget.EventBox,
// TODO: fixed
// TODO: flowbox
"icon": Widget.Icon,
"label": Widget.Label,
"levelbar": Widget.LevelBar,
icon: Widget.Icon,
label: Widget.Label,
levelbar: Widget.LevelBar,
// TODO: listbox
"overlay": Widget.Overlay,
"revealer": Widget.Revealer,
"scrollable": Widget.Scrollable,
"slider": Widget.Slider,
overlay: Widget.Overlay,
revealer: Widget.Revealer,
scrollable: Widget.Scrollable,
slider: Widget.Slider,
// TODO: stack
"switch": Widget.Switch,
"window": Widget.Window,
switch: Widget.Switch,
window: Widget.Window,
}
declare global {
@@ -59,26 +60,26 @@ declare global {
type Element = Gtk.Widget
type ElementClass = Gtk.Widget
interface IntrinsicElements {
"box": Widget.BoxProps,
"button": Widget.ButtonProps,
"centerbox": Widget.CenterBoxProps,
box: Widget.BoxProps
button: Widget.ButtonProps
centerbox: Widget.CenterBoxProps
// TODO: circularprogress
"drawingarea": Widget.DrawingAreaProps,
"entry": Widget.EntryProps,
"eventbox": Widget.EventBoxProps,
drawingarea: Widget.DrawingAreaProps
entry: Widget.EntryProps
eventbox: Widget.EventBoxProps
// TODO: fixed
// TODO: flowbox
"icon": Widget.IconProps,
"label": Widget.LabelProps,
"levelbar": Widget.LevelBarProps,
icon: Widget.IconProps
label: Widget.LabelProps
levelbar: Widget.LevelBarProps
// TODO: listbox
"overlay": Widget.OverlayProps,
"revealer": Widget.RevealerProps,
"scrollable": Widget.ScrollableProps,
"slider": Widget.SliderProps,
overlay: Widget.OverlayProps
revealer: Widget.RevealerProps
scrollable: Widget.ScrollableProps
slider: Widget.SliderProps
// TODO: stack
"switch": Widget.SwitchProps,
"window": Widget.WindowProps,
switch: Widget.SwitchProps
window: Widget.WindowProps
}
}
}
+3 -3
View File
@@ -1,9 +1,9 @@
import { Astal } from "./imports.js"
type Args<Out = void, Err = void> = {
cmd: string | string[],
out?: (stdout: string) => Out,
err?: (stderr: string) => Err,
cmd: string | string[]
out?: (stdout: string) => Out
err?: (stderr: string) => Err
}
function args<O, E>(argsOrCmd: Args | string | string[], onOut: O, onErr: E) {
+11 -7
View File
@@ -22,7 +22,7 @@ class VariableWrapper<T> extends Function {
constructor(init: T) {
super()
this._value = init
this.variable = new Astal.VariableBase
this.variable = new Astal.VariableBase()
this.variable.connect("dropped", () => {
this.stopWatch()
this.stopPoll()
@@ -60,11 +60,13 @@ class VariableWrapper<T> extends Function {
if (v instanceof Promise) {
v.then(v => this.set(v))
.catch(err => this.variable.emit("error", err))
} else {
}
else {
this.set(v)
}
})
} else if (this.pollExec) {
}
else if (this.pollExec) {
this._poll = interval(this.pollInterval, () => {
execAsync(this.pollExec!)
.then(v => this.set(this.pollTransform!(v, this.get())))
@@ -142,7 +144,8 @@ class VariableWrapper<T> extends Function {
if (typeof exec === "function") {
this.pollFn = exec
delete this.pollExec
} else {
}
else {
this.pollExec = exec
delete this.pollFn
}
@@ -183,7 +186,8 @@ class VariableWrapper<T> extends Function {
const [o, s] = obj
o.connect(s, set)
}
} else {
}
else {
if (typeof sigOrFn === "string")
objs.connect(sigOrFn, set)
}
@@ -195,7 +199,7 @@ class VariableWrapper<T> extends Function {
const Deps extends Array<Variable<any> | Binding<any>>,
Args extends {
[K in keyof Deps]: Deps[K] extends Variable<infer T>
? T : Deps[K] extends Binding<infer T> ? T : never
? T : Deps[K] extends Binding<infer T> ? T : never
},
>(deps: Deps, fn: (...args: Args) => V) {
const update = () => fn(...deps.map(d => d.get()) as Args)
@@ -216,7 +220,7 @@ export const Variable = new Proxy(VariableWrapper as any, {
}) as {
derive: typeof VariableWrapper["derive"]
<T>(init: T): Variable<T>
new <T>(init: T): Variable<T>
new<T>(init: T): Variable<T>
}
export default Variable
+30 -30
View File
@@ -5,14 +5,14 @@ import astalify, { type ConstructProps, type Widget } from "./astalify.js"
export { astalify, ConstructProps }
// Box
export type Box = Widget<typeof Astal.Box>
export type Box = Widget<Astal.Box>
export const Box = astalify<typeof Astal.Box, BoxProps, "Box">(Astal.Box)
export type BoxProps = ConstructProps<typeof Astal.Box, Astal.Box.ConstructorProperties>
export type BoxProps = ConstructProps<Astal.Box, Astal.Box.ConstructorProps>
// Button
export type Button = Widget<typeof Astal.Button>
export type Button = Widget<Astal.Button>
export const Button = astalify<typeof Astal.Button, ButtonProps, "Button">(Astal.Button)
export type ButtonProps = ConstructProps<typeof Astal.Button, Astal.Button.ConstructorProperties, {
export type ButtonProps = ConstructProps<Astal.Button, Astal.Button.ConstructorProps, {
onClicked: []
onClick: [event: Astal.ClickEvent]
onClickRelease: [event: Astal.ClickEvent]
@@ -22,31 +22,31 @@ export type ButtonProps = ConstructProps<typeof Astal.Button, Astal.Button.Const
}>
// CenterBox
export type CenterBox = Widget<typeof Astal.CenterBox>
export type CenterBox = Widget<Astal.CenterBox>
export const CenterBox = astalify<typeof Astal.CenterBox, CenterBoxProps, "CenterBox">(Astal.CenterBox)
export type CenterBoxProps = ConstructProps<typeof Astal.CenterBox, Astal.CenterBox.ConstructorProperties>
export type CenterBoxProps = ConstructProps<Astal.CenterBox, Astal.CenterBox.ConstructorProps>
// TODO: CircularProgress
// DrawingArea
export type DrawingArea = Widget<typeof Gtk.DrawingArea>
export type DrawingArea = Widget<Gtk.DrawingArea>
export const DrawingArea = astalify<typeof Gtk.DrawingArea, DrawingAreaProps, "DrawingArea">(Gtk.DrawingArea)
export type DrawingAreaProps = ConstructProps<typeof Gtk.DrawingArea, Gtk.DrawingArea.ConstructorProperties, {
export type DrawingAreaProps = ConstructProps<Gtk.DrawingArea, Gtk.DrawingArea.ConstructorProps, {
onDraw: [cr: any] // TODO: cairo types
}>
// Entry
export type Entry = Widget<typeof Gtk.Entry>
export type Entry = Widget<Gtk.Entry>
export const Entry = astalify<typeof Gtk.Entry, EntryProps, "Entry">(Gtk.Entry)
export type EntryProps = ConstructProps<typeof Gtk.Entry, Gtk.Entry.ConstructorProperties, {
export type EntryProps = ConstructProps<Gtk.Entry, Gtk.Entry.ConstructorProps, {
onChanged: []
onActivate: []
}>
// EventBox
export type EventBox = Widget<typeof Astal.EventBox>
export type EventBox = Widget<Astal.EventBox>
export const EventBox = astalify<typeof Astal.EventBox, EventBoxProps, "EventBox">(Astal.EventBox)
export type EventBoxProps = ConstructProps<typeof Astal.EventBox, Astal.EventBox.ConstructorProperties, {
export type EventBoxProps = ConstructProps<Astal.EventBox, Astal.EventBox.ConstructorProps, {
onClick: [event: Astal.ClickEvent]
onClickRelease: [event: Astal.ClickEvent]
onHover: [event: Astal.HoverEvent]
@@ -58,52 +58,52 @@ export type EventBoxProps = ConstructProps<typeof Astal.EventBox, Astal.EventBox
// TODO: FlowBox
// Icon
export type Icon = Widget<typeof Astal.Icon>
export type Icon = Widget<Astal.Icon>
export const Icon = astalify<typeof Astal.Icon, IconProps, "Icon">(Astal.Icon)
export type IconProps = ConstructProps<typeof Astal.Icon, Astal.Icon.ConstructorProperties>
export type IconProps = ConstructProps<Astal.Icon, Astal.Icon.ConstructorProps>
// Label
export type Label = Widget<typeof Gtk.Label>
export type Label = Widget<Gtk.Label>
export const Label = astalify<typeof Gtk.Label, LabelProps, "Label">(Gtk.Label)
export type LabelProps = ConstructProps<typeof Gtk.Label, Gtk.Label.ConstructorProperties>
export type LabelProps = ConstructProps<Gtk.Label, Gtk.Label.ConstructorProps>
// LevelBar
export type LevelBar = Widget<typeof Astal.LevelBar>
export type LevelBar = Widget<Astal.LevelBar>
export const LevelBar = astalify<typeof Astal.LevelBar, LevelBarProps, "LevelBar">(Astal.LevelBar)
export type LevelBarProps = ConstructProps<typeof Astal.LevelBar, Astal.LevelBar.ConstructorProperties>
export type LevelBarProps = ConstructProps<Astal.LevelBar, Astal.LevelBar.ConstructorProps>
// TODO: ListBox
// Overlay
export type Overlay = Widget<typeof Astal.Overlay>
export type Overlay = Widget<Astal.Overlay>
export const Overlay = astalify<typeof Astal.Overlay, OverlayProps, "Overlay">(Astal.Overlay)
export type OverlayProps = ConstructProps<typeof Astal.Overlay, Astal.Overlay.ConstructorProperties>
export type OverlayProps = ConstructProps<Astal.Overlay, Astal.Overlay.ConstructorProps>
// Revealer
export type Revealer = Widget<typeof Gtk.Revealer>
export type Revealer = Widget<Gtk.Revealer>
export const Revealer = astalify<typeof Gtk.Revealer, RevealerProps, "Revealer">(Gtk.Revealer)
export type RevealerProps = ConstructProps<typeof Gtk.Revealer, Gtk.Revealer.ConstructorProperties>
export type RevealerProps = ConstructProps<Gtk.Revealer, Gtk.Revealer.ConstructorProps>
// Scrollable
export type Scrollable = Widget<typeof Astal.Scrollable>
export type Scrollable = Widget<Astal.Scrollable>
export const Scrollable = astalify<typeof Astal.Scrollable, ScrollableProps, "Scrollable">(Astal.Scrollable)
export type ScrollableProps = ConstructProps<typeof Astal.Scrollable, Astal.Scrollable.ConstructorProperties>
export type ScrollableProps = ConstructProps<Astal.Scrollable, Astal.Scrollable.ConstructorProps>
// Slider
export type Slider = Widget<typeof Astal.Slider>
export type Slider = Widget<Astal.Slider>
export const Slider = astalify<typeof Astal.Slider, SliderProps, "Slider">(Astal.Slider)
export type SliderProps = ConstructProps<typeof Astal.Slider, Astal.Slider.ConstructorProperties, {
export type SliderProps = ConstructProps<Astal.Slider, Astal.Slider.ConstructorProps, {
onDragged: []
}>
// TODO: Stack
// Switch
export type Switch = Widget<typeof Gtk.Switch>
export type Switch = Widget<Gtk.Switch>
export const Switch = astalify<typeof Gtk.Switch, SwitchProps, "Switch">(Gtk.Switch)
export type SwitchProps = ConstructProps<typeof Gtk.Switch, Gtk.Switch.ConstructorProperties>
export type SwitchProps = ConstructProps<Gtk.Switch, Gtk.Switch.ConstructorProps>
// Window
export type Window = Widget<typeof Astal.Window>
export type Window = Widget<Astal.Window>
export const Window = astalify<typeof Astal.Window, WindowProps, "Window">(Astal.Window)
export type WindowProps = ConstructProps<typeof Astal.Window, Astal.Window.ConstructorProperties>
export type WindowProps = ConstructProps<Astal.Window, Astal.Window.ConstructorProps>
+1 -3
View File
@@ -14,11 +14,9 @@
"allowJs": true,
"jsx": "react-jsx",
"jsxImportSource": "./src/jsx",
"typeRoots": [
"./node_modules/@girs"
]
},
"include": [
"./node_modules/@girs",
"./src/**/*",
"./index.ts",
]