diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..f06235c --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..d67de6f --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,30 @@ +{ + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "prettier" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "sourceType": "module", + "ecmaVersion": 2020 + }, + "plugins": ["@typescript-eslint"], + "env": { + "node": true + }, + "rules": { + "@typescript-eslint/ban-ts-comment": [ + "error", + { + "ts-ignore": "allow-with-description" + } + ], + "@typescript-eslint/no-unused-vars": ["warn", { "args": "none" }], + "no-console": ["error", { "allow": ["info", "warn", "error"] }], + "no-constant-binary-expression": "error" + }, + "globals": { + "window": true + } +} diff --git a/lint-staged.config.js b/lint-staged.config.js index 81c0b10..879cbe4 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,11 +1,13 @@ export default { "src/**/*.{js,ts}": [ - "prettier --write", + "eslint --fix --max-warnings 0", + "prettier --write" ], "examples/**/*.{js,mjs,jsx}": [ - "prettier --write", + "prettier --write" ], "package.json": ["prettier --write"], + "src/**/*.ts": () => "tsc --noEmit", }; \ No newline at end of file diff --git a/package.json b/package.json index 99ee7eb..d8a4426 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,12 @@ }, "scripts": { "prebuild": "yarn run clean", - "format": "prettier --check '**/*.(md|json)' 'src/**/*.(js|ts|jsx|tsx)'", + "lint": "yarn lint:js && yarn tsc:compile && yarn format:fix", + "lint:js": "eslint src --ext .js,.ts --max-warnings 0", + "lint:js:fix": "eslint src --ext .js,.ts --fix", + "tsc:compile": "tsc --noEmit", + "format": "prettier --check '**/*.(md|json)' 'src/**/*.(js|ts)' 'example/**/*.(js|jsx)'", + "format:fix": "prettier --loglevel silent --write '**/*.(md|json)' 'src/**/*.(js|ts)' 'example/**/*.(js|jsx)'", "prepack": "yarn run build", "test": "jest", "clean": "rm -rf dist", @@ -43,8 +48,12 @@ "@types/crypto-js": "^4.1.1", "@types/jest": "^29.4.0", "@types/node": "^18.11.0", + "@typescript-eslint/eslint-plugin": "^6.3.0", + "@typescript-eslint/parser": "^6.3.0", "@webbtc/webln-types": "^1.0.11", "browserify": "^17.0.0", + "eslint": "^8.46.0", + "eslint-config-prettier": "^9.0.0", "express": "^4.18.2", "husky": "^8.0.3", "jest": "^29.5.0",