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

TypeError: Cannot read properties of undefined (reading 'loc') #84

Open
BePo65 opened this issue Dec 9, 2024 · 0 comments
Open

TypeError: Cannot read properties of undefined (reading 'loc') #84

BePo65 opened this issue Dec 9, 2024 · 0 comments

Comments

@BePo65
Copy link

BePo65 commented Dec 9, 2024

I use eslint with the eslint-plugin-security-node. Running the tests, I got an error "TypeError: Cannot read properties of undefined (reading 'loc')".

Using the eslint extension in VsCode, I get no error there.

Any idea about what happened here?

Environment

Version : 1.1.4
Node.js : 20.18.0
Eslint: 9.16.0

Used Code

import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import { pipeline } from 'node:stream/promises';

import { stub } from 'sinon';
import StreamTest from 'streamtest';

import config from '../lib/config.js';
import { getFormatter } from '../lib/formatter.js';

describe('FormatterWritable', () => {
  let testConfig;

  beforeEach(() => {
    testConfig = structuredClone(config);
  });

  it('creates a writable with json formatter', async () => {
    const consoleStub = stub(console, 'log');
    testConfig.output = 'json';
    const outputFormatter = getFormatter(testConfig.output);

    const resultPromise = new Promise((resolve, reject) => {
      StreamTest.fromObjects([EXPECTED_RESULT_CLASSIFICATION])  // <<<< this is line 69 mentioned in the error message
        .pipe(new FormatterWritable(outputFormatter, testConfig))
        .on('finish', resolve)
        .on('error', reject);
    });

    await resultPromise;
    const expectedResult = JSON.stringify(EXPECTED_RESULT_CLASSIFICATION);

    assert(consoleStub.calledOnce);
    assert.deepStrictEqual(consoleStub.firstCall.firstArg, expectedResult);

   consoleStub.restore();
  });
});

What actually happened?

Oops! Something went wrong! :(

ESLint: 9.16.0

TypeError: Cannot read properties of undefined (reading 'loc')
Occurred while linting D:\Projekte\github\license-report-check\test\util-stream.spec.js:69
Rule: "security-node/detect-unhandled-event-errors"
    at CallExpression (D:\Projekte\github\license-report-check\node_modules\eslint-plugin-security-node\lib\rules\detect-unhandled-event-errors.js:133:43)
    at ruleErrorHandler (D:\Projekte\github\license-report-check\node_modules\eslint\lib\linter\linter.js:1098:48)
    at D:\Projekte\github\license-report-check\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (D:\Projekte\github\license-report-check\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (D:\Projekte\github\license-report-check\node_modules\eslint\lib\linter\node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (D:\Projekte\github\license-report-check\node_modules\eslint\lib\linter\node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (D:\Projekte\github\license-report-check\node_modules\eslint\lib\linter\node-event-generator.js:337:14)
    at runRules (D:\Projekte\github\license-report-check\node_modules\eslint\lib\linter\linter.js:1142:40)
    at #flatVerifyWithoutProcessors (D:\Projekte\github\license-report-check\node_modules\eslint\lib\linter\linter.js:1911:31)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant