diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 811f8c9..0000000 --- a/.eslintrc +++ /dev/null @@ -1,21 +0,0 @@ -{ - "env": { - "node": true, - "es6": true, - "jest": true - }, - "parserOptions": { - "ecmaVersion": 2018 - }, - "plugins": [ - "jest" - ], - "extends": [ - "plugin:jest/recommended", - "standard" - ], - "rules": { - "no-var": 2, - "node/no-unpublished-require": 0 - } -} diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..6eef70a --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,8 @@ +{ + "extends": "@adobe/eslint-config-aio-lib-config", + "settings": { + "jsdoc": { + "ignorePrivate": true + } + } +} diff --git a/e2e/.eslintrc.json b/e2e/.eslintrc.json new file mode 100644 index 0000000..ae74b09 --- /dev/null +++ b/e2e/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "node/no-unpublished-require": 0 + } +} diff --git a/package.json b/package.json index 00a9b7f..a7101b5 100644 --- a/package.json +++ b/package.json @@ -9,30 +9,35 @@ "@adobe/aio-lib-events": "^3.0.0", "@adobe/aio-lib-ims": "^6.0.1", "@oclif/core": "^1.5.2", - "js-yaml": "^3.13.1" + "js-yaml": "^3.13.1", + "inquirer": "^8.2.5" }, "repository": "adobe/aio-cli-plugin-events", "devDependencies": { + "@adobe/eslint-config-aio-lib-config": "^2.0.0", "@types/jest": "^27.4.1", "acorn": "^7.2.0", "babel-runtime": "^6.26.0", "chalk": "^4.0.0", "eol": "^0.9.1", - "eslint": "^7.1.0", + "eslint": "^8.38.0", + "execa": "^4.0.2", "eslint-config-oclif": "^3.1.0", - "eslint-config-standard": "^16.0.3", - "eslint-plugin-import": "^2.20.2", - "eslint-plugin-jest": "23.13.1", + "eslint-config-standard": "^17.0.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-jest": "^23.20.0", + "eslint-plugin-jsdoc": "^37.9.7", + "eslint-plugin-n": "^15.7.0", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-promise": "^6.1.1", "eslint-plugin-standard": "^4.0.1", - "inquirer": "^7.1.0", "jest": "^27.5.1", "jest-haste-map": "^27.5.1", "jest-junit": "^10.0.0", "jest-resolve": "^27.5.1", "oclif": "^3.2.0", - "stdout-stderr": "^0.1.13" + "stdout-stderr": "^0.1.13", + "typescript": "^5.0.4" }, "engines": { "node": "^14.18 || ^16.13 || >=18" @@ -55,7 +60,7 @@ }, "main": "src/index.js", "scripts": { - "posttest": "eslint src test e2e", + "pretest": "eslint src test e2e", "test": "npm run unit-tests", "unit-tests": "jest --ci", "prepack": "oclif manifest && oclif readme --no-aliases", diff --git a/src/utils/validator.js b/src/utils/validator.js index 4c0bba8..dbbcd44 100644 --- a/src/utils/validator.js +++ b/src/utils/validator.js @@ -10,6 +10,14 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ +/** + * Validate input against a regular expression + * + * @param {string} input to be validated + * @param {object} regex the regular expression to validate the input against + * @param {string} message error message in case of a failed validation + * @returns {string|boolean} message or error message + */ function validator (input, regex, message) { // eslint-disable-next-line no-useless-escape const valid = regex @@ -19,16 +27,28 @@ function validator (input, regex, message) { return message } +/** + * @param {string} input validate input for sentence type of minimum one character and maximum of 255 characters + * @returns {string|boolean} message or error message + */ function sentenceValidatorWithMinOneChar (input) { return validator(input, /^[\w\s-_.(),@:'`?#!]{1,255}$/, `The input: ${input} is invalid, please use < 255 characters string with a combination of alphanumeric characters, spaces and special characters in '-_.(),@:'\`?#!'`) } +/** + * @param {string} input validate input for sentence type + * @returns {string|boolean} message or error message + */ function sentenceValidatorWithMinZeroChar (input) { if (input === undefined || input === '') { return true } return sentenceValidatorWithMinOneChar(input) } +/** + * @param {string} input event code to be validated + * @returns {string|boolean} message or error message + */ function eventCodeValidator (input) { return validator(input, /^[\w-_.]{1,255}$/, `The input: ${input} is invalid, please use at least one and < 255 characters string with a combination of alphanumeric characters and special characters in '-_.'`) diff --git a/test/mocks.js b/test/mocks.js index 4cfb2d4..916a3fc 100644 --- a/test/mocks.js +++ b/test/mocks.js @@ -387,5 +387,5 @@ const data = { } module.exports = { - data: data + data }