appfolio / eslint-rails Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
There are new rules that we don't support. Boooo ๐ป! Thanks @mhmazur for the tip.
I created a local plugin and included it in the config/eslint.json file.
When I run Eslintrb.lint(source, :eslintrc)
i get
high pattern/return-object-only Definition for rule 'pattern/return-object-only' was not found
{
"extends": [
"eslint:recommended"
],
"plugins": [
"pattern"
],
"env": {
"browser": true,
"node": true
},
"globals": {
"angular": true,
"$": true
},
"rules": {
"pattern/return-object-only" : 2,
"comma-dangle": [
"error",
"never"
],
"no-console": "off",
"no-unused-vars": ["error", { "vars": "all", "args": "none" }],
"quote-props": ["error", "as-needed"],
"quotes": [
2,
"single", {"avoidEscape": true, "allowTemplateLiterals": true}
],
"semi": [
"error",
"always"
]
}
}
I typically use the YAML formatted config for readability, but looking through the code this doesn't appear to be supported. I would be glad to submit a PR adding support for different eslint config files and locations.
I would follow the priority order listed in the link below which is what eslint uses adding config/eslint.json
to the top so existing functionality is not changed at all for anyone using both files:
Config priority:
config/eslint.json
.eslintrc.js
.eslintrc.yaml
.eslintrc.yml
.eslintrc.json
The only additional change that would be required is abstracting out the config parsing to make usage of Config agnostic to the config file format.
Relevant portion of lib/runner.rb that needs changed
def plugins
JSON.parse(Config.read)['plugins'] || []
end
def warning_hashes(file_content)
ExecJS.eval <<-JS
function () {
window = this;
#{eslint_js};
#{eslint_plugin_js};
return eslint.verify('#{escape_javascript(file_content)}', #{Config.read});
}()
JS
end
Additional config uses:
https://github.com/appfolio/eslint-rails/search?utf8=%E2%9C%93&q=Config&type=
Additional info:
https://eslint.org/docs/user-guide/configuring#configuration-file-formats
Sorry if I have missed any obvious point, how do I pass option to eslint while running rake eslint:run
I am adding this gem to my rails project and I want to run eslint on only chnaged or new files, so I need to pass option --cache
to eslint
I'm noticing there are a few rules that need to be updated in config/eslint.json
. I'll be working on these as I go along. I'll submit a PR when I'm done.
For example:
no-empty-class
has been removed. There is now a no-empty-character-class
http://eslint.org/docs/rules/no-empty-character-class
Right now, the gem doesn't support erb at all. I'm not quite sure how this would work, but I'm thinking we could render the erb file, and then lint the resulting rendered js.
Please note that i am using node version 0.12.4
filename: is the exact file path of js file.
when i run rake eslint:run_all/ rake eslint:run[filename] below error is throwing up
ExecJS::ProgramError: TypeError: Cannot read property 'firebug' of undefined Function.useColors (eval at <anonymous> ((execjs):1:266), <anonymous>:13435:75) createDebug (eval at <anonymous> ((execjs):1:266), <anonymous>:13688:29) Object.debug (eval at <anonymous> ((execjs):1:266), <anonymous>:49889:29) s (eval at <anonymous> ((execjs):1:266), <anonymous>:12502:620) eval (eval at <anonymous> ((execjs):1:266), <anonymous>:12502:671) Object../debug-helpers (eval at <anonymous> ((execjs):1:266), <anonymous>:47845:13) s (eval at <anonymous> ((execjs):1:266), <anonymous>:12502:620) eval (eval at <anonymous> ((execjs):1:266), <anonymous>:12502:671) Object../code-path-segment (eval at <anonymous> ((execjs):1:266), <anonymous>:48117:23) s (eval at <anonymous> ((execjs):1:266), <anonymous>:12502:620) Tasks: TOP => eslint:run_all
Please let me know anything is wrong? trying with latest version 1.3.0 and 1.2.2 getting same error.
but 1.2.1 works only for js files not es6 files.
This was just an oversight. The README should tell you how to build and embed the new version ESLint. Derp.
It'd be great if this gem could also print the filename the error was found in, specifically for when we run it on the whole app. It kinda works to know where it is in the application.js, but with a large project, it's hard to tell what source file that maps to.
I started looking into this, and it looks like right now there's no concept of where each line of application.js came from. We could loop over the files from sprockets, using Rails.application.assets.each_file
, but I think we'd run into linting issues where variables are defined in different files. I may dig into this some more and see if there's a good solution, but I'd also love to hear some feedback on how feasible this sounds.
Is it possible?
Recently I've been working on an eslint plugin called eslint-plugin-compat that lints support for API's by using the caniuse db. It seems there is demand from the community for this plugin. Would a PR for it be welcome?
Here's a demo of it in action
One thing I noticed is that if there's a warning created that doesn't have a specific ruleID
, associated with it (random syntax errors for example), the linter blows up with this error: NoMethodError: undefined method
size' for nil:NilClass`, which isn't super helpful.
That is happening because ruleID is never being set here:
https://github.com/appfolio/eslint-rails/blob/master/lib/eslint-rails/warning.rb#L9
A quick fix would be something like:
@rule_id = warning_hash['ruleId'] || "-1"
# OR
@rule_id = warning_has['ruleId'] || "unexpected error"
This would allow the linter to finish and put out an error like this:
4:8 high -1 Parsing error: Unexpected token <
Which is a little more helpful (IMO).
I'll submit a PR shortly if that's how you'd like to go about it. Let me know, and I'm happy to modify it however you'd like.
Cheers and thanks again for the tool!
Alan
Is it true that rake eslint:run[filename]
can only check one single file at a time?
It would be nice if there was support for checking multiple files at once.
Right now I have solved this by adding a file to my config/initializers/
folder.
The file contains the following code:
require 'eslint-rails'
ESLintRails::Runner.class_eval do
def initialize(files)
@files = files.split(' ').map do |file|
normalize_infile(file)
end if files.present?
end
def assets
all_js_assets = Rails.application.assets.each_file.to_a.map { |path| Pathname.new(path) }.select do |asset|
ESLintRails::Runner::JAVASCRIPT_EXTENSIONS.include?(asset.extname)
end
assets =
if @files.present?
all_js_assets.select { |a| a.in?(@files) }
else
all_js_assets
end
assets.reject { |a| a.to_s =~ /eslint.js|vendor|gems|min.js|editorial/ }
end
end
It overrides overwrites the initialize
and assets
methods.
Now I can do: rake eslint:run["filename1 filename2 filename3"]
๐
But it would be nice if I can do that out-of-the-box.
Thanks for reading.
Hi,
the newest version has in lib/eslint-rails/runner.rb line 31 Rails.application.assets.each_file.to_a.select { |pn| pn.extname == '.js' }
.. Rails.application.assets.each_file.to_a
returns an array of strings, not files, therefore string.extname trhows an error .. any suggestions?
Thanks :)
rake eslint:run_all
bundle exec rake eslint:run_all
rake aborted!
Don't know how to build task 'eslint:run_all' (see --tasks)
/Users/kristiangerardsson/.rbenv/versions/2.3.1/bin/bundle:23:in `load'
/Users/kristiangerardsson/.rbenv/versions/2.3.1/bin/bundle:23:in `<main>'
(See full trace by running task with --trace)
rake eslint:run
works fine.
If changed, please update README.
Hi,
First of all thank you for your work.
I would like to ask what you approach is to avoid having the vendor js's (jquery/jquery-ujs etc) thrown into the eslinter?
My approach was a really hacky way like this:
my manifest application.js
//= require eslint-fix
//= require jquery
/*eslint-enable */
// ... other eslintable requires
the eslint-fix is a file that only has the /eslint-disable/.
why i did this?
because even if i added /eslint-disable/ before the jquery require, due to sprockets overriding this order, jquery would still get rendered in the bundled application first, so i added a new file that forcefully gets rendered first with that tag disabling everything until i re-enable it.
This might not be a common use case for other persons, nevertheless i would like to know what would be a less hacky approach to this.
Hi,
How to auto-correct indentation once found ? Do we have an option like --fix ?
Also is there a way to execute files with .erb extensions, say reports.js.jsx.erb ?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.