{"size": 3063, "ext": "js", "max_stars_repo_path": "src/__tests__/normalizeRuleSettings-test.js", "max_stars_repo_name": "ellerbrock/stylelint", "max_stars_repo_stars_event_min_datetime": "2019-04-15T16:27:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-15T16:27:19.000Z", "max_issues_repo_path": "src/__tests__/normalizeRuleSettings-test.js", "max_issues_repo_name": "ellerbrock/stylelint", "max_issues_repo_issues_event_min_datetime": "2016-11-24T01:06:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-02T23:46:59.000Z", "max_forks_repo_path": "src/__tests__/normalizeRuleSettings-test.js", "max_forks_repo_name": "ellerbrock/stylelint", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 40, "max_forks_count": null, "avg_line_length": 40.3026315789, "max_line_length": 129, "alphanum_fraction": 0.6460985961}
import normalizeRuleSettings from "../normalizeRuleSettings"
import test from "tape"

test("rules whose primary option IS NOT an array", t => {
  t.equal(normalizeRuleSettings(null, "foo"), null,
    "solo null returns null")
  t.equal(normalizeRuleSettings([null], "foo"), null,
    "arrayed null returns null")
  t.deepEqual(normalizeRuleSettings(2, "foo"), [2],
    "solo number returns arrayed number")
  t.deepEqual(normalizeRuleSettings([2], "foo"), [2],
    "arrayed number returns arrayed number if rule is not special")
  t.deepEqual(
    normalizeRuleSettings([ 2, { "severity": "warning" } ]),
    [ 2, { "severity": "warning" } ],
    "arrayed number with secondary options returns same"
  )
  t.deepEqual(normalizeRuleSettings("always", "foo"), ["always"],
    "solo string returns arrayed string")
  t.deepEqual(normalizeRuleSettings(["always"], "foo"), ["always"],
    "arrayed string returns arrayed string")
  t.deepEqual(
    normalizeRuleSettings([ "always", { "severity": "warning" } ], "foo"),
    [ "always", { "severity": "warning" } ],
    "arrayed string with secondary options returns same"
  )
  t.deepEqual(normalizeRuleSettings(true, "foo"), [true],
    "solo boolean returns arrayed boolean")
  t.deepEqual(normalizeRuleSettings([false], "foo"), [false],
    "arrayed boolean returns arrayed boolean if rule is not special")
  t.deepEqual(
    normalizeRuleSettings([ true, { "severity": "warning" } ]),
    [ true, { "severity": "warning" } ],
    "arrayed boolean with secondary options returns same"
  )
  t.end()
})

test("rules whose primary option CAN BE an array", t => {
  t.equal(normalizeRuleSettings(null, "foo"), null,
    "solo null returns null")
  t.equal(normalizeRuleSettings([null], "foo"), null,
    "arrayed null returns null")
  t.deepEqual(
    normalizeRuleSettings([ "calc", "rgba" ], "function-whitelist", true),
    [[ "calc", "rgba" ]],
    "solo primary option array is nested within an array"
  )
  t.deepEqual(
    normalizeRuleSettings([[ "calc", "rgba" ]], "function-whitelist", true),
    [[ "calc", "rgba" ]],
    "primary option array in an array"
  )
  t.deepEqual(
    normalizeRuleSettings([ [ "calc", "rgba" ], { "severity": "warning" } ], "function-whitelist", true),
    [ [ "calc", "rgba" ], { "severity": "warning" } ],
    "nested primary option array returns same"
  )
  t.deepEqual(
    normalizeRuleSettings([ "alphabetical", { "severity": "warning" } ], "declaration-block-properties-order"),
    [ "alphabetical", { "severity": "warning" } ],
    "string as first primary option returns same"
  )
  t.deepEqual(
    normalizeRuleSettings([ { foo: 1 }, { foo: 2 } ], "declaration-block-properties-order", true),
    [[ { foo: 1 }, { foo: 2 } ]],
    "primary option array with length of 2"
  )
  t.deepEqual(
    normalizeRuleSettings([ [ { foo: 1 }, { foo: 2 } ], { "severity": "warning" } ], "declaration-block-properties-order", true),
    [ [ { foo: 1 }, { foo: 2 } ], { "severity": "warning" } ],
    "primary option array with length of 2 and secondary options"
  )
  t.end()
})
