Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation of code with a multiline tagged template literal string seems off #1236

Closed
nerdo opened this issue Dec 22, 2018 · 1 comment

Comments

@nerdo
Copy link

commented Dec 22, 2018

What version of standard?
12.0.1

What operating system, Node.js, and npm version?
macOS Mojave 10.14.1
Node.js 10.11.0
npm 6.5.0

Input file test.js

/* global describe, test, expect */
import { setupCustomMatchers } from '../helpers/jest'
import { SupervisorInterface } from './SupervisorInterface'
import { Supervisor } from '../Supervisor'

setupCustomMatchers(expect)

const newSupervisor = () => new Supervisor()

describe('SupervisorInterface conformance of', () => {
  test.each`
    concreteImplementationName | newInstance
    ${'Supervisor'}               | ${newSupervisor}
  `('$concreteImplementationName', ({ newInstance }) => {
    const supervisor = newInstance()
    expect(supervisor).toImplement(SupervisorInterface)

    let setPresenterResult
    expect(() => { setPresenterResult = supervisor.setPresenter(null) }).not.toThrow()
    expect(setPresenterResult).toBe(supervisor)
    expect(supervisor.getPresenter()).toBe(null)

    let setNextActionDelegatesResult
    const before = () => {}
    const after = () => {}
    expect(() => { setNextActionDelegatesResult = supervisor.setNextActionDelegates(before, after) }).not.toThrow()
    expect(setNextActionDelegatesResult).toBe(supervisor)
    expect(supervisor.getNextActionDelegates()).toEqual([before, after])
  })
})

What did you expect to happen?
Running standard on test.js reveals several indent errors, however, it seems to me that the indentation in the original file is correct.

For example, if one were to remove the tagged template literal altogether, it would be a normal function call and the indent errors disappear.

What actually happened?
Taking it one step further, running standard --fix on the file produces the following:

/* global describe, test, expect */
import { setupCustomMatchers } from '../helpers/jest'
import { SupervisorInterface } from './SupervisorInterface'
import { Supervisor } from '../Supervisor'

setupCustomMatchers(expect)

const newSupervisor = () => new Supervisor()

describe('SupervisorInterface conformance of', () => {
  test.each`
    concreteImplementationName | newInstance
    ${'Supervisor'}               | ${newSupervisor}
  `('$concreteImplementationName', ({ newInstance }) => {
  const supervisor = newInstance()
  expect(supervisor).toImplement(SupervisorInterface)

  let setPresenterResult
  expect(() => { setPresenterResult = supervisor.setPresenter(null) }).not.toThrow()
  expect(setPresenterResult).toBe(supervisor)
  expect(supervisor.getPresenter()).toBe(null)

  let setNextActionDelegatesResult
  const before = () => {}
  const after = () => {}
  expect(() => { setNextActionDelegatesResult = supervisor.setNextActionDelegates(before, after) }).not.toThrow()
  expect(setNextActionDelegatesResult).toBe(supervisor)
  expect(supervisor.getNextActionDelegates()).toEqual([before, after])
})
})

Thoughts
This only seems to apply to multiline tagged template literals. If one changes test.js and puts the tagged template literal on one line, it behaves as expected... as if it were just a simple function call. Clearly, the indentation of the template literal is affecting the indent rule.

I believe this is a problem with eslint. I have, in fact, run into the same issue with it using just eslint in the past and was able to fix it adding this to my .eslintrc (https://stackoverflow.com/a/53094449/2057996):

"indent": [{ "ignoredNodes": "TemplateLiteral > *" }]
@stale

This comment has been minimized.

Copy link

commented Mar 22, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Mar 22, 2019

@stale stale bot closed this Mar 29, 2019

@lock lock bot locked as resolved and limited conversation to collaborators Jun 27, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
1 participant
You can’t perform that action at this time.