<commit_before>// @ts-check

"use strict";

const { addErrorContext, addErrorDetailIf, forEachHeading } =
  require("../helpers");

module.exports = {
  "names": [ "MD043", "required-headings", "required-headers" ],
  "description": "Required heading structure",
  "tags": [ "headings", "headers" ],
  "function": function MD043(params, onError) {
    const requiredHeadings = params.config.headings || params.config.headers;
    if (Array.isArray(requiredHeadings)) {
      const levels = {};
      [ 1, 2, 3, 4, 5, 6 ].forEach((level) => {
        levels["h" + level] = "######".substr(-level);
      });
      let i = 0;
      let matchAny = false;
      let hasError = false;
      let anyHeadings = false;
      // eslint-disable-next-line func-style
      const getExpected = () => requiredHeadings[i++] || "[None]";
      forEachHeading(params, (heading, content) => {
        if (!hasError) {
          anyHeadings = true;
          const actual = levels[heading.tag] + " " + content;
          let expected = getExpected();
          if (expected === "*") {
            matchAny = true;
            expected = getExpected();
          } else if (expected === "+") {
            matchAny = true;
          } else if (expected.toLowerCase() === actual.toLowerCase()) {
            matchAny = false;
          } else if (matchAny) {
            i--;
          } else {
            addErrorDetailIf(onError, heading.lineNumber,
              expected, actual);
            hasError = true;
          }
        }
      });
      if (
        !hasError &&
        (i < requiredHeadings.length) &&
        (anyHeadings || !requiredHeadings.every((heading) => heading === "*"))
      ) {
        addErrorContext(onError, params.lines.length,
          requiredHeadings[i]);<commit_msg>Remove useless assignment to local variable.<commit_after>// @ts-check

"use strict";

const { addErrorContext, addErrorDetailIf, forEachHeading } =
  require("../helpers");

module.exports = {
  "names": [ "MD043", "required-headings", "required-headers" ],
  "description": "Required heading structure",
  "tags": [ "headings", "headers" ],
  "function": function MD043(params, onError) {
    const requiredHeadings = params.config.headings || params.config.headers;
    if (Array.isArray(requiredHeadings)) {
      const levels = {};
      [ 1, 2, 3, 4, 5, 6 ].forEach((level) => {
        levels["h" + level] = "######".substr(-level);
      });
      let i = 0;
      let matchAny = false;
      let hasError = false;
      let anyHeadings = false;
      // eslint-disable-next-line func-style
      const getExpected = () => requiredHeadings[i++] || "[None]";
      forEachHeading(params, (heading, content) => {
        if (!hasError) {
          anyHeadings = true;
          const actual = levels[heading.tag] + " " + content;
          const expected = getExpected();
          if (expected === "*") {
            matchAny = true;
            getExpected();
          } else if (expected === "+") {
            matchAny = true;
          } else if (expected.toLowerCase() === actual.toLowerCase()) {
            matchAny = false;
          } else if (matchAny) {
            i--;
          } else {
            addErrorDetailIf(onError, heading.lineNumber,
              expected, actual);
            hasError = true;
          }
        }
      });
      if (
        !hasError &&
        (i < requiredHeadings.length) &&
        (anyHeadings || !requiredHeadings.every((heading) => heading === "*"))
      ) {
        addErrorContext(onError, params.lines.length,
          requiredHeadings[i]);
{'fraction_non_alphanumeric': 0.1563717306622148, 'fraction_numerical': 0.007234279354479688, 'mean_word_length': 2.1397379912663754, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 11, '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': '6737303', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1025, 'n_words': 229}