Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
yianzhang14 committed Feb 4, 2025
1 parent c09f399 commit afc6605
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 372 deletions.
140 changes: 70 additions & 70 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command } from "commander";
import { Git } from "./src/models/Git";
import dataSource from "./src/utils/DB";

const pkg: {version: string} = require("../package.json"); // eslint-disable-line
const pkg: { version: string } = require("../package.json"); // eslint-disable-line
const cmd = new Command();

interface CommandOptions {
Expand All @@ -27,93 +27,93 @@ cmd
.option("-s, --sha <sha>", "[operation=add/update] git repository's sha hash")
.action(async (operation: string, cmd: CommandOptions) => {
switch (operation) {
case "add": {
const git = new Git();
case "add": {
const git = new Git();

if (cmd.address && cmd.id) {
git.address = cmd.address;
git.id = cmd.id;
} else {
console.error(
"-a, --address <address> and -i, --id <id> flags is required"
);
return;
}
if (cmd.address && cmd.id) {
git.address = cmd.address;
git.id = cmd.id;
} else {
console.error(
"-a, --address <address> and -i, --id <id> flags is required"
);
return;
}

git.isApproved = true;
if (cmd.sha) git.sha = cmd.sha;
git.isApproved = true;
if (cmd.sha) git.sha = cmd.sha;

const gitRepo = dataSource.getRepository(Git);
await gitRepo.save(git);
const gitRepo = dataSource.getRepository(Git);
await gitRepo.save(git);

console.log("git successfully added:");
console.log(git);
console.log("git successfully added:");
console.log(git);

break;
}
case "update": {
if (!cmd.id) {
console.error("-i, --id <id> flag is required");
return;
break;
}
case "update": {
if (!cmd.id) {
console.error("-i, --id <id> flag is required");
return;
}

const i: { address?: string, sha?: string } = {};
const i: { address?: string, sha?: string } = {};

if (cmd.address) i.address = cmd.address;
if (cmd.sha) i.sha = cmd.sha;
if (cmd.address) i.address = cmd.address;
if (cmd.sha) i.sha = cmd.sha;

await dataSource
.createQueryBuilder()
.update(Git)
.where("id = :id", { id: cmd.id })
.set(i)
.execute();
await dataSource
.createQueryBuilder()
.update(Git)
.where("id = :id", { id: cmd.id })
.set(i)
.execute();

console.log("git successfully updated:");
const gitRepo = dataSource.getRepository(Git);
console.log(await gitRepo.findOneBy({ id: cmd.id }));
console.log("git successfully updated:");
const gitRepo = dataSource.getRepository(Git);
console.log(await gitRepo.findOneBy({ id: cmd.id }));

break;
}
case "approve": {
if (!cmd.id) {
console.error("-i, --id <id> flag is required");
return;
break;
}

await dataSource
.createQueryBuilder()
.update(Git)
.where("id = :id", { id: cmd.id })
.set({ isApproved: true })
.execute();

console.log("git approved");

break;
}
case "delete": {
if (!cmd.id) {
console.error("-i, --id <id> flag is required");
return;
case "approve": {
if (!cmd.id) {
console.error("-i, --id <id> flag is required");
return;
}

await dataSource
.createQueryBuilder()
.update(Git)
.where("id = :id", { id: cmd.id })
.set({ isApproved: true })
.execute();

console.log("git approved");

break;
}
case "delete": {
if (!cmd.id) {
console.error("-i, --id <id> flag is required");
return;
}

const gitRepo = dataSource.getRepository(Git);
await gitRepo.delete(cmd.id);
const gitRepo = dataSource.getRepository(Git);
await gitRepo.delete(cmd.id);

console.log("git successfully deleted");
console.log("git successfully deleted");

break;
}
default: {
console.error(
"<operation> invalid operation, only support [add/update/delete/approve]"
);
break;
}
default: {
console.error(
"<operation> invalid operation, only support [add/update/delete/approve]"
);

break;
}
break;
}
}

await dataSource.destroy();
});

Expand Down
22 changes: 13 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = tseslint.config(
...globals.node
}
},

},

{
Expand All @@ -34,7 +34,11 @@ module.exports = tseslint.config(
rules: {
indent: [
"error",
2
2,
{
"SwitchCase": 1,
"ignoredNodes": ["ConditionalExpression", "flatTernaryExpressions "]
},
],
"linebreak-style": 0,
quotes: [
Expand All @@ -45,7 +49,7 @@ module.exports = tseslint.config(
"error",
"always"
],
"no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error", { argsIgnorePattern: "^_" }
],
Expand Down Expand Up @@ -81,12 +85,12 @@ module.exports = tseslint.config(
},
],
"stylistic/max-len": [
"error",
{
ignoreTemplateLiterals: true,
code: 100,
ignoreComments: true,
ignoreStrings: true
"error",
{
ignoreTemplateLiterals: true,
code: 100,
ignoreComments: true,
ignoreStrings: true
}
],
"stylistic/object-curly-spacing": [
Expand Down
Loading

0 comments on commit afc6605

Please sign in to comment.