Rails: require JS code to pass the Closure Linter or JSHint - ruby-on-rails

With Ruby on Rails, is there a configuration I can set that requires the JS code to pass the Closure Linter or JSHint?
You know how when you have a syntax error in your SCSS, an error shows up in dev. I'd like to require something similar with JSHint.

Can you set up an IDE to trigger JShint checker, check out http://jshint.com/install/

Related

how does preprocessor engine runs when asset files are compiled in rails?

Let's say I have a file called foobar.js.erb.coffee.
I'm confused how this file is interpreted when rails application is compiled. My understanding is like following:
1) Coffeescript preprocessor engine interprets from coffeescript to ruby(erb).
2) ERB preprocessor engine converts ruby to javscript.
Am I understanding this correctly?
For example, foobar.js.erb.coffee
The extension of the file will be composed of two parts: the format (foobar.js) followed by the handler (.erb.coffee).
A handler is a preprocessor for the template, or a templating language. There are a number of handlers built in, and many more can be added by using extra gems.
The order of conversion is from right to left.
In your case, the CoffeeScript engine try to convert CoffeeScript into JavaScript (Error may occur because of existing ERB may cause CoffeeScript has invalid syntax) and then the ERB handlers will replace all the Ruby code to what the output value should be.
I always put .erb at last for these kind of situation. For example, main.css.scss.erb or app.js.es6.erb.

How do I configure StaticParser using expression generator as of angular.dart 0.9.9?

For my production releases, I have been using the expression extractor to generate a file containing expressions that are being used by my templates. When in production, I was configure the StaticParser like so:
import '../gen/expression_cache.gen.dart' as expression_cache;
...
module.type(Parser, implementedBy: StaticParser);
module.value(StaticParserFunctions, expression_cache.functions()); // <-- this no longer works
Something has changed with how the expressions are generated, as the line configuring StaticParserFunctions no longer works. The functions() method no longer exists. So I'm wondering, what is the correct way to do this as of angular 0.9.9?
Is far as I know the Angular Dart tutorial is pretty much up to date.
https://github.com/angular/angular.dart.tutorial/blob/master/Chapter_07/web/initializer-prod.dart
https://angulardart.org/tutorial/09-ch07-deploying-your-app.html (search for generator)

Rails and CoffeeScript compile error in production

Somehow in development environment my coffeeScript files compile correctly. But when I compile them for production I get something like this
CoffeeScript:
$->
alert "hello world"
Compiled to Javascript
(function() {
$(function(){
alert("hello world");
})
}).call(this)
I have checked for miss indentations and spacing errors, or for a mix of tabs and spaces but there are not any. The weird thing is that when I converted the with the compiler from coffeescript.org it compiles correctly, its just in the production environment. Any ideas?
by the way: I am using rails 4
It's a coffeescript setting.
(function() {
# Code here
}).call(this)
Is a closure generated by coffeescript by default (can be disabled, but you shouldn't), used to avoid global namespace pollution.
It doesn't affect the script execution, your jQuery code will still be run once document is loaded.
Important note
The only issue you may find with that closure is that you actually have hard time declaring global variables. This can be solved in this way:
window.yourvar = 'something'
There is also a suggestion here on how you can disable it anyway: How can I use option "--bare" in Rails 3.1 for CoffeeScript?

Why did JSLint mark this line as an error

/*global THREE Coordinates $ document window*/
JSLint says it was expecting */ but got Coordinates instead
but the line passed when passed when I ran it in Eclipse javascript project.
Js lint thought you were using the /*global*/ directive. This is used to indicate a variable is global and somewhere else.
See: JS Lint Global Directive

How can I syntax check (not render) a Rails 3 ERB template file?

I'm trying to have a git pre-commit hook perform a syntax check on all Ruby code; there is one on GitHub at https://github.com/cypher/git-ruby-syntax-check.
It attempts to check .erb files by erb -x to translate them into Ruby code and then passes the output to ruby -c for syntax checking. Unfortunately, Rails 3 introduced a custom ERB parser that is incompatible with Ruby's standard ERB, and so the pre-commit hook is finding errors where there are none.
Is there some equivalent to erb -x that will output Ruby code from a Rails 3 ERB file?
I have not dug much into either of these but you might try rails-erb-check (Git project) or this blog entry. I agree with shingara but the Blog Post describes a situation where this is useful and I wonder if you are in a similar position:
Diaspora is pretty fluid right now. This means we are have some green
tests, some missing tests, and other tests that check intent (not
implementation). In an ideal world, I suppose test cases would cover
all of our bases...
Until then, I've added a new task to my fork, check_syntax:all. This
breaks down further to the subtasks check_syntax:erb,
check_syntax:haml, check_syntax:haml_ruby, check_syntax:sass, and
check_syntax:yaml.
If you get an "argument list too long error" for rails-erb-check , you can try rails-erb-lint which scans your current views folder.

Resources