Skip to content

Commit 50272e7

Browse files
committed
feat: use airbnb style
1 parent 9b2da82 commit 50272e7

20 files changed

+240
-142
lines changed

.eslintrc.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,26 @@ const pkg = require('./package.json');
55

66
module.exports = {
77
plugins: ['@typescript-eslint', 'prettier'],
8-
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'prettier'],
8+
extends: [
9+
'airbnb-typescript',
10+
'react-app',
11+
'plugin:@typescript-eslint/recommended',
12+
'plugin:prettier/recommended',
13+
'prettier',
14+
],
15+
parserOptions: {
16+
project: './tsconfig.eslint.json',
17+
},
918
settings: {
1019
react: {
1120
version: pkg.devDependencies.react ? 'detect' : '99.99.99',
1221
},
1322
},
1423
rules: {
15-
'@typescript-eslint/explicit-module-boundary-types': 'off',
24+
// '@typescript-eslint/explicit-module-boundary-types': 'off',
1625
'@typescript-eslint/no-explicit-any': 'off',
17-
'@typescript-eslint/no-non-null-assertion': 'off',
26+
'no-underscore-dangle': 'off',
27+
'max-classes-per-file': 'off',
28+
// '@typescript-eslint/no-non-null-assertion': 'off',
1829
},
1930
};

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"[yaml]": {
1414
"editor.defaultFormatter": "esbenp.prettier-vscode"
1515
},
16-
"prettier.packageManager": "yarn",
1716
"eslint.packageManager": "yarn",
1817
"npm.packageManager": "yarn",
1918
"eslint.nodePath": ".yarn/sdks",
@@ -26,5 +25,5 @@
2625
"search.exclude": {
2726
"**/.yarn": true,
2827
"**/.pnp.*": true
29-
}
28+
},
3029
}

.yarnrc_patch.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
# packageExtensions:
1+
packageExtensions:
2+
eslint-module-utils@*:
3+
dependencies:
4+
eslint-import-resolver-node: '*'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"canvas-5-polyfill": "^0.1.5",
7676
"chart.js": "^3.0.0-rc",
7777
"eslint": "^7.22.0",
78+
"eslint-config-airbnb-typescript": "^12.3.1",
7879
"eslint-config-prettier": "^8.1.0",
7980
"eslint-config-react-app": "^6.0.0",
8081
"eslint-plugin-flowtype": "^5.4.0",

src/__tests__/createChart.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function toBuffer(canvas: HTMLCanvasElement) {
1717
});
1818
}
1919

