Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed linting #909

Merged
merged 44 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9e528e0
reconfigure eslint
goastler Dec 8, 2023
1f0707d
move file extensions to eslint config
goastler Dec 8, 2023
14a6177
move eslint config to esm format
goastler Dec 8, 2023
efd5f5c
move back to cjs
goastler Dec 8, 2023
4753c7e
remove eslint-plugin-prettier
goastler Dec 8, 2023
009d30a
start eslint config from scratch
goastler Dec 8, 2023
dd66e89
reconfigure eslint config
goastler Dec 9, 2023
c270ab8
remove typed linting from eslint
goastler Dec 11, 2023
ea5e1a4
lint
goastler Dec 11, 2023
141eb36
add lint scripts to each package, delegate using npm workspaces command
goastler Dec 11, 2023
ad87367
add workspace linting script to default lint command
goastler Dec 11, 2023
ce19bd6
remove eslint config from pkg json of client-example
goastler Dec 11, 2023
b7489af
allow prettier to not find files matching pattern
goastler Dec 11, 2023
342aadb
lint
goastler Dec 11, 2023
ef9c12c
move file extensions for linting into prettier and eslint config
goastler Dec 11, 2023
5b9674f
remove extensions from linting commands, use config instead
goastler Dec 11, 2023
87803cf
generalise prettier rules
goastler Dec 11, 2023
13a664b
lint
goastler Dec 11, 2023
9df9500
remove html from general files config in eslint in favour of html-esl…
goastler Dec 11, 2023
5fffb15
add missing plugin to eslint config
goastler Dec 11, 2023
cd9daec
add lang attribute to html
goastler Dec 11, 2023
7114d18
fix workspace paths for linting
goastler Dec 11, 2023
d78aea4
lint
goastler Dec 11, 2023
6cf2fcb
install markdown linter
goastler Dec 11, 2023
c2f3fa7
enable markdown linting
goastler Dec 11, 2023
18ece01
Update .prettierrc.js
goastler Dec 11, 2023
019f6e5
add missing plugin
goastler Dec 11, 2023
31ead34
remove md support
goastler Dec 11, 2023
3348ac6
ignore readme and diagram for eslint
goastler Dec 11, 2023
94d59ba
lint
goastler Dec 11, 2023
bbd718a
Merge branch 'main' into split-lint-commands
goastler Dec 11, 2023
f3a60cf
Merge branch 'main' into split-lint-commands
goastler Dec 11, 2023
7fab9e8
use tsx
goastler Dec 11, 2023
00b0f7f
lint
goastler Dec 11, 2023
375e6e5
disable eslint closing tags and spaces in attributes for html linting
goastler Dec 11, 2023
4a165b0
make prettier run last in vscode
goastler Dec 11, 2023
5d0930e
add stylistic ts linting
goastler Dec 11, 2023
fd5fd61
bump eslint typescript version
goastler Dec 11, 2023
081b11f
remove needless eslintrc config in provider gui
goastler Dec 11, 2023
2597b9d
remove eslint disable line
goastler Dec 11, 2023
c3ae73c
disable rule enforcing use of Record type
goastler Dec 11, 2023
ae80ec8
customise ts rules
goastler Dec 11, 2023
21d358d
lint
goastler Dec 11, 2023
bcf8637
typechain
goastler Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic',
'plugin:yaml/recommended',
'plugin:json/recommended',
'plugin:toml/standard',
Expand All @@ -21,22 +22,22 @@ module.exports = {
'@typescript-eslint',
'workspaces',
'unused-imports',
'@html-eslint',
'sort-imports-es6-autofix',
// do not add prettier to plugins otherwise rule conflicts will occur between prettier and eslint! run prettier as a separate command
],
root: true,
rules: {
'@typescript-eslint/no-unused-vars': 'warn', // allow unused vars
'@typescript-eslint/no-explicit-any': 'warn', // allow any type
'@typescript-eslint/prefer-for-of': 'warn', // allow indexed loops
'@typescript-eslint/consistent-type-assertions': 'off', // needs tsconfig to be set up
'@typescript-eslint/consistent-indexed-object-style': 'off', // allow indexed objects instead of Record<A, B>
'@typescript-eslint/array-type': 'off', // allow Array<A> or A[]
'@typescript-eslint/consistent-type-definitions': 'off', // allow type Foo = { a: string } or interface Foo { a: string }
'no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
'unused-imports/no-unused-vars': 'off',
//"indent": ["error", 4],
//"indent": "off",
'sort-imports': [
Expand All @@ -56,4 +57,39 @@ module.exports = {
],
'json/*': ['error', { allowComments: true }],
},
overrides: [
{
files: ['*.html'],
parser: '@html-eslint/parser',
extends: ['plugin:@html-eslint/recommended'],
rules: {
'@html-eslint/no-extra-spacing-attrs': 'off',
'@html-eslint/require-closing-tags': 'off',
},
},
{
files: [
'*.ts',
'*.tsx',
'*.js',
'*.jsx',
'*.mjs',
'*.cjs',
'*.json',
'*.yaml',
'*.yml',
'*.toml',
'*.d.ts',
'*.cts',
'*.mts',
'.*.json',
'.*.js',
'.*.mjs',
'.*.cjs',
'.*.yaml',
'.*.yml',
'.*.toml',
],
},
],
}
28 changes: 28 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,32 @@ export default {
semi: false,
singleQuote: true,
printWidth: 120,
overrides: [
{
files: [
'*.md',
'*.html',
'*.ts',
'*.tsx',
'*.js',
'*.jsx',
'*.mjs',
'*.cjs',
'*.json',
'*.yaml',
'*.yml',
'*.toml',
'*.d.ts',
'*.cts',
'*.mts',
'.*.json',
'.*.js',
'.*.mjs',
'.*.cjs',
'.*.yaml',
'.*.yml',
'.*.toml',
],
},
],
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"files.autoSave": "onFocusChange",
"vs-code-prettier-eslint.prettierLast": "false",
"vs-code-prettier-eslint.prettierLast": "true",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
Expand Down
52 changes: 23 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ via HTTPS and can
be placed anywhere on the page. Inside the <head> tag or immediately after the `.procaptcha` container are both fine.

```html

<script src="https://js.prosopo.io/js/procaptcha.bundle.js" async defer></script>
```

Expand All @@ -31,10 +30,9 @@ typically a `<div>` (but can be any element) and must have class `procaptcha` an
public
site key.

```html

```html
<body>
<div class="procaptcha" data-sitekey="your_site_key"></div>
<div class="procaptcha" data-sitekey="your_site_key"></div>
</body>
```

Expand All @@ -44,28 +42,27 @@ verification.
You can retrieve it server side with POST parameter `procaptcha-response`.

Here's a full example where Procaptcha is being used to protect a signup form from automated abuse. When the form is
submitted, the `procaptcha-response` JSON data will be included with the email and password POST data after the captcha
submitted, the `procaptcha-response` JSON data will be included with the email and password POST data after the captcha
is
solved.

#### Example of implicit rendering

```html

<html>
<head>
<title>Procaptcha Demo</title>
<script src="https://js.prosopo.io/js/procaptcha.bundle.js" async defer></script>
</head>
<body>
<form action="" method="POST">
<input type="text" name="email" placeholder="Email"/>
<input type="password" name="password" placeholder="Password"/>
<div class="procaptcha" data-sitekey="your_site_key"></div>
<br/>
<input type="submit" value="Submit"/>
</form>
</body>
<head>
<title>Procaptcha Demo</title>
<script src="https://js.prosopo.io/js/procaptcha.bundle.js" async defer></script>
</head>
<body>
<form action="" method="POST">
<input type="text" name="email" placeholder="Email" />
<input type="password" name="password" placeholder="Password" />
<div class="procaptcha" data-sitekey="your_site_key"></div>
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
```

Expand All @@ -80,14 +77,13 @@ The script is loaded in the head of the document and given the id `procaptcha-sc
id `procaptcha-container` where the widget will be rendered.

```html

<html>
<head>
<script id="procaptcha-script" src="https://js.prosopo.io/js/procaptcha.bundle.js" async defer></script>
</head>
<body>
<div id="procaptcha-container"></div>
</body>
<head>
<script id="procaptcha-script" src="https://js.prosopo.io/js/procaptcha.bundle.js" async defer></script>
</head>
<body>
<div id="procaptcha-container"></div>
</body>
</html>
```

Expand All @@ -96,7 +92,6 @@ An `onload` event is added to the script tag to call the render function when th
```javascript
// A function that will call the render Procaptcha function when the procaptcha script has loaded
document.getElementById('procaptcha-script').addEventListener('load', function () {

// Define a callback function to be called when the CAPTCHA is verified
window.onCaptchaVerified = function (output) {
console.log('Captcha verified, output: ' + JSON.stringify(output))
Expand All @@ -117,7 +112,7 @@ The output from the `onCaptchaVerified` function is the `procaptcha-response` JS
data contains the following fields:

| Key | Type | Description |
|--------------|--------|-------------------------------------------------------------------------------------------------------------------------------|
| ------------ | ------ | ----------------------------------------------------------------------------------------------------------------------------- |
| commitmentId | string | The commitment ID of the captcha challenge. This is used to verify the user's response on-chain. |
| providerUrl | string | The URL of the provider that the user used to solve the captcha challenge. |
| dapp | string | The SITE_KEY of your application / website |
Expand All @@ -142,4 +137,3 @@ if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {

There is an example server side implementation
in [demos/client-example-server](https://github.com/prosopo/captcha/tree/main/demos/client-example-server).

8 changes: 6 additions & 2 deletions contracts/captcha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build",
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix --config ../../.eslintrc.js"
"eslint": "npx eslint . --no-error-on-unmatched-pattern",
"eslint:fix": "npm run eslint -- --fix",
"prettier": "npx prettier . --check --no-error-on-unmatched-pattern",
"prettier:fix": "npm run prettier -- --write",
"lint": "npm run eslint && npm run prettier",
"lint:fix": "npm run eslint:fix && npm run prettier:fix"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion contracts/captcha/src/captcha.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0x14647df58e0d35fa467371fb8d655151e814528246dc79649ced4cb3a49fdf83",
"hash": "0xc3e9367adefe6f9a6eade416c5cdf92aec41e19b7f0a0e341a8a07a1ae51e2af",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/captcha/src/contract-info/captcha.ts

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions contracts/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"scripts": {
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix --config ../../.eslintrc.js"
"eslint": "npx eslint . --no-error-on-unmatched-pattern",
"eslint:fix": "npm run eslint -- --fix",
"prettier": "npx prettier . --check --no-error-on-unmatched-pattern",
"prettier:fix": "npm run prettier -- --write",
"lint": "npm run eslint && npm run prettier",
"lint:fix": "npm run eslint:fix && npm run prettier:fix"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion contracts/common/src/common.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0xa7a3f05a5bc911ab3649c713e14e5bab0424b9daa8ff557ebafb41274bdb6148",
"hash": "0x5ca7b28762b19db333dfea1e595b6b66a62e4f6391397eadbaf030de190b3248",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/common/src/contract-info/common.ts

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions contracts/proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"scripts": {
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix --config ../../.eslintrc.js"
"eslint": "npx eslint . --no-error-on-unmatched-pattern",
"eslint:fix": "npm run eslint -- --fix",
"prettier": "npx prettier . --check --no-error-on-unmatched-pattern",
"prettier:fix": "npm run prettier -- --write",
"lint": "npm run eslint && npm run prettier",
"lint:fix": "npm run eslint:fix && npm run prettier:fix"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions contracts/proxy/src/contract-info/proxy.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/proxy/src/proxy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0x79d9d3275367b58a1d70d7085bf2aef7df9b10c74be7efed539d04f4f4fc54ee",
"hash": "0x6c943259434253b483113cea84f109257b388fcd8f572bd959abf53d8848a7d6",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
2 changes: 1 addition & 1 deletion demos/client-bundle-example/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Getting Started with the Client Bundle Example

This project is a *minimal* example demonstrating how to include the Prosopo Procaptcha bundle in a client app.
This project is a _minimal_ example demonstrating how to include the Prosopo Procaptcha bundle in a client app.

## How to run locally

Expand Down
8 changes: 7 additions & 1 deletion demos/client-bundle-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
},
"scripts": {
"start": "light-server -s ./src -p 9232 -w \"**/*.html,**/*.css,**/*.js,**/*.gz\"",
"clean": "echo 'nothing to clean'"
"clean": "echo 'nothing to clean'",
"eslint": "npx eslint . --no-error-on-unmatched-pattern",
"eslint:fix": "npm run eslint -- --fix",
"prettier": "npx prettier . --check --no-error-on-unmatched-pattern",
"prettier:fix": "npm run prettier -- --write",
"lint": "npm run eslint && npm run prettier",
"lint:fix": "npm run eslint:fix && npm run prettier:fix"
},
"dependencies": {
"dotenv": "^16.0.1",
Expand Down
Loading