Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: re-enable no-undef rule for tests #974

Merged
merged 2 commits into from Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions .eslintrc.js
Expand Up @@ -55,9 +55,6 @@ module.exports = {
// base rules; none of these are in eslint/recommended
'no-empty': ['error', { allowEmptyCatch: true }],

// @typescript-eslint/no-unused-vars is more robust
'no-unused-vars': 'off',

// additional errors not in n/recommended
'n/callback-return': 'error',
'n/handle-callback-err': 'error',
Expand Down Expand Up @@ -126,6 +123,8 @@ module.exports = {
rules: {
// eslint-plugin-n does not understand typescript imports
'n/no-missing-import': 'off',
// eslint doesn't understand typescript
'no-unused-vars': 'off'
},
parser: '@typescript-eslint/parser',
},
Expand Down
5 changes: 3 additions & 2 deletions packages/browserify/test/generatePolicy.spec.js
@@ -1,5 +1,5 @@
/* eslint-disable ava/use-t-well */
/* eslint-disable no-undef */
/* eslint-disable no-unused-vars, ava/use-t-well */

const test = require('ava')

const { autoConfigForScenario } = require('./util')
Expand Down Expand Up @@ -38,6 +38,7 @@ test('generatePolicy - ignore various refs', async (t) => {
const scenario = createScenarioFromScaffold({
defineOne: () => {
const js = [this]
// eslint-disable-next-line no-undef
const ignored = [global, require, module, exports, arguments]
const globalRefs = [typeof globalThis, typeof self, typeof window]
global.xyz
Expand Down
4 changes: 3 additions & 1 deletion packages/browserify/test/globalRef.spec.js
@@ -1,4 +1,6 @@
/* eslint-disable no-undef */
// eslint-disable-next-line no-unused-vars
/* global checkThis: true, checkSelf: true, checkWindow: true, checkGlobal: true */

const test = require('ava')
const { runScenario } = require('./util')
const {
Expand Down
6 changes: 1 addition & 5 deletions packages/browserify/test/sourcemaps.js
Expand Up @@ -16,9 +16,8 @@ async function verifySourceMaps({ bundle, log = console.error.bind(console) }) {
}

async function verifyWithSourceExplorer(bundle) {
let result
try {
result = await explore({ code: Buffer.from(bundle, 'utf8') })
await explore({ code: Buffer.from(bundle, 'utf8') })
} catch (resultWithError) {
if (resultWithError.errors) {
resultWithError.errors.forEach((exploreError) => {
Expand All @@ -40,15 +39,12 @@ async function verifySamples(bundle, log) {
log('SourcemapValidator - missing content of some sources...')
}

let sampleCount = 0

const buildLines = bundle.split('\n')
const targetString = 'module.exports'
const matchesPerLine = buildLines.map((line) => indicesOf(targetString, line))
const errors = []
matchesPerLine.forEach((matchIndices, lineIndex) => {
matchIndices.forEach((matchColumn) => {
sampleCount += 1
const position = { line: lineIndex + 1, column: matchColumn }
const result = consumer.originalPositionFor(position)
// warn if source content is missing
Expand Down
18 changes: 10 additions & 8 deletions packages/core/lib/strict-scope-terminator.js
Expand Up @@ -24,11 +24,10 @@ const d = (strings, args) => strings.join() + args.join()
const q = (arg) => arg

/**
* alwaysThrowHandler
* This is an object that throws if any property is called. It's used as
* a proxy handler which throws on any trap called.
* It's made from a proxy with a get trap that throws. It's safe to
* create one and share it between all Proxy handlers.
* AlwaysThrowHandler This is an object that throws if any property is called.
* It's used as a proxy handler which throws on any trap called. It's made from
* a proxy with a get trap that throws. It's safe to create one and share it
* between all Proxy handlers.
*/
const alwaysThrowHandler = new Proxy(
immutableObject,
Expand All @@ -42,16 +41,19 @@ const alwaysThrowHandler = new Proxy(
)

/**
* 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".
* 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 = {
// eslint-disable-next-line no-unused-vars
get(_shadow, _prop) {
return undefined
},

// eslint-disable-next-line no-unused-vars
set(_shadow, prop, _value) {
// We should only hit this if the has() hook returned true matches the v8
// ReferenceError message "Uncaught ReferenceError: xyz is not defined"
Expand Down
3 changes: 2 additions & 1 deletion packages/core/test/globals.spec.js
@@ -1,4 +1,5 @@
/* eslint-disable no-undef, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* global abc: true, xyz, chrome */

const test = require('ava')
const { createScenarioFromScaffold, runScenario } = require('./util')
Expand Down
2 changes: 1 addition & 1 deletion packages/lavapack/test/index.spec.js
@@ -1,6 +1,6 @@
const fs = require('fs')
const test = require('ava')
const { pipe, from, concat } = require('mississippi')
const { pipe, concat } = require('mississippi')
const { SourceMapConsumer } = require('source-map')
const convertSourceMap = require('convert-source-map')
const pack = require('../src')
Expand Down
2 changes: 2 additions & 0 deletions packages/lavapack/test/sourcemaps.spec.js
Expand Up @@ -13,6 +13,7 @@ test.skip('sourcemaps - adjust maps for wrapper', async (t) => {
var three = two + 1
`

// eslint-disable-next-line no-undef
const result = UglifyJS.minify(
{ './foo.js': fooSource },
{
Expand Down Expand Up @@ -52,6 +53,7 @@ function indicesOf(substring, string) {
// this is not perfecct - just a heuristic
async function validateSourcemaps(t, sourceMeta) {
const targetSlug = 'new Error'
// eslint-disable-next-line no-undef
const consumer = await new SourceMapConsumer(sourceMeta.maps)
t.true(consumer.hasContentsOfAllSources(), 'has the contents of all sources')

Expand Down
1 change: 1 addition & 0 deletions packages/laverna/test/laverna.spec.js
Expand Up @@ -135,6 +135,7 @@ test.beforeEach((t) => {
* @param {import('node:child_process').SpawnOptions} opts
* @returns {import('node:events').EventEmitter}
*/
// eslint-disable-next-line no-unused-vars
(cmd, args, opts) => {
const ee = new EventEmitter()
setImmediate(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/tofu/test/findGlobals.spec.js
Expand Up @@ -2,7 +2,6 @@

const fs = require('fs')
const path = require('path')
const assert = require('assert')
const test = require('ava')
const { parse } = require('../src/index')
const { findGlobals } = require('../src/findGlobals')
Expand Down
3 changes: 2 additions & 1 deletion packages/tofu/test/inspectGlobals.spec.js
@@ -1,4 +1,5 @@
/* eslint-disable no-undef */
/* eslint-disable no-unused-vars */
/* global xyz: true, zzz, a, b, c, z: true, abc: true, manifest */

const { EOL } = require('node:os')
const test = require('ava')
Expand Down
1 change: 1 addition & 0 deletions packages/tofu/test/inspectImports.spec.js
Expand Up @@ -41,6 +41,7 @@ testInspect(
'cjs - include even if declared var is unused',
{},
() => {
// eslint-disable-next-line no-unused-vars
const rfs = require('fs').readFileSync
},
{
Expand Down
6 changes: 1 addition & 5 deletions packages/tofu/test/inspectPrimordialAssignments.spec.js
@@ -1,9 +1,5 @@
const test = require('ava')
const {
parse,
inspectPrimordialAssignments,
environmentTypes,
} = require('../src/index')
const { parse, inspectPrimordialAssignments } = require('../src/index')

function inspectPrimordialAssignmentsTest(code) {
return inspectPrimordialAssignments(parse(code))
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/test/e2e-hack.spec.js
@@ -1,6 +1,6 @@
const test = require('ava')
// eslint-disable-next-line ava/no-import-test-files
const { scaffold, runScriptWithSES, runScript } = require('./scaffold.js')
const { scaffold, runScriptWithSES } = require('./scaffold.js')
const webpackConfigDefault = require('./fixtures/main/webpack.config.js')

test.before(async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/test/scaffold.js
Expand Up @@ -2,7 +2,7 @@ const path = require('path')
const webpack = require('webpack')
const memfs = require('memfs')
const { toSnapshotSync } = require('memfs/lib/snapshot')
const { createContext, Script, runInNewContext } = require('vm')
const { createContext, runInNewContext } = require('vm')
const { readFileSync } = require('fs')

/**
Expand Down