From 332d1a89f6224937043751d0ad6c7a90174ff9a8 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 19 Mar 2024 09:52:58 -0400 Subject: [PATCH] Convert eslint to flat config --- .eslintrc.js | 24 ------------------------ .vscode/settings.json | 3 +++ eslint.config.mjs | 28 ++++++++++++++++++++++++++++ index.test.mjs | 2 +- package.json | 1 + pnpm-lock.yaml | 3 +++ 6 files changed, 36 insertions(+), 25 deletions(-) delete mode 100644 .eslintrc.js create mode 100644 .vscode/settings.json create mode 100644 eslint.config.mjs diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 1e4629f..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = { - parserOptions: { - ecmaVersion: 2022, - }, - env: { - node: true, - es6: true, - }, - plugins: ["no-only-tests"], - extends: ["eslint:recommended"], - overrides: [ - { - files: "*.mjs", - parserOptions: { - sourceType: "module", - }, - }, - // Prevent .only in tests - { - files: ["src/**/*.test.{ts,tsx}"], - rules: { "no-only-tests/no-only-tests": "error" }, - }, - ], -}; diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..eb8204b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "eslint.experimental.useFlatConfig": true +} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..79c79ba --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,28 @@ +import noOnlyPlugin from "eslint-plugin-no-only-tests"; +import eslint from "@eslint/js"; + +export default [ + eslint.configs.recommended, + { + rules: { + semi: "error", + "prefer-const": "error", + }, + }, + { + files: ["**/*.js"], + languageOptions: { + globals: { + require: "readonly", + module: "readonly", + }, + }, + }, + // Prevent .only in tests + { + plugins: { + "no-only-tests": noOnlyPlugin, + }, + rules: { "no-only-tests/no-only-tests": "error" }, + }, +]; diff --git a/index.test.mjs b/index.test.mjs index 679915b..437517e 100644 --- a/index.test.mjs +++ b/index.test.mjs @@ -12,7 +12,7 @@ function format(css) { } async function run(input, output, opts, postcssOpts = {}) { - let result = await postcss([plugin(opts)]).process(input, postcssOpts); + const result = await postcss([plugin(opts)]).process(input, postcssOpts); expect(format(result.css)).toEqual(format(output)); expect(result.warnings()).toHaveLength(0); } diff --git a/package.json b/package.json index f625264..a2c4a3f 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "postcss": "^8.3.0" }, "devDependencies": { + "@eslint/js": "^8.57.0", "c8": "^7.11.3", "clean-publish": "^3.4.2", "eslint": "^8.57.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fe497dc..69f1bd6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,6 +10,9 @@ dependencies: version: 4.2.1 devDependencies: + '@eslint/js': + specifier: ^8.57.0 + version: 8.57.0 c8: specifier: ^7.11.3 version: 7.14.0