Code Monkey home page Code Monkey logo

Comments (6)

brodybits avatar brodybits commented on July 17, 2024 1

Thanks @havenchyk, I added the bug label with help wanted for now. A new test case would be very helpful.

from prettierx.

brodybits avatar brodybits commented on July 17, 2024

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.

havenchyk avatar havenchyk commented on July 17, 2024

@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.

brodybits avatar brodybits commented on July 17, 2024

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.

havenchyk avatar havenchyk commented on July 17, 2024

@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.

havenchyk avatar havenchyk commented on July 17, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.