Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
stricter lint
Browse files Browse the repository at this point in the history
  • Loading branch information
threepointone committed Nov 29, 2024
1 parent b0ab510 commit 377d180
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
57 changes: 30 additions & 27 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,72 +1,75 @@
import js from '@eslint/js'
import tseslint from '@typescript-eslint/eslint-plugin'
import tsparser from '@typescript-eslint/parser'
import reactPlugin from 'eslint-plugin-react'
import reactHooksPlugin from 'eslint-plugin-react-hooks'
import importPlugin from 'eslint-plugin-import'
import prettier from 'eslint-config-prettier'
import js from "@eslint/js";
import tseslint from "@typescript-eslint/eslint-plugin";
import tsparser from "@typescript-eslint/parser";
import reactPlugin from "eslint-plugin-react";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import importPlugin from "eslint-plugin-import";
import prettier from "eslint-config-prettier";

export default [
js.configs.recommended,

{
linterOptions: {
reportUnusedDisableDirectives: true,
},
files: ['**/*.{js,jsx,ts,tsx}'],
files: ["**/*.{js,jsx,ts,tsx}"],
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
projectService: true,
},
},
plugins: {
'@typescript-eslint': tseslint,
"@typescript-eslint": tseslint,
react: reactPlugin,
'react-hooks': reactHooksPlugin,
"react-hooks": reactHooksPlugin,
import: importPlugin,
},
settings: {
react: {
version: 'detect',
version: "detect",
},
'import/resolver': {
"import/resolver": {
typescript: true,
node: true,
},
},
rules: {
// TypeScript rules
...tseslint.configs.recommended.rules,
'no-undef': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
// ...tseslint.configs.recommended.rules,
// tseslint.configs.recommended,
...tseslint.configs["recommended-type-checked"].rules,
"no-undef": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],

// React rules
...reactPlugin.configs.recommended.rules,
'react/react-in-jsx-scope': 'off',
"react/react-in-jsx-scope": "off",
...reactHooksPlugin.configs.recommended.rules,

// Import rules
'import/order': [
'error',
"import/order": [
"error",
{
groups: ['builtin', 'external', 'internal', ['parent', 'sibling'], 'index'],
'newlines-between': 'always',
alphabetize: { order: 'asc', caseInsensitive: true },
groups: ["builtin", "external", "internal", ["parent", "sibling"], "index"],
"newlines-between": "always",
alphabetize: { order: "asc", caseInsensitive: true },
},
],

// General rules
'no-console': ['warn', { allow: ['warn', 'error'] }],
"no-console": ["warn", { allow: ["warn", "error"] }],
},
},
{
ignores: ['dist/**', 'node_modules/**', 'coverage/**', '.github/**'],
ignores: ["dist/**", "node_modules/**", "coverage/**", ".github/**"],
},
prettier,
]
];
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type Task = {
export class Scheduler<Env> extends DurableObject<Env> {
constructor(state: DurableObjectState, env: Env) {
super(state, env);
this.ctx.blockConcurrencyWhile(async () => {
void this.ctx.blockConcurrencyWhile(async () => {
// Create tasks table if it doesn't exist
this.ctx.storage.sql.exec(
`
Expand All @@ -45,6 +45,7 @@ export class Scheduler<Env> extends DurableObject<Env> {
});
}

// eslint-disable-next-line @typescript-eslint/require-await
async fetch(_request: Request): Promise<Response> {
return new Response("Hello World!");
}
Expand Down Expand Up @@ -206,7 +207,7 @@ export class Scheduler<Env> extends DurableObject<Env> {
const base = {
id: row.id,
name: row.name,
payload: JSON.parse(row.payload as string), // TODO: should probably parse/validate this
payload: JSON.parse(row.payload as string) as Record<string, unknown>, // TODO: should probably parse/validate this
} as Task;

switch (row.type) {
Expand All @@ -229,10 +230,11 @@ export class Scheduler<Env> extends DurableObject<Env> {
type: "cron",
};
default:
throw new Error(`Unknown task type: ${row.type}`);
throw new Error(`Unknown task type: ${row.type as string}`);
}
}

// eslint-disable-next-line @typescript-eslint/require-await
private async executeTask(task: Task): Promise<void> {
// This is where you would implement the actual task execution
// eslint-disable-next-line no-console
Expand All @@ -244,6 +246,7 @@ export class Scheduler<Env> extends DurableObject<Env> {
return interval.next().toDate();
}

// eslint-disable-next-line @typescript-eslint/require-await
async query(
criteria: {
name?: string;
Expand Down
3 changes: 3 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("Hello World worker", () => {
const stub = getStub(env);
const id = "scheduled-task-001";
const time = new Date(Date.now() + 10000);
// eslint-disable-next-line @typescript-eslint/await-thenable
const task = await stub.scheduleTask({
id,
name: "test",
Expand Down Expand Up @@ -76,6 +77,7 @@ describe("Hello World worker", () => {
const id = "delayed-task-001";
const delay = 10000;
const timestamp = new Date().getTime() + delay;
// eslint-disable-next-line @typescript-eslint/await-thenable
const task = await stub.scheduleTask({
id,
name: "test",
Expand Down Expand Up @@ -123,6 +125,7 @@ describe("Hello World worker", () => {
const next = cronParser.parseExpression(cron).next();
const timestamp = Math.floor(next.toDate().getTime() / 1000);

// eslint-disable-next-line @typescript-eslint/await-thenable
const task = await stub.scheduleTask({
id,
name: "test",
Expand Down

0 comments on commit 377d180

Please sign in to comment.