Skip to content

Commit

Permalink
feat: add eslint check
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Feb 10, 2024
1 parent 26441f1 commit 067421f
Show file tree
Hide file tree
Showing 17 changed files with 1,099 additions and 793 deletions.
14 changes: 12 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"extends": "next/core-web-vitals",
"extends": ["next/core-web-vitals", "eslint:recommended", "plugin:@typescript-eslint/recommended"],
"rules": {
"@next/next/no-img-element": "off"
}
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"overrides": [
{
"files": ["*.test.ts"],
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"],
"rules": { "jest/prefer-expect-assertions": "off" }
}
]
}
1,803 changes: 1,040 additions & 763 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"clsx": "^2.1.0",
"cmdk": "^0.2.0",
"dbgate-query-splitter": "^4.9.3",
"eslint-plugin-jest": "^27.6.3",
"lucide-react": "^0.309.0",
"next": "14.0.4",
"react": "^18",
Expand All @@ -52,6 +53,8 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.0.4",
Expand Down
2 changes: 1 addition & 1 deletion src/app/(components)/Cells/GenericCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default function GenericCell({
onMouseDown={onFocus}
onDoubleClick={onDoubleClick}
>
{(value as any).toString()}
{value.toString()}
</div>
);
}
2 changes: 1 addition & 1 deletion src/app/(components)/Cells/createEditableCell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DatabaseValue } from "@/drivers/DatabaseDriver";
import { useState, useEffect, FunctionComponent } from "react";
import { useState, useEffect } from "react";
import GenericCell from "./GenericCell";
import styles from "./styles.module.css";

Expand Down
1 change: 0 additions & 1 deletion src/app/(components)/ContentMenuHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
ContextMenuSubContent,
} from "@/components/ui/context-menu";
import { useEffect, useRef, useState } from "react";
import { LucideIcon } from "lucide-react";

