Skip to content

Commit 04093a8

Browse files
committed
chore: eslint 配置更新
1 parent bd429f1 commit 04093a8

10 files changed

Lines changed: 166 additions & 149 deletions

File tree

.eslintrc.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

eslint.config.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const js = require('@eslint/js');
2+
const tseslint = require('@typescript-eslint/eslint-plugin');
3+
const tsparser = require('@typescript-eslint/parser');
4+
5+
module.exports = [
6+
// Base configuration for all files
7+
js.configs.recommended,
8+
9+
// TypeScript files configuration
10+
{
11+
files: ['**/*.ts', '**/*.tsx'],
12+
languageOptions: {
13+
parser: tsparser,
14+
parserOptions: {
15+
ecmaVersion: 2020,
16+
sourceType: 'module',
17+
},
18+
globals: {
19+
console: 'readonly',
20+
process: 'readonly',
21+
Buffer: 'readonly',
22+
__dirname: 'readonly',
23+
__filename: 'readonly',
24+
module: 'readonly',
25+
require: 'readonly',
26+
exports: 'readonly',
27+
global: 'readonly',
28+
setTimeout: 'readonly',
29+
setInterval: 'readonly',
30+
clearTimeout: 'readonly',
31+
clearInterval: 'readonly',
32+
NodeJS: 'readonly',
33+
},
34+
},
35+
plugins: {
36+
'@typescript-eslint': tseslint,
37+
},
38+
rules: {
39+
// Disable problematic rules for this project
40+
'@typescript-eslint/no-unused-vars': 'off',
41+
'@typescript-eslint/no-explicit-any': 'off',
42+
'@typescript-eslint/explicit-function-return-type': 'off',
43+
'@typescript-eslint/explicit-module-boundary-types': 'off',
44+
'@typescript-eslint/no-non-null-assertion': 'off',
45+
'no-unused-vars': 'off',
46+
'no-undef': 'off',
47+
'no-redeclare': 'off',
48+
'no-constant-condition': 'off',
49+
50+
// Keep essential rules
51+
'no-console': 'off',
52+
'prefer-const': 'error',
53+
'no-var': 'error',
54+
'semi': ['error', 'always'],
55+
'quotes': ['error', 'single'],
56+
'eol-last': 'error',
57+
},
58+
},
59+
60+
// Ignore patterns
61+
{
62+
ignores: [
63+
'dist/',
64+
'build/',
65+
'node_modules/',
66+
'deps/',
67+
'Release/',
68+
'coverage/',
69+
'*.js',
70+
'test/',
71+
],
72+
},
73+
];

example/common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const config = {
2-
nameServer: '127.0.0.1:9876'
3-
// nameServer: 'onsaddr.cn-hangzhou.mq.aliyuncs.com:80'
4-
// nameServer: 'v0-default-<instanceId>.mq.cloudrun.local:9515'
2+
nameServer: '127.0.0.1:9876'
3+
// nameServer: 'onsaddr.cn-hangzhou.mq.aliyuncs.com:80'
4+
// nameServer: 'v0-default-<instanceId>.mq.cloudrun.local:9515'
55
};

example/producer.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,56 @@ import { config } from './common';
33
import { Producer } from '../src';
44

55
if (typeof (Promise as any).withResolvers === 'undefined') {
6-
(Promise as any).withResolvers = function () {
7-
let resolve: ((value?: any) => void) | null = null;
8-
let reject: ((reason?: any) => void) | null = null;
9-
const promise = new Promise((res, rej) => {
10-
resolve = res;
11-
reject = rej;
12-
});
13-
return { promise, resolve, reject };
14-
};
6+
(Promise as any).withResolvers = function () {
7+
let resolve: ((value?: any) => void) | null = null;
8+
let reject: ((reason?: any) => void) | null = null;
9+
const promise = new Promise((res, rej) => {
10+
resolve = res;
11+
reject = rej;
12+
});
13+
return { promise, resolve, reject };
14+
};
1515
}
1616

1717
const rl = readline.createInterface({
18-
input: process.stdin,
19-
output: process.stdout
18+
input: process.stdin,
19+
output: process.stdout
2020
});
2121

