<commit_before>import { isRegExp, isString } from "lodash"
import { utils } from "stylelint"
import { namespace } from "../../utils"
import nodeJsPath from "path"

export const ruleName = namespace("at-import-no-partial-extension")

export const messages = utils.ruleMessages(ruleName, {
  expected: "Unexpected file extension in imported partial name",
})

export default function (on, options) {
  return (root, result) => {
    const validOptions = utils.validateOptions(result, ruleName, {
      actual: on,
    }, {
      actual: options,
      possible: {
        // Accepting array of either strings or regular expressions
        ignoreExtensions: str => isRegExp(str) || isString(str),
      },
      optional: true,
    })
    if (!validOptions) { return }

    function checkPathForUnderscore(path, decl) {
      // Stripping trailing quotes and whitespaces, if any
      const pathStripped = path.replace(/^\s*?("|')\s*/, "").replace(/\s*("|')\s*?$/, "")
      const extension = nodeJsPath.extname(pathStripped).slice(1)

      // If the extension is not empty
      if (!extension) { return }

      // Skipping importing CSS: url(), ".css", URI with a protocol, media
      if (pathStripped.slice(0, 4) === "url(" ||
        pathStripped.slice(-4) === ".css" ||
        pathStripped.search("//") !== -1 ||
        pathStripped.search(/(?:\s|[,)"'])\w+$/) !== -1
      ) {
        return
      }

      if (options && options.ignoreExtensions) {
        // Return if...
        if (options.ignoreExtensions.some(ignoredExt => {
          // the extension matches on of the ignored strings or Regexps
          return isString(ignoredExt) && ignoredExt === extension ||
            isRegExp(ignoredExt) && extension.search(ignoredExt) !== -1
        })) { return }
      }

      utils.report({
        message: messages.expected,
        node: decl,
        result,
        ruleName,
      })
    }

    root.walkAtRules("import", decl => {
      // Processing comma-separated lists of import paths
      decl.params.split(",").forEach(path => {
        checkPathForUnderscore(path, decl)
      })
    })
  }
}<commit_msg>at-import-no-partial-extension: minor cosmetic fixes<commit_after>import { isRegExp, isString } from "lodash"
import { utils } from "stylelint"
import { namespace } from "../../utils"
import nodeJsPath from "path"

export const ruleName = namespace("at-import-no-partial-extension")

export const messages = utils.ruleMessages(ruleName, {
  expected: "Unexpected file extension in imported partial name",
})

export default function (on, options) {
  return (root, result) => {
    const validOptions = utils.validateOptions(result, ruleName, {
      actual: on,
    }, {
      actual: options,
      possible: {
        // Accepting array of either strings or regular expressions
        ignoreExtensions: str => isRegExp(str) || isString(str),
      },
      optional: true,
    })
    if (!validOptions) { return }

    function checkPathForUnderscore(path, decl) {
      // Stripping trailing quotes and whitespaces, if any
      const pathStripped = path.replace(/^\s*?("|')\s*/, "").replace(/\s*("|')\s*?$/, "")
      const extension = nodeJsPath.extname(pathStripped).slice(1)

      // If the extension is not empty
      if (!extension) { return }

      // Skipping importing CSS: url(), ".css", URI with a protocol, media
      if (pathStripped.slice(0, 4) === "url(" ||
        pathStripped.slice(-4) === ".css" ||
        pathStripped.search("//") !== -1 ||
        pathStripped.search(/(?:\s|[,)"'])\w+$/) !== -1
      ) {
        return
      }

      if (options && options.ignoreExtensions) {
        // Return if...
        if (options.ignoreExtensions.some(ignoredExt => {
          // the extension matches one of the ignored strings or Regexps
          return isString(ignoredExt) && ignoredExt === extension ||
            isRegExp(ignoredExt) && extension.search(ignoredExt) !== -1
        })) { return }
      }

      utils.report({
        message: messages.expected,
        node: decl,
        result,
        ruleName,
      })
    }

    root.walkAtRules("import", atRule => {
      // Processing comma-separated lists of import paths
      atRule.params.split(",").forEach(path => {
        checkPathForUnderscore(path, atRule)
      })
    })
  }
}
{'fraction_non_alphanumeric': 0.1489805375347544, 'fraction_numerical': 0.003243744207599629, 'mean_word_length': 2.5097560975609756, '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': '6534430', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1250, 'n_words': 317}