Skip to content

Commit

Permalink
Update .prettierrc.json to include trailingComma: all to match intern…
Browse files Browse the repository at this point in the history
…al Google config
  • Loading branch information
calebegg committed Mar 21, 2024
1 parent fd270b3 commit 40d9a48
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bracketSpacing": false,
"singleQuote": true,
"trailingComma": "es5",
"trailingComma": "all",
"arrowParens": "avoid"
}
4 changes: 2 additions & 2 deletions src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function clean(options: Options): Promise<boolean> {
if (outDir === '.') {
options.logger.error(
`${chalk.red('ERROR:')} ${chalk.gray('compilerOptions.outDir')} ` +
'cannot use the value ".". That would delete all of our sources.'
'cannot use the value ".". That would delete all of our sources.',
);
return false;
}
Expand All @@ -45,7 +45,7 @@ export async function clean(options: Options): Promise<boolean> {
options.logger.error(
`${chalk.red('ERROR:')} The ${chalk.gray('clean')} command` +
` requires ${chalk.gray('compilerOptions.outDir')} to be defined in ` +
'tsconfig.json.'
'tsconfig.json.',
);
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface Options {
export type VerbFilesFunction = (
options: Options,
files: string[],
fix?: boolean
fix?: boolean,
) => Promise<boolean>;

const logger: Logger = console;
Expand Down Expand Up @@ -105,7 +105,7 @@ export async function run(verb: string, files: string[]): Promise<boolean> {
throw new Error(
`gts requires node.js 10.x or up. You are currently running
${process.version}, which is not supported. Please upgrade to
a safe, secure version of nodejs!`
a safe, secure version of nodejs!`,
);
}

Expand Down Expand Up @@ -133,7 +133,7 @@ export async function run(verb: string, files: string[]): Promise<boolean> {
'**/*.js',
'**/*.tsx',
'**/*.jsx',
'--no-error-on-unmatched-pattern'
'--no-error-on-unmatched-pattern',
);
}

Expand Down
22 changes: 11 additions & 11 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function query(
message: string,
question: string,
defaultVal: boolean,
options: Options
options: Options,
): Promise<boolean> {
if (options.yes) {
return true;
Expand All @@ -77,7 +77,7 @@ async function query(

export async function addScripts(
packageJson: PackageJson,
options: Options
options: Options,
): Promise<boolean> {
let edits = false;
const pkgManager = getPkgManagerCommand(options.yarn);
Expand Down Expand Up @@ -120,7 +120,7 @@ export async function addScripts(

export async function addDependencies(
packageJson: PackageJson,
options: Options
options: Options,
): Promise<boolean> {
let edits = false;
const deps: DefaultPackage = {
Expand Down Expand Up @@ -164,7 +164,7 @@ function formatJson(object: {}) {

async function writePackageJson(
packageJson: PackageJson,
options: Options
options: Options,
): Promise<void> {
options.logger.log('Writing package.json...');
if (!options.dryRun) {
Expand All @@ -186,7 +186,7 @@ export const ESLINT_IGNORE = 'build/\n';
async function generateConfigFile(
options: Options,
filename: string,
contents: string
contents: string,
) {
let existing;
try {
Expand All @@ -209,7 +209,7 @@ async function generateConfigFile(
`${chalk.bold(filename)} already exists`,
'Overwrite',
false,
options
options,
);
}

Expand All @@ -226,7 +226,7 @@ async function generateESLintConfig(options: Options): Promise<void> {
return generateConfigFile(
options,
'./.eslintrc.json',
formatJson(ESLINT_CONFIG)
formatJson(ESLINT_CONFIG),
);
}

Expand Down Expand Up @@ -265,7 +265,7 @@ insert_final_newline = true
}

export async function installDefaultTemplate(
options: Options
options: Options,
): Promise<boolean> {
const cwd = process.cwd();
const sourceDirName = path.join(__dirname, '../template');
Expand All @@ -287,7 +287,7 @@ export async function installDefaultTemplate(
if (tsFiles.length !== 0) {
options.logger.log(
'Target src directory already has ts files. ' +
'Template files not installed.'
'Template files not installed.',
);
return false;
}
Expand All @@ -310,7 +310,7 @@ export async function init(options: Options): Promise<boolean> {
`${chalk.bold('package.json')} does not exist.`,
'Generate',
true,
options
options,
);

if (!generate) {
Expand Down Expand Up @@ -344,7 +344,7 @@ export async function init(options: Options): Promise<boolean> {
cp.spawnSync(
getPkgManagerCommand(options.yarn),
['install', '--ignore-scripts'],
{stdio: 'inherit'}
{stdio: 'inherit'},
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function getBase(
filePath: string,
customReadFilep: ReadFileP,
readFiles: Set<string>,
currentDir: string
currentDir: string,
): Promise<ConfigFile> {
customReadFilep = customReadFilep || readFilep;

Expand Down Expand Up @@ -92,7 +92,7 @@ async function getBase(
contents.extends,
customReadFilep,
readFiles,
path.dirname(filePath)
path.dirname(filePath),
);
contents = combineTSConfig(nextFile, contents);
}
Expand All @@ -117,7 +117,7 @@ function combineTSConfig(base: ConfigFile, inherited: ConfigFile): ConfigFile {
Object.assign(
result.compilerOptions!,
base.compilerOptions!,
inherited.compilerOptions!
inherited.compilerOptions!,
);
delete result.extends;
return result;
Expand Down Expand Up @@ -161,7 +161,7 @@ export function getPkgManagerCommand(isYarnUsed?: boolean): string {
*/
export async function getTSConfig(
rootDir: string,
customReadFilep?: ReadFileP
customReadFilep?: ReadFileP,
): Promise<ConfigFile> {
customReadFilep = (customReadFilep || readFilep) as ReadFileP;
const readArr = new Set<string>();
Expand Down
18 changes: 9 additions & 9 deletions test/kitchen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('🚰 kitchen sink', () => {
// Test package.json expects a gts tarball from ../gts.tgz.
fs.copySync(
path.join(stagingPath, 'gts.tgz'),
path.join(tmpDir.name, 'gts.tgz')
path.join(tmpDir.name, 'gts.tgz'),
);
// It's important to use `-n` here because we don't want to overwrite
// the version of gts installed, as it will trigger the npm install.
Expand All @@ -91,12 +91,12 @@ describe('🚰 kitchen sink', () => {
// The `extends` field must use the local gts path.
const tsconfigJson = fs.readFileSync(
path.join(tmpDir.name, 'kitchen', 'tsconfig.json'),
'utf8'
'utf8',
);
const tsconfig = JSON.parse(tsconfigJson);
assert.deepStrictEqual(
tsconfig.extends,
'./node_modules/gts/tsconfig-google.json'
'./node_modules/gts/tsconfig-google.json',
);

// server.ts has a lint error. Should error.
Expand All @@ -113,35 +113,35 @@ describe('🚰 kitchen sink', () => {
assert.ok(
fs
.readFileSync(path.join(kitchenPath, 'package.json'), 'utf8')
.endsWith('\n')
.endsWith('\n'),
);
assert.ok(
fs
.readFileSync(path.join(kitchenPath, 'tsconfig.json'), 'utf8')
.endsWith('\n')
.endsWith('\n'),
);
assert.ok(
fs
.readFileSync(path.join(kitchenPath, '.eslintrc.json'), 'utf8')
.endsWith('\n')
.endsWith('\n'),
);
assert.ok(
fs
.readFileSync(path.join(kitchenPath, '.eslintignore'), 'utf8')
.endsWith('\n')
.endsWith('\n'),
);
assert.ok(
fs
.readFileSync(path.join(kitchenPath, '.prettierrc.js'), 'utf8')
.endsWith('\n')
.endsWith('\n'),
);
});

it('should lint before fix', async () => {
const res = await execa(
'npm',
['run', 'lint'],
Object.assign({}, {reject: false}, execOpts)
Object.assign({}, {reject: false}, execOpts),
);
assert.strictEqual(res.exitCode, 1);
assert.ok(res.stdout.includes('assigned a value but'));
Expand Down
10 changes: 5 additions & 5 deletions test/test-clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('clean', () => {
return assert.rejects(() =>
withFixtures({}, async () => {
await clean(OPTIONS);
})
}),
);
});

Expand Down Expand Up @@ -73,7 +73,7 @@ describe('clean', () => {
async () => {
const deleted = await clean(OPTIONS);
assert.strictEqual(deleted, false);
}
},
);
});

Expand All @@ -88,8 +88,8 @@ describe('clean', () => {
async () => {
const deleted = await clean(OPTIONS);
assert.strictEqual(deleted, false);
}
)
},
),
);
});

Expand All @@ -110,7 +110,7 @@ describe('clean', () => {
assert.throws(() => {
fs.accessSync(outputPath);
});
}
},
);
});
});
10 changes: 5 additions & 5 deletions test/test-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function hasExpectedScripts(packageJson: PackageJson): boolean {
return (
!!packageJson.scripts &&
['lint', 'clean', 'compile', 'fix', 'prepare', 'pretest', 'posttest'].every(
s => !!packageJson.scripts![s]
s => !!packageJson.scripts![s],
)
);
}
Expand Down Expand Up @@ -161,14 +161,14 @@ describe('init', () => {
assert.notStrictEqual(
contents,
originalContents,
'the file should have been modified'
'the file should have been modified',
);
assert.strictEqual(
contents.some,
originalContents.some,
'unrelated property should have preserved'
'unrelated property should have preserved',
);
}
},
);
});

Expand All @@ -195,7 +195,7 @@ describe('init', () => {
const contents = await readJson('./package.json');
const cmd = process.platform === 'win32' ? 'yarn.cmd' : 'yarn';
assert.strictEqual(contents.scripts.prepare, cmd + ' run compile');
}
},
);
});

Expand Down
16 changes: 8 additions & 8 deletions test/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function createFakeReadFilep(myMap: Map<string, ConfigFile>) {
}

function makeFakeFsExistsSync(
expected: PathLike[]
expected: PathLike[],
): (path: PathLike) => boolean {
return (path: PathLike) => expected.some(item => item === path);
}
Expand All @@ -58,7 +58,7 @@ describe('util', () => {

function fakeReadFilep(
configPath: string,
encoding: string
encoding: string,
): Promise<string> {
assert.strictEqual(configPath, PATH_TO_TSCONFIG);
assert.strictEqual(encoding, 'utf8');
Expand All @@ -82,7 +82,7 @@ describe('util', () => {
return assert.rejects(
() => getTSConfig(FAKE_DIRECTORY, createFakeReadFilep(myMap)),
Error,
'Circular Reference Detected'
'Circular Reference Detected',
);
});

Expand All @@ -108,7 +108,7 @@ describe('util', () => {

const contents = await getTSConfig(
FAKE_DIRECTORY,
createFakeReadFilep(myMap)
createFakeReadFilep(myMap),
);
assert.deepStrictEqual(contents, combinedConfig);
});
Expand All @@ -125,7 +125,7 @@ describe('util', () => {

const contents = await getTSConfig(
FAKE_DIRECTORY,
createFakeReadFilep(myMap)
createFakeReadFilep(myMap),
);
assert.deepStrictEqual(contents, combinedConfig);
});
Expand All @@ -145,12 +145,12 @@ describe('util', () => {
myMap.set(path.resolve(FAKE_DIRECTORY, './foo/FAKE_CONFIG2'), FAKE_CONFIG2);
myMap.set(
path.resolve(FAKE_DIRECTORY, './foo/bar/FAKE_CONFIG3'),
FAKE_CONFIG3
FAKE_CONFIG3,
);

const contents = await getTSConfig(
FAKE_DIRECTORY,
createFakeReadFilep(myMap)
createFakeReadFilep(myMap),
);
assert.deepStrictEqual(contents, combinedConfig);
});
Expand All @@ -162,7 +162,7 @@ describe('util', () => {
return assert.rejects(
() => getTSConfig(FAKE_DIRECTORY, createFakeReadFilep(myMap)),
Error,
`${FAKE_DIRECTORY}/tsconfig.json Not Found`
`${FAKE_DIRECTORY}/tsconfig.json Not Found`,
);
});

Expand Down

0 comments on commit 40d9a48

Please sign in to comment.