How to use gonzales-pe - 10 common examples

To help you get started, we’ve selected a few gonzales-pe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github csscomb / core / test / lint_tree.js View on Github external
it('Should lint, multiple errors', function() {
        var comb = new Comb();
        var ast = originalAST = gonzales.parse('a{color:red}');
        var error = {line:1, column: 7, message: 'foo'};
        comb.plugins = [{
            syntax: ['css'],
            lint: function(node) {
                return [error, error];
            }
        }];
        assert.deepEqual([error, error], comb.lintTree(ast, 'css'));
        // Should not modify ast:
        assert.deepEqual(originalAST, ast);
    });
});
github brackets-userland / brackets-sass-lint / node_modules / sass-lint / lib / groot.js View on Github external
module.exports = function (text, syntax, filename) {
  var tree;

  // Run `.toString()` to allow Buffers to be passed in
  text = helpers.stripBom(text.toString());

  // if we're skipping front matter do it here, fall back to just our text in case it fails
  if (fm.test(text)) {
    text = fm(text).body || text;
  }

  try {
    tree = gonzales.parse(text, {
      'syntax': syntax
    });
  }
  catch (e) {
    throw {
      message: e.message,
      file: filename,
      line: e.line
    };
  }

  if (typeof tree === 'undefined') {
    throw {
      message: 'Undefined tree',
      file: filename,
      text: text.toString(),
github gmac / sass-thematic / lib / thematic.js View on Github external
loadSource: function(source) {
    if (typeof source === 'object') {
      this.ast = source;
    }
    else if (typeof source === 'string') {
      // JSON source:
      if (isJSON(source)) {
        this.ast = JSON.parse(source);
      }
      // Sass source:
      else {
        this.ast = gonzales.parse(source, {syntax: 'scss'});
      }
    }
    else {
      throw 'Source could not be loaded.';
    }

    return this.resetMapping();
  },
github symdiff / symdiff-sass / index.js View on Github external
function symdiffSASS(sassString) {
    var ast;
    try {
        // try SCSS first
        ast = gonzales.parse(sassString, {
            syntax: 'scss'
        });
    } catch(err1) {
        try {
            // try SASS second
            ast = gonzales.parse(sassString, {
                syntax: 'sass'
            });
        } catch(err2) {
            // ok whatever
            return [];
        }
    }

    var classes = [];
    walk(ast, function(node) {
github csscomb / csscomb.js / src / options / sort-order.js View on Github external
if (currentNode.is('multilineComment') ||
          currentNode.is('singlelineComment')) {
        positions.push(i);
        continue;
      }

      // If there are any line breaks in a node with spaces, stop and
      // split the node into two: one with spaces before line break
      // and one with `\n` symbol and everything that goes after.
      // Combine the first one with declaration/@-rule's node:
      let linebreakIndex = currentNode.content.indexOf('\n');
      if (linebreakIndex !== -1) {
        var s = currentNode.content.substring(0, linebreakIndex);
        if (s === '') break;
        var space = gonzales.createNode({type: 'space', content: s});
        node.insert(i + 1, space);
        positions.push(i + 1);
        currentNode.content = currentNode.content
            .substring(linebreakIndex);
        break;
      }

      positions.push(i);
    }

    return positions;
  },
github csscomb / csscomb.js / src / options / space-after-opening-brace.js View on Github external
ast.traverse(function(node) {
      // If found block node stop at the next one for space check
      if (!node.is('block') && !node.is('atrulers')) return;

      if (node.first() &&
          node.first().is('space')) {
        node.first().content = value;
      } else if (value !== '') {
        var space = gonzales.createNode({
          type: 'space',
          content: value
        });
        node.insert(0, space);
      }
    });
  },
github csscomb / sublime-csscomb / node_modules / csscomb / lib / options / vendor-prefix-align.js View on Github external
payload: function (info, i) {
            // `node.get(i - 1)` can be either space or comment:
            var whitespaceNode = node.get(i - 1);
            if (!whitespaceNode) return;
            // If it's a comment, insert an empty space node:
            if (!whitespaceNode.is('space')) {
              whitespaceNode = gonzales.createNode({
                type: 'space',
                content: ''
              });
              node.insert(i - 1, whitespaceNode);
            }
            let content = whitespaceNode.content;
            let updatedContent = updateIndent(info, dict, content);
            whitespaceNode.content = updatedContent;
          }
        });
github csscomb / csscomb.js / src / options / vendor-prefix-align.js View on Github external
payload: function(info, i) {
            // `node.get(i - 1)` can be either space or comment:
            var whitespaceNode = node.get(i - 1);
            if (!whitespaceNode) return;
            // If it's a comment, insert an empty space node:
            if (!whitespaceNode.is('space')) {
              whitespaceNode = gonzales.createNode({
                type: 'space',
                content: ''
              });
              node.insert(i - 1, whitespaceNode);
            }
            let content = whitespaceNode.content;
            let updatedContent = updateIndent(info, dict, content);
            whitespaceNode.content = updatedContent;
          }
        });
github csscomb / csscomb.js / src / options / space-before-closing-brace.js View on Github external
if (blockIndent) {
          value += new Array(level).join(blockIndent);
        }
      }

      // If found block node stop at the next one for space check
      // For the pre-block node, find its last (the deepest) child
      var whitespaceNode = getLastWhitespaceNode(node);

      // If it's spaces, modify this node
      // If it's something different from spaces, add a space node
      // to the end
      if (whitespaceNode) {
        whitespaceNode.content = value;
      } else if (value !== '') {
        var space = gonzales.createNode({
          type: 'space',
          content: value
        });
        node.content.push(space);
      }

      processBlock(node, level);
    });
  }
github lightningtgc / sublime-cssorder / node_modules / cssorder / node_modules / csscomb / lib / csscomb.js View on Github external
function cssToAST(text, syntax, filename) {
    var string = JSON.stringify;
    var fileInfo = filename ? ' at ' + filename : '';
    var tree;

    try {
        tree = gonzales.srcToAST({ syntax: syntax, src: text });
    } catch (e) {
        throw new Error('Parsing error' + fileInfo + ': ' + e.message);
    }

    // TODO: When can tree be undefined? 
    if (typeof tree === 'undefined') {
        throw new Error('Undefined tree' + fileInfo + ': ' + string(text) + ' => ' + string(tree));
    }

    return tree;
}