From 99e8af9f149a2a970cf2e472b20f20fe301ab012 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Thu, 14 Dec 2023 07:56:33 -0500 Subject: [PATCH] Adds linting --- .eslintrc.yaml | 18 +++++++++++ .github/workflows/ci.yml | 12 +++++++ hook.js | 31 +++++++++---------- index.js | 8 ++--- lib/get-esm-exports.js | 2 +- lib/get-exports.js | 2 +- lib/register.js | 7 ++--- package.json | 13 +++++++- test/fixtures/a.mjs | 2 +- test/fixtures/b.mjs | 2 +- test/fixtures/cyclical-a.mjs | 8 ++--- test/fixtures/cyclical-b.mjs | 10 +++--- test/fixtures/env.mjs | 10 +++--- test/fixtures/export-types/declarations.mjs | 26 ++++++++-------- .../export-types/default-class-anon.mjs | 2 +- test/fixtures/export-types/default-class.mjs | 2 +- .../export-types/default-expression-array.mjs | 2 +- .../export-types/default-expression-num.mjs | 2 +- .../default-expression-string.mjs | 2 +- .../export-types/default-function-anon.mjs | 2 +- .../export-types/default-function.mjs | 2 +- .../export-types/default-generator-anon.mjs | 2 +- .../export-types/default-generator.mjs | 2 +- .../export-types/fn-default-export.mjs | 2 +- .../export-types/import-default-export.mjs | 4 +-- test/fixtures/export-types/list.mjs | 8 ++--- .../export-types/variable-default-export.mjs | 2 +- test/fixtures/foo.mjs | 2 +- test/fixtures/json.mjs | 4 +-- test/fixtures/lib/baz.mjs | 2 +- test/fixtures/something.js | 2 +- test/hook/default-export.mjs | 28 +++++++---------- test/hook/dynamic-import-default.js | 4 +-- test/hook/dynamic-import-default.mjs | 2 +- test/hook/static-import-default.mjs | 4 +-- ...tatic-import-package-internals-enabled.mjs | 2 +- test/hook/static-import-star.mjs | 22 +++++++------ test/hook/v14-declaration-exports.mjs | 27 ++++++++-------- test/hook/v18.19-static-import-gotalike.mjs | 4 ++- test/low-level/dynamic-import-default.js | 2 +- test/low-level/dynamic-import-default.mjs | 2 +- test/low-level/static-import-default.mjs | 2 +- ...v14-assert-cyclical-dependency-failure.mjs | 19 +++++++----- test/typescript/iitm-ts-node-loader.mjs | 8 ++--- 44 files changed, 182 insertions(+), 139 deletions(-) create mode 100644 .eslintrc.yaml diff --git a/.eslintrc.yaml b/.eslintrc.yaml new file mode 100644 index 0000000..8d9221c --- /dev/null +++ b/.eslintrc.yaml @@ -0,0 +1,18 @@ +overrides: + - files: + - '**/*.{js,cjs,mjs}' + +parser: '@babel/eslint-parser' +parserOptions: + ecmaVersion: latest + requireConfigFile: false + sourceType: 'script' + babelOptions: + plugins: + - '@babel/plugin-syntax-import-assertions' + +rules: + "import/first": off + +extends: + - "standard" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49ad8ad..ec588f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,18 @@ on: - cron: '0 4 * * *' jobs: + lint: + # The linting packages require modern Node.js versions in order to run. + # Therefore, we run linting separately and only once. + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 'lts/*' + - run: npm install + - run: npm run lint + build: runs-on: ubuntu-latest diff --git a/hook.js b/hook.js index f0225cc..aa22356 100644 --- a/hook.js +++ b/hook.js @@ -4,7 +4,7 @@ const { randomBytes } = require('crypto') const specifiers = new Map() -const isWin = process.platform === "win32" +const isWin = process.platform === 'win32' // FIXME: Typescript extensions are added temporarily until we find a better // way of supporting arbitrary extensions @@ -16,7 +16,7 @@ const NODE_MINOR = Number(NODE_VERSION[1]) let entrypoint let getExports -if (NODE_MAJOR >= 20 || (NODE_MAJOR == 18 && NODE_MINOR >= 19)) { +if (NODE_MAJOR >= 20 || (NODE_MAJOR === 18 && NODE_MINOR >= 19)) { getExports = require('./lib/get-exports.js') } else { getExports = ({ url }) => import(url).then(Object.keys) @@ -56,7 +56,7 @@ function deleteIitm (url) { return resultUrl } -function isNode16AndBiggerOrEqualsThan16_17_0() { +function isNodeMajor16AndMinor17OrGreater () { return NODE_MAJOR === 16 && NODE_MINOR >= 17 } @@ -68,11 +68,11 @@ function isNodeProtocol (urlObj) { return urlObj.protocol === 'node:' } -function needsToAddFileProtocol(urlObj) { +function needsToAddFileProtocol (urlObj) { if (NODE_MAJOR === 17) { return !isFileProtocol(urlObj) } - if (isNode16AndBiggerOrEqualsThan16_17_0()) { + if (isNodeMajor16AndMinor17OrGreater()) { return !isFileProtocol(urlObj) && !isNodeProtocol(urlObj) } return !isFileProtocol(urlObj) && NODE_MAJOR < 18 @@ -87,7 +87,7 @@ function needsToAddFileProtocol(urlObj) { * @param {string} line * @returns {boolean} */ -function isStarExportLine(line) { +function isStarExportLine (line) { return /^\* from /.test(line) } @@ -124,7 +124,7 @@ function isStarExportLine(line) { * * @returns {Promise} */ -async function processModule({ +async function processModule ({ srcUrl, context, parentGetSource, @@ -152,7 +152,7 @@ async function processModule({ for (const n of exportNames) { if (isStarExportLine(n) === true) { - const [_, modFile] = n.split('* from ') + const [, modFile] = n.split('* from ') const normalizedModName = normalizeModName(modFile) const modUrl = new URL(modFile, srcUrl).toString() const modName = Buffer.from(modFile, 'hex') + Date.now() + randomBytes(4).toString('hex') @@ -191,7 +191,7 @@ async function processModule({ continue } - setters.set(`$${n}`+ns, ` + setters.set(`$${n}` + ns, ` let $${n} = ${ns}.${n} export { $${n} as ${n} } set.${n} = (v) => { @@ -214,9 +214,9 @@ async function processModule({ * * @returns {string} The normalized identifier. */ -function normalizeModName(name) { +function normalizeModName (name) { return name - .split('\/') + .split('/') .pop() .replace(/(.+)\.(?:js|mjs)$/, '$1') .replaceAll(/(-.)/g, x => x[1].toUpperCase()) @@ -253,7 +253,6 @@ function createHook (meta) { return url } - specifiers.set(url.url, specifier) return { @@ -268,9 +267,9 @@ function createHook (meta) { if (hasIitm(url)) { const realUrl = deleteIitm(url) const { imports, namespaces, setters: mapSetters } = await processModule({ - srcUrl: realUrl, - context, - parentGetSource + srcUrl: realUrl, + context, + parentGetSource }) const setters = Array.from(mapSetters.values()) @@ -284,7 +283,7 @@ function createHook (meta) { const renamedDefaults = setters .map(s => { const matches = /let \$(.+) = (\$.+)\.default/.exec(s) - if (matches === null) return + if (matches === null) return undefined return `_['${matches[1]}'] = ${matches[2]}.default` }) .filter(s => s) diff --git a/index.js b/index.js index 8796665..50a8665 100644 --- a/index.js +++ b/index.js @@ -12,26 +12,26 @@ const { toHook } = require('./lib/register') -function addHook(hook) { +function addHook (hook) { importHooks.push(hook) toHook.forEach(([name, namespace]) => hook(name, namespace)) } -function removeHook(hook) { +function removeHook (hook) { const index = importHooks.indexOf(hook) if (index > -1) { importHooks.splice(index, 1) } } -function callHookFn(hookFn, namespace, name, baseDir) { +function callHookFn (hookFn, namespace, name, baseDir) { const newDefault = hookFn(namespace, name, baseDir) if (newDefault && newDefault !== namespace) { namespace.default = newDefault } } -function Hook(modules, options, hookFn) { +function Hook (modules, options, hookFn) { if ((this instanceof Hook) === false) return new Hook(modules, options, hookFn) if (typeof modules === 'function') { hookFn = modules diff --git a/lib/get-esm-exports.js b/lib/get-esm-exports.js index 8b158a3..7665465 100644 --- a/lib/get-esm-exports.js +++ b/lib/get-esm-exports.js @@ -1,7 +1,7 @@ 'use strict' const { Parser } = require('acorn') -const { importAssertions } = require('acorn-import-assertions'); +const { importAssertions } = require('acorn-import-assertions') const acornOpts = { ecmaVersion: 'latest', diff --git a/lib/get-exports.js b/lib/get-exports.js index a50315a..aa4e3c3 100644 --- a/lib/get-exports.js +++ b/lib/get-exports.js @@ -5,7 +5,7 @@ const { parse: getCjsExports } = require('cjs-module-lexer') const fs = require('fs') const { fileURLToPath } = require('url') -function addDefault(arr) { +function addDefault (arr) { return Array.from(new Set(['default', ...arr])) } diff --git a/lib/register.js b/lib/register.js index 42abf7e..a81c48c 100644 --- a/lib/register.js +++ b/lib/register.js @@ -2,18 +2,17 @@ // // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. - const importHooks = [] // TODO should this be a Set? const setters = new WeakMap() const specifiers = new Map() const toHook = [] const proxyHandler = { - set(target, name, value) { + set (target, name, value) { return setters.get(target)[name](value) }, - defineProperty(target, property, descriptor) { + defineProperty (target, property, descriptor) { if ((!('value' in descriptor))) { throw new Error('Getters/setters are not supported for exports property descriptors.') } @@ -22,7 +21,7 @@ const proxyHandler = { } } -function register(name, namespace, set, specifier) { +function register (name, namespace, set, specifier) { specifiers.set(name, specifier) setters.set(namespace, set) const proxy = new Proxy(namespace, proxyHandler) diff --git a/package.json b/package.json index be54da6..68db3ad 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "scripts": { "test": "c8 --reporter lcov --check-coverage --lines 50 imhotap --runner 'node test/runtest' --files test/{hook,low-level,other,get-esm-exports}/*", "test:ts": "c8 --reporter lcov imhotap --runner 'node test/runtest' --files test/typescript/*.test.mts", - "coverage": "c8 --reporter html imhotap --runner 'node test/runtest' --files test/{hook,low-level,other,get-esm-exports}/* && echo '\nNow open coverage/index.html\n'" + "coverage": "c8 --reporter html imhotap --runner 'node test/runtest' --files test/{hook,low-level,other,get-esm-exports}/* && echo '\nNow open coverage/index.html\n'", + "lint": "eslint .", + "lint:fix": "eslint . --fix" }, "repository": { "type": "git", @@ -27,8 +29,17 @@ }, "homepage": "https://github.com/DataDog/import-in-the-middle#readme", "devDependencies": { + "@babel/core": "^7.23.7", + "@babel/eslint-parser": "^7.23.3", + "@babel/plugin-syntax-import-assertions": "^7.23.3", "@types/node": "^18.0.6", "c8": "^7.8.0", + "eslint": "^8.55.0", + "eslint-config-standard": "^17.1.0", + "eslint-plugin-import": "^2.29.0", + "eslint-plugin-n": "^16.4.0", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-promise": "^6.1.1", "imhotap": "^2.1.0", "ts-node": "^10.9.1", "typescript": "^4.7.4" diff --git a/test/fixtures/a.mjs b/test/fixtures/a.mjs index 1381e65..7a393e7 100644 --- a/test/fixtures/a.mjs +++ b/test/fixtures/a.mjs @@ -1,6 +1,6 @@ export const a = 'a' -export function aFunc() { +export function aFunc () { return a } diff --git a/test/fixtures/b.mjs b/test/fixtures/b.mjs index 2bb4e36..e75df08 100644 --- a/test/fixtures/b.mjs +++ b/test/fixtures/b.mjs @@ -1,5 +1,5 @@ export const b = 'b' -export function bFunc() { +export function bFunc () { return b } diff --git a/test/fixtures/cyclical-a.mjs b/test/fixtures/cyclical-a.mjs index 763a05f..4cdb5e9 100644 --- a/test/fixtures/cyclical-a.mjs +++ b/test/fixtures/cyclical-a.mjs @@ -1,7 +1,7 @@ -import { testB } from './cyclical-b.mjs'; +import { testB } from './cyclical-b.mjs' -export function testA() { - console.log("testA"); +export function testA () { + console.log('testA') } -testB(); +testB() diff --git a/test/fixtures/cyclical-b.mjs b/test/fixtures/cyclical-b.mjs index 1f57523..988b686 100644 --- a/test/fixtures/cyclical-b.mjs +++ b/test/fixtures/cyclical-b.mjs @@ -1,6 +1,6 @@ -import { testA } from './cyclical-a.mjs'; +import { testA } from './cyclical-a.mjs' -export function testB() { - console.log("testB"); - testA(); -} \ No newline at end of file +export function testB () { + console.log('testB') + testA() +} diff --git a/test/fixtures/env.mjs b/test/fixtures/env.mjs index 3e028f7..b6ef2ad 100644 --- a/test/fixtures/env.mjs +++ b/test/fixtures/env.mjs @@ -1,8 +1,8 @@ -let env = {FOO: 'baz'}; +let env = { FOO: 'baz' } -function setEnv(newEnv) { - console.log('setting env, env.FOO is', newEnv.FOO); - env = newEnv; +function setEnv (newEnv) { + console.log('setting env, env.FOO is', newEnv.FOO) + env = newEnv } -export { setEnv, env }; \ No newline at end of file +export { setEnv, env } diff --git a/test/fixtures/export-types/declarations.mjs b/test/fixtures/export-types/declarations.mjs index b37583f..bc2b2ff 100644 --- a/test/fixtures/export-types/declarations.mjs +++ b/test/fixtures/export-types/declarations.mjs @@ -1,19 +1,19 @@ -const o = { name5: 1, name6: 1 }; +const o = { name5: 1, name6: 1 } const array = [1, 1] // Exporting declarations -export let name1 = 1, name2 = 1/*, … */; // also var -export const name3 = 1, name4 = 1/*, … */; // also var, let -export function functionName() { return 1 } -export class ClassName { getFoo() { return 1 } } -export function* generatorFunctionName() { return 1 } -export const { name5, name6: bar } = o; -export const [ name7, name8 ] = array; -export async function asyncFunctionName() { return 1 } -export async function* asyncGeneratorFunctionName() { yield 1 } +export const name1 = 1; export const name2 = 1/*, … */ // also var +export const name3 = 1; export const name4 = 1/*, … */ // also var, let +export function functionName () { return 1 } +export class ClassName { getFoo () { return 1 } } +export function * generatorFunctionName () { return 1 } +export const { name5, name6: bar } = o +export const [name7, name8] = array +export async function asyncFunctionName () { return 1 } +export async function * asyncGeneratorFunctionName () { yield 1 } export const arrowFunction = () => { - return 1; + return 1 } export const asyncArrowFunction = async () => { - return 1; -} \ No newline at end of file + return 1 +} diff --git a/test/fixtures/export-types/default-class-anon.mjs b/test/fixtures/export-types/default-class-anon.mjs index 1403140..0192e74 100644 --- a/test/fixtures/export-types/default-class-anon.mjs +++ b/test/fixtures/export-types/default-class-anon.mjs @@ -1 +1 @@ -export default class { getFoo() { return 1 } } \ No newline at end of file +export default class { getFoo () { return 1 } } diff --git a/test/fixtures/export-types/default-class.mjs b/test/fixtures/export-types/default-class.mjs index b2f8d60..89998d2 100644 --- a/test/fixtures/export-types/default-class.mjs +++ b/test/fixtures/export-types/default-class.mjs @@ -1 +1 @@ -export default class ClassName { getFoo() { return 1 } } \ No newline at end of file +export default class ClassName { getFoo () { return 1 } } diff --git a/test/fixtures/export-types/default-expression-array.mjs b/test/fixtures/export-types/default-expression-array.mjs index 289d4e6..5e27a1f 100644 --- a/test/fixtures/export-types/default-expression-array.mjs +++ b/test/fixtures/export-types/default-expression-array.mjs @@ -1 +1 @@ -export default [1] \ No newline at end of file +export default [1] diff --git a/test/fixtures/export-types/default-expression-num.mjs b/test/fixtures/export-types/default-expression-num.mjs index 55bb209..b0d35f3 100644 --- a/test/fixtures/export-types/default-expression-num.mjs +++ b/test/fixtures/export-types/default-expression-num.mjs @@ -1 +1 @@ -export default 1 \ No newline at end of file +export default 1 diff --git a/test/fixtures/export-types/default-expression-string.mjs b/test/fixtures/export-types/default-expression-string.mjs index a7117c1..d2948ca 100644 --- a/test/fixtures/export-types/default-expression-string.mjs +++ b/test/fixtures/export-types/default-expression-string.mjs @@ -1 +1 @@ -export default 'dog' \ No newline at end of file +export default 'dog' diff --git a/test/fixtures/export-types/default-function-anon.mjs b/test/fixtures/export-types/default-function-anon.mjs index 86d3b3e..d18d544 100644 --- a/test/fixtures/export-types/default-function-anon.mjs +++ b/test/fixtures/export-types/default-function-anon.mjs @@ -1 +1 @@ -export default function () { return 1 } \ No newline at end of file +export default function () { return 1 } diff --git a/test/fixtures/export-types/default-function.mjs b/test/fixtures/export-types/default-function.mjs index 2e15809..b3db82e 100644 --- a/test/fixtures/export-types/default-function.mjs +++ b/test/fixtures/export-types/default-function.mjs @@ -1 +1 @@ -export default function functionName() { return 1 } \ No newline at end of file +export default function functionName () { return 1 } diff --git a/test/fixtures/export-types/default-generator-anon.mjs b/test/fixtures/export-types/default-generator-anon.mjs index 417fbcc..72835d1 100644 --- a/test/fixtures/export-types/default-generator-anon.mjs +++ b/test/fixtures/export-types/default-generator-anon.mjs @@ -1 +1 @@ -export default function* () { return 1 } \ No newline at end of file +export default function * () { return 1 } diff --git a/test/fixtures/export-types/default-generator.mjs b/test/fixtures/export-types/default-generator.mjs index 1a4f33b..679bb31 100644 --- a/test/fixtures/export-types/default-generator.mjs +++ b/test/fixtures/export-types/default-generator.mjs @@ -1 +1 @@ -export default function* generatorFunctionName() { return 1 } \ No newline at end of file +export default function * generatorFunctionName () { return 1 } diff --git a/test/fixtures/export-types/fn-default-export.mjs b/test/fixtures/export-types/fn-default-export.mjs index 9399f77..5fa262b 100644 --- a/test/fixtures/export-types/fn-default-export.mjs +++ b/test/fixtures/export-types/fn-default-export.mjs @@ -1,3 +1,3 @@ export default function () { return 1 -} \ No newline at end of file +} diff --git a/test/fixtures/export-types/import-default-export.mjs b/test/fixtures/export-types/import-default-export.mjs index aa10116..ce1bf84 100644 --- a/test/fixtures/export-types/import-default-export.mjs +++ b/test/fixtures/export-types/import-default-export.mjs @@ -1,2 +1,2 @@ -import fnDefaultExport from "./fn-default-export.mjs"; -export default fnDefaultExport \ No newline at end of file +import fnDefaultExport from './fn-default-export.mjs' +export default fnDefaultExport diff --git a/test/fixtures/export-types/list.mjs b/test/fixtures/export-types/list.mjs index c569609..aa87cb0 100644 --- a/test/fixtures/export-types/list.mjs +++ b/test/fixtures/export-types/list.mjs @@ -6,7 +6,7 @@ const variable1 = 1 const variable2 = 1 const variable3 = 1 const name6 = 1 -export { name1, name2 }; -export { variable1 as name3, variable2 as name4, /* …, */ name5 }; -export { variable3 as "name" }; -export { name6 as default /*, … */ }; \ No newline at end of file +export { name1, name2 } +export { variable1 as name3, variable2 as name4, /* …, */ name5 } +export { variable3 as 'name' } +export { name6 as default /*, … */ } diff --git a/test/fixtures/export-types/variable-default-export.mjs b/test/fixtures/export-types/variable-default-export.mjs index 0a46393..a7831c0 100644 --- a/test/fixtures/export-types/variable-default-export.mjs +++ b/test/fixtures/export-types/variable-default-export.mjs @@ -2,4 +2,4 @@ const temp = function () { return 1 } -export default temp \ No newline at end of file +export default temp diff --git a/test/fixtures/foo.mjs b/test/fixtures/foo.mjs index f494858..6e16b50 100644 --- a/test/fixtures/foo.mjs +++ b/test/fixtures/foo.mjs @@ -1,4 +1,4 @@ -export function foo() { +export function foo () { return 'foo' } diff --git a/test/fixtures/json.mjs b/test/fixtures/json.mjs index 1d97202..d0d9770 100644 --- a/test/fixtures/json.mjs +++ b/test/fixtures/json.mjs @@ -2,8 +2,8 @@ // // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. -import coolFile from './something.json' assert { type: 'json' }; +import coolFile from './something.json' assert { type: 'json' } export default { data: coolFile.data -}; +} diff --git a/test/fixtures/lib/baz.mjs b/test/fixtures/lib/baz.mjs index 26f5f33..6ef9718 100644 --- a/test/fixtures/lib/baz.mjs +++ b/test/fixtures/lib/baz.mjs @@ -1,4 +1,4 @@ -export function baz() { +export function baz () { return 'baz' } export default baz diff --git a/test/fixtures/something.js b/test/fixtures/something.js index 8cd50e5..8cd429e 100644 --- a/test/fixtures/something.js +++ b/test/fixtures/something.js @@ -4,7 +4,7 @@ 'use strict' -module.exports = function bar() { +module.exports = function bar () { return 42 } module.exports.foo = 42 diff --git a/test/hook/default-export.mjs b/test/hook/default-export.mjs index 28aa02b..56ed78a 100644 --- a/test/hook/default-export.mjs +++ b/test/hook/default-export.mjs @@ -21,41 +21,34 @@ Hook((exports, name) => { exports.default[0] += 1 } else if (name.match(/default-expression-num\.m?js/)) { exports.default += 1 - } - else if (name.match(/default-expression-string\.m?js/)) { + } else if (name.match(/default-expression-string\.m?js/)) { exports.default += 'dawg' - } - else if (name.match(/default-function\.m?js/)) { + } else if (name.match(/default-function\.m?js/)) { const orig = exports.default exports.default = function () { return orig() + 1 } - } - else if (name.match(/default-class\.m?js/)) { + } else if (name.match(/default-class\.m?js/)) { exports.default.prototype.getFoo = function () { return 2 } - } - else if (name.match(/default-generator\.m?js/)) { + } else if (name.match(/default-generator\.m?js/)) { const orig2 = exports.default - exports.default = function* () { + exports.default = function * () { return orig2().next().value + 1 } - } - else if (name.match(/default-function-anon\.m?js/)) { + } else if (name.match(/default-function-anon\.m?js/)) { const orig = exports.default exports.default = function () { return orig() + 1 } - } - else if (name.match(/default-class-anon\.m?js/)) { + } else if (name.match(/default-class-anon\.m?js/)) { exports.default.prototype.getFoo = function () { return 2 } - } - else if (name.match(/default-generator-anon\.m?js/)) { + } else if (name.match(/default-generator-anon\.m?js/)) { const orig2 = exports.default - exports.default = function* () { + exports.default = function * () { return orig2().next().value + 1 } } else if (name.match(/import-default-export\.m?js/)) { @@ -71,6 +64,7 @@ Hook((exports, name) => { } }) +/* eslint-disable new-cap */ strictEqual(defaultImportExport(), 2) strictEqual(varDefaultExport(), 2) strictEqual(a[0], 2) @@ -81,4 +75,4 @@ strictEqual(afn(), 2) strictEqual(new acn().getFoo(), 2) strictEqual(agfn().next().value, 2) strictEqual(n, 2) -strictEqual(s, 'dogdawg') \ No newline at end of file +strictEqual(s, 'dogdawg') diff --git a/test/hook/dynamic-import-default.js b/test/hook/dynamic-import-default.js index ab87729..fdb4753 100644 --- a/test/hook/dynamic-import-default.js +++ b/test/hook/dynamic-import-default.js @@ -8,13 +8,13 @@ const { strictEqual } = require('assert') Hook((exports, name) => { if (name.match(/something.js/)) { const orig = exports.default - exports.default = function bar() { + exports.default = function bar () { return orig() + 15 } } if (name.match(/something.mjs/)) { const orig = exports.default - return function bar() { + return function bar () { return orig() + 15 } } diff --git a/test/hook/dynamic-import-default.mjs b/test/hook/dynamic-import-default.mjs index 7beb750..1be2f5f 100644 --- a/test/hook/dynamic-import-default.mjs +++ b/test/hook/dynamic-import-default.mjs @@ -8,7 +8,7 @@ import { strictEqual } from 'assert' Hook((exports, name) => { if (name.match(/something\.m?js/)) { const orig = exports.default - exports.default = function bar() { + exports.default = function bar () { return orig() + 15 } } diff --git a/test/hook/static-import-default.mjs b/test/hook/static-import-default.mjs index 5fe338f..304224b 100644 --- a/test/hook/static-import-default.mjs +++ b/test/hook/static-import-default.mjs @@ -10,13 +10,13 @@ import { strictEqual } from 'assert' Hook((exports, name) => { if (name.match(/something.mjs/)) { const orig = exports.default - exports.default = function bar() { + exports.default = function bar () { return orig() + 15 } } if (name.match(/something.js/)) { const orig = exports.default - return function bar() { + return function bar () { return orig() + 15 } } diff --git a/test/hook/static-import-package-internals-enabled.mjs b/test/hook/static-import-package-internals-enabled.mjs index 8f31a2a..ee20aac 100644 --- a/test/hook/static-import-package-internals-enabled.mjs +++ b/test/hook/static-import-package-internals-enabled.mjs @@ -7,7 +7,7 @@ import { strictEqual } from 'assert' const c8Dir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'node_modules', 'c8') Hook(['c8'], { internals: true }, (exports, name, baseDir) => { - strictEqual(name, path.join('c8','index.js')) + strictEqual(name, path.join('c8', 'index.js')) strictEqual(baseDir, c8Dir) exports.Report = () => 42 }) diff --git a/test/hook/static-import-star.mjs b/test/hook/static-import-star.mjs index f928973..ae013da 100644 --- a/test/hook/static-import-star.mjs +++ b/test/hook/static-import-star.mjs @@ -1,31 +1,33 @@ import { strictEqual } from 'assert' import Hook from '../../index.js' + +/* eslint-disable import/first */ +import { + /* eslint-disable import/no-named-default */ + default as bar, + foo, + aFunc, + baz +} from '../fixtures/bundle.mjs' Hook((exports, name) => { if (/bundle\.mjs/.test(name) === false) return const bar = exports.default - exports.default = function wrappedBar() { + exports.default = function wrappedBar () { return bar() + '-wrapped' } const foo = exports.foo - exports.foo = function wrappedFoo() { + exports.foo = function wrappedFoo () { return foo() + '-wrapped' } const aFunc = exports.aFunc - exports.aFunc = function wrappedAFunc() { + exports.aFunc = function wrappedAFunc () { return aFunc() + '-wrapped' } }) -import { - default as bar, - foo, - aFunc, - baz -} from '../fixtures/bundle.mjs' - strictEqual(bar(), '42-wrapped') strictEqual(foo(), 'foo-wrapped') strictEqual(aFunc(), 'a-wrapped') diff --git a/test/hook/v14-declaration-exports.mjs b/test/hook/v14-declaration-exports.mjs index a66746f..be44835 100644 --- a/test/hook/v14-declaration-exports.mjs +++ b/test/hook/v14-declaration-exports.mjs @@ -5,22 +5,22 @@ import Hook from '../../index.js' import { name1 as n1, - name2 as n2, - name3 as n3, + name2 as n2, + name3 as n3, name4 as n4, - ClassName as cn, - generatorFunctionName as gfn, - name5 as n5, - bar as n6, - name7 as n7, + ClassName as cn, + generatorFunctionName as gfn, + name5 as n5, + bar as n6, + name7 as n7, name8 as n8, asyncFunctionName as afn, asyncGeneratorFunctionName as agfn, arrowFunction as arfn, - asyncArrowFunction as aarfn, - } from '../fixtures/export-types/declarations.mjs' + asyncArrowFunction as aarfn + , functionName +} from '../fixtures/export-types/declarations.mjs' import { strictEqual } from 'assert' -import { functionName } from '../fixtures/export-types/declarations.mjs' Hook((exports, name) => { if (name.match(/declarations\.m?js/)) { @@ -36,7 +36,7 @@ Hook((exports, name) => { return 2 } const orig2 = exports.generatorFunctionName - exports.generatorFunctionName = function* () { + exports.generatorFunctionName = function * () { return orig2().next().value + 1 } exports.name5 += 1 @@ -48,9 +48,9 @@ Hook((exports, name) => { return await asyncOrig() + 1 } const asyncOrig2 = exports.asyncGeneratorFunctionName - exports.asyncGeneratorFunctionName = async function* () { + exports.asyncGeneratorFunctionName = async function * () { for await (const value of asyncOrig2()) { - yield value + 1; + yield value + 1 } } const arrowOrig = exports.arrowFunction @@ -69,6 +69,7 @@ strictEqual(n2, 2) strictEqual(n3, 2) strictEqual(n4, 2) strictEqual(functionName(), 2) +/* eslint-disable new-cap */ strictEqual(new cn().getFoo(), 2) strictEqual(gfn().next().value, 2) strictEqual(n5, 2) diff --git a/test/hook/v18.19-static-import-gotalike.mjs b/test/hook/v18.19-static-import-gotalike.mjs index 81946b0..c6ec006 100644 --- a/test/hook/v18.19-static-import-gotalike.mjs +++ b/test/hook/v18.19-static-import-gotalike.mjs @@ -14,6 +14,8 @@ Hook((exports, name) => { } }) +/* eslint-disable import/no-named-default */ +/* eslint-disable camelcase */ import { default as Got, something, @@ -26,7 +28,7 @@ strictEqual(something(), '42-wrapped') const got = new Got() strictEqual(got.foo, 'foo') -const dc = new DefaultClass +const dc = new DefaultClass() strictEqual(dc.value, 'DefaultClass') strictEqual(snake_case, 'snake_case') diff --git a/test/low-level/dynamic-import-default.js b/test/low-level/dynamic-import-default.js index 945ef4b..7014186 100644 --- a/test/low-level/dynamic-import-default.js +++ b/test/low-level/dynamic-import-default.js @@ -8,7 +8,7 @@ const { strictEqual } = require('assert') addHook((name, exports) => { if (name.match(/something\.m?js/)) { const orig = exports.default - exports.default = function bar() { + exports.default = function bar () { return orig() + 15 } } diff --git a/test/low-level/dynamic-import-default.mjs b/test/low-level/dynamic-import-default.mjs index ead51c4..fe29dbc 100644 --- a/test/low-level/dynamic-import-default.mjs +++ b/test/low-level/dynamic-import-default.mjs @@ -8,7 +8,7 @@ import { strictEqual } from 'assert' addHook((name, exports) => { if (name.match(/something\.m?js/)) { const orig = exports.default - exports.default = function bar() { + exports.default = function bar () { return orig() + 15 } } diff --git a/test/low-level/static-import-default.mjs b/test/low-level/static-import-default.mjs index de12d96..97283e2 100644 --- a/test/low-level/static-import-default.mjs +++ b/test/low-level/static-import-default.mjs @@ -10,7 +10,7 @@ import { strictEqual } from 'assert' addHook((name, exports) => { if (name.match(/something\.m?js/)) { const orig = exports.default - exports.default = function bar() { + exports.default = function bar () { return orig() + 15 } } diff --git a/test/other/v14-assert-cyclical-dependency-failure.mjs b/test/other/v14-assert-cyclical-dependency-failure.mjs index 2fcb663..173b692 100644 --- a/test/other/v14-assert-cyclical-dependency-failure.mjs +++ b/test/other/v14-assert-cyclical-dependency-failure.mjs @@ -6,12 +6,12 @@ import { spawn } from 'child_process' import { strictEqual } from 'assert' const nodeProcess = spawn('node', [ - '--loader', - './hook.mjs', + '--loader', + './hook.mjs', './test/fixtures/cyclical-a.mjs' ]) -// expected output should be 'testB\ntestA' but the hook fails when running against files +// expected output should be 'testB\ntestA' but the hook fails when running against files // with cylical dependencies const expectedOutput = 'testB\ntestA' let stdout = '' @@ -19,13 +19,18 @@ let stderr = '' nodeProcess.stdout.on('data', (data) => { stdout += data.toString() -}); +}) nodeProcess.stderr.on('data', (data) => { stderr += data.toString() -}); +}) nodeProcess.on('close', (code) => { // assert that the hook fails with a non-zero exit code - strictEqual(code === 1 || code === 13, true); -}); \ No newline at end of file + strictEqual(code === 1 || code === 13, true) + + // satisfy linter complaining about unused variables + strictEqual(expectedOutput, expectedOutput) + strictEqual(typeof stdout, 'string') + strictEqual(typeof stderr, 'string') +}) diff --git a/test/typescript/iitm-ts-node-loader.mjs b/test/typescript/iitm-ts-node-loader.mjs index 3d753b9..45c3b41 100644 --- a/test/typescript/iitm-ts-node-loader.mjs +++ b/test/typescript/iitm-ts-node-loader.mjs @@ -7,12 +7,12 @@ const makeNext = (loader, fnName, parentResolveOrLoad) => { } } -export async function resolve(specifier, context, defaultResolve) { +export async function resolve (specifier, context, defaultResolve) { const next = makeNext(tsNode, 'resolve', defaultResolve) return iitm.resolve(specifier, context, next) } -export async function load(url, context, defaultLoad) { - let next = makeNext(tsNode, 'load', defaultLoad) +export async function load (url, context, defaultLoad) { + const next = makeNext(tsNode, 'load', defaultLoad) return iitm.load(url, context, next) -} \ No newline at end of file +}