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

Duplicate newline added to EOF when reformatting twice #16004

Closed
mist998 opened this issue Jan 31, 2024 · 1 comment
Closed

Duplicate newline added to EOF when reformatting twice #16004

mist998 opened this issue Jan 31, 2024 · 1 comment
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@mist998
Copy link

mist998 commented Jan 31, 2024

Prettier 3.2.4

# Rules:
	"arrowParens": "avoid",
	"bracketSameLine": true,
	"bracketSpacing": true,
	"singleQuote": true,
	"trailingComma": "all",
	"semi": false,
	"printWidth": 100,
	"tabWidth": 3,
	"useTabs": true,
	"endOfLine": "crlf"

Input:

import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')!).render(
	<React.StrictMode>
		<App />
	</React.StrictMode>,
)

Output:

import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')!).render(
	<React.StrictMode>
		<App />
	</React.StrictMode>,
)

Expected output:

import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')!).render(
	<React.StrictMode>
		<App />
	</React.StrictMode>,
)

Why?
Why it decided to add 1 more newline to EOF when I reformat again (ALT+SHIFT+F) in VS Code. I expect at most 1 newline.

Additional Context
VS Code v1.85.1 with Prettier + ESLint extensions installed
node -v 18.18.2

npm create vite@latest . -- --template react-ts
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

le packages:
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.17",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"postcss": "^8.4.33",
"prettier": "3.2.4",
"tailwindcss": "^3.4.1",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}
...

@mist998 mist998 changed the title Double newline added to EOF when reformatting twice Duplicate newline added to EOF when reformatting twice Jan 31, 2024
@mist998
Copy link
Author

mist998 commented Jan 31, 2024

Findings so far:

  • change the file EOL from LF to CRLF using VS Code solves the issue
  • using prettier's CLI to rewrite files solves the issue
  • prettier was not able to convert any LF to CRLF with VS Code using keystroke ALT+SHIFT+F
  • that extra newline is still a LF even when plugin settings and config file are set to CRLF
    Screenshot_4

I guess when it remains LF it is fine but the extra LF added at 2nd reformatting is bit excessive.

@mist998 mist998 closed this as completed Jan 31, 2024
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label May 1, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

1 participant