angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Bug: `ng lint -fix`

Open mikeumus opened this issue 9 years ago • 11 comments

OS

Windows 7 Professional

Version

1.0.0-rc1

Repro steps

ng lint --fix

The log given by the failure

No error in logs, --fix is zealous for semicolons producing things like this: r;eturn; true;

🤖 ; 🤖 ; 🤖 ; 😱🌬

mikeumus avatar Mar 13 '17 21:03 mikeumus

Similar problem here. ng lint --fix broke literally every file it "fixed".

For example it changed double quotes like this: key: ["some", "valeus"] => key: [" 'some value' It deleted brackets, commas and added random spaces.

Here's a real example: Before: tags: ["concert", "festival", "band", "live"], blurb: "Music festivals, live sets and cozy concerts." },

After: tags: ["c'concert'"f'festival'"b'band'"l'live' blurb: "M'Music festivals, live sets and cozy concerts.' },

mikeeus avatar Mar 15 '17 06:03 mikeeus

@mikeumus or @mikeeus, if you can give me a repo that reproduces this issue, I'll take a look at it this weekend and see what I can do to solve this issue.

delasteve avatar Mar 17 '17 05:03 delasteve

I cannot reproduce this. On src/app/app.component.ts I added:

function func() {
  var str = "str";
  var obj = {
    tags: ["concert", "festival", "band", "live"],
    blurb: "Music festivals, live sets and cozy concerts."
  }
  return true;
}

And ng lint --fix changed it to:

function func() {
  const str = 'str';
  const obj = {
    tags: ['concert', 'festival', 'band', 'live'],
    blurb: 'Music festivals, live sets and cozy concerts.'
  };
  return true;
}

Cannot see any mangling of the return statement or strings. If I had to bet, it was a bug on a specific version of tslint.

If you can produce a simple repo we can look at it.

filipesilva avatar Mar 18 '17 12:03 filipesilva

I can't share my project, @mikeeus can you share yours?

Maybe Windows 7 is the culprit. @mikeeus which OS are you on?

mikeumus avatar Mar 18 '17 16:03 mikeumus

I've seen this happen on macOS as well, but it was on a friends project and I thought it was related to TSLint rather than the CLI.

I don't need the entire project. If you can get it to happen on a new project while editing the app.component.ts, that should be plenty to go off of.

delasteve avatar Mar 18 '17 16:03 delasteve

I tried my repro on win10.

filipesilva avatar Mar 18 '17 20:03 filipesilva

Here's my package.json and .angular-cli.json as snippets in this Stack Overflow question:

  • http://stackoverflow.com/q/42846582/1762493

Can get my app.component.ts later.

mikeumus avatar Mar 20 '17 02:03 mikeumus

Thanks to @intellix, we found a project that has this problem. There is a strange interaction between --fix and --type-check. There will be an issue filed with TSLint once we have a slimmed down project to find the exact issue.

That said, we agreed on a --type-check flag for ng lint (#5589). This should take care of the problem. The flag is going to be set to false by default so that this error doesn't happen again.

It will be in before the final release. Hope this helps!

delasteve avatar Mar 23 '17 15:03 delasteve

Very cool. Good work @delasteve and @intellix ! :smile:

mikeumus avatar Mar 24 '17 02:03 mikeumus

I still see this behavior when running ng lint --fix.

Here's my version: @angular/cli: 1.0.3 node: 6.9.1 os: win32 x64 @angular/cli: 1.0.3

czimmons avatar Jun 08 '17 22:06 czimmons

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.