Comments (6)
Thanks @havenchyk, I added the bug label with help wanted for now. A new test case would be very helpful.
from prettierx.
I think this feature is working as intended. Space does come before the function paren in the formatted code.
And I get the same results when using eslint with the following settings in .eslintrc.yml
config:
parser: '@typescript-eslint/parser'
space-before-function-paren: ["error", "always"]
in rules
In case you are looking for something different, please give some more details about what you are looking for, if you can find an existing eslint rule that would support the desired formatting, and what kind of justification you can find. Contributions are always welcome for consideration.
I am not in a position to make any promises within the standard free support on GitHub but would be happy to discuss and consider supporting this kind of feature for hire. Please contact [email protected] in case of any interest.
from prettierx.
@brodybits seems I mixed up everything, let me try once again.
with --space-before-function-paren
this space should be added, so next example is correct
function foo<T> (x: T): T { // <-- space between <T> and (x: T)
return x
}
but the default value for --space-before-function-paren
is false
and if I don't pass it, I expect to receive
function foo<T>(x: T): T { // <-- no space between <T> and (x: T)
return x
}
and it's exactly what eslint does with the rule you mentioned:
And I get the same results when using eslint with the following settings in .eslintrc.yml config:
parser: '@typescript-eslint/parser'
space-before-function-paren: ["error", "always"] in rules
But prettierx adds this space anyway, disregarding flag value.
Hope it's a better explanation. And if you confirm it's a wrong behavior I'm ready to help with it
from prettierx.
I still do not see your issue. Here is what I tried:
Taking the following TypeScript that I saved as example.ts
:
function foo<T> (x: T): T {
return x
}
Tried with prettier version 1.19.1
: prettier example.ts > fix1.ts
, here is the result:
function foo<T>(x: T): T {
return x;
}
Next try with prettierx version 0.10.0
, along with TypeScript 3.7.2 which is no longer bundled: prettierx example.ts > fix2.ts
gives me this result:
function foo<T>(x: T): T {
return x;
}
And another test: prettierx --space-before-function-paren example.ts
gives me:
function foo<T> (x: T): T {
return x;
}
And then still the same results if I would do cp example.ts example.js
and try the same things on the JavaScript files.
from prettierx.
@brodybits my bad. I was sure that prettier-standard just uses prettierx
for formatting, but seems it's not only prettierx
. So even old (0.7.1) version works correctly.
The correct version of broken code is
const foo = function<T>(bar: T) {
return bar
}
prettier-standard adds a space between <T>
and (bar: T)
, prettierx handles this correctly.
Sorry for bothering you @brodybits and thanks for you help!
btw, I see that prettierx
even supports optional chaining in latest version
from prettierx.
@brodybits new info came.
import prettierx from 'prettierx'
const options = {
spaceBeforeFunctionParen: false,
generatorStarSpacing: true,
yieldStarSpacing: true,
singleQuote: true,
semi: false,
jsxSingleQuote: true,
useTabs: true,
endOfLine: 'lf',
filepath: '/Users/havenchyk/projects/test-prettierx/index.ts',
parser: 'typescript'
}
const text = 'const foo = function<T>(bar: T) { return bar }'
const formatted = prettierx.format(text, options)
console.log(formatted)
/**
* const foo = function<T> (bar: T) {
* return bar
* }
*/
Tried it with version 0.10
. Am I doing formatting wrong? I'm also surprised it's different from the result from CLI
from prettierx.
Related Issues (20)
- improve formatting between long function param and long type param HOT 2
- [prettierx] more flexible ternary conditional expression formatting
- [prettierx] Yarn audit issues in transitive dependencies HOT 18
- improve "smart formatting" of HTML class attributes
- option: Break line and indent on nested conditions
- more flexible breaks in assignment statements?
- Prettier vs prettierX in docs
- Test build with Rollup only (no Webpack)
- [prettierx] changed indenting of curried arrow functions should be optional
- followup re: Prettier 2.3.2 & PostCSS 8 updates
- 💡[prettierX] generate pretty-printed code from Babel AST
- [prettierX] parallel / clustered Prettier
- [prettierX] better HTML whitespace sensitivity? HOT 1
- Dependency Dashboard
- Breaks CSS pseudo-class inside a template literal
- Use of enums in object declaration causes failure with --align-object-properties & TypeScript HOT 4
- Having to manually update via npm every other day to keep the extension working?
- Update minimist version to fix security issues HOT 2
- Configure empty lines? HOT 4
- Line-break each argument in TS class constructor definitions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettierx.