Sha256: 37f2659a49823ba474cf5fce3c9209e061dd272b9cca6f64cbcb6f48b43b96ea

Contents?: true

Size: 1.41 KB

Versions: 43

Compression:

Stored size: 1.41 KB

Contents

'use strict';

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

var units = [
  '%',
  'em',
  'ex',
  'ch',
  'rem',
  'vh',
  'vw',
  'vmin',
  'vmax',
  'px',
  'mm',
  'cm',
  'in',
  'pt',
  'pc'
];

module.exports = {
  'name': 'zero-unit',
  'defaults': {
    'include': false
  },
  'detect': function (ast, parser) {
    var result = [];

    ast.traverseByType('number', function (item, i, parent) {

      if (item.content === '0') {
        if (parent.type === 'dimension') {
          var next = parent.content[i + 1] || false;

          if (units.indexOf(next.content) !== -1) {
            if (!parser.options.include) {
              result = helpers.addUnique(result, {
                'ruleId': parser.rule.name,
                'severity': parser.severity,
                'line': item.end.line,
                'column': item.end.column,
                'message': 'No unit allowed for values of 0'
              });
            }
          }
        }
        else {
          if (parent.type === 'value') {
            if (parser.options.include) {
              result = helpers.addUnique(result, {
                'ruleId': parser.rule.name,
                'severity': parser.severity,
                'line': item.end.line,
                'column': item.end.column,
                'message': 'Unit required for values of 0'
              });
            }
          }
        }
      }
    });

    return result;
  }
};

Version data entries

43 entries across 43 versions & 1 rubygems

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