Skip to content

Instantly share code, notes, and snippets.

@leeight
Created May 8, 2014 03:51
Show Gist options
  • Save leeight/2ec947c83a86bede1613 to your computer and use it in GitHub Desktop.
Save leeight/2ec947c83a86bede1613 to your computer and use it in GitHub Desktop.
test.less.js
/***************************************************************************
*
* Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
* $Id$
*
**************************************************************************/
/**
* test.less.js ~ 2014/05/08 11:31:13
* @author leeight([email protected])
* @version $Revision$
* @description
*
**/
var path = require( 'path' );
var less = require( 'less' );
var tree = require( 'less/lib/less/tree' );
var options = {
paths: [ __dirname ],
relativeUrls: true
}
var data =
'@fooBar: 10px;\n' +
'@foo-bar: 20px;\n' +
'div{\n' +
' border: 1px solid @fooBar;\n' +
'}';
// @see tree.toCSSVisitor
function LintVisitor( env ) {
this._visitor = new tree.visitor( this );
this._env = env;
}
LintVisitor.prototype.run = function( root ) {
this._visitor.visit( root );
};
LintVisitor.prototype.visitVariable = function( node, visitArgs ) {
var pattern = /^@([a-z0-9\-]+)$/;
var name = node.name;
if ( !pattern.test( name ) ) {
console.error( 'Invalid variable declaration %s', name );
}
};
var lintVisitor = new LintVisitor();
var parser = new ( less.Parser )( options );
parser.parse( data, function( err, tree ){
if ( err ) throw err;
lintVisitor.run( tree );
// console.log( tree.toCSS() );
});
/* vim: set ts=4 sw=4 sts=4 tw=100: */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment