Closed prescience-data closed 10 months ago
That seems like a bug with the code that adds the import statement? It should add it on the next line. Does that occur with the dprint plugin disabled?
No once the plugin is disabled, the IDE behaves normally.
I don't understand what this plugin would have to do with putting that import on the incorrect line. @ryan-rushton any ideas?
Other interesting effects:
"compact" format: correct format:
(for clarity - each time a file is corrected, the other files that were previously corrected reset back to this strange "compact" state. this does not appear to occur when using the cli dprint fmt
directly)
imports
:with dprint plugin:
without dprint plugin:
Not sure if any of these might be relevant but thought it might help with isolation:
eslint
is enabledpnpm
as package manager@microsoft/rush
monorepo.editorconfig
file (provided below)root = true
# Global Settings
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
# IntelliJ IDE Settings
ij_any_if_brace_force = always
ij_editorconfig_align_group_field_declarations = false
ij_javascript_spaces_within_array_initializer_brackets = true
ij_markdown_force_one_space_after_header_symbol = true
ij_markdown_max_lines_around_block_elements = 1
ij_markdown_max_lines_around_header = 1
ij_markdown_max_lines_between_paragraphs = 1
ij_markdown_min_lines_around_block_elements = 1
ij_markdown_min_lines_around_header = 1
ij_markdown_min_lines_between_paragraphs = 1
ij_typescript_align_imports = false
ij_typescript_array_initializer_wrap = on_every_item
ij_typescript_catch_on_new_line = false
ij_typescript_continuation_indent_size = 2
ij_typescript_blank_lines_after_imports = 1
ij_typescript_else_on_new_line = false
ij_typescript_import_merge_members = true
ij_typescript_indent_chained_calls = true
ij_typescript_indent_size = 2
ij_typescript_jsdoc_include_types = true
ij_typescript_line_comment_add_space = true
ij_typescript_line_comment_at_first_column = true
ij_typescript_space_after_colon = true
ij_typescript_space_after_comma = true
ij_typescript_spaces_within_array_initializer_brackets = true
ij_typescript_spaces_within_imports = true
ij_typescript_use_chained_calls_group_indents = true
ij_typescript_use_public_modifier = false
ij_typescript_while_brace_force = always
ij_typescript_wrap_comments = true
ij_visual_guides = 80, 120, 200
ij_vue_continuation_indent_size = 2
ij_vue_indent_size = 2
ij_vue_interpolation_new_line_after_start_delimiter = true
ij_vue_interpolation_new_line_before_end_delimiter = true
ij_vue_interpolation_wrap = off
ij_vue_keep_indents_on_empty_lines = false
ij_vue_spaces_within_interpolation_expressions = true
ij_vue_tab_width = 2
{
"$schema": "https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest/schema.json",
"includes": [
"**/*.{ts,tsx,js,cjs,mjs,vue,json,md}"
],
"excludes": [
"**/lib/",
"**/dist/",
"**/node_modules/",
"**/jspm_packages/",
"**/.rush/",
"**/.heft/",
"**/.cache/",
"**/temp/"
],
"incremental": true,
"indentWidth": 2,
"useTabs": false,
"lineWidth": 80,
"plugins": [
"https://plugins.dprint.dev/typescript-0.68.2.wasm",
"https://plugins.dprint.dev/prettier-0.7.0.json@4e846f43b32981258cef5095b3d732522947592e090ef52333801f9d6e8adb33",
"https://plugins.dprint.dev/json-0.15.2.wasm",
"https://plugins.dprint.dev/markdown-0.13.2.wasm"
],
"json": {
"indentWidth": 2
},
"prettier": {
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"printWidth": 80,
"proseWrap": "always",
"semi": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false,
"vueIndentScriptAndStyle": true
},
"typescript": {
"lineWidth": 80,
"indentWidth": 2,
"useTabs": false,
"semiColons": "asi",
"quoteStyle": "alwaysDouble",
"trailingCommas": "never",
"newLineKind": "lf",
"spaceAround": true,
"useBraces": "always",
"taggedTemplate.spaceBeforeLiteral": false,
"importDeclaration.spaceSurroundingNamedImports": true,
"constructorType.spaceAfterNewKeyword": true,
"typeAssertion.spaceBeforeExpression": false,
"constructor.spaceBeforeParentheses": false
}
}
Current debugging efforts have been to remove typescript
and prettier
plugins individually to see if there was any conflict.
First, @prescience-data what version of the plugin are you running? There have been a couple of changes that are being evolved atm to integrate into the actual IntelliJ formatter but it isn't complete just yet. I am currently working on improving this with the latest schema version.
If you are on the latest, I thiiink this is due to how the new IntelliJ code refactoring system works. Basically, when refactoring (and I think adding imports is included here) IntelliJ creates a pseudo file with the changes, it tries to run the configured formatter over these. The issue we have is that file won't have a filepath so we don't actually format it. For a setup like this we should just format it anyway but for a repo where some TS files may be formatted and some might not be, we cannot do that. Another option would be to go back to letting IntelliJ format those files, I disabled that recently for a Java issue.
I have noticed this behavior with a custom Java setup we are running but it isn't an issue as semicolons are necessary so it can easily format them.
Also thanks for the report! It is pretty early days for this plugin still so I am stoked people are finding use for it, I will try get this fixed ASAP for you.
Yeah I noticed if I force semicolons it manages to recover and complete the formatting.
Unfortunately for this project the existing style guide across the team is no semis so I'll keep tinkering around.
Regarding the version, it's just whatever the latest one published to the Jetbrains plugin system is.
Thanks for the info above 🕺🏻
All good, I think it is a fairly easy fix in that we will let IntelliJ perform AdHoc formatting (formatting for pseudo files) and we should get around the issue for now.
@dsherret one thing we could do to get around this is to send something to dprint to force a format even if we don't have a file path. This would allow us to perform the AdHoc formatting but we still have the inconsistency where we might partially format something that is ignored in the globs. I will do a bit of digging into the IntelliJ API to see if I can figure out what the destination file path is for AdHoc formatting and maybe we can use that.
we might partially format something that is ignored in the globs.
Not sure if this would be too "janky", but perhaps if the destination path idea doesn't pan out, it could make a copy of the ignored files, and restore the pre-formatted versions post-format if it notices they have changed?
@prescience-data has your issue been fixed with the new version?
Closing as stale
Not sure if this is a configuration or plugin issue, but thought I'd log it just in case:
When I auto complete an import in a TypeScript file with
dprint
turned on it imports it to the end of the preceeding import, which breaks due to having semicolons set tonever
.This causes a scenario the formatter cannot process / recover from.
Example