question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object Shorthand conflicts with func-names

See original GitHub issue

Tell us about your environment

├─ @vue/cli-plugin-eslint@3.11.0
│  └─ eslint@4.19.1
└─ eslint@6.1.0
  • Node Version: v12.6.0
  • npm Version: 6.9.0

What parser (default, Babel-ESLint, etc.) are you using? babel Please show your full configuration:

Configuration
{
  "plugins": [
    "vue"
  ],
  "extends": [
    "plugin:vue/recommended",
    "airbnb-base",
    "plugin:prettier/recommended",
    "prettier/vue"
  ],
  "env": {
    "jest": true
  },
  "parserOptions": {
    "sourceType": "module",
    "ecmaVersion": 2018
  },
  "globals": {
    "App": true
  },
  "settings": {
    "import/extensions": [
      ".vue"
    ],
    "import/resolver": {
      "node": {
        "paths": ["app/javascript"],
        "extensions": [".js", ".vue"]
      }
    }
  },
  "rules": {
    "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
    "no-underscore-dangle": ["error", { "allow": ["_underlying_vm_", "_componentTag"] }],
    "no-return-assign": ["error", "except-parens"],
    "no-restricted-properties": "off",
    "import/prefer-default-export": "off",
    "no-shadow": "off",
    "no-unused-expressions": "off",
    "no-param-reassign": ["error", { "props": false }],
    "quotes": ["error", "single"],
    "max-len": ["error", {
      "code": 130,
      "ignoreComments": true,
      "ignoreUrls": true
    }],
    "vue/max-attributes-per-line": [
      2,
      {
        "singleline": 20,
        "multiline": {
          "max": 1,
          "allowFirstLine": false
        }
      }
    ]
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

    '$route.query': function() {
      this.fetchData();
    },
║ 239      │ 21       │ warning  │ Unexpected unnamed method '$route.query'.              │ func-names           ║
    '$route.query'() {
      this.fetchData();
    },

║ Line     │ Column   │ Type     │ Message                                                │ Rule ID              ║
╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢
║ 239      │ 5        │ error    │ Expected longform method syntax for string literal     │ object-shorthand     ║
║          │          │          │ keys.                                                  │                      ║
eslint --ext .js,.vue app/javascript

What did you expect to happen?

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

Are you willing to submit a pull request to fix this bug? yes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Aug 29, 2019

The option doesn’t enforce unquoted property names (this isn’t the quote-props rule), it disallows shorthands with quoted names.

“avoidQuotes”: true indicates that long-form syntax is preferred whenever the object key is a string literal

Rules are configured to enforce this code:

const foo = { 
  '$route.query': function $routeQuery() {
      this.fetchData();
   }
}

If you want to allow the following:

const foo = { 
  '$route.query'() {
      this.fetchData();
   }
}

then set the avoidQuotes option to false.

1reaction
mysticateacommented, Aug 29, 2019

@ljharb No. I just talked about the current behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object Shorthand conflicts with func-names #2081 - GitHub
The dot means you can't just remove the quotes; this seems like a bug in the core eslint rule (whose name i don't...
Read more >
eslint object-shorthand error with variable passed in
An excerpt from eslint regarding the issue: Require Object Literal Shorthand Syntax (object-shorthand) - Rule Details.
Read more >
object-shorthand - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
9. Classes — Python 3.11.1 documentation
As in Modula-3, there are no shorthands for referencing the object's ... in the expression modname.funcname , modname is a module object and...
Read more >
List of available rules - ESLint - Pluggable JavaScript linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found