Added support for valueFormat directive - linting

This commit is contained in:
Knut Sveidqvist
2025-05-12 17:47:00 +02:00
parent 3e07a5acff
commit 66ce617bea
2 changed files with 15 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ import {
setAccTitle,
setDiagramTitle,
} from '../common/commonDb.js';
import type { TreemapDB, TreemapData, TreemapNode } from './types.js';
import type { TreemapDB, TreemapData, TreemapDiagramConfig, TreemapNode } from './types.js';
const defaultTreemapData: TreemapData = {
nodes: [],
@@ -22,11 +22,15 @@ const defaultTreemapData: TreemapData = {
let outerNodes: TreemapNode[] = [];
let data: TreemapData = structuredClone(defaultTreemapData);
const getConfig = () => {
const getConfig = (): Required<TreemapDiagramConfig> => {
// Use type assertion with unknown as intermediate step
const defaultConfig = DEFAULT_CONFIG as unknown as { treemap: Required<TreemapDiagramConfig> };
const userConfig = commonGetConfig() as unknown as { treemap?: Partial<TreemapDiagramConfig> };
return cleanAndMerge({
...DEFAULT_CONFIG.treemap,
...commonGetConfig().treemap,
});
...defaultConfig.treemap,
...(userConfig.treemap ?? {}),
}) as Required<TreemapDiagramConfig>;
};
const getNodes = (): TreemapNode[] => data.nodes;

View File

@@ -11,7 +11,9 @@ import { buildHierarchy } from './utils.js';
* @param ast - The Treemap AST
*/
const populate = (ast: TreemapAst) => {
populateCommonDb(ast, db);
// We need to bypass the type checking for populateCommonDb
// eslint-disable-next-line @typescript-eslint/no-explicit-any
populateCommonDb(ast as any, db);
const items: {
level: number;
@@ -77,7 +79,7 @@ const populate = (ast: TreemapAst) => {
* @param item - The treemap item
* @returns The name of the item
*/
const getItemName = (item: any): string => {
const getItemName = (item: { name?: string | number }): string => {
return item.name ? String(item.name) : '';
};
@@ -85,7 +87,8 @@ export const parser: ParserDefinition = {
parse: async (text: string): Promise<void> => {
try {
// Use a generic parse that accepts any diagram type
const parseFunc = parse as (diagramType: string, text: string) => Promise<any>;
const parseFunc = parse as (diagramType: string, text: string) => Promise<TreemapAst>;
const ast = await parseFunc('treemap', text);
log.debug('Treemap AST:', ast);
populate(ast);