Skip to content

Commit

Permalink
chore: set max print width to 75 in prettier + rustfmt configs (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Dec 19, 2023
1 parent a3d0fdf commit eb32734
Show file tree
Hide file tree
Showing 47 changed files with 1,661 additions and 592 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"semi": true,
"singleQuote": true,
"printWidth": 80,
"printWidth": 75,
"tabWidth": 2,
"trailingComma": "all",
"arrowParens": "avoid"
Expand Down
5 changes: 1 addition & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"rust-lang.rust-analyzer"
]
"recommendations": ["esbenp.prettier-vscode", "rust-lang.rust-analyzer"]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"build": "turbo run build",
"dev": "turbo run dev --continue",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md,html,json,js,yaml,scss}\" --ignore-path .gitignore"
"format": "prettier --write \"**/*.{ts,tsx,md,html,json,js,yaml,scss}\" && turbo run format"
},
"devDependencies": {
"prettier": "2.8.7",
"prettier": "3.1.1",
"turbo": "1.9.3"
},
"engines": {
Expand Down
4 changes: 3 additions & 1 deletion packages/client-api/src/desktop/current-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export interface WindowStyles {

const logger = createLogger('current-window');

export async function setWindowPosition(position: Partial<WindowPosition>) {
export async function setWindowPosition(
position: Partial<WindowPosition>,
) {
logger.debug(`Setting window position to:`, position);

const window = await getCurrentWindow();
Expand Down
9 changes: 7 additions & 2 deletions packages/client-api/src/desktop/desktop-commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { InvokeArgs, invoke as tauriInvoke } from '@tauri-apps/api/primitives';
import {
InvokeArgs,
invoke as tauriInvoke,
} from '@tauri-apps/api/primitives';

import { createLogger } from '../utils';
import { ProviderConfig } from '~/user-config';
Expand All @@ -19,7 +22,9 @@ export function readConfigFile(): Promise<string> {
export function getOpenWindowArgs(
windowLabel: string,
): Promise<OpenWindowArgs | null> {
return invoke<OpenWindowArgs | null>('get_open_window_args', { windowLabel });
return invoke<OpenWindowArgs | null>('get_open_window_args', {
windowLabel,
});
}

// TODO: Add support for only fetching selected variables.
Expand Down
9 changes: 7 additions & 2 deletions packages/client-api/src/init-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export async function initElement(
runWithOwner(args.owner, () => {
createEffect(() => {
if (parsedConfig.styles) {
styleBuilder.setElementStyles(parsedConfig.id, parsedConfig.styles);
styleBuilder.setElementStyles(
parsedConfig.id,
parsedConfig.styles,
);
}
});
});
Expand Down Expand Up @@ -80,7 +83,9 @@ export async function initElement(
/**
* Get child element configs.
*/
function getChildConfigs(config: WindowConfig | GroupConfig | TemplateConfig) {
function getChildConfigs(
config: WindowConfig | GroupConfig | TemplateConfig,
) {
return Object.entries(config).filter(
(
entry,
Expand Down
4 changes: 3 additions & 1 deletion packages/client-api/src/init-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export async function initWindowAsync(): Promise<ElementContext> {
];

if (!windowConfig) {
throw new Error(`Window '${openArgs.windowId}' doesn't exist in config.`);
throw new Error(
`Window '${openArgs.windowId}' doesn't exist in config.`,
);
}

const windowContext = await initElement({
Expand Down
14 changes: 9 additions & 5 deletions packages/client-api/src/providers/create-provider-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ import {
runWithOwner,
} from 'solid-js';

import { onProviderEmit, listenProvider, unlistenProvider } from '~/desktop';
import {
onProviderEmit,
listenProvider,
unlistenProvider,
} from '~/desktop';
import { ProviderConfig } from '~/user-config';
import { simpleHash } from '~/utils';

/**
* Utility for listening to a provider of a given config type.
*/
export function createProviderListener<TConfig extends ProviderConfig, TVars>(
config: TConfig,
owner: Owner,
): Promise<Accessor<TVars>> {
export function createProviderListener<
TConfig extends ProviderConfig,
TVars,
>(config: TConfig, owner: Owner): Promise<Accessor<TVars>> {
return new Promise(async resolve => {
const [payload, setPayload] = createSignal<TVars>();

Expand Down
5 changes: 4 additions & 1 deletion packages/client-api/src/providers/create-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { createSystemTrayProvider } from './system-tray/create-system-tray-provi
import { createWeatherProvider } from './weather/create-weather-provider';
import { ProviderConfig } from '~/user-config';

export async function createProvider(config: ProviderConfig, owner: Owner) {
export async function createProvider(
config: ProviderConfig,
owner: Owner,
) {
switch (config.type) {
case 'active_window':
return createActiveWindowProvider(config);
Expand Down
8 changes: 5 additions & 3 deletions packages/client-api/src/providers/get-element-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export async function getElementProviders(
) {
const [elementProviders, _] = createSignal(await getElementProviders());

const [mergedProviders, setMergedProviders] =
createStore(getMergedProviders());
const [mergedProviders, setMergedProviders] = createStore(
getMergedProviders(),
);

// Update the store on changes to any provider variables.
runWithOwner(owner, () => {
Expand All @@ -41,7 +42,8 @@ export async function getElementProviders(
// Create tuple of configs and the created provider.
const providers = await Promise.all(
providerConfigs.map(
async config => [config, await createProvider(config, owner)] as const,
async config =>
[config, await createProvider(config, owner)] as const,
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export async function createGlazewmProvider(

// Get GlazeWM monitor that corresponds to the bar's monitor.
const monitor = monitors.reduce((a, b) =>
getDistance(currentPosition, a) < getDistance(currentPosition, b) ? a : b,
getDistance(currentPosition, a) < getDistance(currentPosition, b)
? a
: b,
);

setGlazewmVariables({ workspaces: monitor.children });
Expand Down
5 changes: 4 additions & 1 deletion packages/client-api/src/providers/ip/create-ip-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export interface IpVariables {
approxLongitude: number;
}

export async function createIpProvider(config: IpProviderConfig, owner: Owner) {
export async function createIpProvider(
config: IpProviderConfig,
owner: Owner,
) {
const ipVariables = await createProviderListener<
IpProviderConfig,
IpVariables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export interface SelfVariables {
env: Record<string, string>;
}

export async function createSelfProvider(_: SelfProviderConfig, __: Owner) {
export async function createSelfProvider(
_: SelfProviderConfig,
__: Owner,
) {
const [selfVariables] = createStore<SelfVariables>(await getVariables());

async function getVariables() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export interface RenderContext {
}

/** Pattern for the expression in a for loop statement. */
const FOR_LOOP_EXPRESSION_PATTERN = /^\s*([(),\s0-9A-Za-z_$]*)\s+of\s+(.*)/;
const FOR_LOOP_EXPRESSION_PATTERN =
/^\s*([(),\s0-9A-Za-z_$]*)\s+of\s+(.*)/;

/** Pattern for the loop variable on the left-side of a for loop expression. */
const FOR_LOOP_VARIABLE_PATTERN =
Expand Down Expand Up @@ -67,7 +68,8 @@ export function renderTemplateNodes(
function visitIfStatementNode(node: IfStatementNode): string {
for (const branch of node.branches) {
const shouldVisit =
branch.type === 'else' || Boolean(evalExpression(branch.expression));
branch.type === 'else' ||
Boolean(evalExpression(branch.expression));

if (shouldVisit) {
return visitAll(branch.children);
Expand Down Expand Up @@ -100,7 +102,9 @@ export function renderTemplateNodes(

function parseForExpression(expression: string) {
try {
const expressionMatch = expression.match(FOR_LOOP_EXPRESSION_PATTERN);
const expressionMatch = expression.match(
FOR_LOOP_EXPRESSION_PATTERN,
);
const [_, loopVariableExpression, iterable] = expressionMatch ?? [];

if (!loopVariableExpression || !iterable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ export interface InExpressionState {
activeWrappingSymbol: string | null;
}

export type TokenizeState = { type: TokenizeStateType } | InExpressionState;
export type TokenizeState =
| { type: TokenizeStateType }
| InExpressionState;

export function tokenizeTemplate(template: string): Token[] {
// Stack of tokenize states. Last element represents current state.
const stateStack: TokenizeState[] = [{ type: TokenizeStateType.DEFAULT }];
const stateStack: TokenizeState[] = [
{ type: TokenizeStateType.DEFAULT },
];

// Tokens within input template.
const tokens: Token[] = [];
Expand All @@ -45,7 +49,9 @@ export function tokenizeTemplate(template: string): Token[] {
// Push a tokenize state.
function pushState(typeOrState: TokenizeStateType | TokenizeState) {
const state =
typeof typeOrState === 'object' ? typeOrState : { type: typeOrState };
typeof typeOrState === 'object'
? typeOrState
: { type: typeOrState };

stateStack.push(state);
}
Expand Down Expand Up @@ -238,7 +244,10 @@ export function tokenizeTemplate(template: string): Token[] {
}
}

function getActiveWrappingSymbol(current: string | null, matched: string) {
function getActiveWrappingSymbol(
current: string | null,
matched: string,
) {
const isOpeningSymbol = matched !== ')';

// Set active wrapping symbol to the matched symbol.
Expand Down
6 changes: 3 additions & 3 deletions packages/client-api/src/user-config/get-style-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { createLogger, toCssSelector } from '~/utils';
const logger = createLogger('style-builder');

const [globalStyles, setGlobalStyles] = createSignal<string | null>(null);
const [elementStyles, setElementStyles] = createStore<Record<string, string>>(
{},
);
const [elementStyles, setElementStyles] = createStore<
Record<string, string>
>({});

/**
* Abstraction over building CSS from user-defined styles.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ export function formatConfigError(err: unknown) {
);
}

return new Error(`Problem reading config file: ${(err as Error).message}.`);
return new Error(
`Problem reading config file: ${(err as Error).message}.`,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const ScriptVariableConfigSchema = z.object({
refresh_interval_ms: z.coerce.number().default(5 * 1000),
});

export type ScriptVariableConfig = z.infer<typeof ScriptVariableConfigSchema>;
export type ScriptVariableConfig = z.infer<
typeof ScriptVariableConfigSchema
>;
3 changes: 2 additions & 1 deletion packages/client-api/src/user-config/user-config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export type UserConfigP1 = Prettify<z.infer<typeof UserConfigP1Schema>>;

// Add `window/**` keys to schema.
export const UserConfigSchema = withDynamicKey(UserConfigP1Schema, {
isKey: (key: string): key is `window/${string}` => key.startsWith('window/'),
isKey: (key: string): key is `window/${string}` =>
key.startsWith('window/'),
schema: WindowConfigSchema,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ export const ProviderConfigSchema = z.union([
WeatherProviderConfigSchema,
]);

export type ProviderConfig = Prettify<z.infer<typeof ProviderConfigSchema>>;
export type ProviderConfig = Prettify<
z.infer<typeof ProviderConfigSchema>
>;
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export const ProvidersConfigSchema = z
)
.default([]);

export type ProvidersConfig = Prettify<z.infer<typeof ProvidersConfigSchema>>;
export type ProvidersConfig = Prettify<
z.infer<typeof ProvidersConfigSchema>
>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const BatteryProviderConfigSchema = z.object({
refresh_interval_ms: z.coerce.number().default(60 * 1000),
});

export type BatteryProviderConfig = z.infer<typeof BatteryProviderConfigSchema>;
export type BatteryProviderConfig = z.infer<
typeof BatteryProviderConfigSchema
>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export const GlazewmProviderConfigSchema = z.object({
type: z.literal('glazewm'),
});

export type GlazewmProviderConfig = z.infer<typeof GlazewmProviderConfigSchema>;
export type GlazewmProviderConfig = z.infer<
typeof GlazewmProviderConfigSchema
>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const MemoryProviderConfigSchema = z.object({
type: z.literal('memory'),
});

export type MemoryProviderConfig = z.infer<typeof MemoryProviderConfigSchema>;
export type MemoryProviderConfig = z.infer<
typeof MemoryProviderConfigSchema
>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export const NetworkProviderConfigSchema = z.object({
refresh_interval_ms: z.coerce.number().default(5 * 1000),
});

export type NetworkProviderConfig = z.infer<typeof NetworkProviderConfigSchema>;
export type NetworkProviderConfig = z.infer<
typeof NetworkProviderConfigSchema
>;
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export const WeatherProviderConfigSchema = z.object({
refresh_interval_ms: z.coerce.number().default(60 * 60 * 1000),
});

export type WeatherProviderConfig = z.infer<typeof WeatherProviderConfigSchema>;
export type WeatherProviderConfig = z.infer<
typeof WeatherProviderConfigSchema
>;
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ export const TemplateConfigSchemaP1 = BaseElementConfigSchema.extend({
});

// Add `slot/**` keys to schema.
export const TemplateConfigSchema = withDynamicKey(TemplateConfigSchemaP1, {
isKey: (key: string): key is `slot/${string}` => key.startsWith('slot/'),
schema: z.string(),
});
export const TemplateConfigSchema = withDynamicKey(
TemplateConfigSchemaP1,
{
isKey: (key: string): key is `slot/${string}` =>
key.startsWith('slot/'),
schema: z.string(),
},
);

export type TemplateConfig = z.infer<typeof TemplateConfigSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ export const WindowConfigSchemaP1 = BaseElementConfigSchema.extend({
resizable: BooleanLikeSchema.optional(),
});

export type WindowConfigP1 = Prettify<z.infer<typeof WindowConfigSchemaP1>>;
export type WindowConfigP1 = Prettify<
z.infer<typeof WindowConfigSchemaP1>
>;

// Add `group/**` keys to schema.
// TODO: Should be able to have `template/` as a child of window config.
export const WindowConfigSchema = withDynamicKey(WindowConfigSchemaP1, {
isKey: (key: string): key is `group/${string}` => key.startsWith('group/'),
isKey: (key: string): key is `group/${string}` =>
key.startsWith('group/'),
schema: GroupConfigSchema,
});

Expand Down
Loading

0 comments on commit eb32734

Please sign in to comment.