rhino icon indicating copy to clipboard operation
rhino copied to clipboard

Not using message argument from Shiny.addCustomMessageHandler

Open TymekDev opened this issue 2 years ago • 0 comments

Steps to reproduce

  1. Create custom message handler:
Shiny.addCustomMessageHandler('asdf', (message) => {
  console.log('Hello world!');
});
  1. Run rhino::lint_js()

Bug description

lint_js returns no-unused-vars lint error.

To make it go away I have to either:

  1. disable linter for the line with // eslint-disable-line no-unused-vars, or
  2. artificially use handler's argument, because Shiny.addCustomMessageHandler('asdf', () => {}) results in "handler must be a function that takes one argument."

Expected behavior

I would expect handlers without used arguments to be supported.

Rhino diagnostics

Darwin 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103
R version 4.3.1 (2023-06-16)
rhino: 1.3.0
node: v20.6.1

Comments

A possible solution would be configuring the no-unused-vars rule in .eslintrc.json template.

   "rules": {
     "import/prefer-default-export": "off",
     "no-alert": "off",
-    "no-console": "off"
+    "no-console": "off",
+    "no-unused-vars": ["error", {"argsIgnorePattern": "^_$"}]
   },

This would make _ a special variable that can be used to denote an unused argument, like so:

Shiny.addCustomMessageHandler('asdf', (_) => {
  console.log('Hello world!');
});

TymekDev avatar Oct 09 '23 10:10 TymekDev