refactor: Add lint rules for no unused vars and unused import (#9940)
This commit is contained in:
@@ -8,11 +8,9 @@
|
||||
* Run with: npm run benchmark
|
||||
*/
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
const core = require('@actions/core');
|
||||
const Parse = require('parse/node');
|
||||
const { performance, PerformanceObserver } = require('perf_hooks');
|
||||
const { performance } = require('node:perf_hooks');
|
||||
const { MongoClient } = require('mongodb');
|
||||
const { wrapMongoDBWithLatency } = require('./MongoLatencyWrapper');
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ class NodeEngineCheck {
|
||||
file: file,
|
||||
nodeVersion: version
|
||||
});
|
||||
} catch(e) {
|
||||
} catch {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Ignoring file because it is not valid JSON: ${file}`);
|
||||
core.warning(`Ignoring file because it is not valid JSON: ${file}`);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
const js = require("@eslint/js");
|
||||
const babelParser = require("@babel/eslint-parser");
|
||||
const globals = require("globals");
|
||||
const unusedImports = require("eslint-plugin-unused-imports");
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
ignores: ["**/lib/**", "**/coverage/**", "**/out/**", "**/types/**"],
|
||||
@@ -19,8 +21,13 @@ module.exports = [
|
||||
requireConfigFile: false,
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
"unused-imports": unusedImports,
|
||||
},
|
||||
rules: {
|
||||
indent: ["error", 2, { SwitchCase: 1 }],
|
||||
"unused-imports/no-unused-imports": "error",
|
||||
"unused-imports/no-unused-vars": "error",
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"no-trailing-spaces": "error",
|
||||
"eol-last": "error",
|
||||
|
||||
24
package-lock.json
generated
24
package-lock.json
generated
@@ -82,6 +82,7 @@
|
||||
"deep-diff": "1.0.2",
|
||||
"eslint": "9.27.0",
|
||||
"eslint-plugin-expect-type": "0.6.2",
|
||||
"eslint-plugin-unused-imports": "^4.3.0",
|
||||
"flow-bin": "0.271.0",
|
||||
"form-data": "4.0.4",
|
||||
"globals": "16.2.0",
|
||||
@@ -10246,6 +10247,22 @@
|
||||
"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": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
|
||||
@@ -30154,6 +30171,13 @@
|
||||
"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": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
"deep-diff": "1.0.2",
|
||||
"eslint": "9.27.0",
|
||||
"eslint-plugin-expect-type": "0.6.2",
|
||||
"eslint-plugin-unused-imports": "4.3.0",
|
||||
"flow-bin": "0.271.0",
|
||||
"form-data": "4.0.4",
|
||||
"globals": "16.2.0",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
/**
|
||||
* @interface AnalyticsAdapter
|
||||
* @module Adapters
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
|
||||
/**
|
||||
* @interface ParseAuthResponse
|
||||
|
||||
@@ -63,7 +63,7 @@ const getAppleKeyByKeyId = async (keyId, cacheMaxEntries, cacheMaxAge) => {
|
||||
let key;
|
||||
try {
|
||||
key = await authUtils.getSigningKey(client, keyId);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
`Unable to find matching key for Key ID: ${keyId}`
|
||||
|
||||
@@ -122,7 +122,7 @@ const getFacebookKeyByKeyId = async (keyId, cacheMaxEntries, cacheMaxAge) => {
|
||||
let key;
|
||||
try {
|
||||
key = await authUtils.getSigningKey(client, keyId);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
`Unable to find matching key for Key ID: ${keyId}`
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
/**
|
||||
* @interface
|
||||
* @memberof module:Adapters
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
/**
|
||||
* @interface
|
||||
* @memberof module:Adapters
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
// Files Adapter
|
||||
//
|
||||
// Allows you to change the file storage mechanism.
|
||||
|
||||
@@ -171,7 +171,7 @@ export class GridFSBucketAdapter extends FilesAdapter {
|
||||
fileNamesNotRotated = fileNamesNotRotated.filter(function (value) {
|
||||
return value !== fileName;
|
||||
});
|
||||
} catch (err) {
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
/**
|
||||
* @interface
|
||||
* @memberof module:Adapters
|
||||
|
||||
@@ -42,7 +42,7 @@ function configureTransports(options) {
|
||||
parseServerError.name = 'parse-server-error';
|
||||
transports.push(parseServerError);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
/* */
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ export function configureLogger({
|
||||
}
|
||||
try {
|
||||
fs.mkdirSync(logsFolder);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
/* */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
/**
|
||||
* @interface
|
||||
* @memberof module:Adapters
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
// @flow
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
// Push Adapter
|
||||
//
|
||||
// Allows you to change the push notification mechanism.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
import { WSSAdapter } from './WSSAdapter';
|
||||
const WebSocketServer = require('ws').Server;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*eslint no-unused-vars: "off"*/
|
||||
/* eslint-disable unused-imports/no-unused-vars */
|
||||
// WebSocketServer Adapter
|
||||
//
|
||||
// Adapter classes must implement the following functions:
|
||||
|
||||
@@ -225,7 +225,7 @@ function wrapToHTTPRequest(hook, key) {
|
||||
if (typeof body === 'string') {
|
||||
try {
|
||||
body = JSON.parse(body);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
err = {
|
||||
error: 'Malformed response',
|
||||
code: -1,
|
||||
|
||||
@@ -217,7 +217,7 @@ export function getDatabaseAdapter(databaseURI, collectionPrefix, databaseOption
|
||||
try {
|
||||
const parsedURI = new URL(databaseURI);
|
||||
protocol = parsedURI.protocol ? parsedURI.protocol.toLowerCase() : null;
|
||||
} catch (e) {
|
||||
} catch {
|
||||
/* */
|
||||
}
|
||||
switch (protocol) {
|
||||
|
||||
@@ -38,7 +38,7 @@ const handleUpload = async (upload, config) => {
|
||||
res.on('end', () => {
|
||||
try {
|
||||
resolve(JSON.parse(data));
|
||||
} catch (e) {
|
||||
} catch {
|
||||
reject(new Parse.Error(Parse.error, data));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -55,7 +55,7 @@ function moduleOrObjectParser(opt) {
|
||||
}
|
||||
try {
|
||||
return JSON.parse(opt);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
/* */
|
||||
}
|
||||
return opt;
|
||||
|
||||
@@ -149,7 +149,7 @@ export class ClassesRouter extends PromiseRouter {
|
||||
for (const [key, value] of _.entries(query)) {
|
||||
try {
|
||||
json[key] = JSON.parse(value);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
json[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ export class FilesRouter {
|
||||
const data = await filesController.getMetadata(filename);
|
||||
res.status(200);
|
||||
res.json(data);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
res.status(200);
|
||||
res.json({});
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ export class PagesRouter extends PromiseRouter {
|
||||
let data;
|
||||
try {
|
||||
data = await this.readFile(path);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return this.notFound();
|
||||
}
|
||||
|
||||
@@ -474,7 +474,7 @@ export class PagesRouter extends PromiseRouter {
|
||||
let data;
|
||||
try {
|
||||
data = await this.readFile(path);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return this.notFound();
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ export class PagesRouter extends PromiseRouter {
|
||||
try {
|
||||
const json = require(path.resolve('./', this.pagesConfig.localizationJsonPath));
|
||||
this.jsonParameters = json;
|
||||
} catch (e) {
|
||||
} catch {
|
||||
throw errors.jsonFailedFileLoading;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class Utils {
|
||||
try {
|
||||
await fs.access(path);
|
||||
return true;
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ function mountOnto(router) {
|
||||
function parseURL(urlString) {
|
||||
try {
|
||||
return new URL(urlString);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ function logStartupOptions(options) {
|
||||
if (typeof value === 'object') {
|
||||
try {
|
||||
value = JSON.stringify(value);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
if (value && value.constructor && value.constructor.name) {
|
||||
value = value.constructor.name;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ export async function handleParseHeaders(req, res, next) {
|
||||
if (Object.prototype.toString.call(context) !== '[object Object]') {
|
||||
throw 'Context is not an object';
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
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
|
||||
try {
|
||||
req.body = JSON.parse(req.body);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return invalidRequest(req, res);
|
||||
}
|
||||
fileViaJSON = true;
|
||||
@@ -173,7 +173,7 @@ export async function handleParseHeaders(req, res, next) {
|
||||
if (Object.prototype.toString.call(info.context) !== '[object Object]') {
|
||||
throw 'Context is not an object';
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return malformedContext(req, res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ try {
|
||||
hash: _bcrypt.hash,
|
||||
compare: _bcrypt.verify,
|
||||
};
|
||||
} catch (e) {
|
||||
} catch {
|
||||
/* */
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class HTTPResponse {
|
||||
if (!_data) {
|
||||
try {
|
||||
_data = JSON.parse(getText());
|
||||
} catch (e) {
|
||||
} catch {
|
||||
/* */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user