Skip to content

Commit

Permalink
chore: add dev checks
Browse files Browse the repository at this point in the history
- [x] Add linter
- [x] Add type check
- [x] Fix linter and type errors
- [x] Add main ci checks
  • Loading branch information
0xmad committed Jun 22, 2024
1 parent e60b5ce commit 7333f89
Show file tree
Hide file tree
Showing 158 changed files with 4,614 additions and 3,281 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

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

[*.{yaml,yml}]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
16 changes: 3 additions & 13 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# ------------------
# AUTH CONFIGURATION
# ------------------

# You can generate a new secret on the command line with: `openssl rand -base64 32`
# https://next-auth.js.org/configuration/options#secret
NEXTAUTH_SECRET="secret"

# Domain where your app will be hosted (set to http://localhost:3000 for running locally)
# (if this is not configured correctly, signing the wallet message to sign in will not work)
NEXTAUTH_URL="https://<project>.vercel.app"
# NEXTAUTH_URL="http://localhost:3000"

# Storage for metadata
# Create a Blob database and get token here: https://vercel.com/dashboard/stores?type=blob
BLOB_READ_WRITE_TOKEN=

# ---------------------
# NETWORK CONFIGURATION
Expand Down
11 changes: 11 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
dist
.next
coverage
build
typechain-types
.eslintrc.js
commitlint.config.js
subgraph/generated
public/mockServiceWorker.js

183 changes: 161 additions & 22 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,176 @@
/** @type {import("eslint").Linter.Config} */
const config = {
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
plugins: ["@typescript-eslint"],
const fs = require("fs");
const path = require("path");

const prettierConfig = fs.readFileSync(path.resolve(__dirname, "./.prettierrc"), "utf8");
const prettierOptions = JSON.parse(prettierConfig);
const isProduction = process.env.NODE_ENV === "production";

module.exports = {
root: true,
extends: [
"plugin:@next/next/recommended",
"airbnb",
"prettier",
"next/core-web-vitals",
"plugin:import/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/strict",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:import/typescript",
"plugin:react/recommended",
],
plugins: ["json", "prettier", "unused-imports", "import", "@typescript-eslint", "react-hooks"],
parser: "@typescript-eslint/parser",
env: {
browser: true,
node: true,
jest: true,
es2022: true,
},
settings: {
react: {
version: "18",
},
"import/resolver": {
typescript: {},
node: {
extensions: [".ts", ".js", ".tsx", ".jsx"],
moduleDirectory: ["node_modules", "src"],
},
},
},
parserOptions: {
project: path.resolve(__dirname, "./tsconfig.json"),
sourceType: "module",
typescript: true,
ecmaVersion: 2022,
experimentalDecorators: true,
requireConfigFile: false,
ecmaFeatures: {
classes: true,
impliedStrict: true,
},
warnOnUnsupportedTypeScriptVersion: true,
},
reportUnusedDisableDirectives: isProduction,
rules: {
// These opinionated rules are enabled in stylistic-type-checked above.
// Feel free to reconfigure them to your own preference.
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"import/no-cycle": ["error"],
"unused-imports/no-unused-imports": "error",
"import/no-extraneous-dependencies": [
"error",
{
devDependencies: ["**/*.test.ts", "./src/test-msw.ts", "./src/test-setup.ts", "./src/lib/eas/*.ts"],
},
],
"no-debugger": isProduction ? "error" : "off",
"no-console": "error",
"no-underscore-dangle": "error",
"no-redeclare": ["error", { builtinGlobals: true }],
"import/order": [
"error",
{
groups: ["external", "builtin", "internal", "type", "parent", "sibling", "index", "object"],
alphabetize: {
order: "asc",
caseInsensitive: true,
},
warnOnUnassignedImports: true,
"newlines-between": "always",
},
],
"prettier/prettier": ["error", prettierOptions],
"import/prefer-default-export": "off",
"import/extensions": ["error", { json: "always" }],
"class-methods-use-this": "off",
"prefer-promise-reject-errors": "off",
"max-classes-per-file": "off",
"no-use-before-define": ["off"],
"no-shadow": "off",
curly: ["error", "all"],

"@typescript-eslint/consistent-type-imports": [
"warn",
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "no-public" }],
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/use-unknown-in-catch-callback-variable": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-use-before-define": ["error", { functions: false, classes: false }],
"@typescript-eslint/no-misused-promises": ["error", { checksVoidReturn: false }],
"@typescript-eslint/no-shadow": [
"error",
{
prefer: "type-imports",
fixStyle: "inline-type-imports",
builtinGlobals: true,
allow: [
"alert",
"location",
"event",
"history",
"name",
"status",
"Option",
"Image",
"Lock",
"test",
"expect",
"describe",
"beforeAll",
"afterAll",
],
},
],
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-misused-promises": [
"@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true }],

"react/jsx-filename-extension": [
"error",
{
checksVoidReturn: { attributes: false },
extensions: [".tsx", ".jsx", ".js"],
},
],
"react/no-unknown-property": ["error", { ignore: ["tw", "global", "jsx"] }],
"react/jsx-sort-props": [
"error",
{
callbacksLast: true,
shorthandFirst: true,
ignoreCase: true,
reservedFirst: true,
},
],
"react/sort-prop-types": [
"error",
{
callbacksLast: true,
},
],
"react/react-in-jsx-scope": "off",
"react/jsx-boolean-value": "error",
"react/jsx-handler-names": "error",
"react/prop-types": "error",
"react/jsx-no-bind": "error",
"react-hooks/rules-of-hooks": "error",
"react/no-array-index-key": "warn",
"jsx-a11y/no-static-element-interactions": "warn",
"jsx-a11y/click-events-have-key-events": "warn",
"jsx-a11y/anchor-is-valid": "warn",
"react/jsx-props-no-spreading": "off",
"react/forbid-prop-types": "off",
"react/state-in-constructor": "off",
"react/jsx-fragments": "off",
"react/static-property-placement": ["off"],
"react/jsx-newline": ["error", { prevent: false }],
"jsx-a11y/label-has-associated-control": "off",
"jsx-a11y/label-has-for": "off",
"react/require-default-props": [
"error",
{
functions: "defaultArguments",
},
],
"react/no-unused-prop-types": "error",
"react/function-component-definition": ["error", { namedComponents: ["arrow-function"] }],
},
};

