refactor: Add lint rules for no unused vars and unused import (#9940)

This commit is contained in:
Lucas Coratger
2025-11-22 22:12:34 +01:00
committed by GitHub
parent 9ed9af48d1
commit 69a925879e
32 changed files with 66 additions and 36 deletions

View File

@@ -8,11 +8,9 @@
* Run with: npm run benchmark * Run with: npm run benchmark
*/ */
/* eslint-disable no-console */
const core = require('@actions/core'); const core = require('@actions/core');
const Parse = require('parse/node'); const Parse = require('parse/node');
const { performance, PerformanceObserver } = require('perf_hooks'); const { performance } = require('node:perf_hooks');
const { MongoClient } = require('mongodb'); const { MongoClient } = require('mongodb');
const { wrapMongoDBWithLatency } = require('./MongoLatencyWrapper'); const { wrapMongoDBWithLatency } = require('./MongoLatencyWrapper');

View File

@@ -86,7 +86,7 @@ class NodeEngineCheck {
file: file, file: file,
nodeVersion: version nodeVersion: version
}); });
} catch(e) { } catch {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(`Ignoring file because it is not valid JSON: ${file}`); console.log(`Ignoring file because it is not valid JSON: ${file}`);
core.warning(`Ignoring file because it is not valid JSON: ${file}`); core.warning(`Ignoring file because it is not valid JSON: ${file}`);

View File

@@ -1,6 +1,8 @@
const js = require("@eslint/js"); const js = require("@eslint/js");
const babelParser = require("@babel/eslint-parser"); const babelParser = require("@babel/eslint-parser");
const globals = require("globals"); const globals = require("globals");
const unusedImports = require("eslint-plugin-unused-imports");
module.exports = [ module.exports = [
{ {
ignores: ["**/lib/**", "**/coverage/**", "**/out/**", "**/types/**"], ignores: ["**/lib/**", "**/coverage/**", "**/out/**", "**/types/**"],
@@ -19,8 +21,13 @@ module.exports = [
requireConfigFile: false, requireConfigFile: false,
}, },
}, },
plugins: {
"unused-imports": unusedImports,
},
rules: { rules: {
indent: ["error", 2, { SwitchCase: 1 }], indent: ["error", 2, { SwitchCase: 1 }],
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": "error",
"linebreak-style": ["error", "unix"], "linebreak-style": ["error", "unix"],
"no-trailing-spaces": "error", "no-trailing-spaces": "error",
"eol-last": "error", "eol-last": "error",

24
package-lock.json generated
View File

@@ -82,6 +82,7 @@
"deep-diff": "1.0.2", "deep-diff": "1.0.2",
"eslint": "9.27.0", "eslint": "9.27.0",
"eslint-plugin-expect-type": "0.6.2", "eslint-plugin-expect-type": "0.6.2",
"eslint-plugin-unused-imports": "^4.3.0",
"flow-bin": "0.271.0", "flow-bin": "0.271.0",
"form-data": "4.0.4", "form-data": "4.0.4",
"globals": "16.2.0", "globals": "16.2.0",
@@ -10246,6 +10247,22 @@
"typescript": ">=4" "typescript": ">=4"
} }
}, },
"node_modules/eslint-plugin-unused-imports": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.3.0.tgz",
"integrity": "sha512-ZFBmXMGBYfHttdRtOG9nFFpmUvMtbHSjsKrS20vdWdbfiVYsO3yA2SGYy9i9XmZJDfMGBflZGBCm70SEnFQtOA==",
"dev": true,
"license": "MIT",
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^8.0.0-0 || ^7.0.0 || ^6.0.0 || ^5.0.0",
"eslint": "^9.0.0 || ^8.0.0"
},
"peerDependenciesMeta": {
"@typescript-eslint/eslint-plugin": {
"optional": true
}
}
},
"node_modules/eslint-scope": { "node_modules/eslint-scope": {
"version": "5.1.1", "version": "5.1.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
@@ -30154,6 +30171,13 @@
"get-tsconfig": "^4.8.1" "get-tsconfig": "^4.8.1"
} }
}, },
"eslint-plugin-unused-imports": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.3.0.tgz",
"integrity": "sha512-ZFBmXMGBYfHttdRtOG9nFFpmUvMtbHSjsKrS20vdWdbfiVYsO3yA2SGYy9i9XmZJDfMGBflZGBCm70SEnFQtOA==",
"dev": true,
"requires": {}
},
"eslint-scope": { "eslint-scope": {
"version": "5.1.1", "version": "5.1.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",

View File

@@ -89,6 +89,7 @@
"deep-diff": "1.0.2", "deep-diff": "1.0.2",
"eslint": "9.27.0", "eslint": "9.27.0",
"eslint-plugin-expect-type": "0.6.2", "eslint-plugin-expect-type": "0.6.2",
"eslint-plugin-unused-imports": "4.3.0",
"flow-bin": "0.271.0", "flow-bin": "0.271.0",
"form-data": "4.0.4", "form-data": "4.0.4",
"globals": "16.2.0", "globals": "16.2.0",

View File

@@ -1,4 +1,4 @@
/*eslint no-unused-vars: "off"*/ /* eslint-disable unused-imports/no-unused-vars */
/** /**
* @interface AnalyticsAdapter * @interface AnalyticsAdapter
* @module Adapters * @module Adapters

View File

@@ -1,4 +1,4 @@
/*eslint no-unused-vars: "off"*/ /* eslint-disable unused-imports/no-unused-vars */
/** /**
* @interface ParseAuthResponse * @interface ParseAuthResponse

View File

@@ -63,7 +63,7 @@ const getAppleKeyByKeyId = async (keyId, cacheMaxEntries, cacheMaxAge) => {
let key; let key;
try { try {
key = await authUtils.getSigningKey(client, keyId); key = await authUtils.getSigningKey(client, keyId);
} catch (error) { } catch {
throw new Parse.Error( throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND, Parse.Error.OBJECT_NOT_FOUND,
`Unable to find matching key for Key ID: ${keyId}` `Unable to find matching key for Key ID: ${keyId}`

View File

@@ -122,7 +122,7 @@ const getFacebookKeyByKeyId = async (keyId, cacheMaxEntries, cacheMaxAge) => {
let key; let key;
try { try {
key = await authUtils.getSigningKey(client, keyId); key = await authUtils.getSigningKey(client, keyId);
} catch (error) { } catch {
throw new Parse.Error( throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND, Parse.Error.OBJECT_NOT_FOUND,
`Unable to find matching key for Key ID: ${keyId}` `Unable to find matching key for Key ID: ${keyId}`

View File

@@ -1,4 +1,4 @@
/*eslint no-unused-vars: "off"*/ /* eslint-disable unused-imports/no-unused-vars */
/** /**
* @interface * @interface
* @memberof module:Adapters * @memberof module:Adapters

View File

@@ -1,4 +1,4 @@
/*eslint no-unused-vars: "off"*/ /* eslint-disable unused-imports/no-unused-vars */
/** /**
* @interface * @interface
* @memberof module:Adapters * @memberof module:Adapters

View File

@@ -1,4 +1,4 @@
/*eslint no-unused-vars: "off"*/ /* eslint-disable unused-imports/no-unused-vars */
// Files Adapter // Files Adapter
// //
// Allows you to change the file storage mechanism. // Allows you to change the file storage mechanism.

View File

@@ -171,7 +171,7 @@ export class GridFSBucketAdapter extends FilesAdapter {
fileNamesNotRotated = fileNamesNotRotated.filter(function (value) { fileNamesNotRotated = fileNamesNotRotated.filter(function (value) {
return value !== fileName; return value !== fileName;
}); });
} catch (err) { } catch {
continue; continue;
} }
} }

