Skip to content

Commit

Permalink
chore: migrates to eslint 9 & flat config (#968)
Browse files Browse the repository at this point in the history
## Description

- bumps linting setup to eslint 9
- migrates (both) eslint configurations to 'flat config'
- The _complexity_ calculation changed, so I've set the max allowed
complexity a little bit higher (to 10; eslint's default is 20 (!) -
previously _we_ used 6).

Our eslint-config-moving-meadow configuration is still non-flat, so
@eslint/migrate-config wrapped it in a _compat_ call, which is fine for
now.

## Motivation and Context

eslint 8 is EOL and won't be supported any longer. An alternative till
eslint 10 is setting the [ESLINT_USE_FLAT_CONFIG environment variable to
false](https://eslint.org/docs/latest/use/migrate-to-9.0.0#flat-config),
but that still made eslint emit a warning message on each run + we had
to do the work anyway, eventually.

## How Has This Been Tested?

- [x] green ci

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [ ] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Chore

## Checklist

- [x] 📖

  - My change doesn't require a documentation update, or ...
  - it _does_ and I have updated it

- [x] ⚖️
- The contribution will be subject to [The MIT
license](https://github.com/sverweij/dependency-cruiser/blob/main/LICENSE),
and I'm OK with that.
  - The contribution is my own original work.
- I am ok with the stuff in
[**CONTRIBUTING.md**](https://github.com/sverweij/dependency-cruiser/blob/main/.github/CONTRIBUTING.md).
  • Loading branch information
sverweij authored Nov 24, 2024
1 parent aae6edd commit 8a288dd
Show file tree
Hide file tree
Showing 33 changed files with 869 additions and 1,212 deletions.
9 changes: 4 additions & 5 deletions .dependency-cruiser.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fileURLToPath } from "node:url";

const defaultStrictRules = fileURLToPath(
new URL("./configs/recommended-strict.cjs", import.meta.url),
new URL("configs/recommended-strict.cjs", import.meta.url),
);
/** @type {import('./').IConfiguration} */
export default {
Expand Down Expand Up @@ -203,7 +203,7 @@ export default {
comment:
"In production code do not depend on external ('npm') modules not declared in your package.json's dependencies - otherwise a production only install (i.e. 'npm ci') will break. If this rule triggers on something that's only used during development, adapt the 'from' of the rule in the dependency-cruiser configuration.",
from: {
pathNot: ["^test/", "^tools/"],
pathNot: ["^test/", "^tools/", "^types/eslint[.]config[.]mjs"],
},
to: {
dependencyTypes: ["npm-dev"],
Expand All @@ -214,7 +214,6 @@ export default {
"triple-slash-type-reference",
"npm",
],
pathNot: ["node_modules/@types/"],
},
},
{
Expand Down Expand Up @@ -246,12 +245,12 @@ export default {
to: { dependencyTypes: ["npm-peer"] },
},
{
name: "no-unvetted-license",
name: "no-non-vetted-license",
comment:
"This module uses an external dependency that has license that's not vetted. The license itself might be OK, but bigcorp legal departments might get jittery over anything other than MIT (or ISC).",
severity: "error",
from: {},
to: { licenseNot: "MIT|ISC|Apache-2[.]0" },
to: { licenseNot: "MIT|ISC|Apache-2[.]0|BSD-2-Clause" },
},
{
name: "not-unreachable-from-cli",
Expand Down
74 changes: 0 additions & 74 deletions .eslintrc.cjs

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: ${{matrix.node-version}}
- name: remove .npmrc on node 18 so that the npm install works
if: matrix.node-version == '18.x'
run: |
rm -f .npmrc
npm config set package-lock=true
npm config set save-exact=true
- name: install & build
run: |
sudo apt-get update
Expand Down
3 changes: 2 additions & 1 deletion configs/.dependency-cruiser-show-metrics-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export default {
theme: {
replace: false,
graph: {
splines: "ortho", // "ortho" looks nicer, but with the full graph takes long
// "ortho" looks nicer, but with the full graph takes long
splines: "ortho",
},
modules: [
{
Expand Down
107 changes: 107 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import globals from "globals";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
{
ignores: [
"**/.pnp.cjs",
"**/.yarn",
"**/node_modules",
"**/coverage",
"**/tmp",
"src/**/*.schema.mjs",
"src/report/dot-webpage/svg-in-html-snippets/script.cjs",
"test/integration/**/*",
"test/*/__fixtures__/**/*",
"test/*/*/__fixtures__/**/*",
"test/*/*/*/__fixtures__/**/*",
"test/*/__mocks__/**/*",
"test/*/*/__mocks__/**/*",
"types/**/*",
],
},
...compat.extends("moving-meadow", "plugin:@typescript-eslint/recommended"),
{
plugins: {
"@typescript-eslint": typescriptEslint,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2021,
sourceType: "script",
},

rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unused-vars": "off",
"no-unused-vars": "off",
"budapestian/global-constant-pattern": "off",
"security/detect-non-literal-fs-filename": "off",
"import/exports-last": "off",
"import/no-unresolved": "off",
"@typescript-eslint/no-require-imports": "off",
"no-param-reassign": "error",
"n/no-missing-import": "off",
"n/no-missing-require": "off",
"unicorn/no-empty-file": "off",
"unicorn/no-useless-fallback-in-spread": "off",
// eslint-disable-next-line no-magic-numbers
complexity: ["warn", { max: 10, variant: "classic" }],
},
},
{
files: ["**/*.d.ts"],

rules: {
"init-declarations": "off",
},
},
{
files: ["test/**/*.{js,mjs,cjs}"],

languageOptions: {
globals: {
...globals.mocha,
},
},

rules: {
complexity: "off",
"max-lines": "off",
"max-lines-per-function": "off",
"no-prototype-builtins": "off",

"mocha/valid-suite-description": [
"error",
{
pattern: "^\\[[EIU]\\]",
suiteNames: ["describe"],
message:
"start suite titles with [E], [I] or [U] to mark them as E2E, Integration or Unit test suite",
},
],
},
},
{
files: ["**/*.mjs"],

rules: {
"n/no-unsupported-features/es-syntax": "off",
},
},
];
Loading

0 comments on commit 8a288dd

Please sign in to comment.