From 67f06a881f6744f0cf76639e6af88cef2fbb0929 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 18 Apr 2023 19:11:17 -0500 Subject: [PATCH] chore: linter and current standards --- .eslintrc.js | 12 +-------- messages/messages.md | 4 ++- package.json | 3 ++- src/flags/duration.ts | 2 ++ src/flags/salesforceId.ts | 3 ++- src/stubUx.ts | 1 + test/unit/util.test.ts | 10 ++++--- yarn.lock | 56 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 74 insertions(+), 17 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 3ec1e4fde..5e8ea53a4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,16 +9,6 @@ // See more at https://github.com/forcedotcom/sfdx-dev-packages/tree/master/packages/dev-scripts module.exports = { - extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license'], - rules: { - '@typescript-eslint/restrict-template-expressions': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - 'jsdoc/check-indentation': 'off', - '@typescript-eslint/prefer-regexp-exec': 'off', - '@typescript-eslint/no-use-before-define': 'off', - '@typescript-eslint/camelcase': 'off', - 'no-underscore-dangle': 'off', - '@typescript-eslint/require-await': 'off', - }, + extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license', 'plugin:sf-plugin/library'], root: true, }; diff --git a/messages/messages.md b/messages/messages.md index 5b7ccdb99..3e2289f58 100644 --- a/messages/messages.md +++ b/messages/messages.md @@ -93,7 +93,9 @@ This command is currently in beta. Any aspect of this command can change without # error.InvalidArgumentFormat -Set varargs with this format: key=value or key="value with spaces". +Error in the following argument +%s +Set varargs with this format: key=value or key="value with spaces" # error.DuplicateArgument diff --git a/package.json b/package.json index 7dc387922..75306148a 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "eslint-plugin-header": "^3.1.1", "eslint-plugin-import": "^2.27.5", "eslint-plugin-jsdoc": "^40.3.0", + "eslint-plugin-sf-plugin": "^1.15.1", "husky": "^7.0.4", "mocha": "^9.1.3", "nyc": "^15.1.0", @@ -144,4 +145,4 @@ "output": [] } } -} \ No newline at end of file +} diff --git a/src/flags/duration.ts b/src/flags/duration.ts index 42d901e22..794571b11 100644 --- a/src/flags/duration.ts +++ b/src/flags/duration.ts @@ -41,7 +41,9 @@ export type DurationFlagConfig = { * ``` */ export const durationFlag = Flags.custom({ + // eslint-disable-next-line @typescript-eslint/require-await parse: async (input, _, opts) => validate(input, opts), + // eslint-disable-next-line @typescript-eslint/require-await default: async (context) => context.options.defaultValue ? toDuration(context.options.defaultValue, context.options.unit) : undefined, }); diff --git a/src/flags/salesforceId.ts b/src/flags/salesforceId.ts index adb12473d..53b9f0754 100644 --- a/src/flags/salesforceId.ts +++ b/src/flags/salesforceId.ts @@ -44,6 +44,7 @@ export type IdFlagConfig = { * ``` */ export const salesforceIdFlag = Flags.custom({ + // eslint-disable-next-line @typescript-eslint/require-await parse: async (input, _ctx, opts) => validate(input, opts), char: 'i', }); @@ -52,7 +53,7 @@ const validate = (input: string, config?: IdFlagConfig): string => { const { length, startsWith } = config ?? {}; // If the flag doesn't specify a length or specifies "both", then let it accept both 15 or 18. - const allowedIdLength = (!length || length === 'both') ? [15, 18] : [length]; + const allowedIdLength = !length || length === 'both' ? [15, 18] : [length]; if (!allowedIdLength.includes(input.length)) { throw messages.createError('errors.InvalidIdLength', [ diff --git a/src/stubUx.ts b/src/stubUx.ts index 88cab99cb..2746f5f29 100644 --- a/src/stubUx.ts +++ b/src/stubUx.ts @@ -4,6 +4,7 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +/* eslint-disable @typescript-eslint/explicit-function-return-type */ import { SinonSandbox } from 'sinon'; import { SfCommand } from './sfCommand'; diff --git a/test/unit/util.test.ts b/test/unit/util.test.ts index 02f0a539f..3f63422c5 100644 --- a/test/unit/util.test.ts +++ b/test/unit/util.test.ts @@ -13,9 +13,13 @@ import { OrgConfigProperties, SfdxPropertyKeys, SFDX_ALLOWED_PROPERTIES, + Messages, } from '@salesforce/core'; import { parseVarArgs, toHelpSection } from '../../src/util'; +Messages.importMessagesDirectory(__dirname); +const messages = Messages.loadMessages('@salesforce/sf-plugins-core', 'messages'); + describe('toHelpSection', () => { it('should produce help section for env vars', () => { const envVarSection = toHelpSection('ENV VAR SECTION', EnvironmentVariable.SFDX_ACCESS_TOKEN); @@ -114,9 +118,9 @@ describe('parseVarArgs', () => { }); it('should throw if invalid format', () => { - expect(() => parseVarArgs({ arg1: 'foobar' }, ['foobar', 'key1=value1', 'key2:value2'])).to.throw( - 'Set varargs with this format: key=value or key="value with spaces". key2:value2' - ); + const badArg = 'key2:value2'; + const expectedError = messages.createError('error.InvalidArgumentFormat', [badArg]).message; + expect(() => parseVarArgs({ arg1: 'foobar' }, ['foobar', 'key1=value1', badArg])).to.throw(expectedError); }); it('should throw if duplicates exist', () => { diff --git a/yarn.lock b/yarn.lock index af15f6d05..c6d721830 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1264,6 +1264,14 @@ "@typescript-eslint/types" "5.58.0" "@typescript-eslint/visitor-keys" "5.58.0" +"@typescript-eslint/scope-manager@5.59.0": + version "5.59.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.59.0.tgz#86501d7a17885710b6716a23be2e93fc54a4fe8c" + integrity sha512-tsoldKaMh7izN6BvkK6zRMINj4Z2d6gGhO2UsI8zGZY3XhLq1DndP3Ycjhi1JwdwPRwtLMW4EFPgpuKhbCGOvQ== + dependencies: + "@typescript-eslint/types" "5.59.0" + "@typescript-eslint/visitor-keys" "5.59.0" + "@typescript-eslint/type-utils@5.44.0": version "5.44.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.44.0.tgz#bc5a6e8a0269850714a870c9268c038150dfb3c7" @@ -1284,6 +1292,11 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.58.0.tgz#54c490b8522c18986004df7674c644ffe2ed77d8" integrity sha512-JYV4eITHPzVQMnHZcYJXl2ZloC7thuUHrcUmxtzvItyKPvQ50kb9QXBkgNAt90OYMqwaodQh2kHutWZl1fc+1g== +"@typescript-eslint/types@5.59.0": + version "5.59.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.59.0.tgz#3fcdac7dbf923ec5251545acdd9f1d42d7c4fe32" + integrity sha512-yR2h1NotF23xFFYKHZs17QJnB51J/s+ud4PYU4MqdZbzeNxpgUr05+dNeCN/bb6raslHvGdd6BFCkVhpPk/ZeA== + "@typescript-eslint/typescript-estree@5.44.0": version "5.44.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.44.0.tgz#0461b386203e8d383bb1268b1ed1da9bc905b045" @@ -1310,6 +1323,19 @@ semver "^7.3.7" tsutils "^3.21.0" +"@typescript-eslint/typescript-estree@5.59.0": + version "5.59.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.0.tgz#8869156ee1dcfc5a95be3ed0e2809969ea28e965" + integrity sha512-sUNnktjmI8DyGzPdZ8dRwW741zopGxltGs/SAPgGL/AAgDpiLsCFLcMNSpbfXfmnNeHmK9h3wGmCkGRGAoUZAg== + dependencies: + "@typescript-eslint/types" "5.59.0" + "@typescript-eslint/visitor-keys" "5.59.0" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + semver "^7.3.7" + tsutils "^3.21.0" + "@typescript-eslint/utils@5.44.0": version "5.44.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.44.0.tgz#d733da4d79d6c30f1a68b531cdda1e0c1f00d52d" @@ -1324,6 +1350,20 @@ eslint-utils "^3.0.0" semver "^7.3.7" +"@typescript-eslint/utils@^5.58.0": + version "5.59.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.59.0.tgz#063d066b3bc4850c18872649ed0da9ee72d833d5" + integrity sha512-GGLFd+86drlHSvPgN/el6dRQNYYGOvRSDVydsUaQluwIW3HvbXuxyuD5JETvBt/9qGYe+lOrDk6gRrWOHb/FvA== + dependencies: + "@eslint-community/eslint-utils" "^4.2.0" + "@types/json-schema" "^7.0.9" + "@types/semver" "^7.3.12" + "@typescript-eslint/scope-manager" "5.59.0" + "@typescript-eslint/types" "5.59.0" + "@typescript-eslint/typescript-estree" "5.59.0" + eslint-scope "^5.1.1" + semver "^7.3.7" + "@typescript-eslint/visitor-keys@5.44.0": version "5.44.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.44.0.tgz#10740dc28902bb903d12ee3a005cc3a70207d433" @@ -1340,6 +1380,14 @@ "@typescript-eslint/types" "5.58.0" eslint-visitor-keys "^3.3.0" +"@typescript-eslint/visitor-keys@5.59.0": + version "5.59.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.0.tgz#a59913f2bf0baeb61b5cfcb6135d3926c3854365" + integrity sha512-qZ3iXxQhanchCeaExlKPV3gDQFxMUmU35xfd5eCXB6+kUw1TUAbIy2n7QIrwz9s98DQLzNWyHp61fY0da4ZcbA== + dependencies: + "@typescript-eslint/types" "5.59.0" + eslint-visitor-keys "^3.3.0" + "@ungap/promise-all-settled@1.1.2": version "1.1.2" resolved "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" @@ -2907,6 +2955,14 @@ eslint-plugin-prefer-arrow@^1.2.1: resolved "https://registry.npmjs.org/eslint-plugin-prefer-arrow/-/eslint-plugin-prefer-arrow-1.2.3.tgz#e7fbb3fa4cd84ff1015b9c51ad86550e55041041" integrity sha512-J9I5PKCOJretVuiZRGvPQxCbllxGAV/viI20JO3LYblAodofBxyMnZAJ+WGeClHgANnSJberTNoFWWjrWKBuXQ== +eslint-plugin-sf-plugin@^1.15.1: + version "1.15.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-sf-plugin/-/eslint-plugin-sf-plugin-1.15.1.tgz#c922cd4825d118fcfcb4b20629d9d65b0d394d89" + integrity sha512-D2i0EiQfTOjVNPivS2Bib/YsLS+l+QU5i72NT4Lhn4nSCTb5VS19PP7lLjlFlW5ffg552q7li3BMM6Cs75YQgw== + dependencies: + "@salesforce/core" "^3.34.6" + "@typescript-eslint/utils" "^5.58.0" + eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"