Skip to content

Commit 3b485da

Browse files
authored
chore: convert to typescript (#156)
* chore: convert to typescript * fix: restore default label color * fix: restore border test threshold * fix: update linting, change type to module, etc
1 parent 20cbeb4 commit 3b485da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4318
-3045
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ jobs:
1818
- name: install
1919
run: npm ci
2020

21+
- name: lint
22+
run: npm run lint
23+
24+
- name: typecheck
25+
run: npm run typecheck
26+
2127
- name: build
2228
run: npm run build
2329

.github/workflows/npmpublish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- uses: actions/setup-node@v4
3838
with:
3939
cache: npm
40-
node-version: 16
40+
node-version: 20
4141
registry-url: https://registry.npmjs.org/
4242
- name: Setup and build
4343
run: |
@@ -51,11 +51,11 @@ jobs:
5151
VERSION: ${{ needs.setup.outputs.version }}
5252
- name: Publish @next
5353
run: npm publish --access=public --tag next
54-
if: "github.event.release.prerelease"
54+
if: github.event.release.prerelease == true
5555
env:
5656
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
5757
- name: Publish @latest
5858
run: npm publish --access=public --tag latest
59-
if: "!github.event.release.prerelease"
59+
if: github.event.release.prerelease == false
6060
env:
6161
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bracketSpacing: true
2+
singleQuote: true
3+
printWidth: 120
4+
semi: false
5+
tabWidth: 2
6+
useTabs: false
7+
trailingComma: 'es5'

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Jukka Kurkela
3+
Copyright (c) 2019-2024 Jukka Kurkela
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

eslint.config.mjs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { FlatCompat } from '@eslint/eslintrc'
2+
import js from '@eslint/js'
3+
import markdown from '@eslint/markdown'
4+
import tsParser from '@typescript-eslint/parser'
5+
import prettier from 'eslint-plugin-prettier'
6+
import simpleImportSort from 'eslint-plugin-simple-import-sort'
7+
import unusedImports from 'eslint-plugin-unused-imports'
8+
import globals from 'globals'
9+
import path from 'node:path'
10+
import { fileURLToPath } from 'node:url'
11+
12+
const __filename = fileURLToPath(import.meta.url)
13+
const __dirname = path.dirname(__filename)
14+
const compat = new FlatCompat({
15+
baseDirectory: __dirname,
16+
recommendedConfig: js.configs.recommended,
17+
allConfig: js.configs.all,
18+
})
19+
20+
export default [
21+
{
22+
ignores: ['**/*\\{.,-}min.js', 'dist/**/*'],
23+
},
24+
...compat.extends('chartjs', 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'),
25+
{
26+
plugins: {
27+
'unused-imports': unusedImports,
28+
'simple-import-sort': simpleImportSort,
29+
prettier,
30+
},
31+
32+
languageOptions: {
33+
globals: {
34+
...globals.browser,
35+
...globals.node,
36+
...globals.jasmine,
37+
},
38+
39+
ecmaVersion: 'latest',
40+
sourceType: 'module',
41+
42+
parser: tsParser,
43+
},
44+
45+
rules: {
46+
'prettier/prettier': 'error',
47+
'class-methods-use-this': 'off',
48+
complexity: ['warn', 10],
49+
'max-statements': ['warn', 30],
50+
'no-empty-function': 'off',
51+
semi: ['error', 'never'],
52+
quotes: [
53+
'error',
54+
'single',
55+
{
56+
avoidEscape: true,
57+
allowTemplateLiterals: true,
58+
},
59+
],
60+
'comma-spacing': [
61+
'error',
62+
{
63+
before: false,
64+
after: true,
65+
},
66+
],
67+
68+
'no-use-before-define': [
69+
'error',
70+
{
71+
functions: false,
72+
},
73+
],
74+
'@typescript-eslint/no-explicit-any': 'off',
75+
'@typescript-eslint/no-unused-vars': 'off',
76+
'@typescript-eslint/indent': 'off',
77+
'simple-import-sort/imports': [
78+
'error',
79+
{
80+
groups: [
81+
['^@?\\w.*\\u0000$', '^[^.].*\\u0000$', '^\\..*\\u0000$'],
82+
['^react', '^@?\\w'],
83+
['^(@|components)(/.*|$)'],
84+
['^\\u0000'],
85+
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
86+
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
87+
['^.+\\.?(css)$'],
88+
],
89+
},
90+
],
91+
92+
'unused-imports/no-unused-imports': 'error',
93+
},
94+
},
95+
{
96+
files: ['src/**/*.ts', '**/*.js', '**/*.mjs'],
97+
},
98+
{
99+
files: ['**/*.md'],
100+
language: 'markdown/commonmark',
101+
plugins: {
102+
markdown,
103+
},
104+
rules: {
105+
'no-irregular-whitespace': 'off',
106+
},
107+
},
108+
{
109+
files: ['types/**/*.ts'],
110+
rules: {
111+
'no-use-before-define': 'warn',
112+
},
113+
},
114+
{
115+
files: ['**/*.cjs'],
116+
rules: {
117+
'@typescript-eslint/no-require-imports': 'off',
118+
},
119+
},
120+
]
Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
const istanbul = require('rollup-plugin-istanbul');
2-
const resolve = require('@rollup/plugin-node-resolve').default;
3-
const builds = require('./rollup.config');
4-
const env = process.env.NODE_ENV;
1+
const istanbul = require('rollup-plugin-istanbul')
52

6-
module.exports = function(karma) {
7-
const build = builds[0];
3+
const env = process.env.NODE_ENV
4+
5+
module.exports = async function (karma) {
6+
const builds = (await import('./rollup.config.js')).default
7+
8+
const build = builds[0]
9+
const buildPlugins = [...build.plugins]
810

911
if (env === 'test') {
10-
build.plugins = [
11-
resolve(),
12-
istanbul({exclude: ['node_modules/**/*.js', 'package.json']})
13-
];
12+
build.plugins.push(istanbul({ exclude: ['node_modules/**/*.js', 'package.json'] }))
1413
}
1514

1615
karma.set({
@@ -20,12 +19,12 @@ module.exports = function(karma) {
2019
logLevel: karma.LOG_WARN,
2120

2221
files: [
23-
{pattern: './test/fixtures/**/*.js', included: false},
24-
{pattern: './test/fixtures/**/*.png', included: false},
22+
{ pattern: './test/fixtures/**/*.js', included: false },
23+
{ pattern: './test/fixtures/**/*.png', included: false },
2524
'node_modules/chart.js/dist/chart.umd.js',
2625
'test/index.js',
27-
'src/index.js',
28-
'test/specs/**/*.js'
26+
{ pattern: 'src/index.ts', type: 'js' },
27+
{ pattern: 'test/specs/**/*.js', type: 'js' },
2928
],
3029

3130
customLaunchers: {
@@ -34,38 +33,34 @@ module.exports = function(karma) {
3433
flags: [
3534
'--disable-background-timer-throttling',
3635
'--disable-backgrounding-occluded-windows',
37-
'--disable-renderer-backgrounding'
38-
]
36+
'--disable-renderer-backgrounding',
37+
],
3938
},
4039
firefox: {
4140
base: 'Firefox',
4241
prefs: {
43-
'layers.acceleration.disabled': true
44-
}
45-
}
42+
'layers.acceleration.disabled': true,
43+
},
44+
},
4645
},
4746

4847
preprocessors: {
4948
'test/fixtures/**/*.js': ['fixtures'],
5049
'test/specs/**/*.js': ['rollup'],
5150
'test/index.js': ['rollup'],
52-
'src/index.js': ['sources']
51+
'src/index.ts': ['sources'],
5352
},
5453

5554
rollupPreprocessor: {
56-
plugins: [
57-
resolve(),
58-
],
59-
external: [
60-
'chart.js'
61-
],
55+
plugins: buildPlugins,
56+
external: ['chart.js'],
6257
output: {
6358
format: 'umd',
6459
sourcemap: karma.autoWatch ? 'inline' : false,
6560
globals: {
66-
'chart.js': 'Chart'
67-
}
68-
}
61+
'chart.js': 'Chart',
62+
},
63+
},
6964
},
7065

7166
customPreprocessors: {
@@ -74,25 +69,25 @@ module.exports = function(karma) {
7469
options: {
7570
output: {
7671
format: 'iife',
77-
name: 'fixture'
78-
}
79-
}
72+
name: 'fixture',
73+
},
74+
},
8075
},
8176
sources: {
8277
base: 'rollup',
83-
options: build
84-
}
85-
}
86-
});
78+
options: build,
79+
},
80+
},
81+
})
8782

8883
if (env === 'test') {
89-
karma.reporters.push('coverage');
84+
karma.reporters.push('coverage')
9085
karma.coverageReporter = {
9186
dir: 'coverage/',
9287
reporters: [
93-
{type: 'html', subdir: 'html'},
94-
{type: 'lcovonly', subdir: (browser) => browser.toLowerCase().split(/[ /-]/)[0]}
95-
]
96-
};
88+
{ type: 'html', subdir: 'html' },
89+
{ type: 'lcovonly', subdir: (browser) => browser.toLowerCase().split(/[ /-]/)[0] },
90+
],
91+
}
9792
}
98-
};
93+
}

0 commit comments

Comments
 (0)