Skip to content

Commit 911cceb

Browse files
authored
Merge pull request jaegertracing#126 from jaegertracing/style-guide
Style guide Signed-off-by: vvvprabhakar <[email protected]>
2 parents 6e1f162 + c3a6119 commit 911cceb

Some content is hidden

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

65 files changed

+1128
-1073
lines changed

.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"comma-dangle": 0,
1818
"no-continue": 0,
1919
"no-plusplus": 0,
20-
"no-restricted-syntax": 0,
2120
"no-self-compare": 0,
2221
"no-underscore-dangle": 0,
2322

CONTRIBUTING.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ to be accepted if it:
3838
By contributing your code, you agree to license your contribution under the terms
3939
of the [Apache License](LICENSE).
4040

41-
If you are adding a new file it should have a header like below.
41+
If you are adding a new file it should have a header like below.
4242

4343
```
4444
// Copyright (c) 2017 The Jaeger Authors.
@@ -117,3 +117,17 @@ If you want this to be automatic you can set up some aliases:
117117
git config --add alias.amend "commit -s --amend"
118118
git config --add alias.c "commit -s"
119119
```
120+
121+
# Style Guide
122+
123+
Prefer to use [flow](https://flow.org/) for new code.
124+
125+
We use [`prettier`](https://prettier.io/), an "opinionated" code formatter. It
126+
can be applied to both JavaScript and CSS source files via `yarn prettier`.
127+
128+
Then, most issues will be caught by the linter, which can be applied via `yarn
129+
eslint`.
130+
131+
Finally, we generally adhere to the
132+
[Airbnb Style Guide](https://github.com/airbnb/javascript), with exceptions as
133+
noted in our `.eslintrc`.

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,20 @@
8181
"lint": "npm run eslint && npm run prettier && npm run flow && npm run check-license",
8282
"eslint": "eslint src",
8383
"check-license": "./scripts/check-license.sh",
84-
"prettier": "prettier --single-quote --trailing-comma es5 --print-width 110 --write \"src/**/*.js\"",
84+
"prettier": "prettier --write \"src/**/*.js\" \"src/**/*.css\"",
8585
"flow": "flow; test $? -eq 0 -o $? -eq 2",
8686
"precommit": "lint-staged"
8787
},
8888
"jest": {
89-
"collectCoverageFrom": ["src/**/*.js", "!src/utils/DraggableManager/demo/*.js"]
89+
"collectCoverageFrom": [
90+
"src/**/*.js",
91+
"!src/utils/DraggableManager/demo/*.js"
92+
]
93+
},
94+
"prettier": {
95+
"printWidth": 110,
96+
"singleQuote": true,
97+
"trailingComma": "es5"
9098
},
9199
"lint-staged": {
92100
"*.js": [

src/actions/jaeger-api.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ it('@JAEGER_API/FETCH_SERVICES should return a promise', () => {
106106
it('@JAEGER_API/FETCH_SERVICE_OPERATIONS should call the JaegerAPI', () => {
107107
const api = JaegerAPI;
108108
const mock = sinon.mock(api);
109-
const called = mock.expects('fetchServiceOperations').once().withExactArgs('service');
109+
const called = mock
110+
.expects('fetchServiceOperations')
111+
.once()
112+
.withExactArgs('service');
110113
jaegerApiActions.fetchServiceOperations('service');
111114
expect(called.verify()).toBeTruthy();
112115
mock.restore();

src/api/jaeger.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ function getJSON(url, query) {
3232
.then(({ errors = [] }) => {
3333
throw new Error(errors.length > 0 ? errors[0].msg : 'An unknown error occurred.');
3434
})
35-
.catch(
36-
(/* err */) => {
37-
throw new Error('Bad JSON returned from the Jaeger Query Service.');
38-
}
39-
);
35+
.catch((/* err */) => {
36+
throw new Error('Bad JSON returned from the Jaeger Query Service.');
37+
});
4038
}
4139
return response.json();
4240
});

src/components/App/App.css

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ body ::-webkit-scrollbar {
3434
}
3535

3636
a {
37-
color: #11939A;
37+
color: #11939a;
3838
}
3939

4040
a:hover {
41-
color: #00474E;
41+
color: #00474e;
4242
cursor: pointer;
4343
}
4444

4545
.clearfix:after {
46-
content: " ";
47-
visibility: hidden;
48-
display: block;
49-
height: 0;
50-
clear: both;
46+
content: ' ';
47+
visibility: hidden;
48+
display: block;
49+
height: 0;
50+
clear: both;
5151
}
5252

5353
.pull-left {
@@ -83,19 +83,21 @@ a:hover {
8383
}
8484

8585
.ui.table td.light-grey {
86-
background-color: #F1F1F1;
86+
background-color: #f1f1f1;
8787
}
8888

89-
.ui.table, .ui.table thead tr:first-child>th:last-child, .ui.table thead tr:first-child>th:first-child {
89+
.ui.table,
90+
.ui.table thead tr:first-child > th:last-child,
91+
.ui.table thead tr:first-child > th:first-child {
9092
border-radius: 0;
9193
}
9294

9395
.ui.table thead th {
94-
background-color: #F1F1F1;
96+
background-color: #f1f1f1;
9597
}
9698

9799
.ui.sortable.table thead th.sorted,
98100
.ui.sortable.table thead th:hover,
99101
.ui.sortable.table thead th.sorted:hover {
100-
background-color: #D6D6D5;
102+
background-color: #d6d6d5;
101103
}

src/components/App/NotFound.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @flow
2+
13
// Copyright (c) 2017 Uber Technologies, Inc.
24
//
35
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,40 +14,32 @@
1214
// See the License for the specific language governing permissions and
1315
// limitations under the License.
1416

15-
import PropTypes from 'prop-types';
1617
import React from 'react';
1718
import { Link } from 'react-router-dom';
1819

1920
import prefixUrl from '../../utils/prefix-url';
2021

21-
export default function NotFound({ error }) {
22+
type NotFoundProps = {
23+
error: any,
24+
};
25+
26+
export default function NotFound({ error }: NotFoundProps) {
2227
return (
2328
<section className="ui container">
2429
<div className="ui center aligned basic segment">
2530
<div className="ui center aligned basic segment">
26-
<h1>
27-
{'404'}
28-
</h1>
29-
<p>
30-
{"Looks like you tried to access something that doesn't exist."}
31-
</p>
31+
<h1>{'404'}</h1>
32+
<p>{"Looks like you tried to access something that doesn't exist."}</p>
3233
</div>
33-
{error &&
34+
{error && (
3435
<div className="ui red message">
35-
<p>
36-
{String(error)}
37-
</p>
38-
</div>}
36+
<p>{String(error)}</p>
37+
</div>
38+
)}
3939
<div className="ui center aligned basic segment">
40-
<Link to={prefixUrl('/')}>
41-
{'Back home'}
42-
</Link>
40+
<Link to={prefixUrl('/')}>{'Back home'}</Link>
4341
</div>
4442
</div>
4543
</section>
4644
);
4745
}
48-
49-
NotFound.propTypes = {
50-
error: PropTypes.object,
51-
};

src/components/App/Page.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ class Page extends React.Component<PageProps> {
5555
<section className="jaeger-ui-page" id="jaeger-ui">
5656
<Helmet title="Jaeger UI" />
5757
<TopNav menuConfig={menu} />
58-
<div className="jaeger-ui--content">
59-
{children}
60-
</div>
58+
<div className="jaeger-ui--content">{children}</div>
6159
</section>
6260
);
6361
}

src/components/DependencyGraph/DAG.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ import dagre from 'dagre';
2121
cydagre(cytoscape, dagre);
2222

2323
export default class DAG extends React.Component {
24-
static get propTypes() {
25-
return {
26-
serviceCalls: PropTypes.arrayOf(
27-
PropTypes.shape({
28-
parent: PropTypes.string,
29-
child: PropTypes.string,
30-
callCount: PropTypes.number,
31-
})
32-
),
33-
};
34-
}
24+
static propTypes = {
25+
serviceCalls: PropTypes.arrayOf(
26+
PropTypes.shape({
27+
parent: PropTypes.string,
28+
child: PropTypes.string,
29+
callCount: PropTypes.number,
30+
})
31+
),
32+
};
33+
34+
static defaultProps = {
35+
serviceCalls: [],
36+
};
37+
3538
componentDidMount() {
3639
const { serviceCalls } = this.props;
3740
const nodeMap = {};

src/components/DependencyGraph/DependencyForceGraph.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ export default class DependencyForceGraph extends Component {
6565

6666
return (
6767
<div
68-
ref={/* istanbul ignore next */ c => {
69-
this.container = c;
70-
}}
68+
ref={
69+
/* istanbul ignore next */ c => {
70+
this.container = c;
71+
}
72+
}
7173
style={{ position: 'relative' }}
7274
>
7375
<InteractiveForceGraph
@@ -91,7 +93,7 @@ export default class DependencyForceGraph extends Component {
9193
nodeAttrs={['orphan']}
9294
highlightDependencies
9395
>
94-
{nodes.map(({ labelStyle, labelClass, showLabel, opacity, fill, ...node }) =>
96+
{nodes.map(({ labelStyle, labelClass, showLabel, opacity, fill, ...node }) => (
9597
<ForceGraphNode
9698
key={node.id}
9799
node={node}
@@ -101,10 +103,10 @@ export default class DependencyForceGraph extends Component {
101103
opacity={opacity}
102104
fill={fill}
103105
/>
104-
)}
105-
{links.map(({ opacity, ...link }) =>
106+
))}
107+
{links.map(({ opacity, ...link }) => (
106108
<ForceGraphLink key={`${link.source}=>${link.target}`} opacity={opacity} link={link} />
107-
)}
109+
))}
108110
</InteractiveForceGraph>
109111
</div>
110112
);

0 commit comments

Comments
 (0)