Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replaces own pascal case function with sindresorhus/camelcase #6

Merged
merged 1 commit into from Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 2 additions & 21 deletions 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
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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"
},
Expand Down