simplify eslint configs + add CI job

This commit is contained in:
Brendan Allan 2023-01-22 16:01:15 +08:00
parent 100787a349
commit d3737cea97
32 changed files with 174 additions and 151 deletions

View file

@ -37,6 +37,30 @@ jobs:
- name: Perform typechecks
run: pnpm typecheck
eslint:
name: TypeScript
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
with:
version: 7.x.x
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
- name: Install pnpm dependencies
run: pnpm i --frozen-lockfile
- name: Perform typechecks
run: pnpm lint
rustfmt:
name: rustfmt
runs-on: ubuntu-latest

View file

@ -1,8 +1,7 @@
module.exports = {
...require('@sd/config/eslint-react.js'),
extends: [require.resolve('@sd/config/eslint/web.js')],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json'
},
ignorePatterns: ['**/*.js', '**/*.json', 'node_modules', 'public', 'dist', 'vite.config.ts']
}
};

View file

@ -7,7 +7,7 @@
"build": "vite build",
"server": "ts-node ./server",
"server:prod": "cross-env NODE_ENV=production ts-node ./server",
"lint": "eslint src/**/*.{ts,tsx} && tsc --noEmit",
"lint": "eslint src",
"typecheck": "tsc -b"
},
"dependencies": {

View file

@ -1,5 +1,5 @@
module.exports = {
...require('@sd/config/eslint-react-native.js'),
extends: [require.resolve('@sd/config/eslint/reactNative.js')],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json'

View file

@ -10,7 +10,7 @@
"ios": "expo run:ios",
"xcode": "open ios/spacedrive.xcworkspace",
"android-studio": "open -a '/Applications/Android Studio.app' ./android",
"lint": "eslint src/**/*.{ts,tsx} && tsc --noEmit",
"lint": "eslint src",
"postinstall": "node scripts/postinstall.js",
"typecheck": "tsc -b"
},

View file

@ -21,7 +21,8 @@
"client": "pnpm --filter @sd/client -- ",
"prisma": "cd core && cargo prisma",
"codegen": "cargo test -p sd-core api::tests::test_and_export_rspc_bindings -- --exact",
"typecheck": "turbo run typecheck"
"typecheck": "turbo run typecheck",
"lint": "turbo run lint"
},
"pnpm": {
"overrides": {

View file

@ -1,5 +1,5 @@
module.exports = {
...require('@sd/config/eslint-react.js'),
extends: [require.resolve('@sd/config/eslint/web.js')],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json'

View file

@ -8,7 +8,7 @@
],
"scripts": {
"test": "jest",
"lint": "eslint src/**/*.{ts,tsx} && tsc --noEmit",
"lint": "eslint src",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"typecheck": "tsc -b",
"build": "tsc"

View file

@ -1,4 +1,5 @@
declare global {
// eslint-disable-next-line
var isDev: boolean;
}

View file

@ -1,59 +0,0 @@
module.exports = {
env: {
'react-native/react-native': true
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 12,
sourceType: 'module'
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:@typescript-eslint/recommended'
],
plugins: ['react', 'react-native'],
rules: {
'react/display-name': 'off',
'react/prop-types': 'off',
'react/no-unescaped-entities': 'off',
'react/react-in-jsx-scope': 'off',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'no-control-regex': 'off',
'no-mixed-spaces-and-tabs': ['warn', 'smart-tabs'],
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'react-native',
importNames: ['SafeAreaView'],
message: 'Import SafeAreaView from react-native-safe-area-context instead'
},
{
name: 'react-native',
importNames: ['Button'],
message: 'Import Button from ~/components instead.'
}
]
}
]
},
ignorePatterns: ['**/*.js', '**/*.json', 'node_modules', 'android', 'ios', '.expo'],
settings: {
react: {
version: 'detect'
}
}
};

View file