View File

@@ -1,4 +1,4 @@
/*eslint no-unused-vars: "off"*/ /* eslint-disable unused-imports/no-unused-vars */
/** /**
* @interface * @interface
* @memberof module:Adapters * @memberof module:Adapters

View File

@@ -42,7 +42,7 @@ function configureTransports(options) {
parseServerError.name = 'parse-server-error'; parseServerError.name = 'parse-server-error';
transports.push(parseServerError); transports.push(parseServerError);
} }
} catch (e) { } catch {
/* */ /* */
} }
@@ -86,7 +86,7 @@ export function configureLogger({
} }
try { try {
fs.mkdirSync(logsFolder); fs.mkdirSync(logsFolder);
} catch (e) { } catch {
/* */ /* */
} }
} }

View File

@@ -1,4 +1,4 @@
/*eslint no-unused-vars: "off"*/ /* eslint-disable unused-imports/no-unused-vars */
/** /**
* @interface * @interface
* @memberof module:Adapters * @memberof module:Adapters

View File

@@ -1,5 +1,5 @@
/* eslint-disable unused-imports/no-unused-vars */
// @flow // @flow
/*eslint no-unused-vars: "off"*/
// Push Adapter // Push Adapter
// //
// Allows you to change the push notification mechanism. // Allows you to change the push notification mechanism.

