From ac26d90982535e5442a8d9d2c8a2d7099ce068ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Fern=C3=A1ndez=20Serrata?= Date: Tue, 5 Mar 2024 04:57:38 -0400 Subject: [PATCH] stricter linting --- .eslintrc.json | 101 ++++++++++++++++++++++++++++++++++++------------- src/main.js | 17 +++++++-- 2 files changed, 88 insertions(+), 30 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c40c393..2f61896 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,28 +1,77 @@ { - "env": { - "browser": true, - "es2021": true - }, - "extends": "eslint:recommended", - "parserOptions": { - "ecmaVersion": "latest" - }, - "rules": { - "indent": [ - "error", - "tab" + "env": { + "browser": true, + "es2021": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": "latest" + }, + "rules": { + "no-magic-numbers": [ + "warn", + { + "ignore": [ + -1, + 0, + 1 ], - "linebreak-style": [ - "error", - "unix" - ], - "quotes": [ - "error", - "single" - ], - "semi": [ - "error", - "never" - ] - } -} + "ignoreArrayIndexes": true, + "ignoreDefaultValues": true, + "enforceConst": true + } + ], + "no-unused-vars": "off", + "no-implicit-globals": [ + "error", + { + "lexicalBindings": true + } + ], + "no-empty-function": "error", + "no-loop-func": "error", + "no-lone-blocks": "error", + "no-constant-binary-expression": "error", + "no-self-compare": "error", + "no-unmodified-loop-condition": "error", + "no-unreachable-loop": "error", + "no-extra-label": "error", + "no-else-return": [ + "error", + { + "allowElseIf": false + } + ], + "require-atomic-updates": "error", + "no-eval": "error", + "no-implied-eval": "error", + "dot-notation": "error", + "no-array-constructor": "error", + "max-depth": "warn", + "max-nested-callbacks": [ + "error", + 3 + ], + "max-params": [ + "error", + 4 + ], + "indent": [ + "error", + "tab" + ], + "linebreak-style": [ + "error", + "unix" + ], + "no-template-curly-in-string": "warn", + "quotes": [ + "error", + "single" + ], + "semi": [ + "error", + "never" + ] + } +} \ No newline at end of file diff --git a/src/main.js b/src/main.js index 324ea51..6586bac 100644 --- a/src/main.js +++ b/src/main.js @@ -1,7 +1,14 @@ //@ts-check 'use strict' // global/public, for debugging/testing purposes +/*exported RGBDR_anim*/ const RGBDR_anim = (() => { + const + /** Maximum `Uint8` */ + MAX_U8 = 0xff, + /** Maximum `Uint32` + 1 */ + POW2_32 = 2 ** 32 //eslint-disable-line no-magic-numbers + /** @param {number} n */ @@ -18,7 +25,8 @@ const RGBDR_anim = (() => { @param min inclusive @param max exclusive */ - const rand_U32 = (min = 0, max = 2 ** 32) => (rng() * (max - min) + min) >>> 0 + const rand_U32 = (min = 0, max = POW2_32) => + (rng() * (max - min) + min) >>> 0 /** Get an element at a pseudo-random index @@ -39,7 +47,7 @@ const RGBDR_anim = (() => { @param {number} f frequency @return interval */ - const Hz_to_ms = f => 1000 / f + const Hz_to_ms = f => 1000 / f //eslint-disable-line no-magic-numbers const doc = document, @@ -107,7 +115,7 @@ const RGBDR_anim = (() => { /** ratio to multiply with canvas dimensions */ droplet_rel_size: 1 / DROPLET_DENSITY, /** dimming coefficient */ - dim_factor: 3 / 4 * (is_dark ? 1 : -1), + dim_factor: 3 / 4 * (is_dark ? 1 : -1),//eslint-disable-line no-magic-numbers /** miliseconds to debounce until `resize` is called */ resize_delay_ms: 250 } @@ -247,11 +255,12 @@ const RGBDR_anim = (() => { /** u8 that specifies how much to dim the canvas */ const dim = Math.round( - Math.min((now - last_dim) * Math.abs(df), 0xff) + Math.min((now - last_dim) * Math.abs(df), MAX_U8) ) // performance [0]... if (dim) { + //eslint-disable-next-line no-magic-numbers ctx_fillFull((df < 0 ? 'ffffff' : '000000') + dim.toString(0x10).padStart(2, '0')) // [0]... and ensure hi-FPS don't cause `dim` to get stuck as a no-op. last_dim = now