Skip to content

Commit

Permalink
Add biome, fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
DvvCz committed Mar 22, 2024
1 parent 372d2bd commit 0cc44bf
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 37 deletions.
23 changes: 23 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.2/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"indentStyle": "tab",
"indentWidth": 4
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "off",
"noShadowRestrictedNames": "off"
},
"complexity": {
"useLiteralKeys": "off"
}
}
}
}
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
"test": "vitest",
"coverage": "vitest run --coverage"
},
"workspaces": [
"packages/*"
],
"workspaces": ["packages/*"],
"devDependencies": {
"@biomejs/biome": "1.6.2",
"@vitest/coverage-v8": "^0.34.2",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"vitest": "^0.34.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/ramattra-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Command } from "commander";
import { assemble, parse } from "@ramattra/ramattra-core";
import * as fs from "node:fs/promises";
import { Error } from "@ramattra/ramattra-core/src/compiler/parser";
import type { Error } from "@ramattra/ramattra-core/src/compiler/parser";

const program = new Command();

Expand Down
2 changes: 1 addition & 1 deletion packages/ramattra-core/src/compiler/std.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const CONSTANTS: Record<string, { ow: string, type: Type }> = {
"ROUND_DOWN": { ow: "Down", type: native("rounding") },
};

export const FUNCTIONS: Record<string, { ow: string, args: { type: Type, default?: string }[], ret?: Type } | undefined> = {
export const FUNCTIONS: Record<string, { ow: string, args: { type: Type, default?: string }[], ret?: Type }> = {
"disableGameModeHUD": { ow: "Disable Game Mode HUD", args: [{ type: native("player") }] },

"createHUDText": {
Expand Down
26 changes: 15 additions & 11 deletions packages/ramattra-language-server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FUNCTIONS, analyze, type Error, CONSTANTS, EVENTS, reprType } from "@ramattra/ramattra-core";
import { dedent } from "@ramattra/ramattra-util";
import { CompletionItemKind, Connection, Diagnostic, DiagnosticSeverity, TextDocuments, TextDocumentSyncKind } from "vscode-languageserver";
import { CompletionItemKind, type Connection, type Diagnostic, DiagnosticSeverity, TextDocuments, TextDocumentSyncKind } from "vscode-languageserver";
import { TextDocument } from "vscode-languageserver-textdocument";

export const onInit = (connection: Connection) => {
connection.onInitialize(_params => {
connection.console.log(`[Server] Started and initialize received`);
connection.console.log("[Server] Started and initialize received");

return {
capabilities: {
Expand Down Expand Up @@ -83,7 +83,7 @@ export const onInit = (connection: Connection) => {
const word = text.slice(start, end);

if (FUNCTIONS[word]) {
const fn = FUNCTIONS[word]!;
const fn = FUNCTIONS[word];

return {
contents: {
Expand All @@ -96,7 +96,9 @@ export const onInit = (connection: Connection) => {
`
},
}
} else if (CONSTANTS[word]) {
}

if (CONSTANTS[word]) {
const constant = CONSTANTS[word];
return {
contents: {
Expand All @@ -108,7 +110,9 @@ export const onInit = (connection: Connection) => {
`
},
}
} else if (EVENTS[word]) {
}

if (EVENTS[word]) {
const event = EVENTS[word];
return {
contents: {
Expand Down Expand Up @@ -159,8 +163,8 @@ export const onInit = (connection: Connection) => {

connection.onCompletionResolve(item => {
const data = item.data as [CompletionItemKind, string];
if (data[0] == CompletionItemKind.Function) {
const fn = FUNCTIONS[data[1]]!;
if (data[0] === CompletionItemKind.Function) {
const fn = FUNCTIONS[data[1]];
item.detail = `${data[1]}(${fn?.args.map(x => x.default ? `${reprType(x.type)} = ${x.default}` : reprType(x.type)).join(", ")})`
item.documentation = {
kind: "markdown",
Expand All @@ -169,17 +173,17 @@ export const onInit = (connection: Connection) => {
[workshop.codes](${WORKSHOP_CODES_HREF}${fn.ow.replaceAll(" ", "+").toLowerCase()})
`
}
} else if (data[0] == CompletionItemKind.Constant) {
const constant = CONSTANTS[data[1]]!;
} else if (data[0] === CompletionItemKind.Constant) {
const constant = CONSTANTS[data[1]];
item.detail = `${data[1]}: ${reprType(constant.type)}`;
item.documentation = {
kind: "markdown",
value: dedent`
**Overwatch Value**: \`${constant.ow}\`
`
}
} else if (data[0] == CompletionItemKind.Event) {
const event = EVENTS[data[1]]!;
} else if (data[0] === CompletionItemKind.Event) {
const event = EVENTS[data[1]];
item.detail = `event ${data[1]}(${event.args.map(a => reprType(a.type)).join(", ")})`
item.documentation = {
kind: "markdown",
Expand Down
16 changes: 8 additions & 8 deletions packages/ramattra-playground/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render } from "preact";
import { useEffect, useState } from "preact/hooks";

import { Error, assemble } from "@ramattra/ramattra-core";
import { type Error, assemble } from "@ramattra/ramattra-core";

const urlParams = new URLSearchParams(window.location.search);
const codeParam = urlParams.get("code");
Expand Down Expand Up @@ -67,9 +67,9 @@ const App = () => {
return <>
<div class="top">
<div class="logo">
<button aria-label="GitHub Logo">
<button type="button" aria-label="GitHub Logo">
<a aria-label="GitHub Repository" href="https://github.com/DvvCz/Ramattra">
<i class="fa-brands fa-github"></i>
<i class="fa-brands fa-github" />
</a>
</button>

Expand All @@ -79,9 +79,9 @@ const App = () => {
</div>

<div class="nav">
<button>
<button type="button">
<a href="https://github.com/DvvCz/Ramattra/wiki">
<i class="fas fa-book"></i>
<i class="fas fa-book" />
Documentation
</a>
</button>
Expand All @@ -91,8 +91,8 @@ const App = () => {
<div class="main">
<div class="editor">
<div class="toolbar">
<button onClick={compile}>Compile</button>
<button onClick={share}>Share</button>
<button type="button" onClick={compile}>Compile</button>
<button type="button" onClick={share}>Share</button>
</div>

<Editor
Expand All @@ -115,7 +115,7 @@ const App = () => {
{outCode}
</textarea>

<button onClick={_ => navigator.clipboard.writeText(outCode)}>
<button type="button" onClick={_ => navigator.clipboard.writeText(outCode)}>
Copy to Clipboard
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/ramattra-playground/src/monarch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
operators: ["=", ">", "<", "!", ":", "==", "<=", ">=", "!=", "&&", "||", "+", "-", "*", "/", "%", "+=", "-=", "*=", "/="],

symbols: /[=><!:&|+\-*\/\^%]+/,
escapes: /\\(?:[abfnrtv\\""])/, // Strings don"t actually support escapes for now but here's this.
escapes: /\\(?:[abfnrtv\\""])/, // Strings don't actually support escapes for now but here's this.

// The main tokenizer for our languages
tokenizer: {
Expand Down
1 change: 0 additions & 1 deletion packages/ramattra-playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"moduleResolution": "Node",
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/ramattra-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function dedent(template: TemplateStringsArray, ...subs: any[]): string {
let min = null;
for (const line of lines) {
let ptr = 0;
while (line.charAt(ptr) == "\t") ptr++;
while (line.charAt(ptr) === "\t") ptr++;

if (min) {
if (ptr < min) {
Expand All @@ -15,7 +15,7 @@ export function dedent(template: TemplateStringsArray, ...subs: any[]): string {
min = ptr;
}

if (min == 0) break;
if (min === 0) break;
}

if (min) {
Expand All @@ -24,7 +24,7 @@ export function dedent(template: TemplateStringsArray, ...subs: any[]): string {
}

return lines.join("\n");
} else {
return middle;
}

return middle;
}
8 changes: 3 additions & 5 deletions packages/ramattra-vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as path from "path";
import { ExtensionContext } from "vscode";
import * as path from "node:path";
import type { ExtensionContext } from "vscode";

import {
LanguageClient,
} from "vscode-languageclient/node";
import { LanguageClient } from "vscode-languageclient/node";

let client: LanguageClient;

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "CommonJS",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ESNext",
"composite": true,
Expand Down

0 comments on commit 0cc44bf

Please sign in to comment.