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

[Bug] refactoring changes code formatting #96172

Closed
AbdelrahmanHafez opened this issue Apr 26, 2020 · 3 comments
Closed

[Bug] refactoring changes code formatting #96172

AbdelrahmanHafez opened this issue Apr 26, 2020 · 3 comments
Assignees

Comments

@AbdelrahmanHafez
Copy link

When extracting a code block into a function in global scope, the code formatting often changes in the sense that all empty lines are removed, and some parts go into new lines in themselves.

I would expect the formatting to stay the same.

  • VSCode Version: 1.44.2 (system setup)
  • OS Version: Windows_NT x64 10.0.18363

Steps to Reproduce:

Let's look at this code for example:

const mongoose = require('mongoose');
const { Schema } = mongoose;
const assert = require('assert');


run().catch(console.error);

async function run () {
  // Beginning of code block I want to refactor
  await mongoose.connect('mongodb://localhost:27017/test', {
    useNewUrlParser: true,
    useUnifiedTopology: true
  });

  await mongoose.connection.dropDatabase();

  if (true) console.log('on the same line with condition');
  // End of code block I want to refactor

  const userSchema = new Schema({
    name: { type: String }
  });

  const User = mongoose.model('User', userSchema);

  assert.ok(User.findOne);
  console.log('Done.');
}

When I separate the code between the two comments into a function in the global scope, all the empty lines are removed, and the console.log(...) is moved to the next line after the condition.

const mongoose = require('mongoose');
const { Schema } = mongoose;
const assert = require('assert');


run().catch(console.error);

async function run () {
  await prepareConnection();

  const userSchema = new Schema({
    name: { type: String }
  });

  const User = mongoose.model('User', userSchema);

  assert.ok(User.findOne);
  console.log('Done.');
}

async function prepareConnection() {
  await mongoose.connect('mongodb://localhost:27017/test', {
    useNewUrlParser: true,
    useUnifiedTopology: true
  });
  await mongoose.connection.dropDatabase(); // empty line above and below are deleted
  if (true)
    console.log('on the same line with condition'); // should move to the line above
}

Does this issue occur when all extensions are disabled?: Yes

@mjbvz mjbvz self-assigned this Apr 26, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Apr 26, 2020

Duplicate of microsoft/TypeScript#27294

@mjbvz mjbvz marked this as a duplicate of microsoft/TypeScript#27294 Apr 26, 2020
@mjbvz mjbvz closed this as completed Apr 26, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Apr 26, 2020

We won't include TypeScript 3.9 with this fix until VS Code 1.46. Until then, try upgrading your workspace to use typescript@next by installing this extension

@AbdelrahmanHafez
Copy link
Author

Thank you.
So in VSCode 1.46, would this be fixed by default? Will I need to set some option? Too early to tell?

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

No branches or pull requests

2 participants