Skip to content

Commit 0733cc5

Browse files
authored
Fix code style (#570)
1 parent ab17a3c commit 0733cc5

10 files changed

+40
-28
lines changed

index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import {ESLint} from 'eslint';
33
import globby from 'globby';
44
import {isEqual} from 'lodash-es';
@@ -169,11 +169,13 @@ const getFormatter = async name => {
169169
return format;
170170
};
171171

172-
export default {
172+
const xo = {
173173
getFormatter,
174174
getErrorResults: ESLint.getErrorResults,
175175
outputFixes: async ({results}) => ESLint.outputFixes(results),
176176
getConfig,
177177
lintText,
178178
lintFiles,
179179
};
180+
181+
export default xo;

lib/open-report.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use strict';
21
import openEditor from 'open-editor';
32

43
const sortResults = (a, b) => a.errorCount + b.errorCount > 0 ? (a.errorCount - b.errorCount) : (a.warningCount - b.warningCount);
@@ -37,8 +36,10 @@ const getFiles = (report, predicate) => report.results
3736
.sort(sortResults)
3837
.map(result => resultToFile(result));
3938

40-
export default report => {
39+
const openReport = report => {
4140
const count = report.errorCount > 0 ? 'errorCount' : 'warningCount';
4241
const files = getFiles(report, result => result[count] > 0);
4342
openEditor(files);
4443
};
44+
45+
export default openReport;

lib/options-manager.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use strict';
2-
import os from 'os';
3-
import path from 'path';
1+
import os from 'node:os';
2+
import path from 'node:path';
43
import fsExtra from 'fs-extra';
54
import arrify from 'arrify';
65
import {mergeWith, groupBy, flow, pick} from 'lodash-es';
@@ -43,7 +42,7 @@ const resolveFrom = (moduleId, fromDirectory = process.cwd()) => resolveModule(m
4342
resolveFrom.silent = (moduleId, fromDirectory) => {
4443
try {
4544
return resolveFrom(moduleId, fromDirectory);
46-
} catch { }
45+
} catch {}
4746
};
4847

4948
const resolveLocalConfig = name => resolveModule(normalizePackageName(name, 'eslint-config'), import.meta.url);
@@ -92,7 +91,7 @@ const getEmptyXOConfig = () => ({
9291
const mergeFn = (previousValue, value, key) => {
9392
if (Array.isArray(previousValue)) {
9493
if (MERGE_OPTIONS_CONCAT.includes(key)) {
95-
return previousValue.concat(value);
94+
return [...previousValue, ...value];
9695
}
9796

9897
return value;
@@ -186,7 +185,7 @@ const mergeWithFileConfigs = async (files, options, configFiles) => {
186185

187186
await Promise.all(Object.entries(groupBy(groups.filter(({options}) => Boolean(options.ts)), group => group.options.tsConfigPath || '')).map(
188187
([tsConfigPath, groups]) => {
189-
const files = [].concat(...groups.map(group => group.files));
188+
const files = groups.flatMap(group => group.files);
190189
const cachePath = getTsConfigCachePath(files, tsConfigPath);
191190

192191
for (const group of groups) {
@@ -386,7 +385,7 @@ const buildXOConfig = options => config => {
386385

387386
// Only apply if the user has the React plugin
388387
if (options.cwd && resolveFrom.silent('eslint-plugin-react', options.cwd)) {
389-
config.baseConfig.plugins = config.baseConfig.plugins.concat('react');
388+
config.baseConfig.plugins.push('react');
390389
config.baseConfig.rules['react/jsx-indent-props'] = ['error', spaces];
391390
config.baseConfig.rules['react/jsx-indent'] = ['error', spaces];
392391
}
@@ -452,10 +451,10 @@ const buildExtendsConfig = options => config => {
452451
const buildPrettierConfig = (options, prettierConfig) => config => {
453452
if (options.prettier) {
454453
// The prettier plugin uses Prettier to format the code with `--fix`
455-
config.baseConfig.plugins = config.baseConfig.plugins.concat('prettier');
454+
config.baseConfig.plugins.push('prettier');
456455

457456
// The prettier config overrides ESLint stylistic rules that are handled by Prettier
458-
config.baseConfig.extends = config.baseConfig.extends.concat('prettier');
457+
config.baseConfig.extends.push('prettier');
459458

460459
// The `prettier/prettier` rule reports errors if the code is not formatted in accordance to Prettier
461460
config.baseConfig.rules['prettier/prettier'] = ['error', mergeWithPrettierConfig(options, prettierConfig)];
@@ -464,7 +463,7 @@ const buildPrettierConfig = (options, prettierConfig) => config => {
464463
// See https://github.com/prettier/eslint-config-prettier for the list of plugins overrrides
465464
for (const [plugin, prettierConfig] of Object.entries(PRETTIER_CONFIG_OVERRIDE)) {
466465
if (options.cwd && resolveFrom.silent(plugin, options.cwd)) {
467-
config.baseConfig.extends = config.baseConfig.extends.concat(prettierConfig);
466+
config.baseConfig.extends.push(prettierConfig);
468467
}
469468
}
470469
}
@@ -505,7 +504,7 @@ const mergeWithPrettierConfig = (options, prettierOptions) => {
505504

506505
const buildTSConfig = options => config => {
507506
if (options.ts) {
508-
config.baseConfig.extends = config.baseConfig.extends.concat('xo-typescript');
507+
config.baseConfig.extends.push('xo-typescript');
509508
config.baseConfig.parser = require.resolve('@typescript-eslint/parser');
510509
config.baseConfig.parserOptions = {
511510
...config.baseConfig.parserOptions,
@@ -532,7 +531,7 @@ const applyOverrides = (file, options) => {
532531

533532
const {applicable, hash} = findApplicableOverrides(path.relative(options.cwd, file), overrides);
534533

535-
options = mergeWith(...[getEmptyXOConfig(), options].concat(applicable.map(override => normalizeOptions(override)), mergeFn));
534+
options = mergeWith(getEmptyXOConfig(), options, ...applicable.map(override => normalizeOptions(override)), mergeFn);
536535
delete options.files;
537536
return {options, hash};
538537
}

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@
109109
"webpack": "^5.41.1"
110110
},
111111
"eslintConfig": {
112-
"extends": "eslint-config-xo"
112+
"extends": [
113+
"eslint-config-xo",
114+
"./config/plugins.cjs",
115+
"./config/overrides.cjs"
116+
]
113117
},
114118
"eslintIgnore": [
115-
"test/fixtures"
119+
"test/fixtures",
120+
"coverage"
116121
],
117122
"ava": {
118123
"timeout": "1m"

test/cli.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs from 'fs';
2-
import path from 'path';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
33
import test from 'ava';
44
import execa from 'execa';
55
import slash from 'slash';

test/lint-files.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import test from 'ava';
33
import createEsmUtils from 'esm-utils';
44
import xo from '../index.js';
@@ -200,6 +200,7 @@ test('typescript files', async t => {
200200

201201
test('typescript 2 space option', async t => {
202202
const {errorCount, results} = await xo.lintFiles('two-spaces.tsx', {cwd: 'fixtures/typescript', space: 2});
203+
// eslint-disable-next-line ava/assertion-arguments
203204
t.is(errorCount, 0, JSON.stringify(results[0].messages));
204205
});
205206

@@ -222,6 +223,7 @@ test('webpack import resolver is used if webpack.config.js is found', async t =>
222223
},
223224
});
224225

226+
// eslint-disable-next-line ava/assertion-arguments
225227
t.is(results[0].errorCount, 1, JSON.stringify(results[0].messages));
226228

227229
const errorMessage = results[0].messages[0].message;
@@ -247,6 +249,7 @@ test('webpack import resolver config can be passed through webpack option', asyn
247249
},
248250
});
249251

252+
// eslint-disable-next-line ava/assertion-arguments
250253
t.is(results[0].errorCount, 1, JSON.stringify(results[0].messages));
251254
});
252255

@@ -262,6 +265,7 @@ test('webpack import resolver is used if {webpack: true}', async t => {
262265
},
263266
});
264267

268+
// eslint-disable-next-line ava/assertion-arguments
265269
t.is(results[0].errorCount, 0, JSON.stringify(results[0]));
266270
});
267271

test/lint-text.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {promises as fs} from 'fs';
2-
import path from 'path';
1+
import {promises as fs} from 'node:fs';
2+
import path from 'node:path';
33
import test from 'ava';
44
import createEsmUtils from 'esm-utils';
55
import xo from '../index.js';

test/open-report.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import path from 'path';
1+
/* eslint-disable ava/no-skip-test */
2+
import path from 'node:path';
23
import test from 'ava';
34
import proxyquire from 'proxyquire';
45
import createEsmUtils from 'esm-utils';
@@ -13,7 +14,7 @@ test.skip('opens nothing when there are no errors nor warnings', async t => {
1314

1415
const openReport = proxyquire('../lib/open-report', {
1516
'open-editor': files => {
16-
if (files.length !== 0) {
17+
if (files.length > 0) {
1718
t.fail();
1819
}
1920
},

test/options-manager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import test from 'ava';
33
import {omit} from 'lodash-es';
44
import fsExtra from 'fs-extra';
@@ -429,7 +429,7 @@ test('buildConfig: extends', t => {
429429
test('buildConfig: typescript', t => {
430430
const config = manager.buildConfig({ts: true, tsConfigPath: './tsconfig.json'});
431431

432-
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'xo-typescript');
432+
t.is(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'xo-typescript');
433433
t.is(config.baseConfig.parser, require.resolve('@typescript-eslint/parser'));
434434
t.deepEqual(config.baseConfig.parserOptions, {
435435
warnOnUnsupportedTypeScriptVersion: false,

test/print-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import test from 'ava';
33
import execa from 'execa';
44
import tempWrite from 'temp-write';

0 commit comments

Comments
 (0)