Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable prettier for "resources/*.js" files #1875

Merged
merged 1 commit into from May 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.yml
Expand Up @@ -363,4 +363,3 @@ overrides:
no-console: off
no-sync: off
global-require: off
prettier/prettier: off #TODO
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -29,7 +29,7 @@
"testonly:cover": "nyc npm run testonly",
"lint": "eslint --cache --report-unused-disable-directives src resources",
"benchmark": "node ./resources/benchmark.js",
"prettier": "prettier --write --list-different 'src/**/*.js'",
"prettier": "prettier --write --list-different 'src/**/*.js' 'resources/**/*.js'",
"check": "flow check",
"check-cover": "flow batch-coverage --quiet --strip-root --show-all src/ && flow stop --quiet",
"build": "node resources/build.js",
Expand Down
50 changes: 33 additions & 17 deletions resources/benchmark.js
Expand Up @@ -70,7 +70,7 @@ function prepareRevision(revision) {
fs.copyFileSync(from, to);
}
execSync(
`cp -R "${LOCAL_DIR()}/src/__fixtures__/" "${dir}/src/__fixtures__/"`
`cp -R "${LOCAL_DIR()}/src/__fixtures__/" "${dir}/src/__fixtures__/"`,
);

return babelBuild(dir);
Expand Down Expand Up @@ -109,7 +109,7 @@ function findFiles(cwd, pattern) {
function runBenchmark(benchmark, environments) {
let benchmarkName;
const benches = environments.map(environment => {
const module = require(path.join(environment.distPath, benchmark))
const module = require(path.join(environment.distPath, benchmark));
benchmarkName = module.name;
return new Benchmark(environment.revision, module.measure);
});
Expand Down Expand Up @@ -149,34 +149,50 @@ function beautifyBenchmark(results) {
function printBench(bench) {
const { name, ops, deviation, numRuns } = bench;
console.log(
' ' + nameStr() + grey(' x ') + opsStr() + ' ops/sec ' +
grey('\xb1') + deviationStr() + cyan('%') +
grey(' (' + numRuns + ' runs sampled)')
' ' +
nameStr() +
grey(' x ') +
opsStr() +
' ops/sec ' +
grey('\xb1') +
deviationStr() +
cyan('%') +
grey(' (' + numRuns + ' runs sampled)'),
);

function nameStr() {
const nameFmt = name.padEnd(nameMaxLen);
return (ops === opsTop) ? green(nameFmt) : nameFmt;
return ops === opsTop ? green(nameFmt) : nameFmt;
}

function opsStr() {
const percent = ops / opsTop;
const colorFn = percent > 0.95 ? green : (percent > 0.80 ? yellow : red);
const colorFn = percent > 0.95 ? green : percent > 0.8 ? yellow : red;
return colorFn(beautifyNumber(ops).padStart(opsMaxLen));
}

function deviationStr() {
const colorFn = deviation > 5 ? red : (deviation > 2 ? yellow : green);
const colorFn = deviation > 5 ? red : deviation > 2 ? yellow : green;
return colorFn(deviation.toFixed(2));
}
}
}

function red(str) { return '\u001b[31m' + str + '\u001b[0m' }
function green(str) { return '\u001b[32m' + str + '\u001b[0m' }
function yellow(str) { return '\u001b[33m' + str + '\u001b[0m' }
function cyan(str) { return '\u001b[36m' + str + '\u001b[0m' }
function grey(str) { return '\u001b[90m' + str + '\u001b[0m' }
function red(str) {
return '\u001b[31m' + str + '\u001b[0m';
}
function green(str) {
return '\u001b[32m' + str + '\u001b[0m';
}
function yellow(str) {
return '\u001b[33m' + str + '\u001b[0m';
}
function cyan(str) {
return '\u001b[36m' + str + '\u001b[0m';
}
function grey(str) {
return '\u001b[90m' + str + '\u001b[0m';
}

function beautifyNumber(num) {
return Number(num.toFixed(num > 100 ? 0 : 2)).toLocaleString();
Expand All @@ -193,15 +209,15 @@ function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
if (benchmarkPatterns.length !== 0) {
benchmarks = benchmarks.filter(benchmark =>
benchmarkPatterns.some(pattern =>
path.join('src', benchmark).includes(pattern)
)
path.join('src', benchmark).includes(pattern),
),
);
}

if (benchmarks.length === 0) {
console.warn(
'No benchmarks matching: ' +
`\u001b[1m${benchmarkPatterns.join('\u001b[0m or \u001b[1m')}\u001b[0m`
`\u001b[1m${benchmarkPatterns.join('\u001b[0m or \u001b[1m')}\u001b[0m`,
);
return;
}
Expand Down Expand Up @@ -234,7 +250,7 @@ function getArguments(argv) {
}
if (assumeArgs) {
console.warn(
`Assuming you meant: \u001b[1mbenchmark ${assumeArgs.join(' ')}\u001b[0m`
`Assuming you meant: \u001b[1mbenchmark ${assumeArgs.join(' ')}\u001b[0m`,
);
}
return { benchmarkPatterns, revisions };
Expand Down
5 changes: 3 additions & 2 deletions resources/fs-utils.js
Expand Up @@ -43,8 +43,9 @@ function readdirRecursive(dirPath, opts = {}) {
if (ignoreDir && ignoreDir.test(name)) {
continue;
}
const list = readdirRecursive(path.join(dirPath, name), opts)
.map(f => path.join(name, f));
const list = readdirRecursive(path.join(dirPath, name), opts).map(f =>
path.join(name, f),
);
result.push(...list);
}
return result;
Expand Down
16 changes: 8 additions & 8 deletions resources/watch.js
Expand Up @@ -24,7 +24,7 @@ function exec(command, options) {
const child = spawn(command, options, {
cmd,
env: process.env,
stdio: 'inherit'
stdio: 'inherit',
});
child.on('exit', code => {
if (code === 0) {
Expand All @@ -38,7 +38,7 @@ function exec(command, options) {

const flowServer = spawn(flowBinPath, ['server'], {
cmd,
env: process.env
env: process.env,
});

const watcher = sane(srcDir, { glob: ['**/*.js', '**/*.graphql'] })
Expand Down Expand Up @@ -102,14 +102,14 @@ function checkFiles(filepaths) {
.then(testSuccess =>
lintFiles().then(lintSuccess =>
typecheckStatus().then(
typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess
)
)
typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess,
),
),
)
.catch(() => false)
.then(success => {
process.stdout.write(
'\n' + (success ? '' : '\x07') + green(invert('watching...'))
'\n' + (success ? '' : '\x07') + green(invert('watching...')),
);
});
}
Expand All @@ -123,8 +123,8 @@ function runTests(filepaths) {
['--reporter', 'progress'].concat(
allTests(filepaths)
? filepaths.map(srcPath)
: ['src/**/__tests__/**/*-test.js']
)
: ['src/**/__tests__/**/*-test.js'],
),
).catch(() => false);
}

Expand Down