chore: fix all ESLint errors (#30)
npm run lint failed with 56 errors on develop. Fixes:
- remove unused imports and local variables
- use the optional catch binding (catch {}) where the caught error was unused
- wrap the variable-length case body in Session.getRowCount in a block to
satisfy no-case-declarations
- drop the unused promise reject parameter in SessionDataSet.close
- declare the NodeJS type namespace in the ESLint config, which no-undef
cannot resolve from @types/node
- examples: close the pool/session instances that were constructed purely to
document the alternative APIs, and export the demo helpers that main()
intentionally does not call because they need a live IoTDB
npm run lint now exits 0 (0 errors, 166 warnings), npm run build passes and
npm run test:unit passes (12 suites / 173 tests).diff --git a/benchmark/benchmark-table-cluster.js b/benchmark/benchmark-table-cluster.js
index 47a7352..890aa9a 100644
--- a/benchmark/benchmark-table-cluster.js
+++ b/benchmark/benchmark-table-cluster.js
@@ -79,10 +79,6 @@
[TSDataType.BOOLEAN]: 0.1,
};
-// Generate sensor types ONCE with fixed seed for consistency across all processes
-// This ensures schema and data match
-const SENSOR_TYPES = distributeSensorTypes(SENSOR_NUMBER, INSERT_DATATYPE_PROPORTION);
-
if (cluster.isPrimary) {
// ============== PRIMARY PROCESS ==============
runPrimary();
@@ -181,7 +177,7 @@
}
async function createSchema() {
- const { TableSessionPool, ColumnCategory } = require('../dist');
+ const { TableSessionPool } = require('../dist');
const pool = new TableSessionPool(IOTDB_HOST, IOTDB_PORT, {
username: IOTDB_USER,
@@ -197,7 +193,7 @@
// Drop existing database
try {
await pool.executeNonQueryStatement(`DROP DATABASE ${DATABASE_NAME}`);
- } catch (e) {
+ } catch {
// Ignore if not exists
}
@@ -291,7 +287,7 @@
if (i >= warmupTablets.length) break;
try {
await session.insertTablet(warmupTablets[i]);
- } catch (e) { /* ignore */ }
+ } catch { /* ignore */ }
}
}));
} finally {
@@ -318,7 +314,6 @@
const tablets = buildTabletsForLoop(devices, sharedBatch, loopIdx, ColumnCategory);
let tabletIndex = 0;
- const loopStartTime = performance.now();
await Promise.all(sessions.map(async (session) => {
while (tabletIndex < tablets.length) {
@@ -334,7 +329,7 @@
totalLatency += latency;
totalOperations++;
totalDataPoints += tablet.timestamps.length * (tablet.columnNames.length - 1); // -1 for device_id
- } catch (error) {
+ } catch {
// Count as failed but continue
}
}
diff --git a/benchmark/benchmark-table.js b/benchmark/benchmark-table.js
index b197a50..f8907be 100755
--- a/benchmark/benchmark-table.js
+++ b/benchmark/benchmark-table.js
@@ -41,8 +41,7 @@
const { TableSessionPool } = require('../dist');
const { createConfig, printConfig } = require('./config');
const { prepareTestData } = require('./data-generator');
-const { createTableModelSchema, cleanupSchema } = require('./schema-manager');
-const { runBatchBenchmark } = require('./benchmark-core');
+const { createTableModelSchema } = require('./schema-manager');
// Import ColumnCategory from dist
const { ColumnCategory } = require('../dist');
@@ -233,7 +232,7 @@
if (i >= warmupTablets.length) break;
try {
await session.insertTablet(warmupTablets[i]);
- } catch (e) { /* ignore warmup errors */ }
+ } catch { /* ignore warmup errors */ }
}
});
await Promise.all(workers);
diff --git a/benchmark/benchmark-tree.js b/benchmark/benchmark-tree.js
index d28f623..3f8b4d4 100755
--- a/benchmark/benchmark-tree.js
+++ b/benchmark/benchmark-tree.js
@@ -41,8 +41,7 @@
const { SessionPool } = require('../dist');
const { createConfig, printConfig } = require('./config');
const { prepareTestData } = require('./data-generator');
-const { createTreeModelSchema, cleanupSchema } = require('./schema-manager');
-const { runBatchBenchmark } = require('./benchmark-core');
+const { createTreeModelSchema } = require('./schema-manager');
/**
* Create session pool for tree model
@@ -213,7 +212,7 @@
if (i >= warmupTablets.length) break;
try {
await session.insertTablet(warmupTablets[i]);
- } catch (e) { /* ignore warmup errors */ }
+ } catch { /* ignore warmup errors */ }
}
});
await Promise.all(workers);
diff --git a/benchmark/data-generator.js b/benchmark/data-generator.js
index 417d73d..3d96687 100644
--- a/benchmark/data-generator.js
+++ b/benchmark/data-generator.js
@@ -411,7 +411,7 @@
}
return true;
- } catch (error) {
+ } catch {
return false;
}
}
diff --git a/benchmark/schema-manager.js b/benchmark/schema-manager.js
index 0b50553..c89a597 100644
--- a/benchmark/schema-manager.js
+++ b/benchmark/schema-manager.js
@@ -91,7 +91,7 @@
`DROP DEVICE TEMPLATE ${templateName}`
);
console.log(' ✓ Existing template dropped');
- } catch (error) {
+ } catch {
console.log(' ℹ Template does not exist, will create new one');
}
@@ -182,7 +182,7 @@
try {
await session.executeNonQueryStatement(`DROP TABLE ${config.TABLE_NAME}`);
console.log(' ✓ Dropped existing table');
- } catch (error) {
+ } catch {
// Ignore if table doesn't exist
}
@@ -234,7 +234,7 @@
`DELETE DATABASE ${config.STORAGE_GROUP_PREFIX}.*`
);
console.log(' ✓ Storage group deleted');
- } catch (error) {
+ } catch {
console.log(' ℹ Storage group does not exist or already deleted');
}
} else if (model === 'table') {
@@ -244,7 +244,7 @@
`DROP DATABASE ${config.DATABASE_NAME}`
);
console.log(' ✓ Database dropped');
- } catch (error) {
+ } catch {
console.log(' ℹ Database does not exist or already deleted');
}
}
diff --git a/eslint.config.mjs b/eslint.config.mjs
index 4f4a530..296370d 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -17,6 +17,8 @@
globals: {
...globals.node,
...globals.es2020,
+ // Type namespace provided by @types/node; no-undef cannot see it.
+ NodeJS: 'readonly',
},
},
plugins: {
diff --git a/examples/basic-session.ts b/examples/basic-session.ts
index 81f2d1b..6a4c7f5 100644
--- a/examples/basic-session.ts
+++ b/examples/basic-session.ts
@@ -116,6 +116,7 @@
// Close the session
console.log("\nClosing session...");
await session.close();
+ await session2.close();
console.log("Session closed");
}
}
diff --git a/examples/concurrent-operations.ts b/examples/concurrent-operations.ts
index cb6d218..14691ac 100644
--- a/examples/concurrent-operations.ts
+++ b/examples/concurrent-operations.ts
@@ -20,7 +20,7 @@
createSemaphore
} from "../src";
-async function demonstrateSessionApis() {
+export async function demonstrateSessionApis() {
console.log("=== Session Concurrent APIs ===\n");
const session = new Session({
@@ -90,7 +90,7 @@
}
}
-async function demonstratePoolApis() {
+export async function demonstratePoolApis() {
console.log("\n=== SessionPool Concurrent APIs ===\n");
const pool = new SessionPool("localhost", 6667, {
diff --git a/examples/multi-node.ts b/examples/multi-node.ts
index a5597c7..b9a270a 100644
--- a/examples/multi-node.ts
+++ b/examples/multi-node.ts
@@ -102,6 +102,9 @@
console.error('Error:', error);
} finally {
await pool.close();
+ await pool2.close();
+ await pool3.close();
+ await pool4.close();
console.log('Pool closed');
}
}
diff --git a/examples/session-pool.ts b/examples/session-pool.ts
index 8ed3cb3..f5a949d 100644
--- a/examples/session-pool.ts
+++ b/examples/session-pool.ts
@@ -179,6 +179,7 @@
// Close the pool
console.log("\nClosing session pool...");
await pool.close();
+ await pool2.close();
console.log("Pool closed");
}
}
diff --git a/examples/ssl-connection.ts b/examples/ssl-connection.ts
index 5fcf3de..f53d992 100644
--- a/examples/ssl-connection.ts
+++ b/examples/ssl-connection.ts
@@ -55,7 +55,7 @@
}
// For self-signed certificates or testing, you can use:
-async function selfSignedExample() {
+export async function selfSignedExample() {
const session = new Session({
host: 'localhost',
port: 6667,
diff --git a/examples/table-session-pool.ts b/examples/table-session-pool.ts
index 65ab0be..02cb821 100644
--- a/examples/table-session-pool.ts
+++ b/examples/table-session-pool.ts
@@ -213,6 +213,9 @@
} finally {
console.log("\nClosing table session pool...");
await pool.close();
+ await pool2.close();
+ await pool3.close();
+ await pool4.close();
console.log("Table pool closed");
}
}
diff --git a/src/client/ColumnDecoder.ts b/src/client/ColumnDecoder.ts
index 25d5c13..436d1a3 100644
--- a/src/client/ColumnDecoder.ts
+++ b/src/client/ColumnDecoder.ts
@@ -17,7 +17,6 @@
* under the License.
*/
-import { logger } from "../utils/Logger";
import { parseIntToDate } from "../utils/DataTypes";
/**
diff --git a/src/client/Session.ts b/src/client/Session.ts
index ef6424a..31d1103 100644
--- a/src/client/Session.ts
+++ b/src/client/Session.ts
@@ -29,7 +29,7 @@
import { SessionDataSet } from "./SessionDataSet";
import { RowRecord } from "./RowRecord";
import { BaseColumnDecoder, ColumnEncoding, Column } from "./ColumnDecoder";
-import { RedirectException, isWildcardAddress } from "../utils/Errors";
+import { isWildcardAddress } from "../utils/Errors";
import {
serializeTabletValuesFast,
serializeTimestamps
@@ -1179,14 +1179,16 @@
case 10: // BLOB - variable length
case 11: // STRING - variable length
// For variable-length types, count entries by parsing length prefixes
- let count = 0;
- let offset = 0;
- while (offset + 4 <= length) {
- const strLength = buffer.readInt32BE(offset);
- offset += 4 + strLength;
- count++;
+ {
+ let count = 0;
+ let offset = 0;
+ while (offset + 4 <= length) {
+ const strLength = buffer.readInt32BE(offset);
+ offset += 4 + strLength;
+ count++;
+ }
+ return count;
}
- return count;
default:
logger.warn(
`Unknown data type ${dataType}, cannot determine row count`,
diff --git a/src/client/SessionDataSet.ts b/src/client/SessionDataSet.ts
index ecaeb8a..c0b8f99 100644
--- a/src/client/SessionDataSet.ts
+++ b/src/client/SessionDataSet.ts
@@ -412,7 +412,7 @@
statementId: this.statementId,
});
- await new Promise<void>((resolve, reject) => {
+ await new Promise<void>((resolve) => {
client.closeOperation(req, (err: Error, response: any) => {
if (err) {
logger.warn(`Error closing query operation: ${err.message}`);
diff --git a/src/client/TableSessionPool.ts b/src/client/TableSessionPool.ts
index 3eacb0c..bfeb4c1 100644
--- a/src/client/TableSessionPool.ts
+++ b/src/client/TableSessionPool.ts
@@ -18,7 +18,7 @@
*/
import { TableSession } from "./TableSession";
-import { Session, TableTablet, TreeTablet } from "./Session";
+import { Session } from "./Session";
import { PoolConfig, SQL_DIALECT_TABLE, InternalConfig } from "../utils/Config";
import { BaseSessionPool } from "./BaseSessionPool";
import { logger } from "../utils/Logger";
diff --git a/tests/e2e/AllDataTypes.test.ts b/tests/e2e/AllDataTypes.test.ts
index 184badb..de63ec9 100644
--- a/tests/e2e/AllDataTypes.test.ts
+++ b/tests/e2e/AllDataTypes.test.ts
@@ -39,7 +39,7 @@
try {
await session.open();
console.log("Connected to IoTDB for all data types test");
- } catch (error) {
+ } catch {
console.warn("Could not connect to IoTDB. E2E tests will be skipped.");
console.warn(
"Set IOTDB_HOST, IOTDB_PORT to run E2E tests against a real instance.",
diff --git a/tests/e2e/LargeQuery.test.ts b/tests/e2e/LargeQuery.test.ts
index b5c81c2..c44e56f 100644
--- a/tests/e2e/LargeQuery.test.ts
+++ b/tests/e2e/LargeQuery.test.ts
@@ -40,7 +40,7 @@
try {
await session.open();
console.log("Connected to IoTDB for large query tests");
- } catch (error) {
+ } catch {
console.warn("Could not connect to IoTDB. E2E tests will be skipped.");
console.warn(
"Set IOTDB_HOST, IOTDB_PORT to run E2E tests against a real instance.",
@@ -58,7 +58,7 @@
// Cleanup test data
try {
await session.executeNonQueryStatement("DROP DATABASE root.test");
- } catch (error) {
+ } catch {
// Ignore cleanup errors
}
await session.close();
diff --git a/tests/e2e/MultiNode.test.ts b/tests/e2e/MultiNode.test.ts
index d01ce24..7c2c6fb 100644
--- a/tests/e2e/MultiNode.test.ts
+++ b/tests/e2e/MultiNode.test.ts
@@ -103,7 +103,7 @@
if (isConnected) {
try {
await pool1.executeNonQueryStatement("DROP DATABASE root.test");
- } catch (error) {
+ } catch {
// Ignore cleanup errors
}
diff --git a/tests/e2e/Session.test.ts b/tests/e2e/Session.test.ts
index 1be2e28..e21b0b2 100644
--- a/tests/e2e/Session.test.ts
+++ b/tests/e2e/Session.test.ts
@@ -38,7 +38,7 @@
try {
await session.open();
- } catch (error) {
+ } catch {
console.warn("Could not connect to IoTDB. E2E tests will be skipped.");
console.warn(
"Set IOTDB_HOST, IOTDB_PORT to run E2E tests against a real instance.",
@@ -56,7 +56,7 @@
// Cleanup test data
try {
await session.executeNonQueryStatement("DROP DATABASE root.test");
- } catch (e) {
+ } catch {
// Ignore cleanup errors
}
await session.close();
diff --git a/tests/e2e/SessionDataSet.test.ts b/tests/e2e/SessionDataSet.test.ts
index cbd3a5c..2bde591 100644
--- a/tests/e2e/SessionDataSet.test.ts
+++ b/tests/e2e/SessionDataSet.test.ts
@@ -36,7 +36,7 @@
try {
await session.open();
- } catch (error) {
+ } catch {
console.warn("Could not connect to IoTDB. Tests will be skipped.");
try {
await session.close();
@@ -61,7 +61,7 @@
// Setup test data
try {
await session.executeNonQueryStatement("DELETE DATABASE root.test");
- } catch (e) {
+ } catch {
// Ignore if doesn't exist
}
@@ -247,7 +247,7 @@
// Setup test data
try {
await session.executeNonQueryStatement("DELETE DATABASE root.test");
- } catch (e) {
+ } catch {
// Ignore
}
diff --git a/tests/e2e/SessionPool.test.ts b/tests/e2e/SessionPool.test.ts
index e5464fb..bda032e 100644
--- a/tests/e2e/SessionPool.test.ts
+++ b/tests/e2e/SessionPool.test.ts
@@ -40,7 +40,7 @@
try {
await pool.init();
isConnected = true;
- } catch (error) {
+ } catch {
console.warn("Could not connect to IoTDB. E2E tests will be skipped.");
console.warn(
"Set IOTDB_HOST, IOTDB_PORT to run E2E tests against a real instance.",
@@ -58,7 +58,7 @@
// Cleanup test data
try {
await pool.executeNonQueryStatement("DROP DATABASE root.test");
- } catch (error) {
+ } catch {
// Ignore cleanup errors
}
await pool.close();
@@ -182,7 +182,7 @@
await multiNodePool.init();
expect(multiNodePool.getPoolSize()).toBeGreaterThanOrEqual(1);
await multiNodePool.close();
- } catch (error) {
+ } catch {
console.warn(
"Multi-node test failed, this is expected if IoTDB is not available",
);
diff --git a/tests/e2e/TableModelDataTypes.test.ts b/tests/e2e/TableModelDataTypes.test.ts
index d00580d..632b85e 100644
--- a/tests/e2e/TableModelDataTypes.test.ts
+++ b/tests/e2e/TableModelDataTypes.test.ts
@@ -47,10 +47,10 @@
// Cleanup from previous runs
try {
await pool.executeNonQueryStatement("DROP DATABASE test");
- } catch (e) {
+ } catch {
// Ignore if doesn't exist
}
- } catch (error) {
+ } catch {
console.warn("Could not connect to IoTDB. E2E tests will be skipped.");
console.warn(
"Set IOTDB_HOST, IOTDB_PORT to run E2E tests against a real instance.",
@@ -68,7 +68,7 @@
// Cleanup test data
try {
await pool.executeNonQueryStatement("DROP DATABASE test");
- } catch (error) {
+ } catch {
// Ignore cleanup errors
}
await pool.close();
diff --git a/tests/e2e/TableSessionPool.test.ts b/tests/e2e/TableSessionPool.test.ts
index f7fbb78..5ff13a1 100644
--- a/tests/e2e/TableSessionPool.test.ts
+++ b/tests/e2e/TableSessionPool.test.ts
@@ -45,10 +45,10 @@
// Cleanup from previous runs
try {
await pool.executeNonQueryStatement("DROP DATABASE test");
- } catch (e) {
+ } catch {
// Ignore errors if database doesn't exist
}
- } catch (error) {
+ } catch {
console.warn("Could not connect to IoTDB. E2E tests will be skipped.");
console.warn(
"Set IOTDB_HOST, IOTDB_PORT to run E2E tests against a real instance.",
@@ -66,7 +66,7 @@
// Cleanup
try {
await pool.executeNonQueryStatement("DROP DATABASE test");
- } catch (e) {
+ } catch {
// Ignore cleanup errors
}
await pool.close();
@@ -401,7 +401,7 @@
await pool.executeNonQueryStatement(
`CREATE TABLE IF NOT EXISTS ${tableName}(device_id STRING TAG, value FLOAT FIELD)`
);
- } catch (e: any) {
+ } catch {
// Ignore if already exists
}
@@ -456,7 +456,7 @@
await session.executeNonQueryStatement(
`CREATE TABLE IF NOT EXISTS ${tableName}(device_id STRING TAG, value FLOAT FIELD)`
);
- } catch (e: any) {
+ } catch {
// Ignore if already exists
}
return tableName;