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 autofixer removes comments between method name and parens

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.16.0
  • Node Version: 6.11.3
  • npm Version: 3.10.10

What parser (default, Babel-ESLint, etc.) are you using? babel-eslint@8.2.1

Please show your full configuration:

Configuration
module.exports = {
  // https://standardjs.com/rules.html#javascript-standard-style
  extends: ['standard', 'standard-jsx'],

  overrides: {
    files: '*.specs.js',
    rules: {
      // Due to sinon-chai issue
      // https://github.com/domenic/sinon-chai/issues/20
      'no-unused-expressions': 'off',
    },
  },

  parser: 'babel-eslint',
  parserOptions: {
    ecmaFeatures: {
      classes: true,
      experimentalObjectRestSpread: true,
      jsx: true,
    },
    sourceType: 'module',
  },

  plugins: ['import', 'jsx-a11y', 'react'],

  globals: {
    // app globals
    $: true,
    Headers: true,
    IS_DEVELOPMENT: true,
    Image: true,
    Microsoft: true,
    React: true,
    angular: true,
    document: true,
    elink: true,
    featureFlags: false,
    fetch: true,
    s: true,
    siteConfig: true,
    strings: false,
    valuesData: true,
    window: true,

    // specs globals
    after: false,
    afterEach: false,
    assert: false,
    before: false,
    beforeEach: false,
    chai: false,
    describe: false,
    expect: false,
    it: false,
    sinon: false,
  },

  rules: {
    'array-bracket-spacing': 'error',
    'array-callback-return': 'error',
    'arrow-body-style': 'error',
    'arrow-parens': 'error',
    'arrow-spacing': 'error',
    'brace-style': 'error',
    'comma-dangle': ['error', 'always-multiline'],
    complexity: ['warn', 12],
    'dot-notation': 'error',
    eqeqeq: 'error',
    'guard-for-in': 'warn',
    'id-length': [
      'error',
      {
        exceptions: ['i', 'j', 'k', 'x', 'y', 'z'],
        properties: 'never',
      },
    ],
    'import/first': 'error',
    'import/no-mutable-exports': 'error',
    'import/no-webpack-loader-syntax': 'error',
    'import/prefer-default-export': 'error',
    indent: 'off',
    'jsx-a11y/alt-text': 'error',
    'jsx-a11y/aria-role': 'error',
    'jsx-a11y/img-redundant-alt': 'error',
    'jsx-a11y/no-access-key': 'error',
    'jsx-quotes': ['error', 'prefer-double'],
    'keyword-spacing': 'error',
    'linebreak-style': 'error',
    'max-depth': ['warn', 4],
    'max-statements': ['warn', 30],
    'new-cap': 'error',
    'newline-per-chained-call': [
      'error',
      {
        ignoreChainWithDepth: 3,
      },
    ],
    'no-confusing-arrow': ['error', {allowParens: true}],
    'no-duplicate-imports': 'error',
    'no-else-return': 'error',
    'no-extra-semi': 'error',
    'no-loop-func': 'error',
    'no-mixed-operators': 'off',
    'no-return-assign': 'off',
    'no-underscore-dangle': [
      'error',
      {
        allowAfterThis: true,
      },
    ],
    'no-unused-vars': [
      'error',
      {
        ignoreRestSiblings: true,
        varsIgnorePattern: 'React',
      },
    ],
    'no-var': 'error',
    'object-property-newline': 'error',
    'object-shorthand': 'error',
    'operator-linebreak': ['error', 'after', {overrides: {'?': 'before', ':': 'before'}}],
    'padded-blocks': ['error', 'never'],
    'prefer-arrow-callback': 'error',
    'prefer-const': 'error',
    'prefer-destructuring': [
      'error',
      {
        VariableDeclarator: {array: true, object: true},
        AssignmentExpression: {array: false, object: false},
      },
    ],
    'prefer-rest-params': 'error',
    'prefer-spread': 'error',
    'prefer-template': 'error',
    'quote-props': ['error', 'as-needed'],
    radix: 'error',
    'react/jsx-closing-bracket-location': 'error',
    'react/jsx-closing-tag-location': 'error',
    'react/jsx-no-bind': 'error',
    'react/jsx-no-undef': [
      'error',
      {
        allowGlobals: true,
      },
    ],
    'react/jsx-pascal-case': 'error',
    'react/jsx-wrap-multilines': 'error',
    'react/no-is-mounted': 'error',
    'react/no-multi-comp': 'error',
    'react/no-string-refs': 'error',
    'react/prefer-es6-class': 'error',
    'react/react-in-jsx-scope': 'error',
    'react/require-render-return': 'error',
    'require-jsdoc': 'off',
    semi: ['error', 'always'],
    'sort-imports': [
      'error',
      {
        ignoreMemberSort: false,
        memberSyntaxSortOrder: ['all', 'single', 'multiple', 'none'],
      },
    ],
    'sort-keys': [
      'error',
      'asc',
      {
        natural: true,
      },
    ],
    'space-before-blocks': 'error',
    'space-before-function-paren': ['error', 'never'],
    'space-in-parens': 'error',
    'spaced-comment': 'error',
    'standard/computed-property-even-spacing': 'off',
    'template-curly-spacing': 'error',
    'valid-jsdoc': [
      'warn',
      {
        requireParamDescription: false,
        requireReturn: false,
        requireReturnDescription: 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.

// Before autofixer
controller: /* @ngInject */ function() {

// After autofixer
controller() {
eslint --fix

What did you expect to happen? Either fail to autofix, causing the error to be manually fixed, or moving the comment before the shorthand function.

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Mar 1, 2018

@tylerkayser Yeesh, I don’t think we want to be involved with moving comments around for sure. So I think we’ll just avoid autofixing those (that’s how we usually handle autofix with comments in the way, when there isn’t a 100% equivalent location for the comments). Thanks for the example!

1reaction
tylerkaysercommented, Mar 1, 2018

@platinumazure I agree that not autofixing would probably be the better approach. Here’s an example of the valid output:

/* @ngInject */ controller() {
Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
An in-range update of eslint is breaking the build 🚨 #7 - GitHub
This version is covered by your current version range and after updating it in your project the build failed. As eslint is “only”...
Read more >
demo-outil-edition - node_modules - eslint - CHANGELOG.md
... be83322 Breaking: Remove extra rules from eslint:recommended ... f9c7371 Fix: do not autofix object-shorthand with comments (fixes ...
Read more >
eslint - UNPKG
1403, * 0faf633 Chore: Simplify helper method in Linter tests (#10580) (Kevin ... 1521, * f9c7371 Fix: do not autofix object-shorthand with comments...
Read more >
Rules - ESLint - Pluggable JavaScript Linter
Enforce return statements in callbacks of array methods. Categories: ... Disallow the use of undeclared variables unless mentioned in `/*global */` comments.
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