Skip to content

Commit 01db1d0

Browse files
committed
lints
1 parent 57f5a77 commit 01db1d0

35 files changed

+730
-1379
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"arrowParens": "always",
44
"semi": true,
55
"tabWidth": 2,
6-
"trailingComma": "all"
6+
"trailingComma": "all",
7+
"singleQuote": false
78
}

_includes/stylesheets.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
<!-- {{ page.url }} -->
2-
<link
3-
rel="stylesheet"
4-
href="/css/style.css?v=3"
5-
media="screen"
6-
type="text/css"
7-
/>
2+
<link rel="stylesheet" href="/css/style.css?v=3" media="screen" type="text/css" />
83
<link rel="stylesheet" href="/css/print.css" media="print" type="text/css" />

eslint.config.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ export default tseslint.config({
3636
"no-undef": "off",
3737
"@typescript-eslint/no-require-imports": "off",
3838
"@typescript-eslint/no-unused-vars": "off",
39-
"linebreak-style": [
40-
"error",
41-
process.platform === "win32" ? "windows" : "unix",
42-
],
39+
"linebreak-style": ["error", process.platform === "win32" ? "windows" : "unix"],
4340
quotes: ["error", "double"],
4441
semi: ["error", "always"],
4542
"@typescript-eslint/ban-ts-comment": "off",

lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ class SwaggerParser extends $RefParser {
4444
if (schema.swagger) {
4545
if (typeof schema.swagger === "number") {
4646
// This is a very common mistake, so give a helpful error message
47-
throw new SyntaxError('Swagger version number must be a string (e.g. "2.0") not a number.');
47+
throw new SyntaxError("Swagger version number must be a string (e.g. \"2.0\") not a number.");
4848
} else if (schema.info && typeof schema.info.version === "number") {
4949
// This is a very common mistake, so give a helpful error message
50-
throw new SyntaxError('API version number must be a string (e.g. "1.0.0") not a number.');
50+
throw new SyntaxError("API version number must be a string (e.g. \"1.0.0\") not a number.");
5151
} else if (schema.swagger !== "2.0") {
5252
throw new SyntaxError(`Unrecognized Swagger version: ${schema.swagger}. Expected 2.0`);
5353
}
@@ -62,10 +62,10 @@ class SwaggerParser extends $RefParser {
6262
}
6363
} else if (typeof schema.openapi === "number") {
6464
// This is a very common mistake, so give a helpful error message
65-
throw new SyntaxError('Openapi version number must be a string (e.g. "3.0.0") not a number.');
65+
throw new SyntaxError("Openapi version number must be a string (e.g. \"3.0.0\") not a number.");
6666
} else if (schema.info && typeof schema.info.version === "number") {
6767
// This is a very common mistake, so give a helpful error message
68-
throw new SyntaxError('API version number must be a string (e.g. "1.0.0") not a number.');
68+
throw new SyntaxError("API version number must be a string (e.g. \"1.0.0\") not a number.");
6969
} else if (supportedVersions.indexOf(schema.openapi) === -1) {
7070
throw new SyntaxError(
7171
`Unsupported OpenAPI version: ${schema.openapi}. ` +

lib/options.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"use strict";
22

3-
const {
4-
getJsonSchemaRefParserDefaultOptions,
5-
} = require("@apidevtools/json-schema-ref-parser");
3+
const { getJsonSchemaRefParserDefaultOptions } = require("@apidevtools/json-schema-ref-parser");
64
const schemaValidator = require("./validators/schema");
75
const specValidator = require("./validators/spec");
86

@@ -18,9 +16,7 @@ module.exports = ParserOptions;
1816
function merge(target, source) {
1917
if (isMergeable(source)) {
2018
// prevent prototype pollution
21-
const keys = Object.keys(source).filter(
22-
(key) => !["__proto__", "constructor", "prototype"].includes(key),
23-
);
19+
const keys = Object.keys(source).filter((key) => !["__proto__", "constructor", "prototype"].includes(key));
2420
for (let i = 0; i < keys.length; i++) {
2521
const key = keys[i];
2622
const sourceSetting = source[key];
@@ -45,13 +41,7 @@ function merge(target, source) {
4541
* @returns
4642
*/
4743
function isMergeable(val) {
48-
return (
49-
val &&
50-
typeof val === "object" &&
51-
!Array.isArray(val) &&
52-
!(val instanceof RegExp) &&
53-
!(val instanceof Date)
54-
);
44+
return val && typeof val === "object" && !Array.isArray(val) && !(val instanceof RegExp) && !(val instanceof Date);
5545
}
5646

5747
/**

lib/util.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ exports.swaggerParamRegExp = /\{([^/}]+)}/g;
1414
/**
1515
* List of HTTP verbs used for OperationItem as per the Swagger specification
1616
*/
17-
const operationsList = [
18-
"get",
19-
"post",
20-
"put",
21-
"delete",
22-
"patch",
23-
"options",
24-
"head",
25-
"trace",
26-
];
17+
const operationsList = ["get", "post", "put", "delete", "patch", "options", "head", "trace"];
2718

2819
/**
2920
* This function takes in a Server object, checks if it has relative path
@@ -48,11 +39,7 @@ function fixServers(server, path) {
4839
* be at root, path or operation's level
4940
*/
5041
function fixOasRelativeServers(schema, filePath) {
51-
if (
52-
schema.openapi &&
53-
filePath &&
54-
(filePath.startsWith("http:") || filePath.startsWith("https:"))
55-
) {
42+
if (schema.openapi && filePath && (filePath.startsWith("http:") || filePath.startsWith("https:"))) {
5643
/**
5744
* From OpenAPI v3 spec for Server object's url property: "REQUIRED. A URL to the target host.
5845
* This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where
@@ -76,9 +63,7 @@ function fixOasRelativeServers(schema, filePath) {
7663
} else if (operationsList.includes(opItem)) {
7764
// servers at operation level
7865
if (pathItem[opItem].servers) {
79-
pathItem[opItem].servers.map((server) =>
80-
fixServers(server, filePath),
81-
);
66+
pathItem[opItem].servers.map((server) => fixServers(server, filePath));
8267
}
8368
}
8469
});

lib/validators/schema.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ function validateSchema(api) {
3131
const schemaDynamicRef = schema.$defs.schema;
3232
delete schemaDynamicRef.$dynamicAnchor;
3333

34-
schema.$defs.components.properties.schemas.additionalProperties =
35-
schemaDynamicRef;
36-
schema.$defs.header.dependentSchemas.schema.properties.schema =
37-
schemaDynamicRef;
34+
schema.$defs.components.properties.schemas.additionalProperties = schemaDynamicRef;
35+
schema.$defs.header.dependentSchemas.schema.properties.schema = schemaDynamicRef;
3836
schema.$defs["media-type"].properties.schema = schemaDynamicRef;
3937
schema.$defs.parameter.properties.schema = schemaDynamicRef;
4038

@@ -88,9 +86,7 @@ function formatAjvError(errors, indent) {
8886
indent = indent || " ";
8987
let message = "";
9088
for (let error of errors) {
91-
message += util.format(
92-
`${indent}#${error.instancePath.length ? error.instancePath : "/"} ${error.message}\n`,
93-
);
89+
message += util.format(`${indent}#${error.instancePath.length ? error.instancePath : "/"} ${error.message}\n`);
9490
}
9591
return message;
9692
}

lib/validators/spec.js

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@
33
const util = require("../util");
44
const swaggerMethods = require("@apidevtools/swagger-methods");
55
const primitiveTypes = ["array", "boolean", "integer", "number", "string"];
6-
const schemaTypes = [
7-
"array",
8-
"boolean",
9-
"integer",
10-
"number",
11-
"string",
12-
"object",
13-
"null",
14-
undefined,
15-
];
6+
const schemaTypes = ["array", "boolean", "integer", "number", "string", "object", "null", undefined];
167

178
module.exports = validateSpec;
189

@@ -65,9 +56,7 @@ function validatePath(api, path, pathId, operationIds) {
6556
if (operationIds.indexOf(declaredOperationId) === -1) {
6657
operationIds.push(declaredOperationId);
6758
} else {
68-
throw new SyntaxError(
69-
`Validation failed. Duplicate operation id '${declaredOperationId}'`,
70-
);
59+
throw new SyntaxError(`Validation failed. Duplicate operation id '${declaredOperationId}'`);
7160
}
7261
}
7362
validateParameters(api, path, pathId, operation, operationId);
@@ -99,20 +88,14 @@ function validateParameters(api, path, pathId, operation, operationId) {
9988
try {
10089
checkForDuplicates(pathParams);
10190
} catch (e) {
102-
throw new SyntaxError(
103-
e,
104-
`Validation failed. ${pathId} has duplicate parameters`,
105-
);
91+
throw new SyntaxError(e, `Validation failed. ${pathId} has duplicate parameters`);
10692
}
10793

10894
// Check for duplicate operation parameters
10995
try {
11096
checkForDuplicates(operationParams);
11197
} catch (e) {
112-
throw new SyntaxError(
113-
e,
114-
`Validation failed. ${operationId} has duplicate parameters`,
115-
);
98+
throw new SyntaxError(e, `Validation failed. ${operationId} has duplicate parameters`);
11699
}
117100

118101
// Combine the path and operation parameters,
@@ -203,9 +186,7 @@ function validatePathParameters(params, pathId, operationId) {
203186
}
204187

205188
if (placeholders.length > 0) {
206-
throw new SyntaxError(
207-
`Validation failed. ${operationId} is missing path parameter(s) for ${placeholders}`,
208-
);
189+
throw new SyntaxError(`Validation failed. ${operationId} is missing path parameter(s) for ${placeholders}`);
209190
}
210191
}
211192

@@ -271,9 +252,7 @@ function checkForDuplicates(params) {
271252
for (let j = i + 1; j < params.length; j++) {
272253
let inner = params[j];
273254
if (outer.name === inner.name && outer.in === inner.in) {
274-
throw new SyntaxError(
275-
`Validation failed. Found multiple ${outer.in} parameters named "${outer.name}"`,
276-
);
255+
throw new SyntaxError(`Validation failed. Found multiple ${outer.in} parameters named "${outer.name}"`);
277256
}
278257
}
279258
}
@@ -288,9 +267,7 @@ function checkForDuplicates(params) {
288267
*/
289268
function validateResponse(code, response, responseId) {
290269
if (code !== "default" && (code < 100 || code > 599)) {
291-
throw new SyntaxError(
292-
`Validation failed. ${responseId} has an invalid response code (${code})`,
293-
);
270+
throw new SyntaxError(`Validation failed. ${responseId} has an invalid response code (${code})`);
294271
}
295272

296273
let headers = Object.keys(response.headers || {});
@@ -321,15 +298,11 @@ function validateResponse(code, response, responseId) {
321298
*/
322299
function validateSchema(schema, schemaId, validTypes) {
323300
if (validTypes.indexOf(schema.type) === -1) {
324-
throw new SyntaxError(
325-
`Validation failed. ${schemaId} has an invalid type (${schema.type})`,
326-
);
301+
throw new SyntaxError(`Validation failed. ${schemaId} has an invalid type (${schema.type})`);
327302
}
328303

329304
if (schema.type === "array" && !schema.items) {
330-
throw new SyntaxError(
331-
`Validation failed. ${schemaId} is an array, so it must include an "items" schema`,
332-
);
305+
throw new SyntaxError(`Validation failed. ${schemaId} is an array, so it must include an "items" schema`);
333306
}
334307
}
335308

test/fixtures/mocha.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,7 @@ if (host.browser) {
77
mocha.fullTrace();
88
mocha.asyncOnly();
99
mocha.checkLeaks();
10-
mocha.globals([
11-
"$0",
12-
"$1",
13-
"$2",
14-
"$3",
15-
"$4",
16-
"$5",
17-
"ga",
18-
"gaplugins",
19-
"gaGlobal",
20-
"gaData",
21-
]);
10+
mocha.globals(["$0", "$1", "$2", "$3", "$4", "$5", "ga", "gaplugins", "gaGlobal", "gaData"]);
2211
}
2312

2413
beforeEach(function () {

test/specs/callbacks-promises/bundled.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ module.exports = {
1919
},
2020
middle: {
2121
type: "string",
22-
enum: [
23-
{ $ref: "#/definitions/requiredString/type" },
24-
{ $ref: "#/definitions/requiredString/title" },
25-
],
22+
enum: [{ $ref: "#/definitions/requiredString/type" }, { $ref: "#/definitions/requiredString/title" }],
2623
},
2724
prefix: {
2825
$ref: "#/definitions/requiredString",
@@ -38,8 +35,7 @@ module.exports = {
3835
},
3936
info: {
4037
version: "1.0.0",
41-
description:
42-
"This is an intentionally over-complicated API that returns a person's name",
38+
description: "This is an intentionally over-complicated API that returns a person's name",
4339
title: "Name API",
4440
},
4541
paths: {

0 commit comments

Comments
 (0)