Skip to content

add --ignore-space to ng init d (diff) command #2083

Closed

Description

@bougnat12

This is not an issue but a feature request.

The aim is to avoid to lost a lot of time when migrating from angular-cli version to a new one only because there is a lot of diffs due to spacing (indentation of 2 or 4 spaces for example).

I suggest to add an --ignore-space option (or --ignore-diff-space) to the ng init command to resolve this issue.

Activity

  1. Kiougar commented on Dec 2, 2016

    @Kiougar

    @bougnat12 @filipesilva
    I have made a pull request to the jsdiff module, which is used to generate the diff. When that pull request is accepted I would gladly create a pull request to this repo to add the --ignore-space option.

    Another option I would also suggest is --ignore-line-endings. That way the diff is more accurate and does not display every line as changed.

    Maybe the functionality of these two options should be merged into one?

    What do you think?

  2. Kiougar commented on Dec 26, 2016

    @Kiougar

    @filipesilva
    jsdiff v3.2.0 has been released that includes my previously mentioned pull request.

    Should I proceed with a pull request in this repo that adds the --ignore-space option?

  3. filipesilva commented on Dec 28, 2016

    @filipesilva
    Contributor

    Heya @Kiougar, thanks for the work getting those features into jsdiff! I would appreciate a PR here to use it, yes.

    Unless there are strong opinions otherwise, my instinct says to just default to --ignore-space and --ignore-line-endings, without presenting the options even. It's also easier to implement this way.

  4. Kiougar commented on Dec 28, 2016

    @Kiougar

    Hey @filipesilva.

    I'm not sure if we should default to ignore-space since the ignoreWhitespace option of the diff module removes the formatting of the code when it is outputted to the console (see below for sample output).
    I personally do not care about the formatting, since it is only a visual issue; but it might be misleading to some people, that when accepting the differences the new file would lose the formatting.

    Also, the ignore-line-endings (which AFAIK the diff module does not support - correct me if I'm wrong) has to be solved with the following "trick":

    • Use .replace(/\r\n/g, "\n") on both strings that need to be compared so that they have the same line endings.

    The ignore-line-endings can be implemented by default since I don't see any scenarios that it might not work properly.


    Here is an example of the output with ignore-line-endings and ignore-space:

    Old file contents:

    import { AppModule } from './app/';
    
    if (environment.production) {
      enableProdMode();
    }
    if (a) {
      if (b) {
        func();
      } else {
        func2();
      }
    } else {
      func3();
    }

    New file contents:

    import {AppModule} from './app/';
    
    if (environment.production) {
        enableProdMode();
    }
    if (a) {
        if (b) {
            func1();
        } else {
            func2();
            func21();
        }
    } else {
        func3();
    }

    createPatch output:

    Index: filename
    ===================================================================
    --- filename
    +++ filename
    @@ -1,14 +1,15 @@
    -import { AppModule } from './app/';
    +import {AppModule} from './app/';
     
     if (environment.production) {
     enableProdMode();
     }
     if (a) {
     if (b) {
    -func();
    +func1();
     } else {
     func2();
    +func21();
     }
     } else {
     func3();
     }

    source


    Edit: If you click the source link the output will not be properly displayed until you click inside the output container. Don't know why this happens...

  5. hansl commented on Feb 7, 2017

    @hansl
    Contributor

    We're getting rid of update and init because they won't be needed after the release. They were temporary tools that were useful during the rough transition from beta, and going forward the only things needed for upgrading from 1.0.0 to 1.0.1 will be to npm install.

  6. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    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.

  7. locked and limited conversation to collaborators on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions