diff --git a/lib/rules/parameter-pattern.js b/lib/rules/parameter-pattern.js index ce09c68..262b36c 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" },