Skip to content

Commit

Permalink
ESLint v9 & Prettier v4
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Oct 9, 2024
1 parent e6e6eb2 commit 6d3622a
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 95 deletions.
33 changes: 0 additions & 33 deletions .eslintrc.cjs

This file was deleted.

1 change: 0 additions & 1 deletion .prettierrc.cjs

This file was deleted.

3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import configs from '@run-z/eslint-config';

export default configs;
15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,18 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@run-z/eslint-config": "^4.2.0",
"@run-z/prettier-config": "^2.0.0",
"@run-z/eslint-config": "^5.0.0",
"@run-z/prettier-config": "^3.0.0",
"@run-z/project-config": "^0.20.4",
"@swc/core": "^1.7.26",
"@swc/jest": "^0.2.36",
"@types/node": "^20.16.11",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"chalk": "^5.3.0",
"eslint": "^8.57.1",
"eslint-plugin-jest": "^28.8.3",
"eslint": "^9.12.0",
"gh-pages": "^6.1.1",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"jest-mock": "^29.7.0",
"prettier": "^2.8.8",
"prettier-eslint-cli": "^7.1.0",
"prettier": "^3.3.3",
"rollup": "^4.24.0",
"run-z": "2.1.0-bootstrap",
"strip-ansi": "^7.1.0",
Expand All @@ -92,7 +87,7 @@
"clean": "run-z +z --then clean-z",
"doc": "run-z +z --then typedoc",
"doc:publish": "run-z doc --then gh-pages --dist target/typedoc --dotfiles",
"format": "run-z +z --then prettier-eslint --write --include-dot-files \"src/**/*.*\" \"*.{js,cjs,json,md}\"",
"format": "run-z +z --then prettier --write \"src/**/*.*\" \"*.{js,cjs,json,md}\"",
"lint": "run-z +z --then eslint .",
"test": "run-z +z env:NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" --then test-z",
"z": "run-z +cmd:build-z,+cmd:typedoc,+cmd:eslint,+cmd:test-z"
Expand Down
3 changes: 3 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from '@run-z/prettier-config';

export default config;
3 changes: 1 addition & 2 deletions src/colors/chalk-color-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals
import { asArray, asis, noop } from '@proc7ts/primitives';
import type { ColorSupportLevel } from 'chalk';
import chalk from 'chalk';
import { MockedFunction } from 'jest-mock';
import { helpZOptionReader } from '../help/help-option-reader.js';
import { ZOptionError } from '../option-error.js';
import type { ZOption } from '../option.js';
Expand Down Expand Up @@ -120,7 +119,7 @@ describe('chalkZColorOptions', () => {
const options = [
...asArray<SupportedZOptions.Map | SupportedZOptions.Provider>(chalkZColorOptions()),
];
const display: MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);
const display: jest.MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);

