Skip to content

Commit

Permalink
Rebrand (#16)
Browse files Browse the repository at this point in the history
* feat(package.json): update package name, version, and description to reflect new project scope
feat(package.json): add 'o1js' to keywords for better discoverability

* refactor: rename all instances of 'snarkyjs' to 'o1js' in codebase

This commit includes changes in variable names, function names, comments, and documentation. The reason for this change is to align the codebase with the new naming convention.

* chore(ci.yml): update NodeJS versions in CI workflow from 14, 16 to 18, 20 to test against latest NodeJS versions

* fix(package.json): correct typo in package name from 'eslint-plugin-o1jx' to 'eslint-plugin-o1js' for accurate naming
  • Loading branch information
MartinMinkov authored Sep 5, 2023
1 parent 56ee482 commit 08a967c
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node: [14, 16]
node: [18, 20]
steps:
- name: Set up NodeJS
uses: actions/setup-node@v2
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# eslint-plugin-snarkyjs
# eslint-plugin-o1js

SnarkyJS rules for ESLint to detect bugs and invalid patterns in your Smart Contract code.
o1js rules for ESLint to detect bugs and invalid patterns in your Smart Contract code.

# Rules

Expand All @@ -16,25 +16,25 @@ SnarkyJS rules for ESLint to detect bugs and invalid patterns in your Smart Cont

```
# npm
npm install eslint-plugin-snarkyjs --save-dev
npm install eslint-plugin-o1js --save-dev
# yarn
yarn add eslint-plugin-snarkyjs --dev
yarn add eslint-plugin-o1js --dev
```

Add `eslint-plugin-snarkyjs` to the `plugins` option in your eslint config:
Add `eslint-plugin-o1js` to the `plugins` option in your eslint config:

```
{
"plugins": ["snarkyjs"]
"plugins": ["o1js"]
}
```

- Then extend the recommended eslint config:

```
{
extends: ['plugin:snarkyjs/recommended'],
extends: ['plugin:o1js/recommended'],
}
```

Expand All @@ -43,8 +43,8 @@ Add `eslint-plugin-snarkyjs` to the `plugins` option in your eslint config:
```
{
"rules": {
"snarkyjs/no-greater-storage-limit-in-circuit": "error",
"snarkyjs/no-throw-in-circuit": "error"
"o1js/no-greater-storage-limit-in-circuit": "error",
"o1js/no-throw-in-circuit": "error"
...
}
}
Expand All @@ -55,8 +55,8 @@ Add `eslint-plugin-snarkyjs` to the `plugins` option in your eslint config:
```
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['snarkyjs'],
extends: ['plugin:snarkyjs/recommended'],
plugins: ['o1js'],
extends: ['plugin:o1js/recommended'],
};
```
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eslint-plugin-snarkyjs",
"version": "0.3.0",
"description": "SnarkyJS rules for ESLint",
"name": "eslint-plugin-o1js",
"version": "0.4.0",
"description": "o1js rules for ESLint",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
Expand All @@ -20,7 +20,8 @@
],
"keywords": [
"eslint",
"snarkyjs"
"snarkyjs",
"o1js"
],
"devDependencies": {
"@types/eslint": "^8.2.1",
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TSESLint } from '@typescript-eslint/experimental-utils'

const snarkyJSRules: string[] = [
const o1jsRules: string[] = [
'no-greater-storage-limit-in-circuit',
'no-if-in-circuit',
'no-ternary-in-circuit',
Expand All @@ -11,23 +11,23 @@ const snarkyJSRules: string[] = [
]

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const snarkyJSRuleModules: { [key: string]: any } = {}
const o1jsRuleModules: { [key: string]: any } = {}

const configs: { recommended: TSESLint.Linter.Config } = {
recommended: { plugins: ['snarkyjs'], rules: {} },
recommended: { plugins: ['o1js'], rules: {} },
}

snarkyJSRules.forEach((rule) => {
snarkyJSRuleModules[rule] = require(`./rules/${rule}`)
o1jsRules.forEach((rule) => {
o1jsRuleModules[rule] = require(`./rules/${rule}`)
const {
meta: {
docs: { recommended },
},
} = snarkyJSRuleModules[rule]
} = o1jsRuleModules[rule]
if (configs.recommended.rules) {
configs.recommended.rules[`snarkyjs/${rule}`] =
configs.recommended.rules[`o1js/${rule}`] =
recommended === false ? 'off' : recommended
}
})

export { snarkyJSRuleModules as rules, configs }
export { o1jsRuleModules as rules, configs }
22 changes: 11 additions & 11 deletions src/rules/no-greater-storage-limit-in-circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'
import type { ContractTypeKind } from '../types'
import {
MAX_CONTRACT_STATES,
getSnarkyJSPrimitive,
SnarkyJSPrimitiveSizeInfo,
geto1jsPrimitive,
o1jsPrimitiveSizeInfo,
} from '../types'
import {
getSecondDecoratorValue,
Expand Down Expand Up @@ -155,23 +155,23 @@ function findKnownAndUnknownStates(
}

// Get the user specified type from the decorator node (e.g `Field`, `Group` or a CircuitValue)
const snarkyDecoratorType =
const o1DecoratorType =
getFirstDecoratorValue(decorator.decorator) ??
getPropertyType(classStatement)

if (!snarkyDecoratorType) {
if (!o1DecoratorType) {
continue
}

// If the decorator type is a SnarkyJS primitive, get it's value
const primitive = getSnarkyJSPrimitive(snarkyDecoratorType)
// If the decorator type is a o1js primitive, get it's value
const primitive = geto1jsPrimitive(o1DecoratorType)
if (!primitive) {
isAllPrimitiveState = false
}

if (decorator.kind === 'prop' || decorator.kind === 'state') {
if (primitive) {
const { size } = SnarkyJSPrimitiveSizeInfo[primitive]
const { size } = o1jsPrimitiveSizeInfo[primitive]
stateInfo.push({
kind: 'KnownStateInfo',
type: { kind: decorator.kind },
Expand All @@ -186,14 +186,14 @@ function findKnownAndUnknownStates(
kind: decorator.kind,
},
node: smartContractNode,
dependsOn: snarkyDecoratorType,
dependsOn: o1DecoratorType,
})
}
} else if (decorator.kind === 'arrayProp') {
const arrayPropLength =
(getSecondDecoratorValue(decorator.decorator) as number) ?? 0
if (primitive) {
const { size } = SnarkyJSPrimitiveSizeInfo[primitive]
const { size } = o1jsPrimitiveSizeInfo[primitive]
stateInfo.push({
kind: 'KnownStateInfo',
type: {
Expand All @@ -212,13 +212,13 @@ function findKnownAndUnknownStates(
arrayPropLength,
},
node: smartContractNode,
dependsOn: snarkyDecoratorType,
dependsOn: o1DecoratorType,
})
}
}
}

// If all decorators are a SnarkyJS primitive, we can calculate the Smart Contract state count and
// If all decorators are a o1js primitive, we can calculate the Smart Contract state count and
// insert it into the `knownContractStateMap`. If the user specifies a CircuitValue, we store the state info
// in `unknownContractState` to derive it's state count later.
const className = getClassName(smartContractNode) ?? ''
Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-if-in-circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
},

create(context) {
const snarkyCircuitMap = new Map<string, TSESTree.Node>()
const o1CircuitMap = new Map<string, TSESTree.Node>()
const ifSet = new Set<string>()
const callees: Record<string, string[]> = {}
const callStack: (string | undefined)[] = []
Expand All @@ -36,7 +36,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {

return {
'Program:exit': function () {
for (const circuitNode of snarkyCircuitMap.values()) {
for (const circuitNode of o1CircuitMap.values()) {
simpleTraverse(circuitNode, {
enter: (node: TSESTree.Node) => {
if (isIfStatement(node)) {
Expand All @@ -61,7 +61,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
circuitMethodNode: TSESTree.MethodDefinition
) {
const functionName = getFunctionName(circuitMethodNode)
if (functionName) snarkyCircuitMap.set(functionName, circuitMethodNode)
if (functionName) o1CircuitMap.set(functionName, circuitMethodNode)
},

':function'(node: TSESTree.Node) {
Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-json-functions-in-circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
create(context) {
const bannedImports = new Set<string>(['JSON'])
const bannedFunctions = new Set<string>(['stringify', 'parse'])
const snarkyCircuitMap = new Map<string, TSESTree.Node>()
const o1CircuitMap = new Map<string, TSESTree.Node>()
const jsonSet = new Set<string>()
const callees: Record<string, string[]> = {}
const callStack: (string | undefined)[] = []
Expand All @@ -36,7 +36,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {

return {
'Program:exit': function () {
for (const circuitNode of snarkyCircuitMap.values()) {
for (const circuitNode of o1CircuitMap.values()) {
simpleTraverse(circuitNode, {
enter: (node: TSESTree.Node) => {
if (
Expand Down Expand Up @@ -75,7 +75,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
circuitMethodNode: TSESTree.MethodDefinition
) {
const functionName = getFunctionName(circuitMethodNode)
if (functionName) snarkyCircuitMap.set(functionName, circuitMethodNode)
if (functionName) o1CircuitMap.set(functionName, circuitMethodNode)
},

CallExpression(node: TSESTree.CallExpression) {
Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-random-in-circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
'getRandomValues',
'randomBytes',
])
const snarkyCircuitMap = new Map<string, TSESTree.Node>()
const o1CircuitMap = new Map<string, TSESTree.Node>()
const randomSet = new Set<string>()
const callees: Record<string, string[]> = {}
const callStack: (string | undefined)[] = []
Expand All @@ -41,7 +41,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {

return {
'Program:exit': function () {
for (const circuitNode of snarkyCircuitMap.values()) {
for (const circuitNode of o1CircuitMap.values()) {
simpleTraverse(circuitNode, {
enter: (node: TSESTree.Node) => {
if (
Expand Down Expand Up @@ -80,7 +80,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
circuitMethodNode: TSESTree.MethodDefinition
) {
const functionName = getFunctionName(circuitMethodNode)
if (functionName) snarkyCircuitMap.set(functionName, circuitMethodNode)
if (functionName) o1CircuitMap.set(functionName, circuitMethodNode)
},

CallExpression(node: TSESTree.CallExpression) {
Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-ternary-in-circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
},

create(context) {
const snarkyCircuitMap = new Map<string, TSESTree.Node>()
const o1CircuitMap = new Map<string, TSESTree.Node>()
const ternarySet = new Set<string>()
const callees: Record<string, string[]> = {}
const callStack: (string | undefined)[] = []
Expand All @@ -39,7 +39,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {

return {
'Program:exit': function () {
for (const circuitNode of snarkyCircuitMap.values()) {
for (const circuitNode of o1CircuitMap.values()) {
simpleTraverse(circuitNode, {
enter: (node: TSESTree.Node) => {
if (isConditionalExpression(node)) {
Expand Down Expand Up @@ -67,7 +67,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
circuitMethodNode: TSESTree.MethodDefinition
) {
const functionName = getFunctionName(circuitMethodNode)
if (functionName) snarkyCircuitMap.set(functionName, circuitMethodNode)
if (functionName) o1CircuitMap.set(functionName, circuitMethodNode)
},

':function'(node: TSESTree.Node) {
Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-throw-in-circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
},

create(context) {
const snarkyCircuitMap = new Map<string, TSESTree.Node>()
const o1CircuitMap = new Map<string, TSESTree.Node>()
const throwSet = new Set<string>()
const callees: Record<string, string[]> = {}
const callStack: (string | undefined)[] = []
Expand All @@ -36,7 +36,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {

return {
'Program:exit': function () {
for (const circuitNode of snarkyCircuitMap.values()) {
for (const circuitNode of o1CircuitMap.values()) {
simpleTraverse(circuitNode, {
enter: (node: TSESTree.Node) => {
if (isThrowStatement(node)) {
Expand All @@ -61,7 +61,7 @@ const rule: TSESLint.RuleModule<string, string[]> = {
circuitMethodNode: TSESTree.MethodDefinition
) {
const functionName = getFunctionName(circuitMethodNode)
if (functionName) snarkyCircuitMap.set(functionName, circuitMethodNode)
if (functionName) o1CircuitMap.set(functionName, circuitMethodNode)
},

':function'(node: TSESTree.Node) {
Expand Down
12 changes: 6 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const MAX_CONTRACT_STATES = 8 as const

const SnarkyJSPrimitives = [
const o1jsPrimitives = [
'Field',
'Bool',
'UInt32',
Expand All @@ -12,13 +12,13 @@ const SnarkyJSPrimitives = [
'Signature',
] as const

export type SnarkyJSPrimitive = typeof SnarkyJSPrimitives[number]
export type o1jsPrimitive = typeof o1jsPrimitives[number]

export function getSnarkyJSPrimitive(s: string) {
return SnarkyJSPrimitives.find((primitiveType) => s === primitiveType)
export function geto1jsPrimitive(s: string) {
return o1jsPrimitives.find((primitiveType) => s === primitiveType)
}

export const SnarkyJSPrimitiveSizeInfo = {
export const o1jsPrimitiveSizeInfo = {
Field: { size: 1 },
Bool: { size: 1 },
Scalar: { size: 1 },
Expand All @@ -28,7 +28,7 @@ export const SnarkyJSPrimitiveSizeInfo = {
Group: { size: 2 },
PublicKey: { size: 2 },
Signature: { size: 2 },
} as Record<SnarkyJSPrimitive, { size: number }>
} as Record<o1jsPrimitive, { size: number }>

export type PropKind = {
kind: 'prop'
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getDecorators(node: TSESTree.Node): TSESTree.Decorator[] {
}

/**
* Return an object that contains what kind of SnarkyJS decorator was used
* Return an object that contains what kind of o1js decorator was used
* (e.g `@state` `@prop`, or `@arrayProp`)
* and the decorator node.
* @param node The node to get the decorators from
Expand Down

0 comments on commit 08a967c

Please sign in to comment.