roger_eslint 1.0.0

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: a3ed5a00c847aa7df8754176d1dbeef857ff1969
4
+ data.tar.gz: 20509207b4e93285315bfdd7a4064f866b7226a6
5
+ SHA512:
6
+ metadata.gz: b5c82390bd2e59841405044d4435cbbf160c3125d45e229424697981b550e990508a5317cdc62fb7477dac78ee885a64fd281565e5bbc22794ed62de0d8c40ca
7
+ data.tar.gz: 4d542778c45ca52cdfa929e1f250d982cf1c767d3d8281ec7fec22d12548a366aaacfe857190fbcf3a9adb22ba231668dcb8587d9e1bdedee77cc6c362e521f2
data/.rubocop.yml ADDED
@@ -0,0 +1,47 @@
1
+ LineLength:
2
+ Description: 'Limit lines to 100 characters.'
3
+ Max: 100
4
+ Enabled: true
5
+
6
+ StringLiterals:
7
+ EnforcedStyle: double_quotes
8
+ Enabled: true
9
+
10
+ Style/DotPosition:
11
+ EnforcedStyle: trailing
12
+ Enabled: true
13
+
14
+ Metrics/MethodLength:
15
+ CountComments: false # count full line comments?
16
+ Max: 20
17
+
18
+ Metrics/AbcSize:
19
+ Max: 20
20
+
21
+ Style/ClassAndModuleChildren:
22
+ EnforcedStyle: compact
23
+ Enabled: false
24
+
25
+ # By default, the rails cops are not run. Override in project or home
26
+ # directory .rubocop.yml files, or by giving the -R/--rails option.
27
+ Rails:
28
+ Enabled: false
29
+
30
+ # Disabled cops
31
+ Metrics/ClassLength:
32
+ Enabled: false
33
+
34
+ Metrics/ModuleLength:
35
+ Enabled: false
36
+
37
+ Style/EachWithObject:
38
+ Enabled: false
39
+
40
+ Style/AccessorMethodName:
41
+ Enabled: false
42
+
43
+ Lint/AssignmentInCondition:
44
+ Enabled: false
45
+
46
+ Style/SingleLineBlockParams:
47
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+
3
+ ## Version 1.0.0
4
+ * First workable version
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ roger_eslint (1.0.0)
5
+ roger (~> 1.5, >= 1.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.2.0)
11
+ hpricot (0.8.4)
12
+ metaclass (0.0.4)
13
+ mime-types (2.99)
14
+ mocha (1.1.0)
15
+ metaclass (~> 0.0.1)
16
+ parser (2.3.0.1)
17
+ ast (~> 2.2)
18
+ power_assert (0.2.7)
19
+ powerpack (0.1.1)
20
+ rack (1.6.4)
21
+ rainbow (2.0.0)
22
+ rake (10.5.0)
23
+ redcarpet (3.3.4)
24
+ roger (1.5.0)
25
+ hpricot (= 0.8.4)
26
+ mime-types (~> 2.2)
27
+ rack (>= 1.0.0)
28
+ redcarpet (>= 3.1.1)
29
+ test_construct (~> 2.0)
30
+ thor (~> 0.19.0)
31
+ tilt (~> 2.0.1)
32
+ rubocop (0.36.0)
33
+ parser (>= 2.3.0.0, < 3.0)
34
+ powerpack (~> 0.1)
35
+ rainbow (>= 1.99.1, < 3.0)
36
+ ruby-progressbar (~> 1.7)
37
+ ruby-progressbar (1.7.5)
38
+ test-unit (3.1.5)
39
+ power_assert
40
+ test_construct (2.0.1)
41
+ thor (0.19.1)
42
+ tilt (2.0.2)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ mocha (~> 1.1.0)
49
+ rake
50
+ roger_eslint!
51
+ rubocop
52
+ test-unit
53
+ thor (~> 0)
54
+
55
+ BUNDLED WITH
56
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Digitpant, Flurin Egger
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ Roger ESLint
2
+ ============
3
+
4
+ [![Build Status](https://travis-ci.org/DigitPaint/roger_eslint.svg)](https://travis-ci.org/DigitPaint/roger_eslint)
5
+
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, jshint will walk the directory tree upwards until a .eslintrc file is found.
8
+
9
+ ## Installation
10
+ * Install jshint using npm: ```npm install eslint -g```
11
+
12
+ * Add ```gem 'roger_esliint'``` to your Gemfile
13
+
14
+ * Add this to your Mockupfile:
15
+ ```
16
+ mockup.test do |t|
17
+ t.use :eslint
18
+ end
19
+ ```
20
+
21
+ * (Optional) put a .eslintrc in your project's root directory.
22
+
23
+ ## Running
24
+ Execute ```roger test eslint```.
25
+
26
+ ## License
27
+
28
+ This project is released under the [MIT license](LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "rake/testtask"
2
+ require "rubocop/rake_task"
3
+
4
+ task default: [:test, :rubocop]
5
+
6
+ desc "Run rubocop"
7
+ task :rubocop do
8
+ RuboCop::RakeTask.new
9
+ end
10
+
11
+ Rake::TestTask.new do |t|
12
+ t.libs << "test"
13
+ t.test_files = FileList["test/**/*_test.rb"]
14
+ t.verbose = true
15
+ end
@@ -0,0 +1,126 @@
1
+ require "shellwords"
2
+ require "json"
3
+ require "roger/test"
4
+
5
+ module RogerEslint
6
+ # JS linter plugin for Roger
7
+ class Lint
8
+ # ESLint severities translated into a human readable format
9
+ ESLINT_SEVERITIES = {
10
+ 1 => "Warning",
11
+ 2 => "Error"
12
+ }.freeze
13
+
14
+ # @param [Hash] options The options
15
+ # @option options [Array] :match Files to match
16
+ # @option options [Array[Regexp]] :skip Array of regular expressions to skip files
17
+ # @option options [Boolean] (false) :fail_on_warning Wether or not to fail test on warnings
18
+ # @option options [String] :eslint eslint command
19
+ # @option options [Array] :eslint_options An array of eslint options; make sure
20
+ # you have the commandline flag and the value in separate elments, so: `["--global", "$"]`
21
+ def initialize(options = {})
22
+ @options = {
23
+ match: ["html/**/*.js"],
24
+ skip: [],
25
+ fail_on_warning: false,
26
+ eslint: "eslint",
27
+ eslint_options: []
28
+ }
29
+
30
+ @options.update(options) if options
31
+
32
+ detect_eslint
33
+ end
34
+
35
+ def lint(test, file_path)
36
+ output = `#{eslint_command(file_path)}`
37
+ file_lints = JSON.parse(output).first
38
+
39
+ unless file_lints
40
+ test.warn(self, "No files linted")
41
+ return true
42
+ end
43
+
44
+ success = file_lints["errorCount"] <= 0
45
+ success &&= file_lints["warningCount"] <= 0 if @options[:fail_on_warning]
46
+
47
+ fixables = []
48
+
49
+ if success
50
+ test.log(self, "#{file_path}: OK")
51
+ else
52
+ file_lints["messages"].each do |message|
53
+ fixables << message if message["fix"]
54
+ report_message(test, file_path, message)
55
+ end
56
+ end
57
+
58
+ report_fixables(test, file_path, fixables)
59
+
60
+ success
61
+ end
62
+
63
+ # @param [Hash] options The options
64
+ # @option options [Array] :match Files to match
65
+ # @option options [Array[Regexp]] :skip Array of regular expressions to skip files
66
+ def call(test, options)
67
+ options = {}.update(@options).update(options)
68
+
69
+ test.log(self, "ESLinting files")
70
+
71
+ failures = test.get_files(options[:match], options[:skip]).select do |file_path|
72
+ !lint(test, file_path)
73
+ end
74
+ failures.empty?
75
+ end
76
+
77
+ private
78
+
79
+ def eslint_command(file_path, extras = [])
80
+ command = [
81
+ @options[:eslint],
82
+ "-f", "json"
83
+ ]
84
+
85
+ command += @options[:eslint_options] if @options[:eslint_options]
86
+
87
+ command += extras
88
+ command << file_path
89
+
90
+ Shellwords.join(command)
91
+ end
92
+
93
+ def report_message(test, file_path, message)
94
+ output = "#{file_path}: "
95
+ output << message["line"].to_s
96
+ output << ":"
97
+ output << message["column"].to_s
98
+ output << " ["
99
+ output << ESLINT_SEVERITIES[message["severity"]]
100
+ output << " (Fixable)" if message["fix"]
101
+ output << "] "
102
+ output << message["message"]
103
+
104
+ test.log(self, output)
105
+ test.log(self, " #{message['source']}")
106
+ end
107
+
108
+ def report_fixables(test, file_path, fixables)
109
+ if fixables.any?
110
+ test.log(self, "#{fixables.size} problems can be fixed automatically. Run:")
111
+ test.log(self, " #{eslint_command(file_path, ['--fix'])}")
112
+ end
113
+ end
114
+
115
+ def detect_eslint
116
+ command = [@options[:eslint], "-v", "2>/dev/null"]
117
+ detect = system(Shellwords.join(command))
118
+ unless detect
119
+ err = "Could not find eslint. Install eslint using: 'npm install -g eslint'."
120
+ fail ArgumentError, err
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ Roger::Test.register :eslint, RogerEslint::Lint
@@ -0,0 +1,4 @@
1
+ # Roger main namespace
2
+ module RogerEslint
3
+ VERSION = "1.0.0"
4
+ end
@@ -0,0 +1,6 @@
1
+ # Eslint plugin
2
+ module RogerEslint
3
+ end
4
+
5
+ require File.dirname(__FILE__) + "/roger_eslint/lint"
6
+ require File.dirname(__FILE__) + "/roger_eslint/version"
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + "/lib/roger_eslint/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.authors = ["Flurin Egger"]
7
+ s.email = ["info@digitpaint.nl", "flurin@digitpaint.nl"]
8
+ s.name = "roger_eslint"
9
+ s.version = RogerEslint::VERSION
10
+ s.homepage = "https://github.com/digitpaint/roger_eslint"
11
+
12
+ s.summary = "Lint JavaScript files with ESLint within Roger"
13
+ s.description = <<-EOF
14
+ Lint JavaScript files from within Roger, using eslint.
15
+ Will use .eslintrc.
16
+ EOF
17
+ s.licenses = ["MIT"]
18
+
19
+ s.date = Time.now.strftime("%Y-%m-%d")
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_dependency "roger", "~> 1.5", ">= 1.0.0"
25
+
26
+ s.add_development_dependency "rubocop", [">= 0"]
27
+ s.add_development_dependency "rake", [">= 0"]
28
+ s.add_development_dependency "test-unit", [">= 0"]
29
+ s.add_development_dependency "thor", ["~> 0"]
30
+ s.add_development_dependency "mocha", ["~> 1.1.0"]
31
+ end
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ "root" : true,
3
+ "rules" : {
4
+ "no-undef" : 2
5
+ }
6
+ }
@@ -0,0 +1,2 @@
1
+ x = 5;
2
+ alert(x);
@@ -0,0 +1 @@
1
+ var a = "henk"
@@ -0,0 +1 @@
1
+ var a = my_global;
data/test/lint_test.rb ADDED
@@ -0,0 +1,97 @@
1
+ require File.dirname(__FILE__) + "/../lib/roger_eslint/lint.rb"
2
+ require "test/unit"
3
+
4
+ # Fake tester to pass into the linter plugin
5
+ class TesterStub
6
+ attr_reader :messages
7
+ attr_writer :files
8
+
9
+ def initialize
10
+ @messages = []
11
+ @files = []
12
+ end
13
+
14
+ def log(_, message)
15
+ @messages.push(message)
16
+ end
17
+
18
+ def warn(_, message)
19
+ @messages.push(message)
20
+ end
21
+
22
+ def get_files(_, _)
23
+ @files
24
+ end
25
+ end
26
+
27
+ # Linting plugin unit test
28
+ class LintTest < Test::Unit::TestCase
29
+ def setup
30
+ end
31
+
32
+ def test_detect_eslint
33
+ assert_nothing_raised do
34
+ RogerEslint::Lint.new
35
+ end
36
+
37
+ assert_raise(ArgumentError) do
38
+ RogerEslint::Lint.new eslint: "eslint-blabla"
39
+ end
40
+ end
41
+
42
+ def test_lint_nonexisting_file
43
+ success, messages = lint_file("test/data/does_not_exist.js")
44
+
45
+ assert success
46
+ assert_equal "No files linted", messages[0]
47
+ end
48
+
49
+ def test_lint_with_default_eslintrc
50
+ eslintrc_file = ".eslintrc.js"
51
+ assert !File.exist?(eslintrc_file), ".eslintrc.js file already exists."
52
+ FileUtils.cp("./test/data/.eslintrc-no-undef.js", eslintrc_file)
53
+
54
+ file = "test/data/error.js"
55
+ success, messages = lint_file(file)
56
+
57
+ assert !success
58
+
59
+ assert_equal("#{file}: 1:1 [Error] \"x\" is not defined.", messages[0])
60
+ assert_equal("#{file}: 2:1 [Error] \"alert\" is not defined.", messages[2])
61
+ assert_equal("#{file}: 2:7 [Error] \"x\" is not defined.", messages[4])
62
+ ensure
63
+ File.unlink eslintrc_file
64
+ end
65
+
66
+ def test_lint_pass_eslint_options
67
+ file = "test/data/globals.js"
68
+ success, messages = lint_file(file, eslint_options: ["--no-eslintrc", "--global", "my_global"])
69
+ assert success
70
+ assert_equal "#{file}: OK", messages[0]
71
+ end
72
+
73
+ def test_lint_fixable_errors
74
+ file = "test/data/fixable.js"
75
+ success, messages = lint_file(file, eslint_options: ["--no-eslintrc", "--rule", "semi: 2"])
76
+ assert !success
77
+ assert_equal "#{file}: 1:15 [Error (Fixable)] Missing semicolon.", messages[0]
78
+ assert_equal "1 problems can be fixed automatically. Run:", messages[2]
79
+ end
80
+
81
+ protected
82
+
83
+ def lint_file(file, options = {})
84
+ faketester = TesterStub.new
85
+ faketester.files = [file]
86
+
87
+ linter = RogerEslint::Lint.new options
88
+ success = linter.call(faketester, {})
89
+
90
+ messages = faketester.messages
91
+
92
+ # Chop off the first message is it just says "ESLinting files"
93
+ messages.shift
94
+
95
+ [success, messages]
96
+ end
97
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roger_eslint
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Flurin Egger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rubocop
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: test-unit
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: thor
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: mocha
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: 1.1.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 1.1.0
103
+ description: |2
104
+ Lint JavaScript files from within Roger, using eslint.
105
+ Will use .eslintrc.
106
+ email:
107
+ - info@digitpaint.nl
108
+ - flurin@digitpaint.nl
109
+ executables: []
110
+ extensions: []
111
+ extra_rdoc_files: []
112
+ files:
113
+ - .rubocop.yml
114
+ - CHANGELOG.md
115
+ - Gemfile
116
+ - Gemfile.lock
117
+ - LICENSE
118
+ - README.md
119
+ - Rakefile
120
+ - lib/roger_eslint.rb
121
+ - lib/roger_eslint/lint.rb
122
+ - lib/roger_eslint/version.rb
123
+ - roger_eslint.gemspec
124
+ - test/data/.eslintrc-no-undef.js
125
+ - test/data/error.js
126
+ - test/data/fixable.js
127
+ - test/data/globals.js
128
+ - test/lint_test.rb
129
+ homepage: https://github.com/digitpaint/roger_eslint
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Lint JavaScript files with ESLint within Roger
153
+ test_files: []