deadlink 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/deadlink.gemspec +26 -0
- data/exe/deadlink +6 -0
- data/lib/deadlink.rb +13 -0
- data/lib/deadlink/path.rb +51 -0
- data/lib/deadlink/paths.rb +29 -0
- data/lib/deadlink/scanner.rb +25 -0
- data/lib/deadlink/version.rb +3 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8934c98c596784a15c40112a43895da912885596
|
4
|
+
data.tar.gz: 7bf9ffbc09c3f3f8dc588fb9ce49d27137dcbbf1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a7405ebc139388902b768248054bc8bfe3211aa00d75b712c834d04c1710eaa3f3ac5bb6dc16117c3563a69c489c402b0a387c2c5d39d4101a3764e653ba261
|
7
|
+
data.tar.gz: 0752e347503050eeb59d81f282392595246c56888b0088eadfa152469c399d49214953fac7cdae7fae821532539dd70dbba50c7760248cd1c21389ec8e7311d9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 yutakakinjyo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Deadlink
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/yutakakinjyo/deadlink.svg?branch=master)](https://travis-ci.org/yutakakinjyo/deadlink)
|
4
|
+
|
5
|
+
Check **deadlink** of markdown files in your git repository.
|
6
|
+
|
7
|
+
**Example**
|
8
|
+
|
9
|
+
`$ ls`
|
10
|
+
|
11
|
+
`git_repo`
|
12
|
+
|
13
|
+
`$ deadlink git_repo`
|
14
|
+
|
15
|
+
show deadlink info.
|
16
|
+
|
17
|
+
`<deadlink> in <md file path> line: <line number>`
|
18
|
+
|
19
|
+
case of this repository
|
20
|
+
|
21
|
+
```
|
22
|
+
$ git clone git@github.com:yutakakinjyo/deadlink.git
|
23
|
+
$ cd deadlink
|
24
|
+
$ deadlink
|
25
|
+
```
|
26
|
+
|
27
|
+
result is this
|
28
|
+
|
29
|
+
```
|
30
|
+
example.md#title1 in ./README.md line: 43
|
31
|
+
contributor-covenant.org in ./README.md line: 73
|
32
|
+
nothing_file3.md in ./test/files/dir1/nest_file1.md line: 2
|
33
|
+
dir1/nothing_nest_file2.md in ./test/files/top.md line: 3
|
34
|
+
nothing_dir in ./test/files/top.md line: 5
|
35
|
+
nothing.txt in ./test/files/top.md line: 8
|
36
|
+
```
|
37
|
+
|
38
|
+
## not check patterns
|
39
|
+
|
40
|
+
this gem not check following patterns yet. applying these patterns to gem is future task.
|
41
|
+
|
42
|
+
- http(s) link
|
43
|
+
- anchor link ( only check file path part )
|
44
|
+
- e.g. `[anhor link](example.md#title1)` => check example.md
|
45
|
+
- multibyte characters
|
46
|
+
- specify file.
|
47
|
+
|
48
|
+
## Installation
|
49
|
+
|
50
|
+
`$ gem install deadlink`
|
51
|
+
|
52
|
+
## Usage
|
53
|
+
|
54
|
+
specify path of directory
|
55
|
+
|
56
|
+
```
|
57
|
+
$ deadlink <dir>
|
58
|
+
```
|
59
|
+
|
60
|
+
if your not specify <dir> path, `.` path is specfied.
|
61
|
+
|
62
|
+
```
|
63
|
+
$ deadlink => $ deadlink .
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
## Development
|
68
|
+
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
70
|
+
|
71
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yutakakinjyo/deadlink. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
80
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "deadlink"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/deadlink.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'deadlink/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "deadlink"
|
8
|
+
spec.version = Deadlink::VERSION
|
9
|
+
spec.authors = ["yutakakinjyo"]
|
10
|
+
spec.email = ["yutakakinjyo@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{check deadlink from markdown file in your git repository}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/yutakakinjyo/deadlink"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10.6"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
|
26
|
+
end
|
data/exe/deadlink
ADDED
data/lib/deadlink.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "deadlink/version"
|
2
|
+
require 'deadlink/scanner'
|
3
|
+
require 'deadlink/path'
|
4
|
+
require 'deadlink/paths'
|
5
|
+
|
6
|
+
module Deadlink
|
7
|
+
def self.scan(target_dir)
|
8
|
+
scanner = Scanner.new(target_dir)
|
9
|
+
files = scanner.md_files
|
10
|
+
paths = scanner.paths(files)
|
11
|
+
paths.print_deadlinks
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Deadlink
|
2
|
+
class Path
|
3
|
+
def initialize(file_path, link, index)
|
4
|
+
@file_path = file_path
|
5
|
+
@link = link
|
6
|
+
@index = index
|
7
|
+
end
|
8
|
+
|
9
|
+
def deadlink
|
10
|
+
puts @link + ' in ' + @file_path + ' line: ' + @index.to_s if deadlink?
|
11
|
+
end
|
12
|
+
|
13
|
+
def deadlink?
|
14
|
+
!exist? && ignore
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def exist?
|
20
|
+
File.exist?(link_path) || Dir.exist?(link_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def ignore
|
24
|
+
!url?
|
25
|
+
end
|
26
|
+
|
27
|
+
def url?
|
28
|
+
@link =~ /https?:\/\/[\S]+/
|
29
|
+
end
|
30
|
+
|
31
|
+
def link_path
|
32
|
+
# split path ; <filename>#<title>
|
33
|
+
cap = @link.match(/(?<filelink>[^#]*)#*(?<anchor>.*)/)
|
34
|
+
if cap[:filelink][0] == "/"
|
35
|
+
return File.join(repo_root, cap[:filelink])
|
36
|
+
end
|
37
|
+
|
38
|
+
File.expand_path(cap[:filelink], File.dirname(@file_path))
|
39
|
+
end
|
40
|
+
|
41
|
+
def repo_root
|
42
|
+
dir = File.dirname(@file_path)
|
43
|
+
while(!dir.empty?) do
|
44
|
+
return dir if Dir.exist?(File.join(dir, ".git"))
|
45
|
+
dir = File.expand_path("../", dir)
|
46
|
+
end
|
47
|
+
dir
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Deadlink
|
2
|
+
class Paths
|
3
|
+
def initialize(paths)
|
4
|
+
@paths = paths
|
5
|
+
@deadlinks = paths.select { |path| path.deadlink? }
|
6
|
+
end
|
7
|
+
|
8
|
+
def deadlink_include?
|
9
|
+
@deadlinks.any?
|
10
|
+
end
|
11
|
+
|
12
|
+
def deadlinks
|
13
|
+
@deadlinks
|
14
|
+
end
|
15
|
+
|
16
|
+
def print_deadlinks
|
17
|
+
@paths.each { |path| path.deadlink }
|
18
|
+
end
|
19
|
+
|
20
|
+
def count
|
21
|
+
@paths.count
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](i)
|
25
|
+
@paths[i]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Deadlink
|
2
|
+
class Scanner
|
3
|
+
def initialize(target_dir)
|
4
|
+
@target_dir = target_dir
|
5
|
+
end
|
6
|
+
|
7
|
+
def md_files
|
8
|
+
Dir.glob(File.join(@target_dir, '/**/*.md'))
|
9
|
+
end
|
10
|
+
|
11
|
+
def paths(files)
|
12
|
+
paths = []
|
13
|
+
files.each do |file|
|
14
|
+
File.open(file) do |f|
|
15
|
+
f.each_with_index do |line, index|
|
16
|
+
line.scan /\[[^\]]*\]\(([^)]+)\)/ do |link|
|
17
|
+
paths.push Path.new(f.path, link[0], index + 1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
Paths.new(paths)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deadlink
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yutakakinjyo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.10.6
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.10.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: check deadlink from markdown file in your git repository
|
56
|
+
email:
|
57
|
+
- yutakakinjyo@gmail.com
|
58
|
+
executables:
|
59
|
+
- deadlink
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- deadlink.gemspec
|
73
|
+
- exe/deadlink
|
74
|
+
- lib/deadlink.rb
|
75
|
+
- lib/deadlink/path.rb
|
76
|
+
- lib/deadlink/paths.rb
|
77
|
+
- lib/deadlink/scanner.rb
|
78
|
+
- lib/deadlink/version.rb
|
79
|
+
homepage: https://github.com/yutakakinjyo/deadlink
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.8
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: check deadlink from markdown file in your git repository
|
103
|
+
test_files: []
|