From ff7da4520ca0d0c9314cda02e57fa6a6b7cedbd9 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Mon, 17 Jul 2023 17:52:31 -0300 Subject: [PATCH] add eslint-plugin-unused-imports and fix others unsused variables --- .eslintrc.json | 12 +++---- cli/utils.mjs | 1 - generators/angular/files-angular.mjs | 1 - generators/app/prompts.spec.mts | 2 +- generators/azure-app-service/generator.mjs | 8 ++--- .../application-options.d.mts | 2 +- generators/base-docker/docker-prompts.mjs | 2 +- generators/base/support/faker.mts | 1 - .../generator.mts | 2 +- generators/client/entity-files.mjs | 4 +-- generators/client/generator.mjs | 1 - .../client/support/entity-definition.mjs | 2 +- generators/cloudfoundry/generator.mjs | 4 +-- generators/cloudfoundry/prompts.mjs | 6 ++-- generators/common/generator.mjs | 2 -- generators/cypress/generator.mts | 1 - generators/entities/generator.mjs | 1 - generators/gae/templates.mjs | 6 ++-- generators/heroku/generator.mjs | 14 ++++----- generators/languages/languages.spec.mjs | 1 - generators/liquibase/generator.mts | 1 - generators/openshift/openshift.spec.mts | 1 - generators/page/page.spec.mts | 1 - generators/server/support/doc.mjs | 1 - generators/spring-cache/generator.mts | 4 +-- .../spring-cache/internal/dependencies.mts | 2 +- generators/spring-cloud-stream/generator.mts | 1 - .../spring-controller.spec.mts | 2 +- .../spring-data-cassandra/generator.mjs | 1 - .../spring-data-couchbase/generator.mjs | 1 - .../spring-data-elasticsearch/generator.mjs | 1 - generators/spring-data-mongodb/generator.mjs | 2 -- generators/spring-data-neo4j/generator.mts | 1 - .../spring-data-neo4j/generator.spec.mts | 2 +- .../spring-data-relational/generator.mts | 1 - .../spring-data-relational/generator.spec.mts | 2 +- generators/spring-websocket/files.mts | 2 +- generators/statistics.mts | 2 +- ...basic-entity-information-converter.spec.ts | 2 -- jdl/converters/json-to-jdl-converter.ts | 3 -- .../json-to-jdl-entity-converter.ts | 2 +- jdl/jhipster/json-entity.ts | 4 --- jdl/jhipster/relationship-types.ts | 2 -- jdl/models/jdl-application-configuration.ts | 2 +- .../self-checks/token-collector-visitor.ts | 14 ++++----- jdl/readers/json-reader.ts | 2 -- .../jdl-with-application-validator.spec.ts | 25 --------------- .../jdl-with-application-validator.ts | 2 +- jdl/validators/relationship-validator.ts | 3 +- package-lock.json | 31 +++++++++++++++++++ package.json | 3 +- test/integration-test.spec.mts | 4 +-- test/support/check-enforcements.mts | 6 +--- 53 files changed, 85 insertions(+), 121 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index a58fce136eeb..7a8028771bda 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,7 +5,7 @@ }, "extends": ["airbnb-base", "plugin:prettier/recommended", "plugin:@typescript-eslint/recommended"], "parser": "@typescript-eslint/parser", - "plugins": ["mocha", "prettier", "chai-friendly", "@typescript-eslint"], + "plugins": ["mocha", "prettier", "chai-friendly", "@typescript-eslint", "unused-imports"], "settings": { "import/core-modules": ["generator-jhipster", "generator-jhipster/support"] }, @@ -69,13 +69,11 @@ "no-promise-executor-return": "off", "no-irregular-whitespace": 2, "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-unused-vars": [ + "@typescript-eslint/no-unused-vars": "off", + "unused-imports/no-unused-imports": "error", + "unused-imports/no-unused-vars": [ "warn", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_" - } + { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" } ], "@typescript-eslint/no-explicit-any": "off", "comma-dangle": "off", diff --git a/cli/utils.mjs b/cli/utils.mjs index 3a0174fd83e4..825baa64325f 100644 --- a/cli/utils.mjs +++ b/cli/utils.mjs @@ -18,7 +18,6 @@ */ /* eslint-disable no-console */ import chalk from 'chalk'; -import _ from 'lodash'; import { createJHipsterLogger, CLI_LOGGER } from '../generators/base/support/index.mjs'; diff --git a/generators/angular/files-angular.mjs b/generators/angular/files-angular.mjs index 8ab85fdfb516..5e5aca927960 100644 --- a/generators/angular/files-angular.mjs +++ b/generators/angular/files-angular.mjs @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createTranslationReplacer } from './support/index.mjs'; import { clientApplicationBlock, clientSrcBlock } from '../client/utils.mjs'; diff --git a/generators/app/prompts.spec.mts b/generators/app/prompts.spec.mts index 572a6c6a8444..241d0c5d1ada 100644 --- a/generators/app/prompts.spec.mts +++ b/generators/app/prompts.spec.mts @@ -1,4 +1,4 @@ -import { defaultHelpers as helpers, result as runResult } from '../../test/support/index.mjs'; +import { defaultHelpers as helpers } from '../../test/support/index.mjs'; import { applicationTypes, databaseTypes, diff --git a/generators/azure-app-service/generator.mjs b/generators/azure-app-service/generator.mjs index 5596df1b299d..1d439f8da57e 100644 --- a/generators/azure-app-service/generator.mjs +++ b/generators/azure-app-service/generator.mjs @@ -114,7 +114,7 @@ export default class AzureAppServiceGenerator extends BaseGenerator { if (this.abort) return; const done = this.async(); - exec('az --version', err => { + exec('az --version', () => { done( new Error(`You don't have the Azure CLI installed. Download it from: @@ -285,7 +285,7 @@ export default class AzureAppServiceGenerator extends BaseGenerator { const done = this.async(); this.log.log(chalk.bold(`\nChecking Azure App Service plan '${this.azureAppServicePlan}'...`)); let servicePlanAlreadyExists = false; - exec(`az appservice plan list --resource-group ${this.azureAppServiceResourceGroupName}`, (err, stdout, stderr) => { + exec(`az appservice plan list --resource-group ${this.azureAppServiceResourceGroupName}`, (err, stdout) => { if (err) { this.abort = true; throw new Error('Could not list your Azure App Service plans'); @@ -327,7 +327,7 @@ which is free for the first 30 days`); if (this.abort) return; const done = this.async(); this.log.log(chalk.bold(`\nChecking Azure App Service '${this.azureAppServiceName}'...`)); - exec(`az webapp list --query "[]" --resource-group ${this.azureAppServiceResourceGroupName}`, (err, stdout, stderr) => { + exec(`az webapp list --query "[]" --resource-group ${this.azureAppServiceResourceGroupName}`, (err, stdout) => { if (err) { this.abort = true; throw new Error('Could not list your Azure App Service instances'); @@ -373,7 +373,7 @@ which is free for the first 30 days`); this.log.verboseInfo("Enabling 'prod' and 'azure' Spring Boot profiles"); exec( `az webapp config appsettings set --resource-group ${this.azureAppServiceResourceGroupName} --name ${this.azureAppServiceName} --settings SPRING_PROFILES_ACTIVE=prod,azure`, - (err, stdout) => { + err => { if (err) { this.abort = true; throw new Error('Could not configure Azure App Service instance'); diff --git a/generators/base-application/application-options.d.mts b/generators/base-application/application-options.d.mts index 288e11b545b2..124357fd516b 100644 --- a/generators/base-application/application-options.d.mts +++ b/generators/base-application/application-options.d.mts @@ -1,4 +1,4 @@ -import type { UnionToIntersection, EmptyObject, StringKeyOf } from 'type-fest'; +import type { UnionToIntersection, StringKeyOf } from 'type-fest'; // Values<{ a: string, b: number }> = string | number type Values = T[keyof T]; diff --git a/generators/base-docker/docker-prompts.mjs b/generators/base-docker/docker-prompts.mjs index c7f176ac230e..41d00e4f3746 100644 --- a/generators/base-docker/docker-prompts.mjs +++ b/generators/base-docker/docker-prompts.mjs @@ -243,7 +243,7 @@ async function askForServiceDiscovery() { if (this.regenerate) return; const serviceDiscoveryEnabledApps = []; - this.appConfigs.forEach((appConfig, index) => { + this.appConfigs.forEach(appConfig => { if (appConfig.serviceDiscoveryAny) { serviceDiscoveryEnabledApps.push({ baseName: appConfig.baseName, diff --git a/generators/base/support/faker.mts b/generators/base/support/faker.mts index 2b4e43f21d4f..e50ba08dcd97 100644 --- a/generators/base/support/faker.mts +++ b/generators/base/support/faker.mts @@ -21,7 +21,6 @@ import { Faker, base } from '@faker-js/faker'; import Randexp from 'randexp'; import { languageToJavaLanguage } from '../../languages/support/index.mjs'; -import { stringHashCode } from './string.mjs'; class RandexpWithFaker extends Randexp { faker: Faker; diff --git a/generators/bootstrap-application-server/generator.mts b/generators/bootstrap-application-server/generator.mts index effd3f59e222..abb3d2bf4c8d 100644 --- a/generators/bootstrap-application-server/generator.mts +++ b/generators/bootstrap-application-server/generator.mts @@ -40,7 +40,7 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator get loading() { return this.asLoadingTaskGroup({ - async loadApplication({ application, control }) { + async loadApplication({ application }) { this.loadServerConfig(undefined, application); (application as any).gradleVersion = this.useVersionPlaceholders ? 'GRADLE_VERSION' : GRADLE_VERSION; diff --git a/generators/client/entity-files.mjs b/generators/client/entity-files.mjs index 01d4d0cae7a3..45e324064dc0 100644 --- a/generators/client/entity-files.mjs +++ b/generators/client/entity-files.mjs @@ -19,8 +19,6 @@ import { CLIENT_MAIN_SRC_DIR } from '../generator-constants.mjs'; import { getEnumInfo } from '../base-application/support/index.mjs'; -const CLIENT_COMMON_TEMPLATES_DIR = 'entity/common'; - async function addEnumerationFiles({ application, entity }) { for (const field of entity.fields) { if (field.fieldIsEnum === true) { @@ -35,7 +33,7 @@ async function addEnumerationFiles({ application, entity }) { templates: [ { sourceFile: `${CLIENT_MAIN_SRC_DIR}app/entities/enumerations/enum.model.ts`, - destinationFile: ctx => `${application.webappEnumerationsDir}${enumFileName}.model.ts`, + destinationFile: `${application.webappEnumerationsDir}${enumFileName}.model.ts`, }, ], context: enumInfo, diff --git a/generators/client/generator.mjs b/generators/client/generator.mjs index 441c0290c029..7fa24a0ca905 100644 --- a/generators/client/generator.mjs +++ b/generators/client/generator.mjs @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; diff --git a/generators/client/support/entity-definition.mjs b/generators/client/support/entity-definition.mjs index 0bd9ccc069c9..5b03e032e07a 100644 --- a/generators/client/support/entity-definition.mjs +++ b/generators/client/support/entity-definition.mjs @@ -19,7 +19,7 @@ import getTypescriptKeyType from './types-utils.mjs'; -import { fieldTypes, validations, clientFrameworkTypes, relationshipTypes } from '../../../jdl/jhipster/index.mjs'; +import { fieldTypes, validations, clientFrameworkTypes } from '../../../jdl/jhipster/index.mjs'; const dbTypes = fieldTypes; const { diff --git a/generators/cloudfoundry/generator.mjs b/generators/cloudfoundry/generator.mjs index ab1f0a0a9b92..a85fe5244987 100644 --- a/generators/cloudfoundry/generator.mjs +++ b/generators/cloudfoundry/generator.mjs @@ -129,7 +129,7 @@ export default class CloudfoundryGenerator extends BaseGenerator { const done = this.async(); this.log.log(chalk.bold('\nChecking for an existing Cloud Foundry hosting environment...')); - exec(`cf app ${this.cloudfoundryDeployedName} `, {}, (err, stdout, stderr) => { + exec(`cf app ${this.cloudfoundryDeployedName} `, {}, (_err, stdout) => { // Unauthenticated if (stdout.search('cf login') >= 0) { this.log.error("Error: Not authenticated. Run 'cf login' to login to your cloudfoundry account and try again."); @@ -150,7 +150,7 @@ export default class CloudfoundryGenerator extends BaseGenerator { const child = exec( `cf create-service ${this.cloudfoundryDatabaseServiceName} ${this.cloudfoundryDatabaseServicePlan} ${this.cloudfoundryDeployedName}`, {}, - (err, stdout, stderr) => { + () => { done(); }, ); diff --git a/generators/cloudfoundry/prompts.mjs b/generators/cloudfoundry/prompts.mjs index 767067c1e3fd..de58baba7a33 100644 --- a/generators/cloudfoundry/prompts.mjs +++ b/generators/cloudfoundry/prompts.mjs @@ -28,7 +28,7 @@ export default { }; async function prompting() { - const databaseType = this.databaseType; + const databaseType = this.databaseType ?? this.jhipsterConfig.databaseType; const prompts = [ { name: 'cloudfoundryDeployedName', @@ -52,13 +52,13 @@ async function prompting() { default: 0, }, { - when: response => databaseType !== NO_DATABASE, + when: () => databaseType !== NO_DATABASE, name: 'cloudfoundryDatabaseServiceName', message: 'What is the name of your database service?', default: 'elephantsql', }, { - when: response => databaseType !== NO_DATABASE, + when: () => databaseType !== NO_DATABASE, name: 'cloudfoundryDatabaseServicePlan', message: 'What is the name of your database plan?', default: 'turtle', diff --git a/generators/common/generator.mjs b/generators/common/generator.mjs index 4169517f24d8..8389b28dc899 100644 --- a/generators/common/generator.mjs +++ b/generators/common/generator.mjs @@ -17,7 +17,6 @@ * limitations under the License. */ /* eslint-disable consistent-return */ -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; @@ -30,7 +29,6 @@ import { JHIPSTER_DOCUMENTATION_ARCHIVE_PATH, } from '../generator-constants.mjs'; import { clientFrameworkTypes } from '../../jdl/jhipster/index.mjs'; -import { packageJson } from '../../lib/index.mjs'; import { GENERATOR_COMMON, GENERATOR_BOOTSTRAP_APPLICATION, GENERATOR_GIT } from '../generator-list.mjs'; import command from './command.mjs'; diff --git a/generators/cypress/generator.mts b/generators/cypress/generator.mts index e4fa9195ae35..d3526795159a 100644 --- a/generators/cypress/generator.mts +++ b/generators/cypress/generator.mts @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import { stringHashCode, createFaker } from '../base/support/index.mjs'; import BaseApplicationGenerator from '../base-application/index.mjs'; diff --git a/generators/entities/generator.mjs b/generators/entities/generator.mjs index 3648d089751f..bf063f4afe6b 100644 --- a/generators/entities/generator.mjs +++ b/generators/entities/generator.mjs @@ -19,7 +19,6 @@ import BaseApplicationGenerator from '../base-application/index.mjs'; import { JHIPSTER_CONFIG_DIR } from '../generator-constants.mjs'; import { GENERATOR_ENTITIES, GENERATOR_APP } from '../generator-list.mjs'; -import { getDefaultAppName } from '../project-name/support/index.mjs'; export default class EntitiesGenerator extends BaseApplicationGenerator { constructor(args, options, features) { diff --git a/generators/gae/templates.mjs b/generators/gae/templates.mjs index bb522dc84019..8288a8d0ca13 100644 --- a/generators/gae/templates.mjs +++ b/generators/gae/templates.mjs @@ -1,11 +1,11 @@ -export const mavenPluginConfiguration = data => ` +export const mavenPluginConfiguration = () => ` <%= gcpProjectId %> 1 `; -export const mavenProdProfileContent = data => ` +export const mavenProdProfileContent = () => ` prod\${profile.api-docs}${ // eslint-disable-next-line no-template-curly-in-string this.databaseTypeSql ? '${profile.no-liquibase},prod-gae' : '' @@ -13,7 +13,7 @@ export const mavenProdProfileContent = data => ` `; -export const mavenProfileContent = data => ` +export const mavenProfileContent = () => ` org.springframework.boot spring-boot-starter-undertow diff --git a/generators/heroku/generator.mjs b/generators/heroku/generator.mjs index cf47d1faff54..643b920c9be4 100644 --- a/generators/heroku/generator.mjs +++ b/generators/heroku/generator.mjs @@ -315,7 +315,7 @@ export default class HerokuGenerator extends BaseGenerator { } catch (e) { // An exception is thrown if the folder doesn't exist this.log.log(chalk.bold('\nInitializing Git repository')); - const child = ChildProcess.exec('git init', (err, stdout, stderr) => { + const child = ChildProcess.exec('git init', () => { done(); }); child.stdout.on('data', data => { @@ -335,7 +335,7 @@ export default class HerokuGenerator extends BaseGenerator { done(); } else { this.log.log(chalk.bold('\nInstalling Heroku CLI deployment plugin')); - const child = ChildProcess.exec(`heroku plugins:install ${cliPlugin}`, (err, stdout) => { + const child = ChildProcess.exec(`heroku plugins:install ${cliPlugin}`, err => { if (err) { this.abort = true; this.log.error(err); @@ -397,7 +397,7 @@ export default class HerokuGenerator extends BaseGenerator { done(); }); } else { - ChildProcess.exec(`heroku create ${regionParams}`, (err, stdout, stderr) => { + ChildProcess.exec(`heroku create ${regionParams}`, (err, stdout) => { if (err) { this.abort = true; this.log.error(err); @@ -407,7 +407,7 @@ export default class HerokuGenerator extends BaseGenerator { this.log.verboseInfo(stdout.trim()); // ensure that the git remote is the same as the appName - ChildProcess.exec(`heroku git:remote --app ${this.herokuAppName}`, (err, stdout, stderr) => { + ChildProcess.exec(`heroku git:remote --app ${this.herokuAppName}`, err => { if (err) { this.abort = true; this.log.error(err); @@ -453,7 +453,7 @@ export default class HerokuGenerator extends BaseGenerator { if (this.abort) return; const done = this.async(); - const addonCreateCallback = (addon, err, stdout, stderr) => { + const addonCreateCallback = (addon, err) => { if (err) { const verifyAccountUrl = 'https://heroku.com/verify'; if (_.includes(err, verifyAccountUrl)) { @@ -552,7 +552,7 @@ export default class HerokuGenerator extends BaseGenerator { props.herokuJHipsterRegistryPassword = encodeURIComponent(props.herokuJHipsterRegistryPassword); const herokuJHipsterRegistry = `https://${props.herokuJHipsterRegistryUsername}:${props.herokuJHipsterRegistryPassword}@${props.herokuJHipsterRegistryApp}.herokuapp.com`; const configSetCmd = `heroku config:set JHIPSTER_REGISTRY_URL=${herokuJHipsterRegistry} --app ${this.herokuAppName}`; - const child = ChildProcess.exec(configSetCmd, (err, stdout, stderr) => { + const child = ChildProcess.exec(configSetCmd, err => { if (err) { this.abort = true; this.log.error(err); @@ -589,7 +589,7 @@ export default class HerokuGenerator extends BaseGenerator { } if (this.useOkta) { this.writeFile('provision-okta-addon.sh.ejs', 'provision-okta-addon.sh'); - fs.appendFile('.gitignore', 'provision-okta-addon.sh', 'utf8', (err, data) => { + fs.appendFile('.gitignore', 'provision-okta-addon.sh', 'utf8', err => { if (err) { this.log.warn(`${chalk.yellow.bold('WARNING!')} Failed to add 'provision-okta-addon.sh' to .gitignore.'`); } diff --git a/generators/languages/languages.spec.mjs b/generators/languages/languages.spec.mjs index 3729d7cbe62a..50cdf6210bf1 100644 --- a/generators/languages/languages.spec.mjs +++ b/generators/languages/languages.spec.mjs @@ -3,7 +3,6 @@ import { dirname, join } from 'path'; import { basicHelpers, defaultHelpers as helpers, result as runResult } from '../../test/support/helpers.mjs'; import { CLIENT_MAIN_SRC_DIR, SERVER_MAIN_RES_DIR, CLIENT_WEBPACK_DIR } from '../generator-constants.mjs'; -import EnvironmentBuilder from '../../cli/environment-builder.mjs'; import { supportedLanguages } from './support/index.mjs'; const __filename = fileURLToPath(import.meta.url); diff --git a/generators/liquibase/generator.mts b/generators/liquibase/generator.mts index c5adbbdd9ab4..24691ed54e3c 100644 --- a/generators/liquibase/generator.mts +++ b/generators/liquibase/generator.mts @@ -18,7 +18,6 @@ */ import fs from 'fs'; -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { GENERATOR_LIQUIBASE, GENERATOR_LIQUIBASE_CHANGELOGS, GENERATOR_BOOTSTRAP_APPLICATION_SERVER } from '../generator-list.mjs'; import { liquibaseFiles } from './files.mjs'; diff --git a/generators/openshift/openshift.spec.mts b/generators/openshift/openshift.spec.mts index c73054f82f51..59ce904b5f18 100644 --- a/generators/openshift/openshift.spec.mts +++ b/generators/openshift/openshift.spec.mts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { expect } from 'esmocha'; import { dryRunHelpers as helpers, getGenerator } from '../../test/support/index.mjs'; diff --git a/generators/page/page.spec.mts b/generators/page/page.spec.mts index 9b799259f309..8fdfb34ca69e 100644 --- a/generators/page/page.spec.mts +++ b/generators/page/page.spec.mts @@ -1,6 +1,5 @@ import { basicHelpers as helpers } from '../../test/support/index.mjs'; -import EnvironmentBuilder from '../../cli/environment-builder.mjs'; import { CLIENT_MAIN_SRC_DIR, CLIENT_TEST_SRC_DIR } from '../generator-constants.mjs'; const CLIENT_SPEC_SRC_DIR = `${CLIENT_TEST_SRC_DIR}spec/`; diff --git a/generators/server/support/doc.mjs b/generators/server/support/doc.mjs index dbebc8d12e82..b0b941868a52 100644 --- a/generators/server/support/doc.mjs +++ b/generators/server/support/doc.mjs @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import { formatDocAsSingleLine } from '../../base-application/support/index.mjs'; const escapeDoubleQuotes = text => { diff --git a/generators/spring-cache/generator.mts b/generators/spring-cache/generator.mts index 4bc59373bfb7..c5dff6cea0f0 100644 --- a/generators/spring-cache/generator.mts +++ b/generators/spring-cache/generator.mts @@ -61,9 +61,9 @@ export default class SpringCacheGenerator extends BaseApplicationGenerator { }; } else { // Add noop - source.addEntryToCache = ({ entry }) => {}; + source.addEntryToCache = () => {}; // Add noop - source.addEntityToCache = ({ entityAbsoluteClass }) => {}; + source.addEntityToCache = () => {}; } }, }); diff --git a/generators/spring-cache/internal/dependencies.mts b/generators/spring-cache/internal/dependencies.mts index b6f3ae9ff7e0..5fd27faf107c 100644 --- a/generators/spring-cache/internal/dependencies.mts +++ b/generators/spring-cache/internal/dependencies.mts @@ -17,7 +17,7 @@ * limitations under the License. */ -import { MavenDefinition, MavenDependency, MavenProperty } from '../../maven/types.mjs'; +import { MavenDefinition } from '../../maven/types.mjs'; const javaxCacheApi = { groupId: 'javax.cache', diff --git a/generators/spring-cloud-stream/generator.mts b/generators/spring-cloud-stream/generator.mts index fa547ee187fd..dfc88fa4d21f 100644 --- a/generators/spring-cloud-stream/generator.mts +++ b/generators/spring-cloud-stream/generator.mts @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { GENERATOR_SPRING_CLOUD_STREAM, GENERATOR_BOOTSTRAP_APPLICATION_SERVER } from '../generator-list.mjs'; diff --git a/generators/spring-controller/spring-controller.spec.mts b/generators/spring-controller/spring-controller.spec.mts index 96bf775e63d8..01d835c4ceed 100644 --- a/generators/spring-controller/spring-controller.spec.mts +++ b/generators/spring-controller/spring-controller.spec.mts @@ -1,5 +1,5 @@ import { defaultHelpers as helpers, result as runResult } from '../../test/support/index.mjs'; -import { SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR, GENERATOR_JHIPSTER } from '../generator-constants.mjs'; +import { SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR } from '../generator-constants.mjs'; import { getGenerator } from '../../test/support/index.mjs'; const generator = getGenerator('spring-controller'); diff --git a/generators/spring-data-cassandra/generator.mjs b/generators/spring-data-cassandra/generator.mjs index 91aa5e4c94ee..2156d8bdf004 100644 --- a/generators/spring-data-cassandra/generator.mjs +++ b/generators/spring-data-cassandra/generator.mjs @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { GENERATOR_SPRING_DATA_CASSANDRA, GENERATOR_BOOTSTRAP_APPLICATION } from '../generator-list.mjs'; diff --git a/generators/spring-data-couchbase/generator.mjs b/generators/spring-data-couchbase/generator.mjs index f1097262a55d..d5bacfe651b7 100644 --- a/generators/spring-data-couchbase/generator.mjs +++ b/generators/spring-data-couchbase/generator.mjs @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { GENERATOR_SPRING_DATA_COUCHBASE, GENERATOR_BOOTSTRAP_APPLICATION } from '../generator-list.mjs'; diff --git a/generators/spring-data-elasticsearch/generator.mjs b/generators/spring-data-elasticsearch/generator.mjs index 9c1cc3b861f0..910de7fa69cc 100644 --- a/generators/spring-data-elasticsearch/generator.mjs +++ b/generators/spring-data-elasticsearch/generator.mjs @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { GENERATOR_SPRING_DATA_ELASTICSEARCH, GENERATOR_BOOTSTRAP_APPLICATION } from '../generator-list.mjs'; diff --git a/generators/spring-data-mongodb/generator.mjs b/generators/spring-data-mongodb/generator.mjs index d07ff656e497..717b5f107a2f 100644 --- a/generators/spring-data-mongodb/generator.mjs +++ b/generators/spring-data-mongodb/generator.mjs @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { GENERATOR_SPRING_DATA_MONGODB, GENERATOR_BOOTSTRAP_APPLICATION } from '../generator-list.mjs'; @@ -59,7 +58,6 @@ export default class MongoDBGenerator extends BaseApplicationGenerator { addDependencies({ application, source }) { const { reactive } = application; if (application.buildToolMaven) { - const reactiveMongock = false; // workaround https://github.com/mongock/mongock/issues/613 source.addMavenDefinition?.({ dependencies: [ { groupId: 'io.mongock', artifactId: 'mongock-springboot-v3' }, diff --git a/generators/spring-data-neo4j/generator.mts b/generators/spring-data-neo4j/generator.mts index 8fc0ba9fc360..e02f33f39b49 100644 --- a/generators/spring-data-neo4j/generator.mts +++ b/generators/spring-data-neo4j/generator.mts @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { GENERATOR_BOOTSTRAP_APPLICATION, GENERATOR_LIQUIBASE, GENERATOR_SPRING_DATA_NEO4J } from '../generator-list.mjs'; diff --git a/generators/spring-data-neo4j/generator.spec.mts b/generators/spring-data-neo4j/generator.spec.mts index 3fb159512a61..14146a85e694 100644 --- a/generators/spring-data-neo4j/generator.spec.mts +++ b/generators/spring-data-neo4j/generator.spec.mts @@ -1,6 +1,6 @@ import { expect } from 'esmocha'; import lodash from 'lodash'; -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { buildSamplesFromMatrix, buildServerMatrix, entitiesSimple as entities } from '../../test/support/index.mjs'; diff --git a/generators/spring-data-relational/generator.mts b/generators/spring-data-relational/generator.mts index da9bd55d1f1b..15e7acc2ce1e 100644 --- a/generators/spring-data-relational/generator.mts +++ b/generators/spring-data-relational/generator.mts @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { GENERATOR_SPRING_DATA_RELATIONAL, GENERATOR_BOOTSTRAP_APPLICATION, GENERATOR_LIQUIBASE } from '../generator-list.mjs'; diff --git a/generators/spring-data-relational/generator.spec.mts b/generators/spring-data-relational/generator.spec.mts index d64c8ea7e756..250ef83f3aa9 100644 --- a/generators/spring-data-relational/generator.spec.mts +++ b/generators/spring-data-relational/generator.spec.mts @@ -1,6 +1,6 @@ import { expect } from 'esmocha'; import lodash from 'lodash'; -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { buildServerMatrix, extendMatrix, extendFilteredMatrix, buildSamplesFromMatrix } from '../../test/support/index.mjs'; diff --git a/generators/spring-websocket/files.mts b/generators/spring-websocket/files.mts index c01ed61116e7..3605cdfc86de 100644 --- a/generators/spring-websocket/files.mts +++ b/generators/spring-websocket/files.mts @@ -18,7 +18,7 @@ */ import Generator from './generator.mjs'; import { moveToJavaPackageSrcDir } from '../server/support/index.mjs'; -import { SERVER_MAIN_SRC_DIR, SERVER_TEST_RES_DIR } from '../generator-constants.mjs'; +import { SERVER_MAIN_SRC_DIR } from '../generator-constants.mjs'; import { WriteFileSection } from '../base/api.mjs'; import { SpringBootApplication } from '../server/types.mjs'; diff --git a/generators/statistics.mts b/generators/statistics.mts index 976a24f844c9..d00ac96ef4a7 100644 --- a/generators/statistics.mts +++ b/generators/statistics.mts @@ -108,7 +108,7 @@ class Statistics { .post(url, data) .then( () => {}, - error => { + () => { if (this.axiosProxyClient) { this.axiosProxyClient .post(url, data) diff --git a/jdl/converters/jdl-to-json/jdl-to-json-basic-entity-information-converter.spec.ts b/jdl/converters/jdl-to-json/jdl-to-json-basic-entity-information-converter.spec.ts index 488c791d8e0b..ea9a1879ce25 100644 --- a/jdl/converters/jdl-to-json/jdl-to-json-basic-entity-information-converter.spec.ts +++ b/jdl/converters/jdl-to-json/jdl-to-json-basic-entity-information-converter.spec.ts @@ -20,14 +20,12 @@ /* eslint-disable no-new, no-unused-expressions */ import { jestExpect } from 'esmocha'; import chai, { expect } from 'chai'; -import sinon from 'sinon'; import sinonChai from 'sinon-chai'; chai.use(sinonChai); import { JDLEntity } from '../../models/index.mjs'; import { convert } from './jdl-to-json-basic-entity-converter.js'; -import logger from '../../utils/objects/logger.js'; describe('jdl - JDLToJSONBasicEntityConverter', () => { describe('convert', () => { diff --git a/jdl/converters/json-to-jdl-converter.ts b/jdl/converters/json-to-jdl-converter.ts index 0b2b860c134f..e6fbb9bc41ff 100644 --- a/jdl/converters/json-to-jdl-converter.ts +++ b/jdl/converters/json-to-jdl-converter.ts @@ -26,11 +26,8 @@ import { readJSONFile } from '../readers/json-file-reader.js'; import { convertApplicationToJDL } from './json-to-jdl-application-converter.js'; import { convertEntitiesToJDL } from './json-to-jdl-entity-converter.js'; import exportJDLObject from '../exporters/jdl-exporter.js'; -import ApplicationOptions from '../jhipster/application-options.js'; import { Entity } from './types.js'; -const { OptionNames } = ApplicationOptions; - export default { convertToJDL, convertSingleContentToJDL, diff --git a/jdl/converters/json-to-jdl-entity-converter.ts b/jdl/converters/json-to-jdl-entity-converter.ts index 4918cac718fa..d46cc40cbe55 100644 --- a/jdl/converters/json-to-jdl-entity-converter.ts +++ b/jdl/converters/json-to-jdl-entity-converter.ts @@ -21,7 +21,7 @@ import JDLObject from '../models/jdl-object.js'; import { JDLEntity, JDLEnum } from '../models/index.mjs'; import JDLField from '../models/jdl-field.js'; import JDLValidation from '../models/jdl-validation.js'; -import JDLRelationship, { JDLRelationshipModel, JDLRelationshipOptions, JDL_RELATIONSHIP_ONE_TO_MANY } from '../models/jdl-relationship.js'; +import JDLRelationship, { JDLRelationshipModel, JDLRelationshipOptions } from '../models/jdl-relationship.js'; import JDLUnaryOption from '../models/jdl-unary-option.js'; import JDLBinaryOption from '../models/jdl-binary-option.js'; diff --git a/jdl/jhipster/json-entity.ts b/jdl/jhipster/json-entity.ts index db188191c641..393ccd488ae9 100644 --- a/jdl/jhipster/json-entity.ts +++ b/jdl/jhipster/json-entity.ts @@ -18,11 +18,7 @@ */ import { merge } from '../utils/object-utils.js'; -import formatComment from '../utils/format-utils.js'; import { upperFirst } from '../utils/string-utils.js'; -import getTableNameFromEntityName from './entity-table-name-creator.js'; -import binaryOptions from './binary-options.js'; -import unaryOptions from './unary-options.js'; /** * The JSONEntity class represents a read-to-be exported to JSON entity. diff --git a/jdl/jhipster/relationship-types.ts b/jdl/jhipster/relationship-types.ts index 2b4f54684485..03df41ef81a8 100644 --- a/jdl/jhipster/relationship-types.ts +++ b/jdl/jhipster/relationship-types.ts @@ -17,8 +17,6 @@ * limitations under the License. */ -import _ from 'lodash'; - import { asJdlRelationshipType } from '../converters/parsed-jdl-to-jdl-object/relationship-converter.js'; import { JDLRelationshipType } from '../models/jdl-relationship.js'; diff --git a/jdl/models/jdl-application-configuration.ts b/jdl/models/jdl-application-configuration.ts index d2948eca2041..e17309c59ac3 100644 --- a/jdl/models/jdl-application-configuration.ts +++ b/jdl/models/jdl-application-configuration.ts @@ -24,7 +24,7 @@ const { OptionNames } = ApplicationOptions; export default class JDLApplicationConfiguration { options: any; - constructor(config = {}) { + constructor() { this.options = {}; } diff --git a/jdl/parsing/self-checks/token-collector-visitor.ts b/jdl/parsing/self-checks/token-collector-visitor.ts index 125ea79f3070..48be46f4c83c 100644 --- a/jdl/parsing/self-checks/token-collector-visitor.ts +++ b/jdl/parsing/self-checks/token-collector-visitor.ts @@ -20,13 +20,13 @@ import { Alternation, Alternative, GAstVisitor, NonTerminal, Option, Repetition, RepetitionMandatory, Rule } from 'chevrotain'; export default class TokenCollectorVisitor extends GAstVisitor { - visitNonTerminal(node: NonTerminal) {} - visitAlternative(node: Alternative) {} - visitOption(node: Option) {} - visitRepetition(node: Repetition) {} - visitRepetitionMandatory(node: RepetitionMandatory) {} - visitAlternation(node: Alternation) {} - visitRule(node: Rule) {} + visitNonTerminal(_node: NonTerminal) {} + visitAlternative(_node: Alternative) {} + visitOption(_node: Option) {} + visitRepetition(_node: Repetition) {} + visitRepetitionMandatory(_node: RepetitionMandatory) {} + visitAlternation(_node: Alternation) {} + visitRule(_node: Rule) {} actualTokens: any[]; diff --git a/jdl/readers/json-reader.ts b/jdl/readers/json-reader.ts index b7883bd20aab..95bca9c82997 100644 --- a/jdl/readers/json-reader.ts +++ b/jdl/readers/json-reader.ts @@ -21,12 +21,10 @@ import fs from 'fs'; import { convertEntitiesToJDL } from '../converters/json-to-jdl-entity-converter.js'; import { convertServerOptionsToJDL } from '../converters/json-to-jdl-option-converter.js'; import mergeJDLObjects from '../models/jdl-object-merger.js'; -import { applicationOptions } from '../jhipster/index.mjs'; import { doesDirectoryExist } from '../utils/file-utils.js'; import { readJSONFile } from './json-file-reader.js'; import JDLObject from '../models/jdl-object.js'; -const { OptionNames } = applicationOptions; /* Parse the given jhipster app dir and return a JDLObject */ export default function parseFromDir(dir: string): JDLObject { if (!dir) { diff --git a/jdl/validators/jdl-with-application-validator.spec.ts b/jdl/validators/jdl-with-application-validator.spec.ts index 0b60e305751d..99dd77af660c 100644 --- a/jdl/validators/jdl-with-application-validator.spec.ts +++ b/jdl/validators/jdl-with-application-validator.spec.ts @@ -68,31 +68,6 @@ describe('jdl - JDLWithApplicationValidator', () => { }).to.throw(/^The name 'Continue' is a reserved keyword and can not be used as an entity class name.$/); }); }); - context('when having an entity with a reserved table name', () => { - let parameter; - - before(() => { - const jdlObject = new JDLObject(); - const application = createJDLApplication({ - applicationType: MONOLITH, - databaseType: databaseTypes.SQL, - }); - const entity = new JDLEntity({ - name: 'valid', - tableName: 'continue', - }); - jdlObject.addEntity(entity); - application.addEntityName(entity.name); - jdlObject.addApplication(application); - const logger = { - warn: callParameter => { - parameter = callParameter; - }, - }; - const validator = createValidator(jdlObject, logger); - validator.checkForErrors(); - }); - }); context('when passing gateway as application type', () => { context('with incompatible database type and field type', () => { let validator; diff --git a/jdl/validators/jdl-with-application-validator.ts b/jdl/validators/jdl-with-application-validator.ts index ce37c75ef410..ec8b3d15ce2c 100644 --- a/jdl/validators/jdl-with-application-validator.ts +++ b/jdl/validators/jdl-with-application-validator.ts @@ -76,7 +76,7 @@ export default function createValidator(jdlObject: JDLObject, logger: any = cons }); } - function checkForFieldErrors(entityName, jdlFields, jdlApplication) { + function checkForFieldErrors(_entityName, jdlFields, _jdlApplication) { const validator = new FieldValidator(); Object.keys(jdlFields).forEach(fieldName => { const jdlField = jdlFields[fieldName]; diff --git a/jdl/validators/relationship-validator.ts b/jdl/validators/relationship-validator.ts index 79457039814b..19d7c7732004 100644 --- a/jdl/validators/relationship-validator.ts +++ b/jdl/validators/relationship-validator.ts @@ -18,12 +18,11 @@ */ import Validator from './validator.js'; -import { relationshipTypes, relationshipOptions } from '../jhipster/index.mjs'; +import { relationshipTypes } from '../jhipster/index.mjs'; import JDLRelationship from '../models/jdl-relationship.js'; import { relationshipTypeExists } from '../jhipster/relationship-types.js'; const { ONE_TO_ONE, MANY_TO_MANY, MANY_TO_ONE, ONE_TO_MANY } = relationshipTypes; -const { BUILT_IN_ENTITY } = relationshipOptions; export default class RelationshipValidator extends Validator { constructor() { diff --git a/package-lock.json b/package-lock.json index c0dfefa34692..8ea3e82bba28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -89,6 +89,7 @@ "eslint-plugin-import": "2.27.5", "eslint-plugin-mocha": "10.1.0", "eslint-plugin-prettier": "5.0.0", + "eslint-plugin-unused-imports": "3.0.0", "esmocha": "1.0.1", "fs-extra": "11.1.1", "jest-extended": "4.0.0", @@ -5428,6 +5429,36 @@ } } }, + "node_modules/eslint-plugin-unused-imports": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-3.0.0.tgz", + "integrity": "sha512-sduiswLJfZHeeBJ+MQaG+xYzSWdRXoSw61DpU13mzWumCkR0ufD0HmO4kdNokjrkluMHpj/7PJeN35pgbhW3kw==", + "dev": true, + "dependencies": { + "eslint-rule-composer": "^0.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^6.0.0", + "eslint": "^8.0.0" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + } + } + }, + "node_modules/eslint-rule-composer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz", + "integrity": "sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg==", + "dev": true, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/eslint-utils": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", diff --git a/package.json b/package.json index 90de725e9354..397e1a973722 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "copy-files": "cpy \"jdl/*.json\" \"dist/jdl\" && cpy \"generators/**\" \"!**/*.(js|cjs|mjs|ts|cts|mts|snap)\" \"!**/__*/*\" dist/generators", "copy-types": "cpy \"generators/**/*.d.(|c|m)ts\" dist/types/generators", "ejslint": "ejslint generators/**/*.ejs", - "eslint": "eslint . --ext .js,.cjs,.mjs,.ts,.cts,.mts --max-warnings 158", + "eslint": "eslint . --ext .js,.cjs,.mjs,.ts,.cts,.mts --max-warnings 50", "jdl:test": "esmocha jdl --no-insight --forbid-only -p", "jdl:test-watch": "npm run jdl:test -- --watch", "jsdoc": "jsdoc --configure jsdoc-conf.json", @@ -163,6 +163,7 @@ "eslint-plugin-import": "2.27.5", "eslint-plugin-mocha": "10.1.0", "eslint-plugin-prettier": "5.0.0", + "eslint-plugin-unused-imports": "3.0.0", "esmocha": "1.0.1", "fs-extra": "11.1.1", "jest-extended": "4.0.0", diff --git a/test/integration-test.spec.mts b/test/integration-test.spec.mts index 3c6a7c1b8aef..cf6946e5869c 100644 --- a/test/integration-test.spec.mts +++ b/test/integration-test.spec.mts @@ -45,13 +45,13 @@ const itSamplesEntries = fs .filter(dirent => dirent.isDirectory()) .map(({ name }) => name) .map(name => [name, path.join(itSamplesPath, name, '.yo-rc.json')]) - .filter(([name, yoFile]) => fs.existsSync(yoFile)); + .filter(([_name, yoFile]) => fs.existsSync(yoFile)); const dailyBuildEntries = fs .readdirSync(dailyBuildsSamplesPath, { withFileTypes: true }) .filter(dirent => dirent.isDirectory()) .map(({ name }) => name) .map(name => [name, path.join(dailyBuildsSamplesPath, name, '.yo-rc.json')]) - .filter(([name, yoFile]) => fs.existsSync(yoFile)); + .filter(([_name, yoFile]) => fs.existsSync(yoFile)); const itEntitiesSamplesEntries = fs .readdirSync(itEntitiesSamplesPath, { withFileTypes: true }) diff --git a/test/support/check-enforcements.mts b/test/support/check-enforcements.mts index 86b5af1fb8f0..b98db7b5873c 100644 --- a/test/support/check-enforcements.mts +++ b/test/support/check-enforcements.mts @@ -19,13 +19,9 @@ import assert from 'assert'; import fs, { readFileSync } from 'fs'; import fse from 'fs-extra'; -import path, { basename, dirname } from 'path'; -import { fileURLToPath } from 'url'; +import path, { basename } from 'path'; import { getGeneratorFolder } from './get-generator.mjs'; -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); - const fixEnforcements = process.argv.includes('--fix-enforcements'); const readDir = dirPath => {