Skip to content

Commit

Permalink
Merge pull request #24 from riya461/lint
Browse files Browse the repository at this point in the history
Added a standard eslint setup
  • Loading branch information
blenderskool authored Aug 28, 2024
2 parents c541405 + 23126eb commit f7830d3
Show file tree
Hide file tree
Showing 13 changed files with 2,637 additions and 2,793 deletions.
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true
}

9 changes: 9 additions & 0 deletions compiler/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-check

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

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
);
8 changes: 5 additions & 3 deletions compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@
"scripts": {
"dev": "tsc --watch",
"build": "tsc",
"playground": "tsx src/playground.ts"
"playground": "tsx src/playground.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write ."
},
"dependencies": {
"chevrotain": "^10.1.2",
"just-clone": "^3.2.1"
},
"devDependencies": {
"@types/node": "^14.14.21",
"tslint": "^6.1.3",
"tsx": "^4.15.7",
"typescript": "^4.1.3"
"typescript": "^4.9.5"
}
}
2 changes: 1 addition & 1 deletion compiler/src/regular-grammar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class RegularGrammar extends CompilerClass {
toRegEx() {
const graph: FAGraph = this.toEpsilonFreeFA().optimizeFA().result;

const sigma: Set<String> = new Set();
const sigma: Set<string> = new Set();
const dfs = (root: ParseTree) => {
if (!root) return;
if (!root.body) return;
Expand Down
18 changes: 9 additions & 9 deletions compiler/src/turing-machine/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ export class GraphHandler {
private unreachabilityCheck() {
if (this.errors.length > 0) return this;

let visited = new Map<string, boolean>();
const visited = new Map<string, boolean>();
this.vertices.forEach((state) => {
visited.set(state, false);
});

let queue: string[] = ["S"];
const queue: string[] = ["S"];
visited.set("S", true);
while (queue.length !== 0) {
let remEle = queue.shift();
const remEle = queue.shift();

if (this.edgeList.has(remEle!)) {
this.edgeList.get(remEle!)?.forEach((stateTrans) => {
Expand All @@ -86,7 +86,7 @@ export class GraphHandler {
}

let msg = "";
for (let state of visited) {
for (const state of visited) {
if (state[1] === false) {
msg += state[0] + ", ";
this.edgeList.delete(state[0]);
Expand Down Expand Up @@ -116,8 +116,8 @@ export class GraphHandler {
return this;
}

let finalStates = new Set<string>();
for (let state of this.edgeList.keys()) {
const finalStates = new Set<string>();
for (const state of this.edgeList.keys()) {
if (state[0] === "*") {
this.errors.push({
type: "Error",
Expand All @@ -126,7 +126,7 @@ export class GraphHandler {
return this;
}

for (let stateTrans of this.edgeList.get(state)!) {
for (const stateTrans of this.edgeList.get(state)!) {
if (stateTrans.nextState[0] === "*") {
finalStates.add(stateTrans.nextState);
if (finalStates.size > 1) {
Expand All @@ -153,8 +153,8 @@ export class GraphHandler {
private sameReadSymbolCheck() {
if (this.errors.length > 0) return this;

for (let edge of this.edgeList) {
let readSymbols = new Set();
for (const edge of this.edgeList) {
const readSymbols = new Set();
edge[1].forEach((stateTrans) => {
if (readSymbols.has(stateTrans.readSymbol)) {
this.errors.push({
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/turing-machine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class StateTransitionGrammar extends CompilerClass {
const tokenStream = new StateTransitionLexer(this.program).tokenizer();

if (tokenStream.errors.length > 0) {
for (let error of tokenStream.errors) {
let message = `${error.message} at ${error.line}:${error.column}`;
for (const error of tokenStream.errors) {
const message = `${error.message} at ${error.line}:${error.column}`;

this.errors.push({
type: 'Error',
Expand All @@ -37,7 +37,7 @@ export class StateTransitionGrammar extends CompilerClass {

const parserObj = new StateTransitionParser();
parserObj.input = lexRes.tokens;
let cstOutput = parserObj.grammarStart();
const cstOutput = parserObj.grammarStart();

if (parserObj.errors.length > 0) {
parserObj.errors.forEach((err) => {
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/turing-machine/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class TestInput {
for (let index = 0; index < 100 ; index++) {
this.tape.push("#")
}
for (var i of str) {
for (const i of str) {
this.tape.push(i);
}
for (let index = 0; index < 100; index++) {
Expand All @@ -37,7 +37,7 @@ export class TestInput {
let index = 100;
this.initTape();
this.toTape(this.input);
let value = {
const value = {
moveDir: 100,
string: this.tape,
accepted: false,
Expand All @@ -50,7 +50,7 @@ export class TestInput {
this.vertices.get(s)
) {
let statecount = 0;
for (var j of this.vertices.get(s)) {
for (const j of this.vertices.get(s)) {
if (this.tape[index] == j.readSymbol) {
this.tape[index] = j.writeSymbol;
// value.moveDir = this.tMove(j.transition);
Expand Down Expand Up @@ -89,7 +89,7 @@ export class TestInput {
this.vertices.get(s)
) {
let statecount = 0;
for (var j of this.vertices.get(s)) {
for (const j of this.vertices.get(s)) {
if (this.tape[index] == j.readSymbol) {
this.tape[index] = j.writeSymbol;
index = index + this.tMove(j.transition);
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/turing-machine/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class StateTransitionLexer {

tokenizer() {
const chevLexer = new Lexer(TokenList);
let tokenRes = chevLexer.tokenize(this.program);
const tokenRes = chevLexer.tokenize(this.program);

for (let i = tokenRes.tokens.length - 1; i > 0; i--) {
if (
Expand Down
9 changes: 9 additions & 0 deletions editor/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-check

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

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
);
7 changes: 5 additions & 2 deletions editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"scripts": {
"dev": "vite --port 3000",
"build": "vite build",
"serve": "vite preview"
"serve": "vite preview",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write ."
},
"dependencies": {
"@headlessui/vue": "^1.6.7",
Expand All @@ -33,7 +36,7 @@
"@vuedx/typecheck": "^0.6.0",
"@vuedx/typescript-plugin-vue": "^0.6.0",
"rollup-plugin-visualizer": "^5.5.2",
"typescript": "^4.1.3",
"typescript": "^4.9.5",
"vite": "^3.2.5",
"vite-plugin-windicss": "^1.8.10",
"windicss": "^3.1.7"
Expand Down
6 changes: 3 additions & 3 deletions editor/src/config/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ const vykrnConsole = new JitterConsole({
}

if (playground.type === 'TM') {
let tstr = (args.string as string).trim();
const tstr = (args.string as string).trim();
const str = tstr + '#';
let genobj = new TestInput(
const genobj = new TestInput(
str,
playground.compiled.parseTree as Map<
string,
TuringMachineStateTransition[]
>
);
let strcheck = genobj.consoleTestString();
const strcheck = genobj.consoleTestString();
if (strcheck)
pushToStream(playground, 'Success', 'string was accepted');
else pushToStream(playground, 'Warning', 'string was rejected');
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@
"website:build": "cd website && pnpm run build",
"dev": "pnpm run editor:dev & pnpm run website:dev",
"build": "./build.sh"
},
"devDependencies": {
"@eslint/js": "^9.8.0",
"@types/eslint__js": "^8.42.3",
"eslint": "^9.5.0",
"prettier": "^3.3.3",
"typescript": "^4.9.5",
"typescript-eslint": "8.0.0-alpha.30"
}
}
Loading

0 comments on commit f7830d3

Please sign in to comment.