Skip to content

Commit

Permalink
Now with ESLint!
Browse files Browse the repository at this point in the history
  • Loading branch information
tmr232 committed Sep 5, 2024
1 parent 8897e37 commit 6fd70a8
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 59 deletions.
30 changes: 0 additions & 30 deletions .eslintrc.json

This file was deleted.

Binary file modified bun.lockb
Binary file not shown.
26 changes: 26 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ["dist/*", "webview-content/*", "src/frontend"],

},
{
rules: {
"@typescript-eslint/no-unused-vars": [
"error", // or "error"
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
}
}

);
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"main": "./dist/vscode/extension.cjs",
"module": "index.ts",
"type": "module",
"dependencies": {
"@hpcc-js/wasm-graphviz": "^1.3.0",
"@types/vscode": "^1.86.0",
Expand All @@ -10,21 +11,24 @@
"web-tree-sitter": "^0.23.0"
},
"devDependencies": {
"@eslint/js": "^9.9.1",
"@rollup/plugin-wasm": "^6.2.2",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@types/bun": "latest",
"@types/eslint__js": "^8.42.3",
"@vscode/vsce": "^3.0.0",
"esbuild": "^0.20.0",
"esbuild-plugin-copy": "^2.1.1",
"@rollup/plugin-wasm": "^6.2.2",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"eslint": "^9.9.1",
"svelte": "^4.2.18",
"tree-sitter-cli": "^0.23.0",
"vite": "^5.4.1",
"tree-sitter-go": "^0.23.0"
"tree-sitter-go": "^0.23.0",
"typescript-eslint": "^8.4.0",
"vite": "^5.4.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
"typescript": "^5.5.4"
},
"type": "module",
"scripts": {
"dev": "echo 'Open this directory in VSCode and then run your extension with F5 or `Run and Debug > Run Extension`!'",
"build": "bun run ./scripts/build-with-esbuild.ts",
Expand Down
2 changes: 1 addition & 1 deletion scripts/watch-with-esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import config from "./esbuild.config";
try {
const context = await esbuild.context(config);
await context.watch();
} catch (e) {
} catch (_e) {
process.exit(1);
}
26 changes: 14 additions & 12 deletions src/control-flow/cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ export class CFGBuilder {
return this.processForStatement(node);
case 'expression_switch_statement':
return this.processSwitchStatement(node);
case 'return_statement':
case 'return_statement': {
const returnNode = this.addNode('RETURN', node.text);
return { entry: returnNode, exit: null };
}
case 'break_statement':
return this.processBreakStatement(node);
case 'continue_statement':
Expand All @@ -175,16 +176,17 @@ export class CFGBuilder {
return this.processTypeSwitchStatement(node);
case 'select_statement':
return this.processSelectStatement(node);
default:
default: {
const newNode = this.addNode('STATEMENT', node.text);
return { entry: newNode, exit: newNode };
}
}
}

private processSwitchlike(switchlikeSyntax: Parser.SyntaxNode, props: SwitchlikeProps): BasicBlock {
const { nodeType, mergeType, mergeCode, caseName, caseTypeName, caseFieldName } = props;

let blockHandler = new BlockHandler();
const blockHandler = new BlockHandler();
const valueNode = this.addNode(
nodeType,
this.getChildFieldText(switchlikeSyntax, 'value')
Expand Down Expand Up @@ -215,7 +217,7 @@ export class CFGBuilder {
previous = { node: caseConditionNode, branchType: "alternative" }
});

let defaultCase = switchlikeSyntax.namedChildren.find(child => child.type === 'default_case');
const defaultCase = switchlikeSyntax.namedChildren.find(child => child.type === 'default_case');
if (defaultCase !== undefined) {
const defaultBlock = blockHandler.update(this.processStatements(defaultCase.namedChildren));
this.addEdge(previous.node, defaultBlock.entry, previous.branchType);
Expand Down Expand Up @@ -262,24 +264,24 @@ export class CFGBuilder {
});
}
private processGotoStatement(gotoSyntax: Parser.SyntaxNode): BasicBlock {
let name = gotoSyntax.firstNamedChild.text;
let gotoNode = this.addNode('GOTO', name);
const name = gotoSyntax.firstNamedChild.text;
const gotoNode = this.addNode('GOTO', name);
return { entry: gotoNode, exit: null, gotos: [{ node: gotoNode, label: name }] }
}
private processLabeledStatement(labelSyntax: Parser.SyntaxNode): BasicBlock {
let blockHandler = new BlockHandler();
let name = this.getChildFieldText(labelSyntax, "label");
let labelNode = this.addNode("LABEL", name);
const blockHandler = new BlockHandler();
const name = this.getChildFieldText(labelSyntax, "label");
const labelNode = this.addNode("LABEL", name);
console.log("label", labelSyntax.namedChildCount);
const { entry: labeledEntry, exit: labeledExit } = blockHandler.update(this.processBlock(labelSyntax.namedChildren[1]))
if (labeledEntry) this.addEdge(labelNode, labeledEntry)
return blockHandler.update({ entry: labelNode, exit: labeledExit, labels: new Map([[name, labelNode]]) });
}
private processContinueStatement(continueSyntax: Parser.SyntaxNode): BasicBlock {
private processContinueStatement(_continueSyntax: Parser.SyntaxNode): BasicBlock {
const continueNode = this.addNode("CONTINUE", "CONTINUE");
return { entry: continueNode, exit: null, continues: [continueNode] };
}
private processBreakStatement(breakSyntax: Parser.SyntaxNode): BasicBlock {
private processBreakStatement(_breakSyntax: Parser.SyntaxNode): BasicBlock {
const breakNode = this.addNode("BREAK", "BREAK");
return { entry: breakNode, exit: null, breaks: [breakNode] };
}
Expand Down Expand Up @@ -307,7 +309,7 @@ export class CFGBuilder {
}

private processIfStatement(ifNode: Node, mergeNode: string | null = null): BasicBlock {
let blockHandler = new BlockHandler();
const blockHandler = new BlockHandler();
const conditionChild = ifNode.childForFieldName('condition');
const conditionNode = this.addNode(
'CONDITION',
Expand Down
16 changes: 8 additions & 8 deletions src/control-flow/graph-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { subgraph } from "graphology-operators";
import { bfsFromNode } from "graphology-traversal";
import type { CFG } from "./cfg";

export function distanceFromEntry(cfg: CFG): Map<any, number> {
export function distanceFromEntry(cfg: CFG): Map<string, number> {
const { graph, entry } = cfg;
let levels = new Map();
const levels = new Map();

bfsFromNode(graph, entry, (node, attr, depth) => {
levels.set(node, depth);
Expand All @@ -15,14 +15,14 @@ export function distanceFromEntry(cfg: CFG): Map<any, number> {
}

export type AttrMerger = (nodeAttrs: object, intoAttrs: object) => object;
function collapseNode(graph: MultiDirectedGraph, node: any, into: any, mergeAttrs?: AttrMerger) {
function collapseNode(graph: MultiDirectedGraph, node: string, into: string, mergeAttrs?: AttrMerger) {
graph.forEachEdge(node, (edge, attributes, source, target) => {
if (target === into) {
return;
}

const replaceNode = (n: any) => (n === node ? into : n);
let edgeNodes = [replaceNode(source), replaceNode(target)] as const;
const replaceNode = (n: string) => (n === node ? into : n);
const edgeNodes = [replaceNode(source), replaceNode(target)] as const;
graph.addEdge(...edgeNodes, attributes);
})
if (mergeAttrs) {
Expand All @@ -38,9 +38,9 @@ function collapseNode(graph: MultiDirectedGraph, node: any, into: any, mergeAttr
* @param graph The graph to simplify
*/
export function simplifyCFG(cfg: CFG, mergeAttrs?: AttrMerger): CFG {
let graph = cfg.graph.copy();
const graph = cfg.graph.copy();

let toCollapse: string[][] = graph.mapEdges((edge, attrs, source, target) => {
const toCollapse: string[][] = graph.mapEdges((edge, attrs, source, target) => {
if (graph.outDegree(source) === 1 && graph.inDegree(target) === 1) {
return [source, target];
}
Expand Down Expand Up @@ -71,7 +71,7 @@ export function simplifyCFG(cfg: CFG, mergeAttrs?: AttrMerger): CFG {

export function trimFor(cfg: CFG): CFG {
const { graph, entry } = cfg;
let reachable: any[] = [];
const reachable: string[] = [];

bfsFromNode(graph, entry, (node) => { reachable.push(node); });

Expand Down
2 changes: 1 addition & 1 deletion src/control-flow/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { CFG } from "./cfg";
export function graphToDot(cfg: CFG, verbose: boolean = false): string {
const graph = cfg.graph;
let dotContent = `digraph "" {\n node [shape=box];\n edge [headport=n tailport=s]\n bgcolor="transparent"\n`;
let levels = distanceFromEntry(cfg);
const levels = distanceFromEntry(cfg);
graph.forEachNode((node) => {

let label = "";
Expand Down
2 changes: 1 addition & 1 deletion src/vscode/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class OverviewViewProvider implements vscode.WebviewViewProvider {
}


resolveWebviewView(webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext, token: vscode.CancellationToken): Thenable<void> | void {
resolveWebviewView(webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken): Thenable<void> | void {
this._view = webviewView;

webviewView.webview.options = {
Expand Down

0 comments on commit 6fd70a8

Please sign in to comment.