roger_eslint 1.0.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +6 -6
- data/README.md +3 -3
- data/lib/roger_eslint/lint.rb +53 -36
- data/lib/roger_eslint/version.rb +2 -1
- data/test/lint_test.rb +23 -11
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8e887ef2a6fc0f33e0402f5a8dd6019bd2423c3
|
4
|
+
data.tar.gz: c553c89bc35b5eda0000d2ad550c5b0fd3d6a249
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e0b0a41bec1718f8ce7e1be4a9cf08984b07c21352084fd085595cd89f1c2da3b7556d1b24af52dd6c031ef800a29e2958de8db0de2087d523984368c5e85f8
|
7
|
+
data.tar.gz: d6e0c8788b0a9731dc45629fed1fde498db61893f4f7c203dccac4d7ff49224c8883ff2357bfec40ed4e8d8a0e0f7ae594620b8b298592700b1f8acaa46aef2f
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
roger_eslint (1.0.
|
4
|
+
roger_eslint (1.0.1)
|
5
5
|
roger (~> 1.5, >= 1.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,18 +10,18 @@ GEM
|
|
10
10
|
ast (2.2.0)
|
11
11
|
hpricot (0.8.4)
|
12
12
|
metaclass (0.0.4)
|
13
|
-
mime-types (2.99)
|
13
|
+
mime-types (2.99.2)
|
14
14
|
mocha (1.1.0)
|
15
15
|
metaclass (~> 0.0.1)
|
16
16
|
parser (2.3.0.1)
|
17
17
|
ast (~> 2.2)
|
18
18
|
power_assert (0.2.7)
|
19
19
|
powerpack (0.1.1)
|
20
|
-
rack (
|
20
|
+
rack (2.0.1)
|
21
21
|
rainbow (2.0.0)
|
22
22
|
rake (10.5.0)
|
23
23
|
redcarpet (3.3.4)
|
24
|
-
roger (1.
|
24
|
+
roger (1.6.1)
|
25
25
|
hpricot (= 0.8.4)
|
26
26
|
mime-types (~> 2.2)
|
27
27
|
rack (>= 1.0.0)
|
@@ -39,7 +39,7 @@ GEM
|
|
39
39
|
power_assert
|
40
40
|
test_construct (2.0.1)
|
41
41
|
thor (0.19.1)
|
42
|
-
tilt (2.0.
|
42
|
+
tilt (2.0.5)
|
43
43
|
|
44
44
|
PLATFORMS
|
45
45
|
ruby
|
@@ -53,4 +53,4 @@ DEPENDENCIES
|
|
53
53
|
thor (~> 0)
|
54
54
|
|
55
55
|
BUNDLED WITH
|
56
|
-
1.
|
56
|
+
1.12.5
|
data/README.md
CHANGED
@@ -4,12 +4,12 @@ Roger ESLint
|
|
4
4
|
[![Build Status](https://travis-ci.org/DigitPaint/roger_eslint.svg)](https://travis-ci.org/DigitPaint/roger_eslint)
|
5
5
|
|
6
6
|
|
7
|
-
Lint JavaScript files from within Roger. This plugin uses [eslint](http://eslint.org/). If present, .eslintrc in your project will be used. If not,
|
7
|
+
Lint JavaScript files from within Roger. This plugin uses [eslint](http://eslint.org/). If present, .eslintrc in your project will be used. If not, eslint will walk the directory tree upwards until a .eslintrc file is found.
|
8
8
|
|
9
9
|
## Installation
|
10
|
-
* Install
|
10
|
+
* Install eslint using npm: ```npm install eslint -g```
|
11
11
|
|
12
|
-
* Add ```gem '
|
12
|
+
* Add ```gem 'roger_eslint'``` to your Gemfile
|
13
13
|
|
14
14
|
* Add this to your Mockupfile:
|
15
15
|
```
|
data/lib/roger_eslint/lint.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "shellwords"
|
2
|
+
require "pathname"
|
2
3
|
require "json"
|
3
4
|
require "roger/test"
|
4
5
|
|
@@ -31,32 +32,12 @@ module RogerEslint
|
|
31
32
|
@options.update(options) if options
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
# @return [Array] failed files
|
36
|
+
def lint(test, file_paths)
|
37
|
+
output = `#{eslint_command(file_paths)}`
|
38
|
+
file_lints = JSON.parse(output)
|
37
39
|
|
38
|
-
|
39
|
-
test.warn(self, "No files linted")
|
40
|
-
return true
|
41
|
-
end
|
42
|
-
|
43
|
-
success = file_lints["errorCount"] <= 0
|
44
|
-
success &&= file_lints["warningCount"] <= 0 if @_call_options[:fail_on_warning]
|
45
|
-
|
46
|
-
fixables = []
|
47
|
-
|
48
|
-
if success
|
49
|
-
test.log(self, "#{file_path}: OK")
|
50
|
-
else
|
51
|
-
file_lints["messages"].each do |message|
|
52
|
-
fixables << message if message["fix"]
|
53
|
-
report_message(test, file_path, message)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
report_fixables(test, file_path, fixables)
|
58
|
-
|
59
|
-
success
|
40
|
+
process_lint_results(test, file_lints)
|
60
41
|
end
|
61
42
|
|
62
43
|
# @param [Hash] options The options
|
@@ -69,16 +50,44 @@ module RogerEslint
|
|
69
50
|
|
70
51
|
test.log(self, "ESLinting files")
|
71
52
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
failures.empty?
|
53
|
+
files = test.get_files(@_call_options[:match], @_call_options[:skip])
|
54
|
+
|
55
|
+
lint(test, files).empty?
|
76
56
|
ensure
|
77
57
|
@_call_options = {}
|
78
58
|
end
|
79
59
|
|
80
60
|
private
|
81
61
|
|
62
|
+
def process_lint_results(test, file_lints)
|
63
|
+
if file_lints.empty?
|
64
|
+
test.warn(self, "No files linted")
|
65
|
+
return []
|
66
|
+
end
|
67
|
+
|
68
|
+
file_lints.select do |file_lint|
|
69
|
+
path = file_lint["filePath"]
|
70
|
+
|
71
|
+
success = file_lint["errorCount"] <= 0
|
72
|
+
success &&= file_lint["warningCount"] <= 0 if @_call_options[:fail_on_warning]
|
73
|
+
|
74
|
+
fixables = []
|
75
|
+
|
76
|
+
if success
|
77
|
+
test.log(self, "#{normalize_path(test, path)}: OK")
|
78
|
+
else
|
79
|
+
file_lint["messages"].each do |message|
|
80
|
+
fixables << message if message["fix"]
|
81
|
+
report_message(test, path, message)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
report_fixables(test, path, fixables)
|
86
|
+
|
87
|
+
!success
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
82
91
|
def eslint_command(file_path, extras = [])
|
83
92
|
command = [
|
84
93
|
@_call_options[:eslint],
|
@@ -88,17 +97,19 @@ module RogerEslint
|
|
88
97
|
command += @_call_options[:eslint_options] if @_call_options[:eslint_options]
|
89
98
|
|
90
99
|
command += extras
|
91
|
-
|
100
|
+
if file_path.is_a? Array
|
101
|
+
command += file_path
|
102
|
+
else
|
103
|
+
command << file_path
|
104
|
+
end
|
92
105
|
|
93
106
|
Shellwords.join(command)
|
94
107
|
end
|
95
108
|
|
96
109
|
def report_message(test, file_path, message)
|
97
|
-
output = "#{file_path}: "
|
98
|
-
output << message[
|
99
|
-
output << "
|
100
|
-
output << message["column"].to_s
|
101
|
-
output << " ["
|
110
|
+
output = "#{normalize_path(test, file_path)}: "
|
111
|
+
output << "#{message['line']}:#{message['column']} "
|
112
|
+
output << "["
|
102
113
|
output << ESLINT_SEVERITIES[message["severity"]]
|
103
114
|
output << " (Fixable)" if message["fix"]
|
104
115
|
output << "] "
|
@@ -111,7 +122,7 @@ module RogerEslint
|
|
111
122
|
def report_fixables(test, file_path, fixables)
|
112
123
|
if fixables.any?
|
113
124
|
test.log(self, "#{fixables.size} problems can be fixed automatically. Run:")
|
114
|
-
test.log(self, " #{eslint_command(file_path, ['--fix'])}")
|
125
|
+
test.log(self, " #{eslint_command(normalize_path(test, file_path), ['--fix'])}")
|
115
126
|
end
|
116
127
|
end
|
117
128
|
|
@@ -139,6 +150,12 @@ module RogerEslint
|
|
139
150
|
fail ArgumentError, err
|
140
151
|
end
|
141
152
|
end
|
153
|
+
|
154
|
+
# Will make path relative to project dir
|
155
|
+
# @return [String] relative path
|
156
|
+
def normalize_path(test, path)
|
157
|
+
Pathname.new(path).relative_path_from(test.project.path.realpath).to_s
|
158
|
+
end
|
142
159
|
end
|
143
160
|
end
|
144
161
|
|
data/lib/roger_eslint/version.rb
CHANGED
data/test/lint_test.rb
CHANGED
@@ -41,48 +41,60 @@ class LintTest < Test::Unit::TestCase
|
|
41
41
|
|
42
42
|
def test_detect_eslint
|
43
43
|
assert_nothing_raised do
|
44
|
-
|
44
|
+
lint_files "test.js"
|
45
45
|
end
|
46
46
|
|
47
47
|
assert_raise(ArgumentError) do
|
48
|
-
|
48
|
+
lint_files "test.js", eslint: "eslint-blabla"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_lint_nonexisting_file
|
53
|
-
success, messages =
|
53
|
+
success, messages = lint_files("test/data/does_not_exist.js")
|
54
54
|
|
55
55
|
assert success
|
56
56
|
assert_equal "No files linted", messages[0]
|
57
57
|
end
|
58
58
|
|
59
|
+
def test_lint_multiple_files
|
60
|
+
success, messages = lint_files(
|
61
|
+
["test/data/error.js", "test/data/fixable.js"],
|
62
|
+
eslint_options: ["--no-eslintrc", "--rule", "semi: 2"]
|
63
|
+
)
|
64
|
+
|
65
|
+
assert !success
|
66
|
+
|
67
|
+
assert_equal("test/data/error.js: OK", messages[0])
|
68
|
+
assert_equal("test/data/fixable.js: 1:15 [Error (Fixable)] Missing semicolon.", messages[1])
|
69
|
+
end
|
70
|
+
|
59
71
|
def test_lint_with_default_eslintrc
|
60
72
|
eslintrc_file = ".eslintrc.js"
|
61
73
|
assert !File.exist?(eslintrc_file), ".eslintrc.js file already exists."
|
62
74
|
FileUtils.cp("./test/data/.eslintrc-no-undef.js", eslintrc_file)
|
63
75
|
|
64
76
|
file = "test/data/error.js"
|
65
|
-
success, messages =
|
77
|
+
success, messages = lint_files(file)
|
66
78
|
|
67
79
|
assert !success
|
68
80
|
|
69
|
-
assert_equal("#{file}: 1:1 [Error]
|
70
|
-
assert_equal("#{file}: 2:1 [Error]
|
71
|
-
assert_equal("#{file}: 2:7 [Error]
|
81
|
+
assert_equal("#{file}: 1:1 [Error] 'x' is not defined.", messages[0])
|
82
|
+
assert_equal("#{file}: 2:1 [Error] 'alert' is not defined.", messages[2])
|
83
|
+
assert_equal("#{file}: 2:7 [Error] 'x' is not defined.", messages[4])
|
72
84
|
ensure
|
73
85
|
File.unlink eslintrc_file
|
74
86
|
end
|
75
87
|
|
76
88
|
def test_lint_pass_eslint_options
|
77
89
|
file = "test/data/globals.js"
|
78
|
-
success, messages =
|
90
|
+
success, messages = lint_files(file, eslint_options: ["--no-eslintrc", "--global", "my_global"])
|
79
91
|
assert success
|
80
92
|
assert_equal "#{file}: OK", messages[0]
|
81
93
|
end
|
82
94
|
|
83
95
|
def test_lint_fixable_errors
|
84
96
|
file = "test/data/fixable.js"
|
85
|
-
success, messages =
|
97
|
+
success, messages = lint_files(file, eslint_options: ["--no-eslintrc", "--rule", "semi: 2"])
|
86
98
|
assert !success
|
87
99
|
assert_equal "#{file}: 1:15 [Error (Fixable)] Missing semicolon.", messages[0]
|
88
100
|
assert_equal "1 problems can be fixed automatically. Run:", messages[2]
|
@@ -90,9 +102,9 @@ class LintTest < Test::Unit::TestCase
|
|
90
102
|
|
91
103
|
protected
|
92
104
|
|
93
|
-
def
|
105
|
+
def lint_files(files, options = {})
|
94
106
|
faketester = TesterStub.new
|
95
|
-
faketester.files = [
|
107
|
+
faketester.files = files.is_a?(Array) ? files : [files]
|
96
108
|
|
97
109
|
linter = RogerEslint::Lint.new options
|
98
110
|
success = linter.call(faketester, {})
|
metadata
CHANGED
@@ -1,103 +1,103 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roger_eslint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flurin Egger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roger
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
|
-
- -
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '1.5'
|
30
|
-
- -
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rubocop
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: test-unit
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- -
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: thor
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - ~>
|
79
|
+
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - ~>
|
86
|
+
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: mocha
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - ~>
|
93
|
+
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: 1.1.0
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- - ~>
|
100
|
+
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 1.1.0
|
103
103
|
description: |2
|
@@ -110,7 +110,7 @@ executables: []
|
|
110
110
|
extensions: []
|
111
111
|
extra_rdoc_files: []
|
112
112
|
files:
|
113
|
-
- .rubocop.yml
|
113
|
+
- ".rubocop.yml"
|
114
114
|
- CHANGELOG.md
|
115
115
|
- Gemfile
|
116
116
|
- Gemfile.lock
|
@@ -136,17 +136,17 @@ require_paths:
|
|
136
136
|
- lib
|
137
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
138
138
|
requirements:
|
139
|
-
- -
|
139
|
+
- - ">="
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
|
-
- -
|
144
|
+
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.5.1
|
150
150
|
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: Lint JavaScript files with ESLint within Roger
|