6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[メモ] error: Unexpected console statement (no-console) と言われるとき

Last updated at Posted at 2020-10-20

Vue.js+Electronでbuildしたときに、console.logで
error: Unexpected console statement (no-console) at src\components\**.vue
と叱られるときのメモ。

// eslint-disable-line no-console
をconsole.logの書いてある行に追加すれば解消できる。
ただ、何もしなくてももう一度buildすると問題なく通る。
下のような関数を作って、console.logの代わりに呼んでもよいかもしれない。

function consoleLog(...theArgs) {
  console.log(theArgs); // eslint-disable-line no-console
}

もしもコンソールログが配列になるのが気になるなら展開してもよいかもしれない。

function consoleLog(...theArgs) {
  const len = theArgs.length;
  switch (len) {
    case 1:
      console.log(theArgs[0]); // eslint-disable-line no-console
      break;
    case 2:
      console.log(theArgs[0], theArgs[1]); // eslint-disable-line no-console
      break;
    default:
      console.log(theArgs); // eslint-disable-line no-console
      break;
  }
}
6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?