danger-textlint 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +155 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +134 -0
- data/Guardfile +19 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +23 -0
- data/danger-textlint.gemspec +49 -0
- data/lib/danger_plugin.rb +1 -0
- data/lib/danger_textlint.rb +1 -0
- data/lib/textlint/gem_version.rb +3 -0
- data/lib/textlint/plugin.rb +89 -0
- data/spec/fixtures/textlint_result.json +1 -0
- data/spec/spec_helper.rb +65 -0
- data/spec/textlint_spec.rb +128 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5379e64b36b02923c05004009282dd55cbe1b0fd6ebd7588a5b7f24fc1138fa4
|
4
|
+
data.tar.gz: 7c4a322f0f253e09af1ea07051d32ecfb43d3927483b7c30d3cd39615e87395e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d8f5c1103754a58d990f74307a398657b6b76a6ca5c48488ad661b780d2f0bc7264e8ac9e2c66f206f481bbc4205a2e22490542b6ea56082c7626fbf9cd8faa
|
7
|
+
data.tar.gz: f1e39b6248cc2426d8433d4348561656ae407904acc95daa3643f1152fc9dc75f548fec6b4a30a422e8215c06eae6555250d64866bff445e69b512e1c9c6e20a
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
|
2
|
+
|
3
|
+
# If you don't like these settings, just delete this file :)
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.4
|
7
|
+
|
8
|
+
Style/StringLiterals:
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
# kind_of? is a good way to check a type
|
13
|
+
Style/ClassCheck:
|
14
|
+
EnforcedStyle: kind_of?
|
15
|
+
|
16
|
+
# It's better to be more explicit about the type
|
17
|
+
Style/BracesAroundHashParameters:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
# specs sometimes have useless assignments, which is fine
|
21
|
+
Lint/UselessAssignment:
|
22
|
+
Exclude:
|
23
|
+
- '**/spec/**/*'
|
24
|
+
|
25
|
+
# We could potentially enable the 2 below:
|
26
|
+
Layout/IndentHash:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Layout/AlignHash:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
# HoundCI doesn't like this rule
|
33
|
+
Layout/DotPosition:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# We allow !! as it's an easy way to convert ot boolean
|
37
|
+
Style/DoubleNegation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
# Cop supports --auto-correct.
|
41
|
+
Lint/UnusedBlockArgument:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
# We want to allow class Fastlane::Class
|
45
|
+
Style/ClassAndModuleChildren:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Metrics/AbcSize:
|
49
|
+
Max: 60
|
50
|
+
|
51
|
+
# The %w might be confusing for new users
|
52
|
+
Style/WordArray:
|
53
|
+
MinSize: 19
|
54
|
+
|
55
|
+
# raise and fail are both okay
|
56
|
+
Style/SignalException:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
# Better too much 'return' than one missing
|
60
|
+
Style/RedundantReturn:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
# Having if in the same line might not always be good
|
64
|
+
Style/IfUnlessModifier:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
# and and or is okay
|
68
|
+
Style/AndOr:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
# Configuration parameters: CountComments.
|
72
|
+
Metrics/ClassLength:
|
73
|
+
Max: 350
|
74
|
+
|
75
|
+
Metrics/CyclomaticComplexity:
|
76
|
+
Max: 17
|
77
|
+
|
78
|
+
# Configuration parameters: AllowURI, URISchemes.
|
79
|
+
Metrics/LineLength:
|
80
|
+
Max: 370
|
81
|
+
|
82
|
+
# Configuration parameters: CountKeywordArgs.
|
83
|
+
Metrics/ParameterLists:
|
84
|
+
Max: 10
|
85
|
+
|
86
|
+
Metrics/PerceivedComplexity:
|
87
|
+
Max: 18
|
88
|
+
|
89
|
+
# Sometimes it's easier to read without guards
|
90
|
+
Style/GuardClause:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
# something = if something_else
|
94
|
+
# that's confusing
|
95
|
+
Style/ConditionalAssignment:
|
96
|
+
Enabled: false
|
97
|
+
|
98
|
+
# Better to have too much self than missing a self
|
99
|
+
Style/RedundantSelf:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
Metrics/MethodLength:
|
103
|
+
Max: 60
|
104
|
+
|
105
|
+
# We're not there yet
|
106
|
+
Style/Documentation:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
# Adds complexity
|
110
|
+
Style/IfInsideElse:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
# danger specific
|
114
|
+
|
115
|
+
Style/BlockComments:
|
116
|
+
Enabled: false
|
117
|
+
|
118
|
+
Layout/MultilineMethodCallIndentation:
|
119
|
+
EnforcedStyle: indented
|
120
|
+
|
121
|
+
# FIXME: 25
|
122
|
+
Metrics/BlockLength:
|
123
|
+
Max: 345
|
124
|
+
Exclude:
|
125
|
+
- "**/*_spec.rb"
|
126
|
+
|
127
|
+
Style/MixinGrouping:
|
128
|
+
Enabled: false
|
129
|
+
|
130
|
+
Naming/FileName:
|
131
|
+
Enabled: false
|
132
|
+
|
133
|
+
Layout/IndentHeredoc:
|
134
|
+
Enabled: false
|
135
|
+
|
136
|
+
Style/SpecialGlobalVars:
|
137
|
+
Enabled: false
|
138
|
+
|
139
|
+
PercentLiteralDelimiters:
|
140
|
+
PreferredDelimiters:
|
141
|
+
"%": ()
|
142
|
+
"%i": ()
|
143
|
+
"%q": ()
|
144
|
+
"%Q": ()
|
145
|
+
"%r": "{}"
|
146
|
+
"%s": ()
|
147
|
+
"%w": ()
|
148
|
+
"%W": ()
|
149
|
+
"%x": ()
|
150
|
+
|
151
|
+
Security/YAMLLoad:
|
152
|
+
Enabled: false
|
153
|
+
|
154
|
+
Style/FrozenStringLiteralComment:
|
155
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
danger-textlint (0.0.1)
|
5
|
+
danger-plugin-api (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.5.2)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
ast (2.4.0)
|
13
|
+
claide (1.0.2)
|
14
|
+
claide-plugins (0.9.2)
|
15
|
+
cork
|
16
|
+
nap
|
17
|
+
open4 (~> 1.3)
|
18
|
+
coderay (1.1.2)
|
19
|
+
colored2 (3.1.2)
|
20
|
+
cork (0.3.0)
|
21
|
+
colored2 (~> 3.1)
|
22
|
+
danger (5.5.10)
|
23
|
+
claide (~> 1.0)
|
24
|
+
claide-plugins (>= 0.9.2)
|
25
|
+
colored2 (~> 3.1)
|
26
|
+
cork (~> 0.1)
|
27
|
+
faraday (~> 0.9)
|
28
|
+
faraday-http-cache (~> 1.0)
|
29
|
+
git (~> 1)
|
30
|
+
kramdown (~> 1.5)
|
31
|
+
no_proxy_fix
|
32
|
+
octokit (~> 4.7)
|
33
|
+
terminal-table (~> 1)
|
34
|
+
danger-plugin-api (1.0.0)
|
35
|
+
danger (> 2.0)
|
36
|
+
diff-lcs (1.3)
|
37
|
+
faraday (0.14.0)
|
38
|
+
multipart-post (>= 1.2, < 3)
|
39
|
+
faraday-http-cache (1.3.1)
|
40
|
+
faraday (~> 0.8)
|
41
|
+
ffi (1.9.21)
|
42
|
+
formatador (0.2.5)
|
43
|
+
git (1.3.0)
|
44
|
+
guard (2.14.2)
|
45
|
+
formatador (>= 0.2.4)
|
46
|
+
listen (>= 2.7, < 4.0)
|
47
|
+
lumberjack (>= 1.0.12, < 2.0)
|
48
|
+
nenv (~> 0.1)
|
49
|
+
notiffany (~> 0.0)
|
50
|
+
pry (>= 0.9.12)
|
51
|
+
shellany (~> 0.0)
|
52
|
+
thor (>= 0.18.1)
|
53
|
+
guard-compat (1.2.1)
|
54
|
+
guard-rspec (4.7.3)
|
55
|
+
guard (~> 2.1)
|
56
|
+
guard-compat (~> 1.1)
|
57
|
+
rspec (>= 2.99.0, < 4.0)
|
58
|
+
kramdown (1.16.2)
|
59
|
+
listen (3.0.7)
|
60
|
+
rb-fsevent (>= 0.9.3)
|
61
|
+
rb-inotify (>= 0.9.7)
|
62
|
+
lumberjack (1.0.12)
|
63
|
+
method_source (0.9.0)
|
64
|
+
multipart-post (2.0.0)
|
65
|
+
nap (1.1.0)
|
66
|
+
nenv (0.3.0)
|
67
|
+
no_proxy_fix (0.1.2)
|
68
|
+
notiffany (0.1.1)
|
69
|
+
nenv (~> 0.1)
|
70
|
+
shellany (~> 0.0)
|
71
|
+
octokit (4.8.0)
|
72
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
73
|
+
open4 (1.3.4)
|
74
|
+
parallel (1.12.1)
|
75
|
+
parser (2.4.0.2)
|
76
|
+
ast (~> 2.3)
|
77
|
+
powerpack (0.1.1)
|
78
|
+
pry (0.11.3)
|
79
|
+
coderay (~> 1.1.0)
|
80
|
+
method_source (~> 0.9.0)
|
81
|
+
public_suffix (3.0.1)
|
82
|
+
rainbow (3.0.0)
|
83
|
+
rake (10.5.0)
|
84
|
+
rb-fsevent (0.10.2)
|
85
|
+
rb-inotify (0.9.10)
|
86
|
+
ffi (>= 0.5.0, < 2)
|
87
|
+
rspec (3.7.0)
|
88
|
+
rspec-core (~> 3.7.0)
|
89
|
+
rspec-expectations (~> 3.7.0)
|
90
|
+
rspec-mocks (~> 3.7.0)
|
91
|
+
rspec-core (3.7.1)
|
92
|
+
rspec-support (~> 3.7.0)
|
93
|
+
rspec-expectations (3.7.0)
|
94
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
95
|
+
rspec-support (~> 3.7.0)
|
96
|
+
rspec-mocks (3.7.0)
|
97
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
98
|
+
rspec-support (~> 3.7.0)
|
99
|
+
rspec-support (3.7.1)
|
100
|
+
rubocop (0.52.1)
|
101
|
+
parallel (~> 1.10)
|
102
|
+
parser (>= 2.4.0.2, < 3.0)
|
103
|
+
powerpack (~> 0.1)
|
104
|
+
rainbow (>= 2.2.2, < 4.0)
|
105
|
+
ruby-progressbar (~> 1.7)
|
106
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
107
|
+
ruby-progressbar (1.9.0)
|
108
|
+
sawyer (0.8.1)
|
109
|
+
addressable (>= 2.3.5, < 2.6)
|
110
|
+
faraday (~> 0.8, < 1.0)
|
111
|
+
shellany (0.0.1)
|
112
|
+
terminal-table (1.8.0)
|
113
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
114
|
+
thor (0.20.0)
|
115
|
+
unicode-display_width (1.3.0)
|
116
|
+
yard (0.9.12)
|
117
|
+
|
118
|
+
PLATFORMS
|
119
|
+
ruby
|
120
|
+
|
121
|
+
DEPENDENCIES
|
122
|
+
bundler (~> 1.3)
|
123
|
+
danger-textlint!
|
124
|
+
guard (~> 2.14)
|
125
|
+
guard-rspec (~> 4.7)
|
126
|
+
listen (= 3.0.7)
|
127
|
+
pry
|
128
|
+
rake (~> 10.0)
|
129
|
+
rspec (~> 3.4)
|
130
|
+
rubocop
|
131
|
+
yard
|
132
|
+
|
133
|
+
BUNDLED WITH
|
134
|
+
1.16.0
|
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# A guardfile for making Danger Plugins
|
2
|
+
# For more info see https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# To run, use `bundle exec guard`.
|
5
|
+
|
6
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
7
|
+
require 'guard/rspec/dsl'
|
8
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
9
|
+
|
10
|
+
# RSpec files
|
11
|
+
rspec = dsl.rspec
|
12
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
13
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
14
|
+
watch(rspec.spec_files)
|
15
|
+
|
16
|
+
# Ruby files
|
17
|
+
ruby = dsl.ruby
|
18
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
19
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018 Kenta Kase <kesin1202000@gmail.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# danger-textlint
|
2
|
+
|
3
|
+
[Danger](http://danger.systems/ruby/) plugin for [textlint](https://textlint.github.io/).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install danger-textlint
|
8
|
+
|
9
|
+
`danger-textlint` needs `textlint` to lint your files. Please check the [installation guide](https://github.com/textlint/textlint#installation) and install it before you run Danger.
|
10
|
+
|
11
|
+
`danger-textlint` will first try local `node_modules/.bin/textlint` then the global `textlint`.
|
12
|
+
My recommend is installing `textlint` in local. Create package.json (`npm init`) and then install (`npm i textlint`).
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
<blockquote>Run textlint and send violations as inline comment.
|
17
|
+
<pre>
|
18
|
+
# Lint added and modified files only
|
19
|
+
textlint.lint
|
20
|
+
</pre>
|
21
|
+
</blockquote>
|
22
|
+
|
23
|
+
<blockquote>Keep severity until warning. It allows merging pull request if there are violations remaining.
|
24
|
+
<pre>
|
25
|
+
textlint.max_severity = "warn"
|
26
|
+
textlint.lint
|
27
|
+
</pre>
|
28
|
+
</blockquote>
|
29
|
+
|
30
|
+
#### Attributes
|
31
|
+
|
32
|
+
`config_file` - .textlintrc path
|
33
|
+
|
34
|
+
`max_severity` - Set max danger reporting severity
|
35
|
+
choice: nil or "warn"
|
36
|
+
|
37
|
+
#### Methods
|
38
|
+
|
39
|
+
`lint` - Execute textlint and send comment
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
1. Clone this repo
|
44
|
+
2. Run `bundle install` to setup dependencies.
|
45
|
+
3. Run `bundle exec rake spec` to run the tests.
|
46
|
+
4. Use `bundle exec guard` to automatically have tests run as you make changes.
|
47
|
+
5. Make your changes.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:specs)
|
6
|
+
|
7
|
+
task default: :specs
|
8
|
+
|
9
|
+
task :spec do
|
10
|
+
Rake::Task['specs'].invoke
|
11
|
+
Rake::Task['rubocop'].invoke
|
12
|
+
Rake::Task['spec_docs'].invoke
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run RuboCop on the lib/specs directory'
|
16
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
17
|
+
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Ensure that the plugin passes `danger plugins lint`'
|
21
|
+
task :spec_docs do
|
22
|
+
sh 'bundle exec danger plugins lint'
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'textlint/gem_version.rb'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'danger-textlint'
|
8
|
+
spec.version = Textlint::VERSION
|
9
|
+
spec.authors = ['Kesin']
|
10
|
+
spec.email = ['kesin1202000@gmail.com']
|
11
|
+
spec.description = %q{A short description of danger-textlint.}
|
12
|
+
spec.summary = %q{A longer description of danger-textlint.}
|
13
|
+
spec.homepage = 'https://github.com/Kesin11/danger-textlint'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
|
22
|
+
|
23
|
+
# General ruby development
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
|
27
|
+
# Testing support
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
29
|
+
|
30
|
+
# Linting code and docs
|
31
|
+
spec.add_development_dependency "rubocop"
|
32
|
+
spec.add_development_dependency "yard"
|
33
|
+
|
34
|
+
# Makes testing easy via `bundle exec guard`
|
35
|
+
spec.add_development_dependency 'guard', '~> 2.14'
|
36
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
37
|
+
|
38
|
+
# If you want to work on older builds of ruby
|
39
|
+
spec.add_development_dependency 'listen', '3.0.7'
|
40
|
+
|
41
|
+
# This gives you the chance to run a REPL inside your tests
|
42
|
+
# via:
|
43
|
+
#
|
44
|
+
# require 'pry'
|
45
|
+
# binding.pry
|
46
|
+
#
|
47
|
+
# This will stop test execution and let you inspect the results
|
48
|
+
spec.add_development_dependency 'pry'
|
49
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "textlint/plugin"
|
@@ -0,0 +1 @@
|
|
1
|
+
require "textlint/gem_version"
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Danger
|
5
|
+
# [Danger](http://danger.systems/ruby/) plugin for [textlint](https://textlint.github.io/).
|
6
|
+
#
|
7
|
+
# @example Run textlint and send violations as inline comment.
|
8
|
+
#
|
9
|
+
# # Lint added and modified files only
|
10
|
+
# textlint.lint
|
11
|
+
#
|
12
|
+
# @example Keep severity until warning. It allows merging pull request if there are violations remaining.
|
13
|
+
#
|
14
|
+
# textlint.max_severity = "warn"
|
15
|
+
# textlint.lint
|
16
|
+
#
|
17
|
+
# @see Kesin11/danger-textlint
|
18
|
+
# @tags lint, textlint
|
19
|
+
#
|
20
|
+
class DangerTextlint < Plugin
|
21
|
+
# .textlintrc path
|
22
|
+
# @return [String]
|
23
|
+
attr_accessor :config_file
|
24
|
+
|
25
|
+
# Set max danger reporting severity
|
26
|
+
# choice: nil or "warn"
|
27
|
+
# @return [String]
|
28
|
+
attr_accessor :max_severity
|
29
|
+
|
30
|
+
# Execute textlint and send comment
|
31
|
+
# @return [void]
|
32
|
+
def lint
|
33
|
+
bin = textlint_path
|
34
|
+
result_json = run_textlint(bin, target_files)
|
35
|
+
errors = parse(result_json)
|
36
|
+
send_comment(errors)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def textlint_path
|
42
|
+
local = "./node_modules/.bin/textlint"
|
43
|
+
File.exist?(local) ? local : find_executable("textlint")
|
44
|
+
end
|
45
|
+
|
46
|
+
def textlint_command(bin, target_files)
|
47
|
+
command = "#{bin} -f json"
|
48
|
+
command << " -c #{config_file}" if config_file
|
49
|
+
return "#{command} #{target_files.join(' ')}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def run_textlint(bin, target_files)
|
53
|
+
command = textlint_command(bin, target_files)
|
54
|
+
`#{command}`
|
55
|
+
end
|
56
|
+
|
57
|
+
def target_files
|
58
|
+
((git.modified_files - git.deleted_files) + git.added_files)
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse(json)
|
62
|
+
result = JSON(json)
|
63
|
+
dir = "#{Dir.pwd}/"
|
64
|
+
severity_method = {
|
65
|
+
1 => "warn",
|
66
|
+
2 => "fail"
|
67
|
+
}
|
68
|
+
|
69
|
+
result.flat_map do |file|
|
70
|
+
file_path = file["filePath"]
|
71
|
+
file["messages"].map do |message|
|
72
|
+
severity = max_severity == "warn" ? 1 : message["severity"]
|
73
|
+
{
|
74
|
+
file_path: file_path.gsub(dir, ""),
|
75
|
+
line: message["line"],
|
76
|
+
severity: severity_method[severity],
|
77
|
+
message: "#{message['message']}(#{message['ruleId']})"
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def send_comment(errors)
|
84
|
+
errors.each do |error|
|
85
|
+
send(error[:severity], error[:message], file: error[:file_path], line: error[:line])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"messages":[{"type":"lint","ruleId":"preset-ja-technical-writing/ja-no-mixed-period","message":"文末が\"。\"で終わっていません。","index":54,"line":3,"column":28,"severity":2},{"type":"lint","ruleId":"preset-ja-technical-writing/no-doubled-joshi","message":"一文に二回以上利用されている助詞 \"が\" がみつかりました。","index":142,"line":6,"column":17,"severity":2},{"type":"lint","ruleId":"preset-ja-technical-writing/ja-no-weak-phrase","message":"弱い表現: \"思います\" が使われています。","index":219,"line":7,"column":48,"severity":2}],"filePath":"/Users/your/github/sample_repository/articles/1.md"},{"messages":[{"type":"lint","ruleId":"preset-ja-technical-writing/ja-no-mixed-period","message":"文末が\"。\"で終わっていません。","index":54,"line":3,"column":28,"severity":2},{"type":"lint","ruleId":"preset-ja-technical-writing/no-doubled-joshi","message":"一文に二回以上利用されている助詞 \"が\" がみつかりました。","index":142,"line":6,"column":17,"severity":2},{"type":"lint","ruleId":"preset-ja-technical-writing/ja-no-weak-phrase","message":"弱い表現: \"思います\" が使われています。","index":219,"line":7,"column":48,"severity":2}],"filePath":"/Users/your/github/sample_repository/articles/2.md"}]
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "pathname"
|
2
|
+
ROOT = Pathname.new(File.expand_path("../../", __FILE__))
|
3
|
+
$:.unshift((ROOT + "lib").to_s)
|
4
|
+
$:.unshift((ROOT + "spec").to_s)
|
5
|
+
|
6
|
+
require "bundler/setup"
|
7
|
+
require "pry"
|
8
|
+
|
9
|
+
require "rspec"
|
10
|
+
require "danger"
|
11
|
+
|
12
|
+
if `git remote -v` == ""
|
13
|
+
puts "You cannot run tests without setting a local git remote on this repo"
|
14
|
+
puts "It's a weird side-effect of Danger's internals."
|
15
|
+
exit(0)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Use coloured output, it's the best.
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.filter_gems_from_backtrace "bundler"
|
21
|
+
config.color = true
|
22
|
+
config.tty = true
|
23
|
+
end
|
24
|
+
|
25
|
+
require "danger_plugin"
|
26
|
+
|
27
|
+
# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
|
28
|
+
# If you are expanding these files, see if it's already been done ^.
|
29
|
+
|
30
|
+
# A silent version of the user interface,
|
31
|
+
# it comes with an extra function `.string` which will
|
32
|
+
# strip all ANSI colours from the string.
|
33
|
+
|
34
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
35
|
+
def testing_ui
|
36
|
+
@output = StringIO.new
|
37
|
+
def @output.winsize
|
38
|
+
[20, 9999]
|
39
|
+
end
|
40
|
+
|
41
|
+
cork = Cork::Board.new(out: @output)
|
42
|
+
def cork.string
|
43
|
+
out.string.gsub(/\e\[([;\d]+)?m/, "")
|
44
|
+
end
|
45
|
+
cork
|
46
|
+
end
|
47
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
48
|
+
|
49
|
+
# Example environment (ENV) that would come from
|
50
|
+
# running a PR on TravisCI
|
51
|
+
def testing_env
|
52
|
+
{
|
53
|
+
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
|
54
|
+
"TRAVIS_PULL_REQUEST" => "800",
|
55
|
+
"TRAVIS_REPO_SLUG" => "artsy/eigen",
|
56
|
+
"TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
|
57
|
+
"DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# A stubbed out Dangerfile for use in tests
|
62
|
+
def testing_dangerfile
|
63
|
+
env = Danger::EnvironmentManager.new(testing_env)
|
64
|
+
Danger::Dangerfile.new(env, testing_ui)
|
65
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
describe "with Dangerfile" do
|
5
|
+
before do
|
6
|
+
@dangerfile = testing_dangerfile
|
7
|
+
@textlint = @dangerfile.textlint
|
8
|
+
|
9
|
+
# stub
|
10
|
+
allow(Dir).to receive(:pwd).and_return("/Users/your/github/sample_repository")
|
11
|
+
allow(@textlint).to receive(:textlint_path).and_return("./node_modules/.bin/textlint")
|
12
|
+
allow(@textlint.git).to receive(:added_files).and_return([])
|
13
|
+
allow(@textlint.git).to receive(:modified_files).and_return([])
|
14
|
+
allow(@textlint.git).to receive(:deleted_files).and_return([])
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:fixture) do
|
18
|
+
fixture_path = File.expand_path("../fixtures/textlint_result.json", __FILE__)
|
19
|
+
File.read(fixture_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".parse" do
|
23
|
+
let(:expect_message) do
|
24
|
+
"文末が\"。\"で終わっていません。(preset-ja-technical-writing/ja-no-mixed-period)"
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with default max_severity" do
|
28
|
+
subject(:errors) do
|
29
|
+
@textlint.send(:parse, fixture)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has 6 errors" do
|
33
|
+
expect(errors.size).to eq(6)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "is mapped to be follow hash about index 0" do
|
37
|
+
expected = {
|
38
|
+
file_path: "articles/1.md",
|
39
|
+
line: 3,
|
40
|
+
severity: "fail",
|
41
|
+
message: expect_message
|
42
|
+
}
|
43
|
+
expect(errors[0]).to eq(expected)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with .max_severity = 'warn'" do
|
48
|
+
subject(:errors) do
|
49
|
+
@textlint.max_severity = "warn"
|
50
|
+
@textlint.send(:parse, fixture)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "all errors severity are warn" do
|
54
|
+
expect(errors.all? { |error| error[:severity] == "warn" }).to be true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".lint" do
|
60
|
+
let(:expect_message) do
|
61
|
+
"文末が\"。\"で終わっていません。(preset-ja-technical-writing/ja-no-mixed-period)"
|
62
|
+
end
|
63
|
+
|
64
|
+
# stub for simulate to run textlint
|
65
|
+
before { allow(@textlint).to receive(:run_textlint).and_return fixture }
|
66
|
+
|
67
|
+
context "with default max_severity" do
|
68
|
+
before { @textlint.lint }
|
69
|
+
|
70
|
+
it "status_report" do
|
71
|
+
status_report = @textlint.status_report
|
72
|
+
expect(status_report[:errors].size).to be > 0
|
73
|
+
end
|
74
|
+
|
75
|
+
it "violation_report" do
|
76
|
+
violation_report = @textlint.violation_report
|
77
|
+
expect(violation_report[:errors][0]).to eq(
|
78
|
+
Violation.new(expect_message, false, "articles/1.md", 3)
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with .max_severity = 'warn'" do
|
84
|
+
before do
|
85
|
+
@textlint.max_severity = "warn"
|
86
|
+
@textlint.lint
|
87
|
+
end
|
88
|
+
|
89
|
+
it "status_report" do
|
90
|
+
status_report = @textlint.status_report
|
91
|
+
expect(status_report[:errors].size).to eq(0)
|
92
|
+
expect(status_report[:warnings].size).to be > 0
|
93
|
+
end
|
94
|
+
|
95
|
+
it "violation_report" do
|
96
|
+
violation_report = @textlint.violation_report
|
97
|
+
expect(violation_report[:errors].size).to eq(0)
|
98
|
+
expect(violation_report[:warnings][0]).to eq(
|
99
|
+
Violation.new(expect_message, false, "articles/1.md", 3)
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe ".target_files" do
|
106
|
+
let(:file1) { "articles/1.md" }
|
107
|
+
let(:file2) { "articles/2.md" }
|
108
|
+
let(:file3) { "articles/3.md" }
|
109
|
+
|
110
|
+
before do
|
111
|
+
allow(@textlint.git).to receive(:added_files).and_return([file1])
|
112
|
+
allow(@textlint.git).to receive(:modified_files).and_return([file2])
|
113
|
+
end
|
114
|
+
|
115
|
+
it "are add and modified files only" do
|
116
|
+
allow(@textlint.git).to receive(:deleted_files).and_return([])
|
117
|
+
|
118
|
+
expect(@textlint.send(:target_files)).to match_array([file1, file2])
|
119
|
+
end
|
120
|
+
|
121
|
+
it "are also include removed file" do
|
122
|
+
allow(@textlint.git).to receive(:deleted_files).and_return([file3])
|
123
|
+
|
124
|
+
expect(@textlint.send(:target_files)).to match_array([file1, file2])
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: danger-textlint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kesin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: danger-plugin-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.14'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.14'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.7'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '4.7'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: listen
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.0.7
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.0.7
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: A short description of danger-textlint.
|
154
|
+
email:
|
155
|
+
- kesin1202000@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rubocop.yml"
|
162
|
+
- ".travis.yml"
|
163
|
+
- Gemfile
|
164
|
+
- Gemfile.lock
|
165
|
+
- Guardfile
|
166
|
+
- LICENSE.txt
|
167
|
+
- README.md
|
168
|
+
- Rakefile
|
169
|
+
- danger-textlint.gemspec
|
170
|
+
- lib/danger_plugin.rb
|
171
|
+
- lib/danger_textlint.rb
|
172
|
+
- lib/textlint/gem_version.rb
|
173
|
+
- lib/textlint/plugin.rb
|
174
|
+
- spec/fixtures/textlint_result.json
|
175
|
+
- spec/spec_helper.rb
|
176
|
+
- spec/textlint_spec.rb
|
177
|
+
homepage: https://github.com/Kesin11/danger-textlint
|
178
|
+
licenses:
|
179
|
+
- MIT
|
180
|
+
metadata: {}
|
181
|
+
post_install_message:
|
182
|
+
rdoc_options: []
|
183
|
+
require_paths:
|
184
|
+
- lib
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
requirements: []
|
196
|
+
rubyforge_project:
|
197
|
+
rubygems_version: 2.7.5
|
198
|
+
signing_key:
|
199
|
+
specification_version: 4
|
200
|
+
summary: A longer description of danger-textlint.
|
201
|
+
test_files:
|
202
|
+
- spec/fixtures/textlint_result.json
|
203
|
+
- spec/spec_helper.rb
|
204
|
+
- spec/textlint_spec.rb
|