Sha256: 47bf488a2dbf4bfb9cb35b10abea0ef0928634adbe36f7bb6e9efd334d8b8475

Contents?: true

Size: 1.56 KB

Versions: 45

Compression:

Stored size: 1.56 KB

Contents

'use strict';

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

module.exports = {
  'name': 'space-after-comma',
  'defaults': {
    'include': true
  },
  'detect': function (ast, parser) {
    var result = [];

    ast.traverseByTypes(['operator', 'delimiter'], function (operator, i, parent) {
      var next,
          doubleNext;

      if (operator.content === ',') {
        next = parent.content[i + 1] || false;
        doubleNext = parent.content[i + 2] || false;

        if (next) {
          if (operator.is('delimiter')) {
            if (next.is('selector')) {
              next = next.content[0];
            }
          }

          if ((next.is('space') && !helpers.hasEOL(next.content)) && !parser.options.include) {
            if (doubleNext && doubleNext.is('singlelineComment')) {
              return false;
            }

            result = helpers.addUnique(result, {
              'ruleId': parser.rule.name,
              'line': next.start.line,
              'column': next.start.column,
              'message': 'Commas should not be followed by a space',
              'severity': parser.severity
            });
          }

          if (!next.is('space') && parser.options.include) {
            result = helpers.addUnique(result, {
              'ruleId': parser.rule.name,
              'line': operator.start.line,
              'column': operator.start.column,
              'message': 'Commas should be followed by a space',
              'severity': parser.severity
            });
          }
        }
      }
      return true;
    });

    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/space-after-comma.js
govuk_publishing_components-17.21.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.20.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.19.1 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.19.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.18.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.17.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.16.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.15.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.14.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.13.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.12.2 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.12.1 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.12.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.11.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.10.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.9.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.8.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.7.0 node_modules/sass-lint/lib/rules/space-after-comma.js
govuk_publishing_components-17.6.1 node_modules/sass-lint/lib/rules/space-after-comma.js