Skip to content

Commit

Permalink
feat!: Update '.prettierrc.json' to include trailingComma: "all" to…
Browse files Browse the repository at this point in the history
… match internal Google config (#822)

* feat: Update .prettierrc.json's trailingComma

Use value 'all' to match internal Google config

* chore: bump semver

* style: lint

* refactor: Update package.json

No need to manually bump the version, a bot will create the release PR and handle versioning

---------

Co-authored-by: Daniel Bankhead <dan@danielbankhead.com>
Co-authored-by: Daniel Bankhead <danielbankhead@google.com>
  • Loading branch information
3 people authored Oct 10, 2024
1 parent a6d5e6a commit 27d0d93
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 54 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
17 changes: 8 additions & 9 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 Expand Up @@ -169,16 +169,15 @@ if (cli.input.length < 1) {
usage();
}

run(cli.input[0], cli.input.slice(1)).then(
success => {
run(cli.input[0], cli.input.slice(1))
.then(success => {
if (!success) {
// eslint-disable-next-line n/no-process-exit
process.exit(1);
}
},
e => {
})
.catch(e => {
console.error(e);
// eslint-disable-next-line n/no-process-exit
process.exit(1);
}
);
});
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 @@ -348,7 +348,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 @@ -61,7 +61,7 @@ async function getBase(
filePath: string,
customReadFilep: ReadFileP,
readFiles: Set<string>,
currentDir: string
currentDir: string,
): Promise<ConfigFile> {
customReadFilep = customReadFilep || readFilep;

Expand Down Expand Up @@ -90,7 +90,7 @@ async function getBase(
contents.extends,
customReadFilep,
readFiles,
path.dirname(filePath)
path.dirname(filePath),
);
contents = combineTSConfig(nextFile, contents);
}
Expand All @@ -115,7 +115,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 @@ -159,7 +159,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 @@ -84,7 +84,7 @@ action('🚰 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 @@ -93,12 +93,12 @@ action('🚰 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 @@ -115,35 +115,35 @@ action('🚰 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
Loading

0 comments on commit 27d0d93

Please sign in to comment.