Skip to content

Commit fd910a1

Browse files
committed
Linting/formatting
1 parent 7d51edd commit fd910a1

File tree

4 files changed

+162
-181
lines changed

4 files changed

+162
-181
lines changed

devtools/regl_codegen/server.mjs

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ var args = minimist(process.argv.slice(2), {});
1313
var PORT = args.port || 3000;
1414
var strict = args.strict;
1515

16-
var reglTraceList = [
17-
'parcoords',
18-
'scattergl',
19-
'scatterpolargl',
20-
'splom'
21-
];
22-
23-
16+
var reglTraceList = ['parcoords', 'scattergl', 'scatterpolargl', 'splom'];
2417

2518
// Create server
2619
var _static = ecstatic({
@@ -32,21 +25,21 @@ var _static = ecstatic({
3225

3326
var tracesReceived = [];
3427

35-
var server = http.createServer(function(req, res) {
36-
if(req.method === 'POST' && req.url === '/api/submit-code') {
28+
var server = http.createServer(function (req, res) {
29+
if (req.method === 'POST' && req.url === '/api/submit-code') {
3730
var body = '';
38-
req.on('data', function(data) {
31+
req.on('data', function (data) {
3932
body += data;
4033
});
41-
req.on('end', function() {
34+
req.on('end', function () {
4235
var data = JSON.parse(body);
4336

4437
tracesReceived.push(data.trace);
4538
handleCodegen(data);
4639
res.statusCode = 200;
4740
res.end();
4841
});
49-
} else if(req.method === 'GET' && req.url === '/api/codegen-done') {
42+
} else if (req.method === 'GET' && req.url === '/api/codegen-done') {
5043
console.log('Codegen complete');
5144
console.log('Traces received:', tracesReceived);
5245

@@ -79,9 +72,9 @@ config.minify = false;
7972
await build(config);
8073

8174
function getMockFiles() {
82-
return new Promise(function(resolve, reject) {
83-
fs.readdir(constants.pathToTestImageMocks, function(err, files) {
84-
if(err) {
75+
return new Promise(function (resolve, reject) {
76+
fs.readdir(constants.pathToTestImageMocks, function (err, files) {
77+
if (err) {
8578
reject(err);
8679
} else {
8780
resolve(files);
@@ -91,7 +84,7 @@ function getMockFiles() {
9184
}
9285

9386
function readFiles(files) {
94-
var promises = files.map(function(file) {
87+
var promises = files.map(function (file) {
9588
var filePath = path.join(constants.pathToTestImageMocks, file);
9689
return readFilePromise(filePath);
9790
});
@@ -101,22 +94,24 @@ function readFiles(files) {
10194

10295
function createMocksList(files) {
10396
// eliminate pollutants (e.g .DS_Store) that can accumulate in the mock directory
104-
var jsonFiles = files.filter(function(file) {
97+
var jsonFiles = files.filter(function (file) {
10598
return file.name.substr(-5) === '.json';
10699
});
107100

108-
var mocksList = jsonFiles.map(function(file) {
101+
var mocksList = jsonFiles.map(function (file) {
109102
var contents = JSON.parse(file.contents);
110103

111104
// get plot type keywords from mocks
112-
var types = contents.data.map(function(trace) {
113-
return trace.type || 'scatter';
114-
}).reduce(function(acc, type, i, arr) {
115-
if(arr.lastIndexOf(type) === i) {
116-
acc.push(type);
117-
}
118-
return acc;
119-
}, []);
105+
var types = contents.data
106+
.map(function (trace) {
107+
return trace.type || 'scatter';
108+
})
109+
.reduce(function (acc, type, i, arr) {
110+
if (arr.lastIndexOf(type) === i) {
111+
acc.push(type);
112+
}
113+
return acc;
114+
}, []);
120115

121116
var filename = file.name.split(path.sep).pop();
122117

@@ -145,9 +140,9 @@ function saveReglTracesToFile(traces) {
145140
}
146141

147142
function readFilePromise(file) {
148-
return new Promise(function(resolve, reject) {
149-
fs.readFile(file, { encoding: 'utf-8' }, function(err, contents) {
150-
if(err) {
143+
return new Promise(function (resolve, reject) {
144+
fs.readFile(file, { encoding: 'utf-8' }, function (err, contents) {
145+
if (err) {
151146
reject(err);
152147
} else {
153148
resolve({
@@ -160,9 +155,9 @@ function readFilePromise(file) {
160155
}
161156

162157
function writeFilePromise(path, contents) {
163-
return new Promise(function(resolve, reject) {
164-
fs.writeFile(path, contents, function(err) {
165-
if(err) {
158+
return new Promise(function (resolve, reject) {
159+
fs.writeFile(path, contents, function (err) {
160+
if (err) {
166161
reject(err);
167162
} else {
168163
resolve(path);
@@ -178,31 +173,23 @@ function handleCodegen(data) {
178173
var pathToReglCodegenSrc = constants.pathToReglCodegenSrc;
179174
var pathToReglPrecompiledSrc = path.join(constants.pathToSrc, 'traces', trace, 'regl_precompiled.js');
180175

181-
var header = [
182-
'\'use strict\';',
183-
'',
184-
].join('\n');
176+
var header = ["'use strict';", ''].join('\n');
185177
var imports = '';
186-
var exports = [
187-
'',
188-
'/* eslint-disable quote-props */',
189-
'module.exports = {',
190-
'',
191-
].join('\n');
178+
var exports = ['', '/* eslint-disable quote-props */', 'module.exports = {', ''].join('\n');
192179
var varId = 0;
193180

194-
Object.entries(generated).forEach(function(kv) {
181+
Object.entries(generated).forEach(function (kv) {
195182
var key = kv[0];
196183
var value = kv[1];
197184
var filePath = path.join(pathToReglCodegenSrc, key);
198185
fs.writeFileSync(filePath, 'module.exports = ' + value);
199186

200-
imports += 'var v' + varId + ' = require(\'../../' + path.join(constants.reglCodegenSubdir, key) + '\');\n';
201-
exports += ' \'' + key + '\': v' + varId + ',\n';
187+
imports += 'var v' + varId + " = require('../../" + path.join(constants.reglCodegenSubdir, key) + "');\n";
188+
exports += " '" + key + "': v" + varId + ',\n';
202189
varId++;
203190
});
204191

205-
if(varId > 0) {
192+
if (varId > 0) {
206193
exports = exports.slice(0, -2) + '\n};\n';
207194
} else {
208195
exports = 'module.exports = {};\n';

devtools/test_dashboard/server.mjs

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs';
2-
import path from 'path';
2+
import path from 'path';
33
import http from 'http';
44
import ecstatic from 'ecstatic';
55
import open from 'open';
@@ -17,7 +17,7 @@ var strict = args.strict;
1717
var mathjax3 = args.mathjax3;
1818
var mathjax3chtml = args.mathjax3chtml;
1919

20-
if(strict) {
20+
if (strict) {
2121
config.entryPoints = ['./lib/index-strict.js'];
2222
}
2323

@@ -26,16 +26,11 @@ config.outfile = './build/plotly.js';
2626
var mockFolder = constants.pathToTestImageMocks;
2727

2828
// mock list
29-
await getMockFiles()
30-
.then(readFiles)
31-
.then(createMocksList)
32-
.then(saveMockListToFile);
29+
await getMockFiles().then(readFiles).then(createMocksList).then(saveMockListToFile);
3330

3431
// Devtools config
3532
var devtoolsConfig = {
36-
entryPoints: [
37-
path.join(constants.pathToRoot, 'devtools', 'test_dashboard', 'devtools.js')
38-
],
33+
entryPoints: [path.join(constants.pathToRoot, 'devtools', 'test_dashboard', 'devtools.js')],
3934
outfile: path.join(constants.pathToRoot, 'build', 'test_dashboard-bundle.js'),
4035
format: 'cjs',
4136
globalName: 'Tabs',
@@ -44,14 +39,14 @@ var devtoolsConfig = {
4439
sourcemap: false,
4540
plugins: [
4641
glsl({
47-
minify: true,
48-
}),
42+
minify: true
43+
})
4944
],
5045
define: {
51-
global: 'window',
46+
global: 'window'
5247
},
5348
target: 'es2016',
54-
logLevel: 'info',
49+
logLevel: 'info'
5550
};
5651

5752
build(devtoolsConfig);
@@ -70,7 +65,7 @@ function devServer() {
7065
});
7166

7267
const server = http.createServer((req, res) => {
73-
if(strict) {
68+
if (strict) {
7469
res.setHeader(
7570
'Content-Security-Policy',
7671
// Comment/uncomment for testing CSP. Changes require a server restart.
@@ -83,30 +78,30 @@ function devServer() {
8378
// "connect-src 'self'",
8479
// "object-src 'none'",
8580
// "base-uri 'self';",
86-
"worker-src blob:",
87-
].join("; ")
88-
)
81+
'worker-src blob:'
82+
].join('; ')
83+
);
8984
}
9085

91-
staticFilesHandler(req, res)
92-
})
86+
staticFilesHandler(req, res);
87+
});
9388

9489
// Start the server up!
9590
server.listen(PORT);
9691

9792
let indexName = 'index';
98-
if(mathjax3) indexName += '-mathjax3'
99-
else if(mathjax3chtml) indexName += '-mathjax3chtml'
100-
indexName += '.html'
93+
if (mathjax3) indexName += '-mathjax3';
94+
else if (mathjax3chtml) indexName += '-mathjax3chtml';
95+
indexName += '.html';
10196

10297
// open up browser window
10398
open(`http://localhost:${PORT}/devtools/test_dashboard/${indexName}${strict ? '?strict=true' : ''}`);
10499
}
105100

106101
function getMockFiles() {
107-
return new Promise(function(resolve, reject) {
108-
fs.readdir(mockFolder, function(err, files) {
109-
if(err) {
102+
return new Promise(function (resolve, reject) {
103+
fs.readdir(mockFolder, function (err, files) {
104+
if (err) {
110105
reject(err);
111106
} else {
112107
resolve(files);
@@ -116,7 +111,7 @@ function getMockFiles() {
116111
}
117112

118113
function readFiles(files) {
119-
var promises = files.map(function(file) {
114+
var promises = files.map(function (file) {
120115
var filePath = path.join(mockFolder, file);
121116
return readFilePromise(filePath);
122117
});
@@ -126,22 +121,24 @@ function readFiles(files) {
126121

127122
function createMocksList(files) {
128123
// eliminate pollutants (e.g .DS_Store) that can accumulate in the mock directory
129-
var jsonFiles = files.filter(function(file) {
124+
var jsonFiles = files.filter(function (file) {
130125
return file.name.substr(-5) === '.json';
131126
});
132127

133-
var mocksList = jsonFiles.map(function(file) {
128+
var mocksList = jsonFiles.map(function (file) {
134129
var contents = JSON.parse(file.contents);
135130

136131
// get plot type keywords from mocks
137-
var types = contents.data.map(function(trace) {
138-
return trace.type || 'scatter';
139-
}).reduce(function(acc, type, i, arr) {
140-
if(arr.lastIndexOf(type) === i) {
141-
acc.push(type);
142-
}
143-
return acc;
144-
}, []);
132+
var types = contents.data
133+
.map(function (trace) {
134+
return trace.type || 'scatter';
135+
})
136+
.reduce(function (acc, type, i, arr) {
137+
if (arr.lastIndexOf(type) === i) {
138+
acc.push(type);
139+
}
140+
return acc;
141+
}, []);
145142

146143
var filename = file.name.split(path.sep).pop();
147144

@@ -163,9 +160,9 @@ function saveMockListToFile(mocksList) {
163160
}
164161

165162
function readFilePromise(file) {
166-
return new Promise(function(resolve, reject) {
167-
fs.readFile(file, { encoding: 'utf-8' }, function(err, contents) {
168-
if(err) {
163+
return new Promise(function (resolve, reject) {
164+
fs.readFile(file, { encoding: 'utf-8' }, function (err, contents) {
165+
if (err) {
169166
reject(err);
170167
} else {
171168
resolve({
@@ -178,9 +175,9 @@ function readFilePromise(file) {
178175
}
179176

180177
function writeFilePromise(path, contents) {
181-
return new Promise(function(resolve, reject) {
182-
fs.writeFile(path, contents, function(err) {
183-
if(err) {
178+
return new Promise(function (resolve, reject) {
179+
fs.writeFile(path, contents, function (err) {
180+
if (err) {
184181
reject(err);
185182
} else {
186183
resolve(path);

tasks/util/bundle_wrapper.mjs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ export default async function _bundle(pathToIndex, pathToBundle, opts, cb) {
3535
config.outfile = pathToBundle;
3636
config.minify = !!opts.minify;
3737

38-
if(!opts.noCompressAttributes) {
38+
if (!opts.noCompressAttributes) {
3939
config.plugins = basePlugins.concat([esbuildPluginStripMeta]);
4040
}
4141

42-
if(opts.noPlugins) config.plugins = [];
42+
if (opts.noPlugins) config.plugins = [];
4343

4444
await build(config);
4545

4646
addWrapper(pathToBundle);
4747

48-
if(cb) cb();
48+
if (cb) cb();
4949
}
5050

5151
// Until https://github.com/evanw/esbuild/pull/513 is merged
@@ -67,14 +67,5 @@ function addWrapper(path) {
6767
common.throwOnError
6868
);
6969

70-
fsExtra.appendFile(
71-
path,
72-
[
73-
'',
74-
'window.Plotly = Plotly;',
75-
'return Plotly;',
76-
'}));',
77-
].join('\n'),
78-
common.throwOnError
79-
);
70+
fsExtra.appendFile(path, ['', 'window.Plotly = Plotly;', 'return Plotly;', '}));'].join('\n'), common.throwOnError);
8071
}

0 commit comments

Comments
 (0)