Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to to run eslint on *.js.erb files?

I'd like to lint the files in my rails project (ideally, in my editor while making edits) via eslint, but I am currently unable to lint files that are pre-processed with ERB.

How can I include *.js.erb files in the linting process?

like image 750
Austin York Avatar asked Jun 10 '15 05:06

Austin York


People also ask

How do I run ESLint in JavaScript?

JavaScript - use .eslintrc.js and export an object containing your configuration. JavaScript (ESM) - use .eslintrc.cjs when running ESLint in JavaScript packages that specify "type":"module" in their package.json.

How does ESLint find the root directory?

If there is a .eslintrc file in the same directory as the file being linted, then that configuration takes precedence. ESLint then searches up the directory structure, merging any .eslintrc files it finds along the way until reaching either a .eslintrc file with root: true or the root directory.

How do I use configuration files in ESLint?

The first way to use configuration files is via .eslintrc.* and package.json files. ESLint will automatically look for them in the directory of the file to be linted, and in successive parent directories all the way up to the root directory of the filesystem ( / ), the home directory of the current user ( ~/ ), or when root: true is specified.

Why is ESLint not working on my package?

If there is a .eslintrc and a package.json file found in the same directory, .eslintrc will take priority and package.json file will not be used. By default, ESLint will look for configuration files in all parent folders up to the root directory.


1 Answers

You would need to run eslint with -ext js.erb flag. If your files contain more then just javascript, however, you will have to create your own plugin with processor, that would strip out everything but pure javascript and maintain source map, so that error messages can be changed to point to correct line numbers after linting. You can see more information about processors here: http://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins

like image 144
Ilya Volodin Avatar answered Oct 18 '22 00:10

Ilya Volodin