Sha256: 6aaea4d0365e7544c3076d308224c2d450ae4a4dd189e44a34d2ad88475aa020

Contents?: true

Size: 1.35 KB

Versions: 45

Compression:

Stored size: 1.35 KB

Contents

'use strict';

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

module.exports = {
  'name': 'mixins-before-declarations',
  'defaults': {
    'exclude': [
      'breakpoint',
      'mq'
    ]
  },
  'detect': function (ast, parser) {
    var result = [],
        error;

    ast.traverseByType('include', function (node, i, parent) {
      var depth = 0,
          declarationCount = [depth];

      parent.forEach(function (item) {
        if (item.is('ruleset')) {
          depth++;
          declarationCount[depth] = 0;
        }
        else if (item.is('declaration')) {
          if (item.first().is('property')) {
            var prop = item.first();

            if (prop.first().is('ident')) {
              declarationCount[depth]++;
            }
          }
        }
        else if (item.is('include')) {
          item.forEach('ident', function (name) {
            if (parser.options.exclude.indexOf(name.content) === -1 && declarationCount[depth] > 0) {
              error = {
                'ruleId': parser.rule.name,
                'line': item.start.line,
                'column': item.start.column,
                'message': 'Mixins should come before declarations',
                'severity': parser.severity
              };
              result = helpers.addUnique(result, error);
            }
          });
        }
      });
    });
    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/mixins-before-declarations.js
govuk_publishing_components-17.21.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.20.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.19.1 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.19.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.18.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.17.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.16.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.15.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.14.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.13.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.12.2 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.12.1 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.12.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.11.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.10.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.9.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.8.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.7.0 node_modules/sass-lint/lib/rules/mixins-before-declarations.js
govuk_publishing_components-17.6.1 node_modules/sass-lint/lib/rules/mixins-before-declarations.js