<commit_before>// Note that this file is nearly identical to function-name-format.js, variable-name-format.js, and placeholder-name-format.js
'use strict';

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

module.exports = {
  'name': 'mixin-name-format',
  'defaults': {
    'allow-leading-underscore': true,
    'convention': 'hyphenatedlowercase'
  },
  'detect': function (ast, parser) {
    var result = [];

    ast.traverseByTypes(['mixin', 'include'], function (node) {
      var name;

      if (node.type === 'mixin') {
        name = node.first('ident').content;
      }
      else {
        name = node.first('simpleSelector').first('ident').content;
      }

      var originalName = name;

      if (parser.options['allow-leading-underscore'] && name[0] === '_') {
        name = name.slice(1);
      }

      if (parser.options.convention === 'hyphenatedlowercase' && !helpers.isHyphenatedLowercase(name)) {
        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Mixin \'' + originalName + '\' should be written in lowercase with hyphens',
          'severity': parser.severity
        });
      }
      else if (parser.options.convention === 'camelcase' && !helpers.isCamelCase(name)) {
        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Mixin \'' + originalName + '\' should be written in camelCase',
          'severity': parser.severity
        });
      }
      else if (parser.options.convention === 'snakecase' && !helpers.isSnakeCase(name)) {
        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Mixin \'' + originalName + '\' should be written in snake_case',
          'severity': parser.severity
        });
      }
      else if (parser.options.convention instanceof RegExp && !parser.options.convention.test(name)) {
        var message = parser.options['convention-explanation'];

        if (!message) {
          message = 'should match regular expression /' + parser.options.convention.source + '/' +
                    (parser.options.convention.ignoreCase ? 'i' : '');
        }

        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Mixin \'' + originalName + '\' ' + message,
          'severity': parser.severity
        });
      }
    });

    return result;
  }
};<commit_msg>Declare variables at top of scope<commit_after>// Note that this file is nearly identical to function-name-format.js, variable-name-format.js, and placeholder-name-format.js
'use strict';

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

module.exports = {
  'name': 'mixin-name-format',
  'defaults': {
    'allow-leading-underscore': true,
    'convention': 'hyphenatedlowercase'
  },
  'detect': function (ast, parser) {
    var result = [];

    ast.traverseByTypes(['mixin', 'include'], function (node) {
      var name,
          strippedName;

      if (node.type === 'mixin') {
        name = node.first('ident').content;
      }
      else {
        name = node.first('simpleSelector').first('ident').content;
      }

      strippedName = name;

      if (parser.options['allow-leading-underscore'] && name[0] === '_') {
        strippedName = name.slice(1);
      }

      if (parser.options.convention === 'hyphenatedlowercase' && !helpers.isHyphenatedLowercase(strippedName)) {
        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Mixin \'' + name + '\' should be written in lowercase with hyphens',
          'severity': parser.severity
        });
      }
      else if (parser.options.convention === 'camelcase' && !helpers.isCamelCase(strippedName)) {
        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Mixin \'' + name + '\' should be written in camelCase',
          'severity': parser.severity
        });
      }
      else if (parser.options.convention === 'snakecase' && !helpers.isSnakeCase(strippedName)) {
        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Mixin \'' + name + '\' should be written in snake_case',
          'severity': parser.severity
        });
      }
      else if (parser.options.convention instanceof RegExp && !parser.options.convention.test(strippedName)) {
        var message = parser.options['convention-explanation'];

        if (!message) {
          message = 'should match regular expression /' + parser.options.convention.source + '/' +
                    (parser.options.convention.ignoreCase ? 'i' : '');
        }

        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Mixin \'' + name + '\' ' + message,
          'severity': parser.severity
        });
      }
    });

    return result;
  }
};
{'fraction_non_alphanumeric': 0.15678741309915845, 'fraction_numerical': 0.0007317965605561653, 'mean_word_length': 2.3133333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4307827', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1620, 'n_words': 323}