Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df7e3df

Browse files
committed
refactor(eslint): add more rules for WASM code quality
1 parent 8ab791a commit df7e3df

File tree

7 files changed

+42
-14
lines changed

7 files changed

+42
-14
lines changed

ci/.eslintrc.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,34 @@ module.exports = {
2121
// Next top 3 code quality rules
2222
"no-var": "error", // Use let/const instead of var
2323
"prefer-const": "error", // Use const for variables that never change
24-
"no-redeclare": "error" // Prevent variable redeclaration
24+
"no-redeclare": "error", // Prevent variable redeclaration
25+
26+
// Additional rules based on WASM code analysis
27+
"radix": "error", // Require radix parameter for parseInt()
28+
"no-magic-numbers": ["warn", { // Discourage magic numbers
29+
"ignore": [-1000, -5, -1, 0, 1, 2, 3, 4, 5, 8, 10, 15, 16, 17, 20, 30, 32, 50, 60, 100, 200, 250, 300, 512, 1000, 1024, 32767, 44100, 1000000],
30+
"ignoreArrayIndexes": true,
31+
"enforceConst": true,
32+
"ignoreDefaultValues": true,
33+
"detectObjects": false
34+
}],
35+
"complexity": ["warn", 35], // Warn on high function complexity (increased for complex graphics/UI code)
36+
"max-len": ["warn", { // Limit line length for readability
37+
"code": 140, // Increased for complex expressions
38+
"ignoreUrls": true,
39+
"ignoreStrings": true,
40+
"ignoreTemplateLiterals": true,
41+
"ignoreComments": true
42+
}],
43+
"no-console": "off", // Allow console for this debugging-heavy codebase
44+
"prefer-template": "warn", // Prefer template literals over string concatenation
45+
"no-implicit-coercion": "warn", // Warn instead of error for implicit type coercion
46+
"require-await": "warn", // Warn instead of error for async functions without await
47+
"no-await-in-loop": "warn", // Warn about await in loops (performance)
48+
"no-promise-executor-return": "error", // Prevent return in Promise executor
49+
"prefer-promise-reject-errors": "error", // Require Error objects for Promise.reject
50+
"no-unreachable": "error", // Catch unreachable code
51+
"no-empty-function": "off", // Allow empty functions (common for stubs)
52+
"consistent-return": "warn" // Warn about inconsistent return statements
2553
}
2654
};

src/platforms/wasm/compiler/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ async function fastledLoadSetupLoop(
615615
const streamingFilesPromise = fetchAllFiles(streamingFiles, () => {
616616
console.log('All streaming files downloaded to FastLED.');
617617
});
618-
const delay = new Promise((r) => setTimeout(r, 250));
618+
const delay = new Promise((r) => { setTimeout(r, 250); });
619619
// Wait for either the time delay or the streaming files to be processed, whichever
620620
// happens first.
621621
await Promise.any([delay, streamingFilesPromise]);

src/platforms/wasm/compiler/modules/audio_manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ export class AudioManager {
10021002
await this.cleanupPreviousAudioContext(audioInput.id);
10031003

10041004
// Small delay to ensure cleanup is complete
1005-
await new Promise((resolve) => setTimeout(resolve, 100));
1005+
await new Promise((resolve) => { setTimeout(resolve, 100); });
10061006

10071007
// Set up audio playback with fresh audio element
10081008
const audio = this.createOrUpdateAudioElement(controlDiv);
@@ -1027,7 +1027,7 @@ export class AudioManager {
10271027
* @param {File} file - The selected audio file
10281028
*/
10291029
updateButtonText(button, file) {
1030-
button.textContent = file.name.length > 20 ? file.name.substring(0, 17) + '...' : file.name;
1030+
button.textContent = file.name.length > 20 ? `${file.name.substring(0, 17) }...` : file.name;
10311031
}
10321032

10331033
/**

src/platforms/wasm/compiler/modules/fastled_async_controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FastLEDAsyncController {
3535
this.frameInterval = 1000 / this.frameRate;
3636

3737
FASTLED_DEBUG_LOG('ASYNC_CONTROLLER', 'Properties initialized', {
38-
hasModule: !!this.module,
38+
hasModule: Boolean(this.module),
3939
frameRate: this.frameRate,
4040
frameInterval: this.frameInterval
4141
});
@@ -305,7 +305,7 @@ class FastLEDAsyncController {
305305
if (shouldLog) {
306306
FASTLED_DEBUG_LOG('ASYNC_CONTROLLER', 'Frame completed', {
307307
frameCount: this.frameCount,
308-
frameTime: frameTime.toFixed(2) + 'ms',
308+
frameTime: `${frameTime.toFixed(2) }ms`,
309309
fps: this.getFPS().toFixed(1)
310310
});
311311
}

src/platforms/wasm/compiler/modules/fastled_callbacks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ globalThis.FastLED_onFrame = async function(frameData) {
6565
if (shouldLog) {
6666
FASTLED_DEBUG_LOG('CALLBACKS', 'Processing frame data', {
6767
stripCount: frameData.length,
68-
hasScreenMap: !!frameData.screenMap
68+
hasScreenMap: Boolean(frameData.screenMap)
6969
});
7070
}
7171

src/platforms/wasm/compiler/modules/ui_layout_placement_manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ export class UILayoutPlacementManager {
628628
const hasUiElements = (() => {
629629
const ui1HasChildren = uiControls && uiControls.classList.contains('active') && uiControls.children.length > 0;
630630
const ui2HasChildren = uiControls2 && uiControls2.classList.contains('active') && uiControls2.children.length > 0;
631-
return !!(ui1HasChildren || ui2HasChildren);
631+
return Boolean(ui1HasChildren || ui2HasChildren);
632632
})();
633633

634634
// Main container

src/platforms/wasm/compiler/modules/ui_manager.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ function markdownToHtml(markdown) {
8686
/(<li(?:\s+class="ordered")?>.*?<\/li>(?:\s*<li(?:\s+class="ordered")?>.*?<\/li>)*)/gs,
8787
function (match) {
8888
if (match.includes('class="ordered"')) {
89-
return '<ol>' + match.replace(/\s+class="ordered"/g, '') + '</ol>';
89+
return `<ol>${ match.replace(/\s+class="ordered"/g, '') }</ol>`;
9090
} else {
91-
return '<ul>' + match + '</ul>';
91+
return `<ul>${ match }</ul>`;
9292
}
9393
},
9494
);
@@ -101,7 +101,7 @@ function markdownToHtml(markdown) {
101101
trimmed && !trimmed.startsWith('<h') && !trimmed.startsWith('<ul') &&
102102
!trimmed.startsWith('<ol') && !trimmed.startsWith('<pre')
103103
) {
104-
return '<p>' + trimmed.replace(/\n/g, '<br>') + '</p>';
104+
return `<p>${ trimmed.replace(/\n/g, '<br>') }</p>`;
105105
}
106106
return trimmed;
107107
}).join('\n');
@@ -465,7 +465,7 @@ function createHelp(element) {
465465
// Prepare content for tooltip and popup
466466
const markdownContent = element.markdownContent || '';
467467
const tooltipText = markdownContent.length > 200
468-
? markdownContent.substring(0, 200).trim() + '...'
468+
? `${markdownContent.substring(0, 200).trim() }...`
469469
: markdownContent;
470470

471471
// Convert markdown to HTML for popup
@@ -1095,7 +1095,7 @@ export class JsonUiManager {
10951095
} else if (element.type === 'number') {
10961096
currentValue = parseFloat(element.value);
10971097
} else if (element.tagName === 'SELECT') {
1098-
currentValue = parseInt(element.value);
1098+
currentValue = parseInt(element.value, 10);
10991099
} else if (element.type === 'file' && element.accept === 'audio/*') {
11001100
// Handle audio input - get all accumulated sample blocks with timestamps
11011101
if (
@@ -1543,7 +1543,7 @@ export class JsonUiManager {
15431543
if (this.debugMode && data.type !== 'number-pair') {
15441544
console.log(
15451545
`🎵 UI Registered element: ID '${data.id}' (${data.type}${
1546-
data._layoutHint ? ', ' + data._layoutHint : ''
1546+
data._layoutHint ? `, ${ data._layoutHint}` : ''
15471547
}) - Total: ${Object.keys(this.uiElements).length}`,
15481548
);
15491549
}

0 commit comments

Comments
 (0)