Skip to content

Commit

Permalink
support prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 authored and afc163 committed Dec 7, 2018
1 parent 16c3a94 commit dca9715
Show file tree
Hide file tree
Showing 364 changed files with 8,692 additions and 5,894 deletions.
27 changes: 18 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const eslintrc = {
extends: ['eslint-config-airbnb'],
extends: ['airbnb', 'prettier'],
env: {
browser: true,
node: true,
Expand All @@ -8,18 +8,27 @@ const eslintrc = {
es6: true,
},
parser: 'babel-eslint',
plugins: [
'markdown',
'react',
'babel',
],
plugins: ['markdown', 'react', 'babel'],
rules: {
'react/jsx-one-expression-per-line': 0,
'react/prop-types': 0,
'react/forbid-prop-types': 0,
'import/no-extraneous-dependencies': ['error', {
devDependencies: ['site/**', 'tests/**', 'scripts/**', '**/*.test.js', '**/__tests__/*', '*.config.js', '**/*.md'],
}],
'react/jsx-indent': 0,
'react/jsx-wrap-multilines': ['error', { declaration: false, assignment: false }],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'site/**',
'tests/**',
'scripts/**',
'**/*.test.js',
'**/__tests__/*',
'*.config.js',
'**/*.md',
],
},
],
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx', '.md'] }],
'jsx-a11y/no-static-element-interactions': 0,
'jsx-a11y/anchor-has-content': 0,
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/*.md
**/*.svg
**/*.ejs
**/*.html
package.json
.umi
.umi-production
19 changes: 19 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
},
{
"files": ".stylelintrc",
"options": {
"parser": "json"
}
}
]
}
2 changes: 1 addition & 1 deletion .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "stylelint-config-standard",
"extends": ["stylelint-config-standard", "stylelint-config-prettier"],
"rules": {
"comment-empty-line-before": null,
"declaration-empty-line-before": null,
Expand Down
2 changes: 1 addition & 1 deletion components/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('antd', () => {

it('should hint when import all components in dev mode', () => {
expect(warnSpy).toBeCalledWith(
'You are using a whole package of antd, please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.'
'You are using a whole package of antd, please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.',
);
warnSpy.mockRestore();
});
Expand Down
12 changes: 8 additions & 4 deletions components/_util/__tests__/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Test utils function', () => {
});
});

