pronto-tslint_npm 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da03fc982090f6383bc14a5730249ad01f258f96
4
+ data.tar.gz: b52f36a0334c0940afe7bf2d1ffd435db153e1f9
5
+ SHA512:
6
+ metadata.gz: 1189663781c0d25eaf313b13f8a4da62993ccecf79630ee50bbb9445aa902ec4e5d339c726491bfdd5f930cf1b807a78466144f285d00825329e7196049adcba
7
+ data.tar.gz: dd9202661c160992fd874db1cdaf56b21871ae65ff72ef7852691739b2e218c9e594d8dd02c1a5fb37dd187999018b66d460097c1be84a04e335f2cf175a976d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2016 Mindaugas Mozūras
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,46 @@
1
+ # Pronto runner for TSLint (using tslint from npm)
2
+ (forked from doits/pronto-eslint_npm)
3
+
4
+ <!--
5
+ [![Code Climate](https://codeclimate.com/github/doits/pronto-eslint_npm.svg)](https://codeclimate.com/github/doits/pronto-eslint_npm)
6
+ [![Build Status](https://travis-ci.org/doits/pronto-eslint_npm.svg?branch=master)](https://travis-ci.org/doits/pronto-eslint_npm)
7
+ [![Gem Version](https://badge.fury.io/rb/pronto-eslint_npm.svg)](http://badge.fury.io/rb/pronto-eslint_npm)
8
+ [![Dependency Status](https://gemnasium.com/doits/pronto-eslint_npm.svg)](https://gemnasium.com/doits/pronto-eslint_npm)
9
+ -->
10
+
11
+ Pronto runner for [TSlint](https://palantir.github.io/tslint/), pluggable linting utility for TypeScript. [What is Pronto?](https://github.com/mmozuras/pronto)
12
+
13
+ Uses official tslint executable installed by `npm`.
14
+
15
+ ## Prerequisites
16
+
17
+ You'll need to install [tslint by yourself with npm][tslint-install]. If `tslint` is in your `PATH`, everything will simply work, otherwise you have to provide pronto-tslint-npm your custom executable path (see [below](#configuration-of-tslintnpm)).
18
+
19
+ [eslint-install]: https://palantir.github.io/tslint/
20
+
21
+ ## Configuration of TSLint
22
+
23
+ Configuring TSLint via [tslint.json][tslint.json] will work just fine with pronto-eslint-npm.
24
+
25
+ [tslint.json]: https://palantir.github.io/tslint/usage/configuration/
26
+
27
+ [eslintignore]: http://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories
28
+
29
+ ## Configuration of ESLintNPM
30
+
31
+ pronto-eslint-npm can be configured by placing a `.pronto_tslint_npm.yml` inside the directory where pronto is run.
32
+
33
+ Following options are available:
34
+
35
+ | Option | Meaning | Default |
36
+ | ----------------- | ---------------------------------------------------------------------------------------- | ----------------------------------- |
37
+ | tslint_executable | TSLint executable to call. | `tslint` (calls `tslint` in `PATH`) |
38
+ | files_to_lint | What files to lint. Absolute path of offending file will be matched against this Regexp. | `(\.ts)$` |
39
+
40
+ Example configuration to call custom eslint executable and only lint files ending with `.my_custom_extension`:
41
+
42
+ ```yaml
43
+ # .pronto_tslint_npm.yml
44
+ tslint_executable: '/my/custom/node/path/.bin/tslint'
45
+ files_to_lint: '\.my_custom_extension$'
46
+ ```
@@ -0,0 +1,5 @@
1
+ module Pronto
2
+ module TSLintNpmVersion
3
+ VERSION = '0.0.2'.freeze
4
+ end
5
+ end
@@ -0,0 +1,94 @@
1
+ require 'pronto'
2
+ require 'shellwords'
3
+
4
+ module Pronto
5
+ class TSLintNpm < Runner
6
+ CONFIG_FILE = '.pronto_tslint_npm.yml'.freeze
7
+ CONFIG_KEYS = %w(tslint_executable files_to_lint).freeze
8
+
9
+ attr_writer :tslint_executable
10
+
11
+ def tslint_executable
12
+ @tslint_executable || 'tslint'.freeze
13
+ end
14
+
15
+ def files_to_lint
16
+ @files_to_lint || /(.*\.ts)$/
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
+
34
+ def run
35
+ return [] if !@patches || @patches.count.zero?
36
+ read_config
37
+ @patches
38
+ .select { |patch| patch.additions > 0 }
39
+ .select { |patch| ts_file?(patch.new_file_full_path) }
40
+ .map { |patch| inspect(patch) }
41
+ .flatten.compact
42
+ end
43
+
44
+ # private
45
+
46
+ def repo_path
47
+ @_repo_path ||= @patches.first.repo.path
48
+ end
49
+
50
+ def inspect(patch)
51
+ offences = run_tslint(patch)
52
+ clean_up_tslint_output(offences)
53
+ .map do |offence|
54
+ patch
55
+ .added_lines
56
+ .select { |line| line.new_lineno == offence[:line] }
57
+ .map { |line| new_message(offence[:msg], line) }
58
+ end
59
+ end
60
+
61
+ def new_message(offence, line)
62
+ path = line.patch.delta.new_file[:path]
63
+ level = :warning
64
+ Message.new(path, line, level, offence, nil, self.class)
65
+ end
66
+
67
+ def ts_file?(path)
68
+ !!(files_to_lint =~ path.to_s)
69
+ end
70
+
71
+ def run_tslint(patch)
72
+ Dir.chdir(repo_path) do
73
+ escaped_file_path = Shellwords.escape(patch.new_file_full_path.to_s)
74
+ JSON.parse(
75
+ `#{tslint_executable} #{escaped_file_path} -t json`
76
+ )
77
+ end
78
+ end
79
+
80
+ def clean_up_tslint_output(output)
81
+ # 1. Filter out offences without a warning or error
82
+ # 2. Get the messages for that file
83
+ # 3. Ignore errors without a line number for now
84
+ return [] unless output.count > 0
85
+ output.map do |offence|
86
+ {
87
+ msg: offence['failure'],
88
+ line: offence['startPosition']['line']
89
+ }
90
+ end
91
+
92
+ end
93
+ end
94
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-tslint_npm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Eddie Prislac
8
+ - Markus Doits
9
+ - Mindaugas Mozūras
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2017-06-08 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: pronto
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 0.9.1
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '11.0'
36
+ - - "<"
37
+ - !ruby/object:Gem::Version
38
+ version: '13'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '11.0'
46
+ - - "<"
47
+ - !ruby/object:Gem::Version
48
+ version: '13'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.4'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.4'
63
+ - !ruby/object:Gem::Dependency
64
+ name: byebug
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '9'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '9'
77
+ description:
78
+ email: edward.prislac@gmail.com
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files:
82
+ - LICENSE
83
+ - README.md
84
+ files:
85
+ - LICENSE
86
+ - README.md
87
+ - lib/pronto/tslint_npm.rb
88
+ - lib/pronto/tslint_npm/version.rb
89
+ homepage: https://github.com/eprislac/pronto-tslint_npm
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 2.0.0
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements:
108
+ - tslint (in PATH)
109
+ rubyforge_project:
110
+ rubygems_version: 2.5.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Pronto runner for TSLint, pluggable linting utility for JavaScript and JSX
114
+ test_files: []