lib/eslint/plugin.rb in danger-eslint-0.1.4 vs lib/eslint/plugin.rb in danger-eslint-0.1.5

- old
+ new

@@ -11,10 +11,12 @@ # eslint.lint # # @see leonhartX/danger-eslint # @tags lint, javaxctipt class DangerEslint < Plugin + DEFAULT_BIN_PATH = './node_modules/.bin/eslint' + # An path to eslint's config file # @return [String] attr_accessor :config_file # An path to eslint's ignore file @@ -24,10 +26,24 @@ # Enable filtering # Only show messages within changed files. # @return [Boolean] attr_accessor :filtering + # A path of eslint's bin + attr_writer :bin_path + def bin_path + @bin_path ||= DEFAULT_BIN_PATH + end + + # Specified extentions of target file + # Default is [".js"] + # @return [Array] + attr_writer :target_extensions + def target_extensions + @target_extensions ||= %W(.js) + end + # Lints javascript files. # Generates `errors` and `warnings` due to eslint's config. # Will try to send inline comment if supported(Github) # # @return [void] @@ -43,22 +59,21 @@ # Get eslint' bin path # # return [String] def eslint_path - local = './node_modules/.bin/eslint' - File.exist?(local) ? local : find_executable('eslint') + File.exist?(bin_path) ? bin_path : 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' } + .select { |f| target_extensions.include?(File.extname(f)) } .map { |f| f.gsub("#{Dir.pwd}/", '') } .map { |f| run_lint(bin, f).first } end # Run eslint aginst a single file.