<commit_before>import {
  hasBlock,
  hasEmptyBlock,
  report,
  ruleMessages,
  whitespaceChecker
} from "../../utils"

export const ruleName = "block-opening-brace-newline-after"

export const messages = ruleMessages(ruleName, {
  expectedAfter: () => `Expected newline after "{"`,
  rejectedAfter: () => `Unexpected space after "{"`,
  expectedAfterMultiLine: () => `Expected newline after "{" of a multi-line block`,
  rejectedAfterMultiLine: () => `Unexpected space after "{" of a multi-line block`,
})

/**
 * @param {"always"|"never"|"always-multi-line"|"never-multi-line"} expectation
 */
export default function (expectation) {
  const checker = whitespaceChecker("\n", expectation, messages)

  return function (css, result) {

    // Check both kinds of statement: rules and at-rules
    css.eachRule(check)
    css.eachAtRule(check)

    function check(statement) {

      // Return early if blockless or has empty block
      if (!hasBlock(statement) || hasEmptyBlock(statement)) { return }

      const firstNode = statement.first
      if (!firstNode) { return }

      // Allow an end-of-line comment one space after the brace
      const nodeToCheck = (firstNode.type === "comment" && firstNode.before === " ")
        ? firstNode.next()
        : firstNode

      // The string to check for multi-line vs single-line is the block:
      // the curly braces and everything between them
      const lineCheckStr = (statement.type === "rule")
        ? statement.toString().slice((statement.selector + statement.between).length)
        : statement.toString().slice(
            ("@" + statement.name + statement.afterName + statement.params + statement.between).length
          )

      checker.afterOneOnly(nodeToCheck.toString(), -1, m => report({
        message: m,
        node: nodeToCheck,
        result,
        ruleName,<commit_msg>block-opening-brace-newline-after ignore if no next node to check<commit_after>import {
  hasBlock,
  hasEmptyBlock,
  report,
  ruleMessages,
  whitespaceChecker
} from "../../utils"

export const ruleName = "block-opening-brace-newline-after"

export const messages = ruleMessages(ruleName, {
  expectedAfter: () => `Expected newline after "{"`,
  rejectedAfter: () => `Unexpected space after "{"`,
  expectedAfterMultiLine: () => `Expected newline after "{" of a multi-line block`,
  rejectedAfterMultiLine: () => `Unexpected space after "{" of a multi-line block`,
})

/**
 * @param {"always"|"never"|"always-multi-line"|"never-multi-line"} expectation
 */
export default function (expectation) {
  const checker = whitespaceChecker("\n", expectation, messages)

  return function (css, result) {

    // Check both kinds of statement: rules and at-rules
    css.eachRule(check)
    css.eachAtRule(check)

    function check(statement) {

      // Return early if blockless or has empty block
      if (!hasBlock(statement) || hasEmptyBlock(statement)) { return }

      const firstNode = statement.first
      if (!firstNode) { return }

      // Allow an end-of-line comment one space after the brace
      const nodeToCheck = (firstNode.type === "comment" && firstNode.before === " ")
        ? firstNode.next()
        : firstNode
      if (!nodeToCheck) { return }

      // The string to check for multi-line vs single-line is the block:
      // the curly braces and everything between them
      const lineCheckStr = (statement.type === "rule")
        ? statement.toString().slice((statement.selector + statement.between).length)
        : statement.toString().slice(
            ("@" + statement.name + statement.afterName + statement.params + statement.between).length
          )

      checker.afterOneOnly(nodeToCheck.toString(), -1, m => report({
        message: m,
        node: nodeToCheck,
        result,
        ruleName,
{'fraction_non_alphanumeric': 0.12956636005256242, 'fraction_numerical': 0.0005256241787122207, 'mean_word_length': 3.1324647122692726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6266793', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1043, 'n_words': 291}