options.push({
'-h': helpZOptionReader({ display }),
Expand Down
2 changes: 0 additions & 2 deletions src/colors/chalk-colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { ZColors } from './colors.js';
* This theme is used {@link ZColors.useByDefault by default}.
*/
export class ChalkZColors implements ZColors {

/**
* Chalk instance to use.
*/
Expand All @@ -36,5 +35,4 @@ export class ChalkZColors implements ZColors {
bullet(sign = '\u2023'): string {
return ` ${sign}`;
}

}
2 changes: 0 additions & 2 deletions src/colors/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ let defaultZColors: () => ZColors = /*#__PURE__*/ lazyValue(() => new ChalkZColo
* @internal
*/
class DefaultZColors implements ZColors {

usage(text: string): string {
return defaultZColors().usage(text);
}
Expand All @@ -80,7 +79,6 @@ class DefaultZColors implements ZColors {
bullet(sign?: string): string {
return defaultZColors().bullet(sign);
}

}

export const ZColors = {
Expand Down
28 changes: 13 additions & 15 deletions src/help/help-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { ZOptionMeta } from '../option-meta.js';
* Options help printer used {@link ZHelpConfig.display by default}.
*/
export class ZHelpFormatter {

/**
* Detects usage column width.
*
Expand Down Expand Up @@ -79,12 +78,12 @@ export class ZHelpFormatter {

const textLines = wrapLines(
text,
(process.stdout.columns || 80)
- usageWidth
- usagePadding[1]
- usagePadding[3]
- textPadding[1]
- textPadding[3],
(process.stdout.columns || 80) -
usageWidth -
usagePadding[1] -
usagePadding[3] -
textPadding[1] -
textPadding[3],
);

if (optionIdx) {
Expand All @@ -106,19 +105,18 @@ export class ZHelpFormatter {

for (let lineIdx = 0; lineIdx < numLines; ++lineIdx) {
out +=
usageLeft
+ padLine(usageLines[lineIdx] || '', usageWidth)
+ usageRight
+ textLeft
+ (textLines[lineIdx] || '')
+ textRight
+ '\n';
usageLeft +
padLine(usageLines[lineIdx] || '', usageWidth) +
usageRight +
textLeft +
(textLines[lineIdx] || '') +
textRight +
'\n';
}
}

return out;
}

}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/help/help.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals';
import { noop } from '@proc7ts/primitives';
import type { MockedFunction, SpiedFunction } from 'jest-mock';
import { simpleZOptionsParser } from '../simple-options-parser.js';
import { helpZOptionReader } from './help-option-reader.js';

describe('helpZOptionReader', () => {
let logSpy: SpiedFunction<(...args: unknown[]) => void>;
let logSpy: jest.SpiedFunction<(...args: unknown[]) => void>;

beforeEach(() => {
logSpy = jest.spyOn(console, 'log');
Expand Down Expand Up @@ -58,7 +57,7 @@ describe('helpZOptionReader', () => {
expect(logSpy).not.toHaveBeenCalledWith(expect.stringContaining('TEST DESCRIPTION'));
});
it('displays help with the given method', async () => {
const display: MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);
const display: jest.MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);
const parser = simpleZOptionsParser({
options: {
'--test': noop,
Expand All @@ -80,7 +79,7 @@ describe('helpZOptionReader', () => {
expect(logSpy).not.toHaveBeenCalled();
});
it('compares options by group first', async () => {
const display: MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);
const display: jest.MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);
const parser = simpleZOptionsParser({
options: {
'--test': {
Expand Down Expand Up @@ -115,7 +114,7 @@ describe('helpZOptionReader', () => {
);
});
it('compares options by group and key', async () => {
const display: MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);
const display: jest.MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);
const parser = simpleZOptionsParser({
options: {
'--test': {
Expand Down Expand Up @@ -153,7 +152,7 @@ describe('helpZOptionReader', () => {
);
});
it('compares options by custom method', async () => {
const display: MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);
const display: jest.MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);
const parser = simpleZOptionsParser({
options: {
'--test-option': noop,
Expand Down
2 changes: 0 additions & 2 deletions src/option-base.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { ZOption } from './option.js';
* @internal
*/
export class ZOptionBase<TOption extends ZOption> implements ZOption {

readonly #impl: ZOptionImpl<TOption>;

constructor(impl: ZOptionImpl<TOption>) {
Expand Down Expand Up @@ -71,5 +70,4 @@ export class ZOptionBase<TOption extends ZOption> implements ZOption {
optionMeta(key: string): ZOptionMeta.Combined {
return this.#impl.optionsMeta().get(key) || { usage: [] };
}

}
2 changes: 0 additions & 2 deletions src/option-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ZOptionLocation } from './option-location.js';
* option.
*/
export class ZOptionError extends Error {

readonly #optionLocation: Required<ZOptionLocation>;

/**
Expand All @@ -26,5 +25,4 @@ export class ZOptionError extends Error {
get optionLocation(): Required<ZOptionLocation> {
return this.#optionLocation;
}

}
10 changes: 5 additions & 5 deletions src/option-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ export const ZOptionInput = {
} = second;

return (
name1 === name2
&& key1 === key2
&& retry1 === retry2
&& arraysAreEqual(values1, values2)
&& arraysAreEqual(tail1, tail2)
name1 === name2 &&
key1 === key2 &&
retry1 === retry2 &&
arraysAreEqual(values1, values2) &&
arraysAreEqual(tail1, tail2)
);
},
};
6 changes: 2 additions & 4 deletions src/option.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { ZOption } from './option.js';
* @internal
*/
export class ZOptionImpl<TOption extends ZOption> {

#args: readonly string[];
readonly #head: readonly string[];
#name!: string;
Expand Down Expand Up @@ -133,8 +132,8 @@ export class ZOptionImpl<TOption extends ZOption> {
max != null
? fromIndex + (rest ? max : Math.min(max, this.#values.length))
: rest
? this.#args.length
: fromIndex + this.#values.length;
? this.#args.length
: fromIndex + this.#values.length;
const result = this.args.slice(fromIndex, toIndex);

this.#recognize(fromIndex + result.length);
Expand Down Expand Up @@ -191,5 +190,4 @@ export class ZOptionImpl<TOption extends ZOption> {
args: this.args,
});
}

}
4 changes: 1 addition & 3 deletions src/options-parser.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type { SupportedZOptions } from './supported-options.js';
* @typeParam TOption A type of option representation.
*/
export class ZOptionsParser$<TOption extends ZOption, TCtx> {

readonly #config: ZOptionsParser.Config<TOption, TCtx>;
#syntax?: ZOptionSyntax | undefined;
#optionClass?: ZOption.ImplClass<TOption, TCtx, [ZOptionImpl<TOption>]> | undefined;
Expand Down Expand Up @@ -89,7 +88,7 @@ export class ZOptionsParser$<TOption extends ZOption, TCtx> {
const optionClass = this.optionClass;
const syntax = this.syntax;

for (let argIndex = Math.max(0, fromIndex); argIndex < args.length;) {
for (let argIndex = Math.max(0, fromIndex); argIndex < args.length; ) {
const impl = new ZOptionImpl<TOption>(optionMeta, args, argIndex);
const option = new optionClass(context, impl);

Expand Down Expand Up @@ -123,7 +122,6 @@ export class ZOptionsParser$<TOption extends ZOption, TCtx> {

return context;
}

}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/options-parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
import { asis, noop, valueProvider } from '@proc7ts/primitives';
import type { Mock } from 'jest-mock';
import { ZOptionError } from './option-error.js';
import type { ZOptionLocation } from './option-location.js';
import type { ZOptionReader } from './option-reader.js';
Expand Down Expand Up @@ -538,7 +537,8 @@ describe('ZOptionsParser', () => {
},
],
syntax: [
([name]) => name === '--test'
([name]) =>
name === '--test'
? [{ name: '--replaced', values: ['r'], tail: ['t'], retry: true }]
: [],
ZOptionSyntax.longOptions,
Expand Down Expand Up @@ -575,13 +575,13 @@ describe('ZOptionsParser', () => {
});

describe('fallback reader', () => {
let readShort: Mock<ZOptionReader.Fn>;
let readShort: jest.Mock<ZOptionReader.Fn>;
let defaultShort: string | undefined;

let readLong: Mock<ZOptionReader.Fn>;
let readLong: jest.Mock<ZOptionReader.Fn>;
let defaultLong: string | undefined;

let readPositional: Mock<ZOptionReader.Fn>;
let readPositional: jest.Mock<ZOptionReader.Fn>;
let defaultPositional: string | undefined;

let fallbackKey: string | undefined;
Expand Down
4 changes: 1 addition & 3 deletions src/simple-options-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export function simpleZOptionsParser(
base: ZOption.BaseClass<TArgs>,
): ZOption.ImplClass<ZOption, Record<string, string[]>, TArgs> {
class SimpleZOption extends base {

constructor(recognized: Record<string, string[]>, ...args: TArgs) {
super(...args);
this.whenRecognized(option => {
Expand All @@ -96,8 +95,7 @@ export function simpleZOptionsParser(
}
});
}

}
}

return SimpleZOption;
},
Expand Down

0 comments on commit 6d3622a

Please sign in to comment.