JSLint : how to use it? - jslint

I've understood that JSLint is a great tool for JavaScript development but I've some dark points in my global comprehension of this.
How to use it inside my development environment ? In other words how and when do you run JSLint against your code ? I've seen the Aptana integration but it seems that it doesn't take into account statements like :
/* jslint nomen: false */
How to work correctly in a client side development environment ? I want JSLint to feel good when parsing calls including objects like "console", "$" or "JQuery".
How to use it on a whole project with multiple files (with no import statement inside of them) ?
I've read to much statement suggesting to copy paste on jslint to sleep correctly, so any answer consisting of configuring the online JSLint form would be considered as irrelevant.

I'm sorry to write this answer which is not really one. The best solution I've found is to use JSHint which is a concurrent to JSLint with some nice extra features :
Installation is made easy through NPM with command like (also works for JSLint), NPM is required :
npm install -g jshint
Execution is made easy against a lot of file (doesn't work for JSLint) :
jshint mycodedirectory
Configuration is possible through the --config options, config files look like :
{
"curly":true,
"eqeqeq": true,
"immed": true,
"bitwise": true,
"newcap": true,
"noempty": true,
"unused": true,
"camelcase":true,
"undef": true,
"strict": true,
"trailing": true,
"maxparams": 7,
"maxdepth": 5,
"maxstatements": 50,
"maxcomplexity": 13
}
This solution works for both browser and server code, it's IDE and OS independent, it can be easily integrated in continuous integration process.

Some one came up with a solution to run it automatically on your project using node.js:
Automating JSLint Validation

I use (a slightly modified) JSLINT for WSH on Emacs/WinXP. It highlights problematic code right while I am typing:
This is of great help not only to enforce the configured coding style, but also to find many JavaScript syntax errors before executing code.
It does respect statements such as /* jslint nomen: false */.
As you are asking concerning linting code that runs in a browser environment with jQuery, simply use standard JSLint options:
/*jslint browser: true */
/*global $ */
Just be sure to replace the included JSLint code with the latest version.

Related

How to use Log Parser Plugin in a Jenkins Workflow script

The Log Parser Plugin is now compatible with Workflow but how do I use it?
Easiest is to use Snippet Generator to get an example step statement using it.
Snippet Generator is a good idea; however, it is not generating the complete line to make it work. It is necessary to add at the end of the code line ", projectRulePath: ''".
Final line will be in the way, for example:
logParser failBuildOnError: true, parsingRulePath: '/myRulesPath', showGraphs:true, unstableOnWarning: true, useProjectRule: false, projectRulePath: ''

How to achieve precompiler directive like functionality

I'm developing an angular app, and it's recommended to use generated code for a lot of things running in production, namely template caches, expression caches, and a static DI injector. There's currently no nice way to switch between different build configurations, so I'm using the pattern recommended here:
In lib/main.dart you can see initializer-prod.dart file being imported, which has initializer-dev.dart counterpart. Switching between those two file will allow you to switch between prod and dev modes. You will need to run the generator script before using the prod mode.
This results in the following import:
//import 'initializer_prod.dart' as init; // Use in prod/test.
import 'initializer_dev.dart' as init; // Use in dev.
As you can see, switching the import is a manual process. Is there a better, more automatic way to achieve this?
I see two possibilities (haven't tried any of these myself yet)
one is to use a transformer (see also Pass custom parameters to a dart application when using pub serve to run it)
or
Compile-time dead code elimination with dart2js
Recently a feature should have been added that pub build allows adding an environment variables using a command line option (like dart2js's -d)
log(String msg) {
if (const String.fromEnvironment('DEBUG') != null) {
print('debug: $msg');
}
}
main() {
log('In production, I do not exist');
}
Some links about transformers:
Can We Build It? Yes, We Can!
Assets and Transformers
Day 992: Search and Replace Dart Transformer to Hide from Polymer
Dart Transformers for Polymer Cleanup
Pub transformers
dart2js_dransformer.dart
Document user-defined transformers
EDIT
I was able to configure dart2js options in pubspec.yaml like
transformers:
- $dart2js:
commandLineOptions: [-DDEBUG=true]
environment:
DEBUG: "true"
suppressWarnings: true
terse: true
They are validate and pub build fails if an unknown option is provided or if it's not the expected format (yaml list for commandLineOptions, yaml map form environment)
BUT String.fromEnvironment() didn't get a value
According to this issue, this is supported:
Passing in arguments to dart2js during pub build
I filed a bug How to pass options to dart2js from pubspec.yaml
EDIT-2
I tried it and it is working now:
transformers: # or dev_transformers
- $dart2js:
environment: { PROD: "true" }
access it from the code like
String.fromEnvironment()
main() {
print('PROD: ${const String.fromEnvironment('PROD')}');
// works in the browser
// prints 'PROD: null' in Dartium
// prints 'PROD: true' in Chrome
}
see also Configuring the Built-in dart2js Transformer
EDIT-3
Another way is to use assert to set variables.
assert is ignored in production.

Running F# xUnit Fact from TestDriven.NET reporting "It looks like you're trying to execute an xUnit.net unit test."

I am trying to run xUnit tests (from an F# module, if it makes any difference) using TestDriven.NET, but whatever I do I get this error:
It looks like you're trying to execute an xUnit.net unit test.
For xUnit 1.5 or above (recommended):
Please ensure that the directory containing your 'xunit.dll' reference also contains xUnit's
test runner files ('xunit.dll.tdnet', 'xunit.runner.tdnet.dll' etc.)
For earlier versions:
You need to install support for TestDriven.Net using xUnit's 'xunit.installer.exe' application.
You can find xUnit.net downloads and support here:
http://www.codeplex.com/xunit
I tried following the suggestions, i.e. I copied the files
xunit.dll.tdnet
xunit.extensions.dll
xunit.gui.clr4.exe
xunit.runner.tdnet.dll
xunit.runner.utility.dll
xunit.runner.utility.xml
xunit.xml
to the folder with xunit.dll and I ran xunit.installer.exe. How can I get it to work?
I just figured out that I forgot to make the test a function in F# (so it was just a value). The error message can't be more misleading though!
You have two problems:
your Fact is broken:-
If you hover over the
please work
bit, you'll see something like: unit -> int
For a Fact to be picked up by an xUnit runner, it needs to yield `unit (void).
Hence, one key thing to get right first is to not return anything. In other words, replace your 123 with () (or an Assertion).
You can guard against this by putting a :unit stipulation on the test:-
[<Fact>]
let ``please work`` () : unit = 123
This will force a compilation error.
TestDriven.NET is reporting it cannot find the xunit.tdnet modules
It's critical to get step 1 right first. Then retry and the problem should be gone
If it remains...
Either try the VS-based runner which should work as long as it's installed and xunit.dll is getting to your output dir or look at the docs for your version of TD.NET for detailed troubleshooting notes (exec summary is if the .tdnet file was in your out dir or you undo and redo the xunit.installer from the folder containing the packages it should just work, esp if you are on latest)

LaTeX Failed to Parse(Unknown Error) on MediaWiki

On my wiki implemented by the MediaWiki interface, I am receiving a Failed to Parse (Unknown Error) for the LaTeX in the page. I checked the LocalSettings.php file, and I have set the proper variable($wgUseTeX) to true.
If it helps, the error message before this was a Failed to Parse(Missing texvc executable), but I "fixed" it to the best of my knowledge by running "make" inside the math directory and installing the texvc executable there. I tested texvc and it works on the commandline.
Could there be anything that I am missing?
aptitude install ocaml
cd /math
make clean
make
Found the answer here: MediaWiki Forums LaTeX Error
It seems that I had to clear the math directory except for the original files, rebuild ocaml, and finally rebuild texvc.
Adding this to LocalSettings solved it for me. Just needed to make the directory calls accurate. Tedious.
$wgUseTeX = true;
$wgUploadDirectory = "{$IP}/images";
$wgUploadPath = "{$wgScriptPath}/images";
$wgMathPath = "{$wgUploadPath}/math";
$wgMathDirectory = "{$wgUploadDirectory}/math";
$wgTmpDirectory = "{$wgUploadDirectory}/tmp";
$wgTexvc = "{$IP}/math/texvc";
Have a look at the README file, paying particular attention to "Ensure that the temporary and math directories exist and can be written to by the user account the web server runs under; if you don't control the server, you may have to make them world-writable."
If that does not help, edit render.ml, comment out the block that says "Commenting this block out will aid in debugging", and re-run make. This will leave all temporary files (including the TeX log) so that you can hopefully see what went wrong.

ANTLR parser hanging at proxy.handshake call

I am attempting to get a basic ECMAScript parser working, and found a complete ANTLR grammar for ECMAScript 3, which appears to compile ok and produces the appropriate Lexer/Parser/Walker Java files.
(Running inside ANTLR IDE plugin for Eclipse 3.5)
However, when actually trying to use it with some simple test code (following guide on ANTLR wiki), it just hangs when trying to create the parser:
CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid
ES3Lexer MyLexer = new ES3Lexer(MyChars);
CommonTokenStream MyTokens = new CommonTokenStream(MyLexer);
MyTokens.setTokenSource(MyLexer);
ES3Parser MyParser = new ES3Parser( MyTokens ); // hangs here
ES3Parser.program_return MyReturn = MyParser.program();
I've tracked down the problem to inside the ES3Parser constructor, where it's calling the function proxy.handshake() - before this line I can successfully do System.out.println("text") but after it I get nothing.
So, how do I go about finding out why it's hanging, and stopping it - or even just bypassing this section (can/should I disable debugging?) - so long as that lets it work and allows me to get on with doing useful stuff.
There is a -debug option in Antlr that causes additional code to generated allowing for remote debugging. When the code pauses on the the
dbg.Handshake();
call, it is waiting for the remote debugger to connect to it. In AntlrWorks you can use the Run --> Remote Debug option to connect to it and step through the code.
If you don't wish to use the remote debugging functionality, remove the -debug option from the ANTLR options text box.
File --> Preferences --> General --> ANTLR Options
I solved this by disabling the generation of debug code within the ANTLR IDE plugin.
The setting for this is under Windows > Preferences > ANTLR > Code Generation.
Expand the General section and untick the debug option:
(source: bpsite.net)

Resources