Skip to content

Commit b71d105

Browse files
authored
fix(lint): Fix lint issues (#300)
* fix(lint): fix lint issues and refactor * Remove unused * Remove unused * set no unused vars lint rule * Add linter and prettier to test steps * prettify * Separate testing jobs * Revert "Separate testing jobs" This reverts commit fa5d29e.
1 parent 77200d1 commit b71d105

Some content is hidden

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

58 files changed

+310
-447
lines changed

.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"react/jsx-fragments": 0,
3838
"react/no-unused-prop-types": 0,
3939
"import/export": 0,
40-
"no-unused-vars": "off",
40+
"no-unused-vars": "error",
4141
"@typescript-eslint/no-unused-vars": "off",
4242
"@typescript-eslint/no-use-before-define": "off",
4343
"react/jsx-props-no-spreading": 0,

.github/workflows/uit-tests.yml

+9
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ jobs:
1515
node-version: '14.x'
1616
- name: Install dependencies
1717
run: yarn
18+
19+
- name: Run linter
20+
run: yarn run test:lint
21+
22+
- name: Run formatter
23+
run: yarn run test:prettier
24+
1825
- name: Install Playwright
1926
run: npx playwright install --with-deps
27+
2028
- name: Build Storybook
2129
run: yarn build-storybook --quiet
30+
2231
- name: Serve Storybook and run tests
2332
run: |
2433
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
"start": "microbundle watch --no-compress --format modern,cjs --jsx React.createElement --jsxFragment React.Fragment",
1919
"prepare": "run-s build",
2020
"prepack": "run-s build",
21-
"lint": "eslint --ext .ts,.tsx ./",
22-
"lint:fix": "yarn lint --fix",
21+
"test:lint": "eslint --ext .ts,.tsx ./",
22+
"lint": "yarn lint --fix",
23+
"test:prettier": "prettier --check ./src",
24+
"prettier": "prettier --write ./src",
2325
"test": "run-s test:unit test:lint test:build",
2426
"test:build": "run-s build",
2527
"predeploy": "yarn build-storybook",
@@ -124,4 +126,4 @@
124126
"path": "./node_modules/cz-conventional-changelog"
125127
}
126128
}
127-
}
129+
}

