From 13a735bda4b76369accde0b40d9df8dd4ff120e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 16 Oct 2023 15:44:52 +0800 Subject: [PATCH] feat!: switch the recommended config to flat refs: https://github.com/eslint/eslint/blob/c572ea35c81267d08985242b0eacaecc611e3bc7/docs/src/extend/plugin-migration-flat-config.md --- README.md | 8 ++++---- index.js | 46 +++++++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 8d5a648..e149735 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,12 @@ yarn add --dev eslint-plugin-security ## Usage -Add the following to your `.eslintrc` file: +Add the following to your `eslint.config.js` file: ```js -"extends": [ - "plugin:security/recommended" -] +const pluginSecurity = require('eslint-plugin-security'); + +module.exports = [pluginSecurity.configs.recommended]; ``` ## Developer guide diff --git a/index.js b/index.js index 3125dcb..e77966f 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ const pkg = require('./package.json'); -module.exports = { +const plugin = { meta: { name: pkg.name, version: pkg.version, @@ -43,25 +43,29 @@ module.exports = { 'detect-new-buffer': 0, 'detect-bidi-characters': 0, }, - configs: { - recommended: { - plugins: ['security'], - rules: { - 'security/detect-buffer-noassert': 'warn', - 'security/detect-child-process': 'warn', - 'security/detect-disable-mustache-escape': 'warn', - 'security/detect-eval-with-expression': 'warn', - 'security/detect-new-buffer': 'warn', - 'security/detect-no-csrf-before-method-override': 'warn', - 'security/detect-non-literal-fs-filename': 'warn', - 'security/detect-non-literal-regexp': 'warn', - 'security/detect-non-literal-require': 'warn', - 'security/detect-object-injection': 'warn', - 'security/detect-possible-timing-attacks': 'warn', - 'security/detect-pseudoRandomBytes': 'warn', - 'security/detect-unsafe-regex': 'warn', - 'security/detect-bidi-characters': 'warn', - }, - }, + configs: {}, // was assigned later so we can reference `plugin` +}; + +const recommended = { + plugins: { security: plugin }, + rules: { + 'security/detect-buffer-noassert': 'warn', + 'security/detect-child-process': 'warn', + 'security/detect-disable-mustache-escape': 'warn', + 'security/detect-eval-with-expression': 'warn', + 'security/detect-new-buffer': 'warn', + 'security/detect-no-csrf-before-method-override': 'warn', + 'security/detect-non-literal-fs-filename': 'warn', + 'security/detect-non-literal-regexp': 'warn', + 'security/detect-non-literal-require': 'warn', + 'security/detect-object-injection': 'warn', + 'security/detect-possible-timing-attacks': 'warn', + 'security/detect-pseudoRandomBytes': 'warn', + 'security/detect-unsafe-regex': 'warn', + 'security/detect-bidi-characters': 'warn', }, }; + +Object.assign(plugin.configs, { recommended }); + +module.exports = plugin;