forked from kofal.net/zmk
chore: Add typescript support to eslint, fix errors (#2923)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { ReactNode, CSSProperties } from "react";
|
||||
import { ReactNode, CSSProperties } from "react";
|
||||
import clsx from "clsx";
|
||||
|
||||
interface ColumnsProps {
|
||||
|
||||
@@ -18,11 +18,11 @@ function itemHasMultiple(item: HardwareMetadata) {
|
||||
|
||||
function itemIds(item: HardwareMetadata) {
|
||||
if (item.type == "board" || item.type == "shield") {
|
||||
let nodes = (item.siblings ?? [item.id])
|
||||
.map<ElementOrString>((id) => <code key={id}>{id}</code>)
|
||||
.reduce(
|
||||
const nodes = (item.siblings ?? [item.id])
|
||||
.map((id) => <code key={id}>{id}</code>)
|
||||
.reduce<ElementOrString[]>(
|
||||
(prev, curr, index) => [...prev, index > 0 ? ", " : "", curr],
|
||||
[] as ElementOrString[]
|
||||
[]
|
||||
);
|
||||
return <span key={item.id}>{nodes}</span>;
|
||||
} else {
|
||||
@@ -81,7 +81,7 @@ function mapInterconnect({
|
||||
}
|
||||
|
||||
function HardwareList({ items }: HardwareListProps) {
|
||||
let grouped = groupedMetadata(items);
|
||||
const grouped = groupedMetadata(items);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -21,7 +21,7 @@ function groupedBoard(agg: GroupedMetadata, board: Board) {
|
||||
agg.onboard.push(board);
|
||||
} else if (board.exposes) {
|
||||
board.exposes.forEach((element) => {
|
||||
let ic = agg.interconnects[element] ?? {
|
||||
const ic = agg.interconnects[element] ?? {
|
||||
boards: [],
|
||||
shields: [],
|
||||
};
|
||||
@@ -37,12 +37,12 @@ function groupedBoard(agg: GroupedMetadata, board: Board) {
|
||||
|
||||
function groupedShield(agg: GroupedMetadata, shield: Shield) {
|
||||
shield.requires.forEach((id) => {
|
||||
let ic = agg.interconnects[id] ?? { boards: [], shields: [] };
|
||||
const ic = agg.interconnects[id] ?? { boards: [], shields: [] };
|
||||
ic.shields.push(shield);
|
||||
agg.interconnects[id] = ic;
|
||||
});
|
||||
shield.exposes?.forEach((id) => {
|
||||
let ic = agg.interconnects[id] ?? { boards: [], shields: [] };
|
||||
const ic = agg.interconnects[id] ?? { boards: [], shields: [] };
|
||||
ic.shields.push(shield);
|
||||
agg.interconnects[id] = ic;
|
||||
});
|
||||
@@ -50,7 +50,7 @@ function groupedShield(agg: GroupedMetadata, shield: Shield) {
|
||||
}
|
||||
|
||||
function groupedInterconnect(agg: GroupedMetadata, item: Interconnect) {
|
||||
let ic = agg.interconnects[item.id] ?? { boards: [], shields: [] };
|
||||
const ic = agg.interconnects[item.id] ?? { boards: [], shields: [] };
|
||||
ic.interconnect = item;
|
||||
agg.interconnects[item.id] = ic;
|
||||
|
||||
|
||||
@@ -2,16 +2,16 @@ import Tabs from "@theme/Tabs";
|
||||
import TabItem from "@theme/TabItem";
|
||||
|
||||
import { HardwareMetadata, Interconnect } from "../hardware-metadata";
|
||||
import { groupedMetadata, InterconnectDetails } from "./hardware-utils";
|
||||
import { groupedMetadata } from "./hardware-utils";
|
||||
|
||||
interface InterconnectTabsProps {
|
||||
items: HardwareMetadata[];
|
||||
gpio: Boolean;
|
||||
gpio: boolean;
|
||||
}
|
||||
|
||||
function mapInterconnect(interconnect: Interconnect, gpio: Boolean) {
|
||||
let content = require(`@site/src/data/interconnects/${interconnect.id}/design_guideline.md`);
|
||||
let imageUrl = require(`@site/docs/assets/interconnects/${interconnect.id}/pinout.png`);
|
||||
function mapInterconnect(interconnect: Interconnect, gpio: boolean) {
|
||||
const content = require(`@site/src/data/interconnects/${interconnect.id}/design_guideline.md`);
|
||||
const imageUrl = require(`@site/docs/assets/interconnects/${interconnect.id}/pinout.png`);
|
||||
return (
|
||||
<TabItem value={interconnect.id} key={interconnect.id}>
|
||||
<img src={imageUrl.default} />
|
||||
@@ -53,7 +53,7 @@ function mapInterconnectValue(interconnect: Interconnect) {
|
||||
}
|
||||
|
||||
function InterconnectTabs({ items, gpio }: InterconnectTabsProps) {
|
||||
let grouped = Object.values(groupedMetadata(items).interconnects)
|
||||
const grouped = Object.values(groupedMetadata(items).interconnects)
|
||||
.map((i) => i?.interconnect as Interconnect)
|
||||
.filter((i) => i?.design_guideline)
|
||||
.sort((a, b) => a.id.localeCompare(b.id));
|
||||
|
||||
@@ -22,9 +22,9 @@ const METADATA_GLOB = path.posix.join(BASE_DIR, "app/boards/**/*.zmk.yml");
|
||||
* @param {string} file
|
||||
*/
|
||||
async function readMetadata(file) {
|
||||
/** @type HardwareMetadata[] */
|
||||
// @ts-ignore
|
||||
const documents = yaml.loadAll(await fs.readFile(file, "utf-8"));
|
||||
const documents = /** @type HardwareMetadata[] */ (
|
||||
yaml.loadAll(await fs.readFile(file, "utf-8"))
|
||||
);
|
||||
|
||||
return documents.map(
|
||||
(metadata) =>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { SyntaxNode, Tree } from "web-tree-sitter";
|
||||
import type { Tree } from "web-tree-sitter";
|
||||
import { Devicetree, findCapture } from "./parser";
|
||||
import { getUpgradeEdits, MatchFunc, ReplaceFunc, TextEdit } from "./textedit";
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ function findBehaviorNodes(paramNode: SyntaxNode) {
|
||||
}
|
||||
|
||||
// Walk forward from the behavior to collect all its parameters.
|
||||
let nodes = [behavior];
|
||||
const nodes = [behavior];
|
||||
let param = behavior.nextNamedSibling;
|
||||
while (param && param.type !== "reference") {
|
||||
nodes.push(param);
|
||||
|
||||
@@ -133,7 +133,9 @@ export function findDevicetreeProperty(
|
||||
`(property name: (identifier) @name (#eq? @name "${name}")) @prop`
|
||||
);
|
||||
const matches = query.matches(node);
|
||||
const props = matches.map(({ captures }) => findCapture("prop", captures)!);
|
||||
const props = matches
|
||||
.map(({ captures }) => findCapture("prop", captures))
|
||||
.filter((node) => node !== null);
|
||||
|
||||
if (options?.recursive) {
|
||||
return props;
|
||||
|
||||
@@ -94,7 +94,7 @@ export function applyEdits(text: string, edits: TextEdit[]) {
|
||||
const chunks: TextChunk[] = [];
|
||||
let currentIndex = 0;
|
||||
|
||||
for (let edit of edits) {
|
||||
for (const edit of edits) {
|
||||
if (edit.startIndex < currentIndex) {
|
||||
console.warn("discarding overlapping edit", edit);
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user