Skip to content

Commit

Permalink
add eslint rules (#19)
Browse files Browse the repository at this point in the history
* add eslint rules
most notable:
```
indent:				tab
linebreak-style:	unix
quotes:				double	(", not ')
semi:				never	(semicolons)

arrow-body-style:	as-needed		(require {} in arrow functions if there are >1 statements, otherwise disallow)
camel-case:			always			(scream when someone uses snake_case, except in SUCH_CONSTANTS)
complexity:			20  			(warn if there are more than 8 conditional branches)
curly:				multi-or-nest	(require {} for if,else,etc. statements with multiple lines, otherwise disallow)
eqeqeq:				off				(this *would* require the use of === instead of ==)
id-length:			1-32			(disallows property/variable names and other identifiers to be longer than 32 chars)
max-len:            160             (limits code lines to 160 chars)
```

* allow undefined (we don't use var anyways)

* Create eslint.yml (#20)

* Update .eslintrc.json

* npm i, as Node.JS CI demanded

* Update .eslintrc.json

* eslint fix + add npm scripts

* Update eslint.yml

update eslint versions and install typescript-eslint

* fixed my eslint warns + errors
also disabled no-throw-literal
and I intentionally kept one error in Logger.ts, gonna fix that in another pr

* 🎨 Format code according to ESLint rules

* 🎨 Format code according to ESLint rules

* ♻️ Move POP3 commands into a different file

* Switch to Argon2id (#57)

* switch to argon2
argon2 uses a more secure algorithm than sha-256 (node:crypto)

* updated package.json

* 📦 Update package-lock.json

* make pr approvable

---------

Co-authored-by: Cfp <[email protected]>
  • Loading branch information
j0code and cfpwastaken authored Feb 22, 2024
1 parent e43356e commit 086ee02
Show file tree
Hide file tree
Showing 28 changed files with 2,632 additions and 762 deletions.
294 changes: 294 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
{
"env": {
"node": true,
"es2022": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"constructor-super": "warn",
"for-direction": "warn",
"getter-return": "warn",
"no-async-promise-executor": "error",
"no-await-in-loop": "error",
"no-class-assign": "error",
"no-compare-neg-zero": "off",
"no-cond-assign": ["error", "always"],
"no-const-assign": "error",
"no-constant-binary-expression": "error",
"no-constant-condition": "error",
"no-constructor-return": "error",
"no-control-regex": "warn",
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-class-members": "error",
"no-dupe-else-if": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "off",
"no-duplicate-imports": "error",
"no-empty-character-class": "error",
"no-empty-pattern": "error",
"no-ex-assign": "warn",
"no-fallthrough": "off",
"no-func-assign": "warn",
"no-import-assign": "error",
"no-inner-declarations": ["error", "both"],
"no-invalid-regexp": "error",
"no-loss-of-precision": "error",
"no-misleading-character-class": "error",
"no-new-native-nonconstructor": "error",
"no-new-symbol": "error",
"no-obj-calls": "error",
"no-promise-executor-return": "warn",
"no-prototype-builtins": "off",

"accessor-pairs": "off",
"arrow-body-style": ["warn", "as-needed"],
"block-scoped-var": "error",
"camelcase": "error",
"capitalized-comments": "off",
"class-methods-use-this": "off",
"complexity": ["warn", 24],
"consistent-return": "off",
"consistent-this": ["warn", "that"],
"curly": ["error", "multi-or-nest"],
"default-case": "off",
"default-case-last": "error",
"default-param-last": "off",
"dot-notation": "error",
"eqeqeq": "off",
"func-name-matching": "off",
"func-names": ["warn", "never"],
"grouped-accessor-pairs": "off",
"guard-for-in": "off",
"id-denylist": "off",
"id-length": ["warn", {"min": 1, "max": 32}],
"id-match": "off",
"init-declarations": "off",
"logical-assignment-operators": ["warn", "always"],
"max-classes-per-file": "off",
"max-lines-per-function": "off",
"max-nested-callbacks": "off",
"max-params": "off",
"max-statements": "off",
"multiline-comment-style": "off",
"new-cap": "off",
"no-alert": "error",
"no-array-constructor": "error",
"no-bitwise": "off",
"no-caller": "error",
"no-case-declarations": "error",
"no-confusing-arrow": ["error", {"allowParens": true, "onlyOneSimpleParam": true}],
"no-console": ["error", {"allow": ["table", "group", "groupEnd", "dir"]}],
"no-continue": "off",
"no-delete-var": "error",
"no-div-regex": "warn",
"no-else-return": "error",
"no-empty": "warn",
"no-empty-function": "off",
"no-empty-static-block": "warn",
"no-eq-null": "off",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "warn",
"no-extra-boolean-cast": "error",
"no-extra-label": "error",
"no-extra-semi": "error",
"no-floating-decimal": "off",
"no-global-assign": "error",
"no-implicit-coercion": "off",
"no-implicit-globals": "warn",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-invalid-this": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "off",
"no-lone-blocks": "warn",
"no-lonely-if": "warn",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-mixed-operators": ["warn"],
"no-multi-assign": "off",
"no-multi-str": "error",
"no-negated-condition": "error",
"no-nested-ternary": "error",
"no-new": "off",
"no-new-func": "error",
"no-new-object": "warn",
"no-new-wrappers": "error",
"no-nonoctal-decimal-escape": "error",
"no-octal": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-plusplus": "off",
"no-proto": "error",
"no-redeclare": "error",
"no-regex-spaces": "warn",
"no-restricted-exports": "off",
"no-restricted-globals": "off",
"no-restricted-imports": "off",
"no-restricted-properties": "off",
"no-restricted-syntax": "off",
"no-return-assign": "error",
"no-return-await": "warn",
"no-script-url": "error",
"no-sequences": "warn",
"no-shadow": "warn",
"no-shadow-restricted-names": "error",
"no-ternary": "off",
"no-throw-literal": "off",
"no-undef-init": "warn",
"no-undefined": "off",
"no-underscore-dangle": "warn",
"no-unneeded-ternary": "warn",
"no-unused-expressions": "warn",
"no-unused-labels": "error",
"no-useless-call": "error",
"no-useless-catch": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "warn",
"no-useless-escape": "error",
"no-useless-rename": "error",
"no-var": "error",
"no-void": "off",
"no-warning-comments": "off",
"no-with": "error",
"object-shorthand": ["warn", "always"],
"one-var": "off",
"one-var-declaration-per-line": "off",
"operator-assignment": ["warn", "always"],
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-destructuring": "warn",
"prefer-exponentiation-operator": "warn",
"prefer-named-capture-group": "off",
"prefer-numeric-literals": "warn",
"prefer-object-has-own": "error",
"prefer-object-spread": "warn",
"prefer-promise-reject-errors": "warn",
"prefer-regex-literals": "off",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "warn",
"quote-props": ["warn", "as-needed"],
"radix": "warn",
"require-await": "warn",
"require-unicode-regexp": "off",
"require-yield": "warn",
"sort-imports": "warn",
"sort-keys": "off",
"sort-vars": "warn",
"spaced-comment": ["warn", "always"],
"strict": "warn",
"symbol-description": "error",
"vars-on-top": "warn",
"yoda": ["warn", "never"],

"array-bracket-newline": ["error", {"multiline": true}],
"array-bracket-spacing": ["warn", "never"],
"array-element-newline": ["warn", "consistent"],
"arrow-parens": ["warn", "as-needed"],
"arrow-spacing": ["error", {"before": true, "after": true}],
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", {"allowSingleLine": true}],
"comma-dangle": ["warn", "never"],
"comma-spacing": ["error", {"before": false, "after": true}],
"comma-style": ["error", "last"],
"computed-property-spacing": ["error", "never"],
"dot-location": ["error", "property"],
"eol-last": ["error", "always"],
"func-call-spacing": ["error", "never"],
"function-call-argument-newline": ["error", "consistent"],
"function-paren-newline": ["error", "never"],
"generator-star-spacing": ["warn", {"before": false, "after": true}],
"implicit-arrow-linebreak": ["error", "beside"],
"indent": ["error", "tab"],
"jsx-quotes": ["warn", "prefer-double"],
"key-spacing": ["warn", {
"beforeColon": false, "afterColon": true,
"mode": "minimum", "align": "value"
}],
"keyword-spacing": ["error", {"before": true, "after": true}],
"line-comment-position": "off",
"linebreak-style": ["error", "unix"],
"lines-around-comment": ["warn", {
"beforeBlockComment": true,
"beforeLineComment": true,
"allowBlockStart": true,
"allowBlockEnd": false,
"allowObjectStart": true,
"allowObjectEnd": false,
"allowArrayStart": true,
"allowArrayEnd": false,
"allowClassStart": false,
"allowClassEnd": false
}],
"lines-between-class-members": ["error", "always", {"exceptAfterSingleLine": true}],
"max-len": ["warn", {
"code": 160, "tabWidth": 2, "comments": 120, "ignoreUrls": true
}],
"max-statements-per-line": ["error", {"max": 1}],
"multiline-ternary": ["warn", "never"],
"new-parens": ["error", "always"],
"newline-per-chained-call": ["error", {"ignoreChainWithDepth": 3}],
"no-extra-parens": "off",
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"no-trailing-spaces": "error",
"no-whitespace-before-property": "error",
"nonblock-statement-body-position": ["error", "beside"],
"object-curly-newline": ["error", {"multiline": true}],
"object-curly-spacing": ["warn", "always"],
"object-property-newline": ["error", {"allowAllPropertiesOnSameLine": true}],
"operator-linebreak": ["error", "after"],
"padded-blocks": ["warn", {"blocks": "never", "classes": "always", "switches": "never"}, {"allowSingleLineBlocks": true}],
"padding-line-between-statements": ["warn",
{ "blankLine": "always", "prev": "*", "next": ["return", "throw", "break"] },
{ "blankLine": "always", "prev": "*", "next": "case" },
{ "blankLine": "never", "prev": "case", "next": "*" },
{ "blankLine": "always", "prev": "*", "next": "default" },
{ "blankLine": "never", "prev": "default", "next": "*" },
{ "blankLine": "never", "prev": ["case", "default"], "next": ["case", "default"] },
{ "blankLine": "always", "prev": ["block", "block-like", "class", "function", "iife", "switch", "try", "while"], "next": ["class", "function", "if", "for", "switch", "while"] },
{ "blankLine": "always", "prev": ["class", "function", "if", "for", "switch", "while"], "next": "*" },
{ "blankLine": "any", "prev": "if", "next": "if" },
{ "blankLine": "always", "prev": ["let", "const"], "next": "*" },
{ "blankLine": "any", "prev": ["let", "const"], "next": ["let", "const"] },
{ "blankLine": "any", "prev": "let", "next": ["if", "for", "while"] },
{ "blankLine": "always", "prev": "import", "next": "*" },
{ "blankLine": "never", "prev": "import", "next": "import" }
],
"quotes": ["error", "double", {"avoidEscape": true, "allowTemplateLiterals": true}],
"rest-spread-spacing": ["error", "never"],
"semi": ["error", "never"],
"semi-spacing": ["error", {"before": false, "after": true}],
"semi-style": ["error", "first"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always" }],
"space-in-parens": ["error", "never"],
"space-infix-ops": ["off"],
"space-unary-ops": ["error", {"words": true, "nonwords": false}],
"switch-colon-spacing": ["error", {"before": false, "after": true}],
"template-curly-spacing": ["error", "never"],
"template-tag-spacing": ["error", "never"],
"unicode-bom": "off",
"wrap-iife": ["error", "outside", {"functionPrototypeMethods": true}],
"wrap-regex": "warn",
"yield-star-spacing": ["warn", "after"],

"@typescript-eslint/no-empty-function": "off"
}
}
52 changes: 52 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# ESLint is a tool for identifying and reporting on patterns
# found in ECMAScript/JavaScript code.
# More details at https://github.com/eslint/eslint
# and https://eslint.org

name: ESLint

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '0 12 * * *'

jobs:
eslint:
name: Run eslint scanning
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install ESLint
run: |
npm install [email protected]
npm install @microsoft/[email protected]
npm install @typescript-eslint/[email protected]
npm install @typescript-eslint/[email protected]
- name: Run ESLint
run: npx eslint ./src/
--config .eslintrc.json
--ext .js,.jsx,.ts,.tsx
--format @microsoft/eslint-formatter-sarif
--output-file eslint-results.sarif
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: eslint-results.sarif
wait-for-processing: true
Binary file added bun.lockb
Binary file not shown.
9 changes: 4 additions & 5 deletions dist/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ const YELLOW = ESC + "[93m";
const PINK = ESC + "[95m";
const TEAL = ESC + "[96m";
const WHITE = ESC + "[97m";
const COLOR = {
GRAY, DARK, RED, GREEN, YELLOW, PINK, TEAL, WHITE
};
const COLOR = { GRAY, DARK, RED, GREEN, YELLOW, PINK, TEAL, WHITE };
/* eslint no-console: "off" */
export default class Logger {
actor;
color;
constructor(actor, color) {
this.actor = actor;
this.color = color;
if (!global.debug) {
if (!global.debug)
this.debug = () => { }; // only enable debug logs when debugging is on
}
}
log(...message) {
console.log(`${WHITE}[${DARK}${time()}${WHITE}] [${COLOR[this.color]}${this.actor}${WHITE}]${GRAY}`, message.join(" "));
Expand All @@ -37,6 +35,7 @@ export default class Logger {
console.trace(`${WHITE}[${DARK}${time()}${WHITE}] [${COLOR[this.color]}${this.actor}${WHITE}]${WHITE}`, message.join(" "));
}
}
/* eslint prefer-template: "off" */
function time() {
const d = new Date();
const year = d.getUTCFullYear();
Expand Down
1 change: 0 additions & 1 deletion dist/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export declare const config: any;
type ConfigValue = string | number | boolean;
export default function getConfig<T extends ConfigValue>(key: string, defaultValue?: T): T;
export {};
Loading

0 comments on commit 086ee02

Please sign in to comment.