Sha256: 8f274e6aa05b365ee1c1fd681fb1936b812a995cc6a54112ee1a4f754639193d

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 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
          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
            else
              ext, hash = ext.split '#'
              warn index if ext.empty?
            end
          end
        end

        warnings
      end

      FAIL = 'Relative markdown links must have an extension. [readme](readme.md)'

      def fail
        FAIL
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appium_doc_lint-0.0.4 lib/appium_doc_lint/lint/ext_missing.rb