Skip to content

Object.keys + sort in 'no-side-effects-in-computed-properties' #306

@frandiox

Description

@frandiox

Tell us about your environment

  • ESLint Version: 4.12.0
  • eslint-plugin-vue Version: 4.0.0-beta.4
  • Node Version: 8.8.1

Please show your full configuration:

module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint',
    sourceType: 'module'
  },
  env: {
    browser: true,
  },
  extends: ['airbnb-base', 'plugin:vue/recommended'],
  // check if imports actually resolve
  'settings': {
    'import/resolver': {
      'webpack': {
        'config': 'build/webpack.base.conf.js'
      }
    }
  },
  // add your custom rules here
  'rules': {
    // don't require .vue extension when importing
    'import/extensions': ['error', 'always', {
      'js': 'never',
      'vue': 'never'
    }],
    // allow optionalDependencies
    'import/no-extraneous-dependencies': ['error', {
      'optionalDependencies': ['test/unit/index.js']
    }],
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
    'no-confusing-arrow': 'off',

    // VUE
    'vue/max-attributes-per-line': [2, {
      'singleline': 3,
      'multiline': {
        'max': 1,
        'allowFirstLine': false
      }
    }],
    'no-param-reassign': [
      'error',
      {
        'props': true,
        'ignorePropertyModificationsFor': [
          'state',
          'acc',
          'e',
          'ctx',
          'req',
          'request',
          'res',
          'response',
          'result',
        ]
      }
    ],
  }
}

What did you do? Please include the actual source code causing the issue.

computed: {
  first() {
    return {};
  },
  second() {
    return Object.keys(this.first).sort();
  },
},

What did you expect to happen?

sort changes the array in place, but Object.keys is creating a new array so I think it shouldn't be considered as a side effect.

What actually happened? Please include the actual, raw output from ESLint.

  ✘  https://google.com/#q=vue%2Fno-side-effects-in-computed-properties  Unexpected side effect in "second" computed property            
  src/components/TRPreviewList.vue:68:14
        return Object.keys(this.first).sort();
                ^

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions