Sha256: a7e0e5bf075eb04841c9074ffd4b5dd47e968aff65b29f72537792253b418aea

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

module Appium
  class Lint
    ###
    # all markdown links must have an extension
    #
    # [link to read](readme.md)
    #
    # invalid examples:
    # [link](readme)
    # [link](readme#testing)
    class ExtMissing < Base
      def call
        input.lines.each_with_index do |line, index|
          # regex from github.com/appium/api-docs/lib/api_docs.rb
          # /(?<!!) -- negative look behind. excludes image links
          match_data = line.match(/(?<!!) \[ ( [^\[]* ) \] \( ( [^)\/]+ ) \)/x)
          next unless match_data # skip nil matches
          full        = match_data[0]
          link_text   = match_data[1]
          link_target = match_data[2]

          if link_target && !link_target.include?('/')
            ext = File.extname link_target
            if ext.empty?
              warn index, full
            else
              ext, hash = ext.split '#'
              warn index, full if ext.empty?
            end
          end
        end

        warnings
      end

      FAIL = 'Relative markdown links must have an extension'

      def fail
        FAIL
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
appium_doc_lint-0.0.7 lib/appium_doc_lint/lint/ext_missing.rb
appium_doc_lint-0.0.6 lib/appium_doc_lint/lint/ext_missing.rb
appium_doc_lint-0.0.5 lib/appium_doc_lint/lint/ext_missing.rb