Semicolon added on each save
See original GitHub issueSummary
A certain combination of code and modifications to that code will cause a semicolon to be added on every save, causing syntax error.
This issue was first raised on vscode here but re-directed here. VS Code system info can be found there.
Github Repository to Reproduce Issue
Link to a Github repo that can be used to reproduce the issue.
Steps To Reproduce:
- Load the repo with VS Code and VS Code Prettier extension.
- Ensure format on save is on, that Prettier is chosen as formatter and that the format on save mode is set to either
"editor.formatOnSaveMode": "modificationsIfAvailable"
or"editor.formatOnSaveMode": "modifications"
. - Open the file test_case.js (which is same as before_change.js). Copy the contents of the after_change.js onto the test_case.js file.
- Save the file and see that a semicolon is added on last line every time you save, causing Syntax error.
Expected result
No invalid semicolons added.
Additional information
This only happens on the two mentioned formatOnSaveMode modes. If the format on save is changed to "editor.formatOnSaveMode": "file"
the error doesn’t appear. So it seems to be an interplay between the way VS Code formats only the diffing parts (the diff is compared with what’s in the Git repo, see Test commit in the reproduction repo). The error doesn’t appear if there is no Git history to diff to.
Extension bisect was used to find that this error appears only with Prettier.
VS Code Version: Code 1.66.0 (https://github.com/microsoft/vscode/commit/e18005f0f1b33c29e81d732535d8c0e47cafb0b5, 2022-03-30T05:50:04.419
Prettier Extension Version: 9.5.0
OS and version: Darwin x64 18.7.0
Prettier Log Output
["INFO" - 4:05:20 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 4:05:20 PM] Extension Version: 9.5.0.
["INFO" - 4:05:36 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:36 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:36 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:36 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:36 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 130,
"rangeStart": 39
}
["INFO" - 4:05:36 PM] Formatting completed in 0.06ms.
["INFO" - 4:05:36 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:36 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:36 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:36 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:36 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 313,
"rangeStart": 313
}
["INFO" - 4:05:36 PM] Formatting completed in 0.007ms.
["INFO" - 4:05:36 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:36 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:36 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:36 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:36 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 611,
"rangeStart": 501
}
["INFO" - 4:05:36 PM] Formatting completed in 0.028ms.
["INFO" - 4:05:36 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:36 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:36 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:36 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:36 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 313,
"rangeStart": 39
}
["INFO" - 4:05:36 PM] Formatting completed in 0.008ms.
["INFO" - 4:05:39 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:39 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:39 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:39 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:39 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 130,
"rangeStart": 39
}
["INFO" - 4:05:39 PM] Formatting completed in 0.009ms.
["INFO" - 4:05:39 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:39 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:39 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:39 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:39 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 313,
"rangeStart": 313
}
["INFO" - 4:05:39 PM] Formatting completed in 0.006ms.
["INFO" - 4:05:39 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:39 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:39 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:39 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:39 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 611,
"rangeStart": 501
}
["INFO" - 4:05:39 PM] Formatting completed in 0.012ms.
["INFO" - 4:05:39 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:39 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:39 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:39 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:39 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 795,
"rangeStart": 792
}
["INFO" - 4:05:39 PM] Formatting completed in 0.008ms.
["INFO" - 4:05:39 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:39 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:39 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:39 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:39 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 313,
"rangeStart": 39
}
["INFO" - 4:05:39 PM] Formatting completed in 0.008ms.
["INFO" - 4:05:39 PM] Formatting file:///Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js
["INFO" - 4:05:39 PM] Using ignore file (if present) at /Users/martin/dev/src/repro-vscode-prettier-semicolon/.prettierignore
["INFO" - 4:05:39 PM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:05:39 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:05:39 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/martin/dev/src/repro-vscode-prettier-semicolon/test_case.js",
"parser": "babel",
"rangeEnd": 795,
"rangeStart": 39
}
["INFO" - 4:05:39 PM] Formatting completed in 0.008ms.
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:23 (8 by maintainers)
Top GitHub Comments
I’m pretty suspicious of this commit: https://github.com/prettier/prettier-vscode/commit/be790ca13b85b26196340ce2a89a1f8a47545605
Indeed, if I change my “on save” mode to “whole file” instead of “modifications”, everything works again, no extra semi colon.
any news ? This is annoying.