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

IIFE with leading semicolon wants to be intended when directly after imports #11082

Closed
kjg opened this issue Nov 13, 2018 · 2 comments · Fixed by #11085
Closed

IIFE with leading semicolon wants to be intended when directly after imports #11082

kjg opened this issue Nov 13, 2018 · 2 comments · Fixed by #11085
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly indent Relates to the `indent` rule rule Relates to ESLint's core rules

Comments

@kjg
Copy link

kjg commented Nov 13, 2018

Tell us about your environment

  • ESLint Version: 4.18.2
  • Node Version: 8.9.3
  • npm Version: 6.4.1

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

Please show your full configuration:

Configuration
{
    "parserOptions": {
      "ecmaVersion": 2018,
      "ecmaFeatures": {
        "jsx": true
      },
      "sourceType": "module"
    },

    "rules": {
      "indent": ["error", 2]
    }
  }

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

// Imports
import $ from 'jquery'

// Bootstrap
;(() => {
  window.$ = $
})()
node_modules/.bin/eslint -c .eslintrc testFile.js

What did you expect to happen?
No error, no change of indention needed.

What actually happened? Please include the actual, raw output from ESLint.
It wants the ;(() => { line of the iife with leading semicolon to be indented

5:1  error  Expected indentation of 2 spaces but found 0  indent

✖ 1 problem (1 error, 0 warnings)
  1 error, 0 warnings potentially fixable with the `--fix` option.

Interestingly if I move this IIFE to below other code, ESLint doesn't try to indent it, only when it's the first bit of code after the import statement.

No errors from:

// Imports
import $ from 'jquery'

function foo (){}

// Bootstrap
;(() => {
  window.$ = $
})()

Are you willing to submit a pull request to fix this bug?
I'm willing to, but I couldn't easily figure out exactly which part of the indent rule code was causing this

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Nov 13, 2018
@not-an-aardvark not-an-aardvark added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion indent Relates to the `indent` rule and removed triage An ESLint team member will look at this issue soon labels Nov 13, 2018
@not-an-aardvark
Copy link
Member

Thanks for the report, I can reproduce this issue. It seems to be happening as a result of this line, which declares that the offset of everything after a from token in an import is offset by one indent level. It should probably be updated to ensure that trailing semicolons are excluded from that.

@sstern6
Copy link
Contributor

sstern6 commented Nov 14, 2018

I dont mind taking a look at this.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators May 18, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label May 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly indent Relates to the `indent` rule rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants