<commit_before>var _ = require('lodash');
var languageMapping = require('gherkin/lib/gherkin/gherkin-languages.json');
var rule = 'indentation';

var availableConfigs = {
  'Feature': 0,
  'Background': 0,
  'Scenario': 0,
  'Step': 2,
  'given': 2,
  'when': 2,
  'then': 2,
  'and': 2,
  'but': 2
};

var errors = [];

function test(parsedLocation, config, type) {
    // location.column is 1 index based so, when we compare with the expected indentation we need to subtract 1
  if (--parsedLocation.column !== config[type]) {
    errors.push({message: 'Wrong indentation for "' + type + '", expected indentation level of ' + config[type] + ', but got ' + parsedLocation.column,
                 rule   : rule,
                 line   : parsedLocation.line});
  }
}

function indentation(parsedFile, unused, configuration) {
  var language = languageMapping[parsedFile.language];
  var mergedConfiguration = _.merge(availableConfigs, configuration);
  errors = [];

  // Check Feature indentation
  test(parsedFile.location, mergedConfiguration, 'Feature');

  if (parsedFile.background) {
    // Check Background indentation
    test(parsedFile.background.location, mergedConfiguration, 'Background');

    // Check Background steps
    parsedFile.background.steps.forEach(function(step) {
      test(step.location, mergedConfiguration, 'Step');
    });
  }

  parsedFile.scenarioDefinitions.forEach(function(scenario) {
    // Check Scenario indentation
    test(scenario.location, mergedConfiguration, 'Scenario');
    scenario.steps.forEach(function(step) {
      // Check Step indentation
      var keyword = step.keyword;
      var stepType = _.findKey(language, function(values) { return values instanceof Array && values.indexOf(keyword) !== -1; });
      stepType = stepType in configuration ? stepType : 'Step';
      test(step.location, mergedConfiguration, stepType);
    });
  });

  return errors;
}

module.exports = {
  name: rule,
  run: indentation,
  availableConfigs: availableConfigs
};<commit_msg>Fixing a bug where the indentation config for a specific step type wasn't respected<commit_after>var _ = require('lodash');
var languageMapping = require('gherkin/lib/gherkin/gherkin-languages.json');
var rule = 'indentation';

var availableConfigs = {
  'Feature': 0,
  'Background': 0,
  'Scenario': 0,
  'Step': 2,
  'given': 2,
  'when': 2,
  'then': 2,
  'and': 2,
  'but': 2
};

var errors = [];

function test(parsedLocation, configuration, type) {
    // location.column is 1 index based so, when we compare with the expected indentation we need to subtract 1
  if (--parsedLocation.column !== configuration[type]) {
    errors.push({message: 'Wrong indentation for "' + type + '", expected indentation level of ' + configuration[type] + ', but got ' + parsedLocation.column,
                 rule   : rule,
                 line   : parsedLocation.line});
  }
}

function testStep(step, language, configuration, mergedConfiguration) {
  var keyword = step.keyword;
  var stepType = _.findKey(language, function(values) { return values instanceof Array && values.indexOf(keyword) !== -1; });
  stepType = stepType in configuration ? stepType : 'Step';
  test(step.location, mergedConfiguration, stepType);
}

function indentation(parsedFile, unused, configuration) {
  var language = languageMapping[parsedFile.language];
  var mergedConfiguration = _.merge(availableConfigs, configuration);
  errors = [];

  // Check Feature indentation
  test(parsedFile.location, mergedConfiguration, 'Feature');

  if (parsedFile.background) {
    // Check Background indentation
    test(parsedFile.background.location, mergedConfiguration, 'Background');

    // Check Background steps
    parsedFile.background.steps.forEach(function(step) {
      testStep(step, language, configuration, mergedConfiguration);
    });
  }

  parsedFile.scenarioDefinitions.forEach(function(scenario) {
    // Check Scenario indentation
    test(scenario.location, mergedConfiguration, 'Scenario');
    scenario.steps.forEach(function(step) {
      // Check Step indentation
      testStep(step, language, configuration, mergedConfiguration);
    });
  });

  return errors;
}

module.exports = {
  name: rule,
  run: indentation,
  availableConfigs: availableConfigs
};
{'fraction_non_alphanumeric': 0.1254681647940075, 'fraction_numerical': 0.0056179775280898875, 'mean_word_length': 3.9341801385681294, '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': '1747041', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1204, 'n_words': 317}