daidodo / format-imports-vscode

Format imports and exports for JavaScript and TypeScript in VS Code.
https://marketplace.visualstudio.com/items?itemName=dozerg.tsimportsorter
MIT License
62 stars 5 forks source link

Regression in 7.4.11: Unused imports are no longer removed #67

Closed whather closed 2 years ago

whather commented 2 years ago

I noticed unused imports are no longer getting removed for me when upgrading to 7.4.11 and beyond. Works in 7.4.10.

daidodo commented 2 years ago

@whather, thanks for the feedback!

Could you provide steps to reproduce the issue?

cmlenz commented 2 years ago

I have the same problem, downgrading to 7.4.10 fixed it for now.

I have configured JS/TS Import/Export Sorter in the VSCode workspace settings.json as follows:

  "tsImportSorter.configuration.groupRules": ["^@?[a-z]", {}, "^[@]", "^@/", "^[.]{2}/", "^[.]/", {"flags": "scripts"}],
  "tsImportSorter.configuration.wrappingStyle": {
    "maxBindingNamesPerLine": 0,
    "maxNamesPerWrappedLine": 0
  },

We are using TypeScript ts and tsx. We also have ESLint setup with an .eslintrc.js file at the top level of the project.

daidodo commented 2 years ago

@cmlenz Could you build a demo repo to reproduce the issue? Or sharing debug logs would also help.

Thanks!

cmlenz commented 2 years ago

It seems to be working again with 7.4.13, so maybe the same issue as #66?

However, now my named imports are formatted like this:

import { A, B } from 'stuff';

Whereas previously they were imported without the spaces in the curlies:

import {A, B} from 'stuff';

Sorry for hijacking this ticket, but did something in the regard change since 7.4.10? Is the ESLint rule object-curly-spacing not used to determine this?

Here's the output from extension:

[2022-04-01T11:10:37.037] [INFO] default - vscode: { version: '1.66.0' }
[2022-04-01T11:17:04.976] [INFO] vscode.resolveConfig - Resolving config for fileName: a.tsx languageId: typescriptreact
[2022-04-01T11:17:04.978] [WARN] format-imports.loadPretConfig - Failed to load Prettier/EditorConfig config for filename: a.tsx with error: Cannot read properties of undefined (reading 'sync')
[2022-04-01T11:17:05.209] [INFO] format-imports.extractOptions - Found ESLint rule sort-imports: {
  ignoreCase: true,
  ignoreDeclarationSort: true,
  ignoreMemberSort: false,
  memberSyntaxSortOrder: [ 'none', 'all', 'multiple', 'single' ],
  allowSeparatedGroups: false
}
[2022-04-01T11:17:05.210] [INFO] format-imports.extractOptions - Found ESLint rule import/newline-after-import: { count: 1 }
[2022-04-01T11:17:05.210] [INFO] format-imports.extractOptions - Found ESLint rule max-len: {
  code: 120,
  tabWidth: 2,
  ignoreTrailingComments: false,
  ignoreComments: true,
  ignoreRegExpLiterals: true,
  ignoreStrings: true,
  ignoreTemplateLiterals: true
}
[2022-04-01T11:17:05.210] [INFO] format-imports.extractOptions - Found ESLint rule indent: 2
[2022-04-01T11:17:05.210] [INFO] format-imports.extractOptions - Found ESLint rule eol-last: always
[2022-04-01T11:17:05.210] [INFO] format-imports.extractOptions - Found ESLint rule @typescript-eslint/semi: always
[2022-04-01T11:17:05.210] [INFO] format-imports.extractOptions - Found ESLint rule comma-dangle: {
  arrays: 'always-multiline',
  exports: 'never',
  functions: 'always-multiline',
  imports: 'never',
  objects: 'always-multiline'
}
[2022-04-01T11:17:05.210] [INFO] format-imports.formatSource - Formatting a.tsx with enhanced config: {
  configurationFileName: 'import-sorter.json',
  autoFormat: 'onSave',
  formatExports: true,
  exclude: [ 'node_modules' ],
  excludeGlob: [],
  sortImportsBy: 'paths',
  groupRules: [
    '^@?[a-z]',
    {},
    '^[@]',
    '^@/',
    '^[.]{2}/',
    '^[.]/',
    { flags: 'scripts' }
  ],
  sortRules: { paths: [ '_', 'aA' ], names: [ '_', 'aA' ] },
  keepUnused: [],
  emptyLinesBetweenGroups: 1,
  emptyLinesAfterAllImports: 1,
  removeLastSlashInPath: true,
  removeLastIndexInPath: true,
  wrappingStyle: {
    maxBindingNamesPerLine: 0,
    maxDefaultAndBindingNamesPerLine: 2,
    maxExportNamesPerLine: 0,
    maxNamesPerWrappedLine: 0,
    ignoreComments: true
  },
  development: { enableDebug: false },
  insertFinalNewline: true,
  eol: 'LF',
  force: false,
  maxLineLength: 120,
  tabType: 'space',
  tabSize: 2,
  hasSemicolon: true,
  trailingComma: 'none'
}
[2022-04-01T11:17:05.244] [INFO] vscode.formatDocument - Finished format
daidodo commented 2 years ago

Yes, I think the 2 issues should be related.

Could you create a new issue for object-curly-spacing? I can confirm that this rule is NOT considered by the plugin. But I can add it in the next release.