Skip to content

Commit c8fa46d

Browse files
authored
chore(examples): lint examples/react-load using shared top-level eslint config (#2913)
Refs: #2891
1 parent f125022 commit c8fa46d

File tree

13 files changed

+251
-64
lines changed

13 files changed

+251
-64
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const baseConfig = require('../../../eslint.config');
20+
21+
module.exports = {
22+
...baseConfig,
23+
env: {
24+
browser: true,
25+
},
26+
};

examples/react-load/preact/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/react-load/preact/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"description": "Example of using @opentelemetry/plugin-react-load in browser with Preact",
66
"main": "index.js",
77
"scripts": {
8+
"lint": "eslint . --ext=ts,js,mjs",
9+
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
810
"build": "preact build --no-prerender",
911
"docker:start": "cd ./docker && docker-compose down && docker-compose up",
1012
"docker:startd": "cd ./docker && docker-compose down && docker-compose up -d",
@@ -36,6 +38,7 @@
3638
"sirv-cli": "1.0.3"
3739
},
3840
"dependencies": {
41+
"@opentelemetry/api": "^1.0.0",
3942
"@opentelemetry/context-zone": "^1.11.0",
4043
"@opentelemetry/exporter-trace-otlp-http": "^0.37.0",
4144
"@opentelemetry/plugin-react-load": "^0.28.1",
Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,72 @@
1-
import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load'
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load';
220

321
class Content extends BaseOpenTelemetryComponent {
4-
constructor(props){
5-
super(props)
22+
constructor(props) {
23+
super(props);
624
this.state = {
725
results: null,
8-
isLoading: false
9-
}
26+
isLoading: false,
27+
};
1028
}
1129

12-
componentDidMount(){
30+
// eslint-disable-next-line class-methods-use-this
31+
componentDidMount() {
1332
// Example, do something here
1433
}
1534

1635
buttonHandler() {
17-
this.setState({isLoading: true})
18-
const randomDelay = Math.random() * 10000;
36+
this.setState({ isLoading: true });
37+
const randomDelay = Math.random() * 10000;
1938
setTimeout(() => {
2039
this.setState({
2140
isLoading: false,
22-
results: randomDelay
23-
})
24-
},
25-
randomDelay);
41+
results: randomDelay,
42+
});
43+
}, randomDelay);
2644
}
2745

28-
renderResults(){
29-
if(this.state.isLoading){
46+
renderResults() {
47+
if (this.state.isLoading) {
3048
return <div> Loading results...</div>;
31-
}
32-
if (!this.state.results){
33-
return (
34-
<div>No Results</div>
35-
)
3649
}
37-
return (
38-
<div>
39-
Request was delayed {this.state.results} ms
40-
</div>
41-
)
50+
if (!this.state.results) {
51+
return <div>No Results</div>;
52+
}
53+
return <div>Request was delayed {this.state.results} ms</div>;
4254
}
4355

4456
render() {
4557
return (
4658
<div>
4759
<h1>React Plugin Demo App</h1>
48-
<button onClick={() => this.buttonHandler()} style={{marginBottom: '20px'}}>
60+
<button
61+
onClick={() => this.buttonHandler()}
62+
style={{ marginBottom: '20px' }}
63+
>
4964
Make Request
5065
</button>
51-
<div id="results">
52-
{this.renderResults()}
53-
</div>
66+
<div id="results">{this.renderResults()}</div>
5467
</div>
55-
)
68+
);
5669
}
5770
}
58-
71+
5972
export default Content;

examples/react-load/preact/src/components/Home.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
119
import { Link } from 'preact-router/match';
220
import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load';
321

422
class Home extends BaseOpenTelemetryComponent {
23+
// eslint-disable-next-line class-methods-use-this
524
render() {
625
return (
726
<div>
8-
<h1>
9-
React Plugin Demo App: Preact
10-
</h1>
11-
<Link href='/test'><button>Enter</button></Link>
27+
<h1>React Plugin Demo App: Preact</h1>
28+
<Link href="/test">
29+
<button>Enter</button>
30+
</Link>
1231
</div>
13-
)
32+
);
1433
}
1534
}
1635

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
import { h, Component} from 'preact';
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
import { Component } from 'preact';
220
import { Router } from 'preact-router';
321
import Home from './Home';
422
import Content from './Content';
@@ -7,23 +25,22 @@ import Tracer from '../web-tracer';
725
Tracer('react-load-preact-examples');
826

927
export default class App extends Component {
10-
11-
/** Gets fired when the route changes.
12-
* @param {Object} event "change" event from [preact-router](http://git.io/preact-router)
13-
* @param {string} event.url The newly routed URL
14-
*/
15-
handleRoute = e => {
16-
this.currentUrl = e.url;
17-
};
28+
/** Gets fired when the route changes.
29+
* @param {Object} event "change" event from [preact-router](http://git.io/preact-router)
30+
* @param {string} event.url The newly routed URL
31+
*/
32+
handleRoute = e => {
33+
this.currentUrl = e.url;
34+
};
1835

19-
render() {
20-
return (
21-
<div id="app">
22-
<Router onChange={this.handleRoute}>
23-
<Home path="/" />
24-
<Content path="/test"/>
25-
</Router>
26-
</div>
27-
);
28-
}
36+
render() {
37+
return (
38+
<div id="app">
39+
<Router onChange={this.handleRoute}>
40+
<Home path="/" />
41+
<Content path="/test" />
42+
</Router>
43+
</div>
44+
);
45+
}
2946
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
119
import App from './components/app';
220

321
export default App;

examples/react-load/preact/src/sw.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
119
import { getFiles, setupPrecaching, setupRouting } from 'preact-cli/sw/';
220

321
setupRouting();

examples/react-load/preact/src/web-tracer.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1-
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
import {
20+
ConsoleSpanExporter,
21+
SimpleSpanProcessor,
22+
} from '@opentelemetry/sdk-trace-base';
223
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
324
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
425
import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load';
526
import { ZoneContextManager } from '@opentelemetry/context-zone';
627
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
728

8-
export default (serviceName) => {
29+
export default serviceName => {
930
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
1031
const exporter = new OTLPTraceExporter({
1132
url: 'http://localhost:4318/v1/traces',
@@ -23,7 +44,7 @@ export default (serviceName) => {
2344

2445
const tracer = provider.getTracer(serviceName);
2546

26-
BaseOpenTelemetryComponent.setTracer(serviceName)
47+
BaseOpenTelemetryComponent.setTracer(serviceName);
2748

2849
return tracer;
29-
}
50+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const baseConfig = require('../../../eslint.config');
20+
21+
module.exports = {
22+
...baseConfig,
23+
env: {
24+
browser: true,
25+
},
26+
};

0 commit comments

Comments
 (0)