Skip to content

Commit 72a1f47

Browse files
CoveMBericglau
andauthored
Add linter (and formatter through eslint), config and ci action step (#452)
Co-authored-by: Eric Lau <[email protected]>
1 parent ce68631 commit 72a1f47

File tree

129 files changed

+2661
-1536
lines changed

Some content is hidden

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

129 files changed

+2661
-1536
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ on:
66
pull_request: {}
77

88
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 18.x
16+
cache: 'yarn'
17+
- name: Install dependencies
18+
run: yarn install --network-concurrency 1
19+
- name: Run linter
20+
run: yarn lint
21+
922
build:
1023
strategy:
1124
matrix:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ node_modules
55

66
.env
77
.env.local
8+
.vscode/

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"singleQuote": true,
3+
"arrowParens": "avoid",
4+
"trailingComma": "all",
5+
"printWidth": 120,
6+
"bracketSpacing": true
7+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Install dependencies with `yarn install`.
1515
`packages/core` contains the code generation logic for each language under separately named subfolders. From each language's subfolder:
1616
- Run `yarn test` to run the tests.
1717
- Run `yarn test:update-snapshots` to update AVA snapshots and run the tests.
18+
- Run `yarn lint` to run the linter across the codebase (optionally `yarn lint --fix` will automatically fix fixable issues, like formatting issues).
1819

1920
`packages/ui` is the interface built in Svelte. From the `packages/ui` directory, run `yarn dev` to spin up a local server to develop the UI.
2021

eslint.config.mjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// @ts-check
2+
3+
import eslint from '@eslint/js';
4+
import prettierPluginRecommended from 'eslint-plugin-prettier/recommended';
5+
import unicornPlugin from 'eslint-plugin-unicorn';
6+
import typescriptEslint from 'typescript-eslint';
7+
8+
export default typescriptEslint.config(
9+
eslint.configs.recommended,
10+
typescriptEslint.configs.strict,
11+
prettierPluginRecommended,
12+
{
13+
plugins: {
14+
unicorn: unicornPlugin,
15+
},
16+
rules: {
17+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
18+
'@typescript-eslint/no-non-null-assertion': 'off',
19+
'@typescript-eslint/consistent-type-imports': 'error',
20+
'prettier/prettier': [
21+
'error',
22+
{ singleQuote: true, arrowParens: 'avoid', trailingComma: 'all', printWidth: 120, bracketSpacing: true },
23+
],
24+
},
25+
},
26+
{
27+
ignores: ['node_modules/', '*.sol', 'packages/*/node_modules/', 'packages/**/dist/', 'packages/**/build/'],
28+
},
29+
{
30+
files: ['**/*.config.js'],
31+
languageOptions: {
32+
sourceType: 'commonjs',
33+
},
34+
},
35+
{
36+
files: ['**/*.mjs', '**/*.js'],
37+
languageOptions: {
38+
sourceType: 'commonjs',
39+
globals: {
40+
process: 'readonly',
41+
global: 'readonly',
42+
console: 'readonly',
43+
},
44+
},
45+
rules: {
46+
'@typescript-eslint/no-require-imports': 'off',
47+
},
48+
},
49+
);

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"scripts": {
55
"prepare": "wsrun -m prepare",
6+
"lint": "eslint",
67
"dev:ui": "yarn --cwd ./packages/ui dev",
78
"run:core": "node ./scripts/run-command.mjs"
89
},
@@ -17,6 +18,14 @@
1718
]
1819
},
1920
"devDependencies": {
21+
"@eslint/js": "^9.21.0",
22+
"eslint": "^9.21.0",
23+
"eslint-config-prettier": "^10.0.1",
24+
"eslint-plugin-prettier": "^5.2.3",
25+
"eslint-plugin-unicorn": "^57.0.0",
26+
"prettier": "^3.5.1",
27+
"typescript": "^5.7.3",
28+
"typescript-eslint": "^8.24.1",
2029
"wsrun": "^5.2.4"
2130
}
2231
}

packages/core/cairo/ava.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ module.exports = {
22
extensions: ['ts'],
33
require: ['ts-node/register'],
44
watchmode: {
5-
ignoreChanges: [
6-
'contracts',
7-
'artifacts',
8-
'cache',
9-
],
5+
ignoreChanges: ['contracts', 'artifacts', 'cache'],
106
},
117
timeout: '10m',
128
workerThreads: false,

packages/core/cairo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
"typescript": "^5.0.0",
3232
"semver": "^7.6.0"
3333
}
34-
}
34+
}

