Skip to content

Commit c278744

Browse files
Enable prettier for "resources/*.js" files (#1875)
1 parent cabfd34 commit c278744

File tree

5 files changed

+45
-29
lines changed

5 files changed

+45
-29
lines changed

.eslintrc.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,3 @@ overrides:
363363
no-console: off
364364
no-sync: off
365365
global-require: off
366-
prettier/prettier: off #TODO

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"testonly:cover": "nyc npm run testonly",
3030
"lint": "eslint --cache --report-unused-disable-directives src resources",
3131
"benchmark": "node ./resources/benchmark.js",
32-
"prettier": "prettier --write --list-different 'src/**/*.js'",
32+
"prettier": "prettier --write --list-different 'src/**/*.js' 'resources/**/*.js'",
3333
"check": "flow check",
3434
"check-cover": "flow batch-coverage --quiet --strip-root --show-all src/ && flow stop --quiet",
3535
"build": "node resources/build.js",

resources/benchmark.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function prepareRevision(revision) {
7070
fs.copyFileSync(from, to);
7171
}
7272
execSync(
73-
`cp -R "${LOCAL_DIR()}/src/__fixtures__/" "${dir}/src/__fixtures__/"`
73+
`cp -R "${LOCAL_DIR()}/src/__fixtures__/" "${dir}/src/__fixtures__/"`,
7474
);
7575

7676
return babelBuild(dir);
@@ -109,7 +109,7 @@ function findFiles(cwd, pattern) {
109109
function runBenchmark(benchmark, environments) {
110110
let benchmarkName;
111111
const benches = environments.map(environment => {
112-
const module = require(path.join(environment.distPath, benchmark))
112+
const module = require(path.join(environment.distPath, benchmark));
113113
benchmarkName = module.name;
114114
return new Benchmark(environment.revision, module.measure);
115115
});
@@ -149,34 +149,50 @@ function beautifyBenchmark(results) {
149149
function printBench(bench) {
150150
const { name, ops, deviation, numRuns } = bench;
151151
console.log(
152-
' ' + nameStr() + grey(' x ') + opsStr() + ' ops/sec ' +
153-
grey('\xb1') + deviationStr() + cyan('%') +
154-
grey(' (' + numRuns + ' runs sampled)')
152+
' ' +
153+
nameStr() +
154+
grey(' x ') +
155+
opsStr() +
156+
' ops/sec ' +
157+
grey('\xb1') +
158+
deviationStr() +
159+
cyan('%') +
160+
grey(' (' + numRuns + ' runs sampled)'),
155161
);
156162

157163
function nameStr() {
158164
const nameFmt = name.padEnd(nameMaxLen);
159-
return (ops === opsTop) ? green(nameFmt) : nameFmt;
165+
return ops === opsTop ? green(nameFmt) : nameFmt;
160166
}
161167

162168
function opsStr() {
163169
const percent = ops / opsTop;
164-
const colorFn = percent > 0.95 ? green : (percent > 0.80 ? yellow : red);
170+
const colorFn = percent > 0.95 ? green : percent > 0.8 ? yellow : red;
165171
return colorFn(beautifyNumber(ops).padStart(opsMaxLen));
166172
}
167173

168174
function deviationStr() {
169-
const colorFn = deviation > 5 ? red : (deviation > 2 ? yellow : green);
175+
const colorFn = deviation > 5 ? red : deviation > 2 ? yellow : green;
170176
return colorFn(deviation.toFixed(2));
171177
}
172178
}
173179
}
174180

175-
function red(str) { return '\u001b[31m' + str + '\u001b[0m' }
176-
function green(str) { return '\u001b[32m' + str + '\u001b[0m' }
177-
function yellow(str) { return '\u001b[33m' + str + '\u001b[0m' }
178-
function cyan(str) { return '\u001b[36m' + str + '\u001b[0m' }
179-
function grey(str) { return '\u001b[90m' + str + '\u001b[0m' }
181+
function red(str) {
182+
return '\u001b[31m' + str + '\u001b[0m';
183+
}
184+
function green(str) {
185+
return '\u001b[32m' + str + '\u001b[0m';
186+
}
187+
function yellow(str) {
188+
return '\u001b[33m' + str + '\u001b[0m';
189+
}
190+
function cyan(str) {
191+
return '\u001b[36m' + str + '\u001b[0m';
192+
}
193+
function grey(str) {
194+
return '\u001b[90m' + str + '\u001b[0m';
195+
}
180196

181197
function beautifyNumber(num) {
182198
return Number(num.toFixed(num > 100 ? 0 : 2)).toLocaleString();
@@ -193,15 +209,15 @@ function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
193209
if (benchmarkPatterns.length !== 0) {
194210
benchmarks = benchmarks.filter(benchmark =>
195211
benchmarkPatterns.some(pattern =>
196-
path.join('src', benchmark).includes(pattern)
197-
)
212+
path.join('src', benchmark).includes(pattern),
213+
),
198214
);
199215
}
200216

201217
if (benchmarks.length === 0) {
202218
console.warn(
203219
'No benchmarks matching: ' +
204-
`\u001b[1m${benchmarkPatterns.join('\u001b[0m or \u001b[1m')}\u001b[0m`
220+
`\u001b[1m${benchmarkPatterns.join('\u001b[0m or \u001b[1m')}\u001b[0m`,
205221
);
206222
return;
207223
}
@@ -234,7 +250,7 @@ function getArguments(argv) {
234250
}
235251
if (assumeArgs) {
236252
console.warn(
237-
`Assuming you meant: \u001b[1mbenchmark ${assumeArgs.join(' ')}\u001b[0m`
253+
`Assuming you meant: \u001b[1mbenchmark ${assumeArgs.join(' ')}\u001b[0m`,
238254
);
239255
}
240256
return { benchmarkPatterns, revisions };

resources/fs-utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ function readdirRecursive(dirPath, opts = {}) {
4343
if (ignoreDir && ignoreDir.test(name)) {
4444
continue;
4545
}
46-
const list = readdirRecursive(path.join(dirPath, name), opts)
47-
.map(f => path.join(name, f));
46+
const list = readdirRecursive(path.join(dirPath, name), opts).map(f =>
47+
path.join(name, f),
48+
);
4849
result.push(...list);
4950
}
5051
return result;

resources/watch.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function exec(command, options) {
2424
const child = spawn(command, options, {
2525
cmd,
2626
env: process.env,
27-
stdio: 'inherit'
27+
stdio: 'inherit',
2828
});
2929
child.on('exit', code => {
3030
if (code === 0) {
@@ -38,7 +38,7 @@ function exec(command, options) {
3838

3939
const flowServer = spawn(flowBinPath, ['server'], {
4040
cmd,
41-
env: process.env
41+
env: process.env,
4242
});
4343

4444
const watcher = sane(srcDir, { glob: ['**/*.js', '**/*.graphql'] })
@@ -102,14 +102,14 @@ function checkFiles(filepaths) {
102102
.then(testSuccess =>
103103
lintFiles().then(lintSuccess =>
104104
typecheckStatus().then(
105-
typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess
106-
)
107-
)
105+
typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess,
106+
),
107+
),
108108
)
109109
.catch(() => false)
110110
.then(success => {
111111
process.stdout.write(
112-
'\n' + (success ? '' : '\x07') + green(invert('watching...'))
112+
'\n' + (success ? '' : '\x07') + green(invert('watching...')),
113113
);
114114
});
115115
}
@@ -123,8 +123,8 @@ function runTests(filepaths) {
123123
['--reporter', 'progress'].concat(
124124
allTests(filepaths)
125125
? filepaths.map(srcPath)
126-
: ['src/**/__tests__/**/*-test.js']
127-
)
126+
: ['src/**/__tests__/**/*-test.js'],
127+
),
128128
).catch(() => false);
129129
}
130130

0 commit comments

Comments
 (0)