Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@prettier/plugin-ruby
Advanced tools
@prettier/plugin-ruby is a plugin for Prettier that adds support for formatting Ruby code. It ensures that Ruby code adheres to a consistent style, making it easier to read and maintain.
Code Formatting
This feature automatically formats Ruby code to follow a consistent style. For example, it ensures proper indentation and spacing.
def hello_world
puts 'Hello, world!'
end
Consistent Style
This feature enforces a consistent coding style across Ruby files, such as consistent use of spaces, line breaks, and other stylistic elements.
class Person
attr_accessor :name, :age
def initialize(name, age)
@name = name
@age = age
end
end
Integration with Prettier
This feature allows the plugin to be easily integrated with Prettier, enabling seamless formatting of Ruby code alongside other supported languages.
{
"plugins": ["@prettier/plugin-ruby"]
}
Standard is a Ruby style guide, linter, and formatter based on RuboCop. It enforces a standard style and can automatically fix issues, similar to @prettier/plugin-ruby, but with a focus on simplicity and minimal configuration.
@prettier/plugin-ruby
is a prettier plugin for the Ruby programming language. prettier
is an opinionated code formatter that supports multiple languages and integrates with most editors. The idea is to eliminate discussions of style in code review and allow developers to get back to thinking about code design instead.
Under the hood @prettier/plugin-ruby
uses Ruby's own ripper
library which allows this package to maintain parity with the existing Ruby parser. @prettier/plugin-ruby
supports Ruby versions 2.5
, 2.6
, and trunk
.
For example, the below code segment:
d=[30644250780,9003106878,
30636278846,66641217692,4501790980,
671_24_603036,131_61973916,66_606629_920,
30642677916,30643069058];a,s=[],$*[0]
s.each_byte{|b|a<<("%036b"%d[b.
chr.to_i]).scan(/\d{6}/)}
a.transpose.each{ |a|
a.join.each_byte{\
|i|print i==49?\
($*[1]||"#")\
:32.chr}
puts
}
when run through @prettier/plugin-ruby
will generate:
d = [
30644250780,
9003106878,
30636278846,
66641217692,
4501790980,
671_24_603036,
131_61973916,
66_606629_920,
30642677916,
30643069058
]
a, s = [], $*[0]
s.each_byte { |b| a << ('%036b' % d[b.chr.to_i]).scan(/\d{6}/) }
a.transpose.each do |a|
a.join.each_byte { |i| print i == 49 ? ($*[1] || '#') : 32.chr }
puts
end
First, your system on which you're running is going to need a couple of things:
ruby
2.5
or newer - there are a lot of ways to install ruby
, but I recommend rbenv
node
8.3
or newer - prettier
is a JavaScript package, so you're going to need to install node
to work with itnpm
or yarn
- these are package managers for JavaScript, either one will doSecond, you're going to need to list @prettier/plugin-ruby
as a JavaScript dependency from within whatever project on which you're working.
If you do not already have a package.json
file in the root of your repository, you can create one with:
echo '{ "name": "My Project" }' > package.json
After that you can add prettier
and @prettier/plugin-ruby
to your package.json
devDependencies
by running npm install --save-dev prettier @prettier/plugin-ruby
if you are using npm
or yarn add --dev prettier @prettier/plugin-ruby
if you are using yarn
.
Finally, you can install your dependencies using either npm install
for npm
or yarn install
for yarn
.
Now, you can run prettier
to tidy up your ruby
files! Verify by running against a file:
./node_modules/.bin/prettier --write path/to/file.rb
If you're happy, you can can run prettier
on an entire codebase:
./node_modules/.bin/prettier --write '**/*.{rb,rake}'
Note that you can also install prettier
globally with npm install -g prettier
or you can add ./node_modules/.bin
to your $PATH
so you don't need to reference the executable from the directory each time.
Below are the options (from src/ruby.js
) that @prettier/plugin-ruby
currently supports:
Name | Default | Description |
---|---|---|
printWidth | 80 | Same as in Prettier (see prettier docs). |
tabWidth | 2 | Same as in Prettier (see prettier docs). |
addTrailingCommas | false | Adds a trailing comma to array literals, hash literals, and method calls. |
inlineConditionals | true | When it fits on one line, allows if and unless statements to use the modifier form. |
inlineLoops | true | When it fits on one line, allows while and until statements to use the modifier form. |
preferHashLabels | true | When possible, uses the shortened hash key syntax, as opposed to hash rockets. |
preferSingleQuotes | true | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. |
Any of these can be added to your existing prettier configuration file. For example:
{
"preferSingleQuotes": false
}
Or, they can be passed to prettier
as arguments:
./node_modules/.bin/prettier --prefer-single-quotes false --write '**/*.{rb,rake}'
After checking out the repo, run yarn
and bundle
to install dependencies. Then, run yarn test
to run the tests. You can pretty print a Ruby source file by running yarn print [PATH]
.
Useful resources for understanding the AST structure are:
Bug reports and pull requests are welcome on GitHub at https://github.com/prettier/plugin-ruby.
The package is available as open source under the terms of the MIT License.
Kevin Deisz |
[0.6.3] - 2019-02-18
binary
fixture to minitest.begin
, rescue
, ensure
, while
, and until
nodes.FAQs
prettier plugin for the Ruby programming language
The npm package @prettier/plugin-ruby receives a total of 92,643 weekly downloads. As such, @prettier/plugin-ruby popularity was classified as popular.
We found that @prettier/plugin-ruby demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 14 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.