TypeError in sonar eslint plugin

  • Operating system: MacOS 14.5
  • SonarLint plugin version: eslint-plugin-sonarjs: 2.0.4
  • Programming language you’re coding in: Typescript
  • ESlint 9.14.0

I’m running into the error below when trying to run npx eslint . with the recommended sonar eslint configuration.

Oops! Something went wrong! :(

ESLint: 9.14.0

TypeError: Cannot read properties of undefined (reading 'meta')
    at decorate (/Users/project/node_modules/eslint-plugin-sonarjs/cjs/S1116/decorator.js:12:65)
    at Object.<anonymous> (/Users/project/node_modules/eslint-plugin-sonarjs/cjs/S1116/index.js:25:44)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/Users/project/node_modules/eslint-plugin-sonarjs/cjs/decorated.js:56:19)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)

I have eslint configured like so:

module.exports = [
  // other flat config stuff...
  sonarjs.configs.recommended,
  {
    plugins: {
      sonarjs,
    },
  },
  // more stuff...
];

@David_Gettins thanks for the report.

The rule no-extra-semi, which is failing here, is not enabled in the recommended configuration. Can you confirm that you are enabling it in your ESLint configuration module? If possible, can you share the whole configuration file so that we can try and reproduce the issue?

Thanks,

Eric.

No I am not explicitly enabling any of the sonar lint properties, just using the recommended config as shown.

So I have just re-applied my changes and now things are working as expected. Sorry to bother you with this.

I’m not 100% sure what caused the original error.

1 Like

Great news, @David_Gettins.

If the issue happens again, or you have some new information about it, don’t hesitate to amend this ticket.

1 Like

I get this exact error too.

if I

cd node_modules/eslint-plugin-sonarjs/cjs/S1116
node index.js

This error is produced as well. For an easy way to reproduce this :slight_smile:

Oops! Something went wrong! :(

ESLint: 9.15.0

TypeError: Cannot read properties of undefined (reading 'meta')
    at decorate (C:\Users\BradleyArlt\source\system-admin-another\web\node_modules\eslint-plugin-sonarjs\cjs\S1116\decorator.js:12:65)
    at Object.<anonymous> (C:\Users\BradleyArlt\source\system-admin-another\web\node_modules\eslint-plugin-sonarjs\cjs\S1116\index.js:25:44)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (C:\Users\BradleyArlt\source\system-admin-another\web\node_modules\eslint-plugin-sonarjs\cjs\decorated.js:56:19)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)

As a hack/workaround:

Change remove fixable from meta,js and use rule?.meta instead of rule.meta.

That removes the error at startup