<commit_before>"use strict";

const findAtRuleContext = require("../../utils/findAtRuleContext");
const nodeContextLookup = require("../../utils/nodeContextLookup");
const report = require("../../utils/report");
const ruleMessages = require("../../utils/ruleMessages");
const validateOptions = require("../../utils/validateOptions");
const _ = require("lodash");
const normalizeSelector = require("normalize-selector");
const resolvedNestedSelector = require("postcss-resolve-nested-selector");
const utils = require('../../utils');

const ruleName = utils.namespace('file-name-match');

const messages = ruleMessages(ruleName, {
  rejected: (selector, fileName) => `Need to move "${selector}" to "${fileName}"`,
});

const rule = function (actual) {
  const optionIgnoreIndexOfMatch = [].concat(actual.ignoreIndexOfMatch);
  const optionIgnoreStrictEquality = [].concat(actual.ignoreStrictEquality);

  return (root, result) => {
    const validOptions = validateOptions(result, ruleName, {
      actual: optionIgnoreIndexOfMatch,
      possible: [_.isString]
    })

    if (!validOptions) {
      return
    }

    // The top level of this map will be rule sources.
    // Each source maps to another map, which maps rule parents to a set of selectors.
    // This ensures that selectors are only checked against selectors
    // from other rules that share the same parent and the same source.
    const selectorContextLookup = nodeContextLookup();

    root.walkRules(rule => {
      const resolvedSelectors = rule.selectors.reduce((result, selector) => {
        return _.union(result, resolvedNestedSelector(selector, rule))
      }, []);
      const normalizedSelectorList = resolvedSelectors.map(normalizeSelector);
      const selectorLine = rule.source.start.line

      const ruleSourceInputFrom = rule.source.input.from;
      const ruleSourceInputFromFileName = ruleSourceInputFrom.split('/').pop();
      const selectorAndFileNameMap = {
        'hr': {
          'regex': 'scaffolding',
          'correctFileName': '_scaffolding.scss'
        },
        'btn': {
          'regex': 'btn',
          'correctFileName': '_btn.scss'
        },
        'breadcrumb': {
          'regex': 'breadcrumb',
          'correctFileName': '_breadcrumbs.scss'
        }
      };
      const selectorName = rule.selector.replace(/^\./, '');
  
      // Check if the "selectorAndFileNameMap" has the key selector.
      if (selectorName in selectorAndFileNameMap) {
        if (ruleSourceInputFromFileName.indexOf(selectorAndFileNameMap[selectorName]['regex']) === -1) {
          return report({
            result,
            ruleName,
            node: rule,
            message: messages.rejected(rule.selector, selectorAndFileNameMap[selectorName]['correctFileName']),
          })
        }
      }
    })
  }
}

rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;
<commit_msg>Implement linting file name & scss name<commit_after>"use strict";

const findAtRuleContext = require("../../utils/findAtRuleContext");
const nodeContextLookup = require("../../utils/nodeContextLookup");
const report = require("../../utils/report");
const ruleMessages = require("../../utils/ruleMessages");
const validateOptions = require("../../utils/validateOptions");
const _ = require("lodash");
const normalizeSelector = require("normalize-selector");
const resolvedNestedSelector = require("postcss-resolve-nested-selector");
const utils = require('../../utils');

const ruleName = utils.namespace('file-name-match');

const messages = ruleMessages(ruleName, {
  rejected: (selector, fileName) => `Move "${selector}" to "${fileName}"`
});

const rule = function (actual) {
  const optionSelectorAndFileNameMap = actual.selectorAndFileNameMap

  return (root, result) => {
    const validOptions = validateOptions(result, ruleName, {
      actual: optionSelectorAndFileNameMap,
      possible: [_.isObject]
    });

    if (!validOptions) {
      return
    }

    root.walkRules(rule => {
      const ruleSourceInputFrom = rule.source.input.from;
      const ruleSourceInputFromFileName = ruleSourceInputFrom.split('/').pop();
  
      let selectorName = rule.selector.replace(/^\./, '');
      const selectorPrefixName = selectorName.match(/^(.*?)\-.*?/);
  
      if (selectorPrefixName) {
        selectorName = selectorPrefixName[1];
      }
  
      // Check if the "optionSelectorAndFileNameMap" has the key selector.
      if (selectorName in optionSelectorAndFileNameMap) {
        if (ruleSourceInputFromFileName != optionSelectorAndFileNameMap[selectorName]) {
          return report({
            result,
            ruleName,
            node: rule,
            message: messages.rejected(rule.selector, optionSelectorAndFileNameMap[selectorName]),
          })
        }
      }
    })
  }
}

rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;

{'fraction_non_alphanumeric': 0.13536137198856676, 'fraction_numerical': 0.0004083299305839118, 'mean_word_length': 3.2160068846815837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '1660667', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1293, 'n_words': 301}