View File

@@ -1,4 +1,4 @@
/*eslint no-unused-vars: "off"*/ /* eslint-disable unused-imports/no-unused-vars */
import { WSSAdapter } from './WSSAdapter'; import { WSSAdapter } from './WSSAdapter';
const WebSocketServer = require('ws').Server; const WebSocketServer = require('ws').Server;

View File

@@ -1,4 +1,4 @@
/*eslint no-unused-vars: "off"*/ /* eslint-disable unused-imports/no-unused-vars */
// WebSocketServer Adapter // WebSocketServer Adapter
// //
// Adapter classes must implement the following functions: // Adapter classes must implement the following functions:

View File

@@ -225,7 +225,7 @@ function wrapToHTTPRequest(hook, key) {
if (typeof body === 'string') { if (typeof body === 'string') {
try { try {
body = JSON.parse(body); body = JSON.parse(body);
} catch (e) { } catch {
err = { err = {
error: 'Malformed response', error: 'Malformed response',
code: -1, code: -1,

View File

@@ -217,7 +217,7 @@ export function getDatabaseAdapter(databaseURI, collectionPrefix, databaseOption
try { try {
const parsedURI = new URL(databaseURI); const parsedURI = new URL(databaseURI);
protocol = parsedURI.protocol ? parsedURI.protocol.toLowerCase() : null; protocol = parsedURI.protocol ? parsedURI.protocol.toLowerCase() : null;
} catch (e) { } catch {
/* */ /* */
} }
switch (protocol) { switch (protocol) {

View File

@@ -38,7 +38,7 @@ const handleUpload = async (upload, config) => {
res.on('end', () => { res.on('end', () => {
try { try {
resolve(JSON.parse(data)); resolve(JSON.parse(data));
} catch (e) { } catch {
reject(new Parse.Error(Parse.error, data)); reject(new Parse.Error(Parse.error, data));
} }
}); });

View File

@@ -55,7 +55,7 @@ function moduleOrObjectParser(opt) {
} }
try { try {
return JSON.parse(opt); return JSON.parse(opt);
} catch (e) { } catch {
/* */ /* */
} }
return opt; return opt;

View File

@@ -149,7 +149,7 @@ export class ClassesRouter extends PromiseRouter {
for (const [key, value] of _.entries(query)) { for (const [key, value] of _.entries(query)) {
try { try {
json[key] = JSON.parse(value); json[key] = JSON.parse(value);
} catch (e) { } catch {
json[key] = value; json[key] = value;
} }
} }

View File

@@ -310,7 +310,7 @@ export class FilesRouter {
const data = await filesController.getMetadata(filename); const data = await filesController.getMetadata(filename);
res.status(200); res.status(200);
res.json(data); res.json(data);
} catch (e) { } catch {
res.status(200); res.status(200);
res.json({}); res.json({});
} }

View File

@@ -432,7 +432,7 @@ export class PagesRouter extends PromiseRouter {
let data; let data;
try { try {
data = await this.readFile(path); data = await this.readFile(path);
} catch (e) { } catch {
return this.notFound(); return this.notFound();
} }
@@ -474,7 +474,7 @@ export class PagesRouter extends PromiseRouter {
let data; let data;
try { try {
data = await this.readFile(path); data = await this.readFile(path);
} catch (e) { } catch {
return this.notFound(); return this.notFound();
} }
@@ -517,7 +517,7 @@ export class PagesRouter extends PromiseRouter {
try { try {
const json = require(path.resolve('./', this.pagesConfig.localizationJsonPath)); const json = require(path.resolve('./', this.pagesConfig.localizationJsonPath));
this.jsonParameters = json; this.jsonParameters = json;
} catch (e) { } catch {
throw errors.jsonFailedFileLoading; throw errors.jsonFailedFileLoading;
} }
} }

View File

@@ -82,7 +82,7 @@ class Utils {
try { try {
await fs.access(path); await fs.access(path);
return true; return true;
} catch (e) { } catch {
return false; return false;
} }
} }

View File

@@ -13,7 +13,7 @@ function mountOnto(router) {
function parseURL(urlString) { function parseURL(urlString) {
try { try {
return new URL(urlString); return new URL(urlString);
} catch (error) { } catch {
return undefined; return undefined;
} }
} }

View File

@@ -20,7 +20,7 @@ function logStartupOptions(options) {
if (typeof value === 'object') { if (typeof value === 'object') {
try { try {
value = JSON.stringify(value); value = JSON.stringify(value);
} catch (e) { } catch {
if (value && value.constructor && value.constructor.name) { if (value && value.constructor && value.constructor.name) {
value = value.constructor.name; value = value.constructor.name;
} }

View File

@@ -79,7 +79,7 @@ export async function handleParseHeaders(req, res, next) {
if (Object.prototype.toString.call(context) !== '[object Object]') { if (Object.prototype.toString.call(context) !== '[object Object]') {
throw 'Context is not an object'; throw 'Context is not an object';
} }
} catch (e) { } catch {
return malformedContext(req, res); return malformedContext(req, res);
} }
} }
@@ -126,7 +126,7 @@ export async function handleParseHeaders(req, res, next) {
// to provide x-parse-app-id in header and parse a binary file will fail // to provide x-parse-app-id in header and parse a binary file will fail
try { try {
req.body = JSON.parse(req.body); req.body = JSON.parse(req.body);
} catch (e) { } catch {
return invalidRequest(req, res); return invalidRequest(req, res);
} }
fileViaJSON = true; fileViaJSON = true;
@@ -173,7 +173,7 @@ export async function handleParseHeaders(req, res, next) {
if (Object.prototype.toString.call(info.context) !== '[object Object]') { if (Object.prototype.toString.call(info.context) !== '[object Object]') {
throw 'Context is not an object'; throw 'Context is not an object';
} }
} catch (e) { } catch {
return malformedContext(req, res); return malformedContext(req, res);
} }
} }

View File

@@ -8,7 +8,7 @@ try {
hash: _bcrypt.hash, hash: _bcrypt.hash,
compare: _bcrypt.verify, compare: _bcrypt.verify,
}; };
} catch (e) { } catch {
/* */ /* */
} }

View File

@@ -31,7 +31,7 @@ class HTTPResponse {
if (!_data) { if (!_data) {
try { try {
_data = JSON.parse(getText()); _data = JSON.parse(getText());
} catch (e) { } catch {
/* */ /* */
} }
} }