packages/core/cairo/src/account.test.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import test from 'ava';
22

3-
import { buildAccount, AccountOptions } from './account';
3+
import type { AccountOptions } from './account';
4+
import { buildAccount } from './account';
45
import { printContract } from './print';
56

67
import { account } from '.';
@@ -32,22 +33,27 @@ function testEthAccount(title: string, opts: Partial<AccountOptions>) {
3233
*/
3334
function testAPIEquivalence(title: string, opts?: AccountOptions) {
3435
test(title, t => {
35-
t.is(account.print(opts), printContract(buildAccount({
36-
name: 'MyAccount',
37-
type: 'stark',
38-
declare: true,
39-
deploy: true,
40-
pubkey: true,
41-
outsideExecution: true,
42-
...opts,
43-
})));
36+
t.is(
37+
account.print(opts),
38+
printContract(
39+
buildAccount({
40+
name: 'MyAccount',
41+
type: 'stark',
42+
declare: true,
43+
deploy: true,
44+
pubkey: true,
45+
outsideExecution: true,
46+
...opts,
47+
}),
48+
),
49+
);
4450
});
4551
}
4652

4753
testAccount('default full account, mixin + upgradeable', {});
4854

4955
testAccount('default full account, mixin + non-upgradeable', {
50-
upgradeable: false
56+
upgradeable: false,
5157
});
5258

5359
testAccount('explicit full account, mixin + upgradeable', {
@@ -57,7 +63,7 @@ testAccount('explicit full account, mixin + upgradeable', {
5763
deploy: true,
5864
pubkey: true,
5965
outsideExecution: true,
60-
upgradeable: true
66+
upgradeable: true,
6167
});
6268

6369
testAccount('explicit full account, mixin + non-upgradeable', {
@@ -67,7 +73,7 @@ testAccount('explicit full account, mixin + non-upgradeable', {
6773
deploy: true,
6874
pubkey: true,
6975
outsideExecution: true,
70-
upgradeable: false
76+
upgradeable: false,
7177
});
7278

7379
testAccount('basic account, upgradeable', {
@@ -82,7 +88,7 @@ testAccount('basic account, non-upgradeable', {
8288
deploy: false,
8389
pubkey: false,
8490
outsideExecution: false,
85-
upgradeable: false
91+
upgradeable: false,
8692
});
8793

8894
testAccount('account outside execution', {
@@ -127,7 +133,7 @@ testAccount('account deployable, public key', {
127133
testEthAccount('default full ethAccount, mixin + upgradeable', {});
128134

129135
testEthAccount('default full ethAccount, mixin + non-upgradeable', {
130-
upgradeable: false
136+
upgradeable: false,
131137
});
132138

133139
testEthAccount('explicit full ethAccount, mixin + upgradeable', {
@@ -137,7 +143,7 @@ testEthAccount('explicit full ethAccount, mixin + upgradeable', {
137143
deploy: true,
138144
pubkey: true,
139145
outsideExecution: true,
140-
upgradeable: true
146+
upgradeable: true,
141147
});
142148

143149
testEthAccount('explicit full ethAccount, mixin + non-upgradeable', {
@@ -147,7 +153,7 @@ testEthAccount('explicit full ethAccount, mixin + non-upgradeable', {
147153
deploy: true,
148154
pubkey: true,
149155
outsideExecution: true,
150-
upgradeable: false
156+
upgradeable: false,
151157
});
152158

153159
testEthAccount('basic ethAccount, upgradeable', {
@@ -162,7 +168,7 @@ testEthAccount('basic ethAccount, non-upgradeable', {
162168
deploy: false,
163169
pubkey: false,
164170
outsideExecution: false,
165-
upgradeable: false
171+
upgradeable: false,
166172
});
167173

168174
testEthAccount('ethAccount outside execution', {

packages/core/cairo/src/account.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { Contract, ContractBuilder } from './contract';
2-
import { CommonOptions, withCommonDefaults } from './common-options';
1+
import type { Contract } from './contract';
2+
import { ContractBuilder } from './contract';
3+
import type { CommonOptions } from './common-options';
4+
import { withCommonDefaults } from './common-options';
35
import { defaults as commonDefaults } from './common-options';
46
import { setAccountUpgradeable } from './set-upgradeable';
57
import { setInfo } from './set-info';
68
import { defineComponents } from './utils/define-components';
79
import { printContract } from './print';
810
import { addSRC5Component } from './common-components';
911

10-
1112
export const accountTypes = ['stark', 'eth'] as const;
12-
export type Account = typeof accountTypes[number];
13+
export type Account = (typeof accountTypes)[number];
1314

1415
export const defaults: Required<AccountOptions> = {
1516
name: 'MyAccount',
@@ -19,7 +20,7 @@ export const defaults: Required<AccountOptions> = {
1920
pubkey: true,
2021
outsideExecution: true,
2122
upgradeable: commonDefaults.upgradeable,
22-
info: commonDefaults.info
23+
info: commonDefaults.info,
2324
} as const;
2425

2526
export function printAccount(opts: AccountOptions = defaults): string {
@@ -42,8 +43,8 @@ function withDefaults(opts: AccountOptions): Required<AccountOptions> {
4243
declare: opts.declare ?? defaults.declare,
4344
deploy: opts.deploy ?? defaults.deploy,
4445
pubkey: opts.pubkey ?? defaults.pubkey,
45-
outsideExecution: opts.outsideExecution ?? defaults.outsideExecution
46-
}
46+
outsideExecution: opts.outsideExecution ?? defaults.outsideExecution,
47+
};
4748
}
4849

4950
export function buildAccount(opts: AccountOptions): Contract {
@@ -157,11 +158,14 @@ function addAccountMixin(c: ContractBuilder, accountType: Account) {
157158
}
158159

159160
function getBaseCompAndCompType(accountType: Account): [string, typeof componentType] {
160-
const [baseComponent, componentType] = accountType === 'stark' ? ['AccountComponent', components.AccountComponent] : ['EthAccountComponent', components.EthAccountComponent];
161+
const [baseComponent, componentType] =
162+
accountType === 'stark'
163+
? ['AccountComponent', components.AccountComponent]
164+
: ['EthAccountComponent', components.EthAccountComponent];
161165
return [baseComponent, componentType];
162166
}
163167

164-
const components = defineComponents( {
168+
const components = defineComponents({
165169
AccountComponent: {
166170
path: 'openzeppelin::account',
167171
substorage: {
@@ -172,11 +176,13 @@ const components = defineComponents( {
172176
name: 'AccountEvent',
173177
type: 'AccountComponent::Event',
174178
},
175-
impls: [{
176-
name: 'AccountInternalImpl',
177-
embed: false,
178-
value: 'AccountComponent::InternalImpl<ContractState>',
179-
}],
179+
impls: [
180+
{
181+
name: 'AccountInternalImpl',
182+
embed: false,
183+
value: 'AccountComponent::InternalImpl<ContractState>',
184+
},
185+
],
180186
},
181187
EthAccountComponent: {
182188
path: 'openzeppelin::account::eth_account',
@@ -188,11 +194,13 @@ const components = defineComponents( {
188194
name: 'EthAccountEvent',
189195
type: 'EthAccountComponent::Event',
190196
},
191-
impls: [{
192-
name: 'EthAccountInternalImpl',
193-
embed: false,
194-
value: 'EthAccountComponent::InternalImpl<ContractState>',
195-
}]
197+
impls: [
198+
{
199+
name: 'EthAccountInternalImpl',
200+
embed: false,
201+
value: 'EthAccountComponent::InternalImpl<ContractState>',
202+
},
203+
],
196204
},
197205
SRC9Component: {
198206
path: 'openzeppelin::account::extensions',
@@ -204,13 +212,16 @@ const components = defineComponents( {
204212
name: 'SRC9Event',
205213
type: 'SRC9Component::Event',
206214
},
207-
impls: [{
208-
name: 'OutsideExecutionV2Impl',
209-
value: 'SRC9Component::OutsideExecutionV2Impl<ContractState>',
210-
}, {
211-
name: 'OutsideExecutionInternalImpl',
212-
embed: false,
213-
value: 'SRC9Component::InternalImpl<ContractState>',
214-
}]
215-
}
215+
impls: [
216+
{
217+
name: 'OutsideExecutionV2Impl',
218+
value: 'SRC9Component::OutsideExecutionV2Impl<ContractState>',
219+
},
220+
{
221+
name: 'OutsideExecutionInternalImpl',
222+
embed: false,
223+
value: 'SRC9Component::InternalImpl<ContractState>',
224+
},
225+
],
226+
},
216227
});

0 commit comments

Comments
 (0)