Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: convert to typescript #156

Merged
merged 4 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

31 changes: 0 additions & 31 deletions .eslintrc.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ jobs:
- name: install
run: npm ci

- name: lint
run: npm run lint

- name: typecheck
run: npm run typecheck

- name: build
run: npm run build

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- uses: actions/setup-node@v4
with:
cache: npm
node-version: 16
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Setup and build
run: |
Expand All @@ -51,11 +51,11 @@ jobs:
VERSION: ${{ needs.setup.outputs.version }}
- name: Publish @next
run: npm publish --access=public --tag next
if: "github.event.release.prerelease"
if: github.event.release.prerelease == true
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Publish @latest
run: npm publish --access=public --tag latest
if: "!github.event.release.prerelease"
if: github.event.release.prerelease == false
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bracketSpacing: true
singleQuote: true
printWidth: 120
semi: false
tabWidth: 2
useTabs: false
trailingComma: 'es5'
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Jukka Kurkela
Copyright (c) 2019-2024 Jukka Kurkela

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
120 changes: 120 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import markdown from '@eslint/markdown'
import tsParser from '@typescript-eslint/parser'
import prettier from 'eslint-plugin-prettier'
import simpleImportSort from 'eslint-plugin-simple-import-sort'
import unusedImports from 'eslint-plugin-unused-imports'
import globals from 'globals'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
{
ignores: ['**/*\\{.,-}min.js', 'dist/**/*'],
},
...compat.extends('chartjs', 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'),
{
plugins: {
'unused-imports': unusedImports,
'simple-import-sort': simpleImportSort,
prettier,
},

languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.jasmine,
},

ecmaVersion: 'latest',
sourceType: 'module',

parser: tsParser,
},

rules: {
'prettier/prettier': 'error',
'class-methods-use-this': 'off',
complexity: ['warn', 10],
'max-statements': ['warn', 30],
'no-empty-function': 'off',
semi: ['error', 'never'],
quotes: [
'error',
'single',
{
avoidEscape: true,
allowTemplateLiterals: true,
},
],
'comma-spacing': [
'error',
{
before: false,
after: true,
},
],

'no-use-before-define': [
'error',
{
functions: false,
},
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/indent': 'off',
'simple-import-sort/imports': [
'error',
{
groups: [
['^@?\\w.*\\u0000$', '^[^.].*\\u0000$', '^\\..*\\u0000$'],
['^react', '^@?\\w'],
['^(@|components)(/.*|$)'],
['^\\u0000'],
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
['^.+\\.?(css)$'],
],
},
],

'unused-imports/no-unused-imports': 'error',
},
},
{
files: ['src/**/*.ts', '**/*.js', '**/*.mjs'],
},
{
files: ['**/*.md'],
language: 'markdown/commonmark',
plugins: {
markdown,
},
rules: {
'no-irregular-whitespace': 'off',
},
},
{
files: ['types/**/*.ts'],
rules: {
'no-use-before-define': 'warn',
},
},
{
files: ['**/*.cjs'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
]
79 changes: 37 additions & 42 deletions karma.conf.js → karma.conf.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
const istanbul = require('rollup-plugin-istanbul');
const resolve = require('@rollup/plugin-node-resolve').default;
const builds = require('./rollup.config');
const env = process.env.NODE_ENV;
const istanbul = require('rollup-plugin-istanbul')

module.exports = function(karma) {
const build = builds[0];
const env = process.env.NODE_ENV

module.exports = async function (karma) {
const builds = (await import('./rollup.config.js')).default

const build = builds[0]
const buildPlugins = [...build.plugins]

if (env === 'test') {
build.plugins = [
resolve(),
istanbul({exclude: ['node_modules/**/*.js', 'package.json']})
];
build.plugins.push(istanbul({ exclude: ['node_modules/**/*.js', 'package.json'] }))
}

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

files: [
{pattern: './test/fixtures/**/*.js', included: false},
{pattern: './test/fixtures/**/*.png', included: false},
{ pattern: './test/fixtures/**/*.js', included: false },
{ pattern: './test/fixtures/**/*.png', included: false },
'node_modules/chart.js/dist/chart.umd.js',
'test/index.js',
'src/index.js',
'test/specs/**/*.js'
{ pattern: 'src/index.ts', type: 'js' },
{ pattern: 'test/specs/**/*.js', type: 'js' },
],

customLaunchers: {
Expand All @@ -34,38 +33,34 @@ module.exports = function(karma) {
flags: [
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows',
'--disable-renderer-backgrounding'
]
'--disable-renderer-backgrounding',
],
},
firefox: {
base: 'Firefox',
prefs: {
'layers.acceleration.disabled': true
}
}
'layers.acceleration.disabled': true,
},
},
},

preprocessors: {
'test/fixtures/**/*.js': ['fixtures'],
'test/specs/**/*.js': ['rollup'],
'test/index.js': ['rollup'],
'src/index.js': ['sources']
'src/index.ts': ['sources'],
},

rollupPreprocessor: {
plugins: [
resolve(),
],
external: [
'chart.js'
],
plugins: buildPlugins,
external: ['chart.js'],
output: {
format: 'umd',
sourcemap: karma.autoWatch ? 'inline' : false,
globals: {
'chart.js': 'Chart'
}
}
'chart.js': 'Chart',
},
},
},

customPreprocessors: {
Expand All @@ -74,25 +69,25 @@ module.exports = function(karma) {
options: {
output: {
format: 'iife',
name: 'fixture'
}
}
name: 'fixture',
},
},
},
sources: {
base: 'rollup',
options: build
}
}
});
options: build,
},
},
})

if (env === 'test') {
karma.reporters.push('coverage');
karma.reporters.push('coverage')
karma.coverageReporter = {
dir: 'coverage/',
reporters: [
{type: 'html', subdir: 'html'},
{type: 'lcovonly', subdir: (browser) => browser.toLowerCase().split(/[ /-]/)[0]}
]
};
{ type: 'html', subdir: 'html' },
{ type: 'lcovonly', subdir: (browser) => browser.toLowerCase().split(/[ /-]/)[0] },
],
}
}
};
}
Loading