@ -1,8 +1,4 @@
module.exports = {
env: {
browser: true,
node: true
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
@ -16,7 +12,8 @@ module.exports = {
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:@typescript-eslint/recommended',
'prettier'
'prettier',
'turbo'
],
plugins: ['react'],
rules: {
@ -24,7 +21,7 @@ module.exports = {
'react/prop-types': 'off',
'react/no-unescaped-entities': 'off',
'react/react-in-jsx-scope': 'off',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/rules-of-hooks': 'warn',
'react-hooks/exhaustive-deps': 'warn',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
@ -32,10 +29,12 @@ module.exports = {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-empty-function': 'off',
'no-control-regex': 'off',
'no-mixed-spaces-and-tabs': ['warn', 'smart-tabs']
},
ignorePatterns: ['**/*.js', '**/*.json', 'node_modules'],
ignorePatterns: ['dist', '**/*.js', '**/*.json', 'node_modules'],
settings: {
react: {
version: 'detect'

View file

@ -0,0 +1,27 @@
module.exports = {
extends: [require.resolve('./base.js')],
env: {
'react-native/react-native': true
},
plugins: ['react-native'],
ignorePatterns: ['android', 'ios', '.expo'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'react-native',
importNames: ['SafeAreaView'],
message: 'Import SafeAreaView from react-native-safe-area-context instead'
}
// {
// name: 'react-native',
// importNames: ['Button'],
// message: 'Import Button from ~/components instead.'
// }
]
}
]
}
};

View file

@ -0,0 +1,8 @@
module.exports = {
extends: [require.resolve('./base.js')],
ignorePatterns: ['public', 'vite.config.ts'],
env: {
browser: true,
node: true
}
};

3
packages/config/index.js Normal file
View file

@ -0,0 +1,3 @@
module.exports = {
vite: require('./vite')
};

View file

@ -3,16 +3,18 @@
"version": "0.0.0",
"license": "GPL-3.0-only",
"exports": {
"./vite": "./vite/index.js"
"./*": "./*",
"./vite": "./vite.js"
},
"files": [
"eslint-react.js"
],
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.39.0",
"@typescript-eslint/parser": "^5.39.0",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-turbo": "^0.0.7",
"eslint-plugin-react": "^7.31.8",
"eslint-plugin-react-hooks": "^4.6.0"
}

View file

@ -1,5 +1,5 @@
module.exports = {
...require('@sd/config/eslint-react.js'),
extends: [require.resolve('@sd/config/eslint/web.js')],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json'

View file

@ -13,7 +13,7 @@
},
"scripts": {
"icons": "./scripts/generateSvgImports.mjs",
"lint": "eslint src/**/*.{ts,tsx} && tsc --noEmit",
"lint": "eslint src",
"typecheck": "tsc -b",
"build": "tsc"
},
@ -65,6 +65,7 @@
},
"devDependencies": {
"@sd/config": "workspace:*",
"eslint-config-sd": "workspace:*",
"@types/babel-core": "^6.25.7",
"@types/byte-size": "^8.1.0",
"@types/loadable__component": "^5.13.4",

View file

@ -4,7 +4,7 @@ import { Input, useZodForm, z } from '@sd/ui/src/forms';
const schema = z.object({ path: z.string() });
interface Props extends UseDialogProps {}
type Props = UseDialogProps;
export default function AddLocationDialog(props: Props) {
const dialog = useDialog(props);

View file

@ -14,7 +14,7 @@ const schema = z.object({
filePath: z.string()
});
export interface BackupRestorationDialogProps extends UseDialogProps {}
export type BackupRestorationDialogProps = UseDialogProps;
export const BackupRestoreDialog = (props: BackupRestorationDialogProps) => {
const platform = usePlatform();

View file

@ -20,7 +20,7 @@ const schema = z.object({
hashing_algorithm: z.string()
});
interface Props extends UseDialogProps {}
type Props = UseDialogProps;
export default function CreateLibraryDialog(props: Props) {
const dialog = useDialog(props);

View file

@ -7,7 +7,7 @@ import { useZodForm, z } from '@sd/ui/src/forms';
import { getHashingAlgorithmString } from '~/screens/settings/library/KeysSetting';
import { SelectOptionKeyList } from '../key/KeyList';
interface KeyViewerDialogProps extends UseDialogProps {}
type KeyViewerDialogProps = UseDialogProps;
export const KeyUpdater = (props: {
uuid: string;

View file

@ -9,7 +9,7 @@ import { showAlertDialog } from '~/util/dialog';
import { generatePassword } from '../key/KeyMounter';
import { PasswordMeter } from '../key/PasswordMeter';
export interface MasterPasswordChangeDialogProps extends UseDialogProps {}
export type MasterPasswordChangeDialogProps = UseDialogProps;
const schema = z.object({
masterPassword: z.string(),

View file

@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { ExplorerData, rspc, useCurrentLibrary } from '@sd/client';
import { useExplorerStore } from '~/hooks/useExplorerStore';
import { Inspector } from '../explorer/Inspector';
@ -32,50 +32,50 @@ export default function Explorer(props: Props) {
}
});
return (
<>
<div className="relative">
<ExplorerContextMenu>
<div className="relative flex flex-col w-full">
<TopBar showSeparator={separateTopBar} />
const onScroll = useCallback((y: number) => {
setScrollSegments((old) => {
return {
...old,
mainList: y
};
});
}, []);
return (
<div className="relative">
<ExplorerContextMenu>
<div className="relative flex flex-col w-full">
<TopBar showSeparator={separateTopBar} />
<div className="relative flex flex-row w-full max-h-full app-background">
{props.data && (
<VirtualizedList
data={props.data.items}
context={props.data.context}
onScroll={onScroll}
/>
)}
{expStore.showInspector && (
<div className="flex min-w-[260px] max-w-[260px]">
<Inspector
onScroll={(e) => {
const y = (e.target as HTMLElement).scrollTop;
<div className="relative flex flex-row w-full max-h-full app-background">
{props.data && (
<VirtualizedList
data={props.data.items || []}
context={props.data.context}
onScroll={(y) => {
setScrollSegments((old) => {
return {
...old,
mainList: y
inspector: y
};
});
}}
key={props.data?.items[expStore.selectedRowIndex]?.id}
data={props.data?.items[expStore.selectedRowIndex]}
/>
)}
{expStore.showInspector && (
<div className="flex min-w-[260px] max-w-[260px]">
<Inspector
onScroll={(e) => {
const y = (e.target as HTMLElement).scrollTop;
setScrollSegments((old) => {
return {
...old,
inspector: y
};
});
}}
key={props.data?.items[expStore.selectedRowIndex]?.id}
data={props.data?.items[expStore.selectedRowIndex]}
/>
</div>
)}
</div>
</div>
)}
</div>
</ExplorerContextMenu>
</div>
</>
</div>
</ExplorerContextMenu>
</div>
);
}

View file

@ -1,5 +1,5 @@
import { useVirtualizer } from '@tanstack/react-virtual';
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
import { memo, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useKey, useOnWindowResize } from 'rooks';
import { ExplorerContext, ExplorerItem } from '@sd/client';
@ -17,7 +17,7 @@ interface Props {
onScroll?: (posY: number) => void;
}
export const VirtualizedList: React.FC<Props> = ({ data, context, onScroll }) => {
export const VirtualizedList = memo(({ data, context, onScroll }: Props) => {
const scrollRef = useRef<HTMLDivElement>(null);
const innerRef = useRef<HTMLDivElement>(null);
@ -56,7 +56,7 @@ export const VirtualizedList: React.FC<Props> = ({ data, context, onScroll }) =>
el.addEventListener('scroll', onElementScroll);
return () => el.removeEventListener('scroll', onElementScroll);
}, [scrollRef, onScroll]);
}, [onScroll]);
const rowVirtualizer = useVirtualizer({
count: amountOfRows,
@ -169,7 +169,7 @@ export const VirtualizedList: React.FC<Props> = ({ data, context, onScroll }) =>
</div>
</div>
);
};
});
interface WrappedItemProps {
item: ExplorerItem;
@ -179,7 +179,7 @@ interface WrappedItemProps {
}
// Wrap either list item or grid item with click logic as it is the same for both
const WrappedItem: React.FC<WrappedItemProps> = ({ item, index, isSelected, kind }) => {
const WrappedItem = memo(({ item, index, isSelected, kind }: WrappedItemProps) => {
const [_, setSearchParams] = useSearchParams();
const onDoubleClick = useCallback(() => {
@ -191,6 +191,7 @@ const WrappedItem: React.FC<WrappedItemProps> = ({ item, index, isSelected, kind
}, [isSelected, index]);
const ItemComponent = kind === 'list' ? FileRow : FileItem;
return (
<ItemComponent
data={item}
@ -200,18 +201,4 @@ const WrappedItem: React.FC<WrappedItemProps> = ({ item, index, isSelected, kind
selected={isSelected}
/>
);
// // Memorize the item so that it doesn't get re-rendered when the selection changes
// return useMemo(() => {
// const ItemComponent = kind === 'list' ? FileRow : FileItem;
// return (
// <ItemComponent
// data={item}
// index={index}
// onClick={onClick}
// onDoubleClick={onDoubleClick}
// selected={isSelected}
// />
// );
// }, [item, index, isSelected]);
};
});

View file

@ -22,7 +22,7 @@ function LibraryListItem(props: { library: LibraryConfigWrapped; current: boolea
<p className="mt-0.5 text-xs text-ink-dull">{props.library.uuid}</p>
</div>
<div className="flex flex-row items-center space-x-2">
<Button className="!p-1.5" onClick={() => {}} variant="gray">
<Button className="!p-1.5" variant="gray">
<Tooltip label="TODO">
<Database className="w-4 h-4" />
</Tooltip>

View file

@ -9,6 +9,7 @@
"types": ["vite-plugin-svgr/client", "vite/client"]
},
"include": ["src"],
"exclude": ["dist"],
"references": [
{
"path": "../ui"

7
packages/ui/.eslintrc.js Normal file
View file

@ -0,0 +1,7 @@
module.exports = {
extends: [require.resolve('@sd/config/eslint/web.js')],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json'
}
};

View file

@ -16,6 +16,7 @@
"scripts": {
"storybook": "start-storybook -p 6006",
"storybook:build": "build-storybook",
"lint": "eslint src",
"typecheck": "tsc -b",
"build": "tsc"
},

View file

@ -75,7 +75,7 @@ function Remover({ id }: { id: number }) {
() => () => {
dialogManager.remove(id);
},
[]
[id]
);
return null;

View file

@ -39,7 +39,7 @@ type DropdownItemProps =
VariantProps<typeof itemStyles>;
export const Item = ({ to, className, icon: Icon, children, ...props }: DropdownItemProps) => {
let content = (
const content = (
<>
{Icon && <Icon weight="bold" className={itemIconStyles(props)} />}
<span className="text-left">{children}</span>

View file

@ -17,7 +17,7 @@ type TailwindFactory = {
<T>(c: T): ClassnameFactory<T>;
};
export const tw = new Proxy((() => {}) as unknown as TailwindFactory, {
export const tw = new Proxy({} as unknown as TailwindFactory, {
get: (_, property: string) => twFactory(property),
apply: (_, __, [el]: [React.ReactElement]) => twFactory(el)
});

View file

@ -388,10 +388,11 @@ importers:
packages/config:
specifiers:
'@typescript-eslint/eslint-plugin': ^5.39.0
'@typescript-eslint/parser': ^5.39.0
'@typescript-eslint/eslint-plugin': ^5.48.2
'@typescript-eslint/parser': ^5.48.2
eslint: ^8.24.0
eslint-config-prettier: ^8.5.0
eslint-config-turbo: ^0.0.7
eslint-plugin-react: ^7.31.8
eslint-plugin-react-hooks: ^4.6.0
devDependencies:
@ -399,6 +400,7 @@ importers:
'@typescript-eslint/parser': 5.48.2_eslint@8.32.0
eslint: 8.32.0
eslint-config-prettier: 8.6.0_eslint@8.32.0
eslint-config-turbo: 0.0.7_eslint@8.32.0
eslint-plugin-react: 7.32.1_eslint@8.32.0
eslint-plugin-react-hooks: 4.6.0_eslint@8.32.0
@ -440,6 +442,7 @@ importers:
clsx: ^1.2.1
crypto-random-string: ^5.0.0
dayjs: ^1.11.5
eslint-config-sd: workspace:*
phosphor-react: ^1.4.1
prettier: ^2.7.1
react: ^18.2.0
@ -489,6 +492,7 @@ importers:
clsx: 1.2.1
crypto-random-string: 5.0.0
dayjs: 1.11.7
eslint-config-sd: link:../eslint
phosphor-react: 1.4.1_react@18.2.0
react: 18.2.0
react-colorful: 5.6.1_biqbaboplfbrettd7655fr4n2y
@ -8262,7 +8266,7 @@ packages:
'@babel/plugin-transform-react-jsx-source': 7.19.6_@babel+core@7.20.12
magic-string: 0.26.7
react-refresh: 0.14.0
vite: 4.0.4_sass@1.57.1
vite: 4.0.4_@types+node@18.11.18
transitivePeerDependencies:
- supports-color
@ -11607,6 +11611,15 @@ packages:
eslint: 8.32.0
dev: true
/eslint-config-turbo/0.0.7_eslint@8.32.0:
resolution: {integrity: sha512-WbrGlyfs94rOXrhombi1wjIAYGdV2iosgJRndOZtmDQeq5GLTzYmBUCJQZWtLBEBUPCj96RxZ2OL7Cn+xv/Azg==}
peerDependencies:
eslint: '>6.6.0'
dependencies:
eslint: 8.32.0
eslint-plugin-turbo: 0.0.7_eslint@8.32.0
dev: true
/eslint-plugin-react-hooks/4.6.0_eslint@8.32.0:
resolution: {integrity: sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==}
engines: {node: '>=10'}
@ -11655,6 +11668,14 @@ packages:
string.prototype.matchall: 4.0.8
dev: true
/eslint-plugin-turbo/0.0.7_eslint@8.32.0:
resolution: {integrity: sha512-iajOH8eD4jha3duztGVBD1BEmvNrQBaA/y3HFHf91vMDRYRwH7BpHSDFtxydDpk5ghlhRxG299SFxz7D6z4MBQ==}
peerDependencies:
eslint: '>6.6.0'
dependencies:
eslint: 8.32.0
dev: true
/eslint-scope/4.0.3:
resolution: {integrity: sha512-p7VutNr1O/QrxysMo3E45FjYDTeXBy0iTltPFNSqKAIfjDSXC+4dj+qfyuD8bfAXrW/y6lW3O76VaYNPKfpKrg==}
engines: {node: '>=4.0.0'}
@ -20740,7 +20761,7 @@ packages:
dependencies:
'@rollup/pluginutils': 5.0.2
'@svgr/core': 6.5.1
vite: 4.0.4_sass@1.57.1
vite: 4.0.4_@types+node@18.11.18
transitivePeerDependencies:
- rollup
- supports-color
@ -20836,7 +20857,6 @@ packages:
rollup: 3.10.0
optionalDependencies:
fsevents: 2.3.2
dev: true
/vite/4.0.4_ovmyjmuuyckt3r3gpaexj2onji:
resolution: {integrity: sha512-xevPU7M8FU0i/80DMR+YhgrzR5KS2ORy1B4xcX/cXLsvnUWvfHuqMmVU6N0YiJ4JWGRJJsLCgjEzKjG9/GKoSw==}
@ -20904,6 +20924,7 @@ packages:
sass: 1.57.1
optionalDependencies:
fsevents: 2.3.2
dev: true
/vlq/1.0.1:
resolution: {integrity: sha512-gQpnTgkubC6hQgdIcRdYGDSDc+SaujOdyesZQMv6JlfQee/9Mp0Qhnys6WxDWvQnL5WZdT7o2Ul187aSt0Rq+w==}