Skip to content

Commit

Permalink
init default linters
Browse files Browse the repository at this point in the history
  • Loading branch information
mnyrop committed May 27, 2022
1 parent 8913e8f commit b128f6b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
10 changes: 9 additions & 1 deletion lib/linters/default.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
module Linters
module Default

#
def self.assert_pids(data)
data.each_with_index do |d, i|
warn Rainbow("WARNING: project number #{i} is missing a pid") unless d.key? 'pid'
end
pids = data.map{ |d| d['pid'] }
dupes = pids.select { |p| pids.count(p) > 1 }.uniq! || []
warn Rainbow("WARNING: The following project pids are not unique!\n#{dupes}") unless dupes.empty?
end
end
end
21 changes: 20 additions & 1 deletion lib/linters/projects.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
require 'rainbow'
require 'vars'

module Linters
module Projects

#
def self.assert_people(projects)
people = YAML.load_file(Vars::People.yml_file).map { |h| h['pid'] }
projects.each do |project|
project.dig('pis').each do |pi|
warn Rainbow("WARNING: Published project '#{project['pid']}' references nonexisting person '#{pi}'.").orange unless people.include? pi
end
end
end
#
def self.assert_categories(projects)
categories = ['DH Seed Grant Recipient', 'Grad Fellowship Project', 'Other']
projects.each do |project|
category = project.dig 'category'
warn Rainbow("WARNING: Published project '#{project['pid']}' references nonexisting category '#{category}'.").orange unless categories.include? category
end
end
end
end
4 changes: 4 additions & 0 deletions lib/tasks/fetch/courses.rake
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ namespace :fetch do

puts "Parsing courses into #{Vars::Courses.yml_file}"
Utils.write_to_file(data.to_yaml, Vars::Courses.yml_file)

puts Rainbow("Done ✓").green

Rake::Task["lint:courses"].invoke
end
end
2 changes: 2 additions & 0 deletions lib/tasks/fetch/people.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ namespace :fetch do
Utils.write_to_file data.to_yaml, Vars::People.yml_file

puts Rainbow("Done ✓").green

Rake::Task["lint:people"].invoke
end
end
13 changes: 13 additions & 0 deletions lib/tasks/lint/courses.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rainbow'
require 'linters/default'
require 'vars'
require 'yaml'

namespace :lint do
desc 'lint the fetched courses yaml data'
task :courses do
courses = YAML.load_file Vars::Courses.yml_file

Linters::Default.assert_pids courses
end
end
13 changes: 13 additions & 0 deletions lib/tasks/lint/people.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rainbow'
require 'linters/default'
require 'vars'
require 'yaml'

namespace :lint do
desc 'lint the fetched people yaml data'
task :people do
people = YAML.load_file Vars::People.yml_file

Linters::Default.assert_pids people
end
end
12 changes: 4 additions & 8 deletions lib/tasks/lint/projects.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ require 'yaml'
namespace :lint do
desc 'lint the fetched project yaml data'
task :projects do
categories = %w(DH Seed Grant Recipient Grad Fellowship Project Other)
people = YAML.load_file(Vars::People.yml_file).map { |h| h['pid'] }
projects = YAML.load_file Vars::Projects.yml_file
projects = YAML.load_file Vars::Projects.yml_file

projects.each do |project|
project.dig('pis').each do |pi|
puts Rainbow("WARNING: Project '#{project['pid']}' references nonexisting person '#{pi}'.").magenta unless people.include? pi
end
end
Linters::Default.assert_pids projects
Linters::Projects.assert_categories projects
Linters::Projects.assert_people projects
end
end

0 comments on commit b128f6b

Please sign in to comment.