Skip to content

Commit

Permalink
chore: linter
Browse files Browse the repository at this point in the history
- [x] Update typescript
- [x] Add linter deps and configs
- [x] Run prettier
- [x] Lint fixes for project
- [x] Apply new lint rules for `crypto` package
- [x] Update dev deps
- [x] Add lint, prettier checks for ci
  • Loading branch information
0xmad committed Nov 30, 2023
1 parent 63be592 commit 42ea4f0
Show file tree
Hide file tree
Showing 145 changed files with 47,703 additions and 35,589 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ insert_final_newline = true

[*.{ts,js}]
indent_style = space
indent_size = 4
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true

Expand Down
45 changes: 22 additions & 23 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
rules: {
"no-console": "off",
"no-debugger": "off",
"no-prototype-builtins": "off",
"no-constant-condition": ["error", { checkLoops: false }],
"no-empty": ["error", { allowEmptyCatch: true }],
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
},
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
rules: {
"no-console": "off",
"no-debugger": "off",
"no-prototype-builtins": "off",
"no-constant-condition": ["error", { checkLoops: false }],
"no-empty": ["error", { allowEmptyCatch: true }],
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
},
};
40 changes: 40 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Checks

on:
push:
branches: [master, dev]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
check:
strategy:
fail-fast: false
matrix:
command: ["prettier", "lint"]

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- name: Update npm to latest version
run: npm install --global npm@latest

- name: Build
run: |
npm install
npm run bootstrap
npm run build
- name: ${{ matrix.command }}
run: npm run ${{ matrix.command }}
6 changes: 3 additions & 3 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: GitHub Pages

on:
push:
branches: [ dev ]
branches: [dev]
pull_request:

concurrency:
Expand All @@ -20,7 +20,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
registry-url: "https://registry.npmjs.org"

- name: Run typedoc
run: |
Expand All @@ -29,7 +29,7 @@ jobs:
npm run build
npm run typedoc
- name: Fix typedoc links
- name: Fix typedoc links
run: |
npm install
npm run setup-typedoc
Expand Down
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"**/*.ts": ["prettier --ignore-unknown --write", "eslint --fix"],
"**/*.{yaml, yml}": "prettier --ignore-unknown --write"
"**/*.{sol, yaml, yml, md}": ["prettier --ignore-unknown --write"]
}
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
build/
node_modules/
coverage/
tmp/
artifacts/
cache/
package-lock.json
**/package-lock.json
CHANGELOG.md
.eslintignore
20 changes: 20 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"printWidth": 120,
"singleQuote": false,
"semi": true,
"tabWidth": 2,
"useTabs": false,
"trailingComma": "all",
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 120,
"semi": true
}
}
]
}
7 changes: 0 additions & 7 deletions .prettierrc.yaml

This file was deleted.

13 changes: 8 additions & 5 deletions circuits/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
"maci-domainobjs": "^1.1.2",
"mocha": "^10.2.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.2.3"
"typescript": "^5.3.2"
}
}
44 changes: 20 additions & 24 deletions circuits/ts/__tests__/CalculateTotal.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import { getSignal } from "./utils";
import * as path from "path";
import path from "path";
const tester = require("circom_tester").wasm;
import { expect } from "chai";

describe("CalculateTotal circuit", () => {
const circuitPath = path.join(
__dirname,
"../../circom/test",
`calculateTotal_test.circom`
);
let circuit: any;
const circuitPath = path.join(__dirname, "../../circom/test", `calculateTotal_test.circom`);
let circuit: any;

before(async () => {
circuit = await tester(circuitPath);
});
before(async () => {
circuit = await tester(circuitPath);
});

it("should correctly sum a list of values", async () => {
const nums: number[] = [];
for (let i = 0; i < 6; i++) {
nums.push(Math.floor(Math.random() * 100));
}
const sum = nums.reduce((a, b) => a + b, 0);
it("should correctly sum a list of values", async () => {
const nums: number[] = [];
for (let i = 0; i < 6; i++) {
nums.push(Math.floor(Math.random() * 100));
}
const sum = nums.reduce((a, b) => a + b, 0);

const circuitInputs = {
nums,
};
const circuitInputs = {
nums,
};

const witness = await circuit.calculateWitness(circuitInputs, true);
await circuit.checkConstraints(witness);
const result = await getSignal(circuit, witness, "sum");
expect(result.toString()).to.be.eq(sum.toString());
});
const witness = await circuit.calculateWitness(circuitInputs, true);
await circuit.checkConstraints(witness);
const result = await getSignal(circuit, witness, "sum");
expect(result.toString()).to.be.eq(sum.toString());
});
});
61 changes: 21 additions & 40 deletions circuits/ts/__tests__/Ecdh.test.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,35 @@
import { stringifyBigInts } from "maci-crypto";
import { Keypair } from "maci-domainobjs";
import * as path from "path";
import path from "path";
const tester = require("circom_tester").wasm;
import { getSignal } from "./utils";
import { expect } from "chai";

describe("Public key derivation circuit", () => {
const circuitPath = path.join(
__dirname,
"../../circom/test",
`ecdh_test.circom`
);
let circuit: any;
const circuitPath = path.join(__dirname, "../../circom/test", `ecdh_test.circom`);
let circuit: any;

before(async () => {
circuit = await tester(circuitPath);
});
before(async () => {
circuit = await tester(circuitPath);
});

it("correctly computes a public key", async () => {
const keypair = new Keypair();
const keypair2 = new Keypair();
it("correctly computes a public key", async () => {
const keypair = new Keypair();
const keypair2 = new Keypair();

const ecdhSharedKey = Keypair.genEcdhSharedKey(
keypair.privKey,
keypair2.pubKey
);
const ecdhSharedKey = Keypair.genEcdhSharedKey(keypair.privKey, keypair2.pubKey);

const circuitInputs = stringifyBigInts({
privKey: keypair.privKey.asCircuitInputs(),
pubKey: keypair2.pubKey.asCircuitInputs(),
});
const circuitInputs = stringifyBigInts({
privKey: keypair.privKey.asCircuitInputs(),
pubKey: keypair2.pubKey.asCircuitInputs(),
});

const witness = await circuit.calculateWitness(circuitInputs, true);
await circuit.checkConstraints(witness);
const witness = await circuit.calculateWitness(circuitInputs, true);
await circuit.checkConstraints(witness);

const circuitEcdhSharedKey0 = await getSignal(
circuit,
witness,
"sharedKey[0]"
);
const circuitEcdhSharedKey1 = await getSignal(
circuit,
witness,
"sharedKey[1]"
);
expect(circuitEcdhSharedKey0.toString()).to.be.eq(
ecdhSharedKey[0].toString()
);
expect(circuitEcdhSharedKey1.toString()).to.be.eq(
ecdhSharedKey[1].toString()
);
});
const circuitEcdhSharedKey0 = await getSignal(circuit, witness, "sharedKey[0]");
const circuitEcdhSharedKey1 = await getSignal(circuit, witness, "sharedKey[1]");
expect(circuitEcdhSharedKey0.toString()).to.be.eq(ecdhSharedKey[0].toString());
expect(circuitEcdhSharedKey1.toString()).to.be.eq(ecdhSharedKey[1].toString());
});
});
Loading

0 comments on commit 42ea4f0

Please sign in to comment.