惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
B
Blog
L
LangChain Blog
Y
Y Combinator Blog
美团技术团队
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
量子位
博客园_首页
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
Check Point Blog
D
Docker
小众软件
小众软件
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
IT之家
IT之家

Prettier Blog

Prettier 3.9: Major parser upgrades and Formatting improvements Prettier 3.8: Support for Angular v21.1 Prettier 3.7: Improved formatting consistency and new plugin features! Prettier 3.6: Experimental fast CLI and new OXC and Hermes plugins! Prettier 3.5: New objectWrap option, experimentalOperatorPosition option and TS config file support! Prettier 3.4: A lot of bug fixes Prettier 3.3: New Flow features and a lot of bug fixes Prettier 3.2: Support JSONC and Angular’s ICU expression Prettier's CLI: A Performance Deep Dive $20k Bounty was Claimed! Prettier 3.1: New experimental ternaries formatting and Angular control flow syntax! A curious case of the ternaries Prettier 3.0: Hello, ECMAScript Modules! Prettier 2.8: improve --cache CLI option and TypeScript 4.9 satisfies operator! Prettier 2.7: new --cache CLI option and TypeScript 4.7 syntax! Prettier 2.6: new singleAttributePerLine option and new JavaScript features! Prettier begins paying maintainers Prettier 2.5: TypeScript 4.5 and MDX v2 comment syntax! Prettier 2.4: new bracketSameLine option and TypeScript 4.4 support! Prettier 2.3. In which assignments are consistent, short keys non-breaking, and Handlebars official
Prettier for Ruby goes v1.0 🎉
Kevin Newton · 2020-12-11 · via Prettier Blog

After 1500 commits and 50 releases since July 2018, we're happy to announce that we've just released v1.0 of Prettier for Ruby. In this blog post, we'd like to give a short overview of how the plugin works, its philosophy, and what to expect in the future.

How does it work?

Prettier for Ruby works through Prettier's plugin API. Its parse function works by spawning a Ruby process and using Ruby's own parser (known as Ripper). After tracking all of the various node types, comments, location information, and other various metadata, it returns a built abstract syntax tree (AST) to the Prettier process. Finally it converts that AST into Prettier's intermediate representation (known as Doc) before allowing Prettier to handle printing it back out.

Philosophy

The Ruby plugin attempts to be satisfied with as many varieties of code as possible. For instance, if you decide to a call a method with or without parentheses, the plugin will allow this and honor your selection. For a couple of instances where the Ruby community has entrenched itself into some strong opinions, however, options are provided. These include:

  • rubyArrayLiteral - By default, the Ruby plugin will convert arrays of simple strings and symbols to their equivalent array literal syntax (%w and %i, respectively). If you disable this option, it will leave them alone.
  • rubyHashLabel - This option is for the fans of the hash rocket. By default, the Ruby plugin will print out your hash keys consistently, i.e., it will use labels if it can for every key, otherwise it will use hash rockets for every key. If you disable the default behavior, every key in hashes will always use hash rockets.
  • rubyModifier - For the users that really dislike the modifier form of if, unless, while, and until, this option is for you.
  • rubySingleQuote - The default behavior is to use single quotes where it makes sense, and otherwise to use double quotes. With this option you can reverse that behavior.
  • rubyToProc - This option allows Prettier to convert statements like array.map { |elem| elem.to_s } to array.map(&:to_s). It is disabled by default because it technically changes the arity of block, which can break reflection code.

The plugin additionally supports various Prettier core options, including:

  • printWidth - This defaults to 80 characters, but you can make the line longer if you prefer.
  • tabWidth - This defaults to 2 characters.
  • trailingComma - This defaults to "none", but you can choose "all" to introduce trailing commas into array literals, hash literals, and argument lists that span multiple lines.

In general the style of Prettier will match that of the Ruby style guide, i.e., the default Rubocop configuration. However, while you're using Prettier you might just find that you want to turn off the Formatting/* rules from Rubocop anyway as it will speed up your linter runs.

What's next

Going forward, we're going to be working on a couple of things:

  • Support for the new syntax coming out with Ruby 3, including rightward assignment and more pattern matching.
  • Better performance, as in these experiments.
  • Support for the Ruby language in Prettier's playground.
  • Support for HTML ERB templates as another plugin, as in this experiment.

Today, you can try the plugin from the command line by following the instructions in the README. Definitely report any bugs that you find, we're working diligently to make sure they're squashed as soon as they come up. Also feel free to get started contributing to the project itself if you're interested.