Sha256: e06ebbae1a29330f9bb2729f9af138ec8bcd2e6e7a960c48c155e2ed43afdf61
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
# frozen_string_literal: true require "rake" require "rake/tasklib" module RuboCop module Katalyst # Provides a custom rake task. # # require 'rubocop/katalyst/prettier_task' # RuboCop::Katalyst::PrettierTask.new class PrettierTask < ::Rake::TaskLib attr_accessor :verbose def initialize(verbose: true) super() @verbose = verbose desc "Run Prettier" unless ::Rake.application.last_description task(prettier: "prettier:lint") task(lint: :prettier) task(autocorrect: "prettier:autocorrect") setup_subtasks end private def yarn(*options) sh("yarn", *options) end def installed? config.exist? end def config ::Rails.application.root.join(".prettierrc.json") end def install_prettier yarn("add", "--dev", "prettier") config.open("w") do |f| f.write <<~JSON {} JSON end yarn("install") end def setup_subtasks namespace :prettier do desc "Install npm packages with yarn" task install: :environment do install_prettier unless installed? end desc "Lint JS/SCSS files using prettier" task lint: :install do yarn("run", "prettier", "--check", *paths) end desc "Autocorrect JS/SCSS files using prettier" task autocorrect: :install do yarn("run", "prettier", "--write", *paths) end end end def paths %w[ app/assets/javascripts app/assets/stylesheets ] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-katalyst-1.1.1 | lib/rubocop/katalyst/prettier_task.rb |
rubocop-katalyst-1.1.0 | lib/rubocop/katalyst/prettier_task.rb |