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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 522127e2bb834cbd61737940076956bae357a2f5
4
- data.tar.gz: 11dfe715b25b8ce80305534ac3d55aabc0d9aa88
3
+ metadata.gz: a6072d625ed03699ed2dd021a321c9c275de1dc8
4
+ data.tar.gz: 21ecfadcbeab3db2bd345651eb9ce60bbf566b24
5
5
  SHA512:
6
- metadata.gz: 46f1202a57e3662a5c80245a5c6d8d511a0fd2959c17a822f1a96ae0c53c8f349fc1f10e6706c54624de08dd6292087a643be4e40568a48369b142812ea04f16
7
- data.tar.gz: 1f29e688832ba7a5734ad0c03310c50469b709533dbec75f5c41fe54134f80d403e01a361efc523cac692ec99b91bf2bdcafb922266cd756fc7ebfc04a16cfcb
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`, you would run
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 | Description
35
- ---------------------------- | -------------------------------------------------
36
- `/eslint` | Optionally supply a filename parameter to analyze a file other than `application.js`, e.g. `/eslint?filename=foo` to analyze foo.js.
37
- `/eslint/source/application` | Optionally replace `application` with the name of another JavaScript file, e.g. `eslint/source/button_stuff` will show you `button_source.js`.
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/6671891/b5b92760-cbc5-11e4-8a3c-12c19ccfbb4d.png
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
@@ -10,6 +10,10 @@ class EslintController < ActionController::Base
10
10
  @source = Rails.application.assets[@filename].to_s
11
11
  end
12
12
 
13
+ def config_file
14
+ render json: ESLintRails::Config.read(force_default: params[:force_default])
15
+ end
16
+
13
17
  private
14
18
 
15
19
  def set_filename
@@ -11,7 +11,12 @@
11
11
  </head>
12
12
  <body>
13
13
  <div class="container">
14
- <h1>ESLint Report</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>
@@ -1,6 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
  unless Rails.env.production?
3
- match '/eslint' => 'eslint#show', via: :get
4
- match '/eslint/source/:filename' => 'eslint#source', via: :get, as: :eslint_source
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
@@ -1,5 +1,6 @@
1
1
  require 'execjs'
2
2
 
3
+ require 'eslint-rails/config'
3
4
  require 'eslint-rails/engine'
4
5
  require 'eslint-rails/runner'
5
6
  require 'eslint-rails/text_formatter'
@@ -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
@@ -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}', #{config});
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)}
@@ -1,3 +1,3 @@
1
1
  module ESLintRails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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 |task, args|
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.1
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-03-16 00:00:00.000000000 Z
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.3
146
+ rubygems_version: 2.4.6
146
147
  signing_key:
147
148
  specification_version: 4
148
149
  summary: A Rails wrapper for ESLint.