src/components/code/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const Code: FC<CodeProps> = ({
5858
* if we need deep merging we may use lodash merge function instead
5959
*/
6060
popupProps={{ ...defaultPopupProps, ...popupProps }}
61+
// eslint-disable-next-line react/no-unstable-nested-components
6162
NormalComponent={() => (
6263
<CodeSnippet
6364
content={content}
@@ -72,6 +73,7 @@ const Code: FC<CodeProps> = ({
7273
{...props}
7374
/>
7475
)}
76+
// eslint-disable-next-line react/no-unstable-nested-components
7577
BriefComponent={() => (
7678
<CodeSnippet
7779
content={content}

src/components/collapse/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const Collapse: FC<CollapseProps> = ({
4646
if (isOpen !== isOpenProps) {
4747
setOpen(isOpenProps);
4848
}
49+
// eslint-disable-next-line react-hooks/exhaustive-deps
4950
}, [isOpenProps]);
5051

5152
return (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React, { FC } from 'react';
2+
import useOnClickOutside from '../../utils/useClickOutside';
3+
import StickyPortal, { CONTENT_ID } from '../sticky-portal/StickyPortal';
4+
5+
interface DropdownWrapperProps {
6+
children: any;
7+
containerRef: any;
8+
appendToBody: any;
9+
onClickOutside: any;
10+
}
11+
const DropdownWrapper: FC<DropdownWrapperProps> = ({
12+
children,
13+
containerRef,
14+
appendToBody,
15+
onClickOutside,
16+
}) => {
17+
useOnClickOutside<HTMLDivElement>(
18+
onClickOutside,
19+
[containerRef],
20+
[CONTENT_ID],
21+
);
22+
23+
return appendToBody ? (
24+
<StickyPortal refEl={containerRef?.current} handleClose={onClickOutside}>
25+
{children}
26+
</StickyPortal>
27+
) : (
28+
children
29+
);
30+
};
31+
32+
export default DropdownWrapper;

src/components/dropdown/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { FC, useRef } from 'react';
2+
import { Flex } from 'rebass';
23

34
// Components
45
import ListItem from '../list/item';
@@ -9,7 +10,6 @@ import useOnClickOutside from '../../utils/useClickOutside';
910
import { DropdownItem } from './types';
1011
import { GetIcon } from '../icon';
1112
import Spinner from '../spinner';
12-
import { Flex } from 'rebass';
1313
import Tooltip from '../tooltip';
1414
import TooltipPositions from '../tooltip/positions';
1515

src/components/editableSelect/EditableSelectContainer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const EditableSelectContainer: FC<EditableSelectContainerProps> = forwardRef(
7070
if (counterRef.current < 0 && value.length > 0) {
7171
onChange(value.slice(0, -1));
7272
}
73-
}, [search, value, counterRef]);
73+
}, [search.length, value, onChange]);
7474

7575
useEffect(() => {
7676
counterRef.current = 0;

src/components/editableSelect/EditableSelectDropdown.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import ListItem from '../list/item';
55

66
import Labeling from '../typography/labeling';
77
import List from '../list/container';
8-
import useArrowsSelect from '../select/useArrowsSelect';
98
import { listStyles, messageStyles } from './editableSelect.styles';
109
import { EditableSelectTypes } from './types';
10+
import useArrowsSelect from '../select2/useArrowsSelect';
1111

1212
export interface EditableSelectDropdownProps {
1313
value: string[];
@@ -40,21 +40,21 @@ const EditableSelectDropdown: FC<EditableSelectDropdownProps> = ({
4040
(option: string) => () => {
4141
if (option) onChange([option]);
4242
},
43-
[value, onChange],
43+
[onChange],
4444
);
4545

4646
const fullOptions = useMemo(() => {
4747
if (type !== 'editable') return options;
4848
return search === '' || options.includes(search) || value.includes(search)
4949
? options
5050
: [...options, search];
51-
}, [search, options]);
51+
}, [type, options, search, value]);
5252

5353
const message = useMemo(() => {
5454
if (isMulti && value.includes(search)) return 'value already selected';
5555
if (fullOptions.length === 0) return 'no options available';
5656
return null;
57-
}, [value, search, fullOptions]);
57+
}, [isMulti, value, search, fullOptions.length]);
5858

5959
const { activeIndex } = useArrowsSelect(fullOptions, (val: string) => {
6060
handleClick(val)();

src/components/editableSelect/index.tsx

+11-27
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import React, {
77
useState,
88
} from 'react';
99
import useDropdown from '../../utils/useDropdown';
10-
import useOnClickOutside from '../../utils/useClickOutside';
1110
import { Intents } from '../intents';
1211
import Label, { LabelProps } from '../label';
1312
import EditableSelectContainer from './EditableSelectContainer';
1413
import EditableSelectDropdown from './EditableSelectDropdown';
1514
import EditableSelectInfo from './EditableSelectInfo';
1615
import { EditableSelectTypes, ChipsVariants } from './types';
17-
import StickyPortal, { CONTENT_ID } from '../sticky-portal/StickyPortal';
16+
import DropdownWrapper from '../dropdown-wrapper/DropdownWrapper';
1817

1918
export interface EditableSelectProps
2019
extends Omit<LabelProps, 'onChange' | 'children'> {
@@ -64,12 +63,6 @@ const EditableSelect: FC<EditableSelectProps> = ({
6463

6564
const [isOpen, handleToggle, handleClickOutside] = useDropdown(false);
6665

67-
useOnClickOutside<HTMLDivElement>(
68-
handleClickOutside,
69-
[containerRef],
70-
[CONTENT_ID],
71-
);
72-
7366
const unselectedOpts = useMemo(
7467
() => options.filter((opt) => !value.includes(opt)),
7568
[options, value],
@@ -100,38 +93,25 @@ const EditableSelect: FC<EditableSelectProps> = ({
10093

10194
useEffect(() => {
10295
// Reopen dropdrown when typing.
103-
if (!isOpen && search !== '') {
104-
if (isMulti || search !== value[0]) handleToggle();
96+
if (!isOpen && search !== '' && (isMulti || search !== value[0])) {
97+
handleToggle();
10598
}
99+
// eslint-disable-next-line react-hooks/exhaustive-deps
106100
}, [search]);
107101

108102
const dropdrownWidth = useCallback(() => {
109103
if (containerRef.current) {
110104
return `${containerRef.current.offsetWidth - 2}px`;
111105
}
112106
return 'auto';
113-
}, [containerRef.current?.offsetWidth]);
107+
}, []);
114108

115109
const dropdrownPosition = useCallback(() => {
116110
if (containerRef.current) {
117111
return containerRef.current.offsetHeight + 1;
118112
}
119113
return 33;
120-
}, [containerRef.current?.offsetHeight]);
121-
122-
const DropdownWrapper: FC<{ children: any; refEl: any }> = ({
123-
children,
124-
refEl,
125-
// eslint-disable-next-line arrow-body-style
126-
}) => {
127-
return appendToBody ? (
128-
<StickyPortal refEl={refEl} handleClose={handleClickOutside}>
129-
{children}
130-
</StickyPortal>
131-
) : (
132-
children
133-
);
134-
};
114+
}, []);
135115

136116
return (
137117
<Label
@@ -161,7 +141,11 @@ const EditableSelect: FC<EditableSelectProps> = ({
161141
variant={disabled ? 'disabled' : (variant as ChipsVariants)}
162142
>
163143
{isOpen && (
164-
<DropdownWrapper refEl={containerRef?.current || undefined}>
144+
<DropdownWrapper
145+
containerRef={containerRef}
146+
appendToBody={appendToBody}
147+
onClickOutside={handleClickOutside}
148+
>
165149
<EditableSelectDropdown
166150
type={type}
167151
value={value}

src/components/embedded-tabs/Tab.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ export interface Props {
1111
disabled?: boolean;
1212
}
1313

14-
const getStyles = ({ active, disabled }: Props) =>
14+
const getStyles = ({ active, disabled }: Pick<Props, 'active' | 'disabled'>) =>
1515
({
1616
...S.tab,
1717
...(active ? S.activeTab : {}),
1818
...(disabled ? S.disabledTab : {}),
1919
} as SxStyleProp);
2020

21-
const Tab: FC<Props> = (props) => {
21+
const Tab: FC<Props> = ({ title, ...props }) => {
2222
const propagatedProps = R.pick(['disabled', 'onClick'], props);
2323

2424
return (
2525
<Box sx={getStyles(props)} {...propagatedProps}>
26-
<Label pb="1px">{props.title}</Label>
26+
<Label pb="1px">{title}</Label>
2727
</Box>
2828
);
2929
};

src/components/embedded-tabs/embedded-tabs.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import EmbeddedTabs, {
77
ControlledEmbeddedTabsProps,
88
} from '.';
99
import { Button } from '../button';
10-
import Subtitle from '../typography/subtitle';
1110

1211
export default {
1312
title: 'Quartz/EmbeddedTabs',
@@ -32,6 +31,7 @@ const tabs = [
3231
];
3332

3433
export const Uncontrolled: Story<EmbeddedTabsProps> = (props) => {
34+
// eslint-disable-next-line react/destructuring-assignment
3535
const [activeTab, setActiveTab] = useState(props.initialTab ?? 0);
3636

3737
return (

src/components/file-button/index.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { fileButton, inputBox, inputButton } from './file-button.styles';
77
export interface QuartzFileButtonProps extends Omit<ButtonProps, 'css'> {
88
children: React.ReactNode | string;
99
modeNFiles?: boolean;
10-
intent?: 'secondary';
1110
href?: string;
1211
name?: string;
1312
currentRef?: any;
@@ -18,7 +17,6 @@ export interface QuartzFileButtonProps extends Omit<ButtonProps, 'css'> {
1817
}
1918

2019
const UploadButton: FC<QuartzFileButtonProps> = ({
21-
intent = 'secondary',
2220
children,
2321
href,
2422
modeNFiles,

src/components/file-button/project-file-button.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ export interface QuartzFileButtonProps extends Omit<ButtonProps, 'css'> {
99
children: React.ReactNode;
1010
intent?: 'secondary';
1111
href?: string;
12-
mode?: string;
1312
}
1413

1514
const FileButton: FC<QuartzFileButtonProps> = ({
1615
intent = 'secondary',
1716
children,
18-
mode = 'oneFile',
1917
href,
2018
...props
2119
}: QuartzFileButtonProps) => {

src/components/file-system-explorer/file-item-explorer/styles.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const fileExplorerStyle = (
1010
({
1111
position: 'relative',
1212

13+
// eslint-disable-next-line no-nested-ternary
1314
backgroundColor: !isActive ? 'white' : selected ? 'grayShade2' : 'white',
1415
width: '222px',
1516

src/components/file-system-explorer/footer/footer.stories.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from 'react';
22
import { Story, Meta } from '@storybook/react/types-6-0';
3-
import FooterFileExplorer from './index';
43

5-
import FileExplorerFooter, { Props } from './index';
4+
import FooterFileExplorer, { Props } from './index';
65

76
export default {
87
title: 'Quartz/FileSystemExplorer/Footer',
9-
component: FileExplorerFooter,
8+
component: FooterFileExplorer,
109
args: {
1110
value: 'pick a file',
1211
onClose: (key: any) => {

src/components/flex/Flex.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Flex as RebassFlex, FlexProps } from 'rebass';
44
export interface Props extends Omit<FlexProps, 'css'> {}
55

66
export const Flex: FC<Props> = forwardRef(({ children, ...rest }, ref) => (
7-
<RebassFlex ref={ref} {...rest}>
7+
<RebassFlex ref={ref} {...rest}>
88
{children}
99
</RebassFlex>
1010
));

src/components/header/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const Header: FC<HeaderProps> = ({
4040
<Box sx={rightSectionStyles}>
4141
{/* Actions */}
4242
<Box>
43-
{actions?.map((action, index) => (
44-
<span key={index}>{action}</span>
43+
{actions?.map((action) => (
44+
<span>{action}</span>
4545
))}
4646
</Box>
4747

0 commit comments

Comments
 (0)