Giter Club home page Giter Club logo

eslint-rails's People

Contributors

alanbsmith avatar bbonamin avatar dkniffin avatar e0da avatar francoprud avatar jonkessler avatar zachahn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eslint-rails's Issues

handling unexpected errors (with no ruleID)

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 methodsize' 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

Print source filename

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.

rake eslint:run_all or rake eslint:run[filename] not working

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.

How to autocorrect issues ?

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

Handle linting of erb files

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.

passing options to rake eslint:run

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

Rails Sprockets Integration (Vendor assets getting linted)

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.

rake eslint:run_all does not work

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.

Support for multiple files at once

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.

NoMethodError: undefined method `extname' for "/.../../asset.gif":String

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 :)

Support for .eslintrc.yaml, etc. file formats?

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:

  1. config/eslint.json
  2. .eslintrc.js
  3. .eslintrc.yaml
  4. .eslintrc.yml
  5. .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

eslint.json `plugin` not working

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"
    ]
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.