diff --git a/lib/cmd/lint.js b/lib/cmd/lint.js index 3941598..a697d1e 100644 --- a/lib/cmd/lint.js +++ b/lib/cmd/lint.js @@ -260,16 +260,19 @@ function noDescription(obj) { } /** - * check camelCase, but more flexible than lodash's algorithm - * @param {string} str - * @return {Boolean} + * Check if a string contains non-letter, non-number, or non-underscore chars + * + * @param {string} str + * @return {boolean} */ -function isCamelCased(str) { - const camel = _.camelCase(str); +function isValidKilnDotNotation(str) { + // https://regex101.com/r/wapXTM/2 for an example of this regex in action + + // This function is used after "toDotNotation()" in "assertCamelCasedProps()" below + // "toDotNotation" actually allows numbers, which are not valid property accessors in dot notation, but which is why we permit numbers here - // note: we're lowercasing everything because we don't care about 100% perfect camelCase (e.g. imageURL is valid), - // we just want to make sure that people aren't using weird characters that cannot be used as properties in dot notation - return str.toLowerCase() === camel.toLowerCase() || str.toLowerCase() === `_${camel}`.toLowerCase(); // lodash's camelCase() will remove leading underscores, which we allow in things like _version, _description, and _devDescription + // If the regex returns false, it means that the string is valid + return !(/[^\w\$_]/g.test(str)); } /** @@ -279,7 +282,7 @@ function isCamelCased(str) { */ function nonCamelCasedProps(obj) { return _.reduce(obj, (errors, value, key) => { - return !isCamelCased(key) ? errors.concat(key) : errors; + return !isValidKilnDotNotation(key) ? errors.concat(key) : errors; }, []); }