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

feat: faster and less noisy zk fmt #513

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions infrastructure/zk/src/fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import * as utils from './utils';
const EXTENSIONS = ['ts', 'md', 'sol', 'js'];
const CONFIG_PATH = 'etc/prettier-config';

function prettierFlags(phaseName: string) {
phaseName = phaseName.replace('/', '-').replace('.', '');
return ` --cache --cache-location node_modules/.cache/prettier/.prettier-cache-${phaseName}`;
}
export async function prettier(extension: string, check: boolean = false) {
if (!EXTENSIONS.includes(extension)) {
throw new Error('Unsupported extension');
Expand All @@ -17,19 +21,31 @@ export async function prettier(extension: string, check: boolean = false) {
return;
}

await utils.spawn(`yarn --silent prettier --config ${CONFIG_PATH}/${extension}.js --${command} ${files}`);
await utils.spawn(
`yarn --silent prettier --config ${CONFIG_PATH}/${extension}.js --${command} ${files} ${prettierFlags(
extension
)} ${check ? '' : '> /dev/null'}`
);
}

async function prettierContracts(check: boolean, directory: string) {
await utils.spawn(
`yarn --silent --cwd ${directory} prettier:${check ? 'check' : 'fix'} ${prettierFlags(directory)} ${
check ? '' : '> /dev/null'
}`
);
}

async function prettierL1Contracts(check: boolean = false) {
await utils.spawn(`yarn --silent --cwd contracts/ethereum prettier:${check ? 'check' : 'fix'}`);
await prettierContracts(check, 'contracts/ethereum');
}

async function prettierL2Contracts(check: boolean = false) {
await utils.spawn(`yarn --silent --cwd contracts/zksync prettier:${check ? 'check' : 'fix'}`);
await prettierContracts(check, 'contracts/zksync');
}

async function prettierSystemContracts(check: boolean = false) {
await utils.spawn(`yarn --silent --cwd etc/system-contracts prettier:${check ? 'check' : 'fix'}`);
await prettierContracts(check, 'etc/system-contracts');
}

export async function rustfmt(check: boolean = false) {
Expand Down