From 09da21b61cbe40f77962f1e2a7ba1f724e737010 Mon Sep 17 00:00:00 2001 From: sverweij Date: Sun, 4 Oct 2020 18:30:19 +0200 Subject: [PATCH] refactor: replaces own pascal case function with sindresorhus/camelcase as that now properly handles unicode --- lib/rules/parameter-pattern.js | 23 ++--------------------- package.json | 1 + 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/lib/rules/parameter-pattern.js b/lib/rules/parameter-pattern.js index ce09c68..3a82fa8 100644 --- a/lib/rules/parameter-pattern.js +++ b/lib/rules/parameter-pattern.js @@ -1,8 +1,8 @@ +const camelcase = require("camelcase"); const _get = require("lodash.get"); const { getValidParameterPattern, getIdentifierReplacementPattern, - getValidConstantPattern, } = require("./pattern-utl"); /** * @fileoverview Enforce function parameters to adhere to a pattern @@ -12,28 +12,9 @@ const { function getParameterName(pParam) { return _get(pParam, "name", _get(pParam, "left.name", "pOK")); } -function toInitCaps(pString) { - return pString - .slice(0, 1) - .toLocaleUpperCase() - .concat( - // maybe not such a hot idea to use a function named after - // a valid constant pattern, but otoh it's a perfect fit - // maybe rename that function so it's usable in 2 spots? Copy? - pString.slice(1).match(getValidConstantPattern()) - ? pString.slice(1).toLocaleLowerCase() - : pString.slice(1) - ); -} -// wanted to use sindresorhus/camelize for this, but that is not unicode -// compliant yet -// handles snake_case and SNAKED_ALL_CAPS -function toPascalCase(pString) { - return pString.split("_").map(toInitCaps).join(""); -} function normalizeParameterName(pString) { - return `p${toPascalCase(pString)}`; + return `p${camelcase(pString, { pascalCase: true })}`; } function parameterNameIsValid(pString) { diff --git a/package.json b/package.json index 232edbf..4ac1079 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "version": "npm-run-all check depcruise:graph scm:stage" }, "dependencies": { + "camelcase": "6.0.0", "decamelize": "4.0.0", "lodash.get": "4.4.2" },