Skip to content

Commit

Permalink
migrate to eslint 9 and test adjusts (#1545)
Browse files Browse the repository at this point in the history
* migrate to eslint 9

* drop yeoman-environment from peer dependencies

* disable spawn-command test

* recreate package-lock.json

* test adjusts
  • Loading branch information
mshima authored Sep 6, 2024
1 parent d01aa2f commit a66c6f5
Show file tree
Hide file tree
Showing 28 changed files with 4,056 additions and 6,589 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

13 changes: 13 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-check
import configs from '@yeoman/eslint';
import { config } from 'typescript-eslint';

export default config(...configs, {
rules: {
'unicorn/prevent-abbreviations': 'off',
'unicorn/no-thenable': 'off',
'unicorn/prefer-event-target': 'off',
'unicorn/no-object-as-default-parameter': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
},
});
10,410 changes: 3,942 additions & 6,468 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"doc:generate": "jsdoc -c jsdoc.json -d $npm_package_config_doc_path$DOC_FOLDER",
"doc:prettier": "prettier $npm_package_config_doc_path$DOC_FOLDER --write --ignore-path .prettierignore-doc",
"prepare": "npm run build",
"pretest": "xo",
"pretest": "eslint .",
"test": "c8 esmocha --forbid-only"
},
"config": {
Expand Down Expand Up @@ -73,11 +73,13 @@
"@types/debug": "^4.1.9",
"@types/ejs": "^3.1.4",
"@types/inquirer": "^9.0.4",
"@types/json-schema": "^7.0.15",
"@types/minimist": "^1.2.3",
"@types/semver": "^7.5.3",
"@types/sinon": "^17.0.1",
"@types/text-table": "^0.2.3",
"@yeoman/adapter": "^1.4.0",
"@yeoman/eslint": "^0.2.0",
"@yeoman/transform": "^1.2.0",
"c8": "^8.0.1",
"cpy-cli": "^5.0.0",
Expand All @@ -91,20 +93,13 @@
"sinon": "^18.0.0",
"tui-jsdoc-template": "^1.2.2",
"typescript": "^5.2.2",
"xo": "^0.56.0",
"yeoman-assert": "^3.1.1",
"yeoman-environment": "^4.0.0",
"yeoman-test": "^8.1.0"
},
"peerDependencies": {
"@yeoman/types": "^1.1.1",
"mem-fs": "^4.0.0",
"yeoman-environment": "^4.0.0"
},
"peerDependenciesMeta": {
"yeoman-environment": {
"optional": true
}
"mem-fs": "^4.1.0"
},
"engines": {
"node": "^18.17.0 || >=20.5.0"
Expand Down
13 changes: 4 additions & 9 deletions src/actions/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class FsMixin {
): OverloadReturnType<MemFsEditor['copy']> {
const [from, to, options = {}, ...remaining] = args;
options.fromBasePath = options.fromBasePath ?? this.templatePath();
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression

return this.fs.copy(from, this.destinationPath(to), options, ...remaining);
}

Expand Down Expand Up @@ -120,7 +120,6 @@ export class FsMixin {
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.readJSON(this.destinationPath(filepath)).
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
readDestinationJSON(
this: BaseGenerator,
...args: OverloadParameters<MemFsEditor['readJSON']>
Expand All @@ -145,7 +144,6 @@ export class FsMixin {
* mem-fs-editor method's shortcut, for more information see [mem-fs-editor]{@link https://github.com/SBoudrias/mem-fs-editor}.
* Shortcut for this.fs!.writeJSON(this.destinationPath(filepath)).
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
writeDestinationJSON(
this: BaseGenerator,
...args: OverloadParameters<MemFsEditor['writeJSON']>
Expand All @@ -162,7 +160,6 @@ export class FsMixin {
this: BaseGenerator,
...args: OverloadParameters<MemFsEditor['delete']>
): OverloadReturnType<MemFsEditor['delete']> {
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
return this.fs.delete(...applyToFirstStringArg(this.destinationPath.bind(this), args));
}

Expand All @@ -177,7 +174,7 @@ export class FsMixin {
): OverloadReturnType<MemFsEditor['copy']> {
const [from, to, options = {}, ...remaining] = args;
options.fromBasePath = options.fromBasePath ?? this.destinationPath();
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression

return this.fs.copy(from, this.destinationPath(to), options, ...remaining);
}

Expand All @@ -192,7 +189,7 @@ export class FsMixin {
): OverloadReturnType<MemFsEditor['move']> {
const [from, to, options = {}, ...remaining] = args;
options.fromBasePath = options.fromBasePath ?? this.destinationPath();
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression

return this.fs.move(from, this.destinationPath(to), options, ...remaining);
}

Expand All @@ -217,7 +214,6 @@ export class FsMixin {
* @param templateOptions - ejs options
* @param copyOptions - mem-fs-editor copy options
*/

renderTemplate<D extends TemplateData = TemplateData>(

Check warning on line 217 in src/actions/fs.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.17.x)

Method 'renderTemplate' has too many parameters (6). Maximum allowed is 5

Check warning on line 217 in src/actions/fs.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.17.x)

Method 'renderTemplate' has too many parameters (6). Maximum allowed is 5

Check warning on line 217 in src/actions/fs.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.17.x)

Method 'renderTemplate' has too many parameters (6). Maximum allowed is 5
this: BaseGenerator,
source: string | string[] = '',
Expand Down Expand Up @@ -249,7 +245,6 @@ export class FsMixin {
* @param templateOptions - ejs options
* @param copyOptions - mem-fs-editor copy options
*/

async renderTemplateAsync<D extends TemplateData = TemplateData>(

Check warning on line 248 in src/actions/fs.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.17.x)

Async method 'renderTemplateAsync' has too many parameters (6). Maximum allowed is 5

Check warning on line 248 in src/actions/fs.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.17.x)

Async method 'renderTemplateAsync' has too many parameters (6). Maximum allowed is 5

Check warning on line 248 in src/actions/fs.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.17.x)

Async method 'renderTemplateAsync' has too many parameters (6). Maximum allowed is 5
this: BaseGenerator,
source: string | string[] = '',
Expand Down Expand Up @@ -328,7 +323,7 @@ export class FsMixin {
);
}

return undefined;
return;
}),
);
}
Expand Down
7 changes: 3 additions & 4 deletions src/actions/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class HelpMixin {
const filepath = path.resolve(this.sourceRoot(), '../USAGE');
const exists = fs.existsSync(filepath);

let out = ['Usage:', ' ' + this.usage(), ''];
let out = ['Usage:', ` ${this.usage()}`, ''];

// Build options
if (Object.keys(this._options).length > 0) {
Expand Down Expand Up @@ -60,14 +60,14 @@ export class HelpMixin {
let args = '';

if (this._arguments.length > 0) {
args = this._arguments.map(arg => formatArg(arg)).join(' ') + ' ';
args = `${this._arguments.map(arg => formatArg(arg)).join(' ')} `;
}

name = name.replace(/^yeoman:/, '');
let out = `yo ${name} ${args}${options}`;

if (this.description) {
out += '\n\n' + this.description;
out += `\n\n${this.description}`;
}

return out;
Expand All @@ -78,7 +78,6 @@ export class HelpMixin {
*
* @param description
*/

desc(this: BaseGenerator, description: string) {
this.description = description || '';
return this;
Expand Down
32 changes: 16 additions & 16 deletions src/actions/lifecycle.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/* eslint-disable @typescript-eslint/member-ordering */
import { dirname, isAbsolute, resolve as pathResolve, relative } from 'node:path';
import { pathToFileURL } from 'node:url';
import { createRequire } from 'node:module';
import { Duplex } from 'node:stream';
import { stat } from 'node:fs/promises';
import createDebug from 'debug';
import type { BaseGenerator, GetGeneratorOptions, ComposeOptions as EnvironmentComposeOptions } from '@yeoman/types';
import type { BaseGenerator, ComposeOptions as EnvironmentComposeOptions, GetGeneratorOptions } from '@yeoman/types';
import { toNamespace } from '@yeoman/namespace';
import { type FileTransform, isFileTransform } from 'mem-fs';
import { type MemFsEditorFile } from 'mem-fs-editor';
// eslint-disable-next-line n/file-extension-in-import
import { isFilePending } from 'mem-fs-editor/state';
import type { Task, TaskOptions, BaseOptions, Priority, ComposeOptions, GeneratorPipelineOptions } from '../types.js';
import type { BaseOptions, ComposeOptions, GeneratorPipelineOptions, Priority, Task, TaskOptions } from '../types.js';
import type Generator from '../index.js';
import type BaseGeneratorImpl from '../generator.js';

Expand Down Expand Up @@ -245,13 +243,9 @@ export abstract class TasksMixin {
let validMethods = methods.filter(method => methodIsValid(method));
const { taskPrefix } = this.features;

if (taskPrefix) {
validMethods = validMethods
.filter(method => method.startsWith(taskPrefix))
.map(method => method.slice(taskPrefix.length));
} else {
validMethods = validMethods.filter(method => !method.startsWith('#'));
}
validMethods = taskPrefix
? validMethods.filter(method => method.startsWith(taskPrefix)).map(method => method.slice(taskPrefix.length))
: validMethods.filter(method => !method.startsWith('#'));

if (this.features.tasksMatchingPriority) {
const queueNames = Object.keys(this._queues);
Expand Down Expand Up @@ -485,7 +479,7 @@ export abstract class TasksMixin {
generator: string,
options?: ComposeOptions<G>,
): Promise<G[]>;
// eslint-disable-next-line max-params

async composeWith<G extends BaseGenerator = BaseGenerator>(
this: BaseGeneratorImpl,
generator: string | string[] | { Generator: any; path: string },
Expand Down Expand Up @@ -580,10 +574,12 @@ export abstract class TasksMixin {
let generatorFile;
try {
generatorFile = await this.resolveGeneratorPath(generator.path ?? generator.Generator.resolved);
} catch {}
} catch {
// Ignore error
}

const resolved = generatorFile ?? generator.path ?? generator.Generator.resolved;
// eslint-disable-next-line @typescript-eslint/naming-convention

return this.composeLocallyWithOptions<G>({ Generator: generator.Generator, resolved }, composeOptions);
}

Expand All @@ -596,7 +592,9 @@ export abstract class TasksMixin {
if (!namespace || forceResolve) {
try {
generator = await this.resolveGeneratorPath(generator);
} catch {}
} catch {
// Ignore error
}
}

return this.env.composeWith<G>(generator, composeOptions);
Expand Down Expand Up @@ -636,7 +634,9 @@ export abstract class TasksMixin {
if (status.isFile()) {
generatorResolvedFile = generatorFile;
}
} catch {}
} catch {
// Ignore error
}

if (!generatorResolvedFile) {
// Resolve the generator file.
Expand Down
2 changes: 1 addition & 1 deletion src/actions/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PackageJsonMixin {
return Object.fromEntries(
await Promise.all(
// Make sure to convert empty string too
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing

Object.entries(depMap).map(async ([pkg, version]) => [pkg, version || (await latestVersion(pkg))]),
),
);
Expand Down
10 changes: 5 additions & 5 deletions src/actions/spawn-command.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type Buffer from 'node:buffer';
import {
type ExecaChildProcess,
type Options as ExecaOptions,
type ExecaSyncReturnValue,
type SyncOptions,
execa,
execaSync,
execaCommand,
execaCommandSync,
type Options as ExecaOptions,
type ExecaChildProcess,
type SyncOptions,
type ExecaSyncReturnValue,
execaSync,
} from 'execa';
import type BaseGenerator from '../generator.js';

Check warning on line 12 in src/actions/spawn-command.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.17.x)

Using exported name 'BaseGenerator' as identifier for default export

Check warning on line 12 in src/actions/spawn-command.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.17.x)

Using exported name 'BaseGenerator' as identifier for default export

Check warning on line 12 in src/actions/spawn-command.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.17.x)

Using exported name 'BaseGenerator' as identifier for default export

Expand Down
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line @typescript-eslint/naming-convention
export const DESTINATION_ROOT_CHANGE_EVENT = 'destinationRootChange';

export const requiredEnvironmentVersion = '4.0.0-rc.0';
Loading

0 comments on commit a66c6f5

Please sign in to comment.