module.exports = config;
16 changes: 16 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Lines starting with '#' are comments.
# Each line is a file pattern followed by one or more owners.

# More details are here: https://help.github.com/articles/about-codeowners/

# The '*' pattern is global owners.

# Order is important. The last matching pattern has the most precedence.
# The folders are ordered as follows:

# In each subsection folders are ordered first by depth, then alphabetically.
# This should make it easy to add new rules without breaking existing ones.

# Global:

* @ctrlc03 @kittybest @0xmad @crisgarner
49 changes: 49 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Checks

on:
push:
branches: [main]
pull_request:

env:
NEXT_PUBLIC_CHAIN_NAME: ${{ vars.NEXT_PUBLIC_CHAIN_NAME }}
NEXT_PUBLIC_ADMIN_ADDRESS: ${{ vars.NEXT_PUBLIC_ADMIN_ADDRESS }}
NEXT_PUBLIC_APPROVAL_SCHEMA: ${{ vars.NEXT_PUBLIC_APPROVAL_SCHEMA }}
NEXT_PUBLIC_METADATA_SCHEMA: ${{ vars.NEXT_PUBLIC_METADATA_SCHEMA }}
NEXT_PUBLIC_ROUND_ID: ${{ vars.NEXT_PUBLIC_ROUND_ID }}
NEXT_PUBLIC_SKIP_APPROVED_VOTER_CHECK: false
NEXT_PUBLIC_MACI_ADDRESS: ${{ vars.NEXT_PUBLIC_MACI_ADDRESS }}
NEXT_PUBLIC_TALLY_URL: ${{ vars.NEXT_PUBLIC_TALLY_URL }}
NEXT_PUBLIC_WALLETCONNECT_ID: ${{ secrets.NEXT_PUBLIC_WALLETCONNECT_ID }}

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

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

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 8

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

- name: Install
run: |
pnpm install
- name: ${{ matrix.command }}
run: pnpm run ${{ matrix.command }}
46 changes: 46 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "CodeQL"

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "0 0 * * *"

jobs:
analyze:
name: analyze
runs-on: ubuntu-22.04
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ["javascript-typescript"]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
32 changes: 32 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Commitlint

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
commitlint:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 8

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

- name: Install
run: |
pnpm install --frozen-lockfile --prefer-offline
- run: pnpm exec commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
Loading

0 comments on commit 7333f89

Please sign in to comment.