Code Monkey home page Code Monkey logo

Comments (10)

kddnewton avatar kddnewton commented on May 18, 2024 2

@github0013 that behavior is fixed on master and is going to be released soon. The #prettier-ignore behavior is after that. A PR would be welcome as well.

from plugin-ruby.

kddnewton avatar kddnewton commented on May 18, 2024 2

Ahh @valscion thanks for the reminder - I had forgotten to activate that. That's now in #725 and will be out in the next version.

from plugin-ruby.

AlanFoster avatar AlanFoster commented on May 18, 2024 1

@kddeisz I'm good to send a PR for this, would appreciate your thoughts on #104 (comment)

I also think this implementation will be impacted by comment handling 🤔

from plugin-ruby.

AlanFoster avatar AlanFoster commented on May 18, 2024

Hm; Tempted to take a look at this as I can see that Prettier has an escape hatch built in for this if the printer provides an implementation of hasPrettierIgnore:

https://github.com/prettier/prettier/blob/911d6c88e54a61ca72bd7712f7e2afd9de321b44/src/main/ast-to-doc.js#L97-L103

I'm thinking the implementation should look something like this:

const hasIgnoreComment = path => {
  const node = path.getValue();
  return (
    node &&
    Array.isArray(node.body) &&
    node.body.some(
      node =>
        node && node.type === "@comment" && node.body === "# prettier-ignore"
    )
  );
};

We'll also want to implement locStart and locEnd within the prettier ruby parser to slice out the original string. That way we can provide access to the node's original range within the input source that's been prettied.

That information isn't currently available within the AST though, but I could add a range member to the AST nodes like Babel:

{
    "type": "@comment",
    "body": "# prettier-ignore",
    "start": 3,
    "end": 3,
    "range": [
        46,
        64
    ]
},

@kddeisz Does this sound roughly like the right approach to follow? I'm not quite sure the best way to get the range start/end indexes - other than for scanner events though! 🤔

from plugin-ruby.

github0013 avatar github0013 commented on May 18, 2024

I also had a case where I didn't want prettier to format.

it do
  expect{ subject.action }.
    to change{ subject.some_value } # => this becomes [change do ... end] and it's a SyntaxError
end

So I tried this extension, but it didn't stop the formatting for prettier-ruby.
https://marketplace.visualstudio.com/items?itemName=tombonnike.vscode-status-bar-format-toggle

Can we at least have this extension work with prettier-ruby?

from plugin-ruby.

github0013 avatar github0013 commented on May 18, 2024

@kddeisz thanks!

yarn add https://github.com/prettier/plugin-ruby\#master

and restarted vscode, fixed the change do ... end syntax error.

it do
  expect{ subject.action }.
    to change{ subject.some_value } # =>  { ... } doesn't get modified
end

from plugin-ruby.

kddnewton avatar kddnewton commented on May 18, 2024

This is entirely predicated on #370 as that's going to change the way we do comments, just to link the two.

from plugin-ruby.

kddnewton avatar kddnewton commented on May 18, 2024

I'm going to close this as it's now entirely subsumed by #370

from plugin-ruby.

valscion avatar valscion commented on May 18, 2024

Did #370 resolve the case with # prettier-ignore? It seems to me that one still can't use # prettier-ignore to stop autoformatting in cases where the user for some reason wants to disable auto-formatting.

from plugin-ruby.

valscion avatar valscion commented on May 18, 2024

Wow thank you, you rock! We are thrilled to be able to use Prettier also for Ruby, it is so good and fast and let's me write horrible one-liners that turn into solid Ruby code 😄

from plugin-ruby.

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.