2222
void async function () {
23-
const producer = new Producer('GID_GROUP', {
24-
nameServer: config.nameServer,
25-
});
23+
const producer = new Producer('GID_GROUP', {
24+
nameServer: config.nameServer
25+
});
26+
27+
// producer.setSessionCredentials('accessKey', 'secretKey', 'ALIYUN')
2628

27-
// producer.setSessionCredentials('accessKey', 'secretKey', 'ALIYUN')
28-
29-
await producer.start();
30-
31-
while(1) {
32-
const { promise, resolve, reject } = (Promise as any).withResolvers();
33-
rl.question('Enter input: ', async (input: string) => {
34-
await producer.send('TP_TOPIC', input).catch(reject);
35-
resolve();
36-
});
37-
await promise;
38-
}
39-
40-
// producer.start(async function() {
41-
// console.log('producer started');
42-
// while(1) {
43-
// const { promise, resolve, reject } = Promise.withResolvers()
44-
// rl.question('Enter input: ', input => {
45-
// producer.send('TP_TOPIC', input, function(err, ret) {
46-
// if (err) {
47-
// console.error(err);
48-
// reject(err)
49-
// }
50-
// console.log(ret);
51-
// resolve(ret)
52-
// });
53-
// });
54-
// await promise.catch(console.error);
55-
// }
56-
// });
29+
await producer.start();
30+
31+
while(1) {
32+
const { promise, resolve, reject } = (Promise as any).withResolvers();
33+
rl.question('Enter input: ', async (input: string) => {
34+
await producer.send('TP_TOPIC', input).catch(reject);
35+
resolve();
36+
});
37+
await promise;
38+
}
39+
40+
// producer.start(async function() {
41+
// console.log('producer started');
42+
// while(1) {
43+
// const { promise, resolve, reject } = Promise.withResolvers()
44+
// rl.question('Enter input: ', input => {
45+
// producer.send('TP_TOPIC', input, function(err, ret) {
46+
// if (err) {
47+
// console.error(err);
48+
// reject(err)
49+
// }
50+
// console.log(ret);
51+
// resolve(ret)
52+
// });
53+
// });
54+
// await promise.catch(console.error);
55+
// }
56+
// });
5757

5858
}();

example/push_consumer.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { config } from './common';
22
import { PushConsumer, Message, ConsumerAck } from '../src';
33

44
void function () {
5-
const consumer = new PushConsumer('GID_GROUP', {
6-
nameServer: config.nameServer,
7-
});
5+
const consumer = new PushConsumer('GID_GROUP', {
6+
nameServer: config.nameServer
7+
});
88

9-
// consumer.setSessionCredentials('accessKey', 'secretKey', 'ALIYUN');
9+
// consumer.setSessionCredentials('accessKey', 'secretKey', 'ALIYUN');
1010

11-
consumer.subscribe('TP_TOPIC', '*');
12-
consumer.on('message', function(msg: Message, ack: ConsumerAck) {
13-
console.log(msg);
14-
ack.done(true);
15-
});
11+
consumer.subscribe('TP_TOPIC', '*');
12+
consumer.on('message', function(msg: Message, ack: ConsumerAck) {
13+
console.log(msg);
14+
ack.done(true);
15+
});
1616

17-
consumer.start(function() {
18-
console.log('consumer started');
19-
});
17+
consumer.start(function() {
18+
console.log('consumer started');
19+
});
2020
}();

example/status_behavior.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,48 @@ import { Status } from '../src/constants';
33

