Skip to content

Commit

Permalink
Merge pull request #275 from sto3psl/prettier
Browse files Browse the repository at this point in the history
add Prettier for consistent code formatting
  • Loading branch information
hshoff authored Apr 28, 2018
2 parents 772ccea + ae02448 commit f84a665
Show file tree
Hide file tree
Showing 339 changed files with 4,174 additions and 5,579 deletions.
13 changes: 13 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
node_modules
build
bundle.js
test/tmp
*.log
*.cache
/.eslintcache
.next
coverage
package-lock.json
npm-shrinkwrap.json
yarn.lock
41 changes: 34 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,52 @@
"scripts": {
"test": "lerna bootstrap && lerna exec npm run test",
"docs": "node ./scripts/docs/index.js",
"prepare-release":
"git checkout master && git pull --rebase origin master && npm run docs && lerna updated",
"release": "npm run prepare-release && lerna publish --exact"
"prepare-release": "git checkout master && git pull --rebase origin master && npm run docs && lerna updated",
"release": "npm run prepare-release && lerna publish --exact",
"format": "prettier \"{packages,scripts}/**/*.js\" --write",
"precommit": "lint-staged"
},
"prettier": {
"printWidth": 100,
"singleQuote": true
},
"lint-staged": {
"*.js": [
"prettier --write",
"git add"
]
},
"jest": {
"projects": ["<rootDir>/packages/*"],
"projects": [
"<rootDir>/packages/*"
],
"collectCoverage": true,
"coverageDirectory": "<rootDir>/coverage",
"coveragePathIgnorePatterns": ["/node_modules/"],
"coverageReporters": ["text", "lcov"]
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"text",
"lcov"
]
},
"keywords": ["react", "d3", "visualization", "vx", "charts"],
"keywords": [
"react",
"d3",
"visualization",
"vx",
"charts"
],
"author": "@hshoff",
"license": "MIT",
"devDependencies": {
"babel-jest": "^20.0.3",
"coveralls": "^2.13.1",
"husky": "^0.14.3",
"jest": "^20.0.3",
"lerna": "2.1.2",
"lint-staged": "^7.0.4",
"prettier": "^1.12.1",
"react": "^15.0.0-0 || ^16.0.0-0",
"react-dom": "^15.0.0-0 || ^16.0.0-0",
"regenerator-runtime": "^0.10.5"
Expand Down
12 changes: 4 additions & 8 deletions packages/vx-annotation/src/annotations/LinePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ export default function LinePathAnnotation({
labelFontSize = 10,
labelStroke = 'white',
labelStrokeWidth = 3,
labelPaintOrder = 'stroke',
labelPaintOrder = 'stroke'
}) {
const endPoint = points[points.length - 1];
return (
<Group
className='vx-line-path-annotation-group'
top={top}
left={left}
>
<Group className="vx-line-path-annotation-group" top={top} left={left}>
<LinePath
className={cx('vx-line-path-annotation', className)}
data={points}
Expand All @@ -62,7 +58,7 @@ export default function LinePathAnnotation({
stroke={stroke}
strokeWidth={strokeWidth}
/>
{label &&
{label && (
<text
x={endPoint.x}
y={endPoint.y}
Expand All @@ -77,7 +73,7 @@ export default function LinePathAnnotation({
>
{label}
</text>
}
)}
</Group>
);
}
87 changes: 47 additions & 40 deletions packages/vx-annotation/test/LinePathAnnotation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,63 @@ import { LinePathAnnotation } from '../src';

describe('<LinePathAnnotation />', () => {
test('it should be defined', () => {
expect(LinePathAnnotation).toBeDefined()
})
expect(LinePathAnnotation).toBeDefined();
});

test('it should be wrapped with defaults <Group top={0} left={0} />', () => {
const wrapper = shallow(<LinePathAnnotation />)
expect(wrapper.prop('top')).toEqual(0)
expect(wrapper.prop('left')).toEqual(0)
expect(wrapper.is('.vx-line-path-annotation-group')).toBe(true)
})
const wrapper = shallow(<LinePathAnnotation />);
expect(wrapper.prop('top')).toEqual(0);
expect(wrapper.prop('left')).toEqual(0);
expect(wrapper.is('.vx-line-path-annotation-group')).toBe(true);
});

test('it should set <Group top= left= /> wrapper props', () => {
const wrapper = shallow(
<LinePathAnnotation
top={20}
left={300}
/>
);
expect(wrapper.prop('top')).toEqual(20)
expect(wrapper.prop('left')).toEqual(300)
})
const wrapper = shallow(<LinePathAnnotation top={20} left={300} />);
expect(wrapper.prop('top')).toEqual(20);
expect(wrapper.prop('left')).toEqual(300);
});

test('it should contain a <LinePath />', () => {
const wrapper = shallow(<LinePathAnnotation />)
expect(wrapper.find('.vx-line-path-annotation').length).toBe(1)
})
const wrapper = shallow(<LinePathAnnotation />);
expect(wrapper.find('.vx-line-path-annotation').length).toBe(1);
});

test('it should pass props to <LinePath />', () => {
const points = [new Point({x: 0, y: 0})];
const wrapper = shallow(
<LinePathAnnotation
className='test'
points={points}
/>
);
const points = [new Point({ x: 0, y: 0 })];
const wrapper = shallow(<LinePathAnnotation className="test" points={points} />);
const linePath = wrapper.find('.vx-line-path-annotation');
expect(linePath.prop('data')).toBe(points)
expect(linePath.prop('stroke')).toEqual('black')
expect(linePath.prop('strokeWidth')).toEqual(1)
expect(linePath.prop('className')).toEqual('vx-line-path-annotation test')
})
expect(linePath.prop('data')).toBe(points);
expect(linePath.prop('stroke')).toEqual('black');
expect(linePath.prop('strokeWidth')).toEqual(1);
expect(linePath.prop('className')).toEqual('vx-line-path-annotation test');
});

test('it should not render a label if label prop is undefined', () => {
const wrapper = shallow(<LinePathAnnotation />)
expect(wrapper.prop('children').filter(c => !!c).length).toBe(1)
})
const wrapper = shallow(<LinePathAnnotation />);
expect(wrapper.prop('children').filter(c => !!c).length).toBe(1);
});

test('it should render a label if label prop is defined', () => {
const points = [new Point({x: 0, y: 0})];
const wrapper = shallow(<LinePathAnnotation label='test' points={points} />)
expect(wrapper.prop('children').filter(c => !!c).length).toBe(2)
expect(wrapper.contains(<text dx={0} dy={0} fill="black" fontSize={10} paintOrder="stroke" stroke="white" strokeWidth={3} textAnchor="middle" x={0} y={0}>test</text>)).toBe(true)
})
})
const points = [new Point({ x: 0, y: 0 })];
const wrapper = shallow(<LinePathAnnotation label="test" points={points} />);
expect(wrapper.prop('children').filter(c => !!c).length).toBe(2);
expect(
wrapper.contains(
<text
dx={0}
dy={0}
fill="black"
fontSize={10}
paintOrder="stroke"
stroke="white"
strokeWidth={3}
textAnchor="middle"
x={0}
y={0}
>
test
</text>
)
).toBe(true);
});
});
2 changes: 1 addition & 1 deletion packages/vx-annotation/test/enzyme-setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });
Enzyme.configure({ adapter: new Adapter() });
Loading

0 comments on commit f84a665

Please sign in to comment.