Closed jedrichards closed 10 years ago
You can go with high-level interface with the report in stdout:
var argv = [ "node", "jscs", "./source-dir/", "--standard=Jquery", "--report-full" ],
jscodesniffer = require( "jscodesniffer" );
jscodesniffer( argv, process.cwd() );
Or with low-level one:
var Sniffer = require( "./lib/Sniffer" ),
sniffer = new Sniffer(),
src = "var a= 1;",
options = {
standard: "Jquery"
},
logger = sniffer.getTestResults( src, options, {} );
console.log(logger.getMessages());
/*
[ { sniff: 'OperatorSpacing',
errorCode: 'OperatorPrecedingWhitespaces',
range: [ 5, 5 ],
loc: { start: { line: 1, column: 5 }, end: { line: 1, column: 5 } },
payload:
{ actual: 0,
expected: 1,
excerpt: '',
trace: '..a=..',
where: '<' } } ]
*/
Great that's exactly what I needed, thank you. FYI the Gulp plugin is coming along well. It isn't published to npm yet but here's a heads up:
Hey
I'm considering making a Gulp friendly plugin that processes file streams against this module. I've had a quick look around the code and the docs but its not immediately clear how to use this module strictly programmatically from another module. In pseudo code, something like the following:
Where
results
in the above example would be a reporter/formatter implementation agnostic object literal that could be used flexibly to transform the output in any way:I don't mean the above code examples as a prescriptive suggestion, I'm just trying to illustrate the way I'd need to use the module programmatically. From what I can see the module is quite structured around the notion of using it as a cli tool rather than a node module.
Is this above use case supported do you think?