Use node plugin for Eslint

The Node.js specific rules for Eslint were deprecated in favour of the
node plugin for Eslint.  Add node plugin for eslint and switch over to
using its rules, fixing any issues detected.
This commit is contained in:
Hornwitser committed 2021-05-15 23:22:37 +02:00
1 parent 95b2262cc3
commit b0067eccc6
22 files changed
+129 -39

No files matched your search

+83 -10
View File
@@ -1,5 +1,8 @@
"use strict"; "use strict";
module.exports = { module.exports = {
"plugins": [
"node",
],
"env": { "env": {
"node": true, "node": true,
"commonjs": true, "commonjs": true,
@@ -18,6 +21,8 @@ module.exports = {
"rules": { "rules": {
"prefer-arrow-callback": "off", "prefer-arrow-callback": "off",
"no-invalid-this": "off", "no-invalid-this": "off",
"node/no-unpublished-import": "off",
"node/no-unpublished-require": "off",
}, },
}, },
{ {
@@ -31,6 +36,44 @@ module.exports = {
"jsx": true, "jsx": true,
}, },
}, },
"rules": {
"node/callback-return": "off",
"node/exports-style": "off",
"node/file-extension-in-import": "off",
"node/global-require": "off",
"node/handle-callback-err": "off",
"node/no-callback-literal": "off",
"node/no-deprecated-api": "off",
"node/no-exports-assign": "off",
"node/no-extraneous-import": "off",
"node/no-extraneous-require": "off",
"node/no-missing-import": "off",
"node/no-missing-require": "off",
"node/no-mixed-requires": "off",
"node/no-new-require": "off",
"node/no-path-concat": "off",
"node/no-process-env": "off",
"node/no-process-exit": "off",
"node/no-restricted-require": "off",
"node/no-sync": "off",
"node/no-unpublished-bin": "off",
"node/no-unpublished-import": "off",
"node/no-unpublished-require": "off",
"node/no-unsupported-features/es-builtins": "off",
"node/no-unsupported-features/es-syntax": "off",
"node/no-unsupported-features/node-builtins": "off",
"node/prefer-global/buffer": "off",
"node/prefer-global/console": "off",
"node/prefer-global/process": "off",
"node/prefer-global/text-decoder": "off",
"node/prefer-global/text-encoder": "off",
"node/prefer-global/url-search-params": "off",
"node/prefer-global/url": "off",
"node/prefer-promises/dns": "off",
"node/prefer-promises/fs": "off",
"node/process-exit-as-throw": "off",
"node/shebang": "off",
},
}, },
], ],
@@ -46,7 +89,6 @@ module.exports = {
"block-scoped-var": "error", "block-scoped-var": "error",
"block-spacing": "error", "block-spacing": "error",
"brace-style": ["error", "1tbs", { "allowSingleLine": true }], "brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"callback-return": "off",
"camelcase": "off", "camelcase": "off",
"capitalized-comments": "off", "capitalized-comments": "off",
"class-methods-use-this": "off", "class-methods-use-this": "off",
@@ -81,10 +123,8 @@ module.exports = {
"function-call-argument-newline": "off", "function-call-argument-newline": "off",
"function-paren-newline": "off", "function-paren-newline": "off",
"generator-star-spacing": ["error", { "before": false, "after": true }], "generator-star-spacing": ["error", { "before": false, "after": true }],
"global-require": "error",
"grouped-accessor-pairs": "error", "grouped-accessor-pairs": "error",
"guard-for-in": "error", "guard-for-in": "error",
"handle-callback-err": "error",
"id-blacklist": "error", "id-blacklist": "error",
"id-length": "off", "id-length": "off",
"id-match": "error", "id-match": "error",
@@ -160,7 +200,6 @@ module.exports = {
], ],
}, },
], ],
"no-mixed-requires": "error",
"no-multi-assign": "error", "no-multi-assign": "error",
"no-multi-spaces": "error", "no-multi-spaces": "error",
"no-multi-str": "error", "no-multi-str": "error",
@@ -172,19 +211,14 @@ module.exports = {
"no-new": "error", "no-new": "error",
"no-new-func": "error", "no-new-func": "error",
"no-new-object": "error", "no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error", "no-new-wrappers": "error",
"no-octal-escape": "error", "no-octal-escape": "error",
"no-param-reassign": "off", "no-param-reassign": "off",
"no-path-concat": "error",
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }], "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-process-env": "error",
"no-process-exit": "error",
"no-proto": "error", "no-proto": "error",
"no-restricted-exports": "error", "no-restricted-exports": "error",
"no-restricted-globals": "error", "no-restricted-globals": "error",
"no-restricted-imports": "error", "no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-properties": "error", "no-restricted-properties": "error",
"no-restricted-syntax": "error", "no-restricted-syntax": "error",
"no-return-assign": "error", "no-return-assign": "error",
@@ -194,7 +228,6 @@ module.exports = {
"no-sequences": "error", "no-sequences": "error",
"no-shadow": ["error", { "allow": ["yargs"] }], "no-shadow": ["error", { "allow": ["yargs"] }],
"no-spaced-func": "error", "no-spaced-func": "error",
"no-sync": "error",
"no-tabs": ["error", { "allowIndentationTabs": true }], "no-tabs": ["error", { "allowIndentationTabs": true }],
"no-template-curly-in-string": "error", "no-template-curly-in-string": "error",
"no-ternary": "off", "no-ternary": "off",
@@ -279,5 +312,45 @@ module.exports = {
"wrap-regex": "off", "wrap-regex": "off",
"yield-star-spacing": "error", "yield-star-spacing": "error",
"yoda": ["error", "never", { "exceptRange": true }], "yoda": ["error", "never", { "exceptRange": true }],
"node/callback-return": "off",
"node/exports-style": "off",
"node/file-extension-in-import": "off",
"node/global-require": "error",
"node/handle-callback-err": "error",
"node/no-callback-literal": "error",
"node/no-deprecated-api": "error",
"node/no-exports-assign": "error",
"node/no-extraneous-import": "error",
"node/no-extraneous-require": "error",
"node/no-missing-import": "error",
"node/no-missing-require": "error",
"node/no-mixed-requires": "error",
"node/no-new-require": "error",
"node/no-path-concat": "error",
"node/no-process-env": "error",
"node/no-process-exit": "error",
"node/no-restricted-require": "off",
"node/no-sync": "error",
"node/no-unpublished-bin": "error",
"node/no-unpublished-import": "error",
"node/no-unpublished-require": [
"error",
{ "allowModules": ["webpack", "webpack-merge", "webpack-dev-middleware"] },
],
"node/no-unsupported-features/es-builtins": "error",
"node/no-unsupported-features/es-syntax": "error",
"node/no-unsupported-features/node-builtins": "error",
"node/prefer-global/buffer": "error",
"node/prefer-global/console": "error",
"node/prefer-global/process": "error",
"node/prefer-global/text-decoder": "error",
"node/prefer-global/text-encoder": "error",
"node/prefer-global/url-search-params": "error",
"node/prefer-global/url": "error",
"node/prefer-promises/dns": "off",
"node/prefer-promises/fs": "off",
"node/process-exit-as-throw": "error",
"node/shebang": "error",
}, },
}; };
+1
View File
@@ -22,6 +22,7 @@
}, },
"devDependencies": { "devDependencies": {
"eslint": "^7.25.0", "eslint": "^7.25.0",
"eslint-plugin-node": "^11.1.0",
"jsdoc": "^3.6.6", "jsdoc": "^3.6.6",
"lerna": "^4.0.0", "lerna": "^4.0.0",
"mocha": "^8.4.0", "mocha": "^8.4.0",
+1 -1
View File
@@ -962,7 +962,7 @@ async function startControl() {
control.shutdown().catch(err => { control.shutdown().catch(err => {
setBlocking(true); setBlocking(true);
logger.error(err.stack); logger.error(err.stack);
// eslint-disable-next-line no-process-exit // eslint-disable-next-line node/no-process-exit
process.exit(1); process.exit(1);
}); });
}); });
+1
View File
@@ -22,6 +22,7 @@
"as-table": "^1.0.31", "as-table": "^1.0.31",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"phin": "^3.5.1", "phin": "^3.5.1",
"set-blocking": "^2.0.0",
"winston": "^3.3.3", "winston": "^3.3.3",
"yargs": "^14.2.0" "yargs": "^14.2.0"
}, },
+5 -3
View File
@@ -1,11 +1,13 @@
/* eslint-disable global-require */
/** /**
* Configuration System * Configuration System
* @author Hornwitser * @author Hornwitser
* @module lib/config * @module lib/config
*/ */
"use strict"; "use strict";
const classes = require("./classes");
const definitions = require("./definitions");
module.exports = { module.exports = {
...require("./classes"), ...classes,
...require("./definitions"), ...definitions,
}; };
+7 -4
View File
@@ -1,12 +1,15 @@
/* eslint-disable global-require */
/** /**
* Library for interfacing with Factorio Servers and saves. * Library for interfacing with Factorio Servers and saves.
* @module lib/factorio * @module lib/factorio
* @author Hornwitser * @author Hornwitser
*/ */
"use strict"; "use strict";
const export_ = require("./export");
const patch = require("./patch");
const server = require("./server");
module.exports = { module.exports = {
...require("./export"), ...export_,
...require("./patch"), ...patch,
...require("./server"), ...server,
}; };
+3 -2
View File
@@ -1,7 +1,8 @@
/* eslint-disable global-require */ /* eslint-disable node/global-require */
"use strict"; "use strict";
// eslint-disable-next-line no-process-env // eslint-disable-next-line node/no-process-env
if (process.env.APP_ENV === "browser") { if (process.env.APP_ENV === "browser") {
// eslint-disable-next-line node/no-extraneous-require
module.exports = require("fast-deep-equal/es6"); module.exports = require("fast-deep-equal/es6");
} else { } else {
module.exports = require("util").isDeepStrictEqual; module.exports = require("util").isDeepStrictEqual;
+1 -1
View File
@@ -249,7 +249,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
// Open WebSocket to master // Open WebSocket to master
logger.verbose(`SOCKET | connecting to ${url}`); logger.verbose(`SOCKET | connecting to ${url}`);
// eslint-disable-next-line no-process-env // eslint-disable-next-line node/no-process-env
if (process.env.APP_ENV === "browser") { if (process.env.APP_ENV === "browser") {
this._socket = new WebSocket(url); this._socket = new WebSocket(url);
+7 -4
View File
@@ -1,12 +1,15 @@
/* eslint-disable global-require */
/** /**
* Library for message based communication between nodes * Library for message based communication between nodes
* @module lib/link * @module lib/link
* @author Hornwitser * @author Hornwitser
*/ */
"use strict"; "use strict";
const link = require("./link");
const messages = require("./messages");
const connectors = require("./connectors");
module.exports = { module.exports = {
...require("./link"), ...link,
...require("./messages"), ...messages,
...require("./connectors"), ...connectors,
}; };
+1 -1
View File
@@ -1,4 +1,4 @@
/* eslint-disable global-require */ /* eslint-disable node/global-require */
/** /**
* Helpers for loading plugins in Node.js * Helpers for loading plugins in Node.js
* @module lib/plugin_loader * @module lib/plugin_loader
+1 -1
View File
@@ -55,7 +55,7 @@ async function handlePluginCommand(args, pluginList, pluginListPath) {
let pluginInfo; let pluginInfo;
try { try {
// eslint-disable-next-line global-require // eslint-disable-next-line node/global-require
pluginInfo = require(path.posix.join(pluginPath, "info")); pluginInfo = require(path.posix.join(pluginPath, "info"));
} catch (err) { } catch (err) {
logger.error(`Unable to import plugin info from ${args.path}:\n${err.stack}`); logger.error(`Unable to import plugin info from ${args.path}:\n${err.stack}`);
+1
View File
@@ -0,0 +1 @@
webpack.config.js
+2 -2
View File
@@ -322,7 +322,7 @@ async function startup() {
if (secondSigint) { if (secondSigint) {
setBlocking(true); setBlocking(true);
logger.fatal("Caught second interrupt, terminating immediately"); logger.fatal("Caught second interrupt, terminating immediately");
// eslint-disable-next-line no-process-exit // eslint-disable-next-line node/no-process-exit
process.exit(1); process.exit(1);
} }
@@ -335,7 +335,7 @@ async function startup() {
if (secondSigterm) { if (secondSigterm) {
setBlocking(true); setBlocking(true);
logger.fatal("Caught second termination, terminating immediately"); logger.fatal("Caught second termination, terminating immediately");
// eslint-disable-next-line no-process-exit // eslint-disable-next-line node/no-process-exit
process.exit(1); process.exit(1);
} }
+2 -2
View File
@@ -118,7 +118,7 @@ class Master {
// Start webpack development server if enabled // Start webpack development server if enabled
if (args.dev || args.devPlugin) { if (args.dev || args.devPlugin) {
logger.warn("Webpack development mode enabled"); logger.warn("Webpack development mode enabled");
/* eslint-disable global-require */ /* eslint-disable node/global-require, node/no-unpublished-require */
const webpack = require("webpack"); const webpack = require("webpack");
const webpackDevMiddleware = require("webpack-dev-middleware"); const webpackDevMiddleware = require("webpack-dev-middleware");
const webpackConfigs = []; const webpackConfigs = [];
@@ -136,7 +136,7 @@ class Master {
webpackConfigs.push(config); webpackConfigs.push(config);
} }
} }
/* eslint-enable global-require */ /* eslint-enable node/global-require, node/no-unpublished-require */
const compiler = webpack(webpackConfigs); const compiler = webpack(webpackConfigs);
this.devMiddleware = webpackDevMiddleware(compiler, {}); this.devMiddleware = webpackDevMiddleware(compiler, {});
+3 -3
View File
@@ -1413,7 +1413,7 @@ class Slave extends libLink.Link {
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
${err.stack}` ${err.stack}`
); );
// eslint-disable-next-line no-process-exit // eslint-disable-next-line node/no-process-exit
process.exit(1); process.exit(1);
} }
} }
@@ -1619,7 +1619,7 @@ async function startSlave() {
if (secondSigint) { if (secondSigint) {
setBlocking(true); setBlocking(true);
logger.fatal("Caught second interrupt, terminating immediately"); logger.fatal("Caught second interrupt, terminating immediately");
// eslint-disable-next-line no-process-exit // eslint-disable-next-line node/no-process-exit
process.exit(1); process.exit(1);
} }
@@ -1632,7 +1632,7 @@ async function startSlave() {
if (secondSigterm) { if (secondSigterm) {
setBlocking(true); setBlocking(true);
logger.fatal("Caught second termination, terminating immediately"); logger.fatal("Caught second termination, terminating immediately");
// eslint-disable-next-line no-process-exit // eslint-disable-next-line node/no-process-exit
process.exit(1); process.exit(1);
} }
+1
View File
@@ -0,0 +1 @@
webpack.config.js
+1
View File
@@ -0,0 +1 @@
webpack.config.js
+1
View File
@@ -0,0 +1 @@
webpack.config.js
+1
View File
@@ -0,0 +1 @@
webpack.config.js
+1
View File
@@ -0,0 +1 @@
webpack.config.js
+1 -1
View File
@@ -46,7 +46,7 @@ class TestControlConnector extends libLink.WebSocketClientConnector {
// Mark that this test takes a lot of time, or depeneds on a test // Mark that this test takes a lot of time, or depeneds on a test
// that takes a lot of time. // that takes a lot of time.
function slowTest(test) { function slowTest(test) {
// eslint-disable-next-line no-process-env // eslint-disable-next-line node/no-process-env
if (process.env.FAST_TEST) { if (process.env.FAST_TEST) {
test.skip(); test.skip();
} }
+4 -4
View File
@@ -5,10 +5,10 @@
"node": ">=12" "node": ">=12"
}, },
"dependencies": { "dependencies": {
"@clusterio/ctl": "2.0.0-alpha.5", "@clusterio/ctl": "^2.0.0-alpha.6",
"@clusterio/lib": "2.0.0-alpha.5", "@clusterio/lib": "^2.0.0-alpha.6",
"@clusterio/master": "2.0.0-alpha.5", "@clusterio/master": "^2.0.0-alpha.6",
"@clusterio/slave": "2.0.0-alpha.5", "@clusterio/slave": "^2.0.0-alpha.6",
"express": "^4.16.2", "express": "^4.16.2",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"jsonwebtoken": "^8.2.1", "jsonwebtoken": "^8.2.1",