Skip to content

Commit

Permalink
chore: upgrade lint/prettier for new TS version (#1099)
Browse files Browse the repository at this point in the history
* chore: upgrade lint and prettier for new TS version

* fix: all lint/prettier errors

* chore: update the gosling schema
  • Loading branch information
sehilyi authored Jan 27, 2025
1 parent 3d3afc8 commit 8b3ceac
Show file tree
Hide file tree
Showing 38 changed files with 1,533 additions and 744 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

28 changes: 15 additions & 13 deletions editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function isJSON(str: string | null) {
if (!str) return false;
try {
return JSON.parse(str);
} catch (e) {
} catch {
return false;
}
}
Expand Down Expand Up @@ -139,8 +139,8 @@ const getDescPanelDefultWidth = () => Math.min(500, window.innerWidth);
function resolveRelativeCsvUrls(spec: string, importMeta: URL) {
const newSpec = JSON.parse(spec);
// https://regex101.com/r/l87Q5q/1
// eslint-disable-next-line
const relativePathRegex = /^[.\/]|^\.[.\/]|^\.\.[^\/]/;

const relativePathRegex = /^[./]|^\.[./]|^\.\.[^/]/;
traverseTracksAndViews(newSpec as gosling.GoslingSpec, (tv: any) => {
if (tv.data && tv.data.type === 'csv' && relativePathRegex.test(tv.data.url)) {
tv.data.url = new URL(tv.data.url, importMeta).href;
Expand All @@ -156,7 +156,7 @@ const fetchSpecFromGist = async (gist: string) => {
// which is not supported by the normal `fetch()` so we need `fetchJsonp()`
const response = await fetchJsonp(`https://gist.github.com/${gist}.json`);
metadata = await (response.ok ? response.json() : null);
} catch (error) {
} catch {
return Promise.reject(new Error('Gist not found'));
}

Expand Down Expand Up @@ -430,7 +430,9 @@ function Editor(props: RouteComponentProps) {
>
{Object.keys(deviceToResolution).map(d => {
// separator (https://stackoverflow.com/questions/899148/html-select-option-separator)
if (d === '-') return <optgroup label="──────────"></optgroup>;
if (d === '-') {
return <optgroup key={d} label="──────────"></optgroup>;
}
return (
<option key={d} value={d}>
{d}
Expand Down Expand Up @@ -535,7 +537,7 @@ function Editor(props: RouteComponentProps) {
editedGos = JSON.parse(stripJsonComments(code));
valid = gosling.validateGoslingSpec(editedGos);
setLog(valid);
} catch (e) {
} catch {
const message = '✘ Cannnot parse the code.';
console.warn(message);
setLog({ message, state: 'error' });
Expand Down Expand Up @@ -589,10 +591,10 @@ function Editor(props: RouteComponentProps) {
typeof goslingSpec?.responsiveSize === 'undefined'
? false
: typeof goslingSpec?.responsiveSize === 'boolean'
? goslingSpec?.responsiveSize === true
: typeof goslingSpec?.responsiveSize === 'object'
? goslingSpec?.responsiveSize.width === true || goslingSpec?.responsiveSize.height === true
: false;
? goslingSpec?.responsiveSize === true
: typeof goslingSpec?.responsiveSize === 'object'
? goslingSpec?.responsiveSize.width === true || goslingSpec?.responsiveSize.height === true
: false;
if (newIsResponsive !== isResponsive && newIsResponsive) {
setScreenSize(undefined); // reset the screen
setVisibleScreenSize(undefined);
Expand Down Expand Up @@ -1028,10 +1030,10 @@ function Editor(props: RouteComponentProps) {
`URL of the current visualization is copied to your clipboard! `
)
)
.catch(
.catch(e => {
// eslint-disable-next-line no-alert
e => alert(`something went wrong ${e}`)
);
alert(`something went wrong ${e}`);
});
}
}}
>
Expand Down
2 changes: 1 addition & 1 deletion editor/EditorPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useState, useEffect } from 'react'; // eslint-disable-line no-unused-vars
import React, { useRef, useState, useEffect } from 'react';
import MonacoEditor from 'react-monaco-editor';

import ReactResizeDetector from 'react-resize-detector';
Expand Down
4 changes: 1 addition & 3 deletions editor/error-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ interface State {
hasError: boolean;
}

interface Props {}

export default class ErrorBoundary extends React.Component<React.PropsWithChildren<Props>, State> {
export default class ErrorBoundary extends React.Component<React.PropsWithChildren<unknown>, State> {
state: State = { hasError: false };

componentDidCatch() {
Expand Down
1 change: 0 additions & 1 deletion editor/example/json-spec/matrix-hffc6.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { GoslingSpec } from 'gosling.js';
import { GOSLING_PUBLIC_DATA } from './gosling-data';

export const EX_SPEC_MATRIX_HFFC6: GoslingSpec = {
title: 'Matrix Visualization',
Expand Down
13 changes: 0 additions & 13 deletions editor/example/json-spec/matrix.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
import type { PredefinedColors, SingleTrack } from '@gosling-lang/gosling-schema';
import type { GoslingSpec } from 'gosling.js';
import { random } from 'lodash-es';
import { GOSLING_PUBLIC_DATA } from './gosling-data';

const generateToyJson = (length: number, chr: string, size: number) =>
Array.from({ length }, () => {
return {
c: chr,
x: random(true) * size,
xe: random(true) * size,
y: random(true) * size,
ye: random(true) * size,
v: random(true)
};
});

export const EX_SPEC_MATRIX: GoslingSpec = {
title: 'Hi-C Matrix',
subtitle: 'Visualize Hi-C Data Using Matrix and Annotations',
Expand Down
13 changes: 11 additions & 2 deletions editor/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ body {
/* Common font styles */
body,
button {
font-family: 'Helvetica Neue', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
'Cantarell', 'Droid Sans', sans-serif;
font-family:
'Helvetica Neue',
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
'Roboto',
'Oxygen',
'Ubuntu',
'Cantarell',
'Droid Sans',
sans-serif;
font-size: 14px;
text-align: left;
line-height: 1.42857143;
Expand Down
73 changes: 73 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import tsparser from '@typescript-eslint/parser';
import pluginReact from 'eslint-plugin-react';
import eslintPluginPrettierRecommed from 'eslint-plugin-prettier/recommended';

/** @type {import('eslint').Linter.Config[]} */
export default [
eslintPluginPrettierRecommed,
{ files: ['**/*.{js,mjs,cjs,ts,jsx,tsx}'] },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
pluginReact.configs.flat.recommended,
{ ignores: ['node_modules', 'build', 'dist', 'public'] },
{
languageOptions: {
globals: globals.browser,
parser: tsparser,
parserOptions: {
project: 'tsconfig.json',
ecmaVersion: 6,
sourceType: 'module'
}
}
},
{
settings: {
react: {
version: "detect"
}
}
},
{
rules: {
'prettier/prettier': 'warn',
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-empty-function': 'off', // we need this in higlass plugin track
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'no-unused-vars': 'off', // must disable the base rule as it can report incorrect errors
// https://www.executeprogram.com/blog/the-code-is-the-to-do-list
'no-warning-comments': ['error', { terms: ['xxx'], location: 'anywhere' }],
'@typescript-eslint/no-unused-vars': [
'error',
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: true
}
],
// https://eslint.org/docs/rules/
'linebreak-style': ['error', 'unix'],
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-trailing-spaces': 'error',
'no-irregular-whitespace': ['error', { skipComments: true }],
'no-alert': 'error',
'prefer-const': 'error',
'no-case-declarations': 'warn',
'no-return-assign': 'error',
'no-useless-call': 'error',
'no-shadow': 'off', // 'error', // we could enable this later
'no-useless-concat': 'error',
'prefer-template': 'error'
}
}
];
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"threads": "^1.6.4"
},
"devDependencies": {
"@eslint/js": "^9.19.0",
"@playwright/experimental-ct-react": "^1.41.1",
"@types/bezier-js": "^4.1.0",
"@types/d3": "^7.4.3",
Expand All @@ -117,28 +118,29 @@
"@types/react-dom": "^18.2.0",
"@types/react-resize-detector": "^4.2.0",
"@types/react-router-dom": "^5.1.6",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"@typescript-eslint/eslint-plugin": "^8.22.0",
"@typescript-eslint/parser": "^8.22.0",
"@vitejs/plugin-react": "^4.1.0",
"@vitest/coverage-v8": "^0.34.6",
"ajv": "^6.12.2",
"c8": "^7.11.2",
"conventional-changelog-cli": "^2.1.1",
"esbuild": "^0.12.25",
"eslint": "^8.19.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.30.1",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-react": "^7.37.4",
"fetch-jsonp": "^1.1.3",
"globals": "^15.14.0",
"jsdom": "^19.0.0",
"jsoncrush": "^1.1.6",
"knip": "^2.30.0",
"npm-run-all": "^4.1.5",
"pixelmatch": "^5.3.0",
"pixi.js": "^7.4.0",
"pngjs": "^7.0.0",
"prettier": "^2.0.5",
"prettier": "^3.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^5.0.3",
Expand All @@ -150,6 +152,7 @@
"strip-json-comments": "^3.1.1",
"ts-json-schema-generator": "^1.0.0",
"typescript": "^5.7.3",
"typescript-eslint": "^8.22.0",
"vite": "^4.4.11",
"vitest": "^0.34.6",
"vitest-canvas-mock": "^0.3.3"
Expand Down
Loading

0 comments on commit 8b3ceac

Please sign in to comment.