Skip to content

Commit

Permalink
Linting (#241)
Browse files Browse the repository at this point in the history
* add rubocop

* use ruby-setup

* try

* add platform

* move gemfile to base

* start lint

* save

* move

* fix

* adding lint-staged running prettier --write

* save

* use precommit

* use pre-commit

* fix

* fix jest config

* fix lint-staged

* ignore vendored gems

* try this

* code-review
  • Loading branch information
elliothursh authored Oct 9, 2022
1 parent 1f18c6b commit cf3c9f0
Show file tree
Hide file tree
Showing 84 changed files with 734 additions and 292 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
}
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
**/dist/**
62 changes: 61 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
{
"root": true,
"parser": "@babel/eslint-parser",
"plugins": ["react", "react-hooks"],
"extends": "next/core-web-vitals",
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"globals": {
"prisma": true
},
"parserOptions": {
"requireConfigFile": false,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
"babelOptions": {
"presets": ["next/babel"],
"caller": {
// Eslint supports top level await when a parser for it is included. We enable the parser by default for Babel.
"supportsTopLevelAwait": true
}
}
},
"settings": {
"react": {
"version": "detect"
}
},
"overrides": [
{
"files": ["**/*.ts", "**/*.tsx"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-empty-function": [
"error",
{ "allow": ["arrowFunctions"] }
]
}
}
],
"rules": {
"semi": "off"
"semi": "off",
"@next/next/google-font-display": "off"
}
}
17 changes: 17 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Eslint
on:
push:
jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
cache: "yarn"
- name: Install dependencies
run: yarn
- name: Lint
run: yarn lint
5 changes: 2 additions & 3 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will do a clean installation of node dependencies, cache/restore them,
# This workflow will do a clean installation of node dependencies, cache/restore them,
# build the source code and run tests across different versions of node.
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

Expand All @@ -17,7 +17,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache: "yarn"
- name: Install dependencies
run: yarn
- name: Build the app
Expand All @@ -26,4 +26,3 @@ jobs:
run: yarn ci:test
- name: Run CI Next.js tests
run: yarn ci:test:next

14 changes: 14 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Rubocop
on:
push:
jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
bundler-cache: true
- name: Run rubocop
run: bundle exec rubocop
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
4 changes: 4 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.{js,jsx,ts,tsx}": "eslint --fix",
"*.rb": "rubocop --autocorrect"
}
19 changes: 19 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
AllCops:
NewCops: enable
Exclude:
- 'vendor/**/*'
- '**/vendor/**/*'
- 'node_modules/**/*'
- '**/node_modules/**/*'

Metrics/AbcSize:
Max: 50

Metrics/MethodLength:
Max: 50

Metrics/ClassLength:
Max: 200

Style/Documentation:
Enabled: false
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'

