diff --git a/index.js b/index.js index ce203bf3..594497c3 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -import path from 'path'; +import path from 'node:path'; import {ESLint} from 'eslint'; import globby from 'globby'; import {isEqual} from 'lodash-es'; @@ -169,7 +169,7 @@ const getFormatter = async name => { return format; }; -export default { +const xo = { getFormatter, getErrorResults: ESLint.getErrorResults, outputFixes: async ({results}) => ESLint.outputFixes(results), @@ -177,3 +177,5 @@ export default { lintText, lintFiles, }; + +export default xo; diff --git a/lib/open-report.js b/lib/open-report.js index 6ce16cb6..02870b0e 100644 --- a/lib/open-report.js +++ b/lib/open-report.js @@ -1,4 +1,3 @@ -'use strict'; import openEditor from 'open-editor'; 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 .sort(sortResults) .map(result => resultToFile(result)); -export default report => { +const openReport = report => { const count = report.errorCount > 0 ? 'errorCount' : 'warningCount'; const files = getFiles(report, result => result[count] > 0); openEditor(files); }; + +export default openReport; diff --git a/lib/options-manager.js b/lib/options-manager.js index 9c87cb76..48336d94 100644 --- a/lib/options-manager.js +++ b/lib/options-manager.js @@ -1,6 +1,5 @@ -'use strict'; -import os from 'os'; -import path from 'path'; +import os from 'node:os'; +import path from 'node:path'; import fsExtra from 'fs-extra'; import arrify from 'arrify'; import {mergeWith, groupBy, flow, pick} from 'lodash-es'; @@ -43,7 +42,7 @@ const resolveFrom = (moduleId, fromDirectory = process.cwd()) => resolveModule(m resolveFrom.silent = (moduleId, fromDirectory) => { try { return resolveFrom(moduleId, fromDirectory); - } catch { } + } catch {} }; const resolveLocalConfig = name => resolveModule(normalizePackageName(name, 'eslint-config'), import.meta.url); @@ -92,7 +91,7 @@ const getEmptyXOConfig = () => ({ const mergeFn = (previousValue, value, key) => { if (Array.isArray(previousValue)) { if (MERGE_OPTIONS_CONCAT.includes(key)) { - return previousValue.concat(value); + return [...previousValue, ...value]; } return value; @@ -186,7 +185,7 @@ const mergeWithFileConfigs = async (files, options, configFiles) => { await Promise.all(Object.entries(groupBy(groups.filter(({options}) => Boolean(options.ts)), group => group.options.tsConfigPath || '')).map( ([tsConfigPath, groups]) => { - const files = [].concat(...groups.map(group => group.files)); + const files = groups.flatMap(group => group.files); const cachePath = getTsConfigCachePath(files, tsConfigPath); for (const group of groups) { @@ -386,7 +385,7 @@ const buildXOConfig = options => config => { // Only apply if the user has the React plugin if (options.cwd && resolveFrom.silent('eslint-plugin-react', options.cwd)) { - config.baseConfig.plugins = config.baseConfig.plugins.concat('react'); + config.baseConfig.plugins.push('react'); config.baseConfig.rules['react/jsx-indent-props'] = ['error', spaces]; config.baseConfig.rules['react/jsx-indent'] = ['error', spaces]; } @@ -452,10 +451,10 @@ const buildExtendsConfig = options => config => { const buildPrettierConfig = (options, prettierConfig) => config => { if (options.prettier) { // The prettier plugin uses Prettier to format the code with `--fix` - config.baseConfig.plugins = config.baseConfig.plugins.concat('prettier'); + config.baseConfig.plugins.push('prettier'); // The prettier config overrides ESLint stylistic rules that are handled by Prettier - config.baseConfig.extends = config.baseConfig.extends.concat('prettier'); + config.baseConfig.extends.push('prettier'); // The `prettier/prettier` rule reports errors if the code is not formatted in accordance to Prettier config.baseConfig.rules['prettier/prettier'] = ['error', mergeWithPrettierConfig(options, prettierConfig)]; @@ -464,7 +463,7 @@ const buildPrettierConfig = (options, prettierConfig) => config => { // See https://github.com/prettier/eslint-config-prettier for the list of plugins overrrides for (const [plugin, prettierConfig] of Object.entries(PRETTIER_CONFIG_OVERRIDE)) { if (options.cwd && resolveFrom.silent(plugin, options.cwd)) { - config.baseConfig.extends = config.baseConfig.extends.concat(prettierConfig); + config.baseConfig.extends.push(prettierConfig); } } } @@ -505,7 +504,7 @@ const mergeWithPrettierConfig = (options, prettierOptions) => { const buildTSConfig = options => config => { if (options.ts) { - config.baseConfig.extends = config.baseConfig.extends.concat('xo-typescript'); + config.baseConfig.extends.push('xo-typescript'); config.baseConfig.parser = require.resolve('@typescript-eslint/parser'); config.baseConfig.parserOptions = { ...config.baseConfig.parserOptions, @@ -532,7 +531,7 @@ const applyOverrides = (file, options) => { const {applicable, hash} = findApplicableOverrides(path.relative(options.cwd, file), overrides); - options = mergeWith(...[getEmptyXOConfig(), options].concat(applicable.map(override => normalizeOptions(override)), mergeFn)); + options = mergeWith(getEmptyXOConfig(), options, ...applicable.map(override => normalizeOptions(override)), mergeFn); delete options.files; return {options, hash}; } diff --git a/package.json b/package.json index 8727be27..9ac6171a 100644 --- a/package.json +++ b/package.json @@ -109,10 +109,15 @@ "webpack": "^5.41.1" }, "eslintConfig": { - "extends": "eslint-config-xo" + "extends": [ + "eslint-config-xo", + "./config/plugins.cjs", + "./config/overrides.cjs" + ] }, "eslintIgnore": [ - "test/fixtures" + "test/fixtures", + "coverage" ], "ava": { "timeout": "1m" diff --git a/test/cli.js b/test/cli.js index cfee0a66..2a75fdc8 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,5 +1,5 @@ -import fs from 'fs'; -import path from 'path'; +import fs from 'node:fs'; +import path from 'node:path'; import test from 'ava'; import execa from 'execa'; import slash from 'slash'; diff --git a/test/lint-files.js b/test/lint-files.js index 4cceaf48..575b834a 100644 --- a/test/lint-files.js +++ b/test/lint-files.js @@ -1,4 +1,4 @@ -import path from 'path'; +import path from 'node:path'; import test from 'ava'; import createEsmUtils from 'esm-utils'; import xo from '../index.js'; @@ -200,6 +200,7 @@ test('typescript files', async t => { test('typescript 2 space option', async t => { const {errorCount, results} = await xo.lintFiles('two-spaces.tsx', {cwd: 'fixtures/typescript', space: 2}); + // eslint-disable-next-line ava/assertion-arguments t.is(errorCount, 0, JSON.stringify(results[0].messages)); }); @@ -222,6 +223,7 @@ test('webpack import resolver is used if webpack.config.js is found', async t => }, }); + // eslint-disable-next-line ava/assertion-arguments t.is(results[0].errorCount, 1, JSON.stringify(results[0].messages)); const errorMessage = results[0].messages[0].message; @@ -247,6 +249,7 @@ test('webpack import resolver config can be passed through webpack option', asyn }, }); + // eslint-disable-next-line ava/assertion-arguments t.is(results[0].errorCount, 1, JSON.stringify(results[0].messages)); }); @@ -262,6 +265,7 @@ test('webpack import resolver is used if {webpack: true}', async t => { }, }); + // eslint-disable-next-line ava/assertion-arguments t.is(results[0].errorCount, 0, JSON.stringify(results[0])); }); diff --git a/test/lint-text.js b/test/lint-text.js index 615afb85..109012ac 100644 --- a/test/lint-text.js +++ b/test/lint-text.js @@ -1,5 +1,5 @@ -import {promises as fs} from 'fs'; -import path from 'path'; +import {promises as fs} from 'node:fs'; +import path from 'node:path'; import test from 'ava'; import createEsmUtils from 'esm-utils'; import xo from '../index.js'; diff --git a/test/open-report.js b/test/open-report.js index 02c57a2d..ad1bb055 100644 --- a/test/open-report.js +++ b/test/open-report.js @@ -1,4 +1,5 @@ -import path from 'path'; +/* eslint-disable ava/no-skip-test */ +import path from 'node:path'; import test from 'ava'; import proxyquire from 'proxyquire'; import createEsmUtils from 'esm-utils'; @@ -13,7 +14,7 @@ test.skip('opens nothing when there are no errors nor warnings', async t => { const openReport = proxyquire('../lib/open-report', { 'open-editor': files => { - if (files.length !== 0) { + if (files.length > 0) { t.fail(); } }, diff --git a/test/options-manager.js b/test/options-manager.js index f8e38ddf..74245954 100644 --- a/test/options-manager.js +++ b/test/options-manager.js @@ -1,4 +1,4 @@ -import path from 'path'; +import path from 'node:path'; import test from 'ava'; import {omit} from 'lodash-es'; import fsExtra from 'fs-extra'; @@ -429,7 +429,7 @@ test('buildConfig: extends', t => { test('buildConfig: typescript', t => { const config = manager.buildConfig({ts: true, tsConfigPath: './tsconfig.json'}); - t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'xo-typescript'); + t.is(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'xo-typescript'); t.is(config.baseConfig.parser, require.resolve('@typescript-eslint/parser')); t.deepEqual(config.baseConfig.parserOptions, { warnOnUnsupportedTypeScriptVersion: false, diff --git a/test/print-config.js b/test/print-config.js index e12bc2c7..274db42f 100644 --- a/test/print-config.js +++ b/test/print-config.js @@ -1,4 +1,4 @@ -import path from 'path'; +import path from 'node:path'; import test from 'ava'; import execa from 'execa'; import tempWrite from 'temp-write';