Skip to content

Commit

Permalink
remove duplicate type definition
Browse files Browse the repository at this point in the history
and add a CI check
  • Loading branch information
SlicedSilver committed Jul 30, 2024
1 parent dc5abb6 commit c6749ea
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 34 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@
"lint": "npm-run-all -p lint:**",
"lint:eslint": "eslint --format=unix ./",
"lint:md": "markdownlint -i \"**/node_modules/**\" -i \"**/website/docs/api/**\" -i \"**/website/versioned_docs/**/api/**\" -i \"**/*.mdx\" \"**/*.md\"",
"check-dts-docs": "eslint --format=unix ./dist/typings.d.ts --no-ignore",
"check-dts-docs": "npm-run-all -p check-dts-docs-duplicates check-dts-docs-eslint",
"check-dts-docs-duplicates": "node ./scripts/check-typings-for-duplicates.js ./dist/typings.d.ts",
"check-dts-docs-eslint": "eslint --format=unix ./dist/typings.d.ts --no-ignore",
"check-markdown-links": "node scripts/check-markdown-links.js",
"rollup": "rollup -c rollup.config.js",
"rollup-watch": "npm run rollup -- --watch",
Expand Down
37 changes: 37 additions & 0 deletions scripts/check-typings-for-duplicates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import fs from 'node:fs/promises';
import process from 'node:process';

/*
Quick test to check if there are any duplicates in the d.ts file
which dts-bundle-generator found. The simple quick test is to
look for the string '$1 '.
*/

async function checkDtsFile(filePath) {
try {
// Read the contents of the .d.ts file
const content = await fs.readFile(filePath, 'utf-8');

// Check if the content includes the string '$1 '
if (content.includes('$1 ')) {
console.error('Error: The string "$1 " was found in the .d.ts file. This typically means there is a duplicate type definition.');
process.exit(1); // Exit with an error code
} else {
process.exit(0); // Exit successfully
}
} catch (error) {
console.error('An error occurred:', error.message);
process.exit(1); // Exit with an error code
}
}

// Check if a file path is provided as a command-line argument
if (process.argv.length < 3) {
console.error(
'Please provide the path to the .d.ts file as a command-line argument.'
);
process.exit(1);
}

const filePath = process.argv[2];
checkDtsFile(filePath);
5 changes: 1 addition & 4 deletions src/gui/pane-hit-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { HoveredObject } from '../model/chart-model';
import { Coordinate } from '../model/coordinate';
import { IDataSource, IPrimitiveHitTestSource } from '../model/idata-source';
import { PrimitivePaneViewZOrder } from '../model/ipane-primitive';
import {
PrimitiveHoveredItem,
} from '../model/iseries-primitive';
import { PrimitiveHoveredItem, PrimitivePaneViewZOrder } from '../model/ipane-primitive';
import { Pane } from '../model/pane';
import { IPaneView } from '../views/pane/ipane-view';

Expand Down
3 changes: 1 addition & 2 deletions src/model/idata-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { IPriceAxisView } from '../views/price-axis/iprice-axis-view';
import { ITimeAxisView } from '../views/time-axis/itime-axis-view';

import { Coordinate } from './coordinate';
import { PrimitivePaneViewZOrder } from './ipane-primitive';
import { PrimitiveHoveredItem } from './iseries-primitive';
import { PrimitiveHoveredItem, PrimitivePaneViewZOrder } from './ipane-primitive';
import { Pane } from './pane';
import { PriceScale } from './price-scale';

Expand Down
25 changes: 1 addition & 24 deletions src/model/iseries-primitive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IPrimitivePaneView, PrimitivePaneViewZOrder } from './ipane-primitive';
import { IPrimitivePaneView, PrimitiveHoveredItem } from './ipane-primitive';
import { AutoscaleInfo } from './series-options';
import { Logical } from './time-data';

Expand Down Expand Up @@ -50,29 +50,6 @@ export interface ISeriesPrimitiveAxisView {
tickVisible?(): boolean;
}

/**
* Data representing the currently hovered object from the Hit test.
*/
export interface PrimitiveHoveredItem {
/**
* CSS cursor style as defined here: [MDN: CSS Cursor](https://developer.mozilla.org/en-US/docs/Web/CSS/cursor) or `undefined`
* if you want the library to use the default cursor style instead.
*/
cursorStyle?: string;
/**
* Hovered objects external ID. Can be used to identify the source item within a mouse subscriber event.
*/
externalId: string;
/**
* The zOrder of the hovered item.
*/
zOrder: PrimitivePaneViewZOrder;
/**
* Set to true if the object is rendered using `drawBackground` instead of `draw`.
*/
isBackground?: boolean;
}

/**
* Base interface for series primitives. It must be implemented to add some external graphics to series
*/
Expand Down
2 changes: 1 addition & 1 deletion src/model/pane-primitive-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
IPanePrimitiveBase,
IPrimitivePaneRenderer,
IPrimitivePaneView,
PrimitiveHoveredItem,
PrimitivePaneViewZOrder,
} from './ipane-primitive';
import {
ISeriesPrimitiveBase,
PrimitiveHoveredItem,
} from './iseries-primitive';

class PrimitiveRendererWrapper implements IPaneRenderer {
Expand Down
4 changes: 2 additions & 2 deletions src/model/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import { CustomPriceLine } from './custom-price-line';
import { isDefaultPriceScale } from './default-price-scale';
import { CustomData, CustomSeriesWhitespaceData, ICustomSeriesPaneView, WhitespaceCheck } from './icustom-series';
import { InternalHorzScaleItem } from './ihorz-scale-behavior';
import { PrimitivePaneViewZOrder } from './ipane-primitive';
import { PrimitiveHoveredItem, PrimitivePaneViewZOrder } from './ipane-primitive';
import { FirstValue, IPriceDataSource } from './iprice-data-source';
import { ISeriesPrimitiveBase, PrimitiveHoveredItem } from './iseries-primitive';
import { ISeriesPrimitiveBase } from './iseries-primitive';
import { Pane } from './pane';
import { PlotRowValueIndex } from './plot-data';
import { MismatchDirection } from './plot-list';
Expand Down

0 comments on commit c6749ea

Please sign in to comment.