Skip to content

Commit 1808701

Browse files
authored
Merge pull request #1557 from IgniteUI/dpetev/fix-lint
Fix eslint config ignores, rules and lint errors
2 parents 0756d02 + 3ffa07f commit 1808701

File tree

14 files changed

+62
-82
lines changed

14 files changed

+62
-82
lines changed

eslint.config.mjs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export default [
3232
rules: {
3333
'complexity': 'off',
3434
'eslint-plugin-import/no-extraneous-dependencies': 'warn',
35-
'eslint-plugin-import/no-internal-modules': 'warn',
3635
'eslint-plugin-import/order': [
3736
'off',
3837
{
@@ -93,7 +92,7 @@ export default [
9392
'no-bitwise': 'off',
9493
'no-caller': 'error',
9594
'no-cond-assign': 'error',
96-
'no-console': 'off',
95+
'no-console': 'error',
9796
'no-debugger': 'error',
9897
'no-duplicate-case': 'error',
9998
'no-duplicate-imports': 'error',
@@ -132,12 +131,19 @@ export default [
132131
'valid-typeof': 'off',
133132
},
134133
},
134+
{
135+
files: ['**/*.spec.ts', '**/*-spec.ts', 'spec/**/*.ts'],
136+
rules: {
137+
'eslint-plugin-import/no-extraneous-dependencies': 'off',
138+
'no-console': 'off',
139+
},
140+
},
135141
{
136142
ignores: [
137-
'/node_modules/**/*',
138-
'/coverage/**/*',
139-
'/output/**/*',
140-
'/packages/cli/templates/**/*',
143+
'node_modules/**/*',
144+
'coverage/**/*',
145+
'output/**/*',
146+
'packages/cli/templates/**/*',
141147
'**/files/**/*'
142148
]
143149
},

packages/cli/lib/PromptSession.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ export class PromptSession extends BasePromptSession {
9595

9696
protected async completeAndRun(port?: number) {
9797
await PackageManager.flushQueue(true);
98-
if (true) { // TODO: Make conditional?
99-
await start.start({ port });
100-
}
98+
await start.start({ port });
10199
}
102100

103101
protected async upgradePackages() {

packages/cli/scripts/install.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { App, GoogleAnalytics } from "@igniteui/cli-core";
33

44
function install() {
5-
if (!!process.env.npm_config_global) {
5+
if (process.env.npm_config_global) {
66
App.initialize();
77
GoogleAnalytics.post({
88
t: "screenview",

packages/cli/scripts/uninstall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { App, GoogleAnalytics } from "@igniteui/cli-core";
33

44
function uninstall() {
5-
if (!!process.env.npm_config_global) {
5+
if (process.env.npm_config_global) {
66
App.initialize();
77
GoogleAnalytics.post({
88
t: "screenview",

packages/core/prompt/BasePromptSession.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export abstract class BasePromptSession {
203203
* @param framework to get project library for
204204
*/
205205
protected async getProjectLibrary(framework: Framework): Promise<ProjectLibrary> {
206-
let projectLibrary: ProjectLibrary;
207206
const projectLibraries = this.getProjectLibNames(framework);
208207

209208
const projectRes = await this.getUserInput({
@@ -212,36 +211,29 @@ export abstract class BasePromptSession {
212211
message: "Choose the type of project:",
213212
choices: projectLibraries
214213
});
215-
projectLibrary = this.templateManager.getProjectLibraryByName(framework, projectRes);
216-
217-
return projectLibrary;
214+
return this.templateManager.getProjectLibraryByName(framework, projectRes);
218215
}
219216

220217
/**
221218
* Gets project template from user input, or default if provided `projectLibrary` has a single template
222219
* @param projectLibrary to get theme for
223220
*/
224221
protected async getProjectTemplate(projectLibrary: ProjectLibrary): Promise<ProjectTemplate> {
225-
let projTemplate: ProjectTemplate;
226-
227222
const componentNameRes = await this.getUserInput({
228223
type: "list",
229224
name: "projTemplate",
230225
message: "Choose project template:",
231226
choices: Util.formatChoices(projectLibrary.projects)
232227
});
233-
projTemplate = projectLibrary.projects.find(x => x.name === componentNameRes);
234-
235-
return projTemplate;
228+
return projectLibrary.projects.find(x => x.name === componentNameRes);
236229
}
237230

238231
/**
239232
* Gets the theme from the user input, or default if provided @param projectLibrary has a single theme
240233
* @param projectLibrary to get theme for
241234
*/
242235
protected async getTheme(projectLibrary: ProjectLibrary): Promise<string> {
243-
let theme: string;
244-
theme = await this.getUserInput({
236+
const theme = await this.getUserInput({
245237
type: "list",
246238
name: "theme",
247239
message: "Choose the theme for the project:",
@@ -500,7 +492,6 @@ export abstract class BasePromptSession {
500492
* @param component to get template for
501493
*/
502494
private getTemplateTask: Task<PromptTaskContext> = async (_runner, context) => {
503-
let selectedTemplate: Template;
504495
const templates: Template[] = context.component.templates;
505496

506497
const templateRes = await this.getUserInput({
@@ -514,7 +505,7 @@ export abstract class BasePromptSession {
514505
return WIZARD_BACK_OPTION;
515506
}
516507

517-
selectedTemplate = templates.find((value, i, obj) => {
508+
const selectedTemplate = templates.find((value, i, obj) => {
518509
return value.name === templateRes;
519510
});
520511

packages/core/templates/BaseProjectLibrary.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,8 @@ export class BaseProjectLibrary implements ProjectLibrary {
154154
}
155155

156156
public getComponentGroupNames(): string[] {
157-
let groups: string[];
158-
159157
//poor-man's groupBy reduce
160-
groups = this.components.reduce((prev, current, index, array) => {
158+
const groups = this.components.reduce((prev, current, index, array) => {
161159
if (prev.indexOf(current.group) === -1) {
162160
prev.push(current.group);
163161
}

packages/core/templates/BaseTemplateManager.ts

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export abstract class BaseTemplateManager {
2222
return this.frameworks.map(f => f.id);
2323
}
2424
public getFrameworkNames(): string[] {
25-
// еxclude WebComponents from the Step-By-Step wizard
25+
// exclude WebComponents from the Step-By-Step wizard
2626
return this.frameworks.map(f => f.name);
2727
}
2828
/** Returns framework found by its name or undefined. */
@@ -106,36 +106,31 @@ export abstract class BaseTemplateManager {
106106
const config = ProjectConfig.getConfig();
107107
const customTemplates: Template[] = [];
108108
for (const entry of config.customTemplates) {
109-
let template: Template;
110-
// tslint:disable-next-line:prefer-const
111-
let [protocol, value] = entry.split(/(^[^:]+):/).filter(x => x);
112-
switch (protocol) {
113-
default:
114-
// in case just path is passed:
115-
value = entry;
116-
case "file":
117-
case "path":
118-
value = value.replace(/template\.json$/, "");
119-
if (Util.directoryExists(value)) {
120-
// try single template
121-
template = this.loadFromConfig(path.join(value, "template.json"));
122-
if (template !== null) {
123-
customTemplates.push(template);
124-
break;
125-
}
126-
// try folder of templates:
127-
for (const folder of Util.getDirectoryNames(value)) {
128-
template = this.loadFromConfig(path.join(value, folder, "template.json"));
129-
if (template !== null) {
130-
customTemplates.push(template);
131-
}
132-
}
133-
} else {
134-
// TODO: Util.log(`Ignored: Incorrect custom template path for "${entry}".`);
135-
}
136-
break;
137-
case "ignored":
138-
break;
109+
const [protocol, value] = entry.split(/(^[^:]+):/).filter(x => x);
110+
111+
let templateDir = protocol === "file" || protocol === "path"
112+
? value
113+
: entry;
114+
templateDir = templateDir.replace(/template\.json$/, "");
115+
116+
if (!Util.directoryExists(templateDir)) {
117+
// TODO: Util.log(`Ignored: Incorrect custom template path for "${entry}".`);
118+
continue;
119+
}
120+
121+
// try single template
122+
let template = this.loadFromConfig(path.join(templateDir, "template.json"));
123+
if (template !== null) {
124+
customTemplates.push(template);
125+
continue;
126+
}
127+
128+
// try folder of templates:
129+
for (const folder of Util.getDirectoryNames(templateDir)) {
130+
template = this.loadFromConfig(path.join(templateDir, folder, "template.json"));
131+
if (template !== null) {
132+
customTemplates.push(template);
133+
}
139134
}
140135
}
141136
this.addTemplates(customTemplates);

packages/core/util/Schematics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// tslint:disable: no-implicit-dependencies
1+
// eslint-disable-next-line eslint-plugin-import/no-extraneous-dependencies
22
import { workspaces } from "@angular-devkit/core";
33
import { Tree } from "@angular-devkit/schematics";
44

packages/core/util/Util.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,12 @@ export class Util {
128128
* @param colorKeyword Optional color (CSS keyword like red, green, etc.)
129129
*/
130130
public static log(message: string, colorKeyword?: string) {
131-
// tslint:disable:no-console
132131
if (colorKeyword) {
133132
const color = chalk.keyword(colorKeyword);
134-
console.log(color(message));
135-
} else {
136-
console.log(message);
133+
message = color(message);
137134
}
138-
// tslint:enable:no-console
135+
// eslint-disable-next-line no-console
136+
console.log(message);
139137
}
140138

141139
/**
@@ -149,14 +147,12 @@ export class Util {
149147
cd: `error: ${message}`
150148
});
151149

152-
// tslint:disable:no-console
153150
if (colorKeyword) {
154151
const color = chalk.keyword(colorKeyword);
155-
console.error(color(message));
156-
} else {
157-
console.error(message);
152+
message = color(message);
158153
}
159-
// tslint:enable:no-console
154+
// eslint-disable-next-line no-console
155+
console.error(message);
160156
}
161157

162158
/**
@@ -165,14 +161,12 @@ export class Util {
165161
* @param colorKeyword Optional color (CSS keyword like red, green, etc.)
166162
*/
167163
public static warn(message: string, colorKeyword?: string) {
168-
// tslint:disable:no-console
169164
if (colorKeyword) {
170165
const color = chalk.keyword(colorKeyword);
171-
console.warn(color(message));
172-
} else {
173-
console.warn(message);
166+
message = color(message);
174167
}
175-
// tslint:enable:no-console
168+
// eslint-disable-next-line no-console
169+
console.warn(message);
176170
}
177171

178172
public static greenCheck() {

packages/igx-templates/IgniteUIForAngularTemplate.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
AddTemplateArgs, App, ControlExtraConfiguration, FS_TOKEN, IFileSystem, NPM_ANGULAR,
33
NPM_DOCK_MANAGER, Template, TemplateDependency, Util, resolvePackage
44
} from "@igniteui/cli-core";
5-
import { AngularTypeScriptFileUpdate } from "@igniteui/angular-templates";
5+
import type { AngularTypeScriptFileUpdate } from "./AngularTypeScriptFileUpdate";
66
import * as path from "path";
77

88
export class IgniteUIForAngularTemplate implements Template {
@@ -58,10 +58,8 @@ export class IgniteUIForAngularTemplate implements Template {
5858
// D.P. Don't use the top-level import as that chains import of typescript
5959
// which slows down execution of the entire component noticeably (template loading)
6060
// https://www.typescriptlang.org/docs/handbook/modules.html#dynamic-module-loading-in-nodejs
61-
// tslint:disable-next-line:variable-name
6261
const TsUpdate: typeof AngularTypeScriptFileUpdate =
63-
// tslint:disable-next-line:no-submodule-imports
64-
require("@igniteui/angular-templates").AngularTypeScriptFileUpdate;
62+
require("./AngularTypeScriptFileUpdate").AngularTypeScriptFileUpdate;
6563

6664
const mainModulePath = path.join(projectPath, `src/app/${modulePath}`);
6765
const folderName = this.folderName(name);

0 commit comments

Comments
 (0)