it('delayRaf', (done) => {
it('delayRaf', done => {
jest.useRealTimers();

let bamboo = false;
Expand Down Expand Up @@ -118,9 +118,13 @@ describe('Test utils function', () => {

it('triggerEvent', () => {
const button = document.createElement('button');
button.addEventListener('click', () => {
button.style.width = '100px';
}, true);
button.addEventListener(
'click',
() => {
button.style.width = '100px';
},
true,
);
triggerEvent(button, 'click');
expect(button.style.width).toBe('100px');
});
Expand Down
6 changes: 4 additions & 2 deletions components/_util/isFlexSupported.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export default function isFlexSupported() {
if (typeof window !== 'undefined' && window.document && window.document.documentElement) {
const { documentElement } = window.document;
return 'flex' in documentElement.style ||
return (
'flex' in documentElement.style ||
'webkitFlex' in documentElement.style ||
'Flex' in documentElement.style ||
'msFlex' in documentElement.style;
'msFlex' in documentElement.style
);
}
return false;
}
4 changes: 2 additions & 2 deletions components/_util/raf.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import raf from 'raf';

interface RafMap {
[id: number]: number,
[id: number]: number;
}

let id: number = 0;
Expand Down Expand Up @@ -31,4 +31,4 @@ export default function wrapperRaf(callback: () => void, delayFrames: number = 1
wrapperRaf.cancel = function(id: number) {
raf.cancel(ids[id]);
delete ids[id];
}
};
2 changes: 1 addition & 1 deletion components/_util/warning.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warning from 'warning';

const warned: { [msg: string]: boolean} = {};
const warned: { [msg: string]: boolean } = {};
export default (valid: boolean, message: string): void => {
if (!valid && !warned[message]) {
warning(false, message);
Expand Down
39 changes: 21 additions & 18 deletions components/_util/wave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function isHidden(element: HTMLElement) {
return !element || element.offsetParent === null;
}

export default class Wave extends React.Component<{insertExtraNode?: boolean}> {
export default class Wave extends React.Component<{ insertExtraNode?: boolean }> {
private instance?: {
cancel: () => void;
};
Expand All @@ -22,7 +22,7 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> {
private clickWaveTimeoutId: number;
private animationStartId: number;
private animationStart: boolean = false;
private destroy: boolean = false
private destroy: boolean = false;

isNotGrey(color: string) {
const match = (color || '').match(/rgba?\((\d*), (\d*), (\d*)(, [\.\d]*)?\)/);
Expand All @@ -45,15 +45,16 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> {
node.setAttribute(attributeName, 'true');
// Not white or transparnt or grey
styleForPesudo = styleForPesudo || document.createElement('style');
if (waveColor &&
waveColor !== '#ffffff' &&
waveColor !== 'rgb(255, 255, 255)' &&
this.isNotGrey(waveColor) &&
!/rgba\(\d*, \d*, \d*, 0\)/.test(waveColor) && // any transparent rgba color
waveColor !== 'transparent') {
if (
waveColor &&
waveColor !== '#ffffff' &&
waveColor !== 'rgb(255, 255, 255)' &&
this.isNotGrey(waveColor) &&
!/rgba\(\d*, \d*, \d*, 0\)/.test(waveColor) && // any transparent rgba color
waveColor !== 'transparent'
) {
extraNode.style.borderColor = waveColor;
styleForPesudo.innerHTML =
`[ant-click-animating-without-extra-node]:after { border-color: ${waveColor}; }`;
styleForPesudo.innerHTML = `[ant-click-animating-without-extra-node]:after { border-color: ${waveColor}; }`;
if (!document.body.contains(styleForPesudo)) {
document.body.appendChild(styleForPesudo);
}
Expand All @@ -63,13 +64,15 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> {
}
TransitionEvents.addStartEventListener(node, this.onTransitionStart);
TransitionEvents.addEndEventListener(node, this.onTransitionEnd);
}
};

bindAnimationEvent = (node: HTMLElement) => {
if (!node ||
!node.getAttribute ||
node.getAttribute('disabled') ||
node.className.indexOf('disabled') >= 0) {
if (
!node ||
!node.getAttribute ||
node.getAttribute('disabled') ||
node.className.indexOf('disabled') >= 0
) {
return;
}
const onClick = (e: MouseEvent) => {
Expand Down Expand Up @@ -99,7 +102,7 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> {
node.removeEventListener('click', onClick, true);
},
};
}
};

getAttributeName() {
const { insertExtraNode } = this.props;
Expand Down Expand Up @@ -132,14 +135,14 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> {
if (!this.animationStart) {
this.resetEffect(node);
}
}
};

onTransitionEnd = (e: AnimationEvent) => {
if (!e || e.animationName !== 'fadeEffect') {
return;
}
this.resetEffect(e.target as HTMLElement);
}
};

removeExtraStyleNode() {
if (styleForPesudo) {
Expand Down
31 changes: 21 additions & 10 deletions components/affix/__tests__/Affix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AffixMounter extends React.Component {
});
}

getTarget = () => this.container
getTarget = () => this.container;

render() {
return (
Expand All @@ -21,7 +21,9 @@ class AffixMounter extends React.Component {
height: 100,
overflowY: 'scroll',
}}
ref={(node) => { this.container = node; }}
ref={node => {
this.container = node;
}}
>
<div
className="background"
Expand All @@ -32,12 +34,12 @@ class AffixMounter extends React.Component {
>
<Affix
target={() => this.container}
ref={(ele) => { this.affix = ele; }}
ref={ele => {
this.affix = ele;
}}
{...this.props}
>
<Button type="primary">
Fixed at the top of container
</Button>
<Button type="primary">Fixed at the top of container</Button>
</Affix>
</div>
</div>
Expand All @@ -56,9 +58,14 @@ describe('Affix Render', () => {
jest.useRealTimers();
});

const scrollTo = (top) => {
const scrollTo = top => {
wrapper.instance().affix.fixedNode.parentNode.getBoundingClientRect = jest.fn(() => ({
bottom: 100, height: 28, left: 0, right: 0, top: 50 - top, width: 195,
bottom: 100,
height: 28,
left: 0,
right: 0,
top: 50 - top,
width: 195,
}));
wrapper.instance().container.scrollTop = top;
events.scroll({
Expand Down Expand Up @@ -86,7 +93,9 @@ describe('Affix Render', () => {
it('support offsetBottom', () => {
document.body.innerHTML = '<div id="mounter" />';

wrapper = mount(<AffixMounter offsetBottom={0} />, { attachTo: document.getElementById('mounter') });
wrapper = mount(<AffixMounter offsetBottom={0} />, {
attachTo: document.getElementById('mounter'),
});
jest.runAllTimers();

scrollTo(0);
Expand All @@ -102,7 +111,9 @@ describe('Affix Render', () => {
it('updatePosition when offsetTop changed', () => {
document.body.innerHTML = '<div id="mounter" />';

wrapper = mount(<AffixMounter offsetTop={0} />, { attachTo: document.getElementById('mounter') });
wrapper = mount(<AffixMounter offsetTop={0} />, {
attachTo: document.getElementById('mounter'),
});
jest.runAllTimers();

scrollTo(100);
Expand Down
Loading

0 comments on commit dca9715

Please sign in to comment.