diff --git a/package-lock.json b/package-lock.json index c91718f5..689d10a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "devDependencies": { "@actions/core": "^1.10.1", "@actions/github": "^6.0.0", - "@redocly/openapi-core": "^1.4.1", + "@redocly/openapi-core": "^1.34.5", "@types/node": "^20.9.4", "esbuild": "^0.19.7", "eslint": "^8.54.0", @@ -777,15 +777,16 @@ } }, "node_modules/@redocly/ajv": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@redocly/ajv/-/ajv-8.11.0.tgz", - "integrity": "sha512-9GWx27t7xWhDIR02PA18nzBdLcKQRgc46xNQvjFkrYk4UOmvKhJ/dawwiX0cCOeetN5LcaaiqQbVOWYK62SGHw==", + "version": "8.11.3", + "resolved": "https://registry.npmjs.org/@redocly/ajv/-/ajv-8.11.3.tgz", + "integrity": "sha512-4P3iZse91TkBiY+Dx5DUgxQ9GXkVJf++cmI0MOyLDxV9b5MUBI4II6ES8zA5JCbO72nKAJxWrw4PUPW+YP3ZDQ==", "dev": true, + "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2", - "uri-js": "^4.2.2" + "uri-js-replace": "^1.0.1" }, "funding": { "type": "github", @@ -796,36 +797,38 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true + "dev": true, + "license": "MIT" + }, + "node_modules/@redocly/config": { + "version": "0.22.2", + "resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.22.2.tgz", + "integrity": "sha512-roRDai8/zr2S9YfmzUfNhKjOF0NdcOIqF7bhf4MVC5UxpjIysDjyudvlAiVbpPHp3eDRWbdzUgtkK1a7YiDNyQ==", + "dev": true, + "license": "MIT" }, "node_modules/@redocly/openapi-core": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.4.1.tgz", - "integrity": "sha512-oAhnG8MKocM9LuP++NGFxdniNKWSLA7hzHPQoOK92LIP/DdvXx8pEeZ68UTNxIXhKonoUcO6s86I3L0zj143zg==", + "version": "1.34.5", + "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.34.5.tgz", + "integrity": "sha512-0EbE8LRbkogtcCXU7liAyC00n9uNG9hJ+eMyHFdUsy9lB/WGqnEBgwjA9q2cyzAVcdTkQqTBBU1XePNnN3OijA==", "dev": true, + "license": "MIT", "dependencies": { - "@redocly/ajv": "^8.11.0", - "@types/node": "^14.11.8", + "@redocly/ajv": "^8.11.2", + "@redocly/config": "^0.22.0", "colorette": "^1.2.0", + "https-proxy-agent": "^7.0.5", "js-levenshtein": "^1.1.6", "js-yaml": "^4.1.0", - "lodash.isequal": "^4.5.0", "minimatch": "^5.0.1", - "node-fetch": "^2.6.1", "pluralize": "^8.0.0", "yaml-ast-parser": "0.0.43" }, "engines": { - "node": ">=14.19.0", - "npm": ">=7.0.0" + "node": ">=18.17.0", + "npm": ">=9.5.0" } }, - "node_modules/@redocly/openapi-core/node_modules/@types/node": { - "version": "14.18.42", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.42.tgz", - "integrity": "sha512-xefu+RBie4xWlK8hwAzGh3npDz/4VhF6icY/shU+zv/1fNn+ZVG7T7CRwe9LId9sAYRPxI+59QBPuKL3WpyGRg==", - "dev": true - }, "node_modules/@redocly/openapi-core/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -1387,6 +1390,16 @@ "node": ">=0.4.0" } }, + "node_modules/agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -3029,6 +3042,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/human-signals": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz", @@ -3637,12 +3664,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==", - "dev": true - }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -3970,26 +3991,6 @@ "dev": true, "peer": true }, - "node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dev": true, - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/npm-run-path": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", @@ -4467,6 +4468,7 @@ "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -5208,12 +5210,6 @@ "node": ">=8.0" } }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "dev": true - }, "node_modules/tsconfig-paths": { "version": "3.14.2", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", @@ -5802,6 +5798,13 @@ "punycode": "^2.1.0" } }, + "node_modules/uri-js-replace": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/uri-js-replace/-/uri-js-replace-1.0.1.tgz", + "integrity": "sha512-W+C9NWNLFOoBI2QWDp4UT9pv65r2w5Cx+3sTYFvtMdDBxkKt1syCqsUdSFAChbEe1uK5TfS04wt/nGwmaeIQ0g==", + "dev": true, + "license": "MIT" + }, "node_modules/uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", @@ -5966,22 +5969,6 @@ } } }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "dev": true - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dev": true, - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -6645,15 +6632,15 @@ } }, "@redocly/ajv": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@redocly/ajv/-/ajv-8.11.0.tgz", - "integrity": "sha512-9GWx27t7xWhDIR02PA18nzBdLcKQRgc46xNQvjFkrYk4UOmvKhJ/dawwiX0cCOeetN5LcaaiqQbVOWYK62SGHw==", + "version": "8.11.3", + "resolved": "https://registry.npmjs.org/@redocly/ajv/-/ajv-8.11.3.tgz", + "integrity": "sha512-4P3iZse91TkBiY+Dx5DUgxQ9GXkVJf++cmI0MOyLDxV9b5MUBI4II6ES8zA5JCbO72nKAJxWrw4PUPW+YP3ZDQ==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2", - "uri-js": "^4.2.2" + "uri-js-replace": "^1.0.1" }, "dependencies": { "json-schema-traverse": { @@ -6664,30 +6651,29 @@ } } }, + "@redocly/config": { + "version": "0.22.2", + "resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.22.2.tgz", + "integrity": "sha512-roRDai8/zr2S9YfmzUfNhKjOF0NdcOIqF7bhf4MVC5UxpjIysDjyudvlAiVbpPHp3eDRWbdzUgtkK1a7YiDNyQ==", + "dev": true + }, "@redocly/openapi-core": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.4.1.tgz", - "integrity": "sha512-oAhnG8MKocM9LuP++NGFxdniNKWSLA7hzHPQoOK92LIP/DdvXx8pEeZ68UTNxIXhKonoUcO6s86I3L0zj143zg==", + "version": "1.34.5", + "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.34.5.tgz", + "integrity": "sha512-0EbE8LRbkogtcCXU7liAyC00n9uNG9hJ+eMyHFdUsy9lB/WGqnEBgwjA9q2cyzAVcdTkQqTBBU1XePNnN3OijA==", "dev": true, "requires": { - "@redocly/ajv": "^8.11.0", - "@types/node": "^14.11.8", + "@redocly/ajv": "^8.11.2", + "@redocly/config": "^0.22.0", "colorette": "^1.2.0", + "https-proxy-agent": "^7.0.5", "js-levenshtein": "^1.1.6", "js-yaml": "^4.1.0", - "lodash.isequal": "^4.5.0", "minimatch": "^5.0.1", - "node-fetch": "^2.6.1", "pluralize": "^8.0.0", "yaml-ast-parser": "0.0.43" }, "dependencies": { - "@types/node": { - "version": "14.18.42", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.42.tgz", - "integrity": "sha512-xefu+RBie4xWlK8hwAzGh3npDz/4VhF6icY/shU+zv/1fNn+ZVG7T7CRwe9LId9sAYRPxI+59QBPuKL3WpyGRg==", - "dev": true - }, "brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -7051,6 +7037,12 @@ "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", "dev": true }, + "agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "dev": true + }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -8255,6 +8247,16 @@ "has-symbols": "^1.0.2" } }, + "https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", + "dev": true, + "requires": { + "agent-base": "^7.1.2", + "debug": "4" + } + }, "human-signals": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz", @@ -8661,12 +8663,6 @@ "p-locate": "^5.0.0" } }, - "lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==", - "dev": true - }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -8908,15 +8904,6 @@ "dev": true, "peer": true }, - "node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dev": true, - "requires": { - "whatwg-url": "^5.0.0" - } - }, "npm-run-path": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", @@ -9742,12 +9729,6 @@ "is-number": "^7.0.0" } }, - "tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "dev": true - }, "tsconfig-paths": { "version": "3.14.2", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", @@ -10087,6 +10068,12 @@ "punycode": "^2.1.0" } }, + "uri-js-replace": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/uri-js-replace/-/uri-js-replace-1.0.1.tgz", + "integrity": "sha512-W+C9NWNLFOoBI2QWDp4UT9pv65r2w5Cx+3sTYFvtMdDBxkKt1syCqsUdSFAChbEe1uK5TfS04wt/nGwmaeIQ0g==", + "dev": true + }, "uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", @@ -10151,22 +10138,6 @@ "why-is-node-running": "^2.2.2" } }, - "webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "dev": true - }, - "whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dev": true, - "requires": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 8414abae..65df7a2a 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,14 @@ "prepare": "husky install src/.husky || exit 0", "prepack": "npm run build", "test": "vitest run --root src", - "tsc": "tsc --noEmit -p src/tsconfig.json" + "tsc": "tsc --noEmit -p src/tsconfig.json", + "lint": "eslint 'src/**/*.{ts,js}' && prettier --check 'src/**/*.{ts,js}'", + "lint:fix": "eslint --fix 'src/**/*.{ts,js}' && prettier --write 'src/**/*.{ts,js}'" }, "devDependencies": { "@actions/core": "^1.10.1", "@actions/github": "^6.0.0", - "@redocly/openapi-core": "^1.4.1", + "@redocly/openapi-core": "^1.34.5", "@types/node": "^20.9.4", "esbuild": "^0.19.7", "eslint": "^8.54.0", diff --git a/src/linting/rules/always-return-json-object.ts b/src/linting/rules/always-return-json-object.ts index 625ce7a1..c86f4fc0 100644 --- a/src/linting/rules/always-return-json-object.ts +++ b/src/linting/rules/always-return-json-object.ts @@ -1,11 +1,11 @@ import type { Oas3Rule } from "@redocly/openapi-core/lib/visitors.d.js"; -import { isRef, type Oas3Schema } from "@redocly/openapi-core"; +import { isRef, type Oas3_1Schema, type Oas3Schema } from "@redocly/openapi-core"; import type { Location } from "@redocly/openapi-core/lib/ref-utils.d.js"; import type { ResolveFn } from "@redocly/openapi-core/lib/walk.d.js"; import { isJsonContentType } from "./utils/isJsonContentType.js"; const findNonObjectLocations = ( - schema: Oas3Schema, + schema: Oas3Schema | Oas3_1Schema, location: Location, resolve: ResolveFn, ): Location[] => { diff --git a/src/linting/rules/not-use-null-for-empty-array.ts b/src/linting/rules/not-use-null-for-empty-array.ts index c7faca04..17be2e12 100644 --- a/src/linting/rules/not-use-null-for-empty-array.ts +++ b/src/linting/rules/not-use-null-for-empty-array.ts @@ -1,10 +1,10 @@ import type { Oas3Rule } from "@redocly/openapi-core/lib/visitors.d.js"; -import type { Oas3Schema } from "@redocly/openapi-core"; +import type { Oas3_1Schema, Oas3Schema } from "@redocly/openapi-core"; import type { Location } from "@redocly/openapi-core/lib/ref-utils.d.js"; import type { Problem } from "@redocly/openapi-core/lib/walk.d.js"; const findArrayNullExamples = ( - { type, properties, items }: Oas3Schema, + { type, properties, items }: Oas3Schema | Oas3_1Schema, example: unknown, location: Location, ): Location[] => { @@ -12,7 +12,13 @@ const findArrayNullExamples = ( if (Array.isArray(example) && items) { return example - .map((value, index) => findArrayNullExamples(items, example[index], location.child(index))) + .map((value, index) => + findArrayNullExamples( + items as Oas3Schema | Oas3_1Schema, + example[index], + location.child(index), + ), + ) .flat(); } diff --git a/src/linting/rules/use-common-date-and-time-format.ts b/src/linting/rules/use-common-date-and-time-format.ts index c21f431b..0e50d931 100644 --- a/src/linting/rules/use-common-date-and-time-format.ts +++ b/src/linting/rules/use-common-date-and-time-format.ts @@ -1,12 +1,12 @@ import type { Oas3Rule } from "@redocly/openapi-core/lib/visitors.d.js"; -import type { Oas3Schema } from "@redocly/openapi-core"; +import type { Oas3_1Schema, Oas3Schema } from "@redocly/openapi-core"; import type { Location } from "@redocly/openapi-core/lib/ref-utils.d.js"; import type { Problem } from "@redocly/openapi-core/lib/walk.d.js"; import { isValidDateFormat } from "./utils/isValidDateFormat.js"; import { isValidDateTimeFormat } from "./utils/isValidDateTimeFormat.js"; const findInvalidDateExamples = ( - { format, properties, items }: Oas3Schema, + { format, properties, items }: Oas3Schema | Oas3_1Schema, example: unknown, location: Location, ): Location[] => { @@ -21,7 +21,13 @@ const findInvalidDateExamples = ( if (Array.isArray(example) && items) { return example - .map((value, index) => findInvalidDateExamples(items, example[index], location.child(index))) + .map((value, index) => + findInvalidDateExamples( + items as Oas3Schema | Oas3_1Schema, + example[index], + location.child(index), + ), + ) .flat(); } @@ -35,7 +41,7 @@ const findInvalidDateExamples = ( }; function findAndReport( - schema: Oas3Schema, + schema: Oas3Schema | Oas3_1Schema, example: unknown, location: Location, report: (problem: Problem) => void, diff --git a/src/linting/rules/utils/isCamelCase.spec.ts b/src/linting/rules/utils/isCamelCase.spec.ts index 8aacc318..991c2003 100644 --- a/src/linting/rules/utils/isCamelCase.spec.ts +++ b/src/linting/rules/utils/isCamelCase.spec.ts @@ -1,17 +1,25 @@ import { isCamelCase } from "./isCamelCase.js"; -it("should fooBar should be valid", () => { - expect(isCamelCase("fooBar")).toBeTruthy(); -}); - -it("should foo should be valid", () => { - expect(isCamelCase("foo")).toBeTruthy(); -}); - -it("should foo-bar should be valid", () => { - expect(isCamelCase("foo-bar")).toBeFalsy(); -}); +describe("isCamelCase", () => { + it.each([ + "thisIsCamelCase", + "anotherExample123", + "myGreat0To10Foo", + "variable", + "myTop10Entities", + "affine3D", + ])(`should return true for "%s"`, (value) => { + expect(isCamelCase(value)).toBeTruthy(); + }); -it("should foo_bar should be valid", () => { - expect(isCamelCase("foo_bar")).toBeFalsy(); + it.each([ + "kebab-case", + "10AwesomeThings", + "snake_case", + "SCREAMING_SNAKE_CASE", + "WRonGCAmelCase", + "SCREAMING-KEBAB-CASE", + ])(`should return false for "%s"`, (value) => { + expect(isCamelCase(value)).toBeFalsy(); + }); }); diff --git a/src/linting/rules/utils/isCamelCase.ts b/src/linting/rules/utils/isCamelCase.ts index 1990017b..e6ecba0d 100644 --- a/src/linting/rules/utils/isCamelCase.ts +++ b/src/linting/rules/utils/isCamelCase.ts @@ -1 +1 @@ -export const isCamelCase = (value: string) => /^([a-z]+)(([A-Z]([a-z]+))*)$/.test(value); +export const isCamelCase = (value: string) => /^[a-z][a-zA-Z0-9]+$/.test(value); diff --git a/src/linting/rules/utils/isKebabCase.spec.ts b/src/linting/rules/utils/isKebabCase.spec.ts index 0035dc2b..7d8063bf 100644 --- a/src/linting/rules/utils/isKebabCase.spec.ts +++ b/src/linting/rules/utils/isKebabCase.spec.ts @@ -1,16 +1,29 @@ import { isKebabCase } from "./isKebabCase.js"; -it("should return true for valid kebab case strings", () => { - expect(isKebabCase("this-is-kebab-case")).toBe(true); - expect(isKebabCase("word")).toBe(true); - expect(isKebabCase("a-b-c")).toBe(true); -}); +describe("isKebabCase", () => { + it.each([ + "this-is-kebab-case", + "word", + "a-b-c", + "another-123-example", + "kebab-case-with-numbers-456", + "my-top10-entities", + ])(`should return true for "%s"`, (value) => { + expect(isKebabCase(value)).toBeTruthy(); + }); -it("should return false for invalid kebab case strings", () => { - expect(isKebabCase("ThisIsNotKebabCase")).toBe(false); - expect(isKebabCase("this_is_not_kebab_case")).toBe(false); - expect(isKebabCase("this is not kebab case+v1")).toBe(false); - expect(isKebabCase("this-has_Underscore")).toBe(false); - expect(isKebabCase("this-has-Capital")).toBe(false); - expect(isKebabCase("")).toBe(false); + it.each([ + "ThisIsNotKebabCase", + "this_is_not_kebab_case", + "this is not kebab case+v1", + "this-has_Underscore", + "this-has-Capital", + "123-parameter", + "camelCase", + "snake_case", + "SCREAMING_SNAKE_CASE", + "", + ])(`should return false for "%s"`, (value: string) => { + expect(isKebabCase(value)).toBeFalsy(); + }); }); diff --git a/src/linting/rules/utils/isKebabCase.ts b/src/linting/rules/utils/isKebabCase.ts index bf4f2618..717221b2 100644 --- a/src/linting/rules/utils/isKebabCase.ts +++ b/src/linting/rules/utils/isKebabCase.ts @@ -1 +1 @@ -export const isKebabCase = (s: string): boolean => /^[a-z]+(-[a-z]+)*$/.test(s); +export const isKebabCase = (s: string): boolean => /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.test(s);