-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Prettier adding 2 spaces when using ternary operator and plain object definition #4979
Copy link
Copy link
Closed
Closed
Copy link
Labels
lang:javascriptIssues affecting JSIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.type:questionQuestions and support requests. Please use Stack Overflow for them, not the issue tracker.Questions and support requests. Please use Stack Overflow for them, not the issue tracker.
Description
Happens with any set of options but easier to see with --tab-width 4
--tab-width 4 --single-quote --trailing-comma noneInput:
function test() {
return true
? {
test1: 'test1',
test2: 'test2'
}
: {
test1: 'test1',
test2: 'test2'
};
}
console.log(test());Output:
function test() {
return true
? {
test1: 'test1',
test2: 'test2'
}
: {
test1: 'test1',
test2: 'test2'
};
}
console.log(test());Expected behavior:
function test() {
return true
? {
test1: 'test1',
test2: 'test2'
}
: {
test1: 'test1',
test2: 'test2'
};
}
console.log(test());2 extra spaces are added on lines subsequent to a ternary operator. This breaks eslint indent rule.
I set up a project showing this bug and how it breaks eslint:
clone https://github.com/DanielHoffmann/prettier-test
npm install
npm run precommit
The precommit script will run prettier with --tab-width 4 and after that will run eslint with rules: { indent: ["error", 4] }, this will always result in an error because of the 2 extra spaces mentioned before
This seems related to #4976
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
lang:javascriptIssues affecting JSIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.type:questionQuestions and support requests. Please use Stack Overflow for them, not the issue tracker.Questions and support requests. Please use Stack Overflow for them, not the issue tracker.