0
0

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.

NuxtでESLintのルールを無効にする

0
Posted at

Nuxt.jsではpropsでオブジェクトなどを受け取る際、空のオブジェクトを子コンポーネントで定義しておきます。その際、空のオブジェクトがあるとESLintに怒られるため、グローバルで無効にしておくことにしました。

例 子コンポーネント(propsに空のオブジェクト)

components/atoms/Child.vue
<script>
export default {
  props: {
    receivedObject: {
      type: Object,
      default: () => {},
    },
  },
}
</script>

プロジェクトディレクトリ直下の.eslintrc.jsファイル内

.eslintrc
module.exports = {
  // add your custom rules here
  rules: {
    'no-empty-function': 'off',
    // 空のfunctionあっても大丈夫
  },
}

プロジェクトではこの辺も追加しました。

.eslintrc
module.exports = {
  // add your custom rules here
  rules: {
    'no-console': 'off', // console.log();OK
    'no-unused-vars': 'off', // 使っていない変数あってもOK
    // ↓空白行に対してwarnのみ出るようにする。
    'no-multiple-empty-lines': ['warn', { max: 1 }],
    // 'lodash/prefer-lodash-method': [2, { ignoreObjects: ['_'] }],
    'no-empty-function': 'off',
    // 空のfunctionあっても大丈夫
  },
}

グローバルに適用する必要がない場合は、該当のエラー箇所の直上にコメントをつければOK

alert('foo'); // eslint-disable-line

// eslint-disable-next-line
alert('foo');

/* eslint-disable-next-line */
alert('foo');

alert('foo'); /* eslint-disable-line */

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?