44
async function demonstrateStatusBehavior(): Promise<void> {
55
const producer = new RocketMQProducer('demo-group');
6-
6+
77
console.log('=== 新的状态行为演示 ===');
88
console.log('初始状态:', getStatusName(producer.status)); // STOPPED
9-
9+
1010
console.log('\n1. 调用 start() 后状态不会立即改变');
1111
const startPromise = producer.start();
1212
console.log('调用 start() 后立即检查状态:', getStatusName(producer.status)); // 可能还是 STOPPED
13-
13+
1414
await startPromise;
1515
console.log('start() 完成后状态:', getStatusName(producer.status)); // STARTED
16-
16+
1717
console.log('\n2. 并发调用会被正确处理');
1818
const promise1 = producer.start(); // 应该失败
1919
const promise2 = producer.start(); // 应该失败
20-
20+
2121
try {
2222
await promise1;
2323
console.log('第一个 start() 调用成功');
2424
} catch (err: any) {
2525
console.log('第一个 start() 调用失败:', err.message);
2626
}
27-
27+
2828
try {
2929
await promise2;
3030
console.log('第二个 start() 调用成功');
3131
} catch (err: any) {
3232
console.log('第二个 start() 调用失败:', err.message);
3333
}
34-
34+
3535
console.log('\n3. 清理');
3636
await producer.shutdown();
3737
console.log('最终状态:', getStatusName(producer.status)); // STOPPED
3838
}
3939

4040
function getStatusName(status: Status): string {
4141
switch (status) {
42-
case Status.STOPPED: return 'STOPPED';
43-
case Status.STARTED: return 'STARTED';
44-
case Status.STARTING: return 'STARTING';
45-
case Status.STOPPING: return 'STOPPING';
46-
default: return 'UNKNOWN';
42+
case Status.STOPPED: return 'STOPPED';
43+
case Status.STARTED: return 'STARTED';
44+
case Status.STARTING: return 'STARTING';
45+
case Status.STOPPING: return 'STOPPING';
46+
default: return 'UNKNOWN';
4747
}
4848
}
4949

50-
demonstrateStatusBehavior().catch(console.error);
50+
demonstrateStatusBehavior().catch(console.error);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"test:coverage": "npm run build:test && npm run vitest:coverage",
4040
"test:watch": "npm run build:ts && vitest --watch",
4141
"clean:ts": "tsc -b --clean",
42-
"lint": "eslint src/**/*.ts --fix",
42+
"lint": "eslint src/**/*.ts example/**/*.ts --fix",
4343
"format": "prettier --write src/**/*.ts example/**/*.ts",
4444
"validate": "npm run lint && npm run test:dryrun"
4545
},

src/binding.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ function detectLibc(): 'gnu' | 'musl' {
2222
}
2323

2424
try {
25-
const output = execSync('ldd --version', {
26-
encoding: 'utf8',
27-
stdio: ['ignore', 'pipe', 'ignore']
25+
const output = execSync('ldd --version', {
26+
encoding: 'utf8',
27+
stdio: ['ignore', 'pipe', 'ignore']
2828
});
2929
if (/musl/i.test(output)) {
3030
return 'musl';

src/consumer.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface Message {
2525
}
2626

2727
export interface ConsumerAck {
28-
done(success: boolean): void;
28+
done(success?: boolean): void;
2929
}
3030

3131
type Callback<T = void> = (err?: Error | null, result?: T) => void;
@@ -113,20 +113,12 @@ export class RocketMQPushConsumer extends EventEmitter {
113113
if (typeof accessKey !== 'string') throw new TypeError('accessKey must be a string');
114114
if (typeof secretKey !== 'string') throw new TypeError('secretKey must be a string');
115115
if (typeof onsChannel !== 'string') throw new TypeError('onsChannel must be a string');
116-
116+
117117
this.core.setSessionCredentials(accessKey, secretKey, onsChannel);
118118
return true;
119119
}
120120

121-
private getStatusName(status: Status = this.status): string {
122-
switch (status) {
123-
case Status.STOPPED: return 'STOPPED';
124-
case Status.STARTED: return 'STARTED';
125-
case Status.STARTING: return 'STARTING';
126-
case Status.STOPPING: return 'STOPPING';
127-
default: return 'UNKNOWN';
128-
}
129-
}
121+
130122

131123
private [START_OR_SHUTDOWN](method: 'start' | 'shutdown'): Promise<void>;
132124
private [START_OR_SHUTDOWN](method: 'start' | 'shutdown', callback: Callback): void;

0 commit comments

Comments
 (0)