From b10736f6ff28fcca2aa244aa5db0b6fbbf6a9985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Mon, 14 Nov 2022 23:58:05 +0100 Subject: [PATCH] fix: don't add rules if they're not available --- .github/workflows/CI.yml | 8 +++++++- lib/configs/_base.js | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2537599..5ee1ade 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,7 +15,10 @@ on: jobs: lint: - name: ⬣ Lint + name: ⬣ Lint (ESLint@${{ matrix.eslint }}) + strategy: + matrix: + eslint: [6, 7] runs-on: ubuntu-latest steps: - name: 🛑 Cancel Previous Runs @@ -32,6 +35,9 @@ jobs: - name: 📥 Install dependencies run: npm install + - name: 📥 Install ESLint v${{ matrix.eslint }} + run: npm install --save-dev eslint@${{ matrix.eslint }} + - name: ▶️ Run lint script run: npm run lint diff --git a/lib/configs/_base.js b/lib/configs/_base.js index bd0ba06..0821c6d 100644 --- a/lib/configs/_base.js +++ b/lib/configs/_base.js @@ -4,6 +4,11 @@ */ "use strict" +const { ESLint } = require("eslint") + +const isESLint7 = ESLint.version.startsWith("7") + +/** @type {import('eslint').Linter.Config} */ module.exports = { root: true, plugins: ["@eslint-community/mysticatea"], @@ -27,7 +32,7 @@ module.exports = { "consistent-return": "error", curly: "error", "default-case": "error", - "default-case-last": "error", + ...(isESLint7 ? { "default-case-last": "error" } : {}), // TODO: enable once we drop ESLint v6 support "default-param-last": "error", "dot-notation": "error", eqeqeq: ["error", "always", { null: "ignore" }], @@ -93,7 +98,7 @@ module.exports = { "no-lone-blocks": "error", "no-lonely-if": "error", "no-loop-func": "error", - "no-loss-of-precision": "error", + ...(isESLint7 ? { "no-loss-of-precision": "error" } : {}), // TODO: enable once we drop ESLint v6 support "no-misleading-character-class": "error", "no-mixed-operators": [ "error", @@ -108,14 +113,14 @@ module.exports = { "no-new-object": "error", "no-new-require": "error", "no-new-wrappers": "error", - "no-nonoctal-decimal-escape": "error", + ...(isESLint7 ? { "no-nonoctal-decimal-escape": "error" } : {}), // TODO: enable once we drop ESLint v6 support "no-obj-calls": "error", "no-octal": "error", "no-octal-escape": "error", "no-param-reassign": ["error", { props: false }], "no-process-env": "error", "no-process-exit": "error", - "no-promise-executor-return": "error", + ...(isESLint7 ? { "no-promise-executor-return": "error" } : {}), // TODO: enable once we drop ESLint v6 support "no-prototype-builtins": "error", "no-redeclare": ["error", { builtinGlobals: true }], "no-regex-spaces": "error", @@ -146,10 +151,10 @@ module.exports = { "no-unmodified-loop-condition": "error", "no-unneeded-ternary": "error", "no-unreachable": "error", - "no-unreachable-loop": "error", + ...(isESLint7 ? { "no-unreachable-loop": "error" } : {}), // TODO: enable once we drop ESLint v6 support "no-unsafe-finally": "error", "no-unsafe-negation": ["error", { enforceForOrderingRelations: true }], - "no-unsafe-optional-chaining": "error", + ...(isESLint7 ? { "no-unsafe-optional-chaining": "error" } : {}), // TODO: enable once we drop ESLint v6 support "no-unused-expressions": "error", "no-unused-labels": "error", "no-unused-vars": [ @@ -163,7 +168,7 @@ module.exports = { }, ], "no-use-before-define": ["error", "nofunc"], - "no-useless-backreference": "error", + ...(isESLint7 ? { "no-useless-backreference": "error" } : {}), // TODO: enable once we drop ESLint v6 support "no-useless-call": "error", "no-useless-catch": "error", "no-useless-concat": "error",