diff --git a/eslint.config.mjs b/eslint.config.mjs index 554f54eec..7dd5b5bf0 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -32,7 +32,6 @@ export default [ rules: { 'complexity': 'off', 'eslint-plugin-import/no-extraneous-dependencies': 'warn', - 'eslint-plugin-import/no-internal-modules': 'warn', 'eslint-plugin-import/order': [ 'off', { @@ -93,7 +92,7 @@ export default [ 'no-bitwise': 'off', 'no-caller': 'error', 'no-cond-assign': 'error', - 'no-console': 'off', + 'no-console': 'error', 'no-debugger': 'error', 'no-duplicate-case': 'error', 'no-duplicate-imports': 'error', @@ -132,12 +131,19 @@ export default [ 'valid-typeof': 'off', }, }, + { + files: ['**/*.spec.ts', '**/*-spec.ts', 'spec/**/*.ts'], + rules: { + 'eslint-plugin-import/no-extraneous-dependencies': 'off', + 'no-console': 'off', + }, + }, { ignores: [ - '/node_modules/**/*', - '/coverage/**/*', - '/output/**/*', - '/packages/cli/templates/**/*', + 'node_modules/**/*', + 'coverage/**/*', + 'output/**/*', + 'packages/cli/templates/**/*', '**/files/**/*' ] }, diff --git a/packages/cli/lib/PromptSession.ts b/packages/cli/lib/PromptSession.ts index 99353b3b9..99d941532 100644 --- a/packages/cli/lib/PromptSession.ts +++ b/packages/cli/lib/PromptSession.ts @@ -95,9 +95,7 @@ export class PromptSession extends BasePromptSession { protected async completeAndRun(port?: number) { await PackageManager.flushQueue(true); - if (true) { // TODO: Make conditional? - await start.start({ port }); - } + await start.start({ port }); } protected async upgradePackages() { diff --git a/packages/cli/scripts/install.ts b/packages/cli/scripts/install.ts index 26386be65..acff6954e 100644 --- a/packages/cli/scripts/install.ts +++ b/packages/cli/scripts/install.ts @@ -2,7 +2,7 @@ import { App, GoogleAnalytics } from "@igniteui/cli-core"; function install() { - if (!!process.env.npm_config_global) { + if (process.env.npm_config_global) { App.initialize(); GoogleAnalytics.post({ t: "screenview", diff --git a/packages/cli/scripts/uninstall.ts b/packages/cli/scripts/uninstall.ts index 1dba62d7a..d28001848 100644 --- a/packages/cli/scripts/uninstall.ts +++ b/packages/cli/scripts/uninstall.ts @@ -2,7 +2,7 @@ import { App, GoogleAnalytics } from "@igniteui/cli-core"; function uninstall() { - if (!!process.env.npm_config_global) { + if (process.env.npm_config_global) { App.initialize(); GoogleAnalytics.post({ t: "screenview", diff --git a/packages/core/prompt/BasePromptSession.ts b/packages/core/prompt/BasePromptSession.ts index b73c1650b..34d76c26c 100644 --- a/packages/core/prompt/BasePromptSession.ts +++ b/packages/core/prompt/BasePromptSession.ts @@ -203,7 +203,6 @@ export abstract class BasePromptSession { * @param framework to get project library for */ protected async getProjectLibrary(framework: Framework): Promise { - let projectLibrary: ProjectLibrary; const projectLibraries = this.getProjectLibNames(framework); const projectRes = await this.getUserInput({ @@ -212,9 +211,7 @@ export abstract class BasePromptSession { message: "Choose the type of project:", choices: projectLibraries }); - projectLibrary = this.templateManager.getProjectLibraryByName(framework, projectRes); - - return projectLibrary; + return this.templateManager.getProjectLibraryByName(framework, projectRes); } /** @@ -222,17 +219,13 @@ export abstract class BasePromptSession { * @param projectLibrary to get theme for */ protected async getProjectTemplate(projectLibrary: ProjectLibrary): Promise { - let projTemplate: ProjectTemplate; - const componentNameRes = await this.getUserInput({ type: "list", name: "projTemplate", message: "Choose project template:", choices: Util.formatChoices(projectLibrary.projects) }); - projTemplate = projectLibrary.projects.find(x => x.name === componentNameRes); - - return projTemplate; + return projectLibrary.projects.find(x => x.name === componentNameRes); } /** @@ -240,8 +233,7 @@ export abstract class BasePromptSession { * @param projectLibrary to get theme for */ protected async getTheme(projectLibrary: ProjectLibrary): Promise { - let theme: string; - theme = await this.getUserInput({ + const theme = await this.getUserInput({ type: "list", name: "theme", message: "Choose the theme for the project:", @@ -500,7 +492,6 @@ export abstract class BasePromptSession { * @param component to get template for */ private getTemplateTask: Task = async (_runner, context) => { - let selectedTemplate: Template; const templates: Template[] = context.component.templates; const templateRes = await this.getUserInput({ @@ -514,7 +505,7 @@ export abstract class BasePromptSession { return WIZARD_BACK_OPTION; } - selectedTemplate = templates.find((value, i, obj) => { + const selectedTemplate = templates.find((value, i, obj) => { return value.name === templateRes; }); diff --git a/packages/core/templates/BaseProjectLibrary.ts b/packages/core/templates/BaseProjectLibrary.ts index ad4f70a05..f0a66de08 100644 --- a/packages/core/templates/BaseProjectLibrary.ts +++ b/packages/core/templates/BaseProjectLibrary.ts @@ -154,10 +154,8 @@ export class BaseProjectLibrary implements ProjectLibrary { } public getComponentGroupNames(): string[] { - let groups: string[]; - //poor-man's groupBy reduce - groups = this.components.reduce((prev, current, index, array) => { + const groups = this.components.reduce((prev, current, index, array) => { if (prev.indexOf(current.group) === -1) { prev.push(current.group); } diff --git a/packages/core/templates/BaseTemplateManager.ts b/packages/core/templates/BaseTemplateManager.ts index 329a1870e..df6a19d0a 100644 --- a/packages/core/templates/BaseTemplateManager.ts +++ b/packages/core/templates/BaseTemplateManager.ts @@ -22,7 +22,7 @@ export abstract class BaseTemplateManager { return this.frameworks.map(f => f.id); } public getFrameworkNames(): string[] { - // еxclude WebComponents from the Step-By-Step wizard + // exclude WebComponents from the Step-By-Step wizard return this.frameworks.map(f => f.name); } /** Returns framework found by its name or undefined. */ @@ -106,36 +106,31 @@ export abstract class BaseTemplateManager { const config = ProjectConfig.getConfig(); const customTemplates: Template[] = []; for (const entry of config.customTemplates) { - let template: Template; - // tslint:disable-next-line:prefer-const - let [protocol, value] = entry.split(/(^[^:]+):/).filter(x => x); - switch (protocol) { - default: - // in case just path is passed: - value = entry; - case "file": - case "path": - value = value.replace(/template\.json$/, ""); - if (Util.directoryExists(value)) { - // try single template - template = this.loadFromConfig(path.join(value, "template.json")); - if (template !== null) { - customTemplates.push(template); - break; - } - // try folder of templates: - for (const folder of Util.getDirectoryNames(value)) { - template = this.loadFromConfig(path.join(value, folder, "template.json")); - if (template !== null) { - customTemplates.push(template); - } - } - } else { - // TODO: Util.log(`Ignored: Incorrect custom template path for "${entry}".`); - } - break; - case "ignored": - break; + const [protocol, value] = entry.split(/(^[^:]+):/).filter(x => x); + + let templateDir = protocol === "file" || protocol === "path" + ? value + : entry; + templateDir = templateDir.replace(/template\.json$/, ""); + + if (!Util.directoryExists(templateDir)) { + // TODO: Util.log(`Ignored: Incorrect custom template path for "${entry}".`); + continue; + } + + // try single template + let template = this.loadFromConfig(path.join(templateDir, "template.json")); + if (template !== null) { + customTemplates.push(template); + continue; + } + + // try folder of templates: + for (const folder of Util.getDirectoryNames(templateDir)) { + template = this.loadFromConfig(path.join(templateDir, folder, "template.json")); + if (template !== null) { + customTemplates.push(template); + } } } this.addTemplates(customTemplates); diff --git a/packages/core/util/Schematics.ts b/packages/core/util/Schematics.ts index dbc1fc71f..a443907cd 100644 --- a/packages/core/util/Schematics.ts +++ b/packages/core/util/Schematics.ts @@ -1,4 +1,4 @@ -// tslint:disable: no-implicit-dependencies +// eslint-disable-next-line eslint-plugin-import/no-extraneous-dependencies import { workspaces } from "@angular-devkit/core"; import { Tree } from "@angular-devkit/schematics"; diff --git a/packages/core/util/Util.ts b/packages/core/util/Util.ts index 389b99a2e..753c06982 100644 --- a/packages/core/util/Util.ts +++ b/packages/core/util/Util.ts @@ -128,14 +128,12 @@ export class Util { * @param colorKeyword Optional color (CSS keyword like red, green, etc.) */ public static log(message: string, colorKeyword?: string) { - // tslint:disable:no-console if (colorKeyword) { const color = chalk.keyword(colorKeyword); - console.log(color(message)); - } else { - console.log(message); + message = color(message); } - // tslint:enable:no-console + // eslint-disable-next-line no-console + console.log(message); } /** @@ -149,14 +147,12 @@ export class Util { cd: `error: ${message}` }); - // tslint:disable:no-console if (colorKeyword) { const color = chalk.keyword(colorKeyword); - console.error(color(message)); - } else { - console.error(message); + message = color(message); } - // tslint:enable:no-console + // eslint-disable-next-line no-console + console.error(message); } /** @@ -165,14 +161,12 @@ export class Util { * @param colorKeyword Optional color (CSS keyword like red, green, etc.) */ public static warn(message: string, colorKeyword?: string) { - // tslint:disable:no-console if (colorKeyword) { const color = chalk.keyword(colorKeyword); - console.warn(color(message)); - } else { - console.warn(message); + message = color(message); } - // tslint:enable:no-console + // eslint-disable-next-line no-console + console.warn(message); } public static greenCheck() { diff --git a/packages/igx-templates/IgniteUIForAngularTemplate.ts b/packages/igx-templates/IgniteUIForAngularTemplate.ts index 2e9474986..fc9f6e67c 100644 --- a/packages/igx-templates/IgniteUIForAngularTemplate.ts +++ b/packages/igx-templates/IgniteUIForAngularTemplate.ts @@ -2,7 +2,7 @@ import { AddTemplateArgs, App, ControlExtraConfiguration, FS_TOKEN, IFileSystem, NPM_ANGULAR, NPM_DOCK_MANAGER, Template, TemplateDependency, Util, resolvePackage } from "@igniteui/cli-core"; -import { AngularTypeScriptFileUpdate } from "@igniteui/angular-templates"; +import type { AngularTypeScriptFileUpdate } from "./AngularTypeScriptFileUpdate"; import * as path from "path"; export class IgniteUIForAngularTemplate implements Template { @@ -58,10 +58,8 @@ export class IgniteUIForAngularTemplate implements Template { // D.P. Don't use the top-level import as that chains import of typescript // which slows down execution of the entire component noticeably (template loading) // https://www.typescriptlang.org/docs/handbook/modules.html#dynamic-module-loading-in-nodejs - // tslint:disable-next-line:variable-name const TsUpdate: typeof AngularTypeScriptFileUpdate = - // tslint:disable-next-line:no-submodule-imports - require("@igniteui/angular-templates").AngularTypeScriptFileUpdate; + require("./AngularTypeScriptFileUpdate").AngularTypeScriptFileUpdate; const mainModulePath = path.join(projectPath, `src/app/${modulePath}`); const folderName = this.folderName(name); diff --git a/packages/ng-schematics/scripts/install.ts b/packages/ng-schematics/scripts/install.ts index 670ea391a..84e9e6391 100644 --- a/packages/ng-schematics/scripts/install.ts +++ b/packages/ng-schematics/scripts/install.ts @@ -2,7 +2,7 @@ import { App, GoogleAnalytics } from "@igniteui/cli-core"; function install() { - if (!!process.env.npm_config_global) { + if (process.env.npm_config_global) { App.initialize("angular-cli"); GoogleAnalytics.post({ t: "screenview", diff --git a/packages/ng-schematics/scripts/uninstall.ts b/packages/ng-schematics/scripts/uninstall.ts index c268e2685..c90ca6165 100644 --- a/packages/ng-schematics/scripts/uninstall.ts +++ b/packages/ng-schematics/scripts/uninstall.ts @@ -2,7 +2,7 @@ import { App, GoogleAnalytics } from "@igniteui/cli-core"; function uninstall() { - if (!!process.env.npm_config_global) { + if (process.env.npm_config_global) { App.initialize("angular-cli"); GoogleAnalytics.post({ t: "screenview", diff --git a/scripts/changelogScript.ts b/scripts/changelogScript.ts index 2706db407..b207458d4 100644 --- a/scripts/changelogScript.ts +++ b/scripts/changelogScript.ts @@ -24,7 +24,7 @@ export function generateChangelog(version: string) { try { mainChangelog = readFileSync("CHANGELOG.md"); } catch (e) { - // tslint:disable-next-line:no-console + // eslint-disable-next-line no-console console.warn("No changelog present, creating file"); } let currentLog = mainChangelog ? mainChangelog.toString() : ""; diff --git a/spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts b/spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts index f370703f2..1d266fd1b 100644 --- a/spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts +++ b/spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts @@ -36,7 +36,7 @@ describe("Unit - IgniteUIForAngularTemplate Base", () => { App.initialize(); // spy on require: spyOn(require("module"), "_load").and.callFake((modulePath: string) => { - if (modulePath.endsWith("@igniteui/angular-templates")) { + if (modulePath.endsWith("./AngularTypeScriptFileUpdate")) { return helpers; } else if (modulePath.endsWith("@igniteui/cli-core/packages/components")) { return { dv: ["igDvWidget"] };