Write a Rubocop Cop to ensure no `#p` or `#puts` calls get committed to master. (#6615)
Merge pull request 6615
This commit is contained in:
parent
707dd03fb0
commit
3f4bb55e07
|
@ -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 @@ module Jekyll
|
|||
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 @@ module Jekyll
|
|||
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 @@ class TestFilters < JekyllUnitTest
|
|||
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"],
|
||||
|
|
Loading…
Reference in New Issue