pronto-flow 0.8.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43a98d9323d5fad4588a3f824cdffc769af7d7ca
4
+ data.tar.gz: eb79982e5f36586cebacf8d02fda5342d228c1d8
5
+ SHA512:
6
+ metadata.gz: b539db7bff0a2e7dd78e97ae9ad4682e17aceee5bf3cbaaeb337912ec283dc9c9bca5b23a143a9db38db47418b8d9da4f3f4815bbac04a062189f6a6e0aa3b55
7
+ data.tar.gz: f8dc82643ccf728e3b7f4728cf37a2bc8fcd57f68b3fa8c417a5d9e65b552d09a159d840e780c1882104a2f6a36158327103f2943d2f9d62e4bac60c4dfd4b82
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2017 Kevin Jalbert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Pronto runner for flow (using flow from npm)
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/pronto-flow.svg)](http://badge.fury.io/rb/pronto-flow)
4
+ [![Build Status](https://travis-ci.org/kevinjalbert/pronto-flow.svg?branch=master)](https://travis-ci.org/kevinjalbert/pronto-flow)
5
+ [![Code Climate](https://codeclimate.com/github/kevinjalbert/pronto-flow/badges/gpa.svg)](https://codeclimate.com/github/kevinjalbert/pronto-flow)
6
+ [![Test Coverage](https://codeclimate.com/github/kevinjalbert/pronto-flow/badges/coverage.svg)](https://codeclimate.com/github/kevinjalbert/pronto-flow/coverage)
7
+ [![Dependency Status](https://gemnasium.com/badges/github.com/kevinjalbert/pronto-flow.svg)](https://gemnasium.com/github.com/kevinjalbert/pronto-flow)
8
+
9
+ Pronto runner for [flow](https://flow.org/), a static type checker for javascript. [What is Pronto?](https://github.com/mmozuras/pronto)
10
+
11
+ Uses official flow executable installed by `npm`.
12
+
13
+ ## Prerequisites
14
+
15
+ You'll need to install [flow by yourself with npm](https://flow.org/en/docs/install/). If `flow` is in your `PATH`, everything will simply work, otherwise you have to provide pronto-flow your custom executable path (see [below](#configuration-of-pronto-flow)).
16
+
17
+ ## Configuration of flow
18
+
19
+ Configuring flow via [.flowconfig](https://flow.org/en/docs/config/) will work just fine with pronto-flow.
20
+
21
+ ## Configuration of pronto-flow
22
+
23
+ pronto-flow can be configured by placing a `.pronto_flow.yml` inside the directory where pronto is run.
24
+
25
+ Following options are available:
26
+
27
+ | Option | Meaning | Default |
28
+ | -------------------- | -------------------------------------- | ----------------------------------------- |
29
+ | flow_executable | flow executable to call. | `flow` (calls `flow` in `PATH`) |
30
+
31
+ Example configuration to call custom flow executable:
32
+
33
+ ```yaml
34
+ # .pronto_flow.yml
35
+ flow_executable: '/my/custom/node/path/.bin/flow'
36
+ ```
@@ -0,0 +1,5 @@
1
+ module Pronto
2
+ module FlowVersion
3
+ VERSION = '0.8.2'.freeze
4
+ end
5
+ end
@@ -0,0 +1,107 @@
1
+ require 'pronto'
2
+ require 'shellwords'
3
+
4
+ module Pronto
5
+ class Flow < Runner
6
+ CONFIG_FILE = '.pronto_flow.yml'.freeze
7
+ CONFIG_KEYS = %w(flow_executable).freeze
8
+
9
+ attr_writer :flow_executable
10
+
11
+ def flow_executable
12
+ @flow_executable || 'flow'.freeze
13
+ end
14
+
15
+ def files
16
+ return [] if @patches.nil?
17
+
18
+ @files ||= begin
19
+ @patches
20
+ .select { |patch| patch.additions > 0 }
21
+ .map(&:new_file_full_path)
22
+ .compact
23
+ end
24
+ end
25
+
26
+ def patch_line_for_offence(path, lineno)
27
+ patch_node = @patches.find do |patch|
28
+ patch.new_file_full_path.to_s == path
29
+ end
30
+
31
+ return if patch_node.nil?
32
+
33
+ patch_node.added_lines.find do |patch_line|
34
+ patch_line.new_lineno == lineno
35
+ end
36
+ end
37
+
38
+ def read_config
39
+ config_file = File.join(repo_path, CONFIG_FILE)
40
+ return unless File.exist?(config_file)
41
+ config = YAML.load_file(config_file)
42
+
43
+ CONFIG_KEYS.each do |config_key|
44
+ next unless config[config_key]
45
+ send("#{config_key}=", config[config_key])
46
+ end
47
+ end
48
+
49
+ def run
50
+ if files.any?
51
+ read_config
52
+ messages(run_flow)
53
+ else
54
+ []
55
+ end
56
+ end
57
+
58
+ def run_flow
59
+ Dir.chdir(repo_path) do
60
+ return JSON.parse(`#{flow_executable} --json`)
61
+ end
62
+ end
63
+
64
+ def description_for_error(data, first_line_error_in_patch)
65
+ description = data.map do |item|
66
+ item[:descr]
67
+ end.join(" ")
68
+
69
+ see_file_paths = data.map do |item|
70
+ next if item[:path].nil? || item[:path].empty?
71
+
72
+ file_path = item[:path].sub(repo_path.to_s + File::SEPARATOR, "")
73
+
74
+ next if file_path == first_line_error_in_patch.patch.delta.new_file[:path]
75
+
76
+ "\nSee: #{file_path}:#{item[:line]}"
77
+ end
78
+
79
+ description = description + see_file_paths.join("")
80
+ end
81
+
82
+ def messages(json_output)
83
+ json_output["errors"].map do |error|
84
+ first_patch_with_error = nil
85
+ files_associated_with_error = []
86
+
87
+ data = error["message"].map do |context|
88
+ data = { descr: context["descr"], path: context["path"], line: context["line"] }
89
+ end
90
+
91
+ first_line_error_in_patch = data.map do |item|
92
+ patch_line_for_offence(item[:path], item[:line])
93
+ end.compact.first
94
+
95
+ next if first_line_error_in_patch.nil?
96
+
97
+ description = description_for_error(data, first_line_error_in_patch)
98
+
99
+ path = first_line_error_in_patch.patch.delta.new_file[:path]
100
+
101
+ level = error["level"].to_sym
102
+
103
+ Message.new(path, first_line_error_in_patch, level, description, nil, self.class)
104
+ end
105
+ end
106
+ end
107
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-flow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.2
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Jalbert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pronto
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description:
56
+ email: kevin.j.jalbert@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files:
60
+ - LICENSE
61
+ - README.md
62
+ files:
63
+ - LICENSE
64
+ - README.md
65
+ - lib/pronto/flow.rb
66
+ - lib/pronto/flow/version.rb
67
+ homepage: https://github.com/kevinjalbert/pronto-flow
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.0.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements:
86
+ - flow (in PATH)
87
+ rubyforge_project:
88
+ rubygems_version: 2.6.11
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Pronto runner for flow, a static type checker for javascript.
92
+ test_files: []