Skip to content

Commit c5c5c01

Browse files
committed
fix rubocop
1 parent 015ba98 commit c5c5c01

2 files changed

Lines changed: 38 additions & 24 deletions

File tree

.rubocop.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Metrics/BlockLength:
3+
Exclude:
4+
- "**/*_spec.rb"
5+
6+
Metrics/LineLength:
7+
Max: 120
8+
Exclude:
9+
- "**/*_spec.rb"
10+
11+
Metrics/ModuleLength:
12+
Exclude:
13+
- "**/*_spec.rb"
14+
15+
Metrics/AbcSize:
16+
Enabled: true
17+
Max: 25

lib/eslint/plugin.rb

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22
require 'json'
33

44
module Danger
5-
# This is your plugin class. Any attributes or methods you expose here will
6-
# be available from within your Dangerfile.
5+
# Lint javascript files using [eslint](http://eslint.org/).
6+
# Results are send as inline commen.
77
#
8-
# To be published on the Danger plugins site, you will need to have
9-
# the public interface documented. Danger uses [YARD](http://yardoc.org/)
10-
# for generating documentation from your plugin source, and you can verify
11-
# by running `danger plugins lint` or `bundle exec rake spec`.
8+
# @example Specifying custom config file.
129
#
13-
# You should replace these comments with a public description of your library.
14-
#
15-
# @example Ensure people are well warned about merging on Mondays
16-
#
17-
# my_plugin.warn_on_mondays
10+
# # Run eslint with changed files
11+
# eslint.filtering = true
12+
# eslint.lint
1813
#
1914
# @see leonhartX/danger-eslint
20-
# @tags monday, weekends, time, rattata
21-
#
15+
# @tags lint, javaxctipt
2216
class DangerEslint < Plugin
2317
# An path to eslint's config file
2418
# @return [String]
@@ -40,17 +34,7 @@ class DangerEslint < Plugin
4034
# @return [void]
4135
#
4236
def lint
43-
bin = eslint_path
44-
raise 'eslint is not installed' unless bin
45-
if filtering
46-
results = ((git.modified_files - git.deleted_files) + git.added_files)
47-
.select { |f| f.end_with? '.js' }
48-
.map { |f| f.gsub("#{Dir.pwd}/", '') }
49-
.map { |f| run_lint(bin, f).first }
50-
else
51-
results = run_lint(bin, '.')
52-
end
53-
results
37+
lint_results
5438
.reject { |r| r['messages'].length.zero? }
5539
.reject { |r| r['messages'].first['message'].include? 'matching ignore pattern' }
5640
.map { |r| send_comment r }
@@ -66,6 +50,19 @@ def eslint_path
6650
File.exist?(local) ? local : find_executable('eslint')
6751
end
6852

53+
# Get lint result regards the filtering option
54+
#
55+
# return [Hash]
56+
def lint_results
57+
bin = eslint_path
58+
raise 'eslint is not installed' unless bin
59+
return run_lint(bin, '.') unless filtering
60+
((git.modified_files - git.deleted_files) + git.added_files)
61+
.select { |f| f.end_with? '.js' }
62+
.map { |f| f.gsub("#{Dir.pwd}/", '') }
63+
.map { |f| run_lint(bin, f).first }
64+
end
65+
6966
# Run eslint aginst a single file.
7067
#
7168
# @param [String] bin

0 commit comments

Comments
 (0)