javascriptecmascript-6eslintbabel-eslint

Eslint does not recognize const use in default argument value assignment


I want to do this:

const prefDateFormat = {
    weekday: 'long',
    day: 'numeric',
    month: 'long'
}

function formatDates(dates, dateFormat = prefDateFormat){ ... }

but Eslint throws:

error  'prefDateFormat' is assigned a value but never used  no-unused-vars

Is there a way to make eslint take into account a variable usage in a default argument value assignment?

Eslint version: "^6.7.2".

.eslintr.js file:

module.exports = {
  root: true,

  env: {
    node: true
  },

  'extends': [
    'plugin:vue/vue3-essential',
    'eslint:recommended'
  ],

  parserOptions: {
    parser: 'babel-eslint'
  },

  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
  },

  overrides: [
    {
      files: [
        '**/__tests__/*.{j,t}s?(x)',
        '**/tests/unit/**/*.spec.{j,t}s?(x)'
      ],
      env: {
        jest: true
      }
    }
  ]
}

Solution

  • I solved the problem by adding ecmaVersion: 6 property to parserOptions, in my .eslintr.js file, like so:

    parserOptions: {
      parser: 'babel-eslint',
      ecmaVersion: 6,
    },