Skip to content

Commit

Permalink
fix: fix prettier not working correctly with lint --fix ( fix #410)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjose committed Dec 25, 2024
1 parent c063b12 commit 89a8af0
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
module.exports = {
extends: ['expo', 'plugin:tailwindcss/recommended', 'prettier'],
plugins: [
'prettier',
'unicorn',
'@typescript-eslint',
'unused-imports',
Expand All @@ -14,6 +15,7 @@ module.exports = {
project: './tsconfig.json',
},
rules: {
'prettier/prettier': 'warn',
'unicorn/filename-case': [
'error',
{
Expand Down
8 changes: 6 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
/** @type {import('prettier').Config} */
const config = {
singleQuote: true,
endOfLine: 'auto',
};
trailingComma: 'es5',
};

module.exports = config;
2 changes: 1 addition & 1 deletion app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
'expo-localization',
'expo-router',
['app-icon-badge', appIconBadgeConfig],
["react-native-edge-to-edge"]
['react-native-edge-to-edge'],
],
extra: {
...ClientEnv,
Expand Down
2 changes: 1 addition & 1 deletion src/app/(app)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Feed() {
const { data, isPending, isError } = usePosts();
const renderItem = React.useCallback(
({ item }: { item: Post }) => <Card {...item} />,
[],
[]
);

if (isError) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/feed/add-post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function AddPost() {
onError: () => {
showErrorMessage('Error adding post');
},
},
}
);
};
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/login-form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('LoginForm Form ', () => {
email: 'youssef@gmail.com',
password: 'password',
},
expect.objectContaining({}),
expect.objectContaining({})
);
});
});
6 changes: 3 additions & 3 deletions src/components/settings/language-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ export const LanguageItem = () => {
setLanguage(option.value as Language);
modal.dismiss();
},
[setLanguage, modal],
[setLanguage, modal]
);

const langs = React.useMemo(
() => [
{ label: translate('settings.english'), value: 'en' },
{ label: translate('settings.arabic'), value: 'ar' },
],
[],
[]
);

const selectedLanguage = React.useMemo(
() => langs.find((lang) => lang.value === language),
[language, langs],
[language, langs]
);

return (
Expand Down
6 changes: 3 additions & 3 deletions src/components/settings/theme-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const ThemeItem = () => {
setSelectedTheme(option.value as ColorSchemeType);
modal.dismiss();
},
[setSelectedTheme, modal],
[setSelectedTheme, modal]
);

const themes = React.useMemo(
Expand All @@ -25,12 +25,12 @@ export const ThemeItem = () => {
{ label: `${translate('settings.theme.light')} 🌞`, value: 'light' },
{ label: `${translate('settings.theme.system')} ⚙️`, value: 'system' },
],
[],
[]
);

const theme = React.useMemo(
() => themes.find((t) => t.value === selectedTheme),
[selectedTheme, themes],
[selectedTheme, themes]
);

