Permalink
Browse files

Write a Rubocop Cop to ensure no `#p` or `#puts` calls get committed …

…to master. (#6615)

Merge pull request 6615
  • Loading branch information...
parkr authored and jekyllbot committed Jan 20, 2018
1 parent 707dd03 commit 3f4bb55e07718526fa3bff59d1b48f88d61bdcb5
@@ -1,4 +1,12 @@
---
require:
- ./rubocop/jekyll
Jekyll/NoPutsAllowed:
Exclude:
- rake/*.rake
AllCops:
TargetRubyVersion: 2.1
Include:
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
s.homepage = "https://github.com/jekyll/jekyll"
all_files = `git ls-files -z`.split("\x0")
s.files = all_files.grep(%r!^(exe|lib)/|^.rubocop.yml$!)
s.files = all_files.grep(%r!^(exe|lib|rubocop)/|^.rubocop.yml$!)
s.executables = all_files.grep(%r!^exe/!) { |f| File.basename(f) }
s.bindir = "exe"
s.require_paths = ["lib"]
@@ -12,9 +12,9 @@ def init_with_program(prog)
c.action do |args, _|
cmd = (args.first || "").to_sym
if args.empty?
puts prog
Jekyll.logger.info prog.to_s
elsif prog.has_command? cmd
puts prog.commands[cmd]
Jekyll.logger.info prog.commands[cmd].to_s
else
invalid_command(prog, cmd)
abort
@@ -77,7 +77,7 @@ def process
end
def print_stats
puts @liquid_renderer.stats_table
Jekyll.logger.info @liquid_renderer.stats_table
end
# Reset Site details.
@@ -0,0 +1,5 @@
# frozen_string_literal: true
Dir[File.join(File.expand_path("jekyll", __dir__), "*.rb")].each do |ruby_file|
require ruby_file
end
@@ -0,0 +1,23 @@
# frozen_string_literal: true
require "rubocop"
module RuboCop
module Cop
module Jekyll
class NoPAllowed < Cop
MSG = "Avoid using `p` to print things. Use `Jekyll.logger` instead.".freeze
def_node_search :p_called?, <<-PATTERN
(send _ :p _)
PATTERN
def on_send(node)
if p_called?(node)
add_offense(node, :location => :selector)
end
end
end
end
end
end
@@ -0,0 +1,23 @@
# frozen_string_literal: true
require "rubocop"
module RuboCop
module Cop
module Jekyll
class NoPutsAllowed < Cop
MSG = "Avoid using `puts` to print things. Use `Jekyll.logger` instead.".freeze
def_node_search :puts_called?, <<-PATTERN
(send nil? :puts _)
PATTERN
def on_send(node)
if puts_called?(node)
add_offense(node, :location => :selector)
end
end
end
end
end
end
@@ -779,7 +779,6 @@ def to_liquid
should "include the size of each grouping" do
grouping = @filter.group_by(@filter.site.pages, "layout")
grouping.each do |g|
p g
assert_equal(
g["items"].size,
g["size"],

0 comments on commit 3f4bb55

Please sign in to comment.