group :development, :test do
gem 'pry', '0.14.1'
gem 'rubocop', '1.36'
end
42 changes: 42 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
coderay (1.1.3)
json (2.6.2)
method_source (1.0.0)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rainbow (3.1.1)
regexp_parser (2.6.0)
rexml (3.2.5)
rubocop (1.36.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
unicode-display_width (2.3.0)

PLATFORMS
arm64-darwin-21
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
pry (= 0.14.1)
rubocop (= 1.36)

BUNDLED WITH
2.3.7
9 changes: 6 additions & 3 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ For development, you may want to have a demo next app that pulls in your changes
- cd into packages/cli and run `yarn cypress run`

### Run embedded jest tests for the preview server
During the smoke test process described below, the jest tests in `scripts/e2e_test/jest_tests` are copied into the directory where each target framework is installed and run. Before testing them in the framework install context, however, you will want to make sure they pass on the latest build by running `yarn build` and then `yarn e2e:jest` in the mailing project root.

During the smoke test process described below, the jest tests in `scripts/e2e_test/jest_tests` are copied into the directory where each target framework is installed and run. Before testing them in the framework install context, however, you will want to make sure they pass on the latest build by running `yarn build` and then `yarn e2e:jest` in the mailing project root.

## Smoke tests
The directory `scripts/e2e_test` contains smoke tests targeting supported frameworks that should be run before every public npm release. Each test uses the `yarn create` command to create new projects from their `create-*` starter kits and then runs the cypress cli tests contained in `packages/cli/cypress` and the jest tests contained in `scripts/e2e_test/jest_tests`.

The directory `scripts/e2e_test` contains smoke tests targeting supported frameworks that should be run before every public npm release. Each test uses the `yarn create` command to create new projects from their `create-*` starter kits and then runs the cypress cli tests contained in `packages/cli/cypress` and the jest tests contained in `scripts/e2e_test/jest_tests`.

The frameworks currently covered by the tests are:

- standalone (no framework)
- turbo (Turbo monorepo)
- next_ts (Next.js with Typescript)
Expand Down Expand Up @@ -78,4 +81,4 @@ The script supports some options for running:

**Cache the framework installs for faster runs**

- Use the `--save-cache` flag to save each framework install (before mailing is added) to the `cache` directory. Subsequent test runs will use the cache instead of running `yarn create` and `yarn install`, which will speed things up 🏎 If you need to reset the cache, e.g. if you want to test a newer version of the framework or if the framework install process changes, you can delete the cache directory or the subdirectory containing the specific framework you are targeting.
- Use the `--save-cache` flag to save each framework install (before mailing is added) to the `cache` directory. Subsequent test runs will use the cache instead of running `yarn create` and `yarn install`, which will speed things up 🏎 If you need to reset the cache, e.g. if you want to test a newer version of the framework or if the framework install process changes, you can delete the cache directory or the subdirectory containing the specific framework you are targeting.
3 changes: 1 addition & 2 deletions docs/DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ Here’s a working Vercel configuration:

<img width="793" alt="Screen Shot 2022-09-26 at 11 57 06 AM" src="https://user-images.githubusercontent.com/282016/192357879-a19ec556-00c3-49b6-883c-6ae55e8eff7f.png">


#### CLI

Alternatively, `mailing deploy` deploys your server to Vercel via their interactive CLI.

### Other hosts

If you want to deploy somewhere else, you can use `mailing server build` to build the production next app and `mailing server start` to boot it on localhost. The first command runs `next build .mailing` and the second command runs `next start .mailing`.
If you want to deploy somewhere else, you can use `mailing server build` to build the production next app and `mailing server start` to boot it on localhost. The first command runs `next build .mailing` and the second command runs `next start .mailing`.
1 change: 1 addition & 0 deletions jest.next.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import type { Config } from "jest";

const nextJest = require("next/jest");
Expand Down
32 changes: 19 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"name": "mailing-monorepo",
"homepage": "https://github.com/sofn-xyz/mailing#readme",
"version": "0.1.0",
"private": true,
"type": "module",
"license": "MIT",
"workspaces": [
"packages/*"
],
"scripts": {
"lint": "eslint .",
"dev": "cd packages/cli && rm -rf .mailing && src/dev.js",
"dev:js": "yarn link:emails:js && yarn dev",
"dev:init": "cd packages/cli && rm -rf previews_html; rm -rf .mailing emails mailing.config.json; src/dev.js",
Expand All @@ -18,18 +24,16 @@
"ci:test:next": "start-server-and-test ci:server http://localhost:3883 test:next",
"ci:server": "cd packages/cli && rm -rf .mailing && src/dev.js --quiet",
"prepublish": "yarn build",
"postinstall": "husky install && preconstruct dev",
"watch": "preconstruct watch",
"release": "yarn build && ./scripts/prepare-release && yarn changeset publish",
"postinstall": "preconstruct dev",
"e2e": "cd scripts/e2e_test/ && bundle && bundle exec ruby e2e_test.rb",
"e2e:jest": "yarn jest --rootDir=scripts/e2e_test/jest_tests -c scripts/e2e_test/jest_tests/jest.config.js"
},
"license": "MIT",
"workspaces": [
"packages/*"
],
"homepage": "https://github.com/sofn-xyz/mailing#readme",
"devDependencies": {
"@babel/core": "^7.18.5",
"@babel/eslint-parser": "^7.19.1",
"@babel/preset-env": "^7.18.2",
"@babel/preset-react": "^7.17.12",
"@babel/preset-typescript": "^7.17.12",
"@changesets/cli": "^2.23.0",
Expand All @@ -39,25 +43,27 @@
"@types/jest": "^28.1.6",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@typescript-eslint/parser": "^5.39.0",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"eslint": "8.20.0",
"husky": "^8.0.1",
"jest": "^29.0.3",
"jest-environment-jsdom": "^29.0.3",
"lint-staged": "^13.0.3",
"next-router-mock": "^0.7.4",
"prettier": "^2.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"start-server-and-test": "^1.14.0",
"ts-jest": "29",
"ts-node": "^10.9.1"
"ts-node": "^10.9.1",
"yalc": "^1.0.0-pre.53"
},
"preconstruct": {
"packages": [
"packages/cli",
"packages/core"
]
},
"dependencies": {
"@babel/core": "^7.18.5",
"@babel/preset-env": "^7.18.2",
"start-server-and-test": "^1.14.0",
"yalc": "^1.0.0-pre.53"
}
"dependencies": {}
}
6 changes: 0 additions & 6 deletions packages/cli/.eslintrc.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[![Featured on Openbase](https://badges.openbase.com/js/featured/mailing.svg?token=A6xfdFmUU161m5Jns1Aqf4SwwIMSQBipWCm7HCdl1wc=)](https://openbase.com/js/mailing?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
[![](https://dcbadge.vercel.app/api/server/fdSzmY46wY?style=flat)](https://discord.gg/fdSzmY46wY)


<h2>●&nbsp;&nbsp;Build, test, send emails with React</h2>

- Email templates with React components
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineConfig({
e2e: {
defaultCommandTimeout: 10000,
baseUrl: "http://localhost:3883",
setupNodeEvents(on, config) {
setupNodeEvents(_on, _config) {
// implement node event listeners here
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
// }
4 changes: 2 additions & 2 deletions packages/cli/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')
// require('./commands')
1 change: 0 additions & 1 deletion packages/cli/cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
},
"include": ["**/*.ts"]
}

4 changes: 0 additions & 4 deletions packages/cli/src/commands/__test__/deploy.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import prompts from "prompts";
import fsExtra, { removeSync } from "fs-extra";
import { handler, InitArguments } from "../init";
import { log } from "../../util/log";
import { execCli } from "./execCli";

jest.mock("../../util/log");
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/__test__/execCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export async function execCli(command: string, opts?: { debug: boolean }) {
});
}

export function execCliChild(command: string, opts?: { debug: boolean }) {
export function execCliChild(command: string, _opts?: { debug: boolean }) {
return exec(`FORCE_COLOR=0 ${__dirname}/../../dev.js ${command}`);
}
Loading

1 comment on commit cf3c9f0

@vercel
Copy link

@vercel vercel bot commented on cf3c9f0 Oct 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mailing-dynamic-demo – ./packages/cli

mailing-dynamic-demo-git-main-sofn.vercel.app
demo.mailing.run
mailing-dynamic-demo.vercel.app
mailing-dynamic-demo-sofn.vercel.app

Please sign in to comment.