Skip to content

Commit

Permalink
Merge pull request #222 from razeware/WEB-6543
Browse files Browse the repository at this point in the history
WEB-6543: Updating linter file existence checker to work with subfiles
  • Loading branch information
sammyd authored Oct 11, 2023
2 parents a8114da + 75ce6c8 commit 8a236a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 4 additions & 1 deletion app/lib/linting/metadata/captions_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ def video_course_captions
def module_captions
caption_files = ModuleFile.new(file:, attributes:).file_path_list
caption_files.map do |file|
if yaml?(file)
captions_file = if yaml?(file)
load_yaml(File.read(file)).deep_symbolize_keys[:captions_file]
else
@markdown_metadata = nil
@path = file
markdown_metadata[:captions_file]
end
next unless captions_file.present?

[captions_file, file]
end.compact
end

Expand Down
18 changes: 12 additions & 6 deletions app/lib/linting/metadata/file_attribute_existence_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ module FileAttributeExistenceChecker

def file_attribute_annotations
file_path_list.map do |path|
next if relative_file_exists?(path)
if path.is_a?(Array)
relative_to = path.second
path = path.first
else
relative_to = file
end
next if relative_file_exists?(path, relative_to:)

line = missing_file_line(path)
Annotation.new(
start_line: line,
end_line: line,
absolute_path: file,
absolute_path: relative_to,
annotation_level: 'failure',
message: "`release.yaml` includes references to unknown #{file_description} file: `#{path}",
message: "`#{relative_to}` includes references to unknown #{file_description} file: `#{path}",
title: "Missing #{file_description} file"
)
end.compact
Expand All @@ -33,17 +39,17 @@ def file_description
private

# Check whether script file exists
def relative_file_exists?(path)
def relative_file_exists?(path, relative_to: nil)
# Find path relative to the release.yaml file
file_path = Pathname.new(file).dirname.join(path)
file_path = Pathname.new(relative_to || file).dirname.join(path)
# Check whether this exists
file_exists?(file_path)
end

# Search release.yaml line by line to find the file references
def missing_file_line(path)
File.readlines(file).each_with_index do |line, index|
return index + 1 if line.include?(path)
return index + 1 if line.include?(path.to_s)
end
end
end
Expand Down

0 comments on commit 8a236a7

Please sign in to comment.