Skip to content

Commit

Permalink
chore: enforce prettier (#433)
Browse files Browse the repository at this point in the history
* setting up pre-commit checks

* prettifies all files

* husky pre-commit setup

* package.json updates

* adds docs and github action

* chore: updates action

* removes npm ci scripts and prettier from individual packages

* reverting formatting to secp256k1 byte array
  • Loading branch information
krpeacock authored May 25, 2021
1 parent 979990f commit 4164ea9
Show file tree
Hide file tree
Showing 86 changed files with 1,059 additions and 886 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
"plugin:jsdoc/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"jsdoc"
],
"plugins": ["@typescript-eslint", "jsdoc"],
"rules": {
"jsdoc/newline-after-description": "off",
"jsdoc/require-returns-type": "off",
Expand Down
18 changes: 10 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/nodejs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-18.04]
ghc: ["8.8.4"]
ghc: ['8.8.4']
spec:
- release-0.16 # https://github.com/dfinity-lab/ic-ref/tree/release-0.16
node:
Expand Down Expand Up @@ -38,13 +38,13 @@ jobs:

- uses: actions/setup-python@v2
with:
python-version: "3.8"
python-version: '3.8'
- run: pip3 install mitmproxy~=6.0.2

# IC ref checkout and build.
- uses: actions/checkout@v2
with:
repository: "dfinity-lab/ic-ref"
repository: 'dfinity-lab/ic-ref'
# Personal Read-only Access Token created by Hans Larsen
token: ${{ secrets.IC_REF_TOKEN }}
path: ic-ref
Expand All @@ -61,7 +61,7 @@ jobs:
- uses: actions/[email protected]
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: "3.2"
cabal-version: '3.2'

- name: Cargo cache
uses: actions/cache@v2
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check Formatting
on:
pull_request:
types:
- opened
- reopened
- edited
- synchronize

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-18.04]
ghc: ['8.8.4']
spec:
- release-0.16 # https://github.com/dfinity-lab/ic-ref/tree/release-0.16
node:
- 14
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install -g npm
- run: npm install prettier pretty-quick
- run: npm run prettier:check
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
canary:
default: "true"
default: 'true'

jobs:
release:
Expand Down
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx pretty-quick --staged --branch next
4 changes: 2 additions & 2 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pull_request_rules:
- name: Automatic merge
conditions:
- "#approved-reviews-by>=1"
- "#changes-requested-reviews-by=0"
- '#approved-reviews-by>=1'
- '#changes-requested-reviews-by=0'
- status-success=conventional-pr-title
- label=automerge-squash
actions:
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ commands to keep in mind;
but there is no guarantee that the `next` branch will work with the latest published dfx.
Once you have a replica running locally, you must pass the port to the e2e tests using the
`IC_REF_PORT` environment vairable. If that variable is not set, the tests will fail.
- To run the entire ci, use `npm run ci`. This will validate syntax and linting, as well
as running tests (both unit and e2e).

### Publishing

