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

chore: synchronise linting rules of repositories #312

Closed
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ build/
dist/
volumes/
.tslintrc.js
bellman-cuda
bellman-cuda

# Ignore contract submodules
contracts
etc/system-contracts
4 changes: 4 additions & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Ignore submodule
bellman-cuda

# Ignore contract submodules
contracts
etc/system-contracts
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ bellman-cuda
sdk/zksync-rs/CHANGELOG.md
CHANGELOG.md

# ignore era-contracts, since they have their own formatting CI
# Ignore contract submodules
contracts
etc/system-contracts
3 changes: 3 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore contract submodules
contracts
etc/system-contracts
3 changes: 2 additions & 1 deletion etc/lint-config/sol.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
//
// TODO (ZKS-329): Turn on the majority of the rules and make the solhint comply with them.
"state-visibility": "off",
"func-visibility": ["warn", { "ignoreConstructors": true }],
"var-name-mixedcase": "off",
"avoid-call-value": "off",
"no-empty-blocks": "off",
Expand All @@ -20,6 +21,6 @@ module.exports = {
"func-name-mixedcase": "off",
"no-unused-vars": "off",
"max-states-count": "off",
"compiler-version": ["warn", "^0.7.0"]
"compiler-version": ["warn", "^0.8.0"]
}
};
39 changes: 34 additions & 5 deletions infrastructure/zk/src/fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ export async function prettier(extension: string, check: boolean = false) {
await utils.spawn(`yarn --silent prettier --config ${CONFIG_PATH}/${extension}.js --${command} ${files}`);
}

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

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

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

export async function rustfmt(check: boolean = false) {
process.chdir(process.env.ZKSYNC_HOME as string);
const command = check ? 'cargo fmt -- --check' : 'cargo fmt';
Expand All @@ -28,21 +40,38 @@ export async function rustfmt(check: boolean = false) {
await utils.spawn(command);
}

const ARGS = [...EXTENSIONS, 'rust', 'l1-contracts', 'l2-contracts', 'system-contracts'];

export const command = new Command('fmt')
.description('format code with prettier & rustfmt')
.option('--check')
.arguments('[extension]')
.arguments(`[extension] ${ARGS.join('|')}`)
.action(async (extension: string | null, cmd: Command) => {
if (extension) {
if (extension == 'rust') {
await rustfmt(cmd.check);
} else {
await prettier(extension, cmd.check);
switch (extension) {
case 'rust':
await rustfmt(cmd.check);
break;
case 'l1-contracts':
await prettierL1Contracts(cmd.check);
break;
case 'l2-contracts':
await prettierL2Contracts(cmd.check);
break;
case 'system-contracts':
await prettierSystemContracts(cmd.check);
break;
default:
await prettier(extension, cmd.check);
break;
}
} else {
// Run all the checks concurrently.
const promises = EXTENSIONS.map((ext) => prettier(ext, cmd.check));
promises.push(rustfmt(cmd.check));
promises.push(prettierL1Contracts(cmd.check));
promises.push(prettierL2Contracts(cmd.check));
promises.push(prettierSystemContracts(cmd.check));
await Promise.all(promises);
}
});
Expand Down
57 changes: 40 additions & 17 deletions infrastructure/zk/src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ const EXTENSIONS = Object.keys(LINT_COMMANDS);
const CONFIG_PATH = 'etc/lint-config';

export async function lint(extension: string, check: boolean = false) {
if (extension == 'rust') {
await clippy();
return;
}

if (extension == 'prover') {
await proverClippy();
return;
}

if (!EXTENSIONS.includes(extension)) {
throw new Error('Unsupported extension');
}
Expand All @@ -34,6 +24,18 @@ export async function lint(extension: string, check: boolean = false) {
await utils.spawn(`yarn --silent ${command} ${fixOption} --config ${CONFIG_PATH}/${extension}.js ${files}`);
}

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

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

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

async function clippy() {
process.chdir(process.env.ZKSYNC_HOME!);
await utils.spawn('cargo clippy --tests -- -D warnings');
Expand All @@ -44,18 +46,39 @@ async function proverClippy() {
await utils.spawn('cargo clippy --tests -- -D warnings -A incomplete_features');
}

const ARGS = [...EXTENSIONS, 'rust', 'prover', 'l1-contracts', 'l2-contracts', 'system-contracts'];

export const command = new Command('lint')
.description('lint code')
.option('--check')
.arguments('[extension] rust|md|sol|js|ts|prover')
.arguments(`[extension] ${ARGS.join('|')}`)
.action(async (extension: string | null, cmd: Command) => {
if (extension) {
await lint(extension, cmd.check);
} else {
for (const ext of EXTENSIONS) {
await lint(ext, cmd.check);
switch (extension) {
case 'rust':
await clippy();
break;
case 'prover':
await proverClippy();
break;
case 'l1-contracts':
await lintL1Contracts(cmd.check);
break;
case 'l2-contracts':
await lintL2Contracts(cmd.check);
break;
case 'system-contracts':
await lintSystemContracts(cmd.check);
break;
default:
await lint(extension, cmd.check);
}

await clippy();
} else {
const promises = EXTENSIONS.map((ext) => lint(ext, cmd.check));
promises.push(lintL1Contracts(cmd.check));
promises.push(lintL2Contracts(cmd.check));
promises.push(lintSystemContracts(cmd.check));
promises.push(clippy());
await Promise.all(promises);
}
});
Loading