Skip to content

Add eslint linting #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
env:
browser: true
es6: true
jest: true
node: true

extends:
- "eslint:recommended"

globals:
$WPT_ACCESSIBILITY_TREE: readonly
$WPT_BODIES: readonly
$WPT_COOKIES: readonly
$WPT_DNS: readonly
$WPT_REQUESTS: readonly
$WPT_TEST_URL: readonly
httparchive_enable_observations: writable
__REACT_DEVTOOLS_GLOBAL_HOOK__: writable
CSSUnparsedValue: readonly
LaunchParams: readonly

ignorePatterns:
- "!.*"
- "**/node_modules/.*"
- "/dist/third-parties.js"

plugins:
- n
- prettier

rules:
no-inner-declarations: off

overrides:
# JSON files
- files:
- "*.json"
extends:
- plugin:jsonc/recommended-with-json
parser: jsonc-eslint-parser
parserOptions:
jsonSyntax: JSON

# JSONC files
- files:
- "*.jsonc"
extends:
- plugin:jsonc/recommended-with-jsonc
parser: jsonc-eslint-parser
parserOptions:
jsonSyntax: JSONC

# JSON5 files
- files:
- "*.json5"
extends:
- plugin:jsonc/recommended-with-json5
parser: jsonc-eslint-parser
parserOptions:
jsonSyntax: JSON5

# Javascript files
- files:
- "**/*.js"
extends:
- "plugin:react/recommended"
parserOptions:
ecmaVersion: latest

- files:
- "**/*.mjs"
- "**/*.cjs"
- "**/*.jsx"
extends:
- "plugin:react/recommended"
parserOptions:
sourceType: module
ecmaVersion: latest
ecmaFeatures:
jsx: true
modules: true

# TypeScript files
- files:
- "**/*.ts"
- "**/*.cts"
- "**/*.mts"
- "**/*.tsx"
extends:
- "plugin:@typescript-eslint/recommended"
- plugin:n/recommended
- plugin:react/recommended
- prettier
parser: "@typescript-eslint/parser"
plugins:
- "@typescript-eslint"
parserOptions:
ecmaVersion: latest
sourceType: module
3 changes: 3 additions & 0 deletions .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# <!-- markdownlint-restore -->
#

ignore:
- ".github/pull_request_template.md"

###############
# Rules by id #
###############
Expand Down
4 changes: 3 additions & 1 deletion .markdownlintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# ignore github markdown files (like pull request templates)
**/.github/**/*.md"
.github/*.md
.github/**/*.md

2 changes: 1 addition & 1 deletion bin/create-fugu-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const checkURLConditions = (where, url, mimeType, responseBody) => {
// (https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textjavascript).
if (
where === "JavaScript" &&
/\.m?js/.test(url) &&
/\\.m?js/.test(url) &&
mimeType.toLowerCase().endsWith("script")
) {
return true;
Expand Down
4 changes: 3 additions & 1 deletion dist/Images.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ var wptImages = function (win) {
if (im && im.length) {
images = images.concat(im);
}
} catch (e) {}
} catch (e) {
// continue regardless of error
}
}
if (images.length > 10000) break;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ return JSON.stringify({
// HEIF
'heif', 'heic',
];
const extension_regex = new RegExp(`\.(${image_file_extensions.join('|')})$`, 'i');
const extension_regex = new RegExp(`\\.(${image_file_extensions.join('|')})$`, 'i');

let total_elements_with_non_empty_alt = 0;
let total_with_file_extension = 0;
Expand Down
5 changes: 2 additions & 3 deletions dist/ads.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//[ads]

const ACCOUNT_TYPES = ['direct', 'reseller'];
const SELLER_TYPES = ['publisher', 'intermediary', 'both'];

const isPresent = (response, endings) => response.ok && endings.some(ending => response.url.endsWith(ending));
Expand Down Expand Up @@ -86,7 +85,7 @@ const parseAdsTxt = async (response) => {
}
result.account_count += 1;
}
};
}

// Count unique and remove domain Sets for now
for (let accountType of Object.values(result.account_types)) {
Expand Down Expand Up @@ -173,7 +172,7 @@ const parseSellersJSON = async (response) => {
seller_type.domain_count = seller_type.domains.size;
seller_type.domains = Array.from(seller_type.domains); // delete seller_type.domains;
}
};
}

