Skip to content
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
7 changes: 4 additions & 3 deletions benchmarks/typescript/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { hrtime } from 'process';
// oxlint-disable no-console -- The benchmark reports measurements to stdout.
import { hrtime } from 'node:process';
import { Message, Struct } from '../generated/types';

const pathologicalIterations = 5_000;
Expand Down Expand Up @@ -66,10 +67,10 @@ const s64TestValues: bigint[] = [
s64Max,
];

function benchmark<T, U, V extends { $size: number }>(
function benchmark<T, V extends { $size: number }>(
atlas: (message: T) => V,
serializeWithAtlasUnsafe: (dataView: DataView, offset: number, message: T, atlas: V) => number,
deserialize: (dataView: DataView) => U,
deserialize: (dataView: DataView) => unknown,
message: T,
iterations: number,
): void {
Expand Down
10 changes: 8 additions & 2 deletions benchmarks/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"compilerOptions": {
"target": "es2023",
"module": "nodenext",
"moduleDetection": "force",
"outDir": "dist",
"types": ["node"]
"types": ["node"],
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"strict": true
},
"include": ["src"]
"include": ["src", "vite.config.ts"]
}
124 changes: 6 additions & 118 deletions benchmarks/typescript/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { defineConfig } from 'vite-plus';

export default defineConfig({
fmt: {
ignorePatterns: ['**/*.md'],
singleQuote: true,
},
lint: {
categories: {
correctness: 'deny',
perf: 'deny',
restriction: 'deny',
suspicious: 'deny',
},
jsPlugins: [
{
Expand All @@ -18,126 +22,10 @@ export default defineConfig({
typeAware: true,
typeCheck: true,
},
overrides: [
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
rules: {
'constructor-super': 'error',
'for-direction': 'error',
'getter-return': 'error',
'no-async-promise-executor': 'error',
'no-case-declarations': 'error',
'no-class-assign': 'error',
'no-compare-neg-zero': 'error',
'no-cond-assign': 'error',
'no-const-assign': 'error',
'no-constant-binary-expression': 'error',
'no-constant-condition': 'error',
'no-control-regex': 'error',
'no-debugger': 'error',
'no-delete-var': 'error',
'no-dupe-class-members': 'error',
'no-dupe-else-if': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-empty': 'error',
'no-empty-character-class': 'error',
'no-empty-pattern': 'error',
'no-empty-static-block': 'error',
'no-ex-assign': 'error',
'no-extra-boolean-cast': 'error',
'no-fallthrough': 'error',
'no-func-assign': 'error',
'no-global-assign': 'error',
'no-import-assign': 'error',
'no-invalid-regexp': 'error',
'no-irregular-whitespace': 'error',
'no-loss-of-precision': 'error',
'no-misleading-character-class': 'error',
'no-new-native-nonconstructor': 'error',
'no-nonoctal-decimal-escape': 'error',
'no-obj-calls': 'error',
'no-prototype-builtins': 'error',
'no-redeclare': 'error',
'no-regex-spaces': 'error',
'no-self-assign': 'error',
'no-setter-return': 'error',
'no-shadow-restricted-names': 'error',
'no-sparse-arrays': 'error',
'no-this-before-super': 'error',
'no-unassigned-vars': 'error',
'no-undef': 'error',
'no-unexpected-multiline': 'error',
'no-unreachable': 'error',
'no-unsafe-finally': 'error',
'no-unsafe-negation': 'error',
'no-unsafe-optional-chaining': 'error',
'no-unused-labels': 'error',
'no-unused-private-class-members': 'error',
'no-useless-assignment': 'error',
'no-useless-backreference': 'error',
'no-useless-catch': 'error',
'no-useless-escape': 'error',
'no-with': 'error',
'preserve-caught-error': 'error',
'require-yield': 'error',
'use-isnan': 'error',
'valid-typeof': 'error',
},
env: {
node: true,
},
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
rules: {
'constructor-super': 'off',
'getter-return': 'off',
'no-class-assign': 'off',
'no-const-assign': 'off',
'no-dupe-class-members': 'off',
'no-dupe-keys': 'off',
'no-func-assign': 'off',
'no-import-assign': 'off',
'no-new-native-nonconstructor': 'off',
'no-obj-calls': 'off',
'no-redeclare': 'off',
'no-setter-return': 'off',
'no-this-before-super': 'off',
'no-undef': 'off',
'no-unreachable': 'off',
'no-unsafe-negation': 'off',
'no-var': 'error',
'no-with': 'off',
'prefer-const': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
},
},
],
plugins: ['oxc', 'typescript', 'unicorn'],
rules: {
'no-array-constructor': 'error',
'no-unused-expressions': 'error',
'no-unused-vars': 'error',
'typescript/ban-ts-comment': 'error',
'typescript/no-duplicate-enum-values': 'error',
'typescript/no-empty-object-type': 'error',
'typescript/no-explicit-any': 'error',
'typescript/no-extra-non-null-assertion': 'error',
'typescript/no-misused-new': 'error',
'typescript/no-namespace': 'error',
'typescript/no-non-null-asserted-optional-chain': 'error',
'typescript/no-require-imports': 'error',
'typescript/no-this-alias': 'error',
'typescript/no-unnecessary-type-constraint': 'error',
'typescript/no-unsafe-declaration-merging': 'error',
'typescript/no-unsafe-function-type': 'error',
'typescript/no-wrapper-object-types': 'error',
'typescript/prefer-as-const': 'error',
'typescript/prefer-namespace-keyword': 'error',
'typescript/triple-slash-reference': 'error',
'vite-plus/prefer-vite-plus-imports': 'error',
'no-undefined': 'allow',
'oxc/no-async-await': 'allow',
},
},
});
3 changes: 2 additions & 1 deletion examples/typescript/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFileSync, writeFileSync, unlinkSync } from 'fs';
// oxlint-disable no-console -- This example prints its observable output to stdout.
import { readFileSync, unlinkSync, writeFileSync } from 'node:fs';
import { unreachable } from '../generated/common';
import { SendEmailRequest, SendEmailResponse } from '../generated/types';

Expand Down
10 changes: 8 additions & 2 deletions examples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"compilerOptions": {
"target": "es2023",
"module": "nodenext",
"moduleDetection": "force",
"outDir": "dist",
"types": ["node"]
"types": ["node"],
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"strict": true
},
"include": ["src"]
"include": ["src", "vite.config.ts"]
}
124 changes: 6 additions & 118 deletions examples/typescript/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { defineConfig } from 'vite-plus';

export default defineConfig({
fmt: {
ignorePatterns: ['**/*.md'],
singleQuote: true,
},
lint: {
categories: {
correctness: 'deny',
perf: 'deny',
restriction: 'deny',
suspicious: 'deny',
},
jsPlugins: [
{
Expand All @@ -18,126 +22,10 @@ export default defineConfig({
typeAware: true,
typeCheck: true,
},
overrides: [
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
rules: {
'constructor-super': 'error',
'for-direction': 'error',
'getter-return': 'error',
'no-async-promise-executor': 'error',
'no-case-declarations': 'error',
'no-class-assign': 'error',
'no-compare-neg-zero': 'error',
'no-cond-assign': 'error',
'no-const-assign': 'error',
'no-constant-binary-expression': 'error',
'no-constant-condition': 'error',
'no-control-regex': 'error',
'no-debugger': 'error',
'no-delete-var': 'error',
'no-dupe-class-members': 'error',
'no-dupe-else-if': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-empty': 'error',
'no-empty-character-class': 'error',
'no-empty-pattern': 'error',
'no-empty-static-block': 'error',
'no-ex-assign': 'error',
'no-extra-boolean-cast': 'error',
'no-fallthrough': 'error',
'no-func-assign': 'error',
'no-global-assign': 'error',
'no-import-assign': 'error',
'no-invalid-regexp': 'error',
'no-irregular-whitespace': 'error',
'no-loss-of-precision': 'error',
'no-misleading-character-class': 'error',
'no-new-native-nonconstructor': 'error',
'no-nonoctal-decimal-escape': 'error',
'no-obj-calls': 'error',
'no-prototype-builtins': 'error',
'no-redeclare': 'error',
'no-regex-spaces': 'error',
'no-self-assign': 'error',
'no-setter-return': 'error',
'no-shadow-restricted-names': 'error',
'no-sparse-arrays': 'error',
'no-this-before-super': 'error',
'no-unassigned-vars': 'error',
'no-undef': 'error',
'no-unexpected-multiline': 'error',
'no-unreachable': 'error',
'no-unsafe-finally': 'error',
'no-unsafe-negation': 'error',
'no-unsafe-optional-chaining': 'error',
'no-unused-labels': 'error',
'no-unused-private-class-members': 'error',
'no-useless-assignment': 'error',
'no-useless-backreference': 'error',
'no-useless-catch': 'error',
'no-useless-escape': 'error',
'no-with': 'error',
'preserve-caught-error': 'error',
'require-yield': 'error',
'use-isnan': 'error',
'valid-typeof': 'error',
},
env: {
node: true,
},
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
rules: {
'constructor-super': 'off',
'getter-return': 'off',
'no-class-assign': 'off',
'no-const-assign': 'off',
'no-dupe-class-members': 'off',
'no-dupe-keys': 'off',
'no-func-assign': 'off',
'no-import-assign': 'off',
'no-new-native-nonconstructor': 'off',
'no-obj-calls': 'off',
'no-redeclare': 'off',
'no-setter-return': 'off',
'no-this-before-super': 'off',
'no-undef': 'off',
'no-unreachable': 'off',
'no-unsafe-negation': 'off',
'no-var': 'error',
'no-with': 'off',
'prefer-const': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
},
},
],
plugins: ['oxc', 'typescript', 'unicorn'],
rules: {
'no-array-constructor': 'error',
'no-unused-expressions': 'error',
'no-unused-vars': 'error',
'typescript/ban-ts-comment': 'error',
'typescript/no-duplicate-enum-values': 'error',
'typescript/no-empty-object-type': 'error',
'typescript/no-explicit-any': 'error',
'typescript/no-extra-non-null-assertion': 'error',
'typescript/no-misused-new': 'error',
'typescript/no-namespace': 'error',
'typescript/no-non-null-asserted-optional-chain': 'error',
'typescript/no-require-imports': 'error',
'typescript/no-this-alias': 'error',
'typescript/no-unnecessary-type-constraint': 'error',
'typescript/no-unsafe-declaration-merging': 'error',
'typescript/no-unsafe-function-type': 'error',
'typescript/no-wrapper-object-types': 'error',
'typescript/prefer-as-const': 'error',
'typescript/prefer-namespace-keyword': 'error',
'typescript/triple-slash-reference': 'error',
'vite-plus/prefer-vite-plus-imports': 'error',
'no-undefined': 'allow',
'oxc/no-async-await': 'allow',
},
},
});
18 changes: 9 additions & 9 deletions integration_tests/typescript_node/src/assertions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { deepStrictEqual } from 'assert';
import { unlinkSync, writeFileSync } from 'fs';
// oxlint-disable no-console -- Integration tests print serialized messages for diagnostics.
import { deepStrictEqual } from 'node:assert';
import { unlinkSync, writeFileSync } from 'node:fs';

// The "omnifile" records the bytes of every message serialized by the exported functions below.
// It's used to validate that the TypeScript code generator encodes data identically to other code
Expand All @@ -8,15 +9,14 @@ const omnifilePath = '/tmp/omnifile-typescript';

try {
unlinkSync(omnifilePath);
// oxlint-disable-next-line @typescript-eslint/no-unused-vars
} catch (_) {
} catch {
// Attempting to delete the file will fail if the file doesn't exist. This is harmless.
}

export function assertMatch<O, I>(
export function assertMatch<O>(
size: (message: O) => number,
serialize: (message: O) => ArrayBuffer,
deserialize: (bytes: ArrayBuffer) => I,
deserialize: (bytes: ArrayBuffer) => unknown,
actual: O,
expected: unknown,
): void {
Expand All @@ -37,11 +37,11 @@ export function assertMatch<O, I>(
console.log('Message deserialized from those bytes:', replica);
}

export function assertRoundTrip<O, I, V extends O>(
export function assertRoundTrip<O>(
size: (message: O) => number,
serialize: (message: O) => ArrayBuffer,
deserialize: (bytes: ArrayBuffer) => I,
message: V,
deserialize: (bytes: ArrayBuffer) => unknown,
message: O,
): void {
assertMatch(size, serialize, deserialize, message, message);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// oxlint-disable no-console -- Integration tests print progress between cases.
import { StructFromBelow } from '../generated/circular_dependency/dependency/types';
import { StructFromAbove } from '../generated/circular_dependency/types';
import { assertRoundTrip } from './assertions';
Expand Down
Loading
Loading