Skip to content

Commit

Permalink
feat(esm): flipping on our ESM ESLint config in all packages (#814)
Browse files Browse the repository at this point in the history
* feat: enabling our esm eslint config on `oas`

* feat: enabling our esm eslint config on `oas-extensions`

* feat: enabling our esm eslint config on `oas-normalize`

* fix: cleaning up the oas-to-har eslint config
  • Loading branch information
erunion authored Oct 6, 2023
1 parent b7df260 commit 6795d42
Show file tree
Hide file tree
Showing 56 changed files with 149 additions and 142 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["@readme/eslint-config", "@readme/eslint-config/typescript", "@readme/eslint-config/esm"],
"root": true
}
2 changes: 0 additions & 2 deletions packages/oas-extensions/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": ["@readme/eslint-config", "@readme/eslint-config/typescript"],
"root": true,
"rules": {
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/explicit-module-boundary-types": "off"
Expand Down
2 changes: 1 addition & 1 deletion packages/oas-extensions/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import petstore from '@readme/oas-examples/3.0/json/petstore.json';
import Oas from 'oas';
import { describe, beforeEach, it, expect } from 'vitest';

import * as extensions from '../src';
import * as extensions from '../src/index.js';

describe('oas-extensions', () => {
it.each([
Expand Down
2 changes: 1 addition & 1 deletion packages/oas-extensions/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Options } from 'tsup';
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from 'tsup';

import config from '../../tsup.config';
import config from '../../tsup.config.js';

export default defineConfig((options: Options) => ({
...options,
Expand Down
6 changes: 1 addition & 5 deletions packages/oas-normalize/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"extends": ["@readme/eslint-config", "@readme/eslint-config/typescript"],
"root": true,
"rules": {
"@typescript-eslint/no-explicit-any": "off",

"camelcase": ["error", { "allow": ["OpenAPIV3_1"] }],

"no-case-declarations": "off",

"unicorn/prefer-node-protocol": "error"
"no-case-declarations": "off"
}
}
4 changes: 2 additions & 2 deletions packages/oas-normalize/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Options } from './lib/types';
import type { Options } from './lib/types.js';
import type { OpenAPI } from 'openapi-types';

import fs from 'node:fs';
Expand All @@ -7,7 +7,7 @@ import openapiParser from '@readme/openapi-parser';
import postmanToOpenAPI from '@readme/postman-to-openapi';
import converter from 'swagger2openapi';

import * as utils from './lib/utils';
import * as utils from './lib/utils.js';

export default class OASNormalize {
cache: {
Expand Down
5 changes: 3 additions & 2 deletions packages/oas-normalize/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/prefer-module -- We use `require.resolve` for reading YAML fixtures. */
import type { OpenAPIV3 } from 'openapi-types';

import fs from 'node:fs';
Expand All @@ -6,8 +7,8 @@ import path from 'node:path';
import fetchMock from 'fetch-mock';
import { describe, afterEach, beforeAll, beforeEach, it, expect } from 'vitest';

import OASNormalize from '../src';
import { getAPIDefinitionType, isAPIDefinition, isOpenAPI, isPostman, isSwagger } from '../src/lib/utils';
import OASNormalize from '../src/index.js';
import { getAPIDefinitionType, isAPIDefinition, isOpenAPI, isPostman, isSwagger } from '../src/lib/utils.js';

function cloneObject(obj) {
return JSON.parse(JSON.stringify(obj));
Expand Down
2 changes: 1 addition & 1 deletion packages/oas-normalize/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Options } from 'tsup';
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from 'tsup';

import config from '../../tsup.config';
import config from '../../tsup.config.js';

export default defineConfig((options: Options) => ({
...options,
Expand Down
2 changes: 0 additions & 2 deletions packages/oas-to-har/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": ["@readme/eslint-config", "@readme/eslint-config/typescript", "@readme/eslint-config/esm"],
"root": true,
"rules": {
// `any` types are fine because we're dealing with a lot of unknown data.
"@typescript-eslint/no-explicit-any": "off",
Expand Down
14 changes: 12 additions & 2 deletions packages/oas/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
{
"extends": ["@readme/eslint-config", "@readme/eslint-config/typescript"],
"root": true,
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-use-before-define": ["error", { "classes": false }],

"camelcase": "off",

"max-classes-per-file": "off",

"node/no-extraneous-import": [
"error",
{
"allowModules": [
// When we use this module we only load TS types which come from our `@types/json-schema`
// dependency.
"json-schema"
]
}
],

"no-param-reassign": "off",

"no-underscore-dangle": [
Expand Down
6 changes: 3 additions & 3 deletions packages/oas/src/analyzer/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { OASDocument } from '../rmoas.types';
import type { OASDocument } from '../rmoas.types.js';

import * as OPENAPI_QUERIES from './queries/openapi';
import * as README_QUERIES from './queries/readme';
import * as OPENAPI_QUERIES from './queries/openapi.js';
import * as README_QUERIES from './queries/readme.js';

export interface OASAnalysisFeature {
locations: string[];
Expand Down
6 changes: 3 additions & 3 deletions packages/oas/src/analyzer/queries/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { OASDocument } from '../../rmoas.types';
import type { OASDocument } from '../../rmoas.types.js';

import Oas from '../..';
import { query, refizePointer } from '../util';
import Oas from '../../index.js';
import { query, refizePointer } from '../util.js';

/**
* Determine if a given API definition uses the `additionalProperties` schema property.
Expand Down
4 changes: 2 additions & 2 deletions packages/oas/src/analyzer/queries/readme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { OASDocument } from '../../rmoas.types';
import type { OASDocument } from '../../rmoas.types.js';

import { query, refizePointer } from '../util';
import { query, refizePointer } from '../util.js';

/**
* Determine if a given API definition is using our `x-default` extension for defining auth
Expand Down
12 changes: 6 additions & 6 deletions packages/oas/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type * as RMOAS from './rmoas.types';
import type * as RMOAS from './rmoas.types.js';
import type { OpenAPIV3_1 } from 'openapi-types';
import type { MatchResult } from 'path-to-regexp';

import $RefParser from '@readme/json-schema-ref-parser';
import { pathToRegexp, match } from 'path-to-regexp';

import getAuth from './lib/get-auth';
import getUserVariable from './lib/get-user-variable';
import { isPrimitive } from './lib/helpers';
import Operation, { Webhook } from './operation';
import utils from './utils';
import getAuth from './lib/get-auth.js';
import getUserVariable from './lib/get-user-variable.js';
import { isPrimitive } from './lib/helpers.js';
import Operation, { Webhook } from './operation.js';
import utils from './utils.js';

interface PathMatch {
match?: MatchResult;
Expand Down
2 changes: 1 addition & 1 deletion packages/oas/src/lib/dedupe-common-parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as RMOAS from '../rmoas.types';
import * as RMOAS from '../rmoas.types.js';

/**
* With an array of common parameters filter down them to what isn't already present in a list of
Expand Down
2 changes: 1 addition & 1 deletion packages/oas/src/lib/get-auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as RMOAS from '../rmoas.types';
import type * as RMOAS from '../rmoas.types.js';
import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';

type authKey = null | unknown | { password: string | number; user: string | number };
Expand Down
6 changes: 3 additions & 3 deletions packages/oas/src/lib/get-mediatype-examples.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type * as RMOAS from '../rmoas.types';
import type * as RMOAS from '../rmoas.types.js';

import sampleFromSchema from '../samples';
import sampleFromSchema from '../samples/index.js';

import matchesMimeType from './matches-mimetype';
import matchesMimeType from './matches-mimetype.js';

export interface MediaTypeExample {
description?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/oas/src/lib/get-user-variable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as RMOAS from '../rmoas.types';
import type * as RMOAS from '../rmoas.types.js';

/**
* Retrieve a user variable off of a given user.
Expand Down
2 changes: 1 addition & 1 deletion packages/oas/src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SchemaObject } from '../rmoas.types';
import type { SchemaObject } from '../rmoas.types.js';

export function hasSchemaType(schema: SchemaObject, discriminator: 'array' | 'object') {
if (Array.isArray(schema.type)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/oas/src/lib/openapi-to-json-schema.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable no-continue */
import type { SchemaObject } from '../rmoas.types';
import type { SchemaObject } from '../rmoas.types.js';
import type { JSONSchema7TypeName } from 'json-schema';
import type { OpenAPIV3_1 } from 'openapi-types';

import mergeJSONSchemaAllOf from 'json-schema-merge-allof';
import jsonpointer from 'jsonpointer';
import removeUndefinedObjects from 'remove-undefined-objects';

import * as RMOAS from '../rmoas.types';
import * as RMOAS from '../rmoas.types.js';

import { hasSchemaType, isObject, isPrimitive } from './helpers';
import { hasSchemaType, isObject, isPrimitive } from './helpers.js';

/**
* This list has been pulled from `openapi-schema-to-json-schema` but been slightly modified to fit
Expand Down
4 changes: 2 additions & 2 deletions packages/oas/src/lib/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ComponentsObject, HttpMethods, OASDocument, TagObject } from '../rmoas.types';
import type { ComponentsObject, HttpMethods, OASDocument, TagObject } from '../rmoas.types.js';

import jsonPointer from 'jsonpointer';
import { getAPIDefinitionType } from 'oas-normalize/lib/utils';

import { query } from '../analyzer/util';
import { query } from '../analyzer/util.js';

export interface ReducerOptions {
/** A key-value object of path + method combinations to reduce by. */
Expand Down
28 changes: 14 additions & 14 deletions packages/oas/src/operation.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import type { CallbackExamples } from './operation/get-callback-examples';
import type { getParametersAsJSONSchemaOptions } from './operation/get-parameters-as-json-schema';
import type { RequestBodyExamples } from './operation/get-requestbody-examples';
import type { ResponseExamples } from './operation/get-response-examples';
import type { CallbackExamples } from './operation/get-callback-examples.js';
import type { getParametersAsJSONSchemaOptions } from './operation/get-parameters-as-json-schema.js';
import type { RequestBodyExamples } from './operation/get-requestbody-examples.js';
import type { ResponseExamples } from './operation/get-response-examples.js';
import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';

import dedupeCommonParameters from './lib/dedupe-common-parameters';
import findSchemaDefinition from './lib/find-schema-definition';
import matchesMimeType from './lib/matches-mimetype';
import getCallbackExamples from './operation/get-callback-examples';
import getParametersAsJSONSchema from './operation/get-parameters-as-json-schema';
import getRequestBodyExamples from './operation/get-requestbody-examples';
import getResponseAsJSONSchema from './operation/get-response-as-json-schema';
import getResponseExamples from './operation/get-response-examples';
import * as RMOAS from './rmoas.types';
import utils from './utils';
import dedupeCommonParameters from './lib/dedupe-common-parameters.js';
import findSchemaDefinition from './lib/find-schema-definition.js';
import matchesMimeType from './lib/matches-mimetype.js';
import getCallbackExamples from './operation/get-callback-examples.js';
import getParametersAsJSONSchema from './operation/get-parameters-as-json-schema.js';
import getRequestBodyExamples from './operation/get-requestbody-examples.js';
import getResponseAsJSONSchema from './operation/get-response-as-json-schema.js';
import getResponseExamples from './operation/get-response-examples.js';
import * as RMOAS from './rmoas.types.js';
import utils from './utils.js';

type SecurityType = 'Basic' | 'Bearer' | 'Query' | 'Header' | 'Cookie' | 'OAuth2' | 'http' | 'apiKey';

Expand Down
4 changes: 2 additions & 2 deletions packages/oas/src/operation/get-callback-examples.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as RMOAS from '../rmoas.types';
import type * as RMOAS from '../rmoas.types.js';

import getResponseExamples from './get-response-examples';
import getResponseExamples from './get-response-examples.js';

export type CallbackExamples = {
example: unknown;
Expand Down
14 changes: 7 additions & 7 deletions packages/oas/src/operation/get-parameters-as-json-schema.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { toJSONSchemaOptions } from '../lib/openapi-to-json-schema';
import type Operation from '../operation';
import type { ComponentsObject, ExampleObject, OASDocument, ParameterObject, SchemaObject } from '../rmoas.types';
import type { toJSONSchemaOptions } from '../lib/openapi-to-json-schema.js';
import type Operation from '../operation.js';
import type { ComponentsObject, ExampleObject, OASDocument, ParameterObject, SchemaObject } from '../rmoas.types.js';
import type { OpenAPIV3_1 } from 'openapi-types';

import cloneObject from '../lib/clone-object';
import { isPrimitive } from '../lib/helpers';
import matchesMimetype from '../lib/matches-mimetype';
import toJSONSchema, { getSchemaVersionString } from '../lib/openapi-to-json-schema';
import cloneObject from '../lib/clone-object.js';
import { isPrimitive } from '../lib/helpers.js';
import matchesMimetype from '../lib/matches-mimetype.js';
import toJSONSchema, { getSchemaVersionString } from '../lib/openapi-to-json-schema.js';

export interface SchemaWrapper {
$schema?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/oas/src/operation/get-requestbody-examples.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as RMOAS from '../rmoas.types';
import type * as RMOAS from '../rmoas.types.js';

import getMediaTypeExamples from '../lib/get-mediatype-examples';
import getMediaTypeExamples from '../lib/get-mediatype-examples.js';

export type RequestBodyExamples = {
examples: any;
Expand Down
12 changes: 6 additions & 6 deletions packages/oas/src/operation/get-response-as-json-schema.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type Operation from '../operation';
import type Operation from '../operation.js';
import type {
ComponentsObject,
MediaTypeObject,
OASDocument,
ResponseObject,
SchemaObject,
HeaderObject,
} from '../rmoas.types';
} from '../rmoas.types.js';

import cloneObject from '../lib/clone-object';
import { isPrimitive } from '../lib/helpers';
import matches from '../lib/matches-mimetype';
import toJSONSchema, { getSchemaVersionString } from '../lib/openapi-to-json-schema';
import cloneObject from '../lib/clone-object.js';
import { isPrimitive } from '../lib/helpers.js';
import matches from '../lib/matches-mimetype.js';
import toJSONSchema, { getSchemaVersionString } from '../lib/openapi-to-json-schema.js';

const isJSON = matches.json;

Expand Down
8 changes: 4 additions & 4 deletions packages/oas/src/operation/get-response-examples.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { MediaTypeExample } from '../lib/get-mediatype-examples';
import type * as RMOAS from '../rmoas.types';
import type { MediaTypeExample } from '../lib/get-mediatype-examples.js';
import type * as RMOAS from '../rmoas.types.js';

import getMediaTypeExamples from '../lib/get-mediatype-examples';
import { isRef } from '../rmoas.types';
import getMediaTypeExamples from '../lib/get-mediatype-examples.js';
import { isRef } from '../rmoas.types.js';

export type ResponseExamples = {
mediaTypes: Record<string, MediaTypeExample[]>;
Expand Down
4 changes: 2 additions & 2 deletions packages/oas/src/samples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* @license Apache-2.0
* @see {@link https://github.com/swagger-api/swagger-ui/blob/master/src/core/plugins/samples/fn.js}
*/
import type * as RMOAS from '../rmoas.types';
import type * as RMOAS from '../rmoas.types.js';

import mergeJSONSchemaAllOf from 'json-schema-merge-allof';
import memoize from 'memoizee';

import { objectify, usesPolymorphism, isFunc, normalizeArray, deeplyStripKey } from './utils';
import { objectify, usesPolymorphism, isFunc, normalizeArray, deeplyStripKey } from './utils.js';

const sampleDefaults = (genericSample: string | number | boolean) => {
return (schema: RMOAS.SchemaObject): typeof genericSample =>
Expand Down
4 changes: 2 additions & 2 deletions packages/oas/src/samples/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* @license Apache-2.0
* @see {@link https://github.com/swagger-api/swagger-ui/blob/master/src/core/utils.js}
*/
import type * as RMOAS from '../rmoas.types';
import type * as RMOAS from '../rmoas.types.js';

import { isObject } from '../lib/helpers';
import { isObject } from '../lib/helpers.js';

export function usesPolymorphism(schema: RMOAS.SchemaObject) {
if (schema.oneOf) {
Expand Down
6 changes: 3 additions & 3 deletions packages/oas/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import findSchemaDefinition from './lib/find-schema-definition';
import matchesMimeType from './lib/matches-mimetype';
import { types as jsonSchemaTypes } from './operation/get-parameters-as-json-schema';
import findSchemaDefinition from './lib/find-schema-definition.js';
import matchesMimeType from './lib/matches-mimetype.js';
import { types as jsonSchemaTypes } from './operation/get-parameters-as-json-schema.js';

const supportedMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']);

Expand Down
4 changes: 2 additions & 2 deletions packages/oas/test/__fixtures__/create-oas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as RMOAS from '../../src/rmoas.types';
import type * as RMOAS from '../../src/rmoas.types.js';

import Oas from '../../src';
import Oas from '../../src/index.js';

/**
* @param operation Operation to create a fake API definition and Oas instance for.
Expand Down
2 changes: 1 addition & 1 deletion packages/oas/test/__fixtures__/json-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SchemaObject } from '../../src/rmoas.types';
import type { SchemaObject } from '../../src/rmoas.types.js';

const SCHEMA_SCENARIOS = {
'array of primitives': (props, allowEmptyValue) => {
Expand Down
Loading

0 comments on commit 6795d42

Please sign in to comment.