Skip to content

Commit

Permalink
internal: Run Prettier on codebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles Johnson committed Mar 24, 2020
1 parent 49237a7 commit 91084fe
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions packages/config-danger/src/adr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export function checkForADR(docsPath: string, options: CheckAdrOptions = {}) {
}

const { changeThreshold = 200, docsUrl = '', exclusions = [] } = options;
const hasDocsFiles = touchedFiles.some(file => file.includes(docsPath));
const hasDocsFiles = touchedFiles.some((file) => file.includes(docsPath));
const docsExclusions = [...exclusions, 'package-lock.json', 'yarn.lock', TEST_EXT, SNAP_EXT];
const modifiedExclusions = danger.git.modified_files.filter(file =>
docsExclusions.some(ex => !!file.match(ex)),
const modifiedExclusions = danger.git.modified_files.filter((file) =>
docsExclusions.some((ex) => !!file.match(ex)),
);

Promise.all(modifiedExclusions.map(countChangesInFile)).then(vals => {
Promise.all(modifiedExclusions.map(countChangesInFile)).then((vals) => {
const totalChangeCount = danger.github.pr.additions + danger.github.pr.deletions;
const exclusionChangeCount = vals.reduce((acc, val) => acc + val, 0);
const changeCount = totalChangeCount - exclusionChangeCount;
Expand Down
16 changes: 8 additions & 8 deletions packages/config-danger/src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from './helpers';
import { CommonOptions } from './types';

const changedSrcFiles = updatedFiles.filter(file => IS_SRC.test(file) && SRC_EXT.test(file));
const changedSrcFiles = updatedFiles.filter((file) => IS_SRC.test(file) && SRC_EXT.test(file));

export type TestOptions = {
ignorePattern?: RegExp;
Expand All @@ -21,7 +21,7 @@ export type TestOptions = {

// Check for invalid NPM/Yarn installs by verifying the lock files.
export function checkForInvalidLocks() {
const fileNames = touchedFiles.map(file => path.basename(file));
const fileNames = touchedFiles.map((file) => path.basename(file));

if (fileNames.includes('package-lock.json') && !fileNames.includes('package.json')) {
fail('Your PR contains changes to package-lock.json, but not package.json.');
Expand All @@ -38,9 +38,9 @@ export function checkForAnyTests({ root, ...options }: TestOptions = {}) {
return;
}

const hasTestFiles = touchedFiles.some(file => !!file.match(TEST_EXT));
const hasTestFiles = touchedFiles.some((file) => !!file.match(TEST_EXT));
const srcFiles = root
? changedSrcFiles.filter(srcFile => srcFile.startsWith(root))
? changedSrcFiles.filter((srcFile) => srcFile.startsWith(root))
: changedSrcFiles;

if (srcFiles.length > 0 && !hasTestFiles) {
Expand All @@ -62,10 +62,10 @@ export function checkSourceFilesHaveTests({ ignorePattern, root, ...options }: T

const missingTestFiles: string[] = [];
const srcFiles = root
? changedSrcFiles.filter(srcFile => srcFile.startsWith(root))
? changedSrcFiles.filter((srcFile) => srcFile.startsWith(root))
: changedSrcFiles;

srcFiles.forEach(srcFile => {
srcFiles.forEach((srcFile) => {
if ((ignorePattern && srcFile.match(ignorePattern)) || srcFile.match(GLOBAL_IGNORE)) {
return;
}
Expand All @@ -84,7 +84,7 @@ export function checkSourceFilesHaveTests({ ignorePattern, root, ...options }: T

const regex = new RegExp(testFile);

updatedFiles.forEach(file => {
updatedFiles.forEach((file) => {
if (file.match(regex)) {
missingTestFiles.push(`- ${srcFile.split(IS_SRC)[1]}`);
}
Expand Down Expand Up @@ -138,7 +138,7 @@ export function disableComponentSnapshots(options: SnapshotOptions = {}) {
// Disable new JavaScript files from being created.
export function disableNewJavaScript() {
const hasJS = danger.git.created_files.some(
file => (IS_SRC.test(file) || IS_TEST.test(file)) && JS_EXT.test(file),
(file) => (IS_SRC.test(file) || IS_TEST.test(file)) && JS_EXT.test(file),
);

if (hasJS) {
Expand Down
4 changes: 2 additions & 2 deletions packages/config-danger/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export function isRevert(): boolean {
}

export async function countChangesInFile(file: string): Promise<number> {
return new Promise(resolve => {
danger.git.diffForFile(file).then(d => {
return new Promise((resolve) => {
danger.git.diffForFile(file).then((d) => {
const added = (d?.added && d.added.split('\n').length) || 0;
const removed = (d?.removed && d.removed.split('\n').length) || 0;

Expand Down
8 changes: 4 additions & 4 deletions packages/config-jest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export interface JestOptions {
workspaces?: string[];
}

const exts = EXTS.map(ext => ext.slice(1));
const extsWithoutJSON = exts.filter(ext => ext !== 'json');
const exts = EXTS.map((ext) => ext.slice(1));
const extsWithoutJSON = exts.filter((ext) => ext !== 'json');

function fromHere(filePath: string): string {
return `<rootDir>/${new Path(process.cwd()).relativeTo(
Expand Down Expand Up @@ -46,7 +46,7 @@ export function getConfig({
const setupFilesAfterEnv = [fromHere('bootstrap/consumer.js')];

if (workspaces.length > 0) {
workspaces.forEach(wsPath => {
workspaces.forEach((wsPath) => {
roots.push(new Path('<rootDir>', wsPath.replace('/*', '')).path());
});
} else {
Expand All @@ -66,7 +66,7 @@ export function getConfig({
bail: false,
collectCoverageFrom: [createCoveragePattern(srcFolder), createCoveragePattern(testFolder)],
coverageDirectory: './coverage',
coveragePathIgnorePatterns: IGNORE_PATHS.filter(ignore => !ignore.startsWith('*')),
coveragePathIgnorePatterns: IGNORE_PATHS.filter((ignore) => !ignore.startsWith('*')),
coverageReporters: ['lcov', 'json-summary', 'html'],
coverageThreshold: {
global: {
Expand Down
4 changes: 2 additions & 2 deletions packages/config-webpack/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function getESMAliases(): AliasMap {
onlyDirectories: true,
onlyFiles: false,
})
.forEach(modulePath => {
.forEach((modulePath) => {
const packageName = modulePath.split('/node_modules/')[1];
const esLessName = packageName.replace(/-es$/, '');
const esPath = new Path(modulePath, 'es');
Expand All @@ -57,7 +57,7 @@ export function getESMAliases(): AliasMap {
// optimal/lib -> optimal/esm
if (esPath.exists() || esmPath.exists()) {
const aliasPath = esPath.exists() ? `${packageName}/es` : `${packageName}/esm`;
const aliased = buildTargets.some(targetFolder => {
const aliased = buildTargets.some((targetFolder) => {
if (new Path(modulePath, targetFolder).exists()) {
aliases[`${packageName}/${targetFolder}`] = aliasPath;

Expand Down
4 changes: 2 additions & 2 deletions packages/nimbus-common/src/git.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import execa from 'execa';

export function getLastTag(): Promise<string> {
return execa('git', ['describe', '--tags', '--abbrev=0', '@^']).then(response =>
return execa('git', ['describe', '--tags', '--abbrev=0', '@^']).then((response) =>
response.stdout.trim(),
);
}

export function getCommitsSince(since: string): Promise<string[]> {
return execa('git', ['log', '--oneline', `${since}..@`]).then(response =>
return execa('git', ['log', '--oneline', `${since}..@`]).then((response) =>
response.stdout.trim().split('\n'),
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nimbus/hooks/checkNodeVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { getPackage } = require('@airbnb/nimbus-common');

// Only run if the engines block is defined
if (getPackage().engines) {
execa('check-node-version', ['--package'], { preferLocal: true }).catch(error => {
execa('check-node-version', ['--package'], { preferLocal: true }).catch((error) => {
console.error();
console.error(chalk.red(error.stderr.trim()));
console.error();
Expand Down
2 changes: 1 addition & 1 deletion packages/nimbus/hooks/detectModuleChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ execa('git', ['diff-tree', '-r', '--name-only', remoteHead, branchHead])
);
}
})
.catch(error => {
.catch((error) => {
console.log('\n ', chalk.red(`🛑 Failed to detect module changes: ${error.message}`), ' \n');
});
10 changes: 5 additions & 5 deletions packages/nimbus/src/bins/eject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function copyAndInstallDepsFromModule(
) {
const pkg = require(`${moduleName}/package.json`);
const deps = Object.keys(pkg.dependencies).filter(
dep => !dep.includes('@beemo') && !dep.includes('@airbnb/nimbus'),
(dep) => !dep.includes('@beemo') && !dep.includes('@airbnb/nimbus'),
);

await installDeps(deps, isYarn, isMonorepo);
Expand Down Expand Up @@ -63,7 +63,7 @@ function migrateDotfiles() {
const dotPath = Path.resolve('.gitignore').path();
let data = fs.readFileSync(dotPath, 'utf8');

toRemove.forEach(value => {
toRemove.forEach((value) => {
data = data.replace(new RegExp(`${escapeRegExp(value)}\n?`, 'g'), '');
});

Expand All @@ -87,7 +87,7 @@ function migratePackageScripts(nimbus: NimbusPackage['nimbus']) {
delete scripts.release;
}

Object.keys(scripts).forEach(key => {
Object.keys(scripts).forEach((key) => {
const value = scripts[key];
const esm = value.includes('--esm');

Expand Down Expand Up @@ -119,7 +119,7 @@ function migrateEslint() {
const { extends: extendPaths, ...rootConfig } = require(configPath);
let config: { extends: string[]; parserOptions?: object } = { extends: [] };

(extendPaths as string[]).forEach(extendPath => {
(extendPaths as string[]).forEach((extendPath) => {
if (extendPath.startsWith('.')) {
config = {
...config,
Expand Down Expand Up @@ -236,7 +236,7 @@ export async function eject() {

pkg.set(
'nimbus.drivers',
(pkg.get('nimbus.drivers') as string[]).filter(d => d !== driver),
(pkg.get('nimbus.drivers') as string[]).filter((d) => d !== driver),
);
pkg.save();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nimbus/src/bins/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export async function setup() {
console.log(`${chalk.cyan('[3/6]')} Installing dependencies`);

await installDeps(
['@airbnb/nimbus', ...response.drivers.map(driver => `@airbnb/config-${driver}`)],
['@airbnb/nimbus', ...response.drivers.map((driver) => `@airbnb/config-${driver}`)],
response.yarn,
response.type === 'monolib',
);
Expand Down
8 changes: 4 additions & 4 deletions packages/nimbus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function hasNoPositionalArgs(context: DriverContext, name: string): boolean {
}

function createWorkspacesGlob(workspaces: string[]): string {
const paths = workspaces.map(p => p.replace('./', ''));
const paths = workspaces.map((p) => p.replace('./', ''));

return paths.length === 1 ? `${paths[0]}/` : `{${paths.join(',')}}/`;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ export default function nimbus(tool: Beemo) {
}

// Create a specialized tsconfig for ESLint
driver.onCreateConfigFile.listen(createContext => {
driver.onCreateConfigFile.listen((createContext) => {
if (!usingTypeScript) {
return;
}
Expand All @@ -81,7 +81,7 @@ export default function nimbus(tool: Beemo) {
} else {
extendsFrom = './tsconfig.options.json';

workspaces.forEach(ws => {
workspaces.forEach((ws) => {
const wsPath = new Path(ws);

include.push(
Expand Down Expand Up @@ -139,7 +139,7 @@ export default function nimbus(tool: Beemo) {
* - Always write files.
* - Glob a ton of files by default.
*/
tool.onRunDriver.listen(context => {
tool.onRunDriver.listen((context) => {
context.addOption('--write');

if (hasNoPositionalArgs(context, 'prettier')) {
Expand Down
4 changes: 2 additions & 2 deletions packages/nimbus/src/scripts/AutoRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class AutoReleaseScript extends Script {

handleCommand(promise: Promise<ExecaReturnValue>): Promise<ExecaReturnValue> {
return promise
.then(response => {
.then((response) => {
const out = response.stdout.trim();

if (out) {
Expand All @@ -90,7 +90,7 @@ export default class AutoReleaseScript extends Script {

return response;
})
.catch(error => {
.catch((error) => {
this.tool.log.error(error.stderr);

throw error;
Expand Down
2 changes: 1 addition & 1 deletion packages/nimbus/src/scripts/PullRequestChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class PullRequestChecksScript extends Script {
pull_number: Number(TRAVIS_PULL_REQUEST),
});

const fileNames = new Set(files.map(file => path.basename(file.filename)));
const fileNames = new Set(files.map((file) => path.basename(file.filename)));
const hasPackageChanges = fileNames.has('package.json');

// this.tool.log('Changed files: %s', Array.from(fileNames).join(', '));
Expand Down

0 comments on commit 91084fe

Please sign in to comment.