function ContextMenuList({ menu }: { menu: OpenContextMenuList }) {
return menu.map((item, menuIndex) => {
Expand Down
5 changes: 2 additions & 3 deletions src/app/(components)/MainScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use client";
import DatabaseDriver from "@/drivers/DatabaseDriver";
import { useMemo, useEffect, useState, useLayoutEffect } from "react";
import { useMemo, useEffect, useLayoutEffect } from "react";
import DatabaseGui from "./DatabaseGui";
import { DatabaseDriverProvider } from "@/context/DatabaseDriverProvider";
import { TooltipProvider } from "@/components/ui/tooltip";
import { AutoCompleteProvider } from "@/context/AutoCompleteProvider";
import ContextMenuHandler from "./ContentMenuHandler";
import InternalPubSub from "@/lib/internal-pubsub";
import { useParams, useRouter } from "next/navigation";
import { Metadata } from "next";
import { useRouter } from "next/navigation";

function MainConnection({
credential,
Expand Down
1 change: 0 additions & 1 deletion src/app/(components)/OptimizeTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ function handleTableCellMouseDown({
y,
x,
ctrl,
shift,
}: {
y: number;
x: number;
Expand Down
2 changes: 1 addition & 1 deletion src/app/(components)/QueryProgressLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function QueryProgressLog({
}: {
progress: MultipleQueryProgress;
}) {
const [currentTime, setCurrentTime] = useState(() => Date.now());
const [, setCurrentTime] = useState(() => Date.now());

useEffect(() => {
if (!progress.error) {
Expand Down
2 changes: 0 additions & 2 deletions src/app/(components)/TopNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use client";
import * as React from "react";
import Link from "next/link";

import { cn } from "@/lib/utils";
import {
NavigationMenu,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/export-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function exportRowsToSqlInsert(
headers: string[],
records: unknown[][]
): string {
let result: string[] = [];
const result: string[] = [];

const headersPart = headers.map(escapeIdentity).join(", ");

Expand All @@ -35,7 +35,7 @@ function cellToExcelValue(value: unknown) {
}

export function exportRowsToExcel(records: unknown[][]) {
let result: string[] = [];
const result: string[] = [];

for (const record of records) {
const line = record.map(cellToExcelValue).join("\t");
Expand Down
1 change: 1 addition & 0 deletions src/lib/internal-pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default class InternalPubSub {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected listeners: Record<string, ((obj: any) => void)[]> = {};

addListener<T = unknown>(channel: string, callback: (obj: T) => void) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/multiple-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function multipleQuery(
}
} catch (e) {
log.end = Date.now();
log.error = (e as any).toString();
log.error = (e as Error).toString();

if (onProgress) {
onProgress({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sql-execute-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ export async function executePlans(
return { success: true, plans };
} catch (e) {
await driver.query("ROLLBACK");
return { success: false, error: (e as any).toString(), plans: [] };
return { success: false, error: (e as Error).toString(), plans: [] };
}
}
4 changes: 3 additions & 1 deletion src/lib/sql-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ describe("Mapping sqlite column type to our table type", () => {
expect(convertSqliteType(type)).toBe(TableColumnDataType.TEXT));
}

expect(convertSqliteType("BLOB")).toBe(TableColumnDataType.BLOB);
it("BLOB column type", () => {
expect(convertSqliteType("BLOB")).toBe(TableColumnDataType.BLOB);
});

const realType = ["REAL", "DOUBLE", "DOUBLE PRECISION", "FLOAT"];
for (const type of realType) {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/sql-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export function generateInsertStatement(
tableName: string,
value: Record<string, unknown>
): string {
let fieldPart: string[] = [];
let valuePart: unknown[] = [];
const fieldPart: string[] = [];
const valuePart: unknown[] = [];

for (const entry of Object.entries(value)) {
fieldPart.push(entry[0]);
Expand All @@ -91,7 +91,7 @@ export function generateDeleteStatement(
tableName: string,
where: Record<string, unknown>
) {
let wherePart: string = Object.entries(where)
const wherePart: string = Object.entries(where)
.map(
([columnName, value]) =>
`${escapeIdentity(columnName)} = ${escapeSqlValue(value)}`
Expand All @@ -112,7 +112,7 @@ export function generateUpdateStatement(
})
.join(", ");

let wherePart: string = Object.entries(where)
const wherePart: string = Object.entries(where)
.map(
([columnName, value]) =>
`${escapeIdentity(columnName)} = ${escapeSqlValue(value)}`
Expand Down
36 changes: 27 additions & 9 deletions src/lib/sql-parse-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DatabaseTableSchema,
} from "@/drivers/DatabaseDriver";
import { SQLite } from "@codemirror/lang-sql";
import { SyntaxNode, Tree, TreeCursor } from "@lezer/common";
import { SyntaxNode, TreeCursor } from "@lezer/common";
import { unescapeIdentity } from "./sql-helper";

class Cursor {
Expand Down Expand Up @@ -38,7 +38,7 @@ class Cursor {
if (keywords.length === 0) return;
if (this.matchKeyword(keywords[0])) {
this.next();
for (let k of keywords.slice(1)) {
for (const k of keywords.slice(1)) {
this.expectKeyword(k);
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ class Cursor {
}

enterParens(): Cursor | null {
if (this.ptr && this.ptr.firstChild) {
if (this.ptr?.firstChild) {
if (this.ptr.firstChild.name !== "(") return null;
if (!this.ptr.firstChild.nextSibling) return null;
return new Cursor(this.ptr.firstChild.nextSibling.cursor(), this.sql);
Expand Down Expand Up @@ -240,7 +240,7 @@ export function parseColumnConstraint(
...parseColumnConstraint(cursor),
};
} else if (cursor.matchKeyword("DEFAULT")) {
let defaultValue: unknown | undefined;
let defaultValue: unknown;
let defaultExpression: string | undefined;

cursor.next();
Expand Down Expand Up @@ -271,7 +271,25 @@ export function parseColumnConstraint(
...parseColumnConstraint(cursor),
};
} else if (cursor.matchKeyword("CHECK")) {
cursor.next();

const expr = cursor.read();
cursor.next();

return {
checkExpression: expr,
...parseColumnConstraint(cursor),
};
} else if (cursor.matchKeyword("COLLATE")) {
cursor.next();

const collationName = cursor.read();
cursor.next();

return {
collate: collationName,
...parseColumnConstraint(cursor),
};
} else if (cursor.matchKeyword("FOREIGN")) {
cursor.next();

Expand Down Expand Up @@ -302,10 +320,11 @@ export function parseColumnConstraint(
// We may visit more rule in the future, but at the moment
// it is too complex to handle all the rules.
// We will just grab foreign key column first
while (true) {
if (cursor.end()) break;
if (cursor.type() === "Parens") break;
if (cursor.match(",")) break;
while (
!cursor.end() ||
!(cursor.type() === "Parens") ||
!cursor.match(",")
) {
cursor.next();
}

Expand Down Expand Up @@ -415,7 +434,6 @@ export function parseCreateTableScript(sql: string): DatabaseTableSchema {

ptr.firstChild();
ptr.firstChild();
// console.log(ptr.tree?.toString());

const cursor = new Cursor(ptr, sql);
cursor.expectKeyword("CREATE");
Expand Down

0 comments on commit 067421f

Please sign in to comment.