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

v4 of PrettierPluginSortImports moves ngAnnotate 'ngInject' within the files as if they are imports #205

Closed
1 task
mtpultz1977 opened this issue Jan 27, 2023 · 1 comment

Comments

@mtpultz1977
Copy link

mtpultz1977 commented Jan 27, 2023

Your Environment

  • Prettier version: 2.8.3
  • node version: 18.12.1
  • package manager: npm@8.19.2
  • IDE: VScode

Describe the bug

Updating from v3.4.0 to v4.0.0 in our AngularJS application started to move ngAnnotate 'ngInject' statements to the top of files as if they were imports.

To Reproduce

This is an AngularJS function that I've altered to allow it to be used for reproduction. Opening this in VSCode and saving any change in move all lines with 'ngInject'; to the top of the file with the imports.

import material from './material';
import textAngular from './textAngular';

export { material, textAngular };

export default function () {
  'ngInject';

  const $httpProvider = { interceptors: [] };

  $httpProvider.interceptors.push(($state, $rootScope) => {
    'ngInject';

    return {
      responseError(response) {
        if (response.status === 401) {
          $rootScope.notAuthorized = true;
          $state.go('dashboard', {}, { location: false });
        }
      },
    };
  });
}

Result after saving the file:

'ngInject';
'ngInject';

import material from './material';
import textAngular from './textAngular';

export { material, textAngular };

export default function () {
  const $httpProvider = { interceptors: [] };

  $httpProvider.interceptors.push(($state, $rootScope) => {
    return {
      responseError(response) {
        if (response.status === 401) {
          $rootScope.notAuthorized = true;
          $state.go('dashboard.notauthorized', {}, { location: false });
        }
      },
    };
  });
}

Expected behaviour

'ngInject'; would not be moved since it isn't an import.

Screenshots, code sample, etc

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

In this particular part of the application import order has no rules due to it being legacy code.

{
  "singleQuote": true
}

Error log

No error it is purely a formatting issue.

Contribute to @trivago/prettier-plugin-sort-imports

  • I'm willing to fix this bug 🥇
@c-dante
Copy link
Contributor

c-dante commented Feb 4, 2023

Already have a PR open to fix this: #198

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

No branches or pull requests

2 participants