Skip to content

Commit

Permalink
Resolve linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nikeee committed Apr 2, 2024
1 parent 3db39ce commit 931d4df
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 23 deletions.
25 changes: 23 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,34 @@
"rules": {
"recommended": true,
"suspicious": {
"noConstEnum": "off"
"noConstEnum": "off",
"noDebugger": "off"
},
"correctness": {
"noVoidTypeReturn": "off"
}
}
},
"javascript": {
"formatter": {
"arrowParentheses": "asNeeded"
}
}
},
"overrides": [
{
"include": [
"src/scanner.ts"
],
"linter": {
"rules": {
"suspicious": {
"noAssignInExpressions": "off"
},
"style": {
"noParameterAssign": "off"
}
}
}
}
]
}
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function createMapFromTemplate<T>(template: Record<string, T>): Map<strin
// Copies keys/values from template. Note that for..in will not throw if
// template is undefined, and instead will just exit the loop.
for (const key in template) {
if (template.hasOwnProperty(key)) {
if (key in template) {
map.set(key, template[key]);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export class Parser {
}

private nextToken(): SyntaxKind {
return (this.currentToken = this.scanner.scan(true));
this.currentToken = this.scanner.scan(true);
return this.currentToken;
}
private token(): SyntaxKind {
return this.currentToken;
Expand Down
17 changes: 10 additions & 7 deletions src/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ export class DefaultScanner implements Scanner {

switch (nextChar) {
case CharacterCodes.minus: // --
return (this.pos += 2), (this.token = SyntaxKind.UndirectedEdgeOp);
this.pos += 2;
return (this.token = SyntaxKind.UndirectedEdgeOp);
case CharacterCodes.greaterThan: // ->
return (this.pos += 2), (this.token = SyntaxKind.DirectedEdgeOp);
this.pos += 2;
return (this.token = SyntaxKind.DirectedEdgeOp);

case CharacterCodes._0:
case CharacterCodes._1:
Expand All @@ -247,13 +249,14 @@ export class DefaultScanner implements Scanner {
case CharacterCodes.dot:
this.tokenValue = this.scanNumber();
return (this.token = SyntaxKind.NumericIdentifier);
default:
default: {
const chr = this.text.charAt(this.pos + 1);
this.error(
`Unexpected "${chr}". Did you mean to define an edge? Depending on the type of graph you are defining, use "->" or "--".`,
ScanError.ExpectationFailed,
);
break;
}
}
this.pos++;
break;
Expand Down Expand Up @@ -424,10 +427,9 @@ export class DefaultScanner implements Scanner {
if (subTagsLevel === 0) {
result += this.text.substring(start, this.pos);
break;
} else {
--subTagsLevel;
continue;
}
--subTagsLevel;
continue;
}
this.pos++;
}
Expand Down Expand Up @@ -460,7 +462,8 @@ export class DefaultScanner implements Scanner {
result += this.text.substring(start, this.pos);
this.pos++;
break;
} else if (isLineBreak(ch)) {
}
if (isLineBreak(ch)) {
result += this.text.substring(start, this.pos);
this.tokenFlags |= TokenFlags.Unterminated;
this.isUnterminated = true;
Expand Down
4 changes: 2 additions & 2 deletions src/service/codeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export const enum CommandIds {
type CommandHandler = (
doc: DocumentLike,
sourceFile: SourceFile,
cmd: ExecutableCommand,
cmd: ExecutableCommand<unknown[]>,
) => CommandApplication | undefined;

interface CommandHandlers {
Expand All @@ -341,7 +341,7 @@ export function getAvailableCommands() {
export function executeCommand(
doc: DocumentLike,
sourceFile: SourceFile,
cmd: ExecutableCommand,
cmd: ExecutableCommand<unknown[]>,
): CommandApplication | undefined {
const handler = commandHandlers[cmd.command];
return handler === undefined ? undefined : handler(doc, sourceFile, cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function create(
export function execute(
doc: DocumentLike,
_sourceFile: SourceFile,
cmd: ExecutableCommand,
cmd: ExecutableCommand<unknown[]>,
): CommandApplication | undefined {
if (!isChangeAllOtherEdgeOpsAndFixGraphCommand(cmd)) return undefined;

Expand All @@ -69,7 +69,7 @@ export function execute(
}

function isChangeAllOtherEdgeOpsAndFixGraphCommand(
cmd: ExecutableCommand,
cmd: ExecutableCommand<unknown[]>,
): cmd is ChangeAllOtherEdgeOpsAndFixGraphCommand {
return (
cmd.command === CommandIds.ConvertGraphType && !!cmd.arguments && cmd.arguments.length === 4
Expand Down
4 changes: 2 additions & 2 deletions src/service/command/ChangeEdgeOpCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function create(
export function execute(
doc: DocumentLike,
_sourceFile: SourceFile,
cmd: ExecutableCommand,
cmd: ExecutableCommand<unknown[]>,
): CommandApplication | undefined {
if (!isChangeEdgeOpCommand(cmd)) return undefined; // Invalid arguments

Expand All @@ -46,6 +46,6 @@ export function execute(
};
}

function isChangeEdgeOpCommand(cmd: ExecutableCommand): cmd is ChangeEdgeOpCommand {
function isChangeEdgeOpCommand(cmd: ExecutableCommand<unknown[]>): cmd is ChangeEdgeOpCommand {
return cmd.command === CommandIds.ChangeEdgeOp && !!cmd.arguments && cmd.arguments.length === 3;
}
4 changes: 2 additions & 2 deletions src/service/command/ConsolidateDescendantsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function create(statements: EdgeStatement[], below: boolean): Consolidate
export function execute(
doc: DocumentLike,
sourceFile: SourceFile,
cmd: ExecutableCommand,
cmd: ExecutableCommand<unknown[]>,
): CommandApplication | undefined {
if (!isConsolidateDescendantsCommand(cmd)) return undefined; // Invalid arguments

Expand Down Expand Up @@ -118,7 +118,7 @@ export function execute(
}

function isConsolidateDescendantsCommand(
cmd: ExecutableCommand,
cmd: ExecutableCommand<unknown[]>,
): cmd is ConsolidateDescendantsCommand {
return (
cmd.command === CommandIds.ConsolidateDescendants &&
Expand Down
6 changes: 4 additions & 2 deletions src/service/command/RemoveSemicolons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function create(): RemoveSemicolonsCommand {
export function execute(
doc: DocumentLike,
sourceFile: SourceFile,
cmd: ExecutableCommand,
cmd: ExecutableCommand<unknown[]>,
): CommandApplication | undefined {
if (!isRemoveSemicolonsCommand(cmd)) return undefined;

Expand All @@ -45,7 +45,9 @@ export function execute(
};
}

function isRemoveSemicolonsCommand(cmd: ExecutableCommand): cmd is RemoveSemicolonsCommand {
function isRemoveSemicolonsCommand(
cmd: ExecutableCommand<unknown[]>,
): cmd is RemoveSemicolonsCommand {
return (
cmd.command === CommandIds.RemoveSemicolons &&
(!cmd.arguments || cmd.arguments.length === 0 || cmd.arguments.every(e => e === undefined))
Expand Down
4 changes: 2 additions & 2 deletions src/service/command/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export interface Offset {
end: number;
}

export type ExecutableCommand = {
export type ExecutableCommand<TArgs> = {
command: CommandIds;
arguments?: any[];
arguments?: TArgs;
};

export type EdgeOpStr = "--" | "->";
Expand Down

0 comments on commit 931d4df

Please sign in to comment.