8000 feat: use oxlint by fengmk2 · Pull Request #298 · eggjs/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: use oxlint #298

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 10 commits into from
Mar 28, 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
5 changes: 0 additions & 5 deletions 10000 .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
Job:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release

on:
push:
branches: [ master ]
branches: [master]

jobs:
release:
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
158 changes: 158 additions & 0 deletions .oxlintrc.json
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"env": {
"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"
],
"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",
"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-classes-per-file": "allow",
"radix": "allow",
"no-negated-condition": "error",
"no-else-return": "error",
"no-throw-literal": "error",

// 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",

// 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/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",

// 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",

// 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/**",
"__snapshots__",
"benchmark"
]
}
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CHANGELOG.md
__snapshots__
benchmark
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 2,
"arrowParens": "avoid"
}
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Then you can start with code below
import { EggCore as Application } from '@eggjs/core';

const app = new Application({
baseDir: '/path/to/app'
baseDir: '/path/to/app',
});
app.ready(() => {
app.listen(3000);
Expand Down Expand Up @@ -140,13 +140,13 @@ Load app/service
Retrieve application environment variable values via `serverEnv`.
You can access directly by calling `this.serverEnv` after instantiation.

serverEnv | description
--- | ---
default | default environment
test | system integration testing environment
prod | production environment
local | local environment on your own computer
unittest | unit test environment
| serverEnv | description |
| --------- | -------------------------------------- |
| default | default environment |
| test | system integration testing environment |
| prod | production environment |
| local | local environment on your own computer |
| unittest | unit test environment |

#### getEggPaths()

Expand All @@ -163,7 +163,7 @@ This function will get add loadUnits follow the order:
2. framework
3. app

loadUnit has a path and a type. Type must be one of those values: *app*, *framework*, *plugin*.
loadUnit has a path and a type. Type must be one of those values: _app_, _framework_, _plugin_.

```js
{
Expand All @@ -174,7 +174,7 @@ loadUnit has a path and a type. Type must be one of those values: *app*, *framew

#### getAppname()

To get application name from *package.json*
To get application name from _package.json_

#### appInfo

Expand Down Expand Up @@ -228,18 +228,18 @@ await this.loadExtend('application', app);

### LoaderOptions

Param | Type | Description
-------------- | -------------- | ------------------------
directory | `String/Array` | directories to be loaded
target | `Object` | attach the target object from loaded files
match | `String/Array` | match the files when load, default to `**/*.js`(if process.env.EGG_TYPESCRIPT was true, default to `[ '**/*.(js|ts)', '!**/*.d.ts' ]`)
ignore | `String/Array` | ignore the files when load
initializer | `Function` | custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path`
caseStyle | `String/Function` | set property's case when converting a filepath to property list.
override | `Boolean` | determine whether override the property when get the same name
call | `Boolean` | determine whether invoke when exports is function
inject | `Object` | an object that be the argument when invoke the function
filter | `Function` | a function that filter the exports which can be loaded
| Param | Type | Description |
| ----------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- |
| directory | `String/Array` | directories to be loaded |
| target | `Object` | attach the target object from loaded files |
| match | `String/Array` | match the files when load, default to `**/*.js`(if process.env.EGG\*TYPESCRIPT was true, default to `[ '\*\*/\_.(js | ts)', '!\*_/_.d.ts' ]`) |
| ignore | `String/Array` | ignore the files when load |
| initializer | `Function` | custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path` |
| caseStyle | `String/Function` | set property's case when converting a filepath to property list. |
| override | `Boolean` | determine whether override the property when get the same name |
| call | `Boolean` | determine whether invoke when exports is function |
| inject | `Object` | an object that be the argument when invoke the function |
| filter | `Function` | a function that filter the exports which can be loaded |

## Timing

Expand Down
2 changes: 1 addition & 1 deletion benchmark/middleware/app/middleware/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

let index = 0;

module.exports = function () {
module.exports = function exports() {
return async (ctx, next) => {
await next();
ctx.body.push(`async middleware #${++index}`);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/middleware/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ module.exports = app => {

app.get('/', app.controller.home.index);
app.get('/async', ...asyncMiddlewares, 'home.async');
}
};
16 changes: 9 additions & 7 deletions benchmark/middleware/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ const app = new EggApplication({
type: 'application',
});

app.loader.loadAll().then(() => {
app.listen(7001);
console.log('server started at 7001');
}).catch(err => {
throw err;
});

app.loader
.loadAll()
.then(() => {
app.listen(7001);
console.log('server started at 7001');
})
.catch(err => {
throw err;
});
2 changes: 1 addition & 1 deletion example/middleware/hello.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareFunc } from '../../src/index.js';
import type { MiddlewareFunc } from '../../src/index.js';

export const hello: MiddlewareFunc = async (ctx, next) => {
console.log('Hello middleware');
Expand Down
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@
"description": "A core plugin framework based on @eggjs/koa",
"scripts": {
"clean": "rimraf dist",
"lint": "eslint src test --ext ts",
"lint": "oxlint",
"pretest": "npm run clean && npm run lint -- --fix && npm run prepublishOnly",
"test": "egg-bin test",
"posttest": "npm run clean",
"test-local": "egg-bin test",
"preci": "npm run clean && npm run lint && npm run prepublishOnly",
"ci": "egg-bin cov",
"postci": "npm run clean",
"prepublishOnly": "tshy && tshy-after && attw --pack"
"prepublishOnly": "tshy && tshy-after && attw --pack",
"prepare": "husky"
},
"lint-staged": {
"*": "prettier --write --ignore-unknown --cache",
"*.{ts,js,json,md,yml}": [
"prettier --ignore-unknown --write",
"oxlint --fix"
]
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -51,7 +59,7 @@
"utility": "^2.1.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@arethetypeswrong/cli": "^0.17.4",
"@eggjs/bin": "7",
"@eggjs/supertest": "^8.1.1",
"@eggjs/tsconfig": "1",
Expand All @@ -60,8 +68,10 @@
"@types/node": "22",
"await-event": "2",
"coffee": "5",
"eslint": "8",
"eslint-config-egg": "14",
"husky": "9",
"lint-staged": "15",
"oxlint": "^0.16.2",
"prettier": "3",
"gals": "1",
"js-yaml": "3",
"mm": "^4.0.2",
Expand Down
Loading
0