From b546a7e6dbac679099ad57ba2db075d6a92dcad6 Mon Sep 17 00:00:00 2001 From: tamiroh Date: Tue, 12 Nov 2024 23:53:55 +0900 Subject: [PATCH] Add flat config support --- packages/eslint-config-airbnb-base/README.md | 12 +++++++++ packages/eslint-config-airbnb-base/flat.js | 26 +++++++++++++++++++ .../eslint-config-airbnb-base/package.json | 4 ++- .../rules/flat/es6.js | 12 +++++++++ .../rules/flat/imports.js | 17 ++++++++++++ .../rules/flat/node.js | 11 ++++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 packages/eslint-config-airbnb-base/flat.js create mode 100644 packages/eslint-config-airbnb-base/rules/flat/es6.js create mode 100644 packages/eslint-config-airbnb-base/rules/flat/imports.js create mode 100644 packages/eslint-config-airbnb-base/rules/flat/node.js diff --git a/packages/eslint-config-airbnb-base/README.md b/packages/eslint-config-airbnb-base/README.md index 6ddc34dac1..c9e181551b 100644 --- a/packages/eslint-config-airbnb-base/README.md +++ b/packages/eslint-config-airbnb-base/README.md @@ -62,6 +62,18 @@ Our default export contains all of our ESLint rules, including ECMAScript 6+. It 2. Add `"extends": "airbnb-base"` to your .eslintrc. + If using flat config, you can import `"eslint-config-airbnb-base/flat"` on your `eslint.config.mjs` file like this: + + ```javascript + import airbnbBase from "eslint-config-airbnb-base/flat"; + + export default [ + ...airbnbBase, + // Add your own configs + ]; + ``` + + ### eslint-config-airbnb-base/legacy Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`. diff --git a/packages/eslint-config-airbnb-base/flat.js b/packages/eslint-config-airbnb-base/flat.js new file mode 100644 index 0000000000..3852de0d42 --- /dev/null +++ b/packages/eslint-config-airbnb-base/flat.js @@ -0,0 +1,26 @@ +const index = require('./index'); +const bestPractices = require('./rules/best-practices'); +const errors = require('./rules/errors'); +const node = require('./rules/flat/node'); +const style = require('./rules/style'); +const variables = require('./rules/variables'); +const es6 = require('./rules/flat/es6'); +const imports = require('./rules/flat/imports'); +const strict = require('./rules/strict'); + +module.exports = [ + bestPractices, + errors, + node, + style, + variables, + es6, + imports, + strict, + { + languageOptions: { + parserOptions: index.parserOptions, + }, + rules: {}, + } +]; diff --git a/packages/eslint-config-airbnb-base/package.json b/packages/eslint-config-airbnb-base/package.json index 8f039d4d7c..f4e1e04499 100644 --- a/packages/eslint-config-airbnb-base/package.json +++ b/packages/eslint-config-airbnb-base/package.json @@ -5,6 +5,7 @@ "main": "index.js", "exports": { ".": "./index.js", + "./flat": "./flat.js", "./legacy": "./legacy.js", "./whitespace": "./whitespace.js", "./rules/best-practices": "./rules/best-practices.js", @@ -87,6 +88,7 @@ "node": "^10.12.0 || >=12.0.0" }, "dependencies": { - "confusing-browser-globals": "^1.0.11" + "confusing-browser-globals": "^1.0.11", + "globals": "^15.12.0" } } diff --git a/packages/eslint-config-airbnb-base/rules/flat/es6.js b/packages/eslint-config-airbnb-base/rules/flat/es6.js new file mode 100644 index 0000000000..38b94171cd --- /dev/null +++ b/packages/eslint-config-airbnb-base/rules/flat/es6.js @@ -0,0 +1,12 @@ +const es6 = require('../es6'); +const globals = require('globals'); + +module.exports = { + languageOptions: { + globals: { + ...globals.es2015, + }, + parserOptions: es6.parserOptions, + }, + rules: es6.rules, +}; diff --git a/packages/eslint-config-airbnb-base/rules/flat/imports.js b/packages/eslint-config-airbnb-base/rules/flat/imports.js new file mode 100644 index 0000000000..72fc502a6f --- /dev/null +++ b/packages/eslint-config-airbnb-base/rules/flat/imports.js @@ -0,0 +1,17 @@ +const importPlugin = require('eslint-plugin-import'); +const globals = require('globals'); +const imports = require('../imports'); + +module.exports = { + languageOptions: { + globals: { + ...globals.es2015, + }, + parserOptions: imports.parserOptions, + }, + plugins: { + import: importPlugin + }, + settings: imports.settings, + rules: imports.rules, +}; diff --git a/packages/eslint-config-airbnb-base/rules/flat/node.js b/packages/eslint-config-airbnb-base/rules/flat/node.js new file mode 100644 index 0000000000..4c63b14abc --- /dev/null +++ b/packages/eslint-config-airbnb-base/rules/flat/node.js @@ -0,0 +1,11 @@ +const globals = require('globals'); +const node = require('../node'); + +module.exports = { + languageOptions: { + globals: { + ...globals.es2015, + } + }, + rules: node.rules, +};