Skip to content

Indentation fix is misbehaving and ignoring comments #6571

@adamreisnz

Description

@adamreisnz

What version of ESLint are you using?
I am using Atom Linter's ESLint package, which specified ESLint ^2.11.1 in it's package.json.

What parser (default, Babel-ESLint, etc.) are you using?
Atom Linter ESLint

Please show your full configuration:

root: true
extends: eslint:recommended
parserOptions:
  ecmaVersion: 6
  ecmaFeatures:
    impliedStrict: true
  sourceType: module
env:
  es6: true
  browser: true
  node: true
  mocha: true
  jasmine: true
rules:
  linebreak-style:
    - error
    - unix
  max-len:
    - error
    - code: 100
      tabWidth: 2
      ignoreComments: true
      ignoreUrls: true
  indent:
    - error
    - 2
    - SwitchCase: 1
      VariableDeclarator:
        let: 2
        const: 3
  semi:
    - error
    - always
  consistent-this:
    - error
    - self
    - $ctrl
  quotes:
    - error
    - single
    - allowTemplateLiterals: true
  curly:
    - error
    - all
  comma-dangle:
    - error
    - only-multiline
  new-cap:
    - error
    - newIsCap: true
      capIsNew: true
      properties: true
  camelcase:
    - error
    - properties: never
  array-bracket-spacing:
    - error
    - never
  arrow-spacing:
    - error
    - before: true
      after: true
  block-spacing:
    - error
    - always
  comma-spacing:
    - error
    - before: false
      after: true
  computed-property-spacing:
    - error
    - never
  generator-star-spacing:
    - error
    - before: true
      after: false
  key-spacing:
    - error
    - beforeColon: false
      afterColon: true
      mode: minimum
  keyword-spacing:
    - error
    - before: true
  semi-spacing:
    - error
    - before: false
      after: true
  space-in-parens:
    - error
    - never
  space-unary-ops:
    - error
    - words: true
      nonwords: false
  space-before-function-paren:
    - error
    - never
  space-before-blocks:
    - error
    - always
  yoda:
    - error
    - never
  wrap-iife:
    - error
    - outside
  eqeqeq:
    - error
    - always
  newline-per-chained-call:
    - error
    - ignoreChainWithDepth: 2
  one-var-declaration-per-line:
    - error
    - initializations
  brace-style:
    - error
    - stroustrup
  eol-last: error
  dot-notation: error
  space-infix-ops: error
  no-with: error
  no-unreachable: error
  no-redeclare: error
  no-unexpected-multiline: error
  no-multi-spaces: error
  no-multi-str: error
  no-trailing-spaces: error
  no-mixed-spaces-and-tabs: error
  no-spaced-func: error
  no-whitespace-before-property: error
  no-lonely-if: error
  no-var: error
  no-implicit-coercion: error

What did you do? Please include the actual source code causing the issue.
This is a portion of the source code that is affected. Note that to prevent errors about max line length, I have moved the mixins onto a separate line, but afterwards I open the curly bracket on the first indentation level to prevent the whole file from being indented too much:

export default FlowController.extend(
  BookAppointment, ProcessOutcome, PreventNavigation,
{

  //Nav model
  navModel: Nav.create({
    pageTitle: '...'
  }),

  //Model aliases
  client: Ember.computed.reads('model.client'),
  cards: Ember.computed.reads('model.cards'),

  /**
   * Ok to navigate away check
   */
  isOkToNavigateAway(targetRoute) {

    //Still in first screen
    if (this.get('step') === 'choose-card') {
      return true;
    }

    //Going to appointment
    if (targetRoute === 'appointments.book') {
      return true;
    }

    //Have submitted
    if (this.get('hasSubmitted')) {
      return true;
    }

    //Not ok
    return false;
  }

  //...
});

What did you expect to happen?

  1. That my indentation remains as is, on account of my curly bracket starting at the beginning of the line.
  2. That if ESLInt fixes indentation, it actually also fixes the comments and not leave a garbled mess :)

What actually happened? Please include the actual, raw output from ESLint.
Everything has been indented, except for all the comments, leaving a bit of a mess:

export default FlowController.extend(
  BookAppointment, ProcessOutcome, PreventNavigation,
  {

  //Nav model
    navModel: Nav.create({
      pageTitle: '...'
    }),

  //Model aliases
    client: Ember.computed.reads('model.client'),
    cards: Ember.computed.reads('model.cards'),

  /**
   * Ok to navigate away check
   */
    isOkToNavigateAway(targetRoute) {

    //Still in first screen
      if (this.get('step') === 'choose-card') {
        return true;
      }

    //Going to appointment
      if (targetRoute === 'appointments.book') {
        return true;
      }

    //Have submitted
      if (this.get('hasSubmitted')) {
        return true;
      }

    //Not ok
      return false;
    }

  //...
  });

I don't know how issue 1 can be resolved. It's an annoying Ember pattern that you specify the object you're extending with as the last parameter, and I'd like to be able to have the indentation for that object start at the first position without ESLint trying to fix it.

Issue 2 seems like a genuine bug. It should include comments when fixing indentation or it's just useless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    archived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlyevaluatingThe team will evaluate this issue to decide whether it meets the criteria for inclusionindentRelates to the `indent` ruleruleRelates to ESLint's core rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions