From 81651ea1e2693cf1cb7b387239c895ed26edb9d7 Mon Sep 17 00:00:00 2001
From: Milos Djermanovic <milos.djermanovic@gmail.com>
Date: Sun, 9 Jul 2023 12:36:04 +0200
Subject: [PATCH] [eslint] switch to `eslint.config.js`

---
 .eslint-doc-generatorrc.js |   2 +
 .eslintrc                  |  82 -----------------------
 eslint.config.js           | 130 +++++++++++++++++++++++++++++++++++++
 package.json               |   4 +-
 4 files changed, 135 insertions(+), 83 deletions(-)
 delete mode 100644 .eslintrc
 create mode 100644 eslint.config.js

diff --git a/.eslint-doc-generatorrc.js b/.eslint-doc-generatorrc.js
index 1e6d1717f3..24ea5cd094 100644
--- a/.eslint-doc-generatorrc.js
+++ b/.eslint-doc-generatorrc.js
@@ -1,3 +1,5 @@
+'use strict';
+
 /** @type {import('eslint-doc-generator').GenerateOptions} */
 const config = {
   configEmoji: [
diff --git a/.eslintrc b/.eslintrc
deleted file mode 100644
index 4991f200f2..0000000000
--- a/.eslintrc
+++ /dev/null
@@ -1,82 +0,0 @@
-{
-    "root": true,
-    "extends": ["airbnb-base", "plugin:eslint-plugin/recommended"],
-    "plugins": ["eslint-plugin"],
-    "env": {
-       "es6": true,
-       "node": true
-    },
-    "parserOptions": {
-      "ecmaVersion": 6,
-      "ecmaFeatures": {
-        "jsx": true
-      },
-      "sourceType": "script",
-    },
-    "ignorePatterns": [
-      "coverage/",
-      ".nyc_output/",
-    ],
-    "rules": {
-        "comma-dangle": [2, "always-multiline"],
-        "object-shorthand": [2, "always", {
-          "ignoreConstructors": false,
-          "avoidQuotes": false, // this is the override vs airbnb
-        }],
-        "max-len": [2, 120, {
-          "ignoreStrings": true,
-          "ignoreTemplateLiterals": true,
-          "ignoreComments": true,
-        }],
-        "consistent-return": 0,
-
-        "prefer-destructuring": [2, { "array": false, "object": false }, { "enforceForRenamedProperties": false }],
-        "prefer-object-spread": 0, // until node 8 is required
-        "prefer-rest-params": 0, // until node 6 is required
-        "prefer-spread": 0, // until node 6 is required
-        "function-call-argument-newline": 1, // TODO: enable
-        "function-paren-newline": 0,
-        "no-plusplus": [2, {"allowForLoopAfterthoughts": true}],
-        "no-param-reassign": 1,
-        "no-restricted-syntax": [2, {
-            "selector": "ObjectPattern",
-            "message": "Object destructuring is not compatible with Node v4"
-        }],
-        "strict": [2, "safe"],
-        "valid-jsdoc": [2, {
-          "requireReturn": false,
-          "requireParamDescription": false,
-          "requireReturnDescription": false,
-        }],
-
-        "eslint-plugin/consistent-output": 0,
-        "eslint-plugin/require-meta-docs-description": [2, { "pattern": "^(Enforce|Require|Disallow)" }],
-        "eslint-plugin/require-meta-schema": 0,
-        "eslint-plugin/require-meta-type": 0
-    },
-    "overrides": [
-      {
-        "files": "tests/**",
-        "rules": {
-          "no-template-curly-in-string": 1,
-        },
-      },
-      {
-        "files": "markdown.config.js",
-        "rules": {
-          "no-console": 0,
-        },
-      },
-      {
-        "files": ".github/workflows/*.js",
-        "parserOptions": {
-          "ecmaVersion": 2019,
-        },
-        "rules": {
-          "camelcase": 0,
-          "no-console": 0,
-          "no-restricted-syntax": 0,
-        },
-      },
-    ],
-}
diff --git a/eslint.config.js b/eslint.config.js
new file mode 100644
index 0000000000..8006e90a7f
--- /dev/null
+++ b/eslint.config.js
@@ -0,0 +1,130 @@
+'use strict';
+
+const globals = require('globals');
+const eslintPluginRecommended = require('eslint-plugin-eslint-plugin/configs/recommended');
+
+const FlatCompat = require('@eslint/eslintrc').FlatCompat;
+
+const eslintrc = new FlatCompat({
+  baseDirectory: __dirname,
+});
+
+module.exports = [
+  {
+    ignores: [
+      'coverage/',
+      '.nyc_output/',
+    ],
+  },
+  ...eslintrc.extends('airbnb-base'),
+  eslintPluginRecommended,
+  {
+    languageOptions: {
+      ecmaVersion: 6,
+      sourceType: 'commonjs',
+      parserOptions: {
+        ecmaFeatures: {
+          jsx: true,
+        },
+      },
+      globals: globals.node,
+    },
+    rules: {
+      'comma-dangle': [2, 'always-multiline'],
+      'object-shorthand': [2, 'always', {
+        ignoreConstructors: false,
+        avoidQuotes: false, // this is the override vs airbnb
+      }],
+      'max-len': [2, 120, {
+        ignoreStrings: true,
+        ignoreTemplateLiterals: true,
+        ignoreComments: true,
+      }],
+      'consistent-return': 0,
+
+      'prefer-destructuring': [2, { array: false, object: false }, { enforceForRenamedProperties: false }],
+      'prefer-object-spread': 0, // until node 8 is required
+      'prefer-rest-params': 0, // until node 6 is required
+      'prefer-spread': 0, // until node 6 is required
+      'function-call-argument-newline': 1, // TODO: enable
+      'function-paren-newline': 0,
+      'no-plusplus': [2, { allowForLoopAfterthoughts: true }],
+      'no-param-reassign': 1,
+      'no-restricted-syntax': [2, {
+        selector: 'ObjectPattern',
+        message: 'Object destructuring is not compatible with Node v4',
+      }],
+      strict: [2, 'safe'],
+      'valid-jsdoc': [2, {
+        requireReturn: false,
+        requireParamDescription: false,
+        requireReturnDescription: false,
+      }],
+
+      'eslint-plugin/consistent-output': 0,
+      'eslint-plugin/require-meta-docs-description': [2, { pattern: '^(Enforce|Require|Disallow)' }],
+      'eslint-plugin/require-meta-schema': 0,
+      'eslint-plugin/require-meta-type': 0,
+
+      // overrides airbnb config to add `eslint.config.js` to `devDependencies`
+      'import/no-extraneous-dependencies': [
+        'error',
+        {
+          devDependencies: [
+            'test/**',
+            'tests/**',
+            'spec/**',
+            '**/__tests__/**',
+            '**/__mocks__/**',
+            'test.{js,jsx}',
+            'test-*.{js,jsx}',
+            '**/*{.,_}{test,spec}.{js,jsx}',
+            '**/jest.config.js',
+            '**/jest.setup.js',
+            '**/vue.config.js',
+            '**/webpack.config.js',
+            '**/webpack.config.*.js',
+            '**/rollup.config.js',
+            '**/rollup.config.*.js',
+            '**/gulpfile.js',
+            '**/gulpfile.*.js',
+            '**/Gruntfile{,.js}',
+            '**/protractor.conf.js',
+            '**/protractor.conf.*.js',
+            '**/karma.conf.js',
+            '**/.eslintrc.js',
+            'eslint.config.js',
+          ],
+          optionalDependencies: false,
+        },
+      ],
+    },
+  },
+  {
+    files: ['tests/**'],
+    languageOptions: {
+      globals: globals.mocha,
+    },
+    rules: {
+      'no-template-curly-in-string': 1,
+    },
+  },
+  {
+    files: ['markdown.config.js'],
+    rules: {
+      'no-console': 0,
+    },
+  },
+  {
+    files: ['.github/workflows/*.js'],
+    languageOptions: {
+      ecmaVersion: 2019,
+    },
+    rules: {
+      camelcase: 0,
+      'no-console': 0,
+      'no-restricted-syntax': 0,
+    },
+  },
+
+];
diff --git a/package.json b/package.json
index cb736434ab..bb6f42acd5 100644
--- a/package.json
+++ b/package.json
@@ -48,6 +48,7 @@
     "@babel/plugin-syntax-do-expressions": "^7.18.6",
     "@babel/plugin-syntax-function-bind": "^7.18.6",
     "@babel/preset-react": "^7.18.6",
+    "@eslint/eslintrc": "^2.1.0",
     "@types/eslint": "=7.2.10",
     "@types/estree": "0.0.52",
     "@types/node": "^4.9.5",
@@ -57,12 +58,13 @@
     "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8",
     "eslint-config-airbnb-base": "^15.0.0",
     "eslint-doc-generator": "^1.4.3",
-    "eslint-plugin-eslint-plugin": "^2.3.0 || ^3.5.3 || ^4.0.1 || ^5.0.5",
+    "eslint-plugin-eslint-plugin": "^2.3.0 || ^3.5.3 || ^4.0.1 || ^5.1.0",
     "eslint-plugin-import": "^2.27.5",
     "eslint-remote-tester": "^3.0.0",
     "eslint-remote-tester-repositories": "^1.0.0",
     "eslint-scope": "^3.7.3",
     "espree": "^3.5.4",
+    "globals": "^13.20.0",
     "istanbul": "^0.4.5",
     "jackspeak": "=2.1.1",
     "ls-engines": "^0.8.1",