From 5001cb27fe21f4fdbc20f95b44ee99bbd9812730 Mon Sep 17 00:00:00 2001 From: Markus Doits Date: Thu, 11 Aug 2016 16:02:45 +0200 Subject: rebrand to Pronto::ESLintNpm --- README.md | 16 ++++++++------ lib/pronto/eslint-npm.rb | 46 ++++++++++++++++++++++++++++++++++++++++ lib/pronto/eslint-npm/version.rb | 5 +++++ lib/pronto/eslint.rb | 46 ---------------------------------------- lib/pronto/eslint/version.rb | 5 ----- pronto-eslint-npm.gemspec | 31 +++++++++++++++++++++++++++ pronto-eslint.gemspec | 41 ----------------------------------- spec/pronto/eslint_spec.rb | 4 ++-- spec/spec_helper.rb | 2 +- 9 files changed, 95 insertions(+), 101 deletions(-) create mode 100644 lib/pronto/eslint-npm.rb create mode 100644 lib/pronto/eslint-npm/version.rb delete mode 100644 lib/pronto/eslint.rb delete mode 100644 lib/pronto/eslint/version.rb create mode 100644 pronto-eslint-npm.gemspec delete mode 100644 pronto-eslint.gemspec diff --git a/README.md b/README.md index f07434c..fed1dde 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,19 @@ -# Pronto runner for ESLint +# Pronto runner for ESLint (using eslint from npm) -[![Code Climate](https://codeclimate.com/github/mmozuras/pronto-eslint.png)](https://codeclimate.com/github/mmozuras/pronto-eslint) -[![Build Status](https://travis-ci.org/mmozuras/pronto-eslint.png)](https://travis-ci.org/mmozuras/pronto-eslint) -[![Gem Version](https://badge.fury.io/rb/pronto-eslint.png)](http://badge.fury.io/rb/pronto-eslint) -[![Dependency Status](https://gemnasium.com/mmozuras/pronto-eslint.png)](https://gemnasium.com/mmozuras/pronto-eslint) +[![Code Climate](https://codeclimate.com/github/doits/pronto-eslint-npm.png)](https://codeclimate.com/github/doits/pronto-eslint-npm) +[![Build Status](https://travis-ci.org/doits/pronto-eslint.png)](https://travis-ci.org/doits/pronto-eslint-npm) +[![Gem Version](https://badge.fury.io/rb/pronto-eslint-npm.png)](http://badge.fury.io/rb/pronto-eslint-npm) +[![Dependency Status](https://gemnasium.com/doits/pronto-eslint-npm.png)](https://gemnasium.com/doits/pronto-eslint-npm) Pronto runner for [ESlint](http://eslint.org), pluggable linting utility for JavaScript and JSX. [What is Pronto?](https://github.com/mmozuras/pronto) +Uses system wide installed eslint in contrast to [pronto-eslint][pronto-eslint]. + +[eslint-pronto]: https://github.com/mmozuras/pronto-eslint + ## Prerequisites -You'll need to install [eslint by yourself][eslint-install]. +You'll need to install [eslint by yourself with npm][eslint-install]. [eslint-install]: http://eslint.org/docs/user-guide/getting-started diff --git a/lib/pronto/eslint-npm.rb b/lib/pronto/eslint-npm.rb new file mode 100644 index 0000000..a3219eb --- /dev/null +++ b/lib/pronto/eslint-npm.rb @@ -0,0 +1,46 @@ +require 'pronto' + +module Pronto + class ESLintNpm < Runner + def run + return [] unless @patches + + @patches.select { |patch| patch.additions > 0 } + .select { |patch| js_file?(patch.new_file_full_path) } + .map { |patch| inspect(patch) } + .flatten.compact + end + + def inspect(patch) + @_repo_path ||= @patches.first.repo.path + + offences = + Dir.chdir(@_repo_path) do + JSON.parse(`eslint #{Shellwords.escape(patch.new_file_full_path.to_s)} -f json`) + end + + offences = + offences + .select { |offence| offence['errorCount'] > 0 || offence['warningCount'] > 0 } # no warning or error, no problem + .map { |offence| offence['messages'] } # get error messages for that file + .flatten + .select { |offence| offence['line'] } # for now ignore errors without a line number + + offences.map do |offence| + patch.added_lines.select { |line| line.new_lineno == offence['line'] } + .map { |line| new_message(offence, line) } + end + end + + def new_message(offence, line) + path = line.patch.delta.new_file[:path] + level = :warning + + Message.new(path, line, level, offence['message'], nil, self.class) + end + + def js_file?(path) + %w(.js .es6 .js.es6).include?(File.extname(path)) + end + end +end diff --git a/lib/pronto/eslint-npm/version.rb b/lib/pronto/eslint-npm/version.rb new file mode 100644 index 0000000..7012232 --- /dev/null +++ b/lib/pronto/eslint-npm/version.rb @@ -0,0 +1,5 @@ +module Pronto + module ESLintNpmVersion + VERSION = '0.7.0'.freeze + end +end diff --git a/lib/pronto/eslint.rb b/lib/pronto/eslint.rb deleted file mode 100644 index a2ec738..0000000 --- a/lib/pronto/eslint.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'pronto' - -module Pronto - class ESLint < Runner - def run - return [] unless @patches - - @patches.select { |patch| patch.additions > 0 } - .select { |patch| js_file?(patch.new_file_full_path) } - .map { |patch| inspect(patch) } - .flatten.compact - end - - def inspect(patch) - @_repo_path ||= @patches.first.repo.path - - offences = - Dir.chdir(@_repo_path) do - JSON.parse(`eslint #{Shellwords.escape(patch.new_file_full_path.to_s)} -f json`) - end - - offences = - offences - .select { |offence| offence['errorCount'] > 0 || offence['warningCount'] > 0 } # no warning or error, no problem - .map { |offence| offence['messages'] } # get error messages for that file - .flatten - .select { |offence| offence['line'] } # for now ignore errors without a line number - - offences.map do |offence| - patch.added_lines.select { |line| line.new_lineno == offence['line'] } - .map { |line| new_message(offence, line) } - end - end - - def new_message(offence, line) - path = line.patch.delta.new_file[:path] - level = :warning - - Message.new(path, line, level, offence['message'], nil, self.class) - end - - def js_file?(path) - %w(.js .es6 .js.es6).include?(File.extname(path)) - end - end -end diff --git a/lib/pronto/eslint/version.rb b/lib/pronto/eslint/version.rb deleted file mode 100644 index 0b9940a..0000000 --- a/lib/pronto/eslint/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Pronto - module ESLintVersion - VERSION = '0.6.2'.freeze - end -end diff --git a/pronto-eslint-npm.gemspec b/pronto-eslint-npm.gemspec new file mode 100644 index 0000000..9447bb8 --- /dev/null +++ b/pronto-eslint-npm.gemspec @@ -0,0 +1,31 @@ +# -*- encoding: utf-8 -*- + +$LOAD_PATH.push File.expand_path('../lib', __FILE__) +require 'pronto/eslint-npm/version' +require 'rake' + +Gem::Specification.new do |s| + s.name = 'pronto-eslint-npm' + s.version = Pronto::ESLintNpmVersion::VERSION + s.platform = Gem::Platform::RUBY + s.authors = ['Markus Doits', 'Mindaugas Mozūras'] + s.email = 'markus.doits@gmail.com' + s.homepage = 'http://github.org/doits/pronto-eslint-npm' + s.summary = <<-EOF + Pronto runner for ESLint, pluggable linting utility for JavaScript and JSX + EOF + + s.licenses = ['MIT'] + s.required_ruby_version = '>= 1.9.3' + s.rubygems_version = '1.8.23' + + s.files = FileList['LICENSE', 'README.md', 'lib/*'] + s.extra_rdoc_files = ['LICENSE', 'README.md'] + s.require_paths = ['lib'] + s.requirements << 'eslint (in PATH)' + + s.add_dependency('pronto', '~> 0.7.0') + s.add_development_dependency('rake', '~> 11.0') + s.add_development_dependency('rspec', '~> 3.4') + s.add_development_dependency('rspec-its', '~> 1.2') +end diff --git a/pronto-eslint.gemspec b/pronto-eslint.gemspec deleted file mode 100644 index d6590ec..0000000 --- a/pronto-eslint.gemspec +++ /dev/null @@ -1,41 +0,0 @@ -# -*- encoding: utf-8 -*- -# -$LOAD_PATH.push File.expand_path('../lib', __FILE__) -require 'pronto/eslint/version' -require 'English' - -Gem::Specification.new do |s| - s.name = 'pronto-eslint' - s.version = Pronto::ESLintVersion::VERSION - s.platform = Gem::Platform::RUBY - s.author = 'Mindaugas Mozūras' - s.email = 'mindaugas.mozuras@gmail.com' - s.homepage = 'http://github.org/mmozuras/pronto-eslintt' - s.summary = <<-EOF - Pronto runner for ESLint, pluggable linting utility for JavaScript and JSX - EOF - - s.licenses = ['MIT'] - s.required_ruby_version = '>= 1.9.3' - s.rubygems_version = '1.8.23' - - s.files = `git ls-files`.split($RS).reject do |file| - file =~ %r{^(?: - spec/.* - |Gemfile - |Rakefile - |\.rspec - |\.gitignore - |\.rubocop.yml - |\.travis.yml - )$}x - end - s.test_files = [] - s.extra_rdoc_files = ['LICENSE', 'README.md'] - s.require_paths = ['lib'] - - s.add_dependency('pronto', '~> 0.6.0') - s.add_development_dependency('rake', '~> 11.0') - s.add_development_dependency('rspec', '~> 3.4') - s.add_development_dependency('rspec-its', '~> 1.2') -end diff --git a/spec/pronto/eslint_spec.rb b/spec/pronto/eslint_spec.rb index 27f57d1..f6a5ed0 100644 --- a/spec/pronto/eslint_spec.rb +++ b/spec/pronto/eslint_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' module Pronto - describe ESLint do - let(:eslint) { ESLint.new(patches) } + describe ESLintNpm do + let(:eslint) { ESLintNpm.new(patches) } describe '#run' do subject { eslint.run } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5769c2d..66266cc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require 'rspec' require 'rspec/its' -require 'pronto/eslint' +require 'pronto/eslint-npm' %w(test eslintignore).each do |repo_name| RSpec.shared_context "#{repo_name} repo" do -- cgit v1.2.3