Sha256: c678c6f47e4a19060937d1c32d1f3c887c37bc72136e8162ca7b601e917821b8

Contents?: true

Size: 1.42 KB

Versions: 45

Compression:

Stored size: 1.42 KB

Contents

'use strict';

var helpers = require('../helpers');

/**
 * Check if it's an exception (combinator or a parent selector before or after a space)
 *
 * @param {Object} node - The node to check
 * @param {Object} next - The next node
 * @param {Object} previous - The previous node
 * @returns {Boolean} True if exception
 */
var isException = function (node, next, previous) {
  if (node.is('space')) {
    if (next && next.is('combinator') || next.is('parentSelector')) {
      return true;
    }

    if (previous && previous.is('combinator') || previous.is('parentSelector')) {
      return true;
    }
  }

  return false;
};

module.exports = {
  'name': 'no-combinators',
  'defaults': {},
  'detect': function (ast, parser) {
    var result = [];

    ast.traverseByType('selector', function (selector) {
      selector.forEach(function (item, i) {
        var previous = selector.content[i - 1] || false,
            next = selector.content[i + 1] || false;

        if (isException(item, next, previous)) {
          return false;
        }

        if (item.is('combinator') || item.is('space')) {
          result = helpers.addUnique(result, {
            'ruleId': parser.rule.name,
            'line': item.start.line,
            'column': item.start.column,
            'message': 'Combinators are not allowed',
            'severity': parser.severity
          });
        }
        return false;
      });
    });

    return result;
  }
};

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.21.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.20.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.19.1 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.19.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.18.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.17.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.16.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.15.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.14.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.13.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.12.2 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.12.1 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.12.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.11.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.10.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.9.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.8.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.7.0 node_modules/sass-lint/lib/rules/no-combinators.js
govuk_publishing_components-17.6.1 node_modules/sass-lint/lib/rules/no-combinators.js