Skip to content

Commit d281949

Browse files
authored
Merge pull request #60 from luizbaldi/eslint-prettier-improvements
ESLint and Prettier improvements
2 parents 6010eab + 5cb3abe commit d281949

Some content is hidden

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

68 files changed

+579
-658
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2-
extends: ['airbnb', 'prettier'],
2+
extends: ['airbnb', 'plugin:prettier/recommended', 'prettier/react'],
33
parser: 'babel-eslint',
4-
plugins: ['prettier'],
4+
plugins: ['react', 'prettier'],
55
env: {
66
browser: true,
77
es6: true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"test": "jest",
3333
"test:watch": "jest --watch",
3434
"test:coverage": "jest --coverage",
35-
"lint": "eslint src",
35+
"lint": "eslint src --ext .js",
3636
"lint:fix": "npm run lint -- --fix"
3737
},
3838
"peerDependencies": {

src/components/Anchor/Anchor.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,22 @@ const StyledAnchor = styled.a`
1313
}
1414
`;
1515

16-
const Anchor = ({
17-
className, style, href, children, ...otherProps
18-
}) => (
19-
<StyledAnchor
20-
href={href}
21-
className={className}
22-
style={style}
23-
{...otherProps}
24-
>
16+
const Anchor = ({ className, style, href, children, ...otherProps }) => (
17+
<StyledAnchor href={href} className={className} style={style} {...otherProps}>
2518
{children}
2619
</StyledAnchor>
2720
);
2821

2922
Anchor.defaultProps = {
3023
className: '',
31-
style: {},
24+
style: {}
3225
};
3326

3427
Anchor.propTypes = {
3528
className: propTypes.string,
3629
href: propTypes.string.isRequired,
37-
style: propTypes.shape([
38-
propTypes.string,
39-
propTypes.number,
40-
]),
41-
children: propTypes.node.isRequired,
30+
style: propTypes.shape([propTypes.string, propTypes.number]),
31+
children: propTypes.node.isRequired
4232
};
4333

4434
export default Anchor;

src/components/Anchor/Anchor.spec.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,32 @@ import Anchor from './Anchor';
55

66
const defaultProps = {
77
children: '',
8-
href: '',
8+
href: ''
99
};
1010

1111
describe('<Anchor />', () => {
1212
it('should render href', () => {
13-
const { container } = render((
14-
<Anchor {...defaultProps} href="http://yoda.com" />
15-
));
13+
const { container } = render(
14+
<Anchor {...defaultProps} href='http://yoda.com' />
15+
);
1616
const anchorEl = container.firstChild;
1717

1818
expect(anchorEl).toHaveAttribute('href', 'http://yoda.com');
1919
});
2020

2121
it('should render children', () => {
22-
const { container } = render(<Anchor {...defaultProps}>You shall pass</Anchor>);
22+
const { container } = render(
23+
<Anchor {...defaultProps}>You shall pass</Anchor>
24+
);
2325
const anchorEl = container.firstChild;
2426

2527
expect(anchorEl).toHaveTextContent('You shall pass');
2628
});
2729

2830
it('should render custom style', () => {
29-
const { container } = render((
30-
<Anchor
31-
{...defaultProps}
32-
style={{ color: 'papayawhip' }}
33-
/>
34-
));
31+
const { container } = render(
32+
<Anchor {...defaultProps} style={{ color: 'papayawhip' }} />
33+
);
3534
const anchorEl = container.firstChild;
3635

3736
expect(anchorEl).toHaveAttribute('style', 'color: papayawhip;');

src/components/Anchor/Anchor.stories.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@ storiesOf('Anchor', module)
88
<div
99
style={{
1010
padding: '5rem',
11-
background: '#ced0cf',
11+
background: '#ced0cf'
1212
}}
1313
>
1414
{story()}
1515
</div>
1616
))
1717
.add('default', () => (
18-
<Anchor href="https://expensive.toys" target="_blank">
18+
<Anchor href='https://expensive.toys' target='_blank'>
1919
Expensive Toys
20-
{' '}
2120
</Anchor>
2221
))
2322
.add('within text', () => (
2423
<h1>
25-
{'Everybody needs '}
26-
<Anchor href="https://expensive.toys" target="_blank">
24+
Everybody needs
25+
<Anchor href='https://expensive.toys' target='_blank'>
2726
Expensive Toys
2827
</Anchor>
2928
</h1>

src/components/AppBar/AppBar.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,15 @@ AppBar.defaultProps = {
3939
shadow: true,
4040
fixed: true,
4141
style: {},
42-
className: '',
42+
className: ''
4343
};
4444

4545
AppBar.propTypes = {
46-
style: propTypes.shape([
47-
propTypes.string,
48-
propTypes.number,
49-
]),
46+
style: propTypes.shape([propTypes.string, propTypes.number]),
5047
shadow: propTypes.bool,
5148
className: propTypes.string,
5249
children: propTypes.node.isRequired,
53-
fixed: propTypes.bool,
50+
fixed: propTypes.bool
5451
};
5552

5653
export default AppBar;

src/components/AppBar/AppBar.spec.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ describe('<AppBar />', () => {
3232
});
3333

3434
it('should custom style', () => {
35-
const { container } = render((
36-
<AppBar
37-
{...defaultProps}
38-
style={{ backgroundColor: 'papayawhip' }}
39-
/>
40-
));
35+
const { container } = render(
36+
<AppBar {...defaultProps} style={{ backgroundColor: 'papayawhip' }} />
37+
);
4138
const headerEl = container.firstChild;
4239

4340
expect(headerEl).toHaveAttribute('style', 'background-color: papayawhip;');

src/components/AppBar/AppBar.stories.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ storiesOf('AppBar', module)
1717
<div
1818
style={{
1919
padding: '5rem',
20-
background: 'teal',
20+
background: 'teal'
2121
}}
2222
>
2323
{story()}
@@ -28,7 +28,7 @@ storiesOf('AppBar', module)
2828
<Toolbar style={{ justifyContent: 'space-between' }}>
2929
<Menu />
3030
<TextField
31-
placeholder="Search..."
31+
placeholder='Search...'
3232
width={150}
3333
style={{ marginLeft: 4 }}
3434
/>
@@ -51,22 +51,28 @@ function Menu() {
5151
<div style={{ position: 'relative', display: 'inline-block' }}>
5252
{open && (
5353
<List
54-
horizontalAlign="left"
55-
verticalAlign="bottom"
54+
horizontalAlign='left'
55+
verticalAlign='bottom'
5656
open={open}
5757
onClick={handleClose}
5858
>
5959
<ListItem>
60-
<span role="img" aria-label="👨‍💻">👨‍💻</span>
60+
<span role='img' aria-label='👨‍💻'>
61+
👨‍💻
62+
</span>
6163
Profile
6264
</ListItem>
6365
<ListItem>
64-
<span role="img" aria-label="📁">📁</span>
66+
<span role='img' aria-label='📁'>
67+
📁
68+
</span>
6569
My account
6670
</ListItem>
6771
<Divider />
6872
<ListItem disabled>
69-
<span role="img" aria-label="🔙">🔙</span>
73+
<span role='img' aria-label='🔙'>
74+
🔙
75+
</span>
7076
Logout
7177
</ListItem>
7278
</List>

src/components/Avatar/Avatar.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ const StyledAvatar = styled.div`
1111
width: calc(${() => blockSizes.md} - 2px);
1212
border-radius: ${({ square }) => (square ? 0 : '50%')};
1313
overflow: hidden;
14-
${({ noBorder, theme }) => !noBorder
15-
&& `
14+
${({ noBorder, theme }) =>
15+
!noBorder &&
16+
`
1617
border-top: 2px solid ${theme.borderDark};
1718
border-left: 2px solid ${theme.borderDark};
1819
border-bottom: 2px solid ${theme.borderLightest};
1920
border-right: 2px solid ${theme.borderLightest};
2021
background: ${theme.material};
2122
`}
22-
${({ src }) => !src
23-
&& `
23+
${({ src }) =>
24+
!src &&
25+
`
2426
display: flex;
2527
align-items: center;
2628
justify-content: space-around;
@@ -36,9 +38,7 @@ const SlyledAvatarIMG = styled.img`
3638
height: 100%;
3739
`;
3840

39-
const Avatar = ({
40-
children, noBorder, square, src, alt, ...otherProps
41-
}) => (
41+
const Avatar = ({ children, noBorder, square, src, alt, ...otherProps }) => (
4242
<StyledAvatar noBorder={noBorder} square={square} {...otherProps}>
4343
{src ? <SlyledAvatarIMG src={src} alt={alt} /> : children}
4444
</StyledAvatar>
@@ -49,15 +49,15 @@ Avatar.defaultProps = {
4949
noBorder: false,
5050
src: undefined,
5151
children: null,
52-
alt: '',
52+
alt: ''
5353
};
5454

5555
Avatar.propTypes = {
5656
square: propTypes.bool,
5757
noBorder: propTypes.bool,
5858
children: propTypes.node,
5959
src: propTypes.string,
60-
alt: propTypes.string,
60+
alt: propTypes.string
6161
};
6262

6363
export default Avatar;

src/components/Avatar/Avatar.spec.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ describe('<Avatar />', () => {
2020
});
2121

2222
it('should handle border properly', () => {
23-
const { container, rerender } = renderWithTheme(<Avatar noBorder={false} />);
23+
const { container, rerender } = renderWithTheme(
24+
<Avatar noBorder={false} />
25+
);
2426
const avatarEl = container.firstChild;
2527

26-
expect(avatarEl).toHaveStyleRule('border-top', `2px solid ${theme.borderDark}`);
28+
expect(avatarEl).toHaveStyleRule(
29+
'border-top',
30+
`2px solid ${theme.borderDark}`
31+
);
2732

2833
rerender(<Avatar noBorder />);
2934

@@ -43,21 +48,19 @@ describe('<Avatar />', () => {
4348

4449
it('should render with source', async () => {
4550
const catGif = 'https://cdn2.thecatapi.com/images/1ac.gif';
46-
const { findByAltText } = render((
47-
<Avatar src={catGif} alt="cat avatar" />
48-
));
51+
const { findByAltText } = render(<Avatar src={catGif} alt='cat avatar' />);
4952
const imageEl = await findByAltText('cat avatar');
5053

5154
expect(imageEl.src).toBe(catGif);
5255
});
5356

5457
it('should render source with priority over children', async () => {
5558
const catGif = 'https://cdn2.thecatapi.com/images/1ac.gif';
56-
const { queryByText } = render((
57-
<Avatar src={catGif} alt="cat avatar">
59+
const { queryByText } = render(
60+
<Avatar src={catGif} alt='cat avatar'>
5861
Cats are cool
5962
</Avatar>
60-
));
63+
);
6164
const content = await queryByText(/cats are cool/i);
6265

6366
expect(content).toBeNull();

0 commit comments

Comments
 (0)