Skip to content

Commit

Permalink
Add linting to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sbihel committed Apr 10, 2024
1 parent 9ae4850 commit b31bef6
Show file tree
Hide file tree
Showing 10 changed files with 11,724 additions and 5,613 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ jobs:
npm run build
- name: Run tests
run: ETHERSJS_VERSION=${{ matrix.ethers }} npm run test
- name: Run lints
run: npm run lint
17,271 changes: 11,676 additions & 5,595 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"build": "lerna run build",
"test": "lerna run --stream test",
"lint": "lerna run lint",
"docs": "typedoc --plugin nlfurniss-typedoc-plugin-sourcefile-url --plugin typedoc-plugin-extras --sourcefile-url-prefix 'https://github.com/spruceid/siwe' --favicon ./favicon.svg --out docs packages/siwe/lib/siwe.ts"
},
"author": "Spruce Systems Inc.",
Expand Down
3 changes: 3 additions & 0 deletions packages/siwe-parser/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
jest.config.js
11 changes: 11 additions & 0 deletions packages/siwe-parser/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
]
}
5 changes: 3 additions & 2 deletions packages/siwe-parser/lib/parsers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ParsedMessage } from "./abnf";
import * as fs from "fs";

const parsingPositive: Object = require("../../../test/parsing_positive.json");
const parsingNegative: Object = require("../../../test/parsing_negative.json");
const parsingPositive: object = JSON.parse(fs.readFileSync('../../test/parsing_positive.json', 'utf8'));
const parsingNegative: object = JSON.parse(fs.readFileSync('../../test/parsing_negative.json', 'utf8'));

//
describe("Successfully parses with ABNF Client", () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/siwe-parser/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { bytesToHex } from '@noble/hashes/utils';
* @returns Either the return is or not in the EIP-55 format.
*/
export const isEIP55Address = (address: string) => {
if(address.length != 42) {
if (address.length != 42) {
return false;
}

const lowerAddress = `${address}`.toLowerCase().replace('0x', '');
var hash = bytesToHex(keccak_256(lowerAddress));
var ret = '0x';
const hash = bytesToHex(keccak_256(lowerAddress));
let ret = '0x';

for (var i = 0; i < lowerAddress.length; i++) {
for (let i = 0; i < lowerAddress.length; i++) {
if (parseInt(hash[i], 16) >= 8) {
ret += lowerAddress[i].toUpperCase();
} else {
Expand All @@ -26,7 +26,7 @@ export const isEIP55Address = (address: string) => {

export const parseIntegerNumber = (number: string): number => {
const parsed = parseInt(number);
if(parsed === NaN) throw new Error("Invalid number.");
if(parsed === Infinity) throw new Error("Invalid number.");
if (isNaN(parsed)) throw new Error("Invalid number.");
if (parsed === Infinity) throw new Error("Invalid number.");
return parsed;
}
}
11 changes: 10 additions & 1 deletion packages/siwe-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
},
"scripts": {
"test": "jest",
"build": "tsc"
"build": "tsc",
"lint": "eslint --ext .js,.ts .",
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\""
},
"author": "Spruce Systems Inc.",
"keywords": [
Expand All @@ -27,6 +29,13 @@
"valid-url": "^1.0.9",
"@noble/hashes": "^1.1.2"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"prettier": "^2.6.2"
},
"repository": {
"type": "git",
"url": "git+https://github.com/spruceid/siwe.git"
Expand Down
4 changes: 3 additions & 1 deletion packages/siwe/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
dist
node_modules
node_modules
jest.config.js
jest.setup.js
15 changes: 8 additions & 7 deletions packages/siwe/lib/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint @typescript-eslint/no-explicit-any: 0 */
const parsingPositive = require('../../../test/parsing_positive.json');
const parsingNegative = require('../../../test/parsing_negative.json');
const parsingNegativeObjects = require('../../../test/parsing_negative_objects.json');
const verificationPositive = require('../../../test/verification_positive.json');
const verificationNegative = require('../../../test/verification_negative.json');
const EIP1271 = require('../../../test/eip1271.json');
import * as fs from "fs";

const parsingPositive: object = JSON.parse(fs.readFileSync('../../test/parsing_positive.json', 'utf8'));
const parsingNegative: object = JSON.parse(fs.readFileSync('../../test/parsing_negative.json', 'utf8'));
const parsingNegativeObjects: object = JSON.parse(fs.readFileSync('../../test/parsing_negative_objects.json', 'utf8'));
const verificationPositive: object = JSON.parse(fs.readFileSync('../../test/verification_positive.json', 'utf8'));
const verificationNegative: object = JSON.parse(fs.readFileSync('../../test/verification_negative.json', 'utf8'));
const EIP1271: object = JSON.parse(fs.readFileSync('../../test/eip1271.json', 'utf8'));

import {
providers,
Expand Down

0 comments on commit b31bef6

Please sign in to comment.