UNPKG

890 BJavaScriptView Raw
1/**
2 * Copyright 2013-2015, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 */
9
10'use strict';
11
12function isOff(rule) {
13 return rule === 0 || rule === 'off';
14}
15
16function changeErrorLevel(config, level) {
17 // Clone the config so we don't mutate.
18 config = JSON.parse(JSON.stringify(config))
19
20 Object.keys(config.rules).forEach((rule) => {
21 let val = config.rules[rule];
22 if (Array.isArray(val)) {
23 if (isOff(val[0])) {
24 return;
25 }
26 val[0] = level;
27 config.rules[rule] = level;
28 return;
29 }
30 if (isOff(val)) {
31 return;
32 }
33 config.rules[rule] = level;
34 });
35
36 return config;
37}
38
39module.exports = changeErrorLevel;