Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eslint v9 & flat configs #1397

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
110 changes: 0 additions & 110 deletions .eslintrc.json

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
node-version: 20
cache: 'yarn'
- run: yarn install --immutable --immutable-cache
- name: Typescript
run: yarn turbo tsc
Comment on lines +17 to +18
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now required for the import linting to work appropriately.

- 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 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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
73 changes: 73 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// @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__/**',
],
},
eslint.configs.recommended,
nodePlugin.configs['flat/recommended-module'],
eslintPluginUnicorn.configs['flat/recommended'],
{
languageOptions: {
globals: {
...globals.nodeBuiltin,
},
},
rules: {
'unicorn/consistent-function-scoping': 'off',
'unicorn/filename-case': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/no-null': 'off',
'unicorn/no-process-exit': 'off',
'unicorn/prefer-event-target': 'off',
'unicorn/prefer-top-level-await': 'off',
'unicorn/prevent-abbreviations': 'off',
},
},
{
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
Original file line number Diff line number Diff line change
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.2",
"@vitest/ui": "^1.5.2",
"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.3",
"typescript": "^5.4.5",
"typescript-eslint": "^7.7.1",
"vitest": "^1.5.2"
},
"resolutions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/checkbox/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,4 @@ export default createPrompt(
},
);

export { Separator };
export { Separator } from '@inquirer/core';
8 changes: 4 additions & 4 deletions packages/core/src/lib/create-prompt.mts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export function createPrompt<Value, Config>(view: ViewFunction<Value, Config>) {
store.hooksCleanup.forEach((cleanFn) => {
cleanFn?.();
});
} catch (err) {
reject(err);
} catch (error) {
reject(error);
}

if (context?.clearPromptOnDone) {
Expand Down Expand Up @@ -89,9 +89,9 @@ export function createPrompt<Value, Config>(view: ViewFunction<Value, Config>) {
screen.render(content, bottomContent);

effectScheduler.run();
} catch (err) {
} catch (error) {
onExit();
reject(err);
reject(error);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/use-state.mts
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/demo/demos/input.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as url from 'node:url';
import chalk from 'chalk';
import { input } from '@inquirer/prompts';

const hexRegEx = /([0-9]|[a-f])/gim;
const hexRegEx = /(\d|[a-f])/gim;
const isHex = (value) =>
(value.match(hexRegEx) || []).length === value.length &&
(value.length === 3 || value.length === 6);
Expand Down
9 changes: 6 additions & 3 deletions packages/editor/editor.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ describe('editor prompt', () => {
message: 'Add a description',
validate(value) {
switch (value) {
case '1':
case '1': {
return true;
case '2':
}
case '2': {
return '"2" is not an allowed value';
default:
}
default: {
return false;
}
}
},
});
Expand Down
2 changes: 0 additions & 2 deletions packages/inquirer/examples/filter-validate-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

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

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

const questions = [
{
type: 'input',
Expand Down
28 changes: 15 additions & 13 deletions packages/inquirer/examples/long-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
import inquirer from '../lib/inquirer.js';

const choices = Array.apply(0, Array.from({ length: 26 })).map((x, y) =>
String.fromCharCode(y + 65),
String.fromCodePoint(y + 65),
);
choices.push(
'Multiline option 1\n super cool feature \n more lines',
'Multiline option 2\n super cool feature \n more lines',
'Multiline option 3\n super cool feature \n more lines',
'Multiline option 4\n super cool feature \n more lines',
'Multiline option 5\n super cool feature \n more lines',
new inquirer.Separator(),
'Multiline option \n super cool feature',
{
name: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.',
value: 'foo',
short: 'The long option',
},
);
choices.push('Multiline option 1\n super cool feature \n more lines');
choices.push('Multiline option 2\n super cool feature \n more lines');
choices.push('Multiline option 3\n super cool feature \n more lines');
choices.push('Multiline option 4\n super cool feature \n more lines');
choices.push('Multiline option 5\n super cool feature \n more lines');
choices.push(new inquirer.Separator());
choices.push('Multiline option \n super cool feature');
choices.push({
name: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.',
value: 'foo',
short: 'The long option',
});

inquirer
.prompt([
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/examples/regex-validate-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const questions = [
return true;
}

throw Error('Please provide a valid API key secret.');
throw new Error('Please provide a valid API key secret.');
},
},
];
Expand Down
4 changes: 2 additions & 2 deletions packages/inquirer/examples/rx-observable-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const observable = from(questions);

inquirer.prompt(observable).ui.process.subscribe(
(ans) => {
console.log('Answer is: ', ans);
console.log('Answer is:', ans);
},
(err) => {
console.log('Error: ', err);
console.log('Error:', err);
},
() => {
console.log('Completed');
Expand Down
1 change: 0 additions & 1 deletion packages/inquirer/lib/objects/choice.js
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions packages/inquirer/lib/prompts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ export default class Prompt {
this.startSpinner(filteredValue, this.opt.validatingText);
return validate(filteredValue, this.answers).then(
(isValid) => ({ isValid, value: filteredValue }),
(err) => ({ isValid: err, value: filteredValue }),
(error_) => ({ isValid: error_, value: filteredValue }),
);
},
(err) => ({ isValid: err }),
(error_) => ({ isValid: error_ }),
);
}),
share(),
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class ListPrompt extends Base {
take(1),
map(this.getCurrentValue.bind(this)),
flatMap((value) =>
runAsync(this.opt.filter)(value, this.answers).catch((err) => err),
runAsync(this.opt.filter)(value, this.answers).catch((error) => error),
),
)
.forEach(this.onSubmit.bind(this));
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/utils/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function normalizeKeypressEvents(value, key) {
return { value, key: key || {} };
}

export default function (rl) {
export default function observe(rl) {
const keypress = fromEvent(rl.input, 'keypress', normalizeKeypressEvents)
.pipe(takeUntil(fromEvent(rl, 'close')))
// Ignore `enter` key. On the readline, we only care about the `line` event.
Expand Down