Skip to content

Commit

Permalink
Miscellaneous refactors (#1762)
Browse files Browse the repository at this point in the history
* Update file form key

* Update links in ESLint config

* Disable unicorn/better-regex ESLint rule

* Be more specific in gitignore rules

* Refactor Zod number schemas into a separate file

* Add tsc to `npm run lint`
  • Loading branch information
stephenwade authored Sep 23, 2024
1 parent ab1eb78 commit 89dba58
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
11 changes: 4 additions & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ module.exports = {

// Comments link to blockers for flat config
plugins: [
// https://github.com/import-js/eslint-plugin-import/pull/2873
// https://github.com/import-js/eslint-plugin-import/pull/3061
// https://github.com/import-js/eslint-plugin-import/issues/2948
// https://github.com/un-ts/eslint-plugin-import-x/issues/29
// https://github.com/un-ts/eslint-plugin-import-x/issues/90
'import',
// https://github.com/levibuzolic/eslint-plugin-no-only-tests/issues/43
'no-only-tests',
'simple-import-sort',
'unused-imports',
Expand All @@ -20,17 +19,13 @@ module.exports = {
extends: [
'eslint:recommended',

// https://github.com/jsx-eslint/eslint-plugin-react/issues/3699
'plugin:react/recommended',
'plugin:react/jsx-runtime',
// https://github.com/facebook/react/issues/28313
'plugin:react-hooks/recommended',
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/891
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/978
'plugin:jsx-a11y/recommended',
'plugin:playwright/recommended',

// https://github.com/typescript-eslint/typescript-eslint/milestone/9
'plugin:@typescript-eslint/strict-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',

Expand All @@ -40,6 +35,7 @@ module.exports = {
],

rules: {
'no-plusplus': 'error',
'object-shorthand': 'warn',
quotes: ['warn', 'single', { avoidEscape: true }],
'require-unicode-regexp': 'warn',
Expand Down Expand Up @@ -90,6 +86,7 @@ module.exports = {
requireDefaultForNonUnion: true,
},
],
'unicorn/better-regex': 'off',
'unicorn/filename-case': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/no-null': 'off',
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.DS_Store
node_modules/
.cache/
build/
/build/
.env*

# runtime
upload
/upload

# Playwright
/test-results/
Expand Down
2 changes: 1 addition & 1 deletion app/ffmpeg.server/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { spawn } from 'node:child_process';

import { z } from 'zod';

const integerString = z.string().regex(/^\d+$/u).transform(Number);
import { integerString } from '~/utils/zod-number-schemas';

/**
* Parses a string containing progress output in `key=value` format from FFmpeg.
Expand Down
5 changes: 1 addition & 4 deletions app/ffmpeg.server/ffprobe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { spawn } from 'node:child_process';

import { z } from 'zod';

const numericString = z
.string()
.regex(/^\d+(?:\.\d+)?$/u)
.transform(Number);
import { numericString } from '~/utils/zod-number-schemas';

/**
* Parses a string containing JSON output from `ffprobe`.
Expand Down
2 changes: 1 addition & 1 deletion app/forms/show/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const setSchema = z.object({
audioFileId: zfd.text(z.string().optional()),
});

const COLOR_REGEX = /^#[\da-f]{6}$/iu;
const COLOR_REGEX = /^#[0-9a-f]{6}$/iu;

function isValidTimeZone(timeZone: string): boolean {
try {
Expand Down
2 changes: 1 addition & 1 deletion app/forms/upload-file.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const UPLOAD_FILE_FORM_KEY = 'uploadFile';
export const UPLOAD_FILE_FORM_KEY = 'file';
11 changes: 11 additions & 0 deletions app/utils/zod-number-schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from 'zod';

export const integerString = z
.string()
.regex(/^[0-9]+$/u)
.transform(Number);

export const numericString = z
.string()
.regex(/^[0-9]+(?:\.[0-9]+)?$/u)
.transform(Number);
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
"lint:eslint": "eslint . --ignore-path .gitignore --max-warnings 0",
"lint:stylelint": "stylelint \"**/*.css\" --ignore-path .gitignore --max-warnings 0",
"lint:prettier": "prettier . --check --ignore-path .gitignore --log-level warn",
"lint:dpdm": "dpdm 'app/routes/*' --no-tree --no-warning --exit-code circular:1",
"lint:knip": "knip-bun",
"lint:dpdm": "dpdm 'app/routes/*' --no-tree --no-warning --exit-code circular:1",
"lint:tsc": "tsc",
"lint": "npm-run-all lint:*",
"format:eslint": "eslint . --fix --ignore-path .gitignore",
"format:stylelint": "stylelint \"**/*.css\" --fix --ignore-path .gitignore",
"format:prettier": "prettier . --write --ignore-path .gitignore --log-level warn",
"format:knip": "knip-bun --fix",
"format": "npm-run-all format:* lint:dpdm",
"format": "npm-run-all format:*",
"test": "playwright test",
"test-ct": "playwright test -c playwright-ct.config.ts"
},
Expand Down
4 changes: 2 additions & 2 deletions playwright/ct-tests/AudioController/AudioController.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ function commonTests({ forceSkipAudioContext = false }) {
await expect(
component.locator('audio').nth(0),
'10 seconds before the end of the first set',
).toHaveAttribute('src', /\?1(#t=\d+)?$/u);
).toHaveAttribute('src', /\?1(#t=[0-9]+)?$/u);

await component.getByTestId('alternate-button').click();

await page.waitForTimeout(1000);
await expect(
component.locator('audio').nth(0),
'9 seconds before the end of the first set',
).toHaveAttribute('src', /\?1(#t=\d+)?$/u);
).toHaveAttribute('src', /\?1(#t=[0-9]+)?$/u);
});
});

Expand Down

0 comments on commit 89dba58

Please sign in to comment.