diff --git a/packages/aa/src/index.js b/packages/aa/src/index.js index a7e074a776..acc6589d05 100644 --- a/packages/aa/src/index.js +++ b/packages/aa/src/index.js @@ -1,4 +1,4 @@ -const { readFileSync, statSync } = require('fs') +const { readFileSync } = require('fs') const path = require('path') const nodeResolve = require('resolve') @@ -31,7 +31,7 @@ function createPerformantResolve () { readPackageSync: readPackageWithout(path), }), } -}; +} /** * @param {object} options @@ -39,7 +39,7 @@ function createPerformantResolve () { */ async function loadCanonicalNameMap({ rootDir, includeDevDeps, resolve } = {}) { const canonicalNameMap = new Map() - // performant resolve avoids loading package.jsons if their path is what's being resolved, + // performant resolve avoids loading package.jsons if their path is what's being resolved, // offering 2x performance improvement compared to using original resolve resolve = resolve || createPerformantResolve() // resolve = resolve || nodeResolve @@ -87,7 +87,8 @@ let nextLevelTodos * @param {object} options * @returns {Map<{packageDir: string, logicalPathParts: string[]}>} */ -function walkDependencyTreeForBestLogicalPaths({ packageDir, logicalPath = [], includeDevDeps = false, visited = new Set(), resolve = performantResolve }) { +function walkDependencyTreeForBestLogicalPaths({ packageDir, logicalPath = [], includeDevDeps = false, visited = new Set(), resolve }) { + resolve = resolve ?? createPerformantResolve() const preferredPackageLogicalPathMap = new Map() // add the entry package as the first work unit currentLevelTodos = [{ packageDir, logicalPath, includeDevDeps, visited, resolve }] diff --git a/packages/allow-scripts/src/index.js b/packages/allow-scripts/src/index.js index 1b5c5b47b5..4e85ded8c0 100644 --- a/packages/allow-scripts/src/index.js +++ b/packages/allow-scripts/src/index.js @@ -17,13 +17,13 @@ const setup = require('./setup') * @property {BinsConfig} configs.bin * @property {boolean} somePoliciesAreMissing * - * Individual package info + * Individual package info * @typedef {Object} PkgInfo * @property {string} canonicalName * @property {string} path * @property {Object} scripts * - * Individual bin link info + * Individual bin link info * @typedef {Object} BinInfo * @property {string} canonicalName * @property {boolean} isDirect @@ -41,7 +41,7 @@ const setup = require('./setup') * @property {Array} missingPolicies * @property {Array} excessPolicies * - * @typedef {Map} BinCandidates + * @typedef {Map} BinCandidates * * Configuration for a type of bins policies * @typedef {Object} BinsConfig @@ -193,8 +193,8 @@ function printMissingPoliciesIfAny({ missingPolicies = [], packagesWithScripts = // internals /** - * - * @param {Object} arg + * + * @param {Object} arg * @param {string} arg.event * @param {Array} arg.packages */ @@ -207,7 +207,7 @@ async function runAllScriptsForEvent({ event, packages }) { } } /** - * @param {Array} allowedBins + * @param {Array} allowedBins */ async function installBinScripts(allowedBins) { for (const { bin, path, link, canonicalName } of allowedBins) { @@ -217,7 +217,7 @@ async function installBinScripts(allowedBins) { } /** * Points all bins on the list to whichbin.js cli app from allow-scripts - * @param {Array} firewalledBins + * @param {Array} firewalledBins * @param {string} link - absolute path to the whichbin.js script */ async function installBinFirewall(firewalledBins, link) { @@ -250,7 +250,7 @@ async function runScript({ path, event }) { const bannedBins = new Set(['node', 'npm', 'yarn', 'pnpm']) /** - * @param {BinCandidates} binCandidates + * @param {BinCandidates} binCandidates */ function prepareBinScriptsPolicy(binCandidates) { const policy = {} @@ -267,7 +267,7 @@ function prepareBinScriptsPolicy(binCandidates) { /** - * @param {BinsConfig} param0 + * @param {BinsConfig} param0 */ function printPackagesByBins({ allowedBins, @@ -292,7 +292,7 @@ function printPackagesByBins({ } /** - * @param {ScriptsConfig} param0 + * @param {ScriptsConfig} param0 */ function printPackagesByScriptConfiguration({ packagesWithScripts, @@ -340,8 +340,8 @@ function printPackagesByScriptConfiguration({ } /** - * - * @param {Object} args + * + * @param {Object} args * @param {string} args.rootDir * @param {PkgConfs} args.conf * @returns {Promise} @@ -362,8 +362,8 @@ async function savePackageConfigurations({ rootDir, conf: { } /** - * - * @param {Object} args + * + * @param {Object} args * @param {string} args.rootDir * @returns {Promise} */ @@ -372,13 +372,14 @@ async function loadAllPackageConfigurations({ rootDir }) { const binCandidates = new Map() const dependencyMap = await loadCanonicalNameMap({ rootDir, includeDevDeps: true }) - const sortedDepEntries = Array.from(dependencyMap.entries()).sort(sortBy(([filePath, canonicalName]) => canonicalName)) + const sortedDepEntries = Array.from(dependencyMap.entries()).sort(sortBy(([, canonicalName]) => canonicalName)) const packageJson = JSON.parse(await fs.readFile(path.join(rootDir, 'package.json'), 'utf8')) const directDeps = new Set([...Object.keys(packageJson.devDependencies||{}),...Object.keys(packageJson.dependencies||{})]) for (const [filePath, canonicalName] of sortedDepEntries) { // const canonicalName = getCanonicalNameForPath({ rootDir, filePath: filePath }) let depPackageJson + // eslint-disable-next-line no-useless-catch try { depPackageJson = JSON.parse(await fs.readFile(path.join(filePath, 'package.json'), 'utf-8')) } catch (err) { @@ -412,7 +413,7 @@ async function loadAllPackageConfigurations({ rootDir }) { } collection.push({ // canonical name for a direct dependency is just dependency name - isDirect: directDeps.has(canonicalName), + isDirect: directDeps.has(canonicalName), bin: name, path: filePath, link, @@ -455,9 +456,9 @@ function indexLifecycleConfiguration(config) { // packages with config const configuredPatterns = Object.keys(config.allowConfig) // select allowed + disallowed - config.allowedPatterns = Object.entries(config.allowConfig).filter(([pattern, packageData]) => !!packageData).map(([pattern]) => pattern) + config.allowedPatterns = Object.entries(config.allowConfig).filter(([, packageData]) => !!packageData).map(([pattern]) => pattern) - config.disallowedPatterns = Object.entries(config.allowConfig).filter(([pattern, packageData]) => !packageData).map(([pattern]) => pattern) + config.disallowedPatterns = Object.entries(config.allowConfig).filter(([, packageData]) => !packageData).map(([pattern]) => pattern) config.missingPolicies = Array.from(config.packagesWithScripts.keys()) .filter(pattern => !configuredPatterns.includes(pattern)) diff --git a/packages/allow-scripts/src/linker.js b/packages/allow-scripts/src/linker.js index 4dfdf9c786..4e1648df6d 100644 --- a/packages/allow-scripts/src/linker.js +++ b/packages/allow-scripts/src/linker.js @@ -1,6 +1,5 @@ // @ts-check // All of this is derived from the main functionality of bin-links that unfortunately would not allow for absolute path links -const { promises: fs } = require('fs') const binTarget = require('bin-links/lib/bin-target.js') const isWindows = require('bin-links/lib/is-windows.js') const linkBin = isWindows ? require('bin-links/lib/shim-bin.js') : require('bin-links/lib/link-bin.js') diff --git a/packages/allow-scripts/test/index.js b/packages/allow-scripts/test/index.js index 05a9e3e668..91dcb110d2 100644 --- a/packages/allow-scripts/test/index.js +++ b/packages/allow-scripts/test/index.js @@ -89,10 +89,10 @@ test('cli - run command - good dep at the root', (t) => { // assert the output t.deepEqual(result.stdout.toString().split('\n'), [ - 'running lifecycle scripts for event \"preinstall\"', + 'running lifecycle scripts for event "preinstall"', '- good_dep', - 'running lifecycle scripts for event \"install\"', - 'running lifecycle scripts for event \"postinstall\"', + 'running lifecycle scripts for event "install"', + 'running lifecycle scripts for event "postinstall"', 'running lifecycle scripts for top level package', '', ]) @@ -124,10 +124,10 @@ test('cli - run command - good dep at the root with experimental bins', (t) => { t.deepEqual(result.stdout.toString().split('\n'), [ 'installing bin scripts', '- good - from package: good_dep', - 'running lifecycle scripts for event \"preinstall\"', + 'running lifecycle scripts for event "preinstall"', '- good_dep', - 'running lifecycle scripts for event \"install\"', - 'running lifecycle scripts for event \"postinstall\"', + 'running lifecycle scripts for event "install"', + 'running lifecycle scripts for event "postinstall"', 'running lifecycle scripts for top level package', '', ]) @@ -166,10 +166,10 @@ test('cli - run command - good dep as a sub dep', (t) => { // assert the output t.deepEqual(result.stdout.toString().split('\n'), [ - 'running lifecycle scripts for event \"preinstall\"', + 'running lifecycle scripts for event "preinstall"', '- bbb>good_dep', - 'running lifecycle scripts for event \"install\"', - 'running lifecycle scripts for event \"postinstall\"', + 'running lifecycle scripts for event "install"', + 'running lifecycle scripts for event "postinstall"', '- bbb', 'running lifecycle scripts for top level package', '', @@ -205,10 +205,10 @@ test('cli - run command - good dep as a sub dep with experimental bins', (t) => t.deepEqual(result.stdout.toString().split('\n'), [ 'installing bin scripts', '- good - from package: aaa', - 'running lifecycle scripts for event \"preinstall\"', + 'running lifecycle scripts for event "preinstall"', '- bbb>good_dep', - 'running lifecycle scripts for event \"install\"', - 'running lifecycle scripts for event \"postinstall\"', + 'running lifecycle scripts for event "install"', + 'running lifecycle scripts for event "postinstall"', '- bbb', '', ]) diff --git a/packages/browserify/src/index.js b/packages/browserify/src/index.js index b0de0d6fea..d66172b5fc 100644 --- a/packages/browserify/src/index.js +++ b/packages/browserify/src/index.js @@ -277,7 +277,7 @@ function validatePolicy (policy) { throw new Error('LavaMoat - Expected label \'resources\' for configuration key') } - Object.entries(policy.resources).forEach(([packageName, packageOpts], index) => { + Object.entries(policy.resources).forEach(([, packageOpts]) => { const packageOptions = Object.keys(packageOpts) const packageEntries = Object.values(packageOpts) const optionsWhitelist = ['globals', 'packages'] diff --git a/packages/browserify/test/basic.js b/packages/browserify/test/basic.js index 5682adf453..250fc1ad5a 100644 --- a/packages/browserify/test/basic.js +++ b/packages/browserify/test/basic.js @@ -47,7 +47,7 @@ test('basic - lavamoat policy and bundle', async (t) => { }) await autoConfigForScenario({ scenario }) const { bundleForScenario } = await createBundleForScenario({ scenario }) - + t.true(bundleForScenario.includes('"location.href":true'), 'prelude includes href policy') const testHref = 'https://funky.town.gov/yolo?snake=yes' @@ -74,7 +74,7 @@ test('basic - lavamoat bundle without prelude', async (t) => { let didCallLoadBundle = false const testGlobal = { LavaPack: { loadBundle: () => { - didCallLoadBundle = true + didCallLoadBundle = true } }, } evalBundle(bundleForScenario, testGlobal) diff --git a/packages/browserify/test/generatePolicy.js b/packages/browserify/test/generatePolicy.js index 7d8f5cd189..50743a1850 100644 --- a/packages/browserify/test/generatePolicy.js +++ b/packages/browserify/test/generatePolicy.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ const test = require('ava') const { @@ -19,7 +20,7 @@ test('generatePolicy - empty policy', async (t) => { test('generatePolicy - basic policy', async (t) => { const scenario = createScenarioFromScaffold({ defineOne: () => { - module.exports = global.two + module.exports = global.two }, defaultPolicy: false, }) @@ -83,6 +84,8 @@ test('generatePolicy - policy ignores global refs', async (t) => { test('generatePolicy - policy ignores global refs when properties are not accessed', async (t) => { const scenario = createScenarioFromScaffold({ defineOne: () => { + // XXX: this is probably wrong. either use `typeof window === 'undefined'` or `window === undefined` + // eslint-disable-next-line valid-typeof typeof window !== undefined }, defaultPolicy: false, diff --git a/packages/core/lib/strict-scope-terminator.js b/packages/core/lib/strict-scope-terminator.js index 2641151ccd..3d2e1a906b 100644 --- a/packages/core/lib/strict-scope-terminator.js +++ b/packages/core/lib/strict-scope-terminator.js @@ -41,11 +41,11 @@ const alwaysThrowHandler = new Proxy( }), ) -/* - * scopeProxyHandlerProperties +/** * scopeTerminatorHandler manages a strictScopeTerminator Proxy which serves as * the final scope boundary that will always return "undefined" in order * to prevent access to "start compartment globals". + * @type {ProxyHandler} */ const scopeProxyHandlerProperties = { get(_shadow, _prop) { diff --git a/packages/core/src/generateKernel.js b/packages/core/src/generateKernel.js index 9782e4cdd7..c557d16432 100644 --- a/packages/core/src/generateKernel.js +++ b/packages/core/src/generateKernel.js @@ -39,6 +39,7 @@ function generateKernel (_opts = {}) { output = replaceTemplateRequire(output, 'ses', sesSrc) output = stringReplace(output, '__createKernelCore__', kernelCode) output = stringReplace(output, '__lavamoatDebugOptions__', JSON.stringify({debugMode: !!opts.debugMode})) + // eslint-disable-next-line no-prototype-builtins if (opts?.hasOwnProperty('scuttleGlobalThis')) { // scuttleGlobalThis config placeholder should be set only if ordered so explicitly. // if not, should be left as is to be replaced by a later processor (e.g. LavaPack). diff --git a/packages/core/src/generatePolicy.js b/packages/core/src/generatePolicy.js index 96a9bc40c1..f20cf660c5 100644 --- a/packages/core/src/generatePolicy.js +++ b/packages/core/src/generatePolicy.js @@ -59,6 +59,7 @@ function createModuleInspector (opts = {}) { } } + // eslint-disable-next-line no-unused-vars function inspectBuiltinModule (moduleRecord) { // builtins themselves do not require any configuration // packages that import builtins need to add that to their configuration @@ -189,7 +190,7 @@ function createModuleInspector (opts = {}) { function inspectForImports (ast, moduleRecord, packageName, isBuiltin, includeDebugInfo) { // get all requested names that resolve to isBuiltin const namesForBuiltins = Object.entries(moduleRecord.importMap) - .filter(([_, resolvedName]) => isBuiltin(resolvedName)) + .filter(([, resolvedName]) => isBuiltin(resolvedName)) .map(([requestedName]) => requestedName) const { cjsImports: moduleBuiltins } = inspectImports(ast, namesForBuiltins) if (!moduleBuiltins.length) { diff --git a/packages/core/src/kernelCoreTemplate.js b/packages/core/src/kernelCoreTemplate.js index 900bfbc187..3e353c2e8d 100644 --- a/packages/core/src/kernelCoreTemplate.js +++ b/packages/core/src/kernelCoreTemplate.js @@ -146,12 +146,14 @@ const obj = Object.create(null) for (const prop of props) { + // eslint-disable-next-line no-inner-declarations function set() { console.warn( `LavaMoat - property "${prop}" of globalThis cannot be set under scuttling mode. ` + 'To learn more visit https://github.com/LavaMoat/LavaMoat/pull/360.', ) } + // eslint-disable-next-line no-inner-declarations function get() { throw new Error( `LavaMoat - property "${prop}" of globalThis is inaccessible under scuttling mode. ` + @@ -230,6 +232,7 @@ // this is passed to the module initializer // it adds the context of the parent module // this could be replaced via "Function.prototype.bind" if its more performant + // eslint-disable-next-line no-inner-declarations function requireRelativeWithContext (requestedName) { const parentModuleExports = moduleObj.exports const parentModuleData = moduleData @@ -248,7 +251,8 @@ const parentModulePackageName = parentModuleData.package const parentPackagesWhitelist = parentPackagePolicy.packages const parentBuiltinsWhitelist = Object.entries(parentPackagePolicy.builtin) - .filter(([_, allowed]) => allowed === true) + .filter(([, allowed]) => allowed === true) + // eslint-disable-next-line no-unused-vars .map(([packagePath, allowed]) => packagePath.split('.')[0]) // resolve the moduleId from the requestedName @@ -298,6 +302,7 @@ // grab all allowed builtin paths that match this package .filter(([packagePath, allowed]) => allowed === true && moduleId === packagePath.split('.')[0]) // only include the paths after the packageName + // eslint-disable-next-line no-unused-vars .map(([packagePath, allowed]) => packagePath.split('.').slice(1).join('.')) .sort() ) @@ -475,7 +480,7 @@ // transform functions, getters & setters on prop descs. Solves SES scope proxy bug Object.entries(Object.getOwnPropertyDescriptors(endowments)) // ignore non-configurable properties because we are modifying endowments in place - .filter(([key, propDesc]) => propDesc.configurable) + .filter(([, propDesc]) => propDesc.configurable) .forEach(([key, propDesc]) => { const wrappedPropDesc = applyEndowmentPropDescTransforms(propDesc, packageCompartment, rootPackageCompartment.globalThis) Reflect.defineProperty(endowments, key, wrappedPropDesc) diff --git a/packages/core/src/kernelTemplate.js b/packages/core/src/kernelTemplate.js index 195574d3c1..de8d73048b 100644 --- a/packages/core/src/kernelTemplate.js +++ b/packages/core/src/kernelTemplate.js @@ -48,6 +48,7 @@ // create the SES rootRealm // "templateRequire" calls are inlined in "generateKernel" // load-bearing semi-colon, do not remove + // eslint-disable-next-line no-extra-semi ;templateRequire('ses') const lockdownOptions = { diff --git a/packages/core/src/makeGetEndowmentsForConfig.js b/packages/core/src/makeGetEndowmentsForConfig.js index 5c0089f64a..f7491ecce0 100644 --- a/packages/core/src/makeGetEndowmentsForConfig.js +++ b/packages/core/src/makeGetEndowmentsForConfig.js @@ -43,7 +43,7 @@ function makeGetEndowmentsForConfig ({ createFunctionWrapper }) { // false means no access. It's necessary so that overrides can also be used to tighten the policy if (configValue === false) { explicitlyBanned.push(path) - return + return } // write access handled elsewhere if (configValue === 'write') { @@ -238,6 +238,7 @@ function makeGetEndowmentsForConfig ({ createFunctionWrapper }) { function getPropertyDescriptorDeep (target, key) { let receiver = target + // eslint-disable-next-line no-constant-condition while (true) { // abort if this is the end of the prototype chain. if (!receiver) { diff --git a/packages/core/test/util.js b/packages/core/test/util.js index 24ae614b3d..6be8e082f7 100644 --- a/packages/core/test/util.js +++ b/packages/core/test/util.js @@ -234,7 +234,7 @@ function createHookedConsole () { let hasResolved = false let resolve const firstLogEventPromise = new Promise(_resolve => { - resolve = _resolve + resolve = _resolve }) const hookedLog = (message) => { if (hasResolved) { @@ -359,7 +359,6 @@ function fillInFileDetails (files) { if (path.extname(file) === '.js') { // parse as LavamoatModuleRecord fileObj.specifier = fileObj.file || file - fileObj.packageName = fileObj.packageName fileObj.type = fileObj.type || 'js' fileObj.entry = Boolean(fileObj.entry) } @@ -374,7 +373,7 @@ function moduleDataForBuiltin (builtinObj, name) { package: name, type: 'builtin', moduleInitializer: (_, _2, module) => { - module.exports = builtinObj[name] + module.exports = builtinObj[name] }, } } diff --git a/packages/lavapack/src/pack.js b/packages/lavapack/src/pack.js index 0a3e341e12..a8e7eca51e 100644 --- a/packages/lavapack/src/pack.js +++ b/packages/lavapack/src/pack.js @@ -53,6 +53,8 @@ function createPacker({ policy = {}, // prune policy to only include packages used in the bundle prunePolicy = false, + // XXX: what is this? + // eslint-disable-next-line no-unused-vars externalRequireName, sourceRoot, sourceMapPrefix, @@ -232,7 +234,7 @@ function createPacker({ } function serializeModule (moduleData, sourceMeta) { - const { id, packageName, source, deps, file } = moduleData + const { id, packageName, deps, file } = moduleData const relativeFilePath = file && path.relative(basedir, file) // for now, ignore new sourcemap and just append original filename // serialize final module entry diff --git a/packages/lavapack/src/runtime-cjs-template.js b/packages/lavapack/src/runtime-cjs-template.js index 807d42ffd3..304f91b98d 100644 --- a/packages/lavapack/src/runtime-cjs-template.js +++ b/packages/lavapack/src/runtime-cjs-template.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line no-extra-semi ;(function() { function getGlobalRef () { if (typeof globalThis !== 'undefined') { @@ -43,6 +44,7 @@ } // it is called by the modules collection that will be appended to this file + // eslint-disable-next-line no-unused-vars function loadBundle (newModules, entryPoints, bundlePolicy) { // ignore bundlePolicy as we wont be enforcing it // verify + load in each module diff --git a/packages/lavapack/src/runtime-template.js b/packages/lavapack/src/runtime-template.js index 8baff71ad6..0513208a16 100644 --- a/packages/lavapack/src/runtime-template.js +++ b/packages/lavapack/src/runtime-template.js @@ -1,3 +1,5 @@ +/* eslint-disable no-unused-vars */ +// eslint-disable-next-line no-extra-semi ;(function() { // this runtime template code is destined to wrap LavaMoat entirely, // therefore this is our way of capturing access to basic APIs LavaMoat diff --git a/packages/perf/build.js b/packages/perf/build.js index 2ae013bb66..35bf397591 100644 --- a/packages/perf/build.js +++ b/packages/perf/build.js @@ -32,6 +32,7 @@ const bundler = browserify(['./entry.js'], { // build +// eslint-disable-next-line no-unused-vars async function main () { fs.mkdirSync('./bundle', { recursive: true }) await performBundle() diff --git a/packages/perf/endo.js b/packages/perf/endo.js index 956b34a513..40834b9604 100644 --- a/packages/perf/endo.js +++ b/packages/perf/endo.js @@ -59,7 +59,7 @@ async function main () { path: await addToCompartment('path', require('path')), fs: await addToCompartment('fs', require('fs')), } - + const readPowers = makeReadPowers({ fs, url, crypto }) const moduleLocation = url.pathToFileURL(process.cwd() + '/entry.js') @@ -81,7 +81,7 @@ async function main () { ) function makeSesModuleTransform (language) { - return function sesModuleTransform (sourceBytes, _speciefier, _location) { + return function sesModuleTransform (sourceBytes) { const transformedSource = _applySesEvasions(sourceBytes.toString()) const bytes = Buffer.from(transformedSource, 'utf8') return { bytes, parser: language } @@ -99,13 +99,13 @@ async function main () { return result } - + function applySesEvasions (source) { return applyTransforms(source, [ evadeHtmlCommentTest, evadeImportExpressionTest, (src) => { - const someDirectEvalPattern = /(^|[^.])\beval(\s*\()/g + const someDirectEvalPattern = /(^|[^.])\beval(\s*\()/g return src.replaceAll(someDirectEvalPattern, '$1(0,eval)(') }, ]) diff --git a/packages/survey/src/downloadPackage.js b/packages/survey/src/downloadPackage.js index 31e7492a99..3ee00214a8 100644 --- a/packages/survey/src/downloadPackage.js +++ b/packages/survey/src/downloadPackage.js @@ -1,7 +1,7 @@ const util = require('util') const execFile = util.promisify(require('child_process').execFile) const { promises: fs } = require('fs') -const { resolve } = require('path') +const { resolve, join } = require('path') module.exports = { downloadPackage, @@ -9,10 +9,8 @@ module.exports = { async function downloadPackage (packageName) { - const downloadDir = resolve(__dirname + '/../downloads') + const downloadDir = resolve(join(__dirname, '..', 'downloads')) const packageDir = `${downloadDir}/${packageName}` await fs.rmdir(packageDir, { recursive: true }) - const { stdout, stderr } = await execFile(__dirname + '/download.sh', [packageName, packageDir]) - // console.log(stdout) - // console.info(stderr) + await execFile(join(__dirname, 'download.sh'), [packageName, packageDir]) } diff --git a/packages/survey/src/execTest.js b/packages/survey/src/execTest.js index 3ea861b58c..712641b8d2 100644 --- a/packages/survey/src/execTest.js +++ b/packages/survey/src/execTest.js @@ -7,7 +7,7 @@ const { spawn, exec: execCb } = require('child_process') const exec = promisify(execCb) const makeTempDir = async () => { - return await fs.mkdtemp(path.join(os.tmpdir(), 'lavamoat-survey-')) + return await fs.mkdtemp(path.join(os.tmpdir(), 'lavamoat-survey-')) } const mitmPath = new URL('../mitm', `file://${__filename}`).pathname @@ -42,12 +42,12 @@ async function prepareRepo ({ projectDir, gitRepo, gitRef }) { } async function installDependencies ({ projectDir }) { - const { stdout, stderr } = await exec('yarn install', { cwd: projectDir }) + await exec('yarn install', { cwd: projectDir }) console.log('deps installed') } async function runPlainTests ({ projectDir }) { - const { stdout, stderr } = await exec('yarn run test', { cwd: projectDir }) + await exec('yarn run test', { cwd: projectDir }) console.log('tests passed directly') } diff --git a/packages/survey/src/getTopPackages.js b/packages/survey/src/getTopPackages.js index 3d3d57cc95..b1e29037e7 100644 --- a/packages/survey/src/getTopPackages.js +++ b/packages/survey/src/getTopPackages.js @@ -10,6 +10,8 @@ module.exports = { getTopPackages, } +// XXX: remove if unneeded +// eslint-disable-next-line no-unused-vars const npmDependentsScraper = createScraper({ buildUrl: ({ offset }) => `https://www.npmjs.com/browse/depended?offset=${offset}`, entrySelector: '.flex-row.pr3', @@ -43,7 +45,7 @@ const librariesIoRankScraper = createScraper({ }) async function getTopPackages () { - const indexPath = path.resolve(__dirname + '/../downloads/index.json') + const indexPath = path.resolve(__dirname, '..', 'downloads', 'index.json') try { const indexContent = await fs.readFile(indexPath, 'utf8') return JSON.parse(indexContent) @@ -77,7 +79,7 @@ function createScraper ({ buildUrl, entrySelector, packagesPerPage, maxResults } }), { concurrency: 8 }) return pageResults.flat().slice(0, count) } - + async function downloadPage (page) { const offset = page * packagesPerPage const url = buildUrl({ page, offset }) diff --git a/packages/survey/src/index.js b/packages/survey/src/index.js index 5fd3df6e7c..3da8a99eef 100644 --- a/packages/survey/src/index.js +++ b/packages/survey/src/index.js @@ -80,18 +80,18 @@ async function generateConfigFile (packageName) { } async function generatePolicy (packageName) { - const { package, packageDir } = await loadPackage(packageName) + const { package: pkg, packageDir } = await loadPackage(packageName) // if main is explicitly empty, skip (@types/node, etc) - if (package.main === '') { + if (pkg.main === '') { console.warn(`skipped "${packageName}" - explicitly no entry`) return { resources: {} } } // normalize the id as a relative path - const entryId = './' + path.relative('./', package.main || 'index.js') + const entryId = './' + path.relative('./', pkg.main || 'index.js') const resolveHook = makeResolveHook({ cwd: packageDir }) - let entryFull + try { - entryFull = resolveHook(entryId, `${packageDir}/package.json`) + resolveHook(entryId, `${packageDir}/package.json`) } catch (err) { if (err.code === 'MODULE_NOT_FOUND') { console.warn(`skipped "${packageName}" - no entry`) @@ -117,7 +117,6 @@ async function generatePolicy (packageName) { async function writeConfig (packageName, config) { const configContent = JSON.stringify(config, null, 2) const policyPath = getPolicyPath(packageName) - const policyDir = path.dirname(policyPath) // ensure dir exists (this includes the package scope) await fs.mkdir(path.dirname(policyPath), { recursive: true }) await fs.writeFile(policyPath, configContent) diff --git a/packages/survey/src/load.js b/packages/survey/src/load.js index 7fa87ec135..5943afd33c 100644 --- a/packages/survey/src/load.js +++ b/packages/survey/src/load.js @@ -1,5 +1,3 @@ -const util = require('util') -const { promises: fs } = require('fs') const { resolve } = require('path') const { downloadPackage } = require('./downloadPackage.js') const { fileExists } = require('./util.js') @@ -10,7 +8,7 @@ module.exports = { async function loadPackage (packageName) { - const downloadDir = resolve(__dirname + '/../downloads') + const downloadDir = resolve(__dirname, '..', 'downloads') const packageDir = `${downloadDir}/${packageName}` const packageJsonPath = `${packageDir}/package.json` const exists = await fileExists(packageJsonPath) @@ -18,7 +16,7 @@ async function loadPackage (packageName) { console.info(`downloading ${packageName}`) await downloadPackage(packageName) } - const package = require(packageJsonPath) - return { package, packageDir } + const pkg = require(packageJsonPath) + return { package: pkg, packageDir } } diff --git a/packages/survey/src/parseForPolicy.js b/packages/survey/src/parseForPolicy.js index 22ab055588..65dc137d67 100644 --- a/packages/survey/src/parseForPolicy.js +++ b/packages/survey/src/parseForPolicy.js @@ -1,5 +1,5 @@ const path = require('path') -const { parseForPolicy: nodeParseForConfig, makeResolveHook, makeImportHook } = require('lavamoat/src/parseForPolicy') +const { makeResolveHook, makeImportHook } = require('lavamoat/src/parseForPolicy') const { builtinModules: builtinPackages } = require('module') const { inspectSesCompat, codeSampleFromAstNode } = require('lavamoat-tofu') const { walk } = require('lavamoat-core/src/walk') diff --git a/packages/survey/src/prepareHook.js b/packages/survey/src/prepareHook.js index ef422817aa..0a447382dc 100644 --- a/packages/survey/src/prepareHook.js +++ b/packages/survey/src/prepareHook.js @@ -10,6 +10,7 @@ const path = require('path') const node = process.env.NVM_BIN ? `${process.env.NVM_BIN}/node` : process.argv[0] const npxPath = path.resolve(node, '../npx') const lavamoat = require.resolve('lavamoat/src/index.js') +// eslint-disable-next-line no-unused-vars const lockdown = new URL('../src/lockdown.cjs', `file://${__filename}`).pathname const mitm = new URL('../mitm/node', `file://${__filename}`).pathname diff --git a/packages/tofu/src/inspectSource.js b/packages/tofu/src/inspectSource.js index 1a2320ab50..f960a98912 100644 --- a/packages/tofu/src/inspectSource.js +++ b/packages/tofu/src/inspectSource.js @@ -107,7 +107,7 @@ function inspectGlobals (source, { } } -function inspectEsmImports (ast, packagesToInspect) { +function inspectEsmImports (ast) { const esmImports = [] traverse(ast, { ImportDeclaration: (path) => { diff --git a/packages/tofu/test/inspectEsmImports.js b/packages/tofu/test/inspectEsmImports.js index 88a3ca9b65..30e56e62eb 100644 --- a/packages/tofu/test/inspectEsmImports.js +++ b/packages/tofu/test/inspectEsmImports.js @@ -52,6 +52,7 @@ function testInspect (label, opts, fn, expectedResultObj) { label, opts, ast, source console.log(resultSorted) console.log(expectedSorted) + // eslint-disable-next-line no-debugger debugger } diff --git a/packages/tofu/test/inspectGlobals.js b/packages/tofu/test/inspectGlobals.js index 72385d5b7f..4484b8d7b6 100644 --- a/packages/tofu/test/inspectGlobals.js +++ b/packages/tofu/test/inspectGlobals.js @@ -132,6 +132,8 @@ testInspect('not picking up js language features', { testInspect('ignore globalRef without property lookup', { globalRefs: ['window'], }, () => { + // XXX: this is probably wrong. either use `typeof window === 'undefined'` or `window === undefined` + // eslint-disable-next-line valid-typeof typeof window === undefined }, {}) @@ -274,6 +276,7 @@ function testInspect (label, opts, fn, expectedResultObj) { // for debugging if (!deepEqual(resultSorted, expectedSorted)) { label, opts + // eslint-disable-next-line no-debugger debugger } diff --git a/packages/tofu/test/inspectImports.js b/packages/tofu/test/inspectImports.js index 974d3e7fe1..d893347cb9 100644 --- a/packages/tofu/test/inspectImports.js +++ b/packages/tofu/test/inspectImports.js @@ -94,6 +94,7 @@ function testInspect (label, opts, fn, expectedResultObj) { label, opts console.log(resultSorted) console.log(expectedSorted) + // eslint-disable-next-line no-debugger debugger } diff --git a/packages/viz/bin/index.js b/packages/viz/bin/index.js index 565ddcbdbd..add7ecebb4 100755 --- a/packages/viz/bin/index.js +++ b/packages/viz/bin/index.js @@ -91,7 +91,6 @@ async function main () { console.info('serving a pre-built dashboard. to generate new dashboard and serve use "lavamoat-viz --serve"') console.info('this is equivalent to "npx serve ./viz"') console.info('\n') - const fullDest = path.resolve(dest) return await serveViz(dest) } default: { diff --git a/packages/viz/src/App.js b/packages/viz/src/App.js index 9afc3fe9ca..7426f5d22e 100644 --- a/packages/viz/src/App.js +++ b/packages/viz/src/App.js @@ -11,7 +11,7 @@ const { DepGraph } = require('./graphs/DepGraph.js') const { LavamoatPolicies } = globalThis // merge all configs into final -for (const [policyName, policyData] of Object.entries(LavamoatPolicies)) { +for (const [, policyData] of Object.entries(LavamoatPolicies)) { if (!policyData.final) { if (policyData.override) { policyData.final = mergePolicy(policyData.primary, policyData.override) @@ -27,7 +27,7 @@ const defaultPolicyName = policyNames[0] class App extends Component { selectPolicy (target) { - this.setState(state => ({ policyName: target })) + this.setState(() => ({ policyName: target })) } render () { diff --git a/packages/viz/src/graphs/DepGraph.js b/packages/viz/src/graphs/DepGraph.js index 0246160f9a..ecfa800d40 100644 --- a/packages/viz/src/graphs/DepGraph.js +++ b/packages/viz/src/graphs/DepGraph.js @@ -327,7 +327,9 @@ class DepGraph extends React.Component { onHoverStart: ({ object: { name: nodeId } }, controller) => { setControllerText(controller, `${nodeId}`) }, - onSelectStart: ({ object: { name: nodeId } }, controller) => { + onSelectStart: ({ object: { name: nodeId } }) => { + // FIXME: this is most certainly broken + // eslint-disable-next-line no-undef actions.selectPackage(nodeId) }, controller1, diff --git a/packages/viz/src/graphs/buffer-geometry-controller.js b/packages/viz/src/graphs/buffer-geometry-controller.js index 8ebca1a317..e9de2d00f6 100644 --- a/packages/viz/src/graphs/buffer-geometry-controller.js +++ b/packages/viz/src/graphs/buffer-geometry-controller.js @@ -45,7 +45,7 @@ export class BufferGeometryController { } // update draw range. check position attribute size to see if // we are counting indices or vertices - const [_, count] = this.attributeSizes.position + const [, count] = this.attributeSizes.position this.geometry.setDrawRange(0, (itemCount + 1) * count) return index } @@ -130,7 +130,7 @@ export class InstancedBufferGeometryController { } // update draw range. check position attribute size to see if // we are counting indices or vertices - const [_, count] = this.attributeSizes.position + const [, count] = this.attributeSizes.position this.geometry.setDrawRange(0, (itemCount + 1) * count) return index } diff --git a/packages/viz/src/graphs/points-controller.js b/packages/viz/src/graphs/points-controller.js index dd97c65a52..be541d9e2b 100644 --- a/packages/viz/src/graphs/points-controller.js +++ b/packages/viz/src/graphs/points-controller.js @@ -1,4 +1,4 @@ -import { Mesh, CircleGeometry, Points, PointsMaterial, ShaderMaterial, RawShaderMaterial, TextureLoader } from 'three' +import { Mesh, CircleGeometry, RawShaderMaterial, TextureLoader } from 'three' import { InstancedBufferGeometryController } from './buffer-geometry-controller.js' const vertexShader2 = ` @@ -27,7 +27,7 @@ void main() { mvPosition.xyz += position * scale * size; gl_Position = projectionMatrix * mvPosition; - + vUv = uv; vColor = color; } diff --git a/packages/viz/src/graphs/utils/utils.js b/packages/viz/src/graphs/utils/utils.js index a4b331e2b9..86677255ce 100644 --- a/packages/viz/src/graphs/utils/utils.js +++ b/packages/viz/src/graphs/utils/utils.js @@ -43,7 +43,7 @@ function parseConfigDebugForPackages (policyName, policyDebugData, policyFinal) const { debugInfo } = policyDebugData const { resources } = policyFinal // aggregate info under package name - Object.entries(debugInfo).forEach(([_, moduleDebugInfo]) => { + Object.entries(debugInfo).forEach(([, moduleDebugInfo]) => { const { moduleRecord } = moduleDebugInfo const packageId = moduleRecord.packageName let packageData = packages[packageId] @@ -79,7 +79,7 @@ function parseConfigDebugForPackages (policyName, policyDebugData, policyFinal) }) }) // modify danger rank - Object.entries(packages).forEach(([_, packageData]) => { + Object.entries(packages).forEach(([, packageData]) => { const dangerRank = getDangerRankForPackage(packageData, envConfig) packageData.dangerRank = dangerRank }) @@ -97,7 +97,7 @@ function createGraph (packages, policyFinal, { const nodes = [] const links = [] // for each module, create node and links - Object.entries(packages).forEach(([_, packageData]) => { + Object.entries(packages).forEach(([, packageData]) => { const { importMap } = packageData const packageId = packageData.id // skip hidden packages @@ -332,7 +332,7 @@ function sortByKey (key, reverse = false) { return aVal > bVal ? reverseVal : -reverseVal } } - + export { parseConfigDebugForPackages, diff --git a/packages/viz/src/graphs/vr-viz/forcegraph.js b/packages/viz/src/graphs/vr-viz/forcegraph.js index 79d4b5b807..421304db2c 100644 --- a/packages/viz/src/graphs/vr-viz/forcegraph.js +++ b/packages/viz/src/graphs/vr-viz/forcegraph.js @@ -34,7 +34,7 @@ export class FastThreeForceGraph extends Group { collisionObject.visible = false return collisionObject }) - .linkThreeObject((link) => { + .linkThreeObject(() => { // create dummy object, only used to statisy ThreeForceGraph const dummyObject = new Object3D() dummyObject.visible = false @@ -47,7 +47,7 @@ export class FastThreeForceGraph extends Group { // override link position update return true }) - + this.graph.visible = false this.collisionObjects = this.graph.children diff --git a/packages/viz/src/index.js b/packages/viz/src/index.js index a8b37496b9..978d095380 100644 --- a/packages/viz/src/index.js +++ b/packages/viz/src/index.js @@ -5,7 +5,7 @@ import 'codemirror/lib/codemirror.css' import './css/index.css' import App from './App.js' import * as serviceWorker from './serviceWorker.js' -import ScratchPad from './scene.js' +import './scene.js' ReactDOM.render(, document.getElementById('root')) // ReactDOM.render(, document.getElementById('root')) diff --git a/packages/viz/src/merge-deep.js b/packages/viz/src/merge-deep.js index b78b3e108c..8d86cb5896 100644 --- a/packages/viz/src/merge-deep.js +++ b/packages/viz/src/merge-deep.js @@ -13,7 +13,7 @@ var union = require('arr-union') var clone = require('clone-deep') var typeOf = require('kind-of') -module.exports = function mergeDeep(orig, objects) { +module.exports = function mergeDeep(orig) { if (!isObject(orig) && !Array.isArray(orig)) { orig = {} } diff --git a/packages/viz/src/scene.js b/packages/viz/src/scene.js index fee7df3239..ec168df171 100644 --- a/packages/viz/src/scene.js +++ b/packages/viz/src/scene.js @@ -78,7 +78,7 @@ export default class ScratchPad extends ThreeComponent { const graph = new FastThreeForceGraph({ graphData: packageData }) this.graph = graph const scale = 0.1 - graph.scale.set(scale, scale, scale) + graph.scale.set(scale, scale, scale) this.scene.add(graph) this.animateListeners = [] diff --git a/packages/viz/src/three-component.js b/packages/viz/src/three-component.js index d93bceb35e..613257e9d7 100644 --- a/packages/viz/src/three-component.js +++ b/packages/viz/src/three-component.js @@ -30,7 +30,7 @@ export default class ThreeComponent extends React.Component { // // scene.add(floor); // this.scene.add(new THREE.HemisphereLight(0x808080, 0x606060)) - + // this.renderer = new THREE.WebGLRenderer({ // canvas: this.canvas, // antialias: false, @@ -78,8 +78,8 @@ export default class ThreeComponent extends React.Component { window.addEventListener('resize', this.onWindowResize) } - componentDidUpdate(prevProps, prevState) { - // Pass updated props to + componentDidUpdate() { + // Pass updated props to const newValue = this.props.whateverProperty this.updateValue(newValue) } @@ -100,7 +100,7 @@ export default class ThreeComponent extends React.Component { this.renderer.setSize(innerWidth, innerHeight) } - updateValue (value) { + updateValue () { // Whatever you need to do with React props }