Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenyong committed Sep 23, 2024
1 parent ce355d2 commit edd53f8
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/oas-normalize/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export default class OASNormalize {
* is valid or not we need to clone it before passing it over to `openapi-parser` so as to
* not run into pass-by-reference problems.
*/
// eslint-disable-next-line try-catch-failsafe/json-parse
const clonedSchema = JSON.parse(JSON.stringify(schema));

return openapiParser
Expand Down
1 change: 1 addition & 0 deletions packages/oas-normalize/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function stringToJSON(string: Record<string, unknown> | string): Record<s
if (typeof string === 'object') {
return string;
} else if (string.match(/^\s*{/)) {
// eslint-disable-next-line try-catch-failsafe/json-parse
return JSON.parse(string);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/oas-to-har/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ export default function oasToHar(

if (operation.isFormUrlEncoded()) {
if (Object.keys(formData.formData || {}).length) {
// eslint-disable-next-line try-catch-failsafe/json-parse
const cleanFormData = removeUndefinedObjects(JSON.parse(JSON.stringify(formData.formData)));
if (cleanFormData !== undefined) {
const postData: PostData = { params: [], mimeType: 'application/x-www-form-urlencoded' };
Expand Down Expand Up @@ -543,6 +544,7 @@ export default function oasToHar(
jsonTypes.forEach((prop: boolean | string) => {
try {
set(cleanBody, String(prop), JSON.parse(get(cleanBody, String(prop))));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
// leave the prop as a string value
}
Expand All @@ -555,6 +557,7 @@ export default function oasToHar(
}

har.postData.text = JSON.stringify(cleanBody);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
har.postData.text = stringify(formData.body);
}
Expand All @@ -563,6 +566,7 @@ export default function oasToHar(
}
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
// If anything above fails for whatever reason, assume that whatever we had is invalid
// JSON and just treat it as raw text.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const isRfc3986Unreserved = (char: string) => /^[a-z0-9\-._~]+$/i.test(char);
function isURIEncoded(value: string) {
try {
return decodeURIComponent(value) !== value;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// `decodeURIComponent` will throw an exception if a string that has an un-encoded percent sign
// in it (like 20%), o if it's throwing we can just assume that the value hasn't been encoded.
Expand Down Expand Up @@ -59,6 +60,7 @@ export function encodeDisallowedCharacters(
}

if (parse) {
// eslint-disable-next-line try-catch-failsafe/json-parse
return JSON.parse(str);
}

Expand Down
1 change: 1 addition & 0 deletions packages/oas-to-har/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export function getTypedFormatsInSchema(
})
.flat()
.filter(Boolean);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// If this fails for whatever reason then we should act as if we didn't find any `format`'d
// schemas.
Expand Down
1 change: 1 addition & 0 deletions packages/oas-to-snippet/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default function oasToSnippet(

try {
({ config, language, target } = getLanguageConfig(languages, lang));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
if (!language || !target) {
return { code: '', highlightMode: false, install: false };
Expand Down
1 change: 1 addition & 0 deletions packages/oas-to-snippet/src/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export function getSupportedLanguages(
plugins?: ClientPlugin<any>[];
} = { plugins: [] },
) {
// eslint-disable-next-line try-catch-failsafe/json-parse
const languages: SupportedLanguages = JSON.parse(JSON.stringify(DEFAULT_LANGUAGES));

Object.entries(targets).forEach(([target, { clientsById }]) => {
Expand Down
1 change: 1 addition & 0 deletions packages/oas/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-use-before-define": ["error", { "classes": false }],
"@typescript-eslint/no-unused-vars": "error",

"camelcase": "off",

Expand Down
1 change: 1 addition & 0 deletions packages/oas/src/analyzer/queries/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function callbacks(definition: OASDocument) {
export async function circularRefs(definition: OASDocument) {
// Dereferencing will update the passed in variable, which we don't want to do, so we
// instantiated `Oas` with a clone.
// eslint-disable-next-line try-catch-failsafe/json-parse
const oas = new Oas(JSON.parse(JSON.stringify(definition)));
await oas.dereference();

Expand Down
4 changes: 4 additions & 0 deletions packages/oas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function normalizedUrl(api: RMOAS.OASDocument, selected: number) {
urlWithOrigin.pathname = url;
url = urlWithOrigin.href;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
url = exampleDotCom;
}
Expand Down Expand Up @@ -167,6 +168,7 @@ function generatePathMatches(paths: RMOAS.PathsObject, pathName: string, origin:
try {
const matchStatement = match(cleanedPath, { decode: decodeURIComponent });
matchResult = matchStatement(prunedPathName);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// If path matching fails for whatever reason (maybe they have a malformed path parameter)
// then we shouldn't also fail.
Expand Down Expand Up @@ -281,6 +283,7 @@ export default class Oas {
*/
constructor(oas: RMOAS.OASDocument | string, user?: RMOAS.User) {
if (typeof oas === 'string') {
// eslint-disable-next-line try-catch-failsafe/json-parse
oas = JSON.parse(oas) as RMOAS.OASDocument;
}
// @todo throw an exception here instead of allowing an empty oas
Expand Down Expand Up @@ -337,6 +340,7 @@ export default class Oas {
try {
variables = this.api.servers[selected].variables;
if (!variables) throw new Error('no variables');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
variables = {};
}
Expand Down
1 change: 1 addition & 0 deletions packages/oas/src/lib/clone-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export default function cloneObject<T>(obj: T): T {
return undefined;
}

// eslint-disable-next-line try-catch-failsafe/json-parse
return JSON.parse(JSON.stringify(obj));
}
3 changes: 3 additions & 0 deletions packages/oas/src/lib/openapi-to-json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ function searchForValueByPropAndPointer(

try {
foundValue = jsonpointer.get(schema, pointers[i]);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// If the schema we're looking at is `{obj: null}` and our pointer is `/obj/propertyName`
// `jsonpointer` will throw an error. If that happens, we should silently catch and toss it
Expand Down Expand Up @@ -329,6 +330,7 @@ export function toJSONSchema(data: RMOAS.SchemaObject | boolean, opts: toJSONSch
defaultResolver: mergeJSONSchemaAllOf.options.resolvers.title,
} as unknown,
}) as RMOAS.SchemaObject;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
// If we can't merge the `allOf` for whatever reason (like if one item is a `string` and
// the other is a `object`) then we should completely remove it from the schema and continue
Expand Down Expand Up @@ -780,6 +782,7 @@ export function toJSONSchema(data: RMOAS.SchemaObject | boolean, opts: toJSONSch
if (userJwtDefault) {
schema.default = userJwtDefault;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// If jsonpointer returns an error, we won't show any defaults for that path.
}
Expand Down
6 changes: 4 additions & 2 deletions packages/oas/src/operation/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Extensions } from '../extensions.js';
import type { SecurityType } from '../types.js';
import type { CallbackExamples } from './lib/get-callback-examples.js';
import type { getParametersAsJSONSchemaOptions } from './lib/get-parameters-as-json-schema.js';
import type { RequestBodyExamples } from './lib/get-requestbody-examples.js';
import type { ResponseExamples } from './lib/get-response-examples.js';
import type { Extensions } from '../extensions.js';
import type { SecurityType } from '../types.js';
import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';

import findSchemaDefinition from '../lib/find-schema-definition.js';
Expand Down Expand Up @@ -194,6 +194,7 @@ export class Operation {
let keys;
try {
keys = Object.keys(requirement);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return false;
}
Expand All @@ -203,6 +204,7 @@ export class Operation {
try {
// Remove the reference type, because we know this will be dereferenced
security = this.api.components.securitySchemes[key] as RMOAS.KeyedSecuritySchemeObject;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions packages/oas/src/operation/lib/get-mediatype-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function getMediaTypeExamples(
if (!matchesMimeType.xml(mediaType)) {
return [
{
// eslint-disable-next-line try-catch-failsafe/json-parse
value: sampleFromSchema(JSON.parse(JSON.stringify(mediaTypeObject.schema)), opts),
},
];
Expand Down
1 change: 1 addition & 0 deletions packages/oas/src/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default function reducer(definition: OASDocument, opts: ReducerOptions =
}

// Stringify and parse so we get a full non-reference clone of the API definition to work with.
// eslint-disable-next-line try-catch-failsafe/json-parse
const reduced = JSON.parse(JSON.stringify(definition)) as OASDocument;

// Retain any root-level security definitions.
Expand Down
1 change: 1 addition & 0 deletions packages/oas/src/samples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function sampleFromSchema(
}),
opts,
);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/oas/src/samples/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function normalizeArray(arr: (number | string)[] | number | string) {
return [arr];
}

// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export function isFunc(thing: unknown): thing is Function {
return typeof thing === 'function';
}
Expand Down
1 change: 1 addition & 0 deletions packages/postman-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export namespace PostmanV2 {
variable?: VariableListObject;
}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface ProtocolProfileBehaviorObject {}

export interface ProxyConfigObject {
Expand Down

0 comments on commit edd53f8

Please sign in to comment.