eslint-rails 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -9
- data/app/controllers/eslint_controller.rb +4 -0
- data/app/views/eslint/show.html.erb +7 -2
- data/config/routes.rb +3 -2
- data/lib/eslint-rails.rb +1 -0
- data/lib/eslint-rails/config.rb +27 -0
- data/lib/eslint-rails/runner.rb +1 -2
- data/lib/eslint-rails/version.rb +1 -1
- data/lib/tasks/eslint.rake +6 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6072d625ed03699ed2dd021a321c9c275de1dc8
|
4
|
+
data.tar.gz: 21ecfadcbeab3db2bd345651eb9ce60bbf566b24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44cd898801950e5a480a461bd4766fa11338f2d6c0099dd13d2c56cb51faa0d655f777179575aae6b12d18d673c5875af809f881f845ce8f00198eac1bdd209b
|
7
|
+
data.tar.gz: b2313f4b9173ec07cfc17411695f0d60e9c5a78d81d7e4acfe964726dabacde8ad8839f19a3b6e3b3c9f4942596586a348267b0f9c2b69c816327247924e4809
|
data/README.md
CHANGED
@@ -10,6 +10,26 @@ Add this line to your application's Gemfile:
|
|
10
10
|
gem 'eslint-rails'
|
11
11
|
```
|
12
12
|
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
To customize configuration, place an eslint config file in your app's
|
16
|
+
`config/eslint.json`.
|
17
|
+
|
18
|
+
You can print the configuration thusly:
|
19
|
+
|
20
|
+
```sh
|
21
|
+
# Print the configuration that we're using. If there's a custom configuration
|
22
|
+
# present, print that; if not, print the default configuration.
|
23
|
+
rake eslint:print_config
|
24
|
+
|
25
|
+
# Or print the default configuration even if a custom one exists.
|
26
|
+
rake eslint:print_config[true]
|
27
|
+
```
|
28
|
+
|
29
|
+
You can also retrieve the current eslint.json by visiting `/eslint/eslint.json`
|
30
|
+
in your browser. To force retrieval of the default conguration, use
|
31
|
+
`/eslint/eslint.json?force_default=true`.
|
32
|
+
|
13
33
|
## Usage
|
14
34
|
|
15
35
|
### CLI
|
@@ -21,25 +41,27 @@ rake eslint:run
|
|
21
41
|
```
|
22
42
|
|
23
43
|
This will analyze `application.js`. Optionally, you can supply a filename to the
|
24
|
-
task. To analyze `woop.js
|
44
|
+
task. To analyze `components/woop.js` and `utilities.js.coffee.erb` you would
|
45
|
+
run (respectively):
|
25
46
|
|
26
47
|
```sh
|
27
|
-
rake eslint:run[woop]
|
48
|
+
rake eslint:run[components/woop]
|
49
|
+
rake eslint:run[utilities]
|
28
50
|
```
|
29
51
|
|
30
52
|
### Web interface
|
31
53
|
|
32
54
|
On non-production environments, visit these URLs on your application:
|
33
55
|
|
34
|
-
Path
|
35
|
-
|
36
|
-
`/eslint`
|
37
|
-
`/eslint/source
|
38
|
-
|
39
|
-
![eslint-rails-web-source](https://cloud.githubusercontent.com/assets/324632/6671965/33d6819c-cbc6-11e4-9a64-30be84f20b96.png)
|
56
|
+
Path | Description
|
57
|
+
------------------------------------- | -------------------------------------------------
|
58
|
+
`/eslint` | Optionally supply a filename parameter to analyze a file other than `application.js`, e.g. `/eslint?filename=foo` to analyze foo.js.
|
59
|
+
`/eslint/source?filename=application` | Optionally replace `application` with the name of another JavaScript file, e.g. `eslint/source?filename=button_stuff` can show you `button_stuff.js`, and `eslint/source?filename=components/buttons/icon_button` can show you `components/buttons/icon_button.js.coffee.erb`.
|
40
60
|
|
41
61
|
![eslint-rails-web](https://cloud.githubusercontent.com/assets/324632/6671966/33d8cc86-cbc6-11e4-904d-3379907c429d.png)
|
42
62
|
|
63
|
+
![eslint-rails-web-source](https://cloud.githubusercontent.com/assets/324632/6671965/33d6819c-cbc6-11e4-9a64-30be84f20b96.png)
|
64
|
+
|
43
65
|
# Authors
|
44
66
|
|
45
67
|
- Jon Kessler <[jon.kessler@appfolio.com][]>
|
@@ -54,6 +76,6 @@ Path | Description
|
|
54
76
|
[jon.kessler@appfolio.com]: mailto:jon.kessler@appfolio.com
|
55
77
|
[MIT License]: http://www.opensource.org/licenses/MIT)
|
56
78
|
|
57
|
-
[rake-eslint-rails-run]: https://cloud.githubusercontent.com/assets/324632/
|
79
|
+
[rake-eslint-rails-run]: https://cloud.githubusercontent.com/assets/324632/6672146/9d1f278e-cbc7-11e4-9f56-5a4511d35921.png
|
58
80
|
[eslint-rails-web-source]: https://cloud.githubusercontent.com/assets/324632/6671965/33d6819c-cbc6-11e4-9a64-30be84f20b96.png
|
59
81
|
[eslint-rails-web]: https://cloud.githubusercontent.com/assets/324632/6671966/33d8cc86-cbc6-11e4-904d-3379907c429d.png
|
@@ -11,7 +11,12 @@
|
|
11
11
|
</head>
|
12
12
|
<body>
|
13
13
|
<div class="container">
|
14
|
-
<h1>
|
14
|
+
<h1>
|
15
|
+
ESLint Report
|
16
|
+
<small>
|
17
|
+
<%= link_to 'eslint.json', config_file_path %>
|
18
|
+
</small>
|
19
|
+
</h1>
|
15
20
|
<table class="table">
|
16
21
|
<thead>
|
17
22
|
<tr>
|
@@ -36,7 +41,7 @@
|
|
36
41
|
<tr class="<%= row_class %>">
|
37
42
|
<td><%= link_to(
|
38
43
|
"#{warning.line}:#{warning.column}",
|
39
|
-
eslint_source_path(@filename, anchor: warning.line)
|
44
|
+
eslint_source_path(filename: @filename, anchor: warning.line)
|
40
45
|
) %></td>
|
41
46
|
<td><%= warning.severity.to_s.capitalize %></td>
|
42
47
|
<td><%= link_to warning.rule_id, "http://eslint.org/docs/rules/#{warning.rule_id}.html" %></td>
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
unless Rails.env.production?
|
3
|
-
|
4
|
-
|
3
|
+
get '/eslint' => 'eslint#show'
|
4
|
+
get '/eslint/source' => 'eslint#source', as: :eslint_source
|
5
|
+
get '/eslint/eslint.json' => 'eslint#config_file', as: :config_file
|
5
6
|
end
|
6
7
|
end
|
data/lib/eslint-rails.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module ESLintRails
|
2
|
+
class Config
|
3
|
+
|
4
|
+
def self.read(force_default: false)
|
5
|
+
self.new(force_default: force_default).send(:read)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
CONFIG_PATH = 'config/eslint.json'
|
11
|
+
private_constant :CONFIG_PATH
|
12
|
+
|
13
|
+
def initialize(force_default:)
|
14
|
+
@force_default = force_default
|
15
|
+
@custom_file = Rails.root.join(CONFIG_PATH)
|
16
|
+
@default_file = ESLintRails::Engine.root.join(CONFIG_PATH)
|
17
|
+
end
|
18
|
+
|
19
|
+
def read
|
20
|
+
config_file.read
|
21
|
+
end
|
22
|
+
|
23
|
+
def config_file
|
24
|
+
(@custom_file.exist? && !@force_default) ? @custom_file : @default_file
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/eslint-rails/runner.rb
CHANGED
@@ -10,13 +10,12 @@ module ESLintRails
|
|
10
10
|
file_content = Rails.application.assets[@filename].to_s
|
11
11
|
|
12
12
|
eslint_js = Rails.application.assets['eslint'].to_s
|
13
|
-
config = ESLintRails::Engine.root.join('config/eslint.json').read
|
14
13
|
|
15
14
|
warning_hashes = ExecJS.eval <<-JS
|
16
15
|
function () {
|
17
16
|
window = this;
|
18
17
|
#{eslint_js};
|
19
|
-
return eslint.verify('#{escape_javascript file_content}', #{
|
18
|
+
return eslint.verify('#{escape_javascript file_content}', #{Config.read});
|
20
19
|
}()
|
21
20
|
JS
|
22
21
|
warning_hashes.map{|hash| ESLintRails::Warning.new(hash)}
|
data/lib/eslint-rails/version.rb
CHANGED
data/lib/tasks/eslint.rake
CHANGED
@@ -5,7 +5,7 @@ require 'eslint-rails'
|
|
5
5
|
namespace :eslint do
|
6
6
|
|
7
7
|
desc %{Run ESLint against the specified JavaScript file and report warnings (default is 'application')}
|
8
|
-
task :run, [:filename] => :environment do |
|
8
|
+
task :run, [:filename] => :environment do |_, args|
|
9
9
|
warnings = ESLintRails::Runner.new(args[:filename]).run
|
10
10
|
|
11
11
|
if warnings.empty?
|
@@ -17,4 +17,9 @@ namespace :eslint do
|
|
17
17
|
exit 1
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
desc 'Print the current configuration file (Uses local config/eslint.json if it exists; uses default config/eslint.json if it does not; optionally force default by passing a parameter)'
|
22
|
+
task :print_config, [:force_default] => :environment do |_, args|
|
23
|
+
puts ESLintRails::Config.read(force_default: args[:force_default])
|
24
|
+
end
|
20
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eslint-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Force
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- config/routes.rb
|
116
116
|
- eslint-rails.gemspec
|
117
117
|
- lib/eslint-rails.rb
|
118
|
+
- lib/eslint-rails/config.rb
|
118
119
|
- lib/eslint-rails/engine.rb
|
119
120
|
- lib/eslint-rails/runner.rb
|
120
121
|
- lib/eslint-rails/text_formatter.rb
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
145
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.4.
|
146
|
+
rubygems_version: 2.4.6
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: A Rails wrapper for ESLint.
|