pronto-eslint_npm 0.7.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70ee17c24d2de82f6324109da2f7f020249bd060
4
- data.tar.gz: 183e13d563090e0effde44519400af9139debe46
3
+ metadata.gz: 606c381f93b0e8785e967394f259303420e7e517
4
+ data.tar.gz: 883b1c12ef76bd5bc68144e2f06fa5978fce6eb2
5
5
  SHA512:
6
- metadata.gz: 7b4a13dce0e0181a1ec5bfc88d9c52c72e5bd181fa0df719dcaa2c2e10202aac3c047c3ce983a9a51a36ebb8156076109e7261a0e8ae1a27a4db8273b1621663
7
- data.tar.gz: acd24953accc803f2606fbb11baa2636840176cba344d6c945adb9887aeeb6907592373a6f0346a0779282f6fa9555693953f26774aad5e4961f8dcc36499980
6
+ metadata.gz: 3074674affe7f46e56915fbaf62f4400f8ed578f890598dafa789ee8822c5898ea22c289857b5c21e70e3d5691a96053d2719c144fa6e956b621448596b4079b
7
+ data.tar.gz: ed15b03ea2848117e954cabffe2c8fa2ad55454bff0145afed1859fa8af0b785b9d4ea0df262d236c90af413d9249b9e1663c1b905fd36f6ad05b628a44f09ac
data/README.md CHANGED
@@ -7,19 +7,39 @@
7
7
 
8
8
  Pronto runner for [ESlint](http://eslint.org), pluggable linting utility for JavaScript and JSX. [What is Pronto?](https://github.com/mmozuras/pronto)
9
9
 
10
- Uses system wide installed eslint in contrast to [pronto-eslint][pronto-eslint].
10
+ Uses official eslint executable installed by `npm` in contrast to [pronto-eslint][pronto-eslint].
11
11
 
12
12
  [pronto-eslint]: https://github.com/mmozuras/pronto-eslint
13
13
 
14
14
  ## Prerequisites
15
15
 
16
- You'll need to install [eslint by yourself with npm][eslint-install].
16
+ You'll need to install [eslint by yourself with npm][eslint-install]. If `eslint` is in your `PATH`, everything will simply work, otherwise you have to provide pronto-eslint-npm your custom executable path (see [below](#configuration-of-eslintnpm)).
17
17
 
18
18
  [eslint-install]: http://eslint.org/docs/user-guide/getting-started
19
19
 
20
- ## Configuration
20
+ ## Configuration of ESLint
21
21
 
22
- Configuring ESLint via [.eslintrc and consorts][eslintrc] and excludes via [.eslintignore][eslintignore] will work just fine with pronto-eslint.
22
+ Configuring ESLint via [.eslintrc and consorts][eslintrc] and excludes via [.eslintignore][eslintignore] will work just fine with pronto-eslint-npm.
23
23
 
24
24
  [eslintrc]: http://eslint.org/docs/user-guide/configuring#configuration-file-formats
25
+
25
26
  [eslintignore]: http://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories
27
+
28
+ ## Configuration of ESLintNPM
29
+
30
+ pronto-eslint-npm can be configured by placing a `.pronto_eslint_npm.yml` inside the directory where pronto is run.
31
+
32
+ Following options are available:
33
+
34
+ | Option | Meaning | Default |
35
+ | ----------------- | ---------------------------------------------------------------------------------------- | ----------------------------------- |
36
+ | eslint_executable | ESLint executable to call. | `eslint` (calls `eslint` in `PATH`) |
37
+ | files_to_lint | What files to lint. Absolute path of offending file will be matched against this Regexp. | `(\.js|\.es6)$` |
38
+
39
+ Example configuration to call custom eslint executable and only lint files ending with `.my_custom_extension`:
40
+
41
+ ```yaml
42
+ # .pronto_eslint_npm.yaml
43
+ eslint_executable: '/my/custom/node/path/.bin/eslint'
44
+ files_to_lint: '\.my_custom_extension$'
45
+ ```
@@ -1,19 +1,55 @@
1
1
  require 'pronto'
2
+ require 'shellwords'
2
3
 
3
4
  module Pronto
4
5
  class ESLintNpm < Runner
6
+ CONFIG_FILE = '.pronto_eslint_npm.yml'.freeze
7
+ CONFIG_KEYS = %w(eslint_executable files_to_lint).freeze
8
+
9
+ attr_writer :eslint_executable
10
+
11
+ def eslint_executable
12
+ @eslint_executable || 'eslint'.freeze
13
+ end
14
+
15
+ def files_to_lint
16
+ @files_to_lint || /(\.js|\.es6)$/
17
+ end
18
+
19
+ def files_to_lint=(regexp)
20
+ @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp)
21
+ end
22
+
23
+ def read_config
24
+ config_file = File.join(repo_path, CONFIG_FILE)
25
+ return unless File.exist?(config_file)
26
+ config = YAML.load_file(config_file)
27
+
28
+ CONFIG_KEYS.each do |config_key|
29
+ next unless config[config_key]
30
+ send("#{config_key}=", config[config_key])
31
+ end
32
+ end
33
+
5
34
  def run
6
- return [] unless @patches
35
+ return [] if !@patches || @patches.count.zero?
36
+
37
+ read_config
7
38
 
8
- @patches.select { |patch| patch.additions > 0 }
39
+ @patches
40
+ .select { |patch| patch.additions > 0 }
9
41
  .select { |patch| js_file?(patch.new_file_full_path) }
10
42
  .map { |patch| inspect(patch) }
11
43
  .flatten.compact
12
44
  end
13
45
 
14
- def inspect(patch)
46
+ private
47
+
48
+ def repo_path
15
49
  @_repo_path ||= @patches.first.repo.path
50
+ end
16
51
 
52
+ def inspect(patch)
17
53
  offences = run_eslint(patch)
18
54
  clean_up_eslint_output(offences)
19
55
  .map do |offence|
@@ -24,8 +60,6 @@ module Pronto
24
60
  end
25
61
  end
26
62
 
27
- private
28
-
29
63
  def new_message(offence, line)
30
64
  path = line.patch.delta.new_file[:path]
31
65
  level = :warning
@@ -34,18 +68,18 @@ module Pronto
34
68
  end
35
69
 
36
70
  def js_file?(path)
37
- %w(.js .es6 .js.es6).include?(File.extname(path))
71
+ files_to_lint =~ path.to_s
38
72
  end
39
73
 
40
74
  def run_eslint(patch)
41
- Dir.chdir(@_repo_path) do
75
+ Dir.chdir(repo_path) do
76
+ escaped_file_path = Shellwords.escape(patch.new_file_full_path.to_s)
42
77
  JSON.parse(
43
- `eslint #{Shellwords.escape(patch.new_file_full_path.to_s)} -f json`
78
+ `#{eslint_executable} #{escaped_file_path} -f json`
44
79
  )
45
80
  end
46
81
  end
47
82
 
48
- # rubocop:disable Metrics/LineLength
49
83
  def clean_up_eslint_output(output)
50
84
  # 1. Filter out offences without a warning or error
51
85
  # 2. Get the messages for that file
@@ -1,5 +1,5 @@
1
1
  module Pronto
2
2
  module ESLintNpmVersion
3
- VERSION = '0.7.0'.freeze
3
+ VERSION = '0.7.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pronto-eslint_npm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Doits
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-11 00:00:00.000000000 Z
12
+ date: 2016-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pronto
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.4'
56
- - !ruby/object:Gem::Dependency
57
- name: rspec-its
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '1.2'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '1.2'
70
56
  description:
71
57
  email: markus.doits@gmail.com
72
58
  executables: []