Skip to content

Commit

Permalink
feat(common): CHECKOUT-4378 Add sort-props and one-expression-per-lin…
Browse files Browse the repository at this point in the history
…e rules
  • Loading branch information
Luis Sanchez committed Sep 20, 2019
1 parent 807a7f0 commit 990d043
Show file tree
Hide file tree
Showing 161 changed files with 618 additions and 593 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"react/destructuring-assignment": "error",
"react/display-name": "off",
"react/jsx-closing-bracket-location": [
"error",
"error",
"line-aligned"
],
"react/jsx-curly-newline": [
Expand All @@ -62,8 +62,15 @@
],
"react/jsx-key": "error",
"react/jsx-no-bind": "error",
"react/jsx-one-expression-per-line": [
"error",
{
"allow": "single-child"
}
],
"react/jsx-pascal-case": "error",
"react/jsx-props-no-multi-spaces": "error",
"react/jsx-sort-props": "error",
"react/jsx-tag-spacing": [
"error",
{
Expand Down
18 changes: 9 additions & 9 deletions src/app/address/AddressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,31 @@ class AddressForm extends Component<AddressFormProps & WithLanguageProps> {
if (addressFieldName === 'address1' && googleMapsApiKey && countriesWithAutocomplete) {
return (
<GoogleAutocompleteFormField
key={ field.id }
parentFieldName={ fieldName }
apiKey={ googleMapsApiKey }
countryCode={ countryCode }
supportedCountries={ countriesWithAutocomplete }
field={ field }
key={ field.id }
nextElement={ this.nextElement || undefined }
onChange={ this.handleAutocompleteChange }
onSelect={ this.handleAutocompleteSelect }
onToggleOpen={ onAutocompleteToggle }
onChange={ this.handleAutocompleteChange }
apiKey={ googleMapsApiKey }
nextElement={ this.nextElement || undefined }
parentFieldName={ fieldName }
supportedCountries={ countriesWithAutocomplete }
/>
);
}

return (
<DynamicFormField
onChange={ this.handleDynamicFormFieldChange(addressFieldName) }
field={ field }
// stateOrProvince can sometimes be a dropdown or input, so relying on id is not sufficient
fieldType={ this.getDynamicFormFieldType(field) }
key={ `${field.id}-${field.name}` }
onChange={ this.handleDynamicFormFieldChange(addressFieldName) }
parentFieldName={ field.custom ?
(fieldName ? `${fieldName}.customFields` : 'customFields') :
fieldName }
field={ field }
placeholder={ translatedPlaceholderId && language.translate(translatedPlaceholderId) }
fieldType={ this.getDynamicFormFieldType(field) }
/>
);
}) }
Expand Down
6 changes: 3 additions & 3 deletions src/app/address/AddressSelect.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ describe('AddressSelect Component', () => {
<LocaleContext.Provider value={ localeContext }>
<AddressSelect
addresses={ getCustomer().addresses }
selectedAddress={ getAddress() }
onSelectAddress={ noop }
onUseNewAddress={ noop }
selectedAddress={ getAddress() }
/>
</LocaleContext.Provider>
</CheckoutProvider>
Expand All @@ -65,9 +65,9 @@ describe('AddressSelect Component', () => {
<LocaleContext.Provider value={ localeContext }>
<AddressSelect
addresses={ getCustomer().addresses }
selectedAddress={ getAddress() }
onSelectAddress={ noop }
onUseNewAddress={ noop }
selectedAddress={ getAddress() }
/>
</LocaleContext.Provider>
</CheckoutProvider>
Expand Down Expand Up @@ -115,8 +115,8 @@ describe('AddressSelect Component', () => {
<AddressSelect
addresses={ getCustomer().addresses }
onSelectAddress={ onSelectAddress }
selectedAddress={ getAddress() }
onUseNewAddress={ noop }
selectedAddress={ getAddress() }
/>
</LocaleContext.Provider>
</CheckoutProvider>
Expand Down
8 changes: 4 additions & 4 deletions src/app/address/CheckboxGroupFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ const MultiCheckboxFormField: FunctionComponent<MultiCheckboxFormFieldProps> = (
{ label }

<MultiCheckboxControl
testId={ id }
onSelectedAll={ handleSelectAll }
onSelectedNone={ handleSelectNone }
testId={ id }
/>

<DynamicInput
fieldType={ DynamicFormFieldType.checkbox }
id={ id }
name={ name }
value={ getIn(values, name) || [] }
onChange={ handleInputChange }
fieldType={ DynamicFormFieldType.checkbox }
options={ options }
id={ id }
value={ getIn(values, name) || [] }
/>

<FormFieldError
Expand Down
4 changes: 2 additions & 2 deletions src/app/address/DynamicFormField.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe('DynamicFormField Component', () => {
const component = mount(
<Formik initialValues={ {} } onSubmit={ jest.fn() }>
<DynamicFormField
onChange={ onChange }
field={ formFields.find(({ name }) => name === 'address1') as FormFieldType }
onChange={ onChange }
/>
</Formik>
);
Expand All @@ -48,8 +48,8 @@ describe('DynamicFormField Component', () => {
const component = mount(
<Formik initialValues={ {} } onSubmit={ jest.fn() }>
<DynamicFormField
onChange={ onChange }
field={ formFields.find(({ name }) => name === 'address1') as FormFieldType }
onChange={ onChange }
/>
</Formik>
);
Expand Down
21 changes: 11 additions & 10 deletions src/app/address/DynamicFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ const DynamicFormField: FunctionComponent<DynamicFormFieldProps> = ({
fieldLabel :
translatedLabelString && <TranslatedString id={ translatedLabelString } /> }
{ !required &&
<> { '' }
<>
{ '' }
<small className="optimizedCheckout-contentSecondary">
<TranslatedString id="common.optional_text" />
</small>
Expand All @@ -99,15 +100,15 @@ const DynamicFormField: FunctionComponent<DynamicFormFieldProps> = ({
const renderInput = useCallback(({ field }: FieldProps<string>) => (
<DynamicInput
{ ...field }
maxLength={ maxLength || undefined }
autoComplete={ AUTOCOMPLETE[addressFieldName] }
fieldType={ fieldType }
id={ fieldInputId }
max={ max }
maxLength={ maxLength || undefined }
min={ min }
options={ options && options.items }
placeholder={ placeholder || (options && options.helperLabel) }
fieldType={ fieldType }
rows={ options && (options as any).rows }
options={ options && options.items }
autoComplete={ AUTOCOMPLETE[addressFieldName] }
id={ fieldInputId }
/>
), [
addressFieldName,
Expand All @@ -124,17 +125,17 @@ const DynamicFormField: FunctionComponent<DynamicFormFieldProps> = ({
<div className={ `dynamic-form-field dynamic-form-field--${getFormFieldLegacyName(addressFieldName)}` }>
{ fieldType === DynamicFormFieldType.checkbox ?
<CheckboxGroupFormField
onChange={ onChange }
name={ fieldName }
id={ fieldInputId }
label={ label }
name={ fieldName }
onChange={ onChange }
options={ (options && options.items) || [] }
/> :
<FormField
input={ renderInput }
label={ label }
name={ fieldName }
onChange={ onChange }
label={ label }
input={ renderInput }
/> }
</div>
);
Expand Down
22 changes: 11 additions & 11 deletions src/app/address/DynamicInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('DynamicInput', () => {
it('renders textarea for multiline type', () => {
expect(shallow(
<DynamicInput
id="field_33"
fieldType={ DynamicFormFieldType.multiline }
id="field_33"
rows={ 4 }
/>)
.find(TextArea)
Expand All @@ -28,10 +28,10 @@ describe('DynamicInput', () => {
it('renders date picker for date type', () => {
const datePicker = shallow(
<DynamicInput
id="field_33"
fieldType={ DynamicFormFieldType.date }
min="2019-1-1"
id="field_33"
max="2019-2-1"
min="2019-1-1"
/>
);

Expand All @@ -47,11 +47,11 @@ describe('DynamicInput', () => {
<DynamicInput
fieldType={ DynamicFormFieldType.checkbox }
id="id"
value={ ['y'] }
options={ [
{ value: 'x', label: 'X' },
{ value: 'y', label: 'Y' },
] }
value={ ['y'] }
/>);

expect(component.find(CheckboxInput).at(0).props())
Expand All @@ -72,12 +72,12 @@ describe('DynamicInput', () => {
<DynamicInput
fieldType={ DynamicFormFieldType.radio }
id="id"
value="y"
onChange={ jest.fn() }
options={ [
{ value: 'x', label: 'X' },
{ value: 'y', label: 'Y' },
] }
value="y"
/>);

expect(component.find(RadioInput).at(0).props())
Expand All @@ -96,8 +96,8 @@ describe('DynamicInput', () => {
it('renders number type input for number type', () => {
expect(shallow(
<DynamicInput
id="field_33"
fieldType={ DynamicFormFieldType.number }
id="field_33"
/>)
.find(TextInput)
.prop('type'))
Expand All @@ -107,8 +107,8 @@ describe('DynamicInput', () => {
it('renders password type input for password type', () => {
expect(shallow(
<DynamicInput
id="field_33"
fieldType={ DynamicFormFieldType.password }
id="field_33"
/>)
.find(TextInput)
.prop('type'))
Expand All @@ -118,8 +118,8 @@ describe('DynamicInput', () => {
it('renders tel type input for phone type', () => {
expect(shallow(
<DynamicInput
id="field_33"
fieldType={ DynamicFormFieldType.telephone }
id="field_33"
/>)
.find(TextInput)
.prop('type'))
Expand All @@ -129,15 +129,15 @@ describe('DynamicInput', () => {
it('renders select input with passed props', () => {
expect(shallow(
<DynamicInput
id="field_33"
defaultValue="foo"
fieldType={ DynamicFormFieldType.dropdown }
id="field_33"
name="select"
options={ [
{ label: 'Foo', value: 'foo'},
{ label: 'Foo1', value: 'foo1'},
] }
defaultValue="foo"
placeholder="Select an option"
name="select"
/>).html())
.toMatchSnapshot();
});
Expand Down
Loading

0 comments on commit 990d043

Please sign in to comment.