Skip to content

Commit 370793b

Browse files
committed
[eslint-config] [*] [fix] whitespace: only set erroring rules to "warn"
Fixes airbnb#2105
1 parent 2e3adc9 commit 370793b

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

packages/eslint-config-airbnb-base/whitespace.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ const { CLIEngine } = require('eslint');
44

55
const baseConfig = require('.');
66

7+
const severities = ['off', 'warn', 'error'];
8+
9+
function getSeverity(ruleConfig) {
10+
if (Array.isArray(ruleConfig)) {
11+
return getSeverity(ruleConfig[0]);
12+
}
13+
if (typeof ruleConfig === 'number') {
14+
return severities[ruleConfig];
15+
}
16+
return ruleConfig;
17+
}
18+
719
function onlyErrorOnRules(rulesToError, config) {
820
const errorsOnly = assign({}, config);
921
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
@@ -12,8 +24,9 @@ function onlyErrorOnRules(rulesToError, config) {
1224
entries(baseRules).forEach((rule) => {
1325
const ruleName = rule[0];
1426
const ruleConfig = rule[1];
27+
const severity = getSeverity(ruleConfig);
1528

16-
if (rulesToError.indexOf(ruleName) === -1) {
29+
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
1730
if (Array.isArray(ruleConfig)) {
1831
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
1932
} else if (typeof ruleConfig === 'number') {

packages/eslint-config-airbnb/whitespace.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ const { CLIEngine } = require('eslint');
44

55
const baseConfig = require('.');
66

7+
const severities = ['off', 'warn', 'error'];
8+
9+
function getSeverity(ruleConfig) {
10+
if (Array.isArray(ruleConfig)) {
11+
return getSeverity(ruleConfig[0]);
12+
}
13+
if (typeof ruleConfig === 'number') {
14+
return severities[ruleConfig];
15+
}
16+
return ruleConfig;
17+
}
18+
719
function onlyErrorOnRules(rulesToError, config) {
820
const errorsOnly = assign({}, config);
921
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
@@ -12,8 +24,9 @@ function onlyErrorOnRules(rulesToError, config) {
1224
entries(baseRules).forEach((rule) => {
1325
const ruleName = rule[0];
1426
const ruleConfig = rule[1];
27+
const severity = getSeverity(ruleConfig);
1528

16-
if (rulesToError.indexOf(ruleName) === -1) {
29+
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
1730
if (Array.isArray(ruleConfig)) {
1831
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
1932
} else if (typeof ruleConfig === 'number') {

0 commit comments

Comments
 (0)