Skip to content

Add ESLint #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"trailingComma": "all",
"endOfLine": "lf",
"tabWidth": 2,
"printWidth": 100,
"semi": true,
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"eslint.useFlatConfig": true,
"eslint.workingDirectories": [{ "mode": "auto" }],
"eslint.options": {
"overrideConfigFile": "./eslint.config.js"
}
}
30 changes: 15 additions & 15 deletions entries/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import type { SampleEntry } from './all';
import type * as BOXES from './all-boxes';

type AllBoxes = Partial<typeof BOXES> & Partial<typeof UUID_BOXES>;
export namespace MP4Box {
export interface BoxRegistry extends AllBoxes {}
export interface DescriptorRegistry extends Partial<typeof DESCRIPTORS> {}
}

export type BoxRegistry = AllBoxes;
export type DescriptorRegistry = Partial<typeof DESCRIPTORS>;

export type TypedArray<T extends ArrayBufferLike = ArrayBuffer> =
| Int8Array<T>
Expand All @@ -26,19 +25,19 @@ export type TypedArray<T extends ArrayBufferLike = ArrayBuffer> =
| BigUint64Array<T>;

export type ValueOf<T> = T[keyof T];
export type InstanceOf<T> = T extends new (...args: Array<any>) => infer R ? R : never;
export type InstanceOf<T> = T extends new (...args: Array<unknown>) => infer R ? R : never;
export type KindOf<T> = InstanceOf<ValueOf<T>>;
export type Extends<TObject, TExtends> = {
[TKey in keyof TObject]: TObject[TKey] extends TExtends ? TObject[TKey] : undefined;
}[keyof TObject];

export type TupleOf<T, N extends number, R extends T[] = []> = R['length'] extends N
export type TupleOf<T, N extends number, R extends Array<T> = []> = R['length'] extends N
? R
: TupleOf<T, N, [T, ...R]>;
export type NumberTuple<T extends number> = TupleOf<number, T>;

export type BoxKind = InstanceOf<Extends<MP4Box.BoxRegistry, typeof Box>>;
export type SampleEntryKind = InstanceOf<Extends<MP4Box.BoxRegistry, typeof SampleEntry>>;
export type BoxKind = InstanceOf<Extends<BoxRegistry, typeof Box>>;
export type SampleEntryKind = InstanceOf<Extends<BoxRegistry, typeof SampleEntry>>;

export interface FragmentedTrack<TUser> {
id: number;
Expand Down Expand Up @@ -99,7 +98,7 @@ export interface Track {
created: Date;
cts_shift: BOXES.cslgBox;
duration: number;
edits?: Entry[];
edits?: Array<Entry>;
id: number;
kind: BOXES.kindBox | { schemeURI: ''; value: '' };
language: string;
Expand Down Expand Up @@ -150,14 +149,14 @@ export interface Description {
version: number;
}

export type IncompleteBox = {
export interface IncompleteBox {
box?: Box;
code: number;
hdr_size?: number;
size?: number;
start?: number;
type?: string;
};
}

export interface Item {
alreadyRead?: number;
Expand Down Expand Up @@ -301,10 +300,11 @@ export type StringType =
| EncodedLengthStringType
| EndianStringType;

export type GetterSetterType<T = any> = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface GetterSetterType<T = any> {
get(dataStream: DataStream, struct: Record<string, Type>): T;
set?(dataStream: DataStream, value: T, struct?: Record<string, Type>): void;
};
}

export type TupleType = [
'[]',
Expand All @@ -317,7 +317,7 @@ export type TupleType = [
),
];

export type FnType = <T = any>(dataStream: DataStream, struct: T) => number;
export type FnType = <T = unknown>(dataStream: DataStream, struct: T) => number;

export type Type =
| NumberType
Expand Down Expand Up @@ -360,7 +360,7 @@ export type ValueFromType<TValue extends Type> = TValue extends StringType
: never;

export type StructDataFromStructDefinition<T extends StructDefinition> = {
[TKey in T[number][0]]: Extract<T[number], [TKey, any]>[1] extends infer TValue
[TKey in T[number][0]]: Extract<T[number], [TKey, unknown]>[1] extends infer TValue
? TValue extends Type
? ValueFromType<TValue>
: never
Expand Down
33 changes: 33 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPlugin from 'eslint-plugin-prettier/recommended';

export default tseslint.config(
{ ignores: ['dist', '**/*.{mjs,js}'] },
eslint.configs.recommended,

tseslint.configs.strict,
tseslint.configs.stylistic,
{
rules: {
// Override no-unused-vars to allow unused variables that start with an underscore
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
// Disable the base rule 'no-unused-vars' to avoid conflicts with TypeScript's rule
'no-unused-vars': 'off',
// Disable @typescript-eslint/prefer-for-of we have too much for now
'@typescript-eslint/prefer-for-of': 'off',
// Prefer to use Array<T> over T[]
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
// Use interfaces for object type definitions
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
// Don't require curly braces for simple if statements
curly: ['error', 'multi-line'],
// Enforce strict equality checks
eqeqeq: 'error',
},
},
eslintPlugin,
);
Loading