3 const _ = require("lodash");
4 const rules /*: Object*/ = require("./rules");
6 // Rule settings can take a number of forms, e.g.
7 // a. "rule-name": null
8 // b. "rule-name": [null, ...]
9 // c. "rule-name": primaryOption
10 // d. "rule-name": [primaryOption]
11 // e. "rule-name": [primaryOption, secondaryOption]
12 // Where primaryOption can be anything: primitive, Object, or Array.
14 // This function normalizes all the possibilities into the
15 // standard form: [primaryOption, secondaryOption]
16 // Except in the cases with null, a & b, in which case
18 module.exports = function(
19 rawSettings /*: ?stylelint$configRuleSettings*/,
20 ruleName /*: string*/,
21 // If primaryOptionArray is not provided, we try to get it from the
22 // rules themselves, which will not work for plugins
23 primaryOptionArray /*:: ?: boolean*/
24 ) /*: [any, Object] | Array<any | [any, Object]> | null*/ {
25 if (rawSettings === null) {
29 if (!Array.isArray(rawSettings)) {
32 // Everything below is an array ...
34 if (rawSettings[0] === null) {
38 if (primaryOptionArray === undefined) {
39 const rule /*: Function*/ = rules[ruleName];
40 primaryOptionArray = _.get(rule, "primaryOptionArray");
43 if (!primaryOptionArray) {
46 // Everything below is a rule that CAN have an array for a primary option ...
47 // (they might also have something else, e.g. rule-properties-order can
48 // have the string "alphabetical")
50 if (rawSettings.length === 1 && Array.isArray(rawSettings[0])) {
55 rawSettings.length === 2 &&
56 !_.isPlainObject(rawSettings[0]) &&
57 _.isPlainObject(rawSettings[1])