<commit_before>import testRule from 'stylelint-test-rule-tape'

import declarationStrictValue, { ruleName } from '../src'

const { rule } = declarationStrictValue

// eslint-disable-next-line consistent-return, no-unused-vars
function autoFixFunc(node, validation, root, config) {
  const { value, prop } = node

  if (prop === 'color') {
    // eslint-disable-next-line default-case
    switch (value) {
      case '#fff':
        // auto-fix by returned value
        return '$color-white'

      case 'red':
        // auto-fix by PostCSS AST tranformation
        // eslint-disable-next-line no-param-reassign
        node.value = '$color-red'
    }
  }
}

// autofix by function property
testRule(rule, {
  ruleName,
  skipBasicChecks: true,
  fix: true,

  config: ['color', {
    autoFixFunc,
  }],

  reject: [
    {
      code: '.foo { color: #fff; }',
      fixed: '.foo { color: $color-white; }',
      message: `Expected variable or function for "#fff" of "color" (${ruleName})`,
      line: 1,
      column: 8,
    },
    {
      code: '.foo { color: red; }',
      fixed: '.foo { color: $color-red; }',
      message: `Expected variable or function for "red" of "color" (${ruleName})`,
      line: 1,
      column: 8,
    },
  ],
})

// autofix by file exporting function
testRule(rule, {
  ruleName,
  skipBasicChecks: true,
  fix: true,

  config: ['color', {
    autoFixFunc: './test/helpers/auto-fix-func.js',
  }],

  reject: [
    {
      code: '.foo { color: #fff; }',
      fixed: '.foo { color: $color-white; }',
      message: `Expected variable or function for "#fff" of "color" (${ruleName})`,
      line: 1,
      column: 8,
    },
    {
      code: '.foo { color: red; }',
      fixed: '.foo { color: $color-red; }',
      message: `Expected variable or function for "red" of "color" (${ruleName})`,
      line: 1,
      column: 8,
    },
  ],
})<commit_msg>test: fix auto-fix coverage<commit_after>import testRule from 'stylelint-test-rule-tape'

import declarationStrictValue, { ruleName } from '../src'
import autoFixFunc from './helpers/auto-fix-func'

const { rule } = declarationStrictValue

const ruleWithContext = (context) => (properties, options) => rule(properties, options, context)

// autofix by function property
testRule(ruleWithContext({
  fix: true,
}), {
  ruleName,
  skipBasicChecks: true,

  config: ['color', {
    autoFixFunc,
  }],

  accept: [
    { code: '.foo { color: #fff; }' },
    { code: '.foo { color: red; }' },
  ],
})

// autofix by function property disabled
testRule(ruleWithContext({
  fix: true,
}), {
  ruleName,
  skipBasicChecks: true,

  config: ['color', {
    autoFixFunc,
    disableFix: true,
  }],

  reject: [
    {
      code: '.foo { color: #fff; }',
      fixed: '.foo { color: $color-white; }',
      message: `Expected variable or function for "#fff" of "color" (${ruleName})`,
      line: 1,
      column: 8,
    },
    {
      code: '.foo { color: red; }',
      fixed: '.foo { color: $color-red; }',
      message: `Expected variable or function for "red" of "color" (${ruleName})`,
      line: 1,
      column: 8,
    },
  ],
})

// autofix by file exporting function
testRule(ruleWithContext({
  fix: true,
}), {
  ruleName,
  skipBasicChecks: true,

  config: ['color', {
    autoFixFunc: './test/helpers/auto-fix-func.js',
  }],

  accept: [
    { code: '.foo { color: #fff; }' },
    { code: '.foo { color: red; }' },
  ],
})

// autofix by file exporting function disabled
testRule(ruleWithContext({
  fix: true,
}), {
  ruleName,
  skipBasicChecks: true,

  config: ['color', {
    autoFixFunc: './test/helpers/auto-fix-func.js',
    disableFix: true,
  }],

  reject: [
    {
      code: '.foo { color: #fff; }',
      fixed: '.foo { color: $color-white; }',
      message: `Expected variable or function for "#fff" of "color" (${ruleName})`,
      line: 1,
      column: 8,
    },
    {
      code: '.foo { color: red; }',
      fixed: '.foo { color: $color-red; }',
      message: `Expected variable or function for "red" of "color" (${ruleName})`,
      line: 1,
      column: 8,
    },
  ],
})
{'fraction_non_alphanumeric': 0.17350928641251223, 'fraction_numerical': 0.0039100684261974585, 'mean_word_length': 2.577797202797203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6849013', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1391, 'n_words': 365}