How to use the eslint-plugin-sonarjs.configs function in eslint-plugin-sonarjs

To help you get started, we’ve selected a few eslint-plugin-sonarjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github swissquote / crafty / packages / eslint-plugin-swissquote / src / best-practices.js View on Github external
"error",
      {
        requireReturn: false,
        requireReturnDescription: false
      }
    ],
    "valid-typeof": "error",
    "@swissquote/swissquote/sonarjs/no-duplicate-string": ["error", 10]
  }
};

// Eslint can't load plugins transitively (from a shared config)
// So we have to include the file ourselves and include the rules as if they were ours.
// Solution proposed by @nzakas himself : https://github.com/eslint/eslint/issues/3458#issuecomment-257161846
// replaces `extends: "plugin:sonarjs/recommended",`
const sonarRules = require("eslint-plugin-sonarjs").configs.recommended.rules;
Object.keys(sonarRules).forEach(ruleName => {
  // Only define the rules we don't have configured yet
  const key = `@swissquote/swissquote/${ruleName}`;
  if (!module.exports.rules.hasOwnProperty(key)) {
    module.exports.rules[key] = sonarRules[ruleName];
  }
});