return result;
}
Expand Down
16 changes: 7 additions & 9 deletions dist/almanac.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ return JSON.stringify({
// json+ld
try {
var content = JSON.parse(node.textContent);
var contentLoop = [];
if (content instanceof Object || content instanceof Array) {
// nested lookup
nestedLookup(content, 0);
}
} catch (e) {}
} catch (e) {
// continue regardless of error
}
}
}
}
Expand Down Expand Up @@ -313,7 +314,9 @@ return JSON.stringify({
} else {
navigateHash++;
}
} catch (e) {}
} catch (e) {
// continue regardless of error
}
}
} else if (document.location.hostname !== link.hostname) {
external++;
Expand Down Expand Up @@ -373,7 +376,6 @@ return JSON.stringify({
wordsCount = 0;
wordElements = 0;
var n,
nodes = [],
walk = document.createTreeWalker(
body,
NodeFilter.SHOW_ALL,
Expand Down Expand Up @@ -471,7 +473,7 @@ return JSON.stringify({
};
})(),
'09.27': (() => {
// Returns a JSON array of nodes with a tabindex and their key/value attributes.
// Returns a JSON array of nodes with a tabindex and their key/value attributes.
// We acknowledge that attribute selectors are expensive to query.
var nodes = document.querySelectorAll('body [tabindex]');
return parseNodes(nodes, {
Expand Down Expand Up @@ -569,10 +571,6 @@ return JSON.stringify({
max_prop_length: 255,
};

const parsed_pictures = parseNodes(pictures, filter_options);
const parsed_imgs = parseNodes(imgs, filter_options);
const parsed_sources = parseNodes(sources, filter_options);

return {
pictures: parseNodes(pictures, filter_options),
imgs: parseNodes(imgs, filter_options),
Expand Down
2 changes: 1 addition & 1 deletion dist/avg_dom_depth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function avgDomDepth() {
function numParents(elem) {
var n = 0;
if ( elem.parentNode ) {
while ( elem = elem.parentNode) {
while ((elem = elem.parentNode)) {
n++;
}
}
Expand Down
8 changes: 6 additions & 2 deletions dist/cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function getWordPressTheme() {
theme.child_theme = childTheme.replace( 'wp-child-theme-', '' );
}

} catch ( e ) {}
} catch ( e ) {
// continue regardless of error
}
return theme;
}

Expand Down Expand Up @@ -179,7 +181,9 @@ function getWordPressContentType() {
}
}
}
} catch ( e ) {}
} catch ( e ) {
// continue regardless of error
}
return content;
}

Expand Down
2 changes: 2 additions & 0 deletions dist/crawl_links.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const sameOrigin = function(uri1, uri2){
uri2 = new URL(uri2);
return uri1.origin == uri2.origin;
} catch(e) {
// continue regardless of error
}
return false;
}
Expand Down Expand Up @@ -56,6 +57,7 @@ const getLinks = function(visibleOnly){
}
}
} catch (e) {
// continue regardless of error
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions dist/css-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ function analyzeVariables() {
try {
var rules = stylesheet.cssRules;
}
catch (e) { }
catch (e) {
// continue regardless of error
}

if (rules) {
for (let rule of rules) {
Expand Down Expand Up @@ -286,7 +288,7 @@ function analyzeVariables() {

return { summary, computed };

};
}

function serialize(data, separator) {
return JSON.stringify(data, (key, value) => {
Expand Down
4 changes: 2 additions & 2 deletions dist/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Uncomment the previous line for testing on webpagetest.org

const PREFERS_COLOR_SCHEME_REGEXP =
/(?:@media\s*\(\s*prefers-color-scheme\s*:\s*(?:dark|light)\s*\)\s*\{[^\}]*\}|matchMedia\s*\(\s*['"]\s*\(\s*prefers-color-scheme\s*:\s*(?:dark|light)\s*\)\s*['"]\s*\))/gms;
/(?:@media\s*\(\s*prefers-color-scheme\s*:\s*(?:dark|light)\s*\)\s*\{[^}]*\}|matchMedia\s*\(\s*['"]\s*\(\s*prefers-color-scheme\s*:\s*(?:dark|light)\s*\)\s*['"]\s*\))/gms;

const bodies = $WPT_BODIES;

Expand Down Expand Up @@ -46,7 +46,7 @@ return JSON.stringify({
};

const usedLibraries = [];
for (l in CssInJsMap) {
for (let l in CssInJsMap) {
if (CssInJsMap[l]) {
usedLibraries.push(l);
}
Expand Down
1 change: 1 addition & 0 deletions dist/doctype.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ if ( dt ) {
sDoctype += " " + dt.internalSubset;
}
}
/* eslint-disable-next-line no-control-regex */
return sDoctype.replace(/[\x00-\x1F\x80-\xFF]/g, "").toString();
2 changes: 1 addition & 1 deletion dist/event-names.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const response_bodies = $WPT_BODIES;
const eventNamePattern = /addEventListener\([\'"`](\w+)/g;
const eventNamePattern = /addEventListener\(['"`](\w+)/g;

return Object.fromEntries(response_bodies.filter(har => {
return eventNamePattern.test(har.response_body);
Expand Down
10 changes: 5 additions & 5 deletions dist/fugu-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ const patterns = {
chromeStatusID: 5739224579964928,
},
'Pointer Lock (unadjustedMovement)': {
regEx: /unadjustedMovement\s*\:\s*/g,
regEx: /unadjustedMovement\s*:\s*/g,
where: 'JavaScript',
supported: (async () =>
'HTMLParagraphElement' in self
Expand Down Expand Up @@ -486,7 +486,7 @@ const patterns = {
((await navigator.serviceWorker?.ready) || self.registration))(),
featureDetection: `(async () => 'serviceWorker' in navigator && 'pushManager' in (await navigator.serviceWorker?.ready || self.registration))()`,
documentation: 'https://developer.mozilla.org/en-US/docs/Web/API/Push_API',
blinkFeatureID: 769,
blinkFeatureID: 371,
chromeStatusID: 5416033485586432,
},
'Relative Orientation Sensor': {
Expand Down Expand Up @@ -631,7 +631,7 @@ const patterns = {
chromeStatusID: 5662315307335680,
},
'Web Share Target (Files)': {
regEx: /"enctype"\s*\:\s*"multipart\/form\-data"/g,
regEx: /"enctype"\s*:\s*"multipart\/form-data"/g,
where: 'Web App Manifest',
supported: (async () => undefined)(),
featureDetection: `(async () => undefined)()`,
Expand Down Expand Up @@ -695,7 +695,7 @@ const patterns = {
chromeStatusID: 6261030015467520,
},
'WebOTP': {
regEx: /transport\s*\:\s*\[["']sms["']\]/g,
regEx: /transport\s*:\s*\[["']sms["']\]/g,
where: 'JavaScript',
supported: (async () => 'OTPCredential' in self)(),
featureDetection: `(async () => 'OTPCredential' in self)()`,
Expand Down Expand Up @@ -740,7 +740,7 @@ const patterns = {
chromeStatusID: 5651917954875392,
},
'Window Controls Overlay': {
regEx: /"window\-controls\-overlay"/g,
regEx: /"window-controls-overlay"/g,
where: 'Web App Manifest',
supported: (async () => 'windowControlsOverlay' in navigator)(),
featureDetection: `(async () => 'windowControlsOverlay' in navigator)()`,
Expand Down
2 changes: 0 additions & 2 deletions dist/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ function fetchWithTimeout(url) {
return fetch(url, { signal: controller.signal });
}

const requests = $WPT_REQUESTS;

let getSourceMaps = (async () => {
const $$ = (s) => [...document.querySelectorAll(s)];
const sourcemapRegex = /\/\/[#@] sourceMappingURL=(.+?)$/;
Expand Down
6 changes: 3 additions & 3 deletions dist/localstorage_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ function numKeys(storage) {
return storage.length;
}
else {
len = 0;
for ( var key in storage ) {
let len = 0;
Object.keys(storage).forEach(() => {
len++;
}
});
return len;
}
}
Expand Down
Loading