Skip to content

salesforcecli/eslint-plugin-sf-plugin

eslint-plugin-sf-plugin

Helpful eslint rules for sf plugins.

Use these rules in a sf plugin

yarn add --dev eslint-plugin-sf-plugin

Then, in your plugin's .eslintrc.js, add "plugin:sf-plugin/recommended" to your extends property.

example:

module.exports = {
  extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license', 'plugin:sf-plugin/recommended'],
};

To override how an individual rules behaves, add the plugin name and change the its rules value.

plugins: ['sf-plugin'],
rules: {
  'sf-plugin/no-hardcoded-messages': 'error'
}

Use these rules to migrate a plugin based on sfdxCommand to use sfCommand

These eslint rules are experimental and cause significant code changes. Please use with caution and test changes thoroughly

yarn add @salesforce/sf-plugins-core
yarn add --dev eslint-plugin-sf-plugin

[migration includes all of the recommended rules, so you don't have to include both]

module.exports = {
  extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license', 'plugin:sf-plugin/migration'],
};

Rules

πŸ’Ό Configurations enabled in.
⚠️ Configurations set to warn in.
🚫 Configurations disabled in.
πŸ“š Set in the library configuration.
✈️ Set in the migration configuration.
βœ… Set in the recommended configuration.
πŸ”§ Automatically fixable by the --fix CLI option.
πŸ’‘ Manually fixable by editor suggestions.

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Description πŸ’Ό ⚠️ 🚫 πŸ”§ πŸ’‘
command-example Ensure commands have a summary, description, and examples ✈️ βœ…
command-summary Ensure commands have a summary ✈️ βœ… πŸ”§
dash-o Warn on a flag that uses -o ✈️ βœ…
encourage-alias-deprecation Commands and flags aliases probably want to deprecate their old names to provide more warnings to users πŸ”§ πŸ’‘
esm-message-import Looks for the verbose Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url))) to offer a simpler alternative πŸ“š ✈️ βœ… πŸ”§
flag-case Enforce lowercase kebab-case flag names ✈️ βœ… πŸ”§
flag-cross-references Enforce flag cross references for dependOn,exclusive,exactlyOne ✈️ βœ…
flag-min-max-default Enforce that flags with min/max values have a default value ✈️ βœ…
flag-summary Enforce that flags have a summary property and that longDescription is renamed to description ✈️ βœ… πŸ”§
get-connection-with-version Calls to getConnection should pass in a version ✈️ βœ…
id-flag-suggestions Create better salesforceId flags with length and startsWith properties ✈️ βœ… πŸ”§ πŸ’‘
no-args-parse-without-strict-false If you parse args/argv, the class should have strict set to false ✈️ βœ… πŸ”§
no-builtin-flags Handling for sfdxCommand's flags.builtin ✈️ πŸ”§
no-classes-in-command-return-type The return type of the run method should not contain a class. ✈️ βœ… πŸ”§
no-default-and-depends-on-flags Do not allow creation of a flag with default value and dependsOn ✈️ βœ…
no-depends-on-boolean-flag Do not allow flags to depend on boolean flags ✈️ βœ…
no-deprecated-properties Removes non-existent properties left over from SfdxCommand ✈️ πŸ”§
no-duplicate-short-characters Prevent duplicate use of short characters or conflicts between aliases and flags ✈️ βœ…
no-execcmd-double-quotes Do not use double quotes in NUT examples. They will not work on windows πŸ“š ✈️ βœ… πŸ”§
no-filepath-flags Change filepath flag to file flag πŸ”§
no-h-short-char Do not allow creation of a flag with short char -h ✈️ βœ…
no-hardcoded-messages-commands Use loaded messages and separate files for messages ✈️ βœ…
no-hardcoded-messages-flags Use loaded messages and separate files for messages. Follow the message naming guidelines ✈️ βœ… πŸ”§
no-hyphens-aliases Mark when an alias starts with a hyphen, like -f or --foo ✈️ βœ… πŸ”§
no-id-flags Change Id flag to salesforceId ✈️ πŸ”§
no-json-flag Do not allow creation of json flag ✈️ βœ…
no-messages-load Use Messages.loadMessages() instead of Messages.load() πŸ“š ✈️ βœ… πŸ”§
no-missing-messages Checks core Messages usage for correct usage of named messages and message tokens πŸ“š ✈️ βœ…
no-number-flags Change number flag to integer πŸ”§
no-oclif-flags-command-import Change import of flags and Command from oclif to use sf-plugins-core ✈️ βœ… πŸ”§
no-sfdx-command-import Change import and base class from SfdxCommand to sfCommand ✈️ πŸ”§
no-split-examples Arrays of messags should use getMessages instead of getMessage followed by EOL splitting ✈️ βœ… πŸ”§
no-this-flags Fix references to this.org (property on SfdxCommand) ✈️ πŸ”§ πŸ’‘
no-this-org Fix references to this.org (property on SfdxCommand) ✈️ πŸ”§ πŸ’‘
no-this-ux SfCommand does not have a ux property ✈️ πŸ”§
no-time-flags Migrate time flags to Flags.duration ✈️ πŸ”§
no-unnecessary-aliases Mark when an alias is unnecessary because its only an order permutation, not really a different name ✈️ βœ… πŸ”§
no-unnecessary-properties Boolean properties are false by default, so they should not be set to false ✈️ βœ… πŸ”§
no-username-properties Convert requiresUsername and supportusername to username flags ✈️ πŸ”§
only-extend-SfCommand Only allow commands that directly extend SfCommand ✈️ βœ…
read-only-properties Class-level static properties, like flags or descriptions, should be marked public and read-only ✈️ βœ… πŸ”§
run-matches-class-type The return type of the run method should match the Type passed to sfCommand ✈️ βœ… πŸ”§
sfdx-flags-property Change flag definitions to SfCommand version ✈️ πŸ”§
should-parse-flags The run method should call this.parse when there are flags ✈️ πŸ”§
spread-base-flags When not directly extending SfCommand, the parent's flags must be spread like flags = { ...{{parent}}.{{property}} } ✈️ βœ…
use-sf-command-flags Use Flags export from sf-plugins-core ✈️ πŸ”§