Skip to content

Commit bab2d62

Browse files
author
Jérémy Christillin
committed
Fix ESLint errors and code quality issues
- Fix indentation errors in backup-manager.js and health-monitor.js - Add missing import for extractHostFromSSHError in index.js - Fix ssh_tunnel_create to use SSHManager instead of undefined getSSHConnection - Fix lexical declaration errors in case blocks (wrap in braces) - Remove unused imports (fs, logger, crypto, etc.) - Fix trailing spaces and missing newlines - Fix quote style consistency (single quotes) All ESLint errors are now resolved. Warnings remain for unused imports that may be needed for future features.
1 parent 3d3dbe2 commit bab2d62

16 files changed

+1293
-1291
lines changed

src/backup-manager.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,16 @@ export function buildFilesBackupCommand(options) {
207207
*/
208208
export function buildRestoreCommand(backupType, backupFile, options = {}) {
209209
switch (backupType) {
210-
case BACKUP_TYPES.MYSQL:
211-
return buildMySQLRestoreCommand(backupFile, options);
212-
case BACKUP_TYPES.POSTGRESQL:
213-
return buildPostgreSQLRestoreCommand(backupFile, options);
214-
case BACKUP_TYPES.MONGODB:
215-
return buildMongoDBRestoreCommand(backupFile, options);
216-
case BACKUP_TYPES.FILES:
217-
return buildFilesRestoreCommand(backupFile, options);
218-
default:
219-
throw new Error(`Unknown backup type: ${backupType}`);
210+
case BACKUP_TYPES.MYSQL:
211+
return buildMySQLRestoreCommand(backupFile, options);
212+
case BACKUP_TYPES.POSTGRESQL:
213+
return buildPostgreSQLRestoreCommand(backupFile, options);
214+
case BACKUP_TYPES.MONGODB:
215+
return buildMongoDBRestoreCommand(backupFile, options);
216+
case BACKUP_TYPES.FILES:
217+
return buildFilesRestoreCommand(backupFile, options);
218+
default:
219+
throw new Error(`Unknown backup type: ${backupType}`);
220220
}
221221
}
222222

@@ -379,7 +379,7 @@ export function createBackupMetadata(backupId, type, options = {}) {
379379
export function buildSaveMetadataCommand(metadata, metadataPath) {
380380
const jsonData = JSON.stringify(metadata, null, 2);
381381
// Escape single quotes in JSON for shell
382-
const escapedJson = jsonData.replace(/'/g, "'\\''");
382+
const escapedJson = jsonData.replace(/'/g, '\'\\\'\'');
383383
return `echo '${escapedJson}' > "${metadataPath}"`;
384384
}
385385

@@ -394,7 +394,7 @@ export function buildListBackupsCommand(backupDir = DEFAULT_BACKUP_DIR, type = n
394394
}
395395

396396
// Read and parse each metadata file
397-
command += ` | while read -r file; do cat "$file"; echo "---"; done`;
397+
command += ' | while read -r file; do cat "$file"; echo "---"; done';
398398

399399
return command;
400400
}

src/command-aliases.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export function loadCommandAliases() {
2929
try {
3030
// Start with profile aliases
3131
let aliases = { ...profileAliases };
32-
32+
3333
// Merge with custom aliases from file
3434
if (fs.existsSync(ALIASES_FILE)) {
3535
const data = fs.readFileSync(ALIASES_FILE, 'utf8');
3636
aliases = { ...aliases, ...JSON.parse(data) };
3737
}
38-
38+
3939
return aliases;
4040
} catch (error) {
4141
console.error(`Error loading command aliases: ${error.message}`);
@@ -55,7 +55,7 @@ export function saveCommandAliases(aliases) {
5555
customAliases[key] = value;
5656
}
5757
}
58-
58+
5959
fs.writeFileSync(ALIASES_FILE, JSON.stringify(customAliases, null, 2));
6060
return true;
6161
} catch (error) {
@@ -69,21 +69,21 @@ export function saveCommandAliases(aliases) {
6969
*/
7070
export function expandCommandAlias(command) {
7171
const aliases = loadCommandAliases();
72-
72+
7373
// Check if the entire command is an alias
7474
if (aliases[command]) {
7575
return aliases[command];
7676
}
77-
77+
7878
// Check if the command starts with an alias
7979
const parts = command.split(' ');
8080
const firstPart = parts[0];
81-
81+
8282
if (aliases[firstPart]) {
8383
parts[0] = aliases[firstPart];
8484
return parts.join(' ');
8585
}
86-
86+
8787
return command;
8888
}
8989

@@ -101,14 +101,14 @@ export function addCommandAlias(alias, command) {
101101
*/
102102
export function removeCommandAlias(alias) {
103103
const aliases = loadCommandAliases();
104-
104+
105105
// Don't remove profile aliases, just reset them
106106
if (profileAliases[alias]) {
107107
aliases[alias] = profileAliases[alias];
108108
} else {
109109
delete aliases[alias];
110110
}
111-
111+
112112
return saveCommandAliases(aliases);
113113
}
114114

@@ -118,7 +118,7 @@ export function removeCommandAlias(alias) {
118118
export function listCommandAliases() {
119119
const aliases = loadCommandAliases();
120120
const result = [];
121-
121+
122122
for (const [alias, command] of Object.entries(aliases)) {
123123
result.push({
124124
alias,
@@ -127,7 +127,7 @@ export function listCommandAliases() {
127127
isCustom: profileAliases[alias] !== command
128128
});
129129
}
130-
130+
131131
return result.sort((a, b) => a.alias.localeCompare(b.alias));
132132
}
133133

@@ -137,15 +137,15 @@ export function listCommandAliases() {
137137
export function suggestAliases(command) {
138138
const suggestions = [];
139139
const aliases = loadCommandAliases();
140-
140+
141141
const commandLower = command.toLowerCase();
142-
142+
143143
for (const [alias, aliasCommand] of Object.entries(aliases)) {
144-
if (aliasCommand.toLowerCase().includes(commandLower) ||
144+
if (aliasCommand.toLowerCase().includes(commandLower) ||
145145
alias.toLowerCase().includes(commandLower)) {
146146
suggestions.push({ alias, command: aliasCommand });
147147
}
148148
}
149-
149+
150150
return suggestions;
151-
}
151+
}

src/config-loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,4 @@ export class ConfigLoader {
278278
}
279279

280280
// Export singleton instance
281-
export const configLoader = new ConfigLoader();
281+
export const configLoader = new ConfigLoader();

src/database-manager.js

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Provides database operations for MySQL, PostgreSQL, and MongoDB
44
*/
55

6-
import { logger } from './logger.js';
7-
86
// Supported database types
97
export const DB_TYPES = {
108
MYSQL: 'mysql',
@@ -254,7 +252,7 @@ export function buildMySQLListDatabasesCommand(options) {
254252
if (password) command += ` -p'${password}'`;
255253
if (host) command += ` -h ${host}`;
256254
if (port) command += ` -P ${port}`;
257-
command += ` -e "SHOW DATABASES;" | tail -n +2`;
255+
command += ' -e "SHOW DATABASES;" | tail -n +2';
258256

259257
return command;
260258
}
@@ -290,7 +288,7 @@ export function buildPostgreSQLListDatabasesCommand(options) {
290288
if (user) command += ` -U ${user}`;
291289
if (host) command += ` -h ${host}`;
292290
if (port) command += ` -p ${port}`;
293-
command += ` -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;" | sed '/^$/d' | sed 's/^[ \\t]*//'`;
291+
command += ' -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;" | sed \'/^$/d\' | sed \'s/^[ \\t]*//\'';
294292

295293
return command;
296294
}
@@ -311,7 +309,7 @@ export function buildPostgreSQLListTablesCommand(options) {
311309
if (host) command += ` -h ${host}`;
312310
if (port) command += ` -p ${port}`;
313311
command += ` -d ${database}`;
314-
command += ` -t -c "SELECT tablename FROM pg_tables WHERE schemaname = 'public';" | sed '/^$/d' | sed 's/^[ \\t]*//'`;
312+
command += ' -t -c "SELECT tablename FROM pg_tables WHERE schemaname = \'public\';" | sed \'/^$/d\' | sed \'s/^[ \\t]*//\'';
315313

316314
return command;
317315
}
@@ -327,7 +325,7 @@ export function buildMongoDBListDatabasesCommand(options) {
327325
if (port) command += ` --port ${port}`;
328326
if (user) command += ` --username ${user}`;
329327
if (password) command += ` --password '${password}'`;
330-
command += ` --quiet --eval "db.adminCommand('listDatabases').databases.forEach(function(d){print(d.name)})"`;
328+
command += ' --quiet --eval "db.adminCommand(\'listDatabases\').databases.forEach(function(d){print(d.name)})"';
331329

332330
return command;
333331
}
@@ -344,7 +342,7 @@ export function buildMongoDBListCollectionsCommand(options) {
344342
if (user) command += ` --username ${user}`;
345343
if (password) command += ` --password '${password}'`;
346344
command += ` ${database}`;
347-
command += ` --quiet --eval "db.getCollectionNames().forEach(function(c){print(c)})"`;
345+
command += ' --quiet --eval "db.getCollectionNames().forEach(function(c){print(c)})"';
348346

349347
return command;
350348
}
@@ -479,43 +477,43 @@ export function buildEstimateSizeCommand(type, database, options = {}) {
479477
const { user, password, host = 'localhost', port } = options;
480478

481479
switch (type) {
482-
case DB_TYPES.MYSQL: {
483-
let command = 'mysql';
484-
if (user) command += ` -u${user}`;
485-
if (password) command += ` -p'${password}'`;
486-
if (host) command += ` -h ${host}`;
487-
if (port) command += ` -P ${port}`;
488-
command += ` -e "SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema='${database}';" | tail -n 1`;
489-
return command;
490-
}
480+
case DB_TYPES.MYSQL: {
481+
let command = 'mysql';
482+
if (user) command += ` -u${user}`;
483+
if (password) command += ` -p'${password}'`;
484+
if (host) command += ` -h ${host}`;
485+
if (port) command += ` -P ${port}`;
486+
command += ` -e "SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema='${database}';" | tail -n 1`;
487+
return command;
488+
}
491489

492-
case DB_TYPES.POSTGRESQL: {
493-
let command = '';
494-
if (password) {
495-
command = `PGPASSWORD='${password}' `;
496-
}
497-
command += 'psql';
498-
if (user) command += ` -U ${user}`;
499-
if (host) command += ` -h ${host}`;
500-
if (port) command += ` -p ${port}`;
501-
command += ` -d ${database}`;
502-
command += ` -t -c "SELECT pg_database_size('${database}');" | sed 's/^[ \\t]*//'`;
503-
return command;
490+
case DB_TYPES.POSTGRESQL: {
491+
let command = '';
492+
if (password) {
493+
command = `PGPASSWORD='${password}' `;
504494
}
495+
command += 'psql';
496+
if (user) command += ` -U ${user}`;
497+
if (host) command += ` -h ${host}`;
498+
if (port) command += ` -p ${port}`;
499+
command += ` -d ${database}`;
500+
command += ` -t -c "SELECT pg_database_size('${database}');" | sed 's/^[ \\t]*//'`;
501+
return command;
502+
}
505503

506-
case DB_TYPES.MONGODB: {
507-
let command = 'mongo';
508-
if (host) command += ` --host ${host}`;
509-
if (port) command += ` --port ${port}`;
510-
if (user) command += ` --username ${user}`;
511-
if (password) command += ` --password '${password}'`;
512-
command += ` ${database}`;
513-
command += ` --quiet --eval "db.stats().dataSize"`;
514-
return command;
515-
}
504+
case DB_TYPES.MONGODB: {
505+
let command = 'mongo';
506+
if (host) command += ` --host ${host}`;
507+
if (port) command += ` --port ${port}`;
508+
if (user) command += ` --username ${user}`;
509+
if (password) command += ` --password '${password}'`;
510+
command += ` ${database}`;
511+
command += ' --quiet --eval "db.stats().dataSize"';
512+
return command;
513+
}
516514

517-
default:
518-
throw new Error(`Unknown database type: ${type}`);
515+
default:
516+
throw new Error(`Unknown database type: ${type}`);
519517
}
520518
}
521519

src/deploy-helper.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from 'fs';
21
import path from 'path';
32
import crypto from 'crypto';
43

@@ -43,8 +42,8 @@ export function buildDeploymentStrategy(remotePath, options = {}) {
4342
}
4443

4544
// Step 2: Determine if we need sudo
46-
const needsSudo = remotePath.startsWith('/etc/') ||
47-
remotePath.startsWith('/var/') ||
45+
const needsSudo = remotePath.startsWith('/etc/') ||
46+
remotePath.startsWith('/var/') ||
4847
remotePath.startsWith('/usr/') ||
4948
owner || permissions;
5049

@@ -53,11 +52,11 @@ export function buildDeploymentStrategy(remotePath, options = {}) {
5352
}
5453

5554
// Step 3: Copy from temp to final location
56-
const copyCmd = needsSudo && sudoPassword ?
55+
const copyCmd = needsSudo && sudoPassword ?
5756
`echo "${sudoPassword}" | sudo -S cp {{tempFile}} "${remotePath}"` :
5857
needsSudo ?
59-
`sudo cp {{tempFile}} "${remotePath}"` :
60-
`cp {{tempFile}} "${remotePath}"`;
58+
`sudo cp {{tempFile}} "${remotePath}"` :
59+
`cp {{tempFile}} "${remotePath}"`;
6160

6261
strategy.steps.push({
6362
type: 'copy',
@@ -69,7 +68,7 @@ export function buildDeploymentStrategy(remotePath, options = {}) {
6968
const chownCmd = sudoPassword ?
7069
`echo "${sudoPassword}" | sudo -S chown ${owner} "${remotePath}"` :
7170
`sudo chown ${owner} "${remotePath}"`;
72-
71+
7372
strategy.steps.push({
7473
type: 'chown',
7574
command: chownCmd
@@ -81,7 +80,7 @@ export function buildDeploymentStrategy(remotePath, options = {}) {
8180
const chmodCmd = sudoPassword ?
8281
`echo "${sudoPassword}" | sudo -S chmod ${permissions} "${remotePath}"` :
8382
`sudo chmod ${permissions} "${remotePath}"`;
84-
83+
8584
strategy.steps.push({
8685
type: 'chmod',
8786
command: chmodCmd
@@ -151,11 +150,11 @@ export function detectDeploymentNeeds(remotePath) {
151150
*/
152151
export function createBatchDeployScript(deployments) {
153152
const script = ['#!/bin/bash', 'set -e', ''];
154-
153+
155154
script.push('# Batch deployment script');
156155
script.push(`# Generated at ${new Date().toISOString()}`);
157156
script.push('');
158-
157+
159158
deployments.forEach((deploy, index) => {
160159
script.push(`# File ${index + 1}: ${deploy.localPath} -> ${deploy.remotePath}`);
161160
deploy.strategy.steps.forEach(step => {
@@ -165,12 +164,12 @@ export function createBatchDeployScript(deployments) {
165164
});
166165
script.push('');
167166
});
168-
167+
169168
// Cleanup all temp files at the end
170169
script.push('# Cleanup temporary files');
171170
deployments.forEach(deploy => {
172171
script.push(`rm -f ${deploy.tempFile}`);
173172
});
174-
173+
175174
return script.join('\n');
176-
}
175+
}

0 commit comments

Comments
 (0)