Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 73303e7

Browse files
authored
Merge pull request magento-commerce/devdocs#2712
Add a rake task for unused includes
2 parents bde3bfe + 8d5c205 commit 73303e7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rakelib/test.rake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,26 @@ namespace :test do
8383
end
8484
puts "Found #{images.size} dangling images".red
8585
end
86+
87+
desc 'Find unused includes'
88+
task :unused_includes do
89+
puts 'Running a task to find unused _includes'.magenta
90+
includes = Dir['src/_includes/**/*']
91+
puts "The project contains a total of #{includes.size} includes"
92+
puts 'The following includes are not linked:'
93+
Dir['src/**/*.{md,html}'].each do |file|
94+
# Exclude symmlinks
95+
next if File.symlink? file
96+
97+
includes.delete_if { |include| File.read(file).include?(File.basename(include)) }
98+
end
99+
100+
abort 'No unlinked includes' if includes.empty?
101+
102+
includes.each do |include|
103+
puts "No links for #{include}".yellow
104+
end
105+
puts "Found #{includes.size} unlinked includes".red
106+
puts 'Be careful removing include files. Some include files, such as those in the layout/** directory, may not be linked in the project, but may be used implicitly by the doc theme.'.bold
107+
end
86108
end

0 commit comments

Comments
 (0)