Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • pub/frama-c
  • proidiot/frama-c
  • lthls/frama-c
3 results
Show changes
Showing
with 118 additions and 65 deletions
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/no-explicit-any */
// --------------------------------------------------------------------------
// --- Comparison Utilities
// --------------------------------------------------------------------------
......@@ -67,7 +69,7 @@ export function isBigNum(x: any): x is BigNum {
}
/** @internal */
function primitive(x: any, y: any) {
function primitive(x: any, y: any): number {
if (x < y) return -1;
if (x > y) return 1;
return 0;
......@@ -96,7 +98,7 @@ export const bignum: Order<BigNum> = primitive;
/**
Primitive comparison for number (NaN included).
*/
export function number(x: number, y: number) {
export function number(x: number, y: number): number {
const nx = Number.isNaN(x);
const ny = Number.isNaN(y);
if (nx && ny) return 0;
......@@ -111,7 +113,7 @@ export function number(x: number, y: number) {
Alphabetic comparison for strings.
Handles case differently than `byString` comparison.
*/
export function alpha(x: string, y: string) {
export function alpha(x: string, y: string): number {
const cmp = primitive(x.toLowerCase(), y.toLowerCase());
return cmp !== 0 ? cmp : primitive(x, y);
}
......
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/no-explicit-any, no-console */
// --------------------------------------------------------------------------
// --- JSON Utilities
// --------------------------------------------------------------------------
......@@ -32,8 +34,6 @@
import { DEVEL } from 'dome/system';
/* eslint-disable @typescript-eslint/naming-convention, no-shadow */
export type json =
undefined | null | boolean | number | string |
json[] | { [key: string]: json };
......@@ -62,14 +62,14 @@ export function parse(text: string, noError = false): json {
/**
Export JSON (or any data) as a compact string.
*/
export function stringify(js: any) {
export function stringify(js: any): string {
return JSON.stringify(js, undefined, 0);
}
/**
Export JSON (or any data) as a string with indentation.
*/
export function pretty(js: any) {
export function pretty(js: any): string {
return JSON.stringify(js, undefined, 2);
}
......@@ -104,8 +104,9 @@ export function identity<A>(v: A): A { return v; }
// --- Primitives
// --------------------------------------------------------------------------
/** Always returns `undefined` on any input. */
export const jNull: Safe<undefined> = () => undefined;
/** 'null' or 'undefined'. */
export const jNull: Loose<null> = (js: json) =>
js === null ? null : undefined;
/** Identity. */
export const jAny: Safe<json> = (js: json) => js;
......@@ -453,6 +454,7 @@ export function eObject<A>(fp: EProps<A>): Encoder<A> {
}
// Intentionnaly internal and only declared
// eslint-disable-next-line @typescript-eslint/no-unused-vars
declare const tag: unique symbol;
/** Phantom type. */
......
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// --------------------------------------------------------------------------
// --- States
// --------------------------------------------------------------------------
......@@ -311,10 +313,10 @@ export function setWindowSettings(
Local window settings are stored in the `.<appName>` file of the working
directory, or in the closest one in parent directories, if any.
*/
export function useWindowSettings<A extends JSON.json>(
export function useWindowSettings<A>(
key: string | undefined,
decoder: JSON.Loose<A>,
defaultValue: A,
decoder: JSON.Loose<A & JSON.json>,
defaultValue: A & JSON.json,
) {
return useSettings({
decoder,
......@@ -395,12 +397,12 @@ export function setLocalStorage(
if (key) LocalStorageDriver.save(key, value);
}
export function useLocalStorage<A extends JSON.json>(
export function useLocalStorage<A>(
key: string | undefined,
decoder: JSON.Loose<A>,
defaultValue: A,
decoder: JSON.Loose<A & JSON.json>,
defaultValue: A & JSON.json,
) {
return useSettings({
return useSettings<A & JSON.json>({
decoder,
encoder: JSON.identity,
defaultValue,
......
......@@ -33,6 +33,9 @@
import React from 'react';
import Emitter from 'events';
import isEqual from 'react-fast-compare';
import { Debug } from 'dome';
const D = new Debug('State');
// --------------------------------------------------------------------------
// --- State utilities
......@@ -72,7 +75,7 @@ export function debug<A>(msg: string, st: State<A>): State<A> {
const [value, setValue] = st;
return [value, (v) => {
setValue(v);
console.log(msg, v); // eslint-disable-line no-console
D.log(msg, v);
}];
}
......@@ -102,10 +105,10 @@ export class GlobalState<A> {
}
/** Current state value. */
getValue() { return this.value; }
getValue(): A { return this.value; }
/** Notify callbacks on change, using _deep_ structural comparison. */
setValue(value: A) {
setValue(value: A): void {
if (!isEqual(value, this.value)) {
this.value = value;
this.emitter.emit(UPDATE, value);
......@@ -113,12 +116,12 @@ export class GlobalState<A> {
}
/** Callback Emitter. */
on(callback: (value: A) => void) {
on(callback: (value: A) => void): void {
this.emitter.on(UPDATE, callback);
}
/** Callback Emitter. */
off(callback: (value: A) => void) {
off(callback: (value: A) => void): void {
this.emitter.off(UPDATE, callback);
}
......
......@@ -44,7 +44,7 @@ const defaultItems: DialogButton<boolean>[] = [
{ value: true, label: 'Ok' },
];
const valueLabel = (v: any) => {
const valueLabel = (v: unknown): string => {
switch (v) {
case undefined: return 'Cancel';
case true: return 'Ok';
......@@ -53,15 +53,15 @@ const valueLabel = (v: any) => {
}
};
const itemLabel = ({ value, label }: DialogButton<any>) => (
const itemLabel = ({ value, label }: DialogButton<unknown>): string => (
(label || valueLabel(value))
);
const isDefault = ({ value, label }: DialogButton<any>) => (
const isDefault = ({ value, label }: DialogButton<unknown>): boolean => (
(value === true || label === 'Ok' || label === 'Yes')
);
const isCancel = ({ value, label }: DialogButton<any>) => (
const isCancel = ({ value, label }: DialogButton<unknown>): boolean => (
(!value || label === 'Cancel' || label === 'No')
);
......@@ -142,7 +142,8 @@ export async function showMessageBox<A>(
// --------------------------------------------------------------------------
const defaultPath =
(path: string) => (filepath.extname(path) ? filepath.dirname(path) : path);
(path: string): string =>
(filepath.extname(path) ? filepath.dirname(path) : path);
export interface FileFilter {
/** Filter name. */
......
......@@ -20,6 +20,9 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
Dome Application (Renderer Process)
......@@ -47,6 +50,7 @@ import SYS, * as System from 'dome/system';
import * as Json from 'dome/data/json';
import * as Settings from 'dome/data/settings';
import './style.css';
import { State } from './data/states';
// --------------------------------------------------------------------------
// --- Context
......@@ -413,6 +417,7 @@ export interface MenuItemProps {
*/
export function addMenuItem(props: MenuItemProps) {
if (!props.id && props.type !== 'separator') {
// eslint-disable-next-line no-console
console.error('[Dome] Missing menu-item identifier', props);
return;
}
......@@ -708,7 +713,7 @@ export function useFlipSettings(
export function useNumberSettings(
key: string | undefined,
defaultValue = 0,
) {
): State<number> {
return Settings.useWindowSettings(
key, Json.jNumber, defaultValue,
);
......
......@@ -30,9 +30,12 @@
*/
import React from 'react';
import { Debug } from 'dome';
import { Label } from 'dome/controls/labels';
import { Button } from 'dome/controls/buttons';
const D = new Debug('Dome');
// --------------------------------------------------------------------------
// --- Error Boundaries
// --------------------------------------------------------------------------
......@@ -42,7 +45,7 @@ import { Button } from 'dome/controls/buttons';
@param reload - callback for re-rendering the faulty component
*/
export interface ErrorRenderer {
(error: any, info: any, reload: () => void): JSX.Element;
(error: unknown, info: unknown, reload: () => void): JSX.Element;
}
export interface CatchProps {
......@@ -53,8 +56,8 @@ export interface CatchProps {
}
interface CatchState {
error?: any;
info?: any;
error?: unknown;
info?: unknown;
}
/**
......@@ -69,20 +72,20 @@ export class Catch extends React.Component<CatchProps, CatchState, unknown> {
this.reload = this.reload.bind(this);
}
componentDidCatch(error: any, info: any) {
componentDidCatch(error: unknown, info: unknown): void {
this.setState({ error, info });
}
logerr() {
logerr(): void {
const { error, info } = this.state;
console.error('[dome] Catched error:', error, info);
D.error('catched error:', error, info);
}
reload() {
reload(): void {
this.setState({ error: undefined, info: undefined });
}
render() {
render(): JSX.Element {
const { error, info } = this.state;
if (error) {
const { onError, label = 'Error' } = this.props;
......@@ -93,7 +96,7 @@ export class Catch extends React.Component<CatchProps, CatchState, unknown> {
<Button
icon="WARNING"
kind="warning"
title={error}
title={typeof(error) === 'string' ? error : undefined}
onClick={this.logerr}
/>
<Button icon="RELOAD" onClick={this.reload} />
......@@ -101,7 +104,7 @@ export class Catch extends React.Component<CatchProps, CatchState, unknown> {
</div>
);
}
return this.props.children || null;
return (<>{this.props.children}</>);
}
}
......
......@@ -50,7 +50,7 @@ export interface SideBarProps {
/**
Container for sidebar items.
*/
export function SideBar(props: SideBarProps) {
export function SideBar(props: SideBarProps): JSX.Element {
const className = classes(
'dome-xSideBar',
'dome-color-frame',
......@@ -91,7 +91,12 @@ const makeBadge = (elt: Badges): React.ReactNode => {
// --- SideBar Section Hide/Show Button
// --------------------------------------------------------------------------
const HideShow = (props: { onClick: () => void; visible: boolean }) => (
interface HideShowProps {
onClick: () => void;
visible: boolean;
}
const HideShow = (props: HideShowProps): JSX.Element => (
<label
className="dome-xSideBarSection-hideshow dome-text-label"
onClick={props.onClick}
......@@ -137,7 +142,7 @@ export interface SectionProps {
Sections with no items are not displayed.
*/
export function Section(props: SectionProps) {
export function Section(props: SectionProps): JSX.Element | null {
const [state, flipState] = useFlipSettings(
props.settings,
......@@ -202,7 +207,7 @@ export interface ItemProps {
}
/** Sidebar Items. */
export function Item(props: ItemProps) {
export function Item(props: ItemProps): JSX.Element {
const { selected = false, disabled = false, enabled = true } = props;
const isDisabled = disabled || !enabled;
const ref = React.useRef<HTMLDivElement>(null);
......
......@@ -43,7 +43,7 @@ export interface TabsBarProps {
}
/** Container for Tabs. */
export function TabsBar(props: TabsBarProps) {
export function TabsBar(props: TabsBarProps): JSX.Element {
return (
<div className="dome-xTabsBar dome-color-frame">
{props.children}
......@@ -73,7 +73,7 @@ export interface TabProps<A> {
}
/** Tab Selector. */
export function Tab<A>(props: TabProps<A>) {
export function Tab<A>(props: TabProps<A>): JSX.Element {
const { value, selection, onSelection, onClose } = props;
const selected = value === selection;
// --- Tab Rendering
......
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// --------------------------------------------------------------------------
// --- ToolBars
// --------------------------------------------------------------------------
......@@ -232,7 +234,7 @@ export function Select(props: SelectionProps<string>) {
const DEBOUNCED_SEARCH = 200;
const scrollToRef = (r: undefined | HTMLLabelElement) => {
const scrollToRef = (r: null | HTMLLabelElement) => {
if (r) r.scrollIntoView({ block: 'nearest' });
};
......
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// --------------------------------------------------------------------------
// --- Box Layout
// --------------------------------------------------------------------------
......
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// --------------------------------------------------------------------------
// --- Dispatch Layout
// --------------------------------------------------------------------------
......@@ -54,7 +56,7 @@ class ITEM {
this.event = new Event(`dome-dispatch-${id}`);
}
update(content: React.ReactNode) {
update(content: React.ReactNode): void {
this.content = content;
if (this.rendered) {
this.rendered = false;
......
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* --------------------------------------------------------------------------*/
/* --- Form Fields ---*/
/* --------------------------------------------------------------------------*/
......
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// --------------------------------------------------------------------------
// --- Splitters
// --------------------------------------------------------------------------
......
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// --------------------------------------------------------------------------
// --- Array Models
// --------------------------------------------------------------------------
......@@ -29,6 +31,7 @@
@module dome/table/arrays
*/
import { Debug } from 'dome';
import * as Compare from 'dome/data/compare';
import type { ByFields, Order } from 'dome/data/compare';
import {
......@@ -37,6 +40,8 @@ import {
Model, Collection, forEach,
} from './models';
const D = new Debug('Dome');
// --------------------------------------------------------------------------
// --- Sorting Utilities
// --------------------------------------------------------------------------
......@@ -147,7 +152,7 @@ export class ArrayModel<Key, Row>
});
table.sort(this.sorter());
} catch (err) {
console.warn('[Dome] error when rebuilding table:', err);
D.warn('error when rebuilding table:', err);
}
table.forEach((packed, index) => { packed.index = index; });
this.table = table;
......@@ -266,9 +271,9 @@ export class ArrayModel<Key, Row>
}
}
canSortBy(column: string) {
const columns = this.columns as any;
return columns[column] !== undefined;
canSortBy(column: string): boolean {
const columns = this.columns;
return !!columns && columns[column] !== undefined;
}
getSorting(): SortingInfo | undefined {
......@@ -460,7 +465,7 @@ export class CompactModel<Key, Row> extends ArrayModel<Key, Row> {
getkey: (d: Row) => Key;
/** @param key - the key property of `Row` holding an entry identifier. */
constructor(getkey: any) {
constructor(getkey: (d: Row) => Key) {
super();
this.getkey = getkey;
}
......
......@@ -102,7 +102,7 @@ export interface Filtering<Key, Row> {
export type Collection<A> = undefined | null | A | Collection<A>[];
/** Iterator over collection. */
export function forEach<A>(data: Collection<A>, fn: (elt: A) => void) {
export function forEach<A>(data: Collection<A>, fn: (elt: A) => void): void {
if (Array.isArray(data)) data.forEach((e) => forEach(e, fn));
else if (data !== undefined && data !== null) fn(data);
}
......@@ -201,7 +201,7 @@ export abstract class Model<Key, Row> {
delegates to [[updateIndex]].
All views that might be rendering the specified item will be updated.
*/
update(key: Key) {
update(key: Key): void {
const k = this.getIndexOf(key);
if (k !== undefined && 0 <= k) this.updateIndex(k);
}
......@@ -211,7 +211,7 @@ export abstract class Model<Key, Row> {
@param first - the first updated item index
@param last - the last updated item index (defaults to `first`)
*/
updateIndex(first: number, last = first) {
updateIndex(first: number, last = first): void {
if (first <= last) {
this.clients.forEach(({ lower, upper, update }) => {
if (update && first <= upper && lower <= last) update();
......@@ -223,7 +223,7 @@ export abstract class Model<Key, Row> {
Re-render all views.
Bound to this.
*/
reload() {
reload(): void {
this.clients.forEach(({ reload }) => reload && reload());
}
......@@ -271,7 +271,7 @@ export abstract class Model<Key, Row> {
@return a number that can be used to memoize other effects
*/
export function useModel(model: Model<any, any>, sync = true): number {
export function useModel<K, R>(model: Model<K, R>, sync = true): number {
const [age, setAge] = React.useState(0);
React.useEffect(() => {
if (sync) {
......
......@@ -20,6 +20,9 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable @typescript-eslint/no-explicit-any */
// --------------------------------------------------------------------------
// --- Tables
// --------------------------------------------------------------------------
......@@ -45,6 +48,7 @@ import {
TableHeaderRowProps,
TableHeaderProps,
TableCellDataGetter,
TableCellProps,
TableCellRenderer,
RowMouseEventHandlerParams,
} from 'react-virtualized';
......@@ -54,6 +58,7 @@ import { Trigger, Client, Sorting, SortingInfo, Model } from './models';
import './style.css';
const D = new Dome.Debug('Dome.table');
const SVG = SVGraw as (props: { id: string; size?: number }) => JSX.Element;
// --------------------------------------------------------------------------
......@@ -246,8 +251,8 @@ function makeDataGetter(
try {
if (rowData !== undefined) return getter(rowData, dataKey);
} catch (err) {
console.error(
'[Dome.table] Custom getter error',
D.error(
'custom getter error',
'rowData:', rowData,
'dataKey:', dataKey,
err,
......@@ -261,7 +266,7 @@ function makeDataRenderer(
render: ((data: any) => ReactNode) = defaultRenderer,
onContextMenu?: (row: any, index: number, dataKey: string) => void,
): TableCellRenderer {
return ((props) => {
return function TableCell(props: TableCellProps) {
const { cellData } = props;
try {
const contents = cellData ? render(cellData) : null;
......@@ -274,15 +279,15 @@ function makeDataRenderer(
}
return contents;
} catch (err) {
console.error(
'[Dome.table] Custom renderer error',
D.error(
'custom renderer error',
'dataKey:', props.dataKey,
'cellData:', cellData,
err,
);
return null;
}
});
};
}
// --------------------------------------------------------------------------
......
......@@ -20,6 +20,9 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable @typescript-eslint/no-explicit-any */
// --------------------------------------------------------------------------
// --- Text Documents
// --------------------------------------------------------------------------
......@@ -31,6 +34,9 @@
import Emitter from 'events';
import CodeMirror from 'codemirror/lib/codemirror';
import { Debug } from 'dome';
const D = new Debug('Dome.text');
export type Range = { from: CodeMirror.Position; to: CodeMirror.Position };
......@@ -553,7 +559,7 @@ export class RichTextBuffer extends Emitter {
*/
forEach(fn: (editor: CodeMirror.Editor) => void) {
this.editors.forEach((cm) => {
try { fn(cm); } catch (e) { console.error('[Dome.text]', e); }
try { fn(cm); } catch (e) { D.error(e); }
});
}
......
......@@ -20,6 +20,8 @@
/* */
/* ************************************************************************ */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// --------------------------------------------------------------------------
// --- Text Documents
// --------------------------------------------------------------------------
......@@ -42,6 +44,8 @@ import 'codemirror/lib/codemirror.css';
const CSS_HOVERED = 'dome-xText-hover';
const CSS_SELECTED = 'dome-xText-select';
const D = new Dome.Debug('Dome');
/* --------------------------------------------------------------------------*/
/* --- View Properties --- */
/* --------------------------------------------------------------------------*/
......@@ -378,7 +382,7 @@ class CodeMirrorWrapper extends React.Component<TextProps> {
const cm = this.codeMirror;
return cm && cm.scrollIntoView({ line, ch: 0 });
} catch (_error) {
console.warn(`[Dome] Unable to scroll to line ${line}: out of range.`);
D.warn(`unable to scroll to line ${line}: out of range.`);
}
}
......
......@@ -68,7 +68,7 @@ export interface TextProps {
The page has insets and shadows and fills the entire available area.
Large content is crolled inside in both directions.
*/
export const Page = (props: TextProps) => (
export const Page = (props: TextProps): JSX.Element => (
<div className="dome-xPages-page">
<div
className={classes('dome-xPages-sheet dome-pages', props.className)}
......@@ -88,7 +88,7 @@ export const Page = (props: TextProps) => (
The area has small padding and no margin, and does not scroll its content.
*/
export const Note = (props: TextProps) => (
export const Note = (props: TextProps): JSX.Element => (
<div
className={classes('dome-xPages-note', 'dome-pages', props.className)}
style={props.style}
......