Skip to content

Commit c1740ae

Browse files
authored
chore: eslint adjusts (#33)
* chore: drop .xo-config.json files * chore: eslint adjusts
1 parent 472af72 commit c1740ae

25 files changed

+129
-117
lines changed

.xo-config.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

eslint.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,32 @@
33
import eslint from '@eslint/js';
44
import tseslint from 'typescript-eslint';
55
import prettier from 'eslint-config-prettier';
6+
import globals from 'globals';
67

78
export default tseslint.config(
9+
{
10+
languageOptions: {
11+
globals: {
12+
...globals.es2022,
13+
...globals.nodeBuiltin,
14+
},
15+
ecmaVersion: 2022,
16+
sourceType: 'module',
17+
},
18+
linterOptions: {
19+
reportUnusedDisableDirectives: 'error',
20+
},
21+
},
822
eslint.configs.recommended,
923
...tseslint.configs.recommended,
1024
{ ignores: ['**/dist/**', '**/fixtures/**'] },
1125
{
1226
rules: {
1327
'@typescript-eslint/no-explicit-any': 'off',
28+
'no-await-in-loop': 'off',
29+
'sort-imports': ['error', { ignoreDeclarationSort: true }],
30+
'prefer-destructuring': 'error',
31+
'prefer-template': 'error',
1432
},
1533
},
1634
prettier,

package-lock.json

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"build": "npm run build --workspaces",
1616
"clean": "npm run clean --workspaces",
1717
"clean-all": "npm run clean-all --workspaces && rimraf node_modules",
18-
"fix": "eslint . --fix && prettier . --write",
18+
"fix": "prettier . --write && eslint . --fix",
1919
"prepare": "npm run build && husky",
2020
"prettier": "prettier --write .",
2121
"pretest": "eslint . && prettier . --check",
@@ -33,6 +33,7 @@
3333
"cpy-cli": "^5.0.0",
3434
"eslint": "^9.9.1",
3535
"eslint-config-prettier": "^9.1.0",
36+
"globals": "^15.9.0",
3637
"husky": "^9.1.5",
3738
"lerna": "^8.1.8",
3839
"prettier": "^3.3.3",

workspaces/adapter/.xo-config.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

workspaces/adapter/src/adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import process from 'node:process';
22
import type inquirer from 'inquirer';
3-
import { createPromptModule, type PromptModule } from 'inquirer';
3+
import { type PromptModule, createPromptModule } from 'inquirer';
44
import chalk from 'chalk';
5-
import type { PromptAnswers, Logger, PromptQuestions, InputOutputAdapter } from '@yeoman/types';
5+
import type { InputOutputAdapter, Logger, PromptAnswers, PromptQuestions } from '@yeoman/types';
66
import { createLogger } from './log.js';
77

88
export type TerminalAdapterOptions = {

workspaces/adapter/src/log.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function createLogger<Loggers = any, LoggerCategories extends string | nu
9292
//
9393
// Returns the logger
9494
function log(message: string, ctx?: Record<string, string | number>) {
95-
message = message ?? '';
95+
message ??= '';
9696

9797
if (typeof ctx === 'object' && !Array.isArray(ctx)) {
9898
customConsole.error(formatter(message, ctx));
@@ -126,12 +126,12 @@ export function createLogger<Loggers = any, LoggerCategories extends string | nu
126126
// Convenience helper to write sucess status, this simply prepends the
127127
// message with a gren `✔`.
128128
log.ok = function (...args: Parameters<typeof util.format>) {
129-
this.write(logSymbols.success + ' ' + util.format(...args) + '\n');
129+
this.write(`${logSymbols.success} ${util.format(...args)}\n`);
130130
return this;
131131
};
132132

133133
log.error = function (...args: Parameters<typeof util.format>) {
134-
this.write(logSymbols.error + ' ' + util.format(...args) + '\n');
134+
this.write(`${logSymbols.error} ${util.format(...args)}\n`);
135135
return this;
136136
};
137137

@@ -171,7 +171,7 @@ export function createLogger<Loggers = any, LoggerCategories extends string | nu
171171
// @ts-expect-error
172172
log[status] = function (...args: Parameters<typeof util.format>) {
173173
this.write(color(pad(status))).write(padding);
174-
this.write(util.format(...args) + '\n');
174+
this.write(`${util.format(...args)}\n`);
175175
return this;
176176
};
177177
}
@@ -192,7 +192,7 @@ export function createLogger<Loggers = any, LoggerCategories extends string | nu
192192
const tableData = [];
193193

194194
options = Array.isArray(options) ? { rows: options } : (options ?? {});
195-
options.rows = options.rows || [];
195+
options.rows ||= [];
196196

197197
for (const row of options.rows) {
198198
tableData.push(row);
@@ -204,6 +204,7 @@ export function createLogger<Loggers = any, LoggerCategories extends string | nu
204204
log.colored = function (coloredMessages: Array<ColoredMessage<LoggerCategories>>) {
205205
this.write(coloredMessages.map(({ color, message }): string => (color ? colors[color](message) : message)).join(''));
206206
};
207+
207208
return log as any;
208209
}
209210

workspaces/adapter/src/queued-adapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { format } from 'node:util';
33
import ora, { type Ora } from 'ora';
44
import PQueue from 'p-queue';
55
import type {
6-
Logger,
76
InputOutputAdapter,
8-
PromptAnswers,
9-
PromptQuestions,
7+
Logger,
108
ProgressCallback,
119
ProgressOptions,
10+
PromptAnswers,
11+
PromptQuestions,
1212
QueuedAdapter as QueuedAdapterApi,
1313
} from '@yeoman/types';
1414
import { TerminalAdapter, type TerminalAdapterOptions } from './adapter.js';

workspaces/adapter/src/testing/test-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import events from 'node:events';
22
import { PassThrough } from 'node:stream';
3-
import type { PromptAnswers, PromptQuestion, Logger, PromptQuestions, Task, QueuedAdapter } from '@yeoman/types';
4-
import { createPromptModule, type PromptModule } from 'inquirer';
3+
import type { Logger, PromptAnswers, PromptQuestion, PromptQuestions, QueuedAdapter, Task } from '@yeoman/types';
4+
import { type PromptModule, createPromptModule } from 'inquirer';
55

66
import { createLogger } from '../log.js';
77

workspaces/adapter/test/test-adapter.test.ts

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,91 @@ import assert from 'node:assert';
22
import { describe, expect, it, vitest } from 'vitest';
33
import { TestAdapter } from '../src/testing/test-adapter.js';
44

5-
describe('TestAdapter', function () {
6-
describe('#prompt()', function () {
7-
it('allows pre-filled answers', async function () {
5+
describe('TestAdapter', () => {
6+
describe('#prompt()', () => {
7+
it('allows pre-filled answers', async () => {
88
const adapter = new TestAdapter();
99
return adapter
10-
.prompt([{ name: 'respuesta', message: 'foo', type: 'input', default: 'bar' }], {
11-
respuesta: 'foo',
12-
})
13-
.then(function (answers) {
10+
.prompt(
11+
[
12+
{
13+
name: 'respuesta',
14+
message: 'foo',
15+
type: 'input',
16+
default: 'bar',
17+
},
18+
],
19+
{
20+
respuesta: 'foo',
21+
},
22+
)
23+
.then(answers => {
1424
assert.equal(answers.respuesta, 'foo');
1525
});
1626
});
17-
it('handles mockedAnswers', async function () {
27+
it('handles mockedAnswers', async () => {
1828
const adapter = new TestAdapter({
1929
mockedAnswers: {
2030
respuesta: 'foo',
2131
},
2232
});
23-
const answers = await adapter.prompt([{ name: 'respuesta', message: 'foo', type: 'input', default: 'bar' }]);
33+
const answers = await adapter.prompt([
34+
{
35+
name: 'respuesta',
36+
message: 'foo',
37+
type: 'input',
38+
default: 'bar',
39+
},
40+
]);
2441
assert.equal(answers.respuesta, 'foo');
2542
});
26-
it('handles default value', async function () {
43+
it('handles default value', async () => {
2744
const adapter = new TestAdapter();
28-
const answers = await adapter.prompt([{ name: 'respuesta', message: 'foo', type: 'input', default: 'bar' }]);
45+
const answers = await adapter.prompt([
46+
{
47+
name: 'respuesta',
48+
message: 'foo',
49+
type: 'input',
50+
default: 'bar',
51+
},
52+
]);
2953
assert.equal(answers.respuesta, 'bar');
3054
});
31-
it('optionally throws on missing answer', async function () {
55+
it('optionally throws on missing answer', async () => {
3256
const adapter = new TestAdapter({ throwOnMissingAnswer: true });
3357
await expect(adapter.prompt([{ name: 'respuesta', message: 'foo', type: 'input' }])).rejects.toThrowError(
3458
'yeoman-test: question respuesta was asked but answer was not provided',
3559
);
3660
});
37-
it('should default to true for confirm prompt', async function () {
61+
it('should default to true for confirm prompt', async () => {
3862
const adapter = new TestAdapter();
3963
await expect(adapter.prompt([{ name: 'respuesta', message: 'foo', type: 'confirm' }])).resolves.toMatchObject({
4064
respuesta: true,
4165
});
4266
});
43-
it('list prompt should accept null answer', async function () {
67+
it('list prompt should accept null answer', async () => {
4468
const adapter = new TestAdapter({ mockedAnswers: { respuesta: null } });
4569
await expect(adapter.prompt([{ name: 'respuesta', message: 'foo', type: 'list' }])).resolves.toMatchObject({
4670
respuesta: null,
4771
});
4872
});
4973
});
50-
describe('#close()', function () {
51-
it('should restore prompts', async function () {
74+
describe('#close()', () => {
75+
it('should restore prompts', async () => {
5276
const adapter = new TestAdapter();
5377
vitest.spyOn(adapter.promptModule, 'restoreDefaultPrompts');
5478
adapter.close();
5579
expect(adapter.promptModule.restoreDefaultPrompts).toHaveBeenCalled();
5680
});
5781
});
58-
describe('#queue()', function () {
59-
it('should execute the callback', async function () {
82+
describe('#queue()', () => {
83+
it('should execute the callback', async () => {
6084
const adapter = new TestAdapter();
6185
await expect(adapter.queue(() => 2)).resolves.toBe(2);
6286
});
6387
});
64-
describe('#progress()', function () {
65-
it('should execute the callback', async function () {
88+
describe('#progress()', () => {
89+
it('should execute the callback', async () => {
6690
const adapter = new TestAdapter();
6791
await expect(
6892
adapter.progress(({ step }) => {

0 commit comments

Comments
 (0)