Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

ESLint auto fix corrupts code #343

Closed
OliverJAsh opened this issue Aug 4, 2017 · 1 comment
Closed

ESLint auto fix corrupts code #343

OliverJAsh opened this issue Aug 4, 2017 · 1 comment
Labels

Comments

@OliverJAsh
Copy link

OliverJAsh commented Aug 4, 2017

Note: I have created the smallest reproduction case I can find and published it to https://github.com/OliverJAsh/typescript-eslint-fix-issue. You can reproduce my issue by cloning the repo, running yarn, and then running eslint --fix test.js. Below I have pasted the same file contents.

What version of TypeScript are you using?
2.4.2

What version of typescript-eslint-parser are you using?
4.0.0

What code were you trying to parse?

// test.js
import React from "react";

const Foo = () =>
  <div>
    {true
      ? null
      : <a>
          {"foo"}
        </a>}
  </div>;

with .eslintrc.js:

module.exports = {
  parser: 'typescript-eslint-parser',
  extends: 'airbnb',
};

and package.json:

{
  "private": true,
  "dependencies": {
    "eslint": "4.3.0",
    "eslint-config-airbnb": "15.1.0",
    "eslint-plugin-import": "2.7.0",
    "eslint-plugin-jsx-a11y": "6.0.2",
    "eslint-plugin-react": "7.1.0",
    "react": "15.6.1",
    "typescript": "2.4.2",
    "typescript-eslint-parser": "4.0.0"
  }
}

What did you expect to happen?
When I run eslint --fix test.js, test.js should contain the ESLint auto fixes.

What happened?
When I run eslint --fix test.js, I get an error:

/Users/OliverJAsh/Development/temp/typescript-eslint-fix-issue/test.js
  10:17  error  Parsing error: ',' expected

and test.js is corrupted:

import React from 'react';

const Foo = () =>
  (<div>
    {true
      ? null
      : <a>
          {"foo"}
        </a>}
  </div>)        import React from "react";

const Foo = () =>
  <div>
    {true
      ? null
      : <a>
          {'foo'}
            import React from "react";

const Foo = () =>
  <div>
    {true
      ? null
      : <a>
          {"foo"}
        </a>}
  </div>;

Notes

This only appears to occur when using typescript-eslint-parser. The auto fixes work if I remove this parser.

I am unsure which ESLint rules it is having trouble with, but I suspect it's the ones in eslint-plugin-react.

Possibly related to #213.

@JamesHenry
Copy link
Member

Thanks a lot for providing the repo @OliverJAsh! I just tried rerunning this after updating all of the dependencies to latest and can no longer reproduce the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants