Adopt eslint-plugin-unicorn alongside the rest of the sitespeed.io stack#176
Merged
Conversation
Brings coach-core onto eslint-plugin-unicorn 64 — the same major sitespeed.io is on — and migrates the eslint config from .cjs to .js (ESM), which is what the plugin requires and what coach-core's already ESM package implies anyway. The unicorn rule set surfaced 354 findings, 276 of them auto-fixable: a sweep through the codebase toward modern array methods (for…of over .forEach, flatMap over map().flat(), some over findIndex truthy checks), node-native helpers (Number.parseInt, String.fromCodePoint, structuredClone, String#slice, String#replaceAll, String.raw, includes), and tidier conditionals (explicit length checks, no nested ternaries, no useless undefined). The remaining hand-fixes are small. The wappalyzer engine moves its priority arrow out of resolve() into a module-level helper; an exec()-as-truthy check becomes a .test(); lib/index.js hoists getFolders to module scope and stops chaining off an awaited stat() call. A single inline disable lives in lib/dom/bestpractice/charset.js because the page's document.characterSet returns the literal 'UTF-8' and the unicorn rule would rewrite it to 'utf8' and silently break detection. The config disables the same six unicorn rules sitespeed.io disables, plus three more that don't fit coach-core's situation: no-null (the vendored wappalyzer engine deliberately uses null to match the upstream data format), import-style (destructured node:* imports are clearer than forcing default imports), and prefer-module scoped to lib/dom/** (those files are not modules — they are IIFE fragments that get concatenated into dist/coach.min.js and evaluated in the browser via WebDriver executeScript). Co-authored-by: Claude noreply@anthropic.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings coach-core onto eslint-plugin-unicorn 64 — the same major
sitespeed.io is on — and migrates the eslint config from .cjs to .js
(ESM), which is what the plugin requires and what coach-core's already
ESM package implies anyway. The unicorn rule set surfaced 354 findings,
276 of them auto-fixable: a sweep through the codebase toward modern
array methods (for…of over .forEach, flatMap over map().flat(),
some over findIndex truthy checks), node-native helpers
(Number.parseInt, String.fromCodePoint, structuredClone, String#slice,
String#replaceAll, String.raw, includes), and tidier conditionals
(explicit length checks, no nested ternaries, no useless undefined).
The remaining hand-fixes are small. The wappalyzer engine moves its
priority arrow out of resolve() into a module-level helper; an
exec()-as-truthy check becomes a .test(); lib/index.js hoists
getFolders to module scope and stops chaining off an awaited stat()
call. A single inline disable lives in lib/dom/bestpractice/charset.js
because the page's document.characterSet returns the literal 'UTF-8'
and the unicorn rule would rewrite it to 'utf8' and silently break
detection.
The config disables the same six unicorn rules sitespeed.io disables,
plus three more that don't fit coach-core's situation: no-null
(the vendored wappalyzer engine deliberately uses null to match the
upstream data format), import-style (destructured node:* imports are
clearer than forcing default imports), and prefer-module scoped to
lib/dom/** (those files are not modules — they are IIFE fragments
that get concatenated into dist/coach.min.js and evaluated in the
browser via WebDriver executeScript).
Co-authored-by: Claude noreply@anthropic.com