class Prettier::Rake::Task

A Rake task that runs prettier on a set of source files.

Example:

require 'prettier/rake/task'

Prettier::Rake::Task.new do |t|
  t.source_files = '{app,config,lib}/**/*.rb'
end

This will create a task that can be run with:

rake prettier

Attributes

name[RW]

Name of prettier task. Defaults to :prettier.

source_files[RW]

Glob pattern to match source files. Defaults to 'lib/*/.rb'.

write[RW]

Whether or not to overwrite the source files with the prettier output. Defaults to true.

Public Class Methods

new(name = :prettier) { |self| ... } click to toggle source
# File lib/prettier/rake/task.rb, line 35
def initialize(name = :prettier)
  @name = name
  @write = true
  @source_files = 'lib/**/*.rb'

  yield self if block_given?
  define_task
end

Private Instance Methods

define_task() click to toggle source
# File lib/prettier/rake/task.rb, line 46
def define_task
  desc 'Runs prettier over source files'
  task(name) { run_task }
end
run_task() click to toggle source
# File lib/prettier/rake/task.rb, line 51
def run_task
  Prettier.run([('--write' if write), source_files].compact)
  exit($?.exitstatus) if $?&.exited?
end