roger_eslint 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/roger_eslint/lint.rb +33 -14
- data/lib/roger_eslint/version.rb +1 -1
- data/test/lint_test.rb +14 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 147aa12ad5cdcde7af013082566d33aa3e497597
|
4
|
+
data.tar.gz: dc97130bb05546b487d4bedd3459703cb27eff37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dce1b94ecbfed10fedccf4c96b0fb7bcb70837e03dae9dd9a4bfa11d4a736eda58b8ce37cc62c2d5ee3253feb5a2d8f5964a5744fd1b7ee578e87c2e5184d08
|
7
|
+
data.tar.gz: 74970d9a1f0fb43916e8eba4d06ec9ec6764d46598c137c047c3c37e36854fd7315f9eabadd210a21216010c2d6ad9a96f7eb5983f5167ec0552cb2da6eca04b
|
data/CHANGELOG.md
CHANGED
data/lib/roger_eslint/lint.rb
CHANGED
@@ -15,21 +15,20 @@ module RogerEslint
|
|
15
15
|
# @option options [Array] :match Files to match
|
16
16
|
# @option options [Array[Regexp]] :skip Array of regular expressions to skip files
|
17
17
|
# @option options [Boolean] (false) :fail_on_warning Wether or not to fail test on warnings
|
18
|
-
# @option options [String] :eslint eslint command
|
18
|
+
# @option options [String, nil] :eslint eslint command, if nil will search for the command
|
19
|
+
# Preferring the local node_modules path.
|
19
20
|
# @option options [Array] :eslint_options An array of eslint options; make sure
|
20
21
|
# you have the commandline flag and the value in separate elments, so: `["--global", "$"]`
|
21
22
|
def initialize(options = {})
|
22
23
|
@options = {
|
23
24
|
match: ["html/**/*.js"],
|
24
|
-
skip: [],
|
25
|
+
skip: [%r{vendor\/.*\.js\Z}],
|
25
26
|
fail_on_warning: false,
|
26
|
-
eslint:
|
27
|
+
eslint: nil,
|
27
28
|
eslint_options: []
|
28
29
|
}
|
29
30
|
|
30
31
|
@options.update(options) if options
|
31
|
-
|
32
|
-
detect_eslint
|
33
32
|
end
|
34
33
|
|
35
34
|
def lint(test, file_path)
|
@@ -42,7 +41,7 @@ module RogerEslint
|
|
42
41
|
end
|
43
42
|
|
44
43
|
success = file_lints["errorCount"] <= 0
|
45
|
-
success &&= file_lints["warningCount"] <= 0 if @
|
44
|
+
success &&= file_lints["warningCount"] <= 0 if @_call_options[:fail_on_warning]
|
46
45
|
|
47
46
|
fixables = []
|
48
47
|
|
@@ -64,25 +63,29 @@ module RogerEslint
|
|
64
63
|
# @option options [Array] :match Files to match
|
65
64
|
# @option options [Array[Regexp]] :skip Array of regular expressions to skip files
|
66
65
|
def call(test, options)
|
67
|
-
|
66
|
+
@_call_options = {}.update(@options).update(options)
|
67
|
+
|
68
|
+
detect_eslint(test)
|
68
69
|
|
69
70
|
test.log(self, "ESLinting files")
|
70
71
|
|
71
|
-
failures = test.get_files(
|
72
|
+
failures = test.get_files(@_call_options[:match], @_call_options[:skip]).select do |file_path|
|
72
73
|
!lint(test, file_path)
|
73
74
|
end
|
74
75
|
failures.empty?
|
76
|
+
ensure
|
77
|
+
@_call_options = {}
|
75
78
|
end
|
76
79
|
|
77
80
|
private
|
78
81
|
|
79
82
|
def eslint_command(file_path, extras = [])
|
80
83
|
command = [
|
81
|
-
@
|
84
|
+
@_call_options[:eslint],
|
82
85
|
"-f", "json"
|
83
86
|
]
|
84
87
|
|
85
|
-
command += @
|
88
|
+
command += @_call_options[:eslint_options] if @_call_options[:eslint_options]
|
86
89
|
|
87
90
|
command += extras
|
88
91
|
command << file_path
|
@@ -112,11 +115,27 @@ module RogerEslint
|
|
112
115
|
end
|
113
116
|
end
|
114
117
|
|
115
|
-
def detect_eslint
|
116
|
-
|
117
|
-
|
118
|
-
|
118
|
+
def detect_eslint(test)
|
119
|
+
if @_call_options[:eslint]
|
120
|
+
commands_to_test = [@_call_options[:eslint]]
|
121
|
+
else
|
122
|
+
commands_to_test = [
|
123
|
+
test.project.path + "node_modules/eslint/bin/eslint.js",
|
124
|
+
"eslint.js",
|
125
|
+
"eslint"
|
126
|
+
]
|
127
|
+
end
|
128
|
+
|
129
|
+
detect = commands_to_test.detect do |command|
|
130
|
+
system(Shellwords.join([command, "-v"]) + "> /dev/null 2>&1")
|
131
|
+
end
|
132
|
+
|
133
|
+
if detect
|
134
|
+
# Bit of a hack to set the value like this
|
135
|
+
@_call_options[:eslint] = detect
|
136
|
+
else
|
119
137
|
err = "Could not find eslint. Install eslint using: 'npm install -g eslint'."
|
138
|
+
err += " Or install eslint locally."
|
120
139
|
fail ArgumentError, err
|
121
140
|
end
|
122
141
|
end
|
data/lib/roger_eslint/version.rb
CHANGED
data/test/lint_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../lib/roger_eslint/lint.rb"
|
2
2
|
require "test/unit"
|
3
|
+
require "roger/testing/mock_project"
|
3
4
|
|
4
5
|
# Fake tester to pass into the linter plugin
|
5
6
|
class TesterStub
|
@@ -11,6 +12,15 @@ class TesterStub
|
|
11
12
|
@files = []
|
12
13
|
end
|
13
14
|
|
15
|
+
def project
|
16
|
+
# Creating a mock project with path will forego the construct creation
|
17
|
+
@project ||= Roger::Testing::MockProject.new(".")
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy
|
21
|
+
@project.destroy if @project
|
22
|
+
end
|
23
|
+
|
14
24
|
def log(_, message)
|
15
25
|
@messages.push(message)
|
16
26
|
end
|
@@ -31,11 +41,11 @@ class LintTest < Test::Unit::TestCase
|
|
31
41
|
|
32
42
|
def test_detect_eslint
|
33
43
|
assert_nothing_raised do
|
34
|
-
|
44
|
+
lint_file "test.js"
|
35
45
|
end
|
36
46
|
|
37
47
|
assert_raise(ArgumentError) do
|
38
|
-
|
48
|
+
lint_file "test.js", eslint: "eslint-blabla"
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
@@ -93,5 +103,7 @@ class LintTest < Test::Unit::TestCase
|
|
93
103
|
messages.shift
|
94
104
|
|
95
105
|
[success, messages]
|
106
|
+
ensure
|
107
|
+
faketester.destroy
|
96
108
|
end
|
97
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.0.1
|
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-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roger
|