From 8f3e08b2b0f8e220e391d3b223a5af729333345f Mon Sep 17 00:00:00 2001 From: Olivier Zalmanski Date: Sat, 2 Sep 2023 01:05:15 +0200 Subject: [PATCH] Fix eslints --- resolvers/node/test/packageMains.js | 3 +-- resolvers/node/test/paths.js | 2 +- resolvers/webpack/index.js | 6 +++--- resolvers/webpack/test/alias.js | 3 +-- resolvers/webpack/test/config.js | 5 ++--- resolvers/webpack/test/example.js | 2 +- resolvers/webpack/test/extensions.js | 5 ++--- resolvers/webpack/test/externals.js | 3 +-- resolvers/webpack/test/fallback.js | 5 ++--- resolvers/webpack/test/loaders.js | 5 ++--- resolvers/webpack/test/modules.js | 5 ++--- resolvers/webpack/test/packageMains.js | 3 +-- resolvers/webpack/test/plugins.js | 3 +-- resolvers/webpack/test/root.js | 5 ++--- utils/declaredScope.js | 2 +- utils/hash.js | 4 ++-- utils/ignore.js | 2 +- utils/moduleVisitor.js | 6 +++--- utils/parse.js | 4 ++-- utils/pkgUp.js | 2 +- utils/resolve.js | 7 +++---- utils/visit.js | 2 +- 22 files changed, 36 insertions(+), 48 deletions(-) diff --git a/resolvers/node/test/packageMains.js b/resolvers/node/test/packageMains.js index 170b10e1a..9435b93d0 100644 --- a/resolvers/node/test/packageMains.js +++ b/resolvers/node/test/packageMains.js @@ -1,7 +1,6 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); const resolver = require('../'); diff --git a/resolvers/node/test/paths.js b/resolvers/node/test/paths.js index e6ffdafcd..86de91c4f 100644 --- a/resolvers/node/test/paths.js +++ b/resolvers/node/test/paths.js @@ -1,4 +1,4 @@ -const expect = require('chai').expect; +const { expect } = require('chai'); const path = require('path'); const node = require('../index.js'); diff --git a/resolvers/webpack/index.js b/resolvers/webpack/index.js index ebd77af1e..45d6c4d6b 100644 --- a/resolvers/webpack/index.js +++ b/resolvers/webpack/index.js @@ -293,15 +293,15 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) { && plugin.constructor.name === 'ResolverPlugin' && Array.isArray(plugin.plugins) ) { - resolvePlugins.push.apply(resolvePlugins, plugin.plugins); + resolvePlugins.push(...plugin.plugins); } }); } - resolver.apply.apply(resolver, resolvePlugins); + resolver.apply(...resolvePlugins); return function () { - return resolver.resolveSync.apply(resolver, arguments); + return resolver.resolveSync(...arguments); }; } diff --git a/resolvers/webpack/test/alias.js b/resolvers/webpack/test/alias.js index 946365b30..0ab83881f 100644 --- a/resolvers/webpack/test/alias.js +++ b/resolvers/webpack/test/alias.js @@ -1,7 +1,6 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); const webpack = require('../index'); diff --git a/resolvers/webpack/test/config.js b/resolvers/webpack/test/config.js index 35f46e66c..89900e8f3 100644 --- a/resolvers/webpack/test/config.js +++ b/resolvers/webpack/test/config.js @@ -1,10 +1,9 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); -const resolve = require('../index').resolve; +const { resolve } = require('../index'); const file = path.join(__dirname, 'files', 'src', 'jsx', 'dummy.js'); const extensionFile = path.join(__dirname, 'config-extensions', 'src', 'dummy.js'); diff --git a/resolvers/webpack/test/example.js b/resolvers/webpack/test/example.js index cd9ece015..b8fd568c1 100644 --- a/resolvers/webpack/test/example.js +++ b/resolvers/webpack/test/example.js @@ -2,7 +2,7 @@ const path = require('path'); -const resolve = require('../index').resolve; +const { resolve } = require('../index'); const file = path.join(__dirname, 'files', 'src', 'dummy.js'); diff --git a/resolvers/webpack/test/extensions.js b/resolvers/webpack/test/extensions.js index 096df7728..d55c19c31 100644 --- a/resolvers/webpack/test/extensions.js +++ b/resolvers/webpack/test/extensions.js @@ -1,10 +1,9 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); -const resolve = require('../index').resolve; +const { resolve } = require('../index'); const file = path.join(__dirname, 'files', 'dummy.js'); const extensions = path.join(__dirname, 'custom-extensions', 'dummy.js'); diff --git a/resolvers/webpack/test/externals.js b/resolvers/webpack/test/externals.js index 27dec2033..c4ce95340 100644 --- a/resolvers/webpack/test/externals.js +++ b/resolvers/webpack/test/externals.js @@ -1,7 +1,6 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); const semver = require('semver'); diff --git a/resolvers/webpack/test/fallback.js b/resolvers/webpack/test/fallback.js index b164209e1..85bb918f2 100644 --- a/resolvers/webpack/test/fallback.js +++ b/resolvers/webpack/test/fallback.js @@ -1,10 +1,9 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); -const resolve = require('../index').resolve; +const { resolve } = require('../index'); const file = path.join(__dirname, 'files', 'src', 'dummy.js'); diff --git a/resolvers/webpack/test/loaders.js b/resolvers/webpack/test/loaders.js index e250894a5..c52f7645c 100644 --- a/resolvers/webpack/test/loaders.js +++ b/resolvers/webpack/test/loaders.js @@ -1,10 +1,9 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); -const resolve = require('../index').resolve; +const { resolve } = require('../index'); const file = path.join(__dirname, 'files', 'dummy.js'); diff --git a/resolvers/webpack/test/modules.js b/resolvers/webpack/test/modules.js index 066e52a6f..bd284b572 100644 --- a/resolvers/webpack/test/modules.js +++ b/resolvers/webpack/test/modules.js @@ -1,10 +1,9 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); -const resolve = require('../index').resolve; +const { resolve } = require('../index'); const file = path.join(__dirname, 'files', 'dummy.js'); diff --git a/resolvers/webpack/test/packageMains.js b/resolvers/webpack/test/packageMains.js index d3ddad9da..66fe02e17 100644 --- a/resolvers/webpack/test/packageMains.js +++ b/resolvers/webpack/test/packageMains.js @@ -1,7 +1,6 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); const resolver = require('../'); diff --git a/resolvers/webpack/test/plugins.js b/resolvers/webpack/test/plugins.js index b964e7c30..406d05b6e 100644 --- a/resolvers/webpack/test/plugins.js +++ b/resolvers/webpack/test/plugins.js @@ -1,7 +1,6 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); const webpack = require('../index'); diff --git a/resolvers/webpack/test/root.js b/resolvers/webpack/test/root.js index 194bb8fc8..76d7f9623 100644 --- a/resolvers/webpack/test/root.js +++ b/resolvers/webpack/test/root.js @@ -1,10 +1,9 @@ 'use strict'; -const chai = require('chai'); -const expect = chai.expect; +const { expect } = require('chai'); const path = require('path'); -const resolve = require('../index').resolve; +const { resolve } = require('../index'); const file = path.join(__dirname, 'files', 'src', 'dummy.js'); const webpackDir = path.join(__dirname, 'different-package-location'); diff --git a/utils/declaredScope.js b/utils/declaredScope.js index dd2a20149..985d64da2 100644 --- a/utils/declaredScope.js +++ b/utils/declaredScope.js @@ -3,7 +3,7 @@ exports.__esModule = true; exports.default = function declaredScope(context, name) { - const references = context.getScope().references; + const { references } = context.getScope(); const reference = references.find((x) => x.identifier.name === name); if (!reference) { return undefined; } return reference.resolved.scope.type; diff --git a/utils/hash.js b/utils/hash.js index b9bff25bd..fd244f055 100644 --- a/utils/hash.js +++ b/utils/hash.js @@ -7,9 +7,9 @@ exports.__esModule = true; -const createHash = require('crypto').createHash; +const { createHash } = require('crypto'); -const stringify = JSON.stringify; +const { stringify } = JSON; function hashify(value, hash) { if (!hash) { hash = createHash('sha256'); } diff --git a/utils/ignore.js b/utils/ignore.js index 960538e70..23d5b0214 100644 --- a/utils/ignore.js +++ b/utils/ignore.js @@ -2,7 +2,7 @@ exports.__esModule = true; -const extname = require('path').extname; +const { extname } = require('path'); const log = require('debug')('eslint-plugin-import:utils:ignore'); diff --git a/utils/moduleVisitor.js b/utils/moduleVisitor.js index c312ca2d4..796328f9b 100644 --- a/utils/moduleVisitor.js +++ b/utils/moduleVisitor.js @@ -45,7 +45,7 @@ exports.default = function visitModules(visitor, options) { if (node.callee.type !== 'Import') { return; } if (node.arguments.length !== 1) { return; } - modulePath = node.arguments[0]; + [modulePath] = node.arguments; } if (modulePath.type !== 'Literal') { return; } @@ -61,7 +61,7 @@ exports.default = function visitModules(visitor, options) { if (call.callee.name !== 'require') { return; } if (call.arguments.length !== 1) { return; } - const modulePath = call.arguments[0]; + const [modulePath] = call.arguments; if (modulePath.type !== 'Literal') { return; } if (typeof modulePath.value !== 'string') { return; } @@ -73,7 +73,7 @@ exports.default = function visitModules(visitor, options) { if (call.callee.name !== 'require' && call.callee.name !== 'define') { return; } if (call.arguments.length !== 2) { return; } - const modules = call.arguments[0]; + const [modules] = call.arguments; if (modules.type !== 'ArrayExpression') { return; } for (const element of modules.elements) { diff --git a/utils/parse.js b/utils/parse.js index 7646b3177..d56ad2489 100644 --- a/utils/parse.js +++ b/utils/parse.js @@ -3,7 +3,7 @@ exports.__esModule = true; const moduleRequire = require('./module-require').default; -const extname = require('path').extname; +const { extname } = require('path'); const fs = require('fs'); const log = require('debug')('eslint-plugin-import:parse'); @@ -95,7 +95,7 @@ exports.default = function parse(path, content, context) { let ast; try { const parserRaw = parser.parseForESLint(content, parserOptions); - ast = parserRaw.ast; + ({ ast } = parserRaw); return makeParseReturn(ast, keysFromParser(parserOrPath, parser, parserRaw)); } catch (e) { console.warn(); diff --git a/utils/pkgUp.js b/utils/pkgUp.js index 889f62265..e6ea4608a 100644 --- a/utils/pkgUp.js +++ b/utils/pkgUp.js @@ -33,7 +33,7 @@ const path = require('path'); */ function findUp(filename, cwd) { let dir = path.resolve(cwd || ''); - const root = path.parse(dir).root; + const { root } = path.parse(dir); const filenames = [].concat(filename); diff --git a/utils/resolve.js b/utils/resolve.js index 0ed5bdb0c..092e9751d 100644 --- a/utils/resolve.js +++ b/utils/resolve.js @@ -6,7 +6,7 @@ const fs = require('fs'); const Module = require('module'); const path = require('path'); -const hashObject = require('./hash').hashObject; +const { hashObject } = require('./hash'); const ModuleCache = require('./ModuleCache').default; const pkgDir = require('./pkgDir').default; @@ -60,7 +60,7 @@ exports.fileExistsWithCaseSync = function fileExistsWithCaseSync(filepath, cache if (filepath === null) { return true; } if (filepath.toLowerCase() === process.cwd().toLowerCase() && !strict) { return true; } const parsedPath = path.parse(filepath); - const dir = parsedPath.dir; + const { dir } = parsedPath; let result = fileExistsCache.get(filepath, cacheSettings); if (result != null) { return result; } @@ -129,8 +129,7 @@ function fullResolve(modulePath, sourceFile, settings) { const resolvers = resolverReducer(configResolvers, new Map()); for (const pair of resolvers) { - const name = pair[0]; - const config = pair[1]; + const [name, config] = pair; const resolver = requireResolver(name, sourceFile); const resolved = withResolver(resolver, config); diff --git a/utils/visit.js b/utils/visit.js index 6178faeaa..559271a9c 100644 --- a/utils/visit.js +++ b/utils/visit.js @@ -6,7 +6,7 @@ exports.default = function visit(node, keys, visitorSpec) { if (!node || !keys) { return; } - const type = node.type; + const { type } = node; if (typeof visitorSpec[type] === 'function') { visitorSpec[type](node); }