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: add prettier #89

Merged
merged 1 commit into from
Dec 19, 2023
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
5 changes: 2 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = {
'eslint:recommended',
'plugin:react/recommended',
'plugin:jest/recommended',
'plugin:storybook/recommended'
'plugin:storybook/recommended',
'prettier'
],
settings: {
'import/resolver': {
Expand All @@ -35,7 +36,6 @@ module.exports = {
localStorage: true
},
rules: {
indent: ['error', 2],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
Expand All @@ -44,7 +44,6 @@ module.exports = {
'object-curly-spacing': ['error', 'never'],
'eol-last': ['error'],
'comma-dangle': ['error', 'never'],
'max-len': ['error', 125],
'react/jsx-filename-extension': [1, {
extensions: ['.js', '.jsx']
}],
Expand Down
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"arrowParens": "avoid",
"bracketSpacing": false,
"trailingComma": "none",
"singleQuote": true,
"tabWidth": 2,
"printWidth": 125
}
84 changes: 74 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"test:coverage": "jest --config=jest.config.json --coverage",
"test:watch": "jest --config=jest.config.json --watch",
"prepare": "husky install",
"validate": "npm run lint && npm run test",
"prettier": "prettier src/ --write",
"validate": "npm run prettier && npm run lint && npm run test",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build -o docs-build"
},
Expand Down Expand Up @@ -56,6 +57,7 @@
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"eslint": "^8.41.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-webpack": "^0.13.2",
"eslint-plugin-import": "^2.27.5",
Expand All @@ -68,6 +70,7 @@
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-watch-typeahead": "^2.2.2",
"prettier": "^3.1.1",
"storybook": "^7.0.26"
},
"dependencies": {
Expand Down
8 changes: 3 additions & 5 deletions src/components/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ const handleChecked = (e, options, selectedOption, {name, value}, setFieldValue)
setFieldValue(name, values);
};

function Checkbox({
options, label, field, form, disabled, warnings
}) {
function Checkbox({options, label, field, form, disabled, warnings}) {
return (
<Stack direction="column" sx={{width: '100%'}}>
<InputLabel warnings={warnings} form={form} field={field} label={label} disabled={disabled} />
Expand All @@ -42,7 +40,7 @@ function Checkbox({
<FormControlLabel
key={option.value}
data-testid={`checkbox-${index}`}
control={(
control={
<MuiCheckbox
data-testid={`option-${index}`}
checked={field.value.includes(option.value)}
Expand All @@ -51,7 +49,7 @@ function Checkbox({
form.setFieldTouched(field.name, false);
}}
/>
)}
}
label={option.label}
disabled={disabled}
/>
Expand Down
16 changes: 6 additions & 10 deletions src/components/Checkbox/Checkbox.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,12 @@ function Template(args) {
const warnings = withWarnings ? getWarnings(warningSchema, values) || {} : {};
return (
<>
<Field
component={Checkbox}
{...props}
warnings={warnings}
/>
{
withErrors
? <Button onClick={submitForm} variant="contained">Click to validate form</Button>
: null
}
<Field component={Checkbox} {...props} warnings={warnings} />
{withErrors ? (
<Button onClick={submitForm} variant="contained">
Click to validate form
</Button>
) : null}
</>
);
}}
Expand Down
4 changes: 1 addition & 3 deletions src/components/Checkbox/Checkbox.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
fireEvent, getByTestId, getByText, queryByText
} from '@testing-library/react';
import {fireEvent, getByTestId, getByText, queryByText} from '@testing-library/react';

import Checkbox from './Checkbox';

Expand Down
4 changes: 1 addition & 3 deletions src/components/Currency/Currency.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ function Template(args) {
>
{({values}) => {
const warnings = withWarnings ? getWarnings(warningSchema, values) || {} : {};
return (
<Field component={Currency} {...props} warnings={warnings} />
);
return <Field component={Currency} {...props} warnings={warnings} />;
}}
</Formik>
);
Expand Down
4 changes: 1 addition & 3 deletions src/components/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import InputLabel from '../InputLabel';
import TextField from '../TextField';
import DateTimePickerSelector from './DateTimePickerSelector';

function DatePicker({
metadata: {dateType}, field, label, form, warnings, disabled, ...props
}) {
function DatePicker({metadata: {dateType}, field, label, form, warnings, disabled, ...props}) {
const isRange = [dateTypes.RANGE_WITHOUT_HOUR, dateTypes.RANGE_WITH_HOUR].includes(dateType);
return (
<LocalizationProvider dateAdapter={AdapterDateFns} adapterLocale={es}>
Expand Down
26 changes: 8 additions & 18 deletions src/components/DatePicker/DatePicker.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,20 @@ export default {
};

function Template(args) {
const {
withErrors, withWarnings, initialValues, section, ...props
} = args;
const {withErrors, withWarnings, initialValues, section, ...props} = args;
const {errorSchema: validateSchema, warningSchema} = getSchemas({section});
return (
<Formik
initialValues={initialValues}
validationSchema={withErrors ? validateSchema : null}
onSubmit={() => {}}
>
<Formik initialValues={initialValues} validationSchema={withErrors ? validateSchema : null} onSubmit={() => {}}>
{({values, submitForm}) => {
const warnings = withWarnings ? getWarnings(warningSchema, values) || {} : {};
return (
<>
<Field
component={DatePicker}
warnings={warnings}
{...props}
/>
{
withErrors
? <Button onClick={submitForm} variant="contained">Click to validate form</Button>
: null
}
<Field component={DatePicker} warnings={warnings} {...props} />
{withErrors ? (
<Button onClick={submitForm} variant="contained">
Click to validate form
</Button>
) : null}
</>
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ function DateTimePickerSelector({type, onChange, value, ...props}) {
);
}
return (
<MuiDatePicker
{...props}
inputFormat="dd/MM/yyyy"
onChange={handleChange}
value={value ? new Date(value) : value}
/>
<MuiDatePicker {...props} inputFormat="dd/MM/yyyy" onChange={handleChange} value={value ? new Date(value) : value} />
);
}

Expand Down
12 changes: 7 additions & 5 deletions src/components/FieldMessage/FieldMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import hasFormikErrorsAndWarnings from '@/utils/hasFormikErrorsAndWarnings';
const alertStyles = {justifyContent: 'center', mt: 2};

function FieldMessage({form, field, disabled, warnings}) {
const {
hasWarning, warning, hasError, error
} = hasFormikErrorsAndWarnings({form, field, warnings});
const {hasWarning, warning, hasError, error} = hasFormikErrorsAndWarnings({form, field, warnings});
if (hasError && !disabled) {
return (
<Alert severity="error" sx={alertStyles}>{error}</Alert>
<Alert severity="error" sx={alertStyles}>
{error}
</Alert>
);
}
if (hasWarning && !disabled) {
return (
<Alert severity="warning" sx={alertStyles}>{warning}</Alert>
<Alert severity="warning" sx={alertStyles}>
{warning}
</Alert>
);
}
return null;
Expand Down
Loading
Loading