eslint-rails-ee 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f8dda485adf47335a2d7ee6ea66b17fd5b0ee2b
4
+ data.tar.gz: 35e48b79e17394be368e491dfb630d63bd2912cd
5
+ SHA512:
6
+ metadata.gz: f9c66719fc1886b05d35c0730f46fbd00217bbae09889a1decdb19dc352d22795fd04af935aaaf045f43e9b15897be4f674fa3f85b6d4cc1d9ad9804c6be1b20
7
+ data.tar.gz: 5d80f57cb3436a70132dc29aaddc7432707bccaa3dadc138e1f02269e94da44b7a594bbf4714736b7d2a3301fc2f63751763fb726784cadb420c54eb4215aaf6
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eslint-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 AppFolio, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,216 @@
1
+ # eslint-rails-ee: a fork of eslint-rails with enhanced features
2
+
3
+ Run [ESLint][] against your Rails repo, and even auto-correct issues! The supported javascript file extensions are the following:
4
+
5
+ - _.js_
6
+ - _.jsx_
7
+ - _.es6_
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'eslint-rails-ee'
15
+ gem 'therubyracer'
16
+ gem 'execjs'
17
+ ```
18
+
19
+ This uses TheRubyRacer as a runtime. For most environments, this works fine. However if you run windows do this to your gemfile:
20
+
21
+ ```ruby
22
+ gem 'eslint-rails-ee'
23
+ gem 'therubyracer', :platforms => :ruby
24
+ gem 'execjs'
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ To customize configuration, place an eslint config file in your app's
30
+ `config/eslint.json`.
31
+
32
+ You can print the configuration thusly:
33
+
34
+ ```sh
35
+ # Print the configuration that we're using. If there's a custom configuration
36
+ # present, print that; if not, print the default configuration.
37
+ rake eslint:print_config
38
+
39
+ # Or print the default configuration even if a custom one exists.
40
+ rake eslint:print_config[true]
41
+ ```
42
+
43
+ You can also retrieve the current eslint.json by visiting `/eslint/eslint.json`
44
+ in your browser. To force retrieval of the default conguration, use
45
+ `/eslint/eslint.json?force_default=true`.
46
+
47
+ ## Usage
48
+
49
+ ### CLI
50
+
51
+ ![rake-eslint-rails-run][]
52
+
53
+ This will analyze all of the javascript files in the project:
54
+
55
+ ```sh
56
+ rake eslint:run_all
57
+ ```
58
+
59
+ Or you can run it on a single file. This will analyze `application.js`:
60
+
61
+ ```sh
62
+ rake eslint:run
63
+ ```
64
+
65
+ Or, you can supply a filename to the task, using several different formats, and it will lint just that file. For example, to analyze `app/assets/javascripts/components/utilities.js`, you can run any of the following:
66
+
67
+ ```sh
68
+ rake eslint:run[components/utilities]
69
+ rake eslint:run[components/utilities.js]
70
+ rake eslint:run[app/assets/javascripts/components/utilities]
71
+ rake eslint:run[app/assets/javascripts/components/utilities.js]
72
+ ```
73
+
74
+ To auto-correct files in either execution of the above rake tasks just add `true` to the arguments like so:
75
+
76
+ ```sh
77
+ rake eslint:run_all[true]
78
+ ```
79
+ or
80
+
81
+ ```sh
82
+ rake eslint:run[test.js,true]
83
+ ```
84
+
85
+ ### Web interface
86
+
87
+ On non-production environments, visit these URLs on your application:
88
+
89
+ Path | Description
90
+ ------------------------------------- | -------------------------------------------------
91
+ `/eslint` | Optionally supply a filename parameter to analyze a file other than `application.js`, e.g. `/eslint?filename=foo` to analyze foo.js.
92
+ `/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`. This returns the source code with syntax highlighting
93
+ `/eslint?filename=<path+filename>` | Providing you give a correct path/filename, it will run the eslint report and show you the errors
94
+ `/eslint?filename=<path+filename>&should_autocorrect=true` | Same as above, but will report errors AFTER auto-correcting any auto-correct-able issues
95
+
96
+ ![eslint-rails-web][]
97
+
98
+ ![eslint-rails-web-source][]
99
+
100
+ # Contributing
101
+
102
+ It's easiest to contribute by forking the repo and creating a pull request. For
103
+ help with this, see this [helpful article][fork a repo].
104
+
105
+ For all of the example shell commands below, I'm going to assume that you've set
106
+ these two variables, so go ahead and customize these and set them before you
107
+ start.
108
+
109
+ ```sh
110
+ ESLINT=~/src/eslint
111
+ ESLINT_RAILS=~/src/eslint-rails
112
+ ```
113
+
114
+ ## Cloning the repository
115
+
116
+ ```sh
117
+ git clone https://github.com/appfolio/eslint-rails-ee $ESLINT_RAILS
118
+ ```
119
+
120
+ ## Updating ESLint version
121
+
122
+ ### Summary
123
+
124
+ 1. [Clone the ESLint repository](#clone-the-eslint-repository)
125
+ 2. [Install dependencies](#install-dependencies)
126
+ 3. [Render `eslint.js`](#render-eslintjs)
127
+ 4. [Copy `eslint.js` into `eslint-rails`](#copy-eslintjs-into-eslint-rails)
128
+ 5. [Update the file in git](#update-the-file-in-git)
129
+ 6. [Commit, push, and create a pull request](#commit-push-and-create-a-pull-request)
130
+
131
+ ### Step-by-step instructions
132
+
133
+ First, make sure you set the environment variables [as suggested above](#contributing).
134
+
135
+ #### Clone the [ESLint repository][]
136
+
137
+ I would recommend only trying this with a released version unless you have a
138
+ good reason to. In this example, I'm going to check out v1.10.1 and work with
139
+ that.
140
+
141
+ ```sh
142
+ git clone https://github.com/eslint/eslint $ESLINT
143
+ cd $ESLINT
144
+ git checkout v1.10.1
145
+ ```
146
+
147
+ #### Install dependencies
148
+
149
+ ```sh
150
+ cd $ESLINT
151
+ npm install
152
+ ```
153
+
154
+ #### Render `eslint.js`
155
+
156
+ ```sh
157
+ cd $ESLINT
158
+ node Makefile.js browserify
159
+ ```
160
+
161
+ #### Copy `eslint.js` into `eslint-rails`
162
+
163
+ ```sh
164
+ # Assuming you cloned eslint into a repository next to eslint-rails
165
+ cp $ESLINT/build/eslint.js $ESLINT_RAILS/vendor/assets/javascripts/eslint.js
166
+ ```
167
+
168
+ #### Update the file in git
169
+
170
+ ```sh
171
+ cd $ESLINT_RAILS
172
+ git add vendor/assets/javascripts/eslint.js
173
+ ```
174
+
175
+ #### Commit, push, and create a pull request
176
+
177
+ The details of how to create your own branch, commit, push, and create a pull
178
+ request are outside the scope of this README. If you need help with this part,
179
+ here's a [helpful article][fork a repo]. This is the gist.
180
+
181
+ ```sh
182
+ cd $ESLINT_RAILS
183
+ # Make your changes
184
+ git add :/
185
+ git commit
186
+ git push origin master
187
+ # Open a pull request
188
+ ```
189
+ # Fork Authors
190
+
191
+ Since the original repo lacked some features I wanted and hasn't seen support/PRs in over a year, I decided to make this repo. Future maintenance of this gem will exist in
192
+ the new eslint-rails-ee repo:
193
+
194
+ - David Valentine &lt;[davidlewisrogers3@gmail.com][]&gt;
195
+
196
+ # Original Authors
197
+
198
+ This repo was orignially written by the following people:
199
+
200
+ - Jon Kessler &lt;[jon.kessler@appfolio.com][]&gt;
201
+ - Justin Force &lt;[justin.force@appfolio.com][]&gt;
202
+
203
+ # License
204
+
205
+ [MIT License][].
206
+
207
+ [ESLint]: http://eslint.org/
208
+ [fork a repo]: https://help.github.com/articles/fork-a-repo/
209
+ [ESLint repository]: https://github.com/eslint/eslint
210
+ [justin.force@appfolio.com]: mailto:justin.force@appfolio.com
211
+ [jon.kessler@appfolio.com]: mailto:jon.kessler@appfolio.com
212
+ [MIT License]: http://www.opensource.org/licenses/MIT)
213
+
214
+ [rake-eslint-rails-run]: https://cloud.githubusercontent.com/assets/324632/6672146/9d1f278e-cbc7-11e4-9f56-5a4511d35921.png
215
+ [eslint-rails-web-source]: https://cloud.githubusercontent.com/assets/324632/6671965/33d6819c-cbc6-11e4-9a64-30be84f20b96.png
216
+ [eslint-rails-web]: https://cloud.githubusercontent.com/assets/324632/6671966/33d8cc86-cbc6-11e4-904d-3379907c429d.png
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ class EslintController < ActionController::Base
2
+
3
+ before_action :set_options
4
+
5
+ def show
6
+ @warnings = ESLintRails::Runner.new(@filename).run(@should_autocorrect)
7
+ end
8
+
9
+ def source
10
+ @source = Rails.application.assets[@filename].to_s
11
+ end
12
+
13
+ def config_file
14
+ render json: ESLintRails::Config.read(force_default: params[:force_default] || false)
15
+ end
16
+
17
+ private
18
+
19
+ def set_options
20
+ @filename = params[:filename] || 'application'
21
+ @should_autocorrect = ['true'].include?(params[:should_autocorrect]) ? true : false
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
5
+ <style>
6
+ .container {
7
+ margin: 0 auto;
8
+ width: 980px;
9
+ }
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <div class="container">
14
+ <h1>
15
+ ESLint Report <%= "(after auto-corrections)" if params[:should_autocorrect] %>
16
+ <small>
17
+ <%= link_to 'eslint.json', config_file_path %>
18
+ </small>
19
+ </h1>
20
+ <table class="table">
21
+ <thead>
22
+ <tr>
23
+ <th>Location</th>
24
+ <th>Severity</th>
25
+ <th>Rule</th>
26
+ <th>Message</th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+ <% @warnings.each do |warning| %>
31
+ <%
32
+ row_class = case warning.severity
33
+ when :low
34
+ 'warning'
35
+ when :high
36
+ 'danger'
37
+ else
38
+ ''
39
+ end
40
+ %>
41
+ <tr class="<%= row_class %>">
42
+ <td><%= link_to(
43
+ "#{warning.line}:#{warning.column}",
44
+ eslint_source_path(filename: @filename, anchor: warning.line)
45
+ ) %></td>
46
+ <td><%= warning.severity.to_s.capitalize %></td>
47
+ <td><%= link_to warning.rule_id, "http://eslint.org/docs/rules/#{warning.rule_id}.html" %></td>
48
+ <td><%= warning.message %></td>
49
+ </tr>
50
+ <% end %>
51
+ </tbody>
52
+ </table>
53
+ </div>
54
+ </body>
55
+ </html>
@@ -0,0 +1,80 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
5
+ <style>
6
+ .container {
7
+ display: flex;
8
+ }
9
+
10
+ .line-numbers {
11
+ padding-right: 0.5em;
12
+ }
13
+
14
+ .line-numbers > a {
15
+ color: #000;
16
+ display: block;
17
+ font-family: monospace;
18
+ text-align: right;
19
+ text-decoration: none;
20
+ }
21
+
22
+ .line-numbers > a.current {
23
+ color: orangered;
24
+ outline: none;
25
+ }
26
+
27
+ .line-numbers > a.current:after {
28
+ content: '';
29
+ position: absolute;
30
+ left: 0;
31
+ right: 100%;
32
+ width: 100vw;
33
+ height: 12px;
34
+ background: #ff9;
35
+ z-index: -1;
36
+ }
37
+
38
+ .the-code {
39
+ flex: 1;
40
+ margin: 0;
41
+ }
42
+
43
+ .hljs {
44
+ background: rgba(0,0,0,0.01);
45
+ padding: 0;
46
+ }
47
+ </style>
48
+ </head>
49
+ <body>
50
+ <div class="container">
51
+ <div class="line-numbers">
52
+ <% 1.upto(@source.lines.size) do |line_number| %>
53
+ <a id="<%= line_number %>" href="#<%= line_number %>" class="line-number"><%= line_number %></a>
54
+ <% end %>
55
+ </div>
56
+ <pre class="the-code hljs javascript"><code><%= @source %></code></pre>
57
+ </div>
58
+ <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
59
+ <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/languages/javascript.min.js"></script>
60
+ <script>
61
+ (function() {
62
+ hljs.initHighlightingOnLoad();
63
+
64
+ function selectCurrentLine() {
65
+ var hash = location.hash
66
+ , currentLineNumber = hash.replace(/#/, '');
67
+ Array.prototype.slice.call(document.querySelectorAll('.line-number')).forEach(function(lineNumber) {
68
+ lineNumber.classList.remove('current');
69
+ });
70
+ document.getElementById(currentLineNumber).classList.add('current');
71
+ }
72
+
73
+ if (location.hash) {
74
+ selectCurrentLine();
75
+ }
76
+ window.addEventListener('hashchange', selectCurrentLine);
77
+ }())
78
+ </script>
79
+ </body>
80
+ </html>
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ESLINT_RAILS_DIR=$(pwd)
4
+ PLUGINS=(yannickcr/eslint-plugin-react) # Add new plugins here.
5
+ GIT_URL_PREFIX="git@github.com:"
6
+ GIT_URL_SUFFIX=".git"
7
+
8
+ mkdir -p /tmp/eslint-rails-plugins
9
+ cd /tmp/eslint-rails-plugins
10
+
11
+ for plugin in ${PLUGINS[@]}; do
12
+ git_url=$GIT_URL_PREFIX$plugin$GIT_URL_SUFFIX
13
+ git clone $git_url
14
+ plugin_name=$(basename $git_url .git)
15
+ cd $plugin_name
16
+ npm install
17
+ browserify index.js -o $plugin_name.js
18
+ cp $plugin_name.js $ESLINT_RAILS_DIR/vendor/assets/javascripts/plugins/
19
+ done
20
+
21
+ rm -rf /tmp/eslint-rails-plugins