return (
Expand Down
8 changes: 4 additions & 4 deletions src/components/ui/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Button component ', () => {
render(
<Button testID="button">
<Text> Custom child </Text>
</Button>,
</Button>
);
expect(screen.getByText('Custom child')).toBeOnTheScreen();
});
Expand All @@ -34,7 +34,7 @@ describe('Button component ', () => {
it('should call onClick handler when clicked', async () => {
const onClick = jest.fn();
const { user } = setup(
<Button testID="button" label="Click the button" onPress={onClick} />,
<Button testID="button" label="Click the button" onPress={onClick} />
);
expect(screen.getByTestId('button')).toBeOnTheScreen();
await user.press(screen.getByTestId('button'));
Expand All @@ -48,7 +48,7 @@ describe('Button component ', () => {
loading={true}
label="Click the button"
onPress={onClick}
/>,
/>
);
expect(screen.getByTestId('button')).toBeOnTheScreen();
expect(screen.getByTestId('button-activity-indicator')).toBeOnTheScreen();
Expand All @@ -69,7 +69,7 @@ describe('Button component ', () => {
disabled={true}
onPress={onClick}
variant="secondary"
/>,
/>
);
expect(screen.getByTestId('button')).toBeOnTheScreen();
await user.press(screen.getByTestId('button'));
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ export const Button = React.forwardRef<View, Props>(
textClassName = '',
...props
},
ref,
ref
) => {
const styles = React.useMemo(
() => button({ variant, disabled, size }),
[variant, disabled, size],
[variant, disabled, size]
);

return (
Expand Down Expand Up @@ -142,5 +142,5 @@ export const Button = React.forwardRef<View, Props>(
)}
</Pressable>
);
},
}
);
40 changes: 20 additions & 20 deletions src/components/ui/checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ describe('Checkbox, Radio & Switch components ', () => {
onChange={mockOnChange}
accessibilityLabel="agree"
accessibilityHint="toggle Agree"
/>,
/>
);
expect(screen.getByTestId('checkbox')).toBeOnTheScreen();
expect(screen.queryByTestId('checkbox-label')).not.toBeOnTheScreen();
expect(screen.getByTestId('checkbox')).toBeEnabled();

expect(screen.getByTestId('checkbox')).not.toBeChecked();
expect(screen.getByTestId('checkbox').props.accessibilityRole).toBe(
'checkbox',
'checkbox'
);
expect(screen.getByTestId('checkbox').props.accessibilityLabel).toBe(
'agree',
'agree'
);

await user.press(screen.getByTestId('checkbox'));
Expand All @@ -46,7 +46,7 @@ describe('Checkbox, Radio & Switch components ', () => {
onChange={mockOnChange}
accessibilityLabel="agree"
accessibilityHint="toggle Agree"
/>,
/>
);
expect(screen.getByTestId('checkbox')).toBeOnTheScreen();
expect(screen.getByTestId('checkbox')).toBeDisabled();
Expand All @@ -63,22 +63,22 @@ describe('Checkbox, Radio & Switch components ', () => {
accessibilityLabel="agree"
accessibilityHint="toggle Agree"
label="I agree to terms and conditions"
/>,
/>
);
expect(screen.getByTestId('checkbox')).toBeOnTheScreen();
expect(screen.getByTestId('checkbox-label')).toBeOnTheScreen();
expect(
screen.getByTestId('checkbox').props.accessibilityState.checked,
screen.getByTestId('checkbox').props.accessibilityState.checked
).toBe(false);
expect(screen.getByTestId('checkbox').props.accessibilityRole).toBe(
'checkbox',
'checkbox'
);

expect(screen.getByTestId('checkbox').props.accessibilityLabel).toBe(
'agree',
'agree'
);
expect(screen.getByTestId('checkbox-label')).toHaveTextContent(
'I agree to terms and conditions',
'I agree to terms and conditions'
);
await user.press(screen.getByTestId('checkbox'));
expect(mockOnChange).toHaveBeenCalledTimes(0);
Expand All @@ -92,7 +92,7 @@ describe('Checkbox, Radio & Switch components ', () => {
onChange={mockOnChange}
accessibilityLabel="agree"
accessibilityHint="toggle Agree"
/>,
/>
);
expect(screen.getByTestId('radio')).toBeOnTheScreen();
expect(screen.queryByTestId('radio-label')).not.toBeOnTheScreen();
Expand All @@ -114,16 +114,16 @@ describe('Checkbox, Radio & Switch components ', () => {
accessibilityLabel="agree"
label="I agree to terms and conditions"
accessibilityHint="toggle Agree"
/>,
/>
);
expect(screen.getByTestId('radio')).toBeOnTheScreen();
expect(screen.getByTestId('radio-label')).toBeOnTheScreen();
expect(screen.getByTestId('radio-label')).toHaveTextContent(
'I agree to terms and conditions',
'I agree to terms and conditions'
);

expect(screen.getByTestId('radio').props.accessibilityState.checked).toBe(
false,
false
);
expect(screen.getByTestId('radio').props.accessibilityRole).toBe('radio');
expect(screen.getByTestId('radio').props.accessibilityLabel).toBe('agree');
Expand All @@ -141,7 +141,7 @@ describe('Checkbox, Radio & Switch components ', () => {
onChange={mockOnChange}
accessibilityLabel="agree"
accessibilityHint="toggle Agree"
/>,
/>
);
expect(screen.getByTestId('radio')).toBeOnTheScreen();
expect(screen.getByTestId('radio')).toBeDisabled();
Expand All @@ -157,13 +157,13 @@ describe('Checkbox, Radio & Switch components ', () => {
onChange={mockOnChange}
accessibilityLabel="agree"
accessibilityHint="toggle Agree"
/>,
/>
);
expect(screen.getByTestId('switch')).toBeOnTheScreen();
expect(screen.queryByTestId('switch-label')).not.toBeOnTheScreen();
expect(screen.getByTestId('switch')).toBeEnabled();
expect(screen.getByTestId('switch').props.accessibilityState.checked).toBe(
false,
false
);
expect(screen.getByTestId('switch').props.accessibilityRole).toBe('switch');
expect(screen.getByTestId('switch').props.accessibilityLabel).toBe('agree');
Expand All @@ -181,15 +181,15 @@ describe('Checkbox, Radio & Switch components ', () => {
accessibilityLabel="agree"
label="I agree to terms and conditions"
accessibilityHint="toggle Agree"
/>,
/>
);
expect(screen.getByTestId('switch')).toBeOnTheScreen();
expect(screen.getByTestId('switch-label')).toBeOnTheScreen();
expect(screen.getByTestId('switch-label')).toHaveTextContent(
'I agree to terms and conditions',
'I agree to terms and conditions'
);
expect(screen.getByTestId('switch').props.accessibilityState.checked).toBe(
false,
false
);
expect(screen.getByTestId('switch').props.accessibilityRole).toBe('switch');
expect(screen.getByTestId('switch').props.accessibilityLabel).toBe('agree');
Expand All @@ -207,7 +207,7 @@ describe('Checkbox, Radio & Switch components ', () => {
onChange={mockOnChange}
accessibilityLabel="agree"
accessibilityHint="toggle Agree"
/>,
/>
);
expect(screen.getByTestId('switch')).toBeOnTheScreen();
await user.press(screen.getByTestId('switch'));
Expand Down
12 changes: 6 additions & 6 deletions src/components/ui/input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Input component ', () => {
render(<Input testID="input" placeholder="Enter your username" />);
expect(screen.getByTestId('input')).toBeOnTheScreen();
expect(
screen.getByPlaceholderText('Enter your username'),
screen.getByPlaceholderText('Enter your username')
).toBeOnTheScreen();
});

Expand All @@ -49,7 +49,7 @@ describe('Input component ', () => {
expect(screen.getByTestId('input')).toBeOnTheScreen();

expect(screen.getByTestId('input-error')).toHaveTextContent(
'This is an error message',
'This is an error message'
);
});
it('should render the label, error message & placeholder correctly ', () => {
Expand All @@ -59,17 +59,17 @@ describe('Input component ', () => {
label="Username"
placeholder="Enter your username"
error="This is an error message"
/>,
/>
);
expect(screen.getByTestId('input')).toBeOnTheScreen();

expect(screen.getByTestId('input-label')).toHaveTextContent('Username');
expect(screen.getByTestId('input-error')).toBeOnTheScreen();
expect(screen.getByTestId('input-error')).toHaveTextContent(
'This is an error message',
'This is an error message'
);
expect(
screen.getByPlaceholderText('Enter your username'),
screen.getByPlaceholderText('Enter your username')
).toBeOnTheScreen();
});

Expand All @@ -93,7 +93,7 @@ describe('Input component ', () => {
it('should trigger onChangeText event correctly', async () => {
const onChangeText = jest.fn();
const { user } = setup(
<Input testID="input" onChangeText={onChangeText} />,
<Input testID="input" onChangeText={onChangeText} />
);

const input = screen.getByTestId('input');
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const Input = React.forwardRef<NTextInput, NInputProps>((props, ref) => {
focused: isFocussed,
disabled: Boolean(props.disabled),
}),
[error, isFocussed, props.disabled],
[error, isFocussed, props.disabled]
);

return (
Expand Down Expand Up @@ -125,7 +125,7 @@ export const Input = React.forwardRef<NTextInput, NInputProps>((props, ref) => {

// only used with react-hook-form
export function ControlledInput<T extends FieldValues>(
props: ControlledInputProps<T>,
props: ControlledInputProps<T>
) {
const { name, control, rules, ...inputProps } = props;

Expand Down
Loading

0 comments on commit 89a8af0

Please sign in to comment.