Skip to content

Commit

Permalink
Chore: migrate to eslint@9
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Apr 24, 2024
1 parent e734cf4 commit 9fbc78b
Show file tree
Hide file tree
Showing 111 changed files with 239 additions and 938 deletions.
98 changes: 0 additions & 98 deletions .eslintrc.json

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Expand Up @@ -14,6 +14,8 @@ jobs:
node-version: 20
cache: 'yarn'
- run: yarn install --immutable --immutable-cache
- name: Typescript
run: yarn turbo tsc
- name: Eslint
run: yarn eslint .
- name: Validate package setup
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/has-npm-1.0.3-b7f00631c1-a449f3185b.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
68 changes: 68 additions & 0 deletions eslint.config.js
@@ -0,0 +1,68 @@
// @ts-check
import eslint from '@eslint/js';
import globals from 'globals';
import tseslint from 'typescript-eslint';
import nodePlugin from 'eslint-plugin-n';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';

export default tseslint.config(
{
ignores: [
'.git',
'node_modules',
'coverage',
'packages/*/dist/**',
'packages/*/node_modules/**',
'packages/*/__snapshots__/**',
],
},
{
languageOptions: {
globals: {
...globals.nodeBuiltin,
},
},
plugins: {
unicorn: eslintPluginUnicorn,
},
rules: {
'unicorn/no-abusive-eslint-disable': 'error',
'unicorn/prefer-module': 'error',
'unicorn/prefer-node-protocol': 'error',
},
},
eslint.configs.recommended,
nodePlugin.configs['flat/recommended-module'],
{
files: ['**/*.mts', '**/*.ts'],
extends: [...tseslint.configs.recommended],
},
{
files: ['**/*.cjs'],
extends: [nodePlugin.configs['flat/recommended-script']],
languageOptions: {
globals: {
...globals.node,
},
},
},
{
files: ['packages/inquirer/test/**', 'packages/**/*.test.*'],
rules: {
'n/no-extraneous-import': [
'error',
{
allowModules: ['vitest'],
},
],
'n/no-extraneous-require': [
'error',
{
allowModules: ['vitest'],
},
],
},
},
eslintPluginPrettierRecommended,
);
9 changes: 4 additions & 5 deletions package.json
Expand Up @@ -48,19 +48,17 @@
],
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
"@eslint/js": "^9.1.1",
"@sindresorhus/tsconfig": "^5.0.0",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"@vitest/coverage-v8": "^1.5.1",
"@vitest/ui": "^1.5.1",
"eslint": "^8.57.0",
"eslint": "^9.1.1",
"eslint-config-prettier": "^9.1.0",
"eslint-config-xo": "^0.44.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^17.3.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^52.0.0",
"globals": "^15.0.0",
"globby": "^14.0.1",
"husky": "^9.0.11",
"lerna": "^8.1.2",
Expand All @@ -69,6 +67,7 @@
"ts-node": "^10.9.2",
"turbo": "^1.13.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.7.1",
"vitest": "^1.5.1"
},
"resolutions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/checkbox/checkbox.test.mts
Expand Up @@ -644,7 +644,7 @@ describe('checkbox prompt', () => {
const { answer, events, getScreen } = await render(checkbox, {
message: 'Select a number',
choices: numberedChoices,
validate(items: any) {
validate(items: ReadonlyArray<unknown>) {
if (items.length !== 1) {
return 'Please select only one choice';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/checkbox/src/index.mts
Expand Up @@ -94,7 +94,7 @@ function check(checked: boolean) {
}

export default createPrompt(
<Value extends unknown>(config: Config<Value>, done: (value: Array<Value>) => void) => {
<Value,>(config: Config<Value>, done: (value: Array<Value>) => void) => {
const {
instructions,
pageSize = 7,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/core.test.mts
Expand Up @@ -514,7 +514,7 @@ describe('Error handling', () => {
});

it('surface errors in useEffect cleanup functions', async () => {
const Prompt = (config: {}, done: (value: string) => void) => {
const Prompt = (config: object, done: (value: string) => void) => {
useEffect(() => {
done('done');

Expand All @@ -533,8 +533,8 @@ describe('Error handling', () => {
});

it('prevent returning promises from useEffect hook', async () => {
const Prompt = (config: {}, done: (value: string) => void) => {
// @ts-ignore: This is a test
const Prompt = (config: object, done: (value: string) => void) => {
// @ts-expect-error: This is a test
useEffect(async () => {
done('done');
}, []);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/lib/hook-engine.mts
@@ -1,3 +1,5 @@
/* eslint @typescript-eslint/no-explicit-any: ["off"] */

import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
import type { InquirerReadline } from './read-line.type.mjs';
import { HookError, ValidationError } from './errors.mjs';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/make-theme.mts
@@ -1,7 +1,7 @@
import type { Prettify, PartialDeep } from '@inquirer/type';
import { defaultTheme, type Theme } from './theme.mjs';

export function makeTheme<SpecificTheme extends {}>(
export function makeTheme<SpecificTheme extends object>(
...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>
): Prettify<Theme<SpecificTheme>> {
return Object.assign({}, defaultTheme, ...themes, {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/theme.mts
Expand Up @@ -19,7 +19,7 @@ type DefaultTheme = {
};
};

export type Theme<Extension extends {} = {}> = Prettify<Extension & DefaultTheme>;
export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;

export const defaultTheme: DefaultTheme = {
prefix: chalk.green('?'),
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/use-state.mts
@@ -1,5 +1,6 @@
import { withPointer, handleChange } from './hook-engine.mjs';

// eslint-disable-next-line @typescript-eslint/ban-types
type NotFunction<T> = T extends Function ? never : T;

export function useState<Value>(
Expand Down
1 change: 0 additions & 1 deletion packages/demo/index.mjs
@@ -1,5 +1,4 @@
#!/usr/bin/env node
/* eslint-disable no-await-in-loop */

import { select } from '@inquirer/prompts';
import checkboxDemo from './demos/checkbox.mjs';
Expand Down
2 changes: 0 additions & 2 deletions packages/inquirer/examples/filter-validate-progress.js
Expand Up @@ -4,8 +4,6 @@

import inquirer from '../lib/inquirer.js';

/* eslint-disable no-promise-executor-return */

const questions = [
{
type: 'input',
Expand Down
1 change: 0 additions & 1 deletion packages/inquirer/lib/objects/choice.js
Expand Up @@ -10,7 +10,6 @@ export default class Choice {
constructor(val, answers) {
// Don't process Choice and Separator object
if (val instanceof Choice || val.type === 'separator') {
// eslint-disable-next-line no-constructor-return
return val;
}

Expand Down
5 changes: 2 additions & 3 deletions packages/inquirer/lib/prompts/base.js
Expand Up @@ -94,16 +94,15 @@ export default class Prompt {
* @return {Object} Object containing two observables: `success` and `error`
*/
handleSubmitEvents(submit) {
const self = this;
const validate = runAsync(this.opt.validate);
const asyncFilter = runAsync(this.opt.filter);
const validation = submit.pipe(
flatMap((value) => {
this.startSpinner(value, this.opt.filteringText);
return asyncFilter(value, self.answers).then(
return asyncFilter(value, this.answers).then(
(filteredValue) => {
this.startSpinner(filteredValue, this.opt.validatingText);
return validate(filteredValue, self.answers).then(
return validate(filteredValue, this.answers).then(
(isValid) => ({ isValid, value: filteredValue }),
(err) => ({ isValid: err, value: filteredValue }),
);
Expand Down
4 changes: 1 addition & 3 deletions packages/inquirer/lib/prompts/list.js
Expand Up @@ -49,8 +49,6 @@ export default class ListPrompt extends Base {
_run(cb) {
this.done = cb;

const self = this;

const events = observe(this.rl);
events.normalizedUpKey.pipe(takeUntil(events.line)).forEach(this.onUpKey.bind(this));
events.normalizedDownKey
Expand All @@ -62,7 +60,7 @@ export default class ListPrompt extends Base {
take(1),
map(this.getCurrentValue.bind(this)),
flatMap((value) =>
runAsync(self.opt.filter)(value, self.answers).catch((err) => err),
runAsync(this.opt.filter)(value, this.answers).catch((err) => err),
),
)
.forEach(this.onSubmit.bind(this));
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/test/helpers/readline.js
Expand Up @@ -26,7 +26,7 @@ Object.assign(stub, {
const ReadlineStub = function () {
this.line = '';
this.input = new EventEmitter();
// eslint-disable-next-line prefer-rest-params

EventEmitter.apply(this, arguments);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/rawlist/src/index.mts
Expand Up @@ -32,7 +32,7 @@ function isSelectableChoice<T>(
}

export default createPrompt(
<Value extends unknown>(config: RawlistConfig<Value>, done: (value: Value) => void) => {
<Value,>(config: RawlistConfig<Value>, done: (value: Value) => void) => {
const { choices } = config;
const [status, setStatus] = useState<string>('pending');
const [value, setValue] = useState<string>('');
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/src/index.mts
Expand Up @@ -42,7 +42,7 @@ class BufferedStream extends Stream.Writable {
}
}

export async function render<TestedPrompt extends Prompt<any, any>>(
export async function render<TestedPrompt extends Prompt<unknown, unknown>>(
prompt: TestedPrompt,
props: Parameters<TestedPrompt>[0],
options?: Parameters<TestedPrompt>[1],
Expand Down
1 change: 1 addition & 0 deletions packages/type/src/index.mts
Expand Up @@ -4,6 +4,7 @@ export class CancelablePromise<T> extends Promise<T> {

export type Prettify<T> = {
[K in keyof T]: T[K];
// eslint-disable-next-line @typescript-eslint/ban-types
} & {};

export type PartialDeep<T> = T extends object
Expand Down

0 comments on commit 9fbc78b

Please sign in to comment.