appfolio / eslint-rails

MIT License
39 stars 22 forks source link

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

Open stadelmanma opened 7 years ago

stadelmanma commented 7 years ago

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