Skip to content

Commit

Permalink
Bump eslint to 9.x (#1371)
Browse files Browse the repository at this point in the history
* Install eslint 9.3.0

npm i --save-dev eslint@latest eslint-config-prettier@latest

* npm remove eslint-plugin-node

* npm i --save-dev globals @eslint/js

* Initial version of eslint.config.js (migrated away from the legacy YAML file)

* Fix / ignore browser globals being redeclared

* examples/screenshot.js: use process.exit()

* Ignore no-empty for try / catch blocks

* requestsMonitor: fix "Unexpected constant truthiness on the left-hand side"

* bin/phantomas.js: use process.exit()

* Prettify the code
  • Loading branch information
macbre committed May 28, 2024
1 parent 38aef73 commit 6980cae
Show file tree
Hide file tree
Showing 12 changed files with 525 additions and 450 deletions.
20 changes: 0 additions & 20 deletions .eslintrc.yml

This file was deleted.

3 changes: 1 addition & 2 deletions bin/phantomas.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ let options = parseArgv(process.argv);
if (typeof options.url !== "string" && typeof options.config === "undefined") {
debug("URL not provided - show help and leave");
getProgram().outputHelp();
process.exitCode = 1;
return;
process.exit(1);
}

url = options.url;
Expand Down
2 changes: 1 addition & 1 deletion core/modules/requestsMonitor/requestsMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function parseEntryUrl(entry) {
entry.protocol = false;
entry.isBlob = true;
} else {
parsed = new URL(entry.url) || {};
parsed = new URL(entry.url);

entry.protocol = parsed.protocol.replace(":", ""); // e.g. "http:"
entry.domain = parsed.hostname;
Expand Down
1 change: 1 addition & 0 deletions core/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
console,
"log:" + stringify(Array.prototype.slice.call(arguments))
);
// eslint-disable-next-line no-empty
} catch (e) {}
};

Expand Down
39 changes: 39 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const globals = require("globals");
const js = require("@eslint/js");

const eslintConfigPrettier = require("eslint-config-prettier");

module.exports = [
js.configs.recommended,
eslintConfigPrettier,
{
languageOptions: {
ecmaVersion: 2022,
sourceType: "script",
globals: {
// https://eslint.org/docs/latest/use/configure/language-options#predefined-global-variables
...globals.node,
...globals.browser,
},
},
rules: {
"prefer-const": "off",
"no-console": "off",
"no-async-promise-executor": "off",
// https://eslint.org/docs/latest/rules/no-unused-vars
"no-unused-vars": [
"error",
{
vars: "all",
args: "after-used",
caughtErrors: "none", // ignore catch block variables
ignoreRestSiblings: false,
reportUsedIgnorePattern: false,
},
],
},
},
{
ignores: ["coverage/**", "test/webroot/**"],
},
];
3 changes: 1 addition & 2 deletions examples/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ var phantomas = require(".."),

if (typeof url !== "string") {
console.log("Usage:\n\t./screenshot.js <URL>");
process.exitCode = 1;
return;
process.exit(1);
}

run = phantomas(url, {
Expand Down
4 changes: 2 additions & 2 deletions extensions/postLoadDelay/postLoadDelay.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
"use strict";

const { setTimeout } = require("timers/promises");
const { setTimeout: setTimeoutAsync } = require("timers/promises");

module.exports = function (phantomas) {
// e.g. --post-load-delay 5
Expand All @@ -19,6 +19,6 @@ module.exports = function (phantomas) {
phantomas.on("beforeClose", async () => {
phantomas.log("Sleeping for %d seconds", delay);

return setTimeout(delay * 1000);
return setTimeoutAsync(delay * 1000);
});
};
Loading

0 comments on commit 6980cae

Please sign in to comment.