Skip to content

Commit

Permalink
Merge branch 'tmigone/lint-config' into tmigone/subgraph-service
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigone committed Feb 23, 2024
2 parents 993cede + eddea69 commit ab36183
Show file tree
Hide file tree
Showing 154 changed files with 45,447 additions and 1,604 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/ci-token-dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

env:
CI: true

on:
push:
branches: "*"
paths:
- packages/token-distribution/**
pull_request:
branches: "*"
paths:
- packages/token-distribution/**
workflow_dispatch:

jobs:
test-ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up environment
uses: ./.github/actions/setup
- name: Run tests
run: yarn test
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dist/
build/
typechain/
typechain-types/
deployments/hardhat/

# Ignore solc bin output
bin/
Expand All @@ -47,4 +48,9 @@ addresses-fork.json
.keystore

# Forge artifacts
cache_forge
cache_forge
# Graph client
.graphclient

tx-builder-*.json
!tx-builder-template.json
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ This repository is a Yarn workspaces monorepo containing the following packages:
| --- | --- | --- |
| [contracts](./packages/contracts) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fcontracts.svg)](https://badge.fury.io/js/@graphprotocol%2Fcontracts) | Contracts enabling the open and permissionless decentralized network known as The Graph protocol. |
| [eslint-graph-config](./packages/eslint-graph-config) | [![npm version]()]() | Shared linting and formatting rules for TypeScript projects. |
| [subgraph-service](./packages/subgraph-service) | [![npm version]()]() | Contracts for the Subgraph data service in Graph Horizon. |
| [sdk](./packages/sdk) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fsdk.svg)](https://badge.fury.io/js/@graphprotocol%2Fsdk) | TypeScript based SDK to interact with the protocol contracts |
| [solhint-graph-config](./packages/eslint-graph-config) | [![npm version]()]() | Shared linting and formatting rules for Solidity projects. |
| [subgraph-service](./packages/subgraph-service) | [![npm version]()]() | Contracts for the Subgraph data service in Graph Horizon. |
| [token-distribution](./packages/token-distribution) | - | Contracts managing token locks for network participants |


## Development
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"workspaces": [
"packages/contracts",
"packages/eslint-graph-config",
"packages/subgraph-service",
"packages/sdk"
"packages/sdk",
"packages/solhint-graph-config",
"packages/token-distribution"
],
"scripts": {
"postinstall": "husky install",
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-graph-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.js
26 changes: 24 additions & 2 deletions packages/eslint-graph-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,30 @@ yarn add --dev eslint eslint-graph-config@workspace:^x.y.z
To enable the rules, you need to create an `eslint.config.js` file in the root of your project with the following content:

```javascript
import eslintGraphConfig from 'eslint-graph-config'
export default eslintGraphConfig
const config = require('eslint-graph-config')
module.exports = config.default
```

**Recommended config for existing projects**
The default configuration is quite strict specially with the usage of `any` and it's derivatives. For existing projects with a codebase that was developed with more lenient guidelines migrating to this configuration can be a bit overwhelming.

You can customize your `eslint.config.js` file to disable some rules and make the transition easier. For example, you can create a `eslint.config.js` file with the following content:

```javascript
const config = require('eslint-graph-config')

module.exports = [
...config.default,
{
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
},
},
]
```

## Tooling
Expand Down
14 changes: 2 additions & 12 deletions packages/eslint-graph-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
// This file only exists to enable linting on index.js
const config = require('./index.js')
const globals = require('globals')
const config = require('./index')

module.exports = [
...config,
...config.default,
{
// Additional configuration just for this package
// since it's a commonjs module and not an ES module
languageOptions: {
globals: {
...globals.node,
},
},
rules: {
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-var-requires': 'off',
},
Expand Down
49 changes: 49 additions & 0 deletions packages/eslint-graph-config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import eslint from '@eslint/js'
import globals from 'globals'
import noOnlyTests from 'eslint-plugin-no-only-tests'
import noSecrets from 'eslint-plugin-no-secrets'
import stylistic from '@stylistic/eslint-plugin'
import tseslint from 'typescript-eslint'

export default [
// Base eslint configuration
eslint.configs.recommended,

// Enable linting with type information
// https://typescript-eslint.io/getting-started/typed-linting
...tseslint.configs.recommendedTypeChecked,

// Formatting and stylistic rules
stylistic.configs['recommended-flat'],

// Custom config
{
languageOptions: {
parserOptions: {
project: ['../*/tsconfig.json', 'tsconfig.json'],
tsconfigRootDir: __dirname,
},
globals: {
...globals.node,
},
},
plugins: {
'no-only-tests': noOnlyTests,
'no-secrets': noSecrets,
},
ignores: ['dist/*', 'node_modules/*', 'build/*'],
rules: {
'prefer-const': 'warn',
'@typescript-eslint/no-inferrable-types': 'warn',
'@typescript-eslint/no-empty-function': 'warn',
'no-only-tests/no-only-tests': 'error',
'no-secrets/no-secrets': 'error',
'sort-imports': [
'warn', {
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
ignoreCase: true,
allowSeparatedGroups: true,
}],
},
},
]
17 changes: 12 additions & 5 deletions packages/eslint-graph-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
"author": "The Graph Team",
"license": "GPL-2.0-or-later",
"scripts": {
"clean": "rm -rf build",
"lint": "eslint '**/*.{js,ts}' --fix"
"clean": "rm -rf index.js",
"lint": "eslint '**/*.{js,ts}' --ignore-pattern index.js --fix",
"build": "yarn clean && tsc"
},
"devDependencies": {
"dependencies": {
"@stylistic/eslint-plugin": "^1.6.2",
"@types/node": "^20.11.19",
"eslint": "^8.56.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-no-secrets": "^0.8.9",
"typescript": "^5.3.3",
"typescript-eslint": "^7.0.2"
},
"devDependencies": {
"@types/eslint__js": "^8.42.3",
"@types/node": "^20.11.19",
"typescript": "^5.3.3"
},
"peerDependencies": {
"eslint": "^8.56.0"
}
}
2 changes: 1 addition & 1 deletion packages/eslint-graph-config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"skipLibCheck": true,
"resolveJsonModule": true
},
"include": ["index.js", "eslint.config.js"]
"include": ["index.ts", "typings/**/*.d.ts", "eslint.config.js"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'eslint-plugin-no-only-tests' {
import { FlatConfig } from 'typescript-eslint'
const plugin: FlatConfig.Plugin
export default plugin
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'eslint-plugin-no-secrets' {
import { FlatConfig } from 'typescript-eslint'
const plugin: FlatConfig.Plugin
export default plugin
}
88 changes: 88 additions & 0 deletions packages/solhint-graph-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# solhint-graph-config

This repository contains shared linting and formatting rules for Solidity projects.

## Code linting

### Installation

⚠️ Unfortunately there isn't a way to install peer dependencies using Yarn v4, so we need to install them manually.


```bash
# Install with peer packages
yarn add --dev solhint solhint-graph-config

# For projects on this monorepo
yarn add --dev solhint solhint-graph-config@workspace:^x.y.z
```

### Configuration

Run `solhint` with `node_modules/solhint-graph-config/index.js` as the configuration file. We suggest creating an npm script to make it easier to run:

```json

{
"scripts": {
"lint": "solhint --fix contracts/**/*.sol --config node_modules/solhint-graph-config/index.js"
}
}

```

## Code formatting

### Installation

⚠️ Unfortunately there isn't a way to install peer dependencies using Yarn v4, so we need to install them manually.


```bash
# Install with peer packages
yarn add --dev solhint-graph-config prettier prettier-plugin-solidity

# For projects on this monorepo
yarn add --dev solhint-graph-config@workspace:^x.y.z prettier prettier-plugin-solidity
```


### Configuration: formatting

Create a configuration file for prettier at `prettier.config.js`:

```javascript
const prettierGraphConfig = require('solhint-graph-config/prettier')
module.exports = prettierGraphConfig
```

Running `prettier` will automatically pick up the configuration file. We suggest creating an npm script to make it easier to run:

```json
{
"scripts": {
"format": "prettier --write 'contracts/**/*.sol'"
}
}
```

## Tooling

This package uses the following tools:
- [solhint](https://protofire.github.io/solhint/) as the base linting tool
- [prettier](https://prettier.io/) as the base formatting tool
- [prettier-plugin-solidity](https://github.com/prettier-solidity/prettier-plugin-solidity) to format Solidity code


## VSCode support

If you are using VSCode you can install the [Solidity extension by Nomic Foundation](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity). Unfortunately there is currently no way of getting real-time linting output from solhint, but this extension will provide formatting support using our prettier config and will also provide inline code validation using solc compiler output.

For formatting, the following settings should be added to your `settings.json` file:
```json
"[solidity]": {
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
},
```

Additionally you can configure the `Format document` keyboard shortcut to run `prettier --write` on demand.
12 changes: 12 additions & 0 deletions packages/solhint-graph-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
extends: 'solhint:recommended',
rules: {
'func-visibility': ['warn', { ignoreConstructors: true }],
'compiler-version': ['off'],
'constructor-syntax': 'warn',
'quotes': ['error', 'double'],
'reason-string': ['off'],
'not-rely-on-time': 'off',
'no-empty-blocks': 'off',
},
}
13 changes: 13 additions & 0 deletions packages/solhint-graph-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "solhint-graph-config",
"version": "0.0.1",
"description": "Linting and formatting rules for The Graph's Solidity projects",
"main": "index.js",
"author": "The Graph Team",
"license": "GPL-2.0-or-later",
"peerDependencies": {
"prettier": "^3.2.5",
"prettier-plugin-solidity": "^1.3.1",
"solhint": "^4.1.1"
}
}
15 changes: 15 additions & 0 deletions packages/solhint-graph-config/prettier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
"printWidth": 120,
"useTabs": false,
"bracketSpacing": true,
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"tabWidth": 4,
"singleQuote": false,
}
}
]
}
3 changes: 3 additions & 0 deletions packages/token-distribution/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MNEMONIC=
ETHERSCAN_API_KEY=
INFURA_KEY=
5 changes: 5 additions & 0 deletions packages/token-distribution/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build/
cache/
dist/
node_modules/
reports/
15 changes: 15 additions & 0 deletions packages/token-distribution/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"extends": ["plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
"rules": {
"prefer-const": "warn",
"no-extra-semi": "off",
"@typescript-eslint/no-extra-semi": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/no-empty-function": "warn"
}
}
Loading

0 comments on commit ab36183

Please sign in to comment.