In ES6, compact methods and unnamed function expression assignments within object literals do not create a lexical identification (name) binding that corresponds to the function name identifier for recursion or event binding. The compact method syntax will not be an appropriate option for these types of solutions, and a named function expression should be used instead. This custom ESLint rule will identify instances where a function name is being called and a lexical identifier is unavailable within a compact object literal.
More information on this can be found:
Note - Tests are provided in the repo, but not necessary for installation or use of the rule.
Node.js & NPM - For instructions on how to install Node.js, check here.
ESLint - More information on ESLint setup & configuration can be found here.
Install the plugin using NPM:
$ npm install eslint-plugin-no-inferred-method-name --save-dev
Note: If ESLint is installed globally, the plugin must also be installed globally.
Within the project directory, create or edit the ESLint configuration file to enable the new rule.
{
plugins: ['eslint-plugin-no-inferred-method-name'],
rules: {
// ...
'no-inferred-method-name/no-inferred-method-name': 'error'
}
// ...
}
You can lint files from the command line using: eslint [filename]
Additionally, the above setup should enable the rule within your Text Editor or IDE (assuming that you have a Linter enabled).
Detailed information / examples of the rule can be found here.