lib/metanorma/iso/validate.rb in metanorma-iso-2.0.4 vs lib/metanorma/iso/validate.rb in metanorma-iso-2.0.5

- old
+ new

@@ -2,10 +2,11 @@ require_relative "./validate_style" require_relative "./validate_requirements" require_relative "./validate_section" require_relative "./validate_title" require_relative "./validate_image" +require_relative "./validate_list" require "nokogiri" require "jing" require "iev" module Metanorma @@ -33,11 +34,11 @@ preceding = t.at("./preceding-sibling::text()[last()]") next unless !preceding.nil? && /\b(see| refer to)\s*\Z/mi.match(preceding) (target = root.at("//*[@id = '#{t['target']}']")) || next - if target&.at("./ancestor-or-self::*[@obligation = 'normative']") + if target.at("./ancestor-or-self::*[@obligation = 'normative']") @log.add("Style", t, "'see #{t['target']}' is pointing to a normative section") end end end @@ -73,10 +74,34 @@ def termdef_warn(text, regex, elem, term, msg) regex.match(text) && @log.add("Style", elem, "#{term}: #{msg}") end + # https://www.iso.org/ISO-house-style.html#iso-hs-s-text-r-r-ref_clause3 + def term_xrefs_validate(xmldoc) + termids = xmldoc + .xpath("//sections/terms | //sections/clause[.//terms] | "\ + "//annex[.//terms]").each_with_object({}) do |t, m| + t.xpath(".//*/@id").each { |a| m[a.text] = true } + t.name == "terms" and m[t["id"]] = true + end + xmldoc.xpath(".//xref").each do |x| + term_xrefs_validate1(x, termids) + end + end + + def term_xrefs_validate1(xref, termids) + (termids[xref["target"]] && !termids[xref.parent["id"]]) and + @log.add("Style", xref, + "only terms clauses can cross-reference terms clause "\ + "(#{xref['target']})") + (!termids[xref["target"]] && termids[xref.parent["id"]]) and + @log.add("Style", xref, + "non-terms clauses cannot cross-reference terms clause "\ + "(#{xref['target']})") + end + # ISO/IEC DIR 2, 16.5.6 def termdef_style(xmldoc) xmldoc.xpath("//term").each do |t| para = t.at("./definition/verbal-definition") || return term = t.at("./preferred//name").text @@ -137,14 +162,17 @@ title_validate(doc.root) isosubgroup_validate(doc.root) onlychild_clause_validate(doc.root) termdef_style(doc.root) see_xrefs_validate(doc.root) + term_xrefs_validate(doc.root) see_erefs_validate(doc.root) locality_erefs_validate(doc.root) bibdata_validate(doc.root) bibitem_validate(doc.root) figure_validate(doc.root) + listcount_validate(doc) + list_punctuation(doc) end def bibitem_validate(xmldoc) xmldoc.xpath("//bibitem[date/on = '–']").each do |b| b.at("./note[@type = 'Unpublished-Status']") or