Skip to content

Commit

Permalink
stricter linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Fernández Serrata committed Mar 5, 2024
1 parent 9558c41 commit ac26d90
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 30 deletions.
101 changes: 75 additions & 26 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
17 changes: 13 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac26d90

Please sign in to comment.