20-
export async function expectMatchSnapshot(canvas: HTMLCanvasElement) {
20+
export async function expectMatchSnapshot(canvas: HTMLCanvasElement): Promise<void> {
2121
const image = await toBuffer(canvas);
2222
expect(image).toMatchImageSnapshot();
2323
}
@@ -32,21 +32,19 @@ export default function createChart<
3232
canvas.height = height;
3333
defaults.font.family = 'Courier New';
3434
defaults.color = 'transparent';
35-
config.options = Object.assign(
36-
{
37-
responsive: false,
38-
animation: false,
39-
plugins: {
40-
legend: {
41-
display: false,
42-
},
43-
title: {
44-
display: false,
45-
},
35+
config.options = {
36+
responsive: false,
37+
animation: false,
38+
plugins: {
39+
legend: {
40+
display: false,
41+
},
42+
title: {
43+
display: false,
4644
},
4745
},
48-
config.options || {}
49-
) as any;
46+
...(config.options || {}),
47+
} as any;
5048
const ctx = canvas.getContext('2d')!;
5149

5250
const t = new Chart<TYPE, DATA, LABEL>(ctx, config);

src/animation.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ const interpolators = {
1515
},
1616
};
1717

18-
export function interpolateNumberArray(from: number | number[], to: number | number[], factor: number) {
18+
export function interpolateNumberArray(
19+
from: number | number[],
20+
to: number | number[],
21+
factor: number
22+
): number | null | undefined | (number | null | undefined)[] {
1923
if (typeof from === 'number' && typeof to === 'number') {
2024
return interpolators.number(from, to, factor);
2125
}
@@ -25,7 +29,11 @@ export function interpolateNumberArray(from: number | number[], to: number | num
2529
return to;
2630
}
2731

28-
export function interpolateKdeCoords(from: IKDEPoint[], to: IKDEPoint[], factor: number) {
32+
export function interpolateKdeCoords(
33+
from: IKDEPoint[],
34+
to: IKDEPoint[],
35+
factor: number
36+
): { v: number | null | undefined; estimate: number | null | undefined }[] {
2937
if (Array.isArray(from) && Array.isArray(to)) {
3038
return to.map((t, i) => ({
3139
v: interpolators.number(from[i] ? from[i].v : null, t.v, factor),

src/controllers/BoxPlotController.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { registry, BarController, LineController, PointElement, BarElement, LineElement } from 'chart.js';
12
import createChart from '../__tests__/createChart';
23
import { BoxPlotController, BoxPlotDataPoint } from './BoxPlotController';
34
import { Samples } from './__tests__/utils';
4-
import { registry, BarController, LineController, PointElement, BarElement, LineElement } from 'chart.js';
55
import { BoxAndWiskers } from '../elements';
66

77
const options = {

src/controllers/BoxPlotController.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { asBoxPlotStats, IBaseStats, IBoxPlot, IBoxplotOptions } from '../data';
2-
import {
1+
import {
32
Chart,
43
BarController,
54
ControllerDatasetOptions,
@@ -12,25 +11,27 @@ import {
1211
CartesianScaleTypeRegistry,
1312
} from 'chart.js';
1413
import { merge } from 'chart.js/helpers';
14+
import { asBoxPlotStats, IBaseStats, IBoxPlot, IBoxplotOptions } from '../data';
1515
import { baseDefaults, StatsBase, defaultOverrides } from './base';
1616
import { BoxAndWiskers, IBoxAndWhiskersOptions } from '../elements';
1717
import patchController from './patchController';
1818
import { boxOptionsKeys } from '../elements/BoxAndWiskers';
1919

2020
export class BoxPlotController extends StatsBase<IBoxPlot, Required<IBoxplotOptions>> {
21-
protected _parseStats(value: any, config: IBoxplotOptions) {
21+
protected _parseStats(value: unknown, config: IBoxplotOptions): IBoxPlot | undefined {
2222
return asBoxPlotStats(value, config);
2323
}
2424

25-
protected _transformStats<T>(target: any, source: IBoxPlot, mapper: (v: number) => T) {
25+
protected _transformStats<T>(target: any, source: IBoxPlot, mapper: (v: number) => T): void {
2626
super._transformStats(target, source, mapper);
2727
for (const key of ['whiskerMin', 'whiskerMax']) {
2828
target[key] = mapper(source[key as 'whiskerMin' | 'whiskerMax']);
2929
}
3030
}
3131

3232
static readonly id = 'boxplot';
33-
static readonly defaults: any = /*#__PURE__*/ merge({}, [
33+
34+
static readonly defaults: any = /* #__PURE__ */ merge({}, [
3435
BarController.defaults,
3536
baseDefaults(boxOptionsKeys),
3637
{
@@ -46,7 +47,8 @@ export class BoxPlotController extends StatsBase<IBoxPlot, Required<IBoxplotOpti
4647
dataElementType: BoxAndWiskers.id,
4748
},
4849
]);
49-
static readonly overrides: any = /*#__PURE__*/ merge({}, [(BarController as any).overrides, defaultOverrides()]);
50+
51+
static readonly overrides: any = /* #__PURE__ */ merge({}, [(BarController as any).overrides, defaultOverrides()]);
5052
}
5153

5254
export interface BoxPlotControllerDatasetOptions

src/controllers/ViolinController.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { registry } from 'chart.js';
12
import createChart from '../__tests__/createChart';
23
import { ViolinController } from './ViolinController';
34
import { Samples } from './__tests__/utils';
4-
import { registry } from 'chart.js';
55
import { Violin } from '../elements';
66

77
describe('violin', () => {

src/controllers/ViolinController.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { asViolinStats, IBaseStats, IViolin, IViolinOptions } from '../data';
2-
import {
1+
import {
32
Chart,
43
BarController,
54
ChartItem,
@@ -12,6 +11,7 @@ import {
1211
CartesianScaleTypeRegistry,
1312
} from 'chart.js';
1413
import { merge } from 'chart.js/helpers';
14+
import { asViolinStats, IBaseStats, IViolin, IViolinOptions } from '../data';
1515
import { StatsBase, baseDefaults, defaultOverrides } from './base';
1616
import { baseOptionKeys } from '../elements/base';
1717
import { IViolinElementOptions, Violin } from '../elements';
@@ -27,12 +27,13 @@ export class ViolinController extends StatsBase<IViolin, Required<IViolinOptions
2727
super._transformStats(target, source, mapper);
2828
target.maxEstimate = source.maxEstimate;
2929
if (Array.isArray(source.coords)) {
30-
target.coords = source.coords.map((c) => Object.assign({}, c, { v: mapper(c.v) }));
30+
target.coords = source.coords.map((c) => ({ ...c, v: mapper(c.v) }));
3131
}
3232
}
3333

3434
static readonly id = 'violin';
35-
static readonly defaults: any = /*#__PURE__*/ merge({}, [
35+
36+
static readonly defaults: any = /* #__PURE__ */ merge({}, [
3637
BarController.defaults,
3738
baseDefaults(baseOptionKeys),
3839
{
@@ -53,7 +54,8 @@ export class ViolinController extends StatsBase<IViolin, Required<IViolinOptions
5354
dataElementType: Violin.id,
5455
},
5556
]);
56-
static readonly overrides: any = /*#__PURE__*/ merge({}, [(BarController as any).overrides, defaultOverrides()]);
57+
58+
static readonly overrides: any = /* #__PURE__ */ merge({}, [(BarController as any).overrides, defaultOverrides()]);
5759
}
5860
export type ViolinDataPoint = number[] | (Partial<IViolin> & IBaseStats);
5961

0 commit comments

Comments
 (0)