Skip to content

Commit

Permalink
fix(workspaces): properly setup eslint v9 (#1793)
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax authored Jan 7, 2025
1 parent 074936a commit 4d696f5
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 102 deletions.
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

24 changes: 24 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pluginJs from '@eslint/js';
import globals from 'globals';
import tseslint from 'typescript-eslint';

/** @type {import('eslint').Linter.Config[]} */
export default [
{ files: ['**/*.{js,mjs,cjs,ts}'] },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'no-prototype-builtins': 'warn',
'no-useless-escape': 'warn',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'warn',
'@typescript-eslint/no-unsafe-function-type': 'warn',
'@typescript-eslint/no-require-imports': 'warn',
'@typescript-eslint/ban-ts-comment': 'warn',
'no-case-declarations': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
},
},
];
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.17.0",
"@faker-js/faker": "^8.4.0",
"@release-it-plugins/workspaces": "^4.2.0",
"@release-it/conventional-changelog": "^8.0.1",
Expand All @@ -40,6 +42,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "^2.3.3",
"eslint-plugin-prettier": "^5.1.3",
"globals": "^15.14.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"npm-run-all": "^4.1.5",
Expand All @@ -49,6 +52,7 @@
"tsup": "^8.0.2",
"turbo": "^1.13.3",
"typescript": "^4.7.4",
"typescript-eslint": "^8.19.1",
"vitest": "^0.6.3",
"zx": "^7.2.3"
},
Expand Down
1 change: 0 additions & 1 deletion packages/angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
pascal,
sanitize,
toObjectString,
VERBS_WITH_BODY,
} from '@orval/core';

const ANGULAR_DEPENDENCIES: GeneratorDependency[] = [
Expand Down
1 change: 0 additions & 1 deletion packages/axios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
pascal,
sanitize,
toObjectString,
VERBS_WITH_BODY,
} from '@orval/core';

