Skip to content

Commit

Permalink
fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
leonhartX committed Jun 19, 2017
1 parent 015ba98 commit c5c5c01
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
17 changes: 17 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Metrics/BlockLength:
Exclude:
- "**/*_spec.rb"

Metrics/LineLength:
Max: 120
Exclude:
- "**/*_spec.rb"

Metrics/ModuleLength:
Exclude:
- "**/*_spec.rb"

Metrics/AbcSize:
Enabled: true
Max: 25
45 changes: 21 additions & 24 deletions lib/eslint/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
require 'json'

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

# Get lint result regards the filtering option
#
# return [Hash]
def lint_results
bin = eslint_path
raise 'eslint is not installed' unless bin
return run_lint(bin, '.') unless filtering
((git.modified_files - git.deleted_files) + git.added_files)
.select { |f| f.end_with? '.js' }
.map { |f| f.gsub("#{Dir.pwd}/", '') }
.map { |f| run_lint(bin, f).first }
end

# Run eslint aginst a single file.
#
# @param [String] bin
Expand Down

0 comments on commit c5c5c01

Please sign in to comment.