Skip to content

Commit

Permalink
[eslint config] [*] [robustness] cache static builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 28, 2024
1 parent 0681a43 commit 51a37d0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions packages/eslint-config-airbnb-base/whitespace-async.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

const { isArray } = Array;
const { entries } = Object;
const { ESLint } = require('eslint');

const baseConfig = require('.');
Expand All @@ -8,7 +10,7 @@ const whitespaceRules = require('./whitespaceRules');
const severities = ['off', 'warn', 'error'];

function getSeverity(ruleConfig) {
if (Array.isArray(ruleConfig)) {
if (isArray(ruleConfig)) {
return getSeverity(ruleConfig[0]);
}
if (typeof ruleConfig === 'number') {
Expand All @@ -25,13 +27,13 @@ async function onlyErrorOnRules(rulesToError, config) {
});
const baseRules = (await cli.calculateConfigForFile(require.resolve('./'))).rules;

Object.entries(baseRules).forEach((rule) => {
entries(baseRules).forEach((rule) => {
const ruleName = rule[0];
const ruleConfig = rule[1];
const severity = getSeverity(ruleConfig);

if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
if (Array.isArray(ruleConfig)) {
if (isArray(ruleConfig)) {
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
} else if (typeof ruleConfig === 'number') {
errorsOnly.rules[ruleName] = 1;
Expand Down
8 changes: 5 additions & 3 deletions packages/eslint-config-airbnb-base/whitespace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint global-require: 0 */

const { isArray } = Array;
const { entries } = Object;
const { CLIEngine } = require('eslint');

if (CLIEngine) {
Expand All @@ -11,7 +13,7 @@ if (CLIEngine) {
const severities = ['off', 'warn', 'error'];

function getSeverity(ruleConfig) {
if (Array.isArray(ruleConfig)) {
if (isArray(ruleConfig)) {
return getSeverity(ruleConfig[0]);
}
if (typeof ruleConfig === 'number') {
Expand All @@ -25,13 +27,13 @@ if (CLIEngine) {
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
const baseRules = cli.getConfigForFile(require.resolve('./')).rules;

Object.entries(baseRules).forEach((rule) => {
entries(baseRules).forEach((rule) => {
const ruleName = rule[0];
const ruleConfig = rule[1];
const severity = getSeverity(ruleConfig);

if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
if (Array.isArray(ruleConfig)) {
if (isArray(ruleConfig)) {
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
} else if (typeof ruleConfig === 'number') {
errorsOnly.rules[ruleName] = 1;
Expand Down
8 changes: 5 additions & 3 deletions packages/eslint-config-airbnb/whitespace-async.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

const { isArray } = Array;
const { entries } = Object;
const { ESLint } = require('eslint');

const baseConfig = require('.');
Expand All @@ -8,7 +10,7 @@ const whitespaceRules = require('./whitespaceRules');
const severities = ['off', 'warn', 'error'];

function getSeverity(ruleConfig) {
if (Array.isArray(ruleConfig)) {
if (isArray(ruleConfig)) {
return getSeverity(ruleConfig[0]);
}
if (typeof ruleConfig === 'number') {
Expand All @@ -25,13 +27,13 @@ async function onlyErrorOnRules(rulesToError, config) {
});
const baseRules = (await cli.calculateConfigForFile(require.resolve('./'))).rules;

Object.entries(baseRules).forEach((rule) => {
entries(baseRules).forEach((rule) => {
const ruleName = rule[0];
const ruleConfig = rule[1];
const severity = getSeverity(ruleConfig);

if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
if (Array.isArray(ruleConfig)) {
if (isArray(ruleConfig)) {
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
} else if (typeof ruleConfig === 'number') {
errorsOnly.rules[ruleName] = 1;
Expand Down
8 changes: 5 additions & 3 deletions packages/eslint-config-airbnb/whitespace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint global-require: 0 */

const { isArray } = Array;
const { entries } = Object;
const { CLIEngine } = require('eslint');

if (CLIEngine) {
Expand All @@ -11,7 +13,7 @@ if (CLIEngine) {
const severities = ['off', 'warn', 'error'];

function getSeverity(ruleConfig) {
if (Array.isArray(ruleConfig)) {
if (isArray(ruleConfig)) {
return getSeverity(ruleConfig[0]);
}
if (typeof ruleConfig === 'number') {
Expand All @@ -25,13 +27,13 @@ if (CLIEngine) {
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
const baseRules = cli.getConfigForFile(require.resolve('./')).rules;

Object.entries(baseRules).forEach((rule) => {
entries(baseRules).forEach((rule) => {
const ruleName = rule[0];
const ruleConfig = rule[1];
const severity = getSeverity(ruleConfig);

if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
if (Array.isArray(ruleConfig)) {
if (isArray(ruleConfig)) {
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
} else if (typeof ruleConfig === 'number') {
errorsOnly.rules[ruleName] = 1;
Expand Down

0 comments on commit 51a37d0

Please sign in to comment.