Expand Down Expand Up @@ -77,3 +75,7 @@ Monorepo-related scripts run in this order, but are usually invoked by `npm inst
- It copies devtools dependencies from ./packages/agent-js-devtools/node_modules -> ./node_modules
- build - Build (`npm run build`) each subpackage in ./packages/
- test - Run `npm test` in each subpackage

### Formatting

To save time on formatting, we use automated formatting for this repo using prettier. You can either use git pre-commit hooks or run the command `npm exec prettier:format` before submitting your PR to have your changes pass. We check formatting on CI.
6 changes: 5 additions & 1 deletion apps/sw-cert/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# Certifying Service Worker

Certified fun guaranteed.

## Build

From the root of this repo, `npm ci && npm build --workspaces --if-present`. The output should be in a `dist/`
folder next to this file.

### Build With FETCH_ROOT_KEY

By setting the `FORCE_FETCH_ROOT_KEY` environment variable prior to building, the service worker will
always fetch the root key of the network before doing the validation.

**THIS SHOULD ONLY BE USED ON A TEST OR LOCAL NETWORK.** The IC mainnet public key is hard coded in
the agent and, for security reasons, should not be fetched by the agent.

## Develop

You will need to build the rest of the repo first (see Build section above) so that the agent packages are available when building this app.

Start a replica on the port 8080 (doesn't have to be `dfx start` or a proxy, can be a plain replica).

Start a watch mode webpack build with `npm run build -- --watch`.

To start the local development instance: `cd apps/sw-cert && npm start`. This will start serving the files built. Any path that don't match a file instead will be sent to localhost:8000.
To start the local development instance: `cd apps/sw-cert && npm start`. This will start serving the files built. Any path that don't match a file instead will be sent to localhost:8000.

It's important to not use `webpack-dev-server` (even if it's available) as it is not fully compatible with Service Workers.
80 changes: 39 additions & 41 deletions apps/sw-cert/src/index.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
<html>
<head>
<meta charset="utf8">
<title>Internet Computer Content Validation Bootstrap</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<style>
html, body {
padding: 0;
margin: 0;
height: 100%;
}
body {
text-align: center;
font-size: 16px;
padding: 5em 1em 1em;
box-sizing: border-box;
font-family: sans-serif;
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
}
footer a {
padding: 1em;
display: inline-block;
}
</style>
</head>
<body>
<main>
<div>
<h1>Installing &quot;Internet Computer Validating Service Worker&quot;...</h1>
<p>Please wait one moment. Blockchain cryptography will make this domain more secure.</p>
<head>
<meta charset="utf8" />
<title>Internet Computer Content Validation Bootstrap</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<style>
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
body {
text-align: center;
font-size: 16px;
padding: 5em 1em 1em;
box-sizing: border-box;
font-family: sans-serif;
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
}
footer a {
padding: 1em;
display: inline-block;
}
</style>
</head>
<body>
<main>
<div>
<h1>Installing &quot;Internet Computer Validating Service Worker&quot;...</h1>
<p>Please wait one moment. Blockchain cryptography will make this domain more secure.</p>

<progress> Loading... </progress>
</div>
<div id="status">
</div>
</main>
<footer>
</footer>

</body>
<progress>Loading...</progress>
</div>
<div id="status"></div>
</main>
<footer></footer>
</body>
</html>
15 changes: 10 additions & 5 deletions apps/sw-cert/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function updateStatus(message: string) {
const statusEl = document.getElementById('status');
if (statusEl) {
Expand All @@ -11,10 +10,12 @@ window.addEventListener('load', async () => {
if (!window.navigator.serviceWorker) {
updateStatus(
`This web browser cannot interact with the Internet Computer securely.
Please try new web browser software.`
Please try new web browser software.`,
);
} else {
console.log("Installing a service worker to proxy and validate raw content into the browser...");
console.log(
'Installing a service worker to proxy and validate raw content into the browser...',
);
// Ok, let's install the service worker...
// note: if the service worker was already installed, when the browser requested <domain>/, it would have
// proxied the response from <domain>/<canister-id>/, so this bootstrap file would never been
Expand All @@ -23,7 +24,9 @@ window.addEventListener('load', async () => {
// Webpack recognizes this special syntax so it's okay to ignore that this isn't a string.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const reg = await navigator.serviceWorker.register(new URL("./sw/sw.ts", import.meta.url) as any);
const reg = await navigator.serviceWorker.register(
new URL('./sw/sw.ts', import.meta.url) as any,
);
if (reg.installing) {
const sw = reg.installing || reg.waiting;
sw.onstatechange = () => {
Expand All @@ -36,7 +39,9 @@ window.addEventListener('load', async () => {
// would have obtained the underlying raw content from the canister, validated it, and proxied
// it to the browser. This might be either a disabled SW or the user did a hard reload on the
// page.
setTimeout(function() { window.location.reload(); }, 800)
setTimeout(function () {
window.location.reload();
}, 800);
}
}
});
Loading

0 comments on commit 4164ea9

Please sign in to comment.