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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With