Skip to content
Closed
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ lib/
.tshy*
dist
.package-lock.json
pnpm-lock.yaml
111 changes: 26 additions & 85 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,151 +4,92 @@
"node": true,
"mocha": true
},
"categories": {
"correctness": "error",
"perf": "error",
"nursery": "error",
"restriction": "error",
"style": "error",
"pedantic": "error",
"suspicious": "error"
},
"plugins": [
"import",
"typescript",
"unicorn",
"jsdoc",
"node",
"promise",
"oxc"
],
"extends": ["./node_modules/@eggjs/oxlint-config/.oxlintrc.json"],
"rules": {
// eslint
"constructor-super": "error",
"getter-return": "error",
"no-undef": "error",
"no-unreachable": "error",
"no-var": "error",
"no-eq-null": "error",
"no-await-in-loop": "allow",
"eqeqeq": ["error", "smart"],
"init-declarations": "allow",
"curly": "allow",
"no-ternary": "allow",
"max-params": ["error", 5],
"no-await-expression-member": "error",
"max-params": ["error", 8],
"no-continue": "allow",
"guard-for-in": "allow",
"func-style": "allow",
"sort-imports": "allow",
"yoda": "allow",
"sort-keys": "allow",
"no-magic-numbers": "allow",
"no-duplicate-imports": "error",
"no-multi-assign": "error",
"func-names": "error",
"default-param-last": "error",
"prefer-object-spread": "error",
"no-undefined": "allow",
"no-plusplus": "allow",
"no-console": "allow",
"no-extraneous-class": "allow",
"no-empty-function": "error",
"max-depth": ["error", 6],
"max-lines-per-function": "allow",
"no-lonely-if": "error",
"max-lines": "allow",
"require-await": "allow",
"max-nested-callbacks": ["error", 5],
"max-nested-callbacks": ["error", 6],
"max-classes-per-file": "allow",
"radix": "allow",
"no-negated-condition": "error",
"no-else-return": "error",
"no-throw-literal": "error",
"prefer-template": "allow",
"new-cap": "allow",

// import
"import/exports-last": "allow",
"import/max-dependencies": "allow",
"import/no-cycle": "error",
"import/no-anonymous-default-export": "allow",
"import/no-namespace": "error",
"import/named": "error",
"import/export": "error",
"import/no-default-export": "allow",
"import/unambiguous": "error",

// promise
"promise/no-return-wrap": "error",
"promise/param-names": "error",
"promise/prefer-await-to-callbacks": "allow",
"promise/prefer-await-to-then": "error",
"promise/prefer-catch": "error",
"promise/no-return-in-finally": "error",
"promise/avoid-new": "error",
"promise/avoid-new": "allow",
"promise/always-return": "allow",

// unicorn
"unicorn/error-message": "error",
"unicorn/no-null": "allow",
"unicorn/filename-case": "allow",
"unicorn/prefer-structured-clone": "error",
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/prefer-number-properties": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-string-slice": "error",
"unicorn/switch-case-braces": ["error", "avoid"],
// "unicorn/no-null": "error",
"unicorn/throw-new-error": "error",
"unicorn/catch-error-name": "allow",
"unicorn/prefer-spread": "allow",
"unicorn/numeric-separators-style": "error",
"unicorn/prefer-string-raw": "error",
"unicorn/text-encoding-identifier-case": "error",
"unicorn/no-array-for-each": "error",
"unicorn/explicit-length-check": "error",
"unicorn/no-lonely-if": "error",
"unicorn/no-useless-undefined": "allow",
"unicorn/prefer-date-now": "error",
"unicorn/no-static-only-class": "allow",
"unicorn/no-typeof-undefined": "error",
"unicorn/prefer-negative-index": "error",
"unicorn/no-anonymous-default-export": "allow",
"unicorn/prefer-event-target": "allow",
"unicorn/no-array-for-each": "allow",

// oxc
"oxc/no-map-spread": "error",
"oxc/no-rest-spread-properties": "allow",
"oxc/no-optional-chaining": "allow",
"oxc/no-async-await": "allow",
"oxc/no-barrel-file": "allow",

// typescript
"typescript/explicit-function-return-type": "allow",
"typescript/consistent-type-imports": "error",
"typescript/consistent-type-definitions": "error",
"typescript/consistent-indexed-object-style": "allow",
"typescript/no-inferrable-types": "error",
"typescript/array-type": "error",
"typescript/no-non-null-assertion": "error",
"typescript/no-explicit-any": "allow",
"typescript/no-import-type-side-effects": "error",
"typescript/no-dynamic-delete": "error",
"typescript/prefer-ts-expect-error": "error",
"typescript/ban-ts-comment": "error",
"typescript/prefer-enum-initializers": "error",
"typescript/no-unnecessary-boolean-literal-compare": "allow",
"typescript/no-unsafe-member-access": "allow",
"typescript/no-unsafe-type-assertion": "allow",
"typescript/no-unsafe-call": "allow",
"typescript/no-unsafe-argument": "allow",
"typescript/no-misused-promises": "allow",
"typescript/promise-function-async": "allow",
"typescript/no-floating-promises": "allow",
"typescript/no-unsafe-assignment": "allow",
"typescript/require-await": "allow",
"typescript/no-unsafe-return": "allow",
"typescript/no-confusing-void-expression": "allow",
"typescript/prefer-promise-reject-errors": "allow",
"typescript/use-unknown-in-catch-callback-variable": "allow",
"typescript/non-nullable-type-assertion-style": "allow",
"typescript/unbound-method": "allow",
"typescript/restrict-template-expressions": "allow",

// jsdoc
"jsdoc/require-returns": "allow",
"jsdoc/require-param": "allow"
},
"overrides": [
{
"rules": {
"unicorn/no-array-for-each": "allow",
"promise/avoid-new": "allow",
"max-nested-callbacks": "allow"
},
"files": ["test/**/*.ts"]
}
],
"ignorePatterns": [
"index.d.ts",
"test/fixtures/**",
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"description": "A core plugin framework based on @eggjs/koa",
"scripts": {
"clean": "rimraf dist",
"lint": "oxlint",
"lint": "oxlint --type-aware",
"pretest": "npm run clean && npm run lint -- --fix && npm run prepublishOnly",
"test": "egg-bin test",
"posttest": "npm run clean",
Expand Down Expand Up @@ -61,21 +61,23 @@
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.4",
"@eggjs/bin": "7",
"@eggjs/oxlint-config": "^1.0.0",
"@eggjs/supertest": "^8.1.1",
"@eggjs/tsconfig": "1",
"@types/js-yaml": "4",
"@types/mocha": "10",
"@types/node": "22",
"await-event": "2",
"coffee": "5",
"husky": "9",
"lint-staged": "15",
"oxlint": "^0.16.2",
"prettier": "3",
"gals": "1",
"husky": "9",
"js-yaml": "3",
"lint-staged": "15",
"mm": "^4.0.2",
"oxlint": "^1.14.0",
"oxlint-tsgolint": "^0.1.5",
"pedding": "2",
"prettier": "3",
"rimraf": "6",
"ts-node": "10",
"tshy": "3",
Expand Down
8 changes: 4 additions & 4 deletions src/egg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ export class EggCore extends KoaApplication {
constructor(options: EggCoreInitOptions = {}) {
options.baseDir = options.baseDir ?? process.cwd();
options.type = options.type ?? 'application';
assert(
assert.ok(
typeof options.baseDir === 'string',
'options.baseDir required, and must be a string'
);
// assert(fs.existsSync(options.baseDir), `Directory ${options.baseDir} not exists`);
// assert(fs.statSync(options.baseDir).isDirectory(), `Directory ${options.baseDir} is not a directory`);
assert(
assert.ok(
options.type === 'application' || options.type === 'agent',
'options.type should be application or agent'
);
Expand Down Expand Up @@ -219,7 +219,7 @@ export class EggCore extends KoaApplication {
* @since 1.0.0
*/
const Loader = this[EGG_LOADER];
assert(Loader, "Symbol.for('egg#loader') is required");
assert.ok(Loader, "Symbol.for('egg#loader') is required");
this.loader = new Loader({
baseDir: options.baseDir,
app: this,
Expand Down Expand Up @@ -264,7 +264,7 @@ export class EggCore extends KoaApplication {
* @since 1.0.0
*/
use<T extends KoaContext = Context>(fn: MiddlewareFunc<T>) {
assert(typeof fn === 'function', 'app.use() requires a function');
assert.ok(typeof fn === 'function', 'app.use() requires a function');
debug('[use] add middleware: %o', fn._name || fn.name || '-');
this.middleware.push(fn as unknown as KoaMiddlewareFunc);
return this;
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ export * from './loader/context_loader.js';
export * from './utils/sequencify.js';
export * from './utils/timing.js';
export type * from './types.js';

export default function hello() {
const a = {
b: 1,
c: 2,
};

const b = a.b;

return b;
}
15 changes: 7 additions & 8 deletions src/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { Ready as ReadyObject, type ReadyFunctionArg } from 'get-ready';
import { Ready } from 'ready-callback';
import { EggConsoleLogger } from 'egg-logger';

import utils from './utils/index.js';
import type { Fun } from './utils/index.js';
import utils, { type Fun } from './utils/index.js';
import type { EggCore } from './egg.js';

const debug = debuglog('@eggjs/core/lifecycle');
Expand Down Expand Up @@ -93,7 +92,7 @@ export class Lifecycle extends EventEmitter {
const eggReadyTimeoutEnv = Number.parseInt(
process.env.EGG_READY_TIMEOUT_ENV || '10000'
);
assert(
assert.ok(
Number.isInteger(eggReadyTimeoutEnv),
`process.env.EGG_READY_TIMEOUT_ENV ${process.env.EGG_READY_TIMEOUT_ENV} should be able to parseInt.`
);
Expand Down Expand Up @@ -159,7 +158,7 @@ export class Lifecycle extends EventEmitter {
}

addBootHook(bootHootOrBootClass: BootImplClass | ILifecycleBoot) {
assert(
assert.ok(
this.#init === false,
'do not add hook when lifecycle has been initialized'
);
Expand All @@ -170,7 +169,7 @@ export class Lifecycle extends EventEmitter {
hook: (app: T) => void,
fullPath?: string
) {
assert(
assert.ok(
this.#init === false,
'do not add hook when lifecycle has been initialized'
);
Expand All @@ -195,7 +194,7 @@ export class Lifecycle extends EventEmitter {
*/
init() {
debug('%s init lifecycle', this.app.type);
assert(this.#init === false, 'lifecycle have been init');
assert.ok(this.#init === false, 'lifecycle have been init');
this.#init = true;
this.#boots = this.#bootHooks.map(BootHootOrBootClass => {
let instance = BootHootOrBootClass as ILifecycleBoot;
Expand All @@ -221,8 +220,8 @@ export class Lifecycle extends EventEmitter {
}

registerBeforeClose(fn: FunWithFullPath, fullPath?: string) {
assert(typeof fn === 'function', 'argument should be function');
assert(this.#isClosed === false, 'app has been closed');
assert.ok(typeof fn === 'function', 'argument should be function');
assert.ok(this.#isClosed === false, 'app has been closed');
if (fullPath) {
fn.fullPath = fullPath;
}
Expand Down
6 changes: 3 additions & 3 deletions src/loader/context_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ClassLoader {
_ctx: Context;

constructor(options: ClassLoaderOptions) {
assert(options.ctx, 'options.ctx is required');
assert.ok(options.ctx, 'options.ctx is required');
const properties = options.properties;
this._ctx = options.ctx;

Expand Down Expand Up @@ -62,8 +62,8 @@ export class ContextLoader extends FileLoader {
* @param {String} options.fieldClass - determine the field name of inject object.
*/
constructor(options: ContextLoaderOptions) {
assert(options.property, 'options.property is required');
assert(options.inject, 'options.inject is required');
assert.ok(options.property, 'options.property is required');
assert.ok(options.inject, 'options.inject is required');
const target = {};
if (options.fieldClass) {
options.inject[options.fieldClass] = target;
Expand Down
Loading
Loading