Skip to content

Commit b64f732

Browse files
authored
chore(bb.js): fix linting (#24902)
## Summary - make the ESLint 9 flat config executable and apply the full `yarn-project/foundation` lint contract to bb.js - enable all 36 canonical explicit rules, including `import-x/no-cycle`, core `require-await`, `no-console`, camelcase, no-only-tests, and the three Aztec custom rules - use the same canonical ESLint plugins, type-checked/import-x base configs, and byte-identical Prettier import-order configuration - fix all resulting bb.js lint and formatting violations, including refactoring the backend factories to remove four dependency cycles - run `yarn formatting` during every bb.js build before cache lookup and from the default `ci-barretenberg` path - make `formatting:fix` run both ESLint fixes and Prettier ## Canonical alignment A machine comparison of bb.js and `yarn-project/foundation` reports: - 36 explicit rules in each config - identical values for 35 rules - the same plugin set: import-x, jsdoc, tsdoc, no-only-tests, and aztec-custom - byte-identical implementations for all three Aztec custom rules - byte-identical Prettier configuration, including import ordering The sole rule-option difference is the project-specific ignore list for `import-x/no-unresolved`. bb.js ignores `src/cbind/generated` and the checked-in wasm symlinks because those targets are created later in bootstrap; yarn-project has its own four generated/conditional-export resolver exceptions. This is module-resolution plumbing, not a style relaxation: the rule remains enabled at `error` everywhere. ## CI coverage `merge-train/barretenberg` PRs select `ci-barretenberg`. That mode runs `barretenberg/ts/bb.js/bootstrap.sh formatting` before the CRS/C++ work. Normal bb.js builds also run the same check before a build-cache hit can return early. A temporary `src/lint_probe.ts` containing a disallowed `console.log` made the exact bootstrap formatting command exit 1 with `no-console`; removing it made the command exit 0. The lint command also passes in a fresh worktree where the wasm symlinks are unresolved and `src/cbind/generated` is absent. ## Testing - machine comparison of canonical/bb.js explicit rule maps and plugin sets - byte comparison of canonical/bb.js Prettier configs and custom rule implementations - `yarn formatting` - `yarn install --immutable` - focused strict TypeScript compile of the refactored backend factories and implementations - `CI=1 AVM=0 AVM_TRANSPILER=0 barretenberg/ts/bb.js/bootstrap.sh formatting` - the same bootstrap command in a fresh worktree with unresolved generated artifacts - red/green lint probe through the bootstrap command - exact-head `ci-barretenberg` passed - exact-head `ci-barretenberg-full` passed bb.js formatting, binding generation, and ESM/CommonJS/browser builds; that wider job later stopped in the separate bb-avm-sim build because `@aztec/ipc-runtime` was unavailable
2 parents 37fd82b + e9fa6bf commit b64f732

55 files changed

Lines changed: 2087 additions & 284 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

barretenberg/ts/bb.js/.prettierrc.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@
22
"singleQuote": true,
33
"trailingComma": "all",
44
"printWidth": 120,
5-
"arrowParens": "avoid"
5+
"arrowParens": "avoid",
6+
"importOrder": ["^@aztec/(.*)$", "<THIRD_PARTY_MODULES>", "^\\./|\\.\\./"],
7+
"importOrderSeparation": true,
8+
"importOrderSortSpecifiers": true,
9+
"importOrderParserPlugins": ["importAssertions", "typescript", "decorators", "explicitResourceManagement"],
10+
"plugins": ["@trivago/prettier-plugin-sort-imports"]
611
}

barretenberg/ts/bb.js/bootstrap.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ hash=$(hash_str \
1212
$(semver check $REF_NAME && echo 1 || echo 0) \
1313
${AVM_TRANSPILER:-1})
1414

15-
function build {
16-
echo_header "bb.js build"
15+
function prepare_project {
1716
(cd .. && ./bootstrap.sh generate_bb_avm_sim_package)
1817
(cd .. && npm_install_deps)
18+
}
19+
20+
function formatting {
21+
echo_header "bb.js formatting"
22+
prepare_project
23+
yarn formatting
24+
}
25+
26+
function build {
27+
echo_header "bb.js build"
28+
prepare_project
29+
yarn formatting
1930

2031
if ! cache_download bb.js-$hash.tar.gz; then
2132
find . -exec touch -d "@0" {} + 2>/dev/null || true
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// @ts-check
2+
3+
/**
4+
* @fileoverview Rule to disallow async [Symbol.dispose]() methods.
5+
* Use [Symbol.asyncDispose]() with AsyncDisposable instead.
6+
*/
7+
8+
/** @type {import('eslint').Rule.RuleModule} */
9+
export default {
10+
meta: {
11+
type: 'problem',
12+
docs: {
13+
description: 'Disallow async [Symbol.dispose]() methods',
14+
category: 'Best Practices',
15+
recommended: true,
16+
},
17+
messages: {
18+
asyncDispose: '[Symbol.dispose]() should not be async. Use [Symbol.asyncDispose]() with AsyncDisposable instead.',
19+
},
20+
schema: [],
21+
},
22+
23+
create(context) {
24+
return {
25+
MethodDefinition(node) {
26+
// Match computed property keys like [Symbol.dispose]
27+
if (!node.computed || !node.key || node.key.type !== 'MemberExpression') {
28+
return;
29+
}
30+
31+
const key = node.key;
32+
if (
33+
key.object.type !== 'Identifier' ||
34+
key.object.name !== 'Symbol' ||
35+
key.property.type !== 'Identifier' ||
36+
key.property.name !== 'dispose'
37+
) {
38+
return;
39+
}
40+
41+
// Check if the method is async
42+
if (node.value.async) {
43+
context.report({ node, messageId: 'asyncDispose' });
44+
return;
45+
}
46+
47+
// Check if the return type annotation contains Promise
48+
// @ts-expect-error returnType is a typescript-eslint AST extension
49+
const returnType = node.value.returnType?.typeAnnotation;
50+
if (
51+
returnType &&
52+
returnType.type === 'TSTypeReference' &&
53+
returnType.typeName?.type === 'Identifier' &&
54+
returnType.typeName.name === 'Promise'
55+
) {
56+
context.report({ node, messageId: 'asyncDispose' });
57+
}
58+
},
59+
};
60+
},
61+
};

0 commit comments

Comments
 (0)