const AXIOS_DEPENDENCIES: GeneratorDependency[] = [
Expand Down
11 changes: 3 additions & 8 deletions packages/core/src/getters/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { camel, sanitize } from '../utils';
import { ServerObject } from 'openapi3-ts/oas31';
import { TEMPLATE_TAG_REGEX } from '../constants';
import {
BaseUrlFromConstant,
BaseUrlFromSpec,
ContextSpecs,
NormalizedOutputOptions,
} from '../types';
import { PathItemObject, ServerObject } from 'openapi3-ts/oas31';
import { BaseUrlFromConstant, BaseUrlFromSpec } from '../types';
import { camel, sanitize } from '../utils';

const TEMPLATE_TAG_IN_PATH_REGEX = /\/([\w]+)(?:\$\{)/g; // all dynamic parts of path

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function isUndefined(x: any): x is undefined {
}

export function isNull(x: any): x is null {
return typeof x === null;
return x === null;
}

export function isSchema(x: any): x is SchemaObject {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const prep = (s: string, isFill = false, isPascal = false, isUpper = false) => {
s = low.call(s);
}
if (!isFill && !regexps.hole.test(s)) {
// eslint-disable-next-line no-var
var holey = fill(s, ' ');
if (regexps.hole.test(holey)) {
s = holey;
Expand All @@ -89,7 +90,7 @@ const lower = (s: string, fillWith: string, isDeapostrophe: boolean) => {
};

// Caches the previously converted strings to improve performance
let pascalMemory: Record<string, string> = {};
const pascalMemory: Record<string, string> = {};

export const pascal = (s: string) => {
if (pascalMemory[s]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Object.entries(basepath).forEach(([propName, propValue]) => {
}
});

let { join, resolve, extname, dirname, basename, isAbsolute } = path;
const { join, resolve, extname, dirname, basename, isAbsolute } = path;
export { join, resolve, extname, dirname, basename, isAbsolute };

/**
Expand Down
30 changes: 14 additions & 16 deletions packages/hono/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import {
ClientFooterBuilder,
ClientGeneratorsBuilder,
ClientHeaderBuilder,
ContextSpecs,
generateMutatorImports,
GeneratorDependency,
GeneratorImport,
GeneratorMutator,
GeneratorOptions,
GeneratorVerbOptions,
getFileInfo,
pascal,
upath,
kebab,
ContextSpecs,
NormalizedOutputOptions,
GeneratorImport,
getOrvalGeneratedTypes,
jsDoc,
generateMutatorImports,
GeneratorMutator,
kebab,
NormalizedMutator,
NormalizedOutputOptions,
pascal,
upath,
} from '@orval/core';
import { getRoute } from './route';
import fs from 'fs-extra';
import { generateZod } from '@orval/zod';
import fs from 'fs-extra';
import { InfoObject } from 'openapi3-ts/oas30';
import { getRoute } from './route';

const HONO_DEPENDENCIES: GeneratorDependency[] = [
{
Expand Down Expand Up @@ -164,7 +164,7 @@ const getZvalidatorImports = (
verbOption: GeneratorVerbOptions,
isHonoValidator: boolean,
) => {
let imports = [];
const imports = [];

if (verbOption.headers) {
imports.push(`${verbOption.operationName}Header`);
Expand Down Expand Up @@ -561,7 +561,7 @@ const generateContext = async (

const imps = verbs
.flatMap((verb) => {
let imports: GeneratorImport[] = [];
const imports: GeneratorImport[] = [];
if (verb.params.length) {
imports.push(...verb.params.map((param) => param.imports).flat());
}
Expand Down Expand Up @@ -614,7 +614,7 @@ const generateContext = async (

const imps = Object.values(verbOptions)
.flatMap((verb) => {
let imports: GeneratorImport[] = [];
const imports: GeneratorImport[] = [];
if (verb.params.length) {
imports.push(...verb.params.map((param) => param.imports).flat());
}
Expand Down Expand Up @@ -661,9 +661,7 @@ const generateZodFiles = async (
output: NormalizedOutputOptions,
context: ContextSpecs,
) => {
const { pathWithoutExtension, extension, dirname, filename } = getFileInfo(
output.target,
);
const { extension, dirname, filename } = getFileInfo(output.target);

const header = getHeader(
output.override.header,
Expand Down
8 changes: 4 additions & 4 deletions packages/mock/src/faker/getters/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export const combineSchemasMock = ({
existingReferencedProperties: string[];
splitMockImplementations: string[];
}): MockDefinition => {
let combineImports: GeneratorImport[] = [];
let includedProperties: string[] = (combine?.includedProperties ?? []).slice(
0,
);
const combineImports: GeneratorImport[] = [];
const includedProperties: string[] = (
combine?.includedProperties ?? []
).slice(0);

const isRefAndNotExisting =
isReference(item) && !existingReferencedProperties.includes(item.name);
Expand Down
8 changes: 4 additions & 4 deletions packages/mock/src/faker/getters/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
PropertySortOrder,
} from '@orval/core';
import { ReferenceObject, SchemaObject } from 'openapi3-ts/oas30';
import { resolveMockValue } from '../resolvers/value';
import { MockDefinition, MockSchemaObject } from '../../types';
import { combineSchemasMock } from './combine';
import { DEFAULT_OBJECT_KEY_MOCK } from '../constants';
import { resolveMockValue } from '../resolvers/value';
import { combineSchemasMock } from './combine';

export const overrideVarName = 'overrideResponse';

Expand Down Expand Up @@ -103,8 +103,8 @@ export const getMockObject = ({
combine?.separator === 'anyOf'
? '{'
: '';
let imports: GeneratorImport[] = [];
let includedProperties: string[] = [];
const imports: GeneratorImport[] = [];
const includedProperties: string[] = [];

const entries = Object.entries(item.properties);
if (context.output.propertySortOrder === PropertySortOrder.ALPHABETICAL) {
Expand Down
6 changes: 3 additions & 3 deletions packages/orval/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import {
OutputClientFunc,
pascal,
} from '@orval/core';
import fetchClient from '@orval/fetch';
import hono from '@orval/hono';
import * as mock from '@orval/mock';
import query from '@orval/query';
import swr from '@orval/swr';
import zod from '@orval/zod';
import hono from '@orval/hono';
import fetchClient from '@orval/fetch';

const DEFAULT_CLIENT = OutputClient.AXIOS;

Expand Down Expand Up @@ -159,7 +159,7 @@ export const generateClientFooter: GeneratorClientFooter = ({
hasAwaitedType,
});
}
} catch (e) {
} catch {
implementation = footer({
operationNames,
title: titles.implementation,
Expand Down
3 changes: 2 additions & 1 deletion packages/orval/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const normalizeOptions = async (
if (typeof mock === 'boolean' && mock) {
mock = DEFAULT_MOCK_OPTIONS;
} else if (isFunction(mock)) {
// do nothing
} else if (!mock) {
mock = undefined;
} else {
Expand Down Expand Up @@ -347,7 +348,7 @@ const parserDefaultOptions = {
resolve: { github: githubResolver },
} as SwaggerParserOptions;

const normalizeMutator = <T>(
const normalizeMutator = (
workspace: string,
mutator?: Mutator,
): NormalizedMutator | undefined => {
Expand Down
8 changes: 4 additions & 4 deletions packages/orval/src/write-specs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
createSuccessMessage,
getFileInfo,
getMockFileExtensionByTypeName,
isRootKey,
jsDoc,
log,
Expand All @@ -13,14 +14,13 @@ import {
writeSplitMode,
writeSplitTagsMode,
writeTagsMode,
getMockFileExtensionByTypeName,
} from '@orval/core';
import chalk from 'chalk';
import execa from 'execa';
import fs from 'fs-extra';
import { Application, TypeDocOptions } from 'typedoc';
import uniq from 'lodash.uniq';
import { InfoObject } from 'openapi3-ts/oas30';
import { Application, TypeDocOptions } from 'typedoc';
import { executeHook } from './utils';

const getHeader = (
Expand Down Expand Up @@ -104,7 +104,7 @@ export const writeSpecs = async (

if (output.workspace) {
const workspacePath = output.workspace;
let imports = implementationPaths
const imports = implementationPaths
.filter(
(path) =>
!output.mock ||
Expand Down Expand Up @@ -177,7 +177,7 @@ export const writeSpecs = async (
if (output.prettier) {
try {
await execa('prettier', ['--write', ...paths]);
} catch (e) {
} catch {
log(
chalk.yellow(
`⚠️ ${projectTitle ? `${projectTitle} - ` : ''}Prettier not found`,
Expand Down
12 changes: 6 additions & 6 deletions packages/query/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export const generateAxiosRequestFunction = (
isVue,
});

let bodyDefinition = body.definition.replace('[]', '\\[\\]');
let propsImplementation =
const bodyDefinition = body.definition.replace('[]', '\\[\\]');
const propsImplementation =
mutator?.bodyTypeName && body.definition
? toObjectString(props, 'implementation').replace(
new RegExp(`(\\w*):\\s?${bodyDefinition}`),
Expand Down Expand Up @@ -357,10 +357,10 @@ const {mutation: mutationOptions${
: mutator?.hasSecondArg
? ', request: requestOptions'
: ''
}} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
}} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }${mutator?.hasSecondArg ? ', request: undefined' : ''}${!mutator ? (httpClient === OutputHttpClient.AXIOS ? ', axios: undefined' : ', fetch: undefined') : ''}};`
: '';
};
Expand Down
Loading

0 comments on commit 4d696f5

Please sign in to comment.