[nit] Add consistent method chaining linter (#613)

Enforces that chained accessed should **either** all be on one line, or
all on individual lines (same as imports).
This commit is contained in:
filtered
2025-02-26 21:11:11 +11:00
committed by GitHub
parent 5cdd0581fa
commit 867b9ed316
5 changed files with 51 additions and 13 deletions

View File

@@ -1,10 +1,23 @@
import globals from "globals"
import eslint from "@eslint/js"
import tseslint from "typescript-eslint"
import stylistic from "@stylistic/eslint-plugin"
import eslintPluginAntfu from "eslint-plugin-antfu"
import jsdoc from "eslint-plugin-jsdoc"
import unusedImports from "eslint-plugin-unused-imports"
import eslintPluginSimpleImportSort from "eslint-plugin-simple-import-sort"
import unusedImports from "eslint-plugin-unused-imports"
import globals from "globals"
import tseslint from "typescript-eslint"
const rules = Object.fromEntries(
Object.entries(eslintPluginAntfu.rules)
.map(
([id]) => [`antfu/${id}`, "off"],
),
)
const antfuLint = {
name: "antfu/without-if-newline-or-imports",
plugins: { antfu: eslintPluginAntfu },
rules,
}
export default tseslint.config(
{ files: ["**/*.{js,mjs,ts,mts}"] },
@@ -133,7 +146,6 @@ export default tseslint.config(
],
"@stylistic/function-paren-newline": ["error", "multiline-arguments"],
"@stylistic/newline-per-chained-call": "error",
"@stylistic/array-bracket-spacing": "error",
"@stylistic/arrow-parens": "error",
@@ -209,6 +221,14 @@ export default tseslint.config(
},
},
// Antfu
antfuLint,
{
rules: {
"antfu/consistent-chaining": "error",
},
},
// Sort imports
{
plugins: {

14
package-lock.json generated
View File

@@ -14,6 +14,7 @@
"@types/eslint__js": "^8.42.3",
"@types/node": "^22.1.0",
"eslint": "^9.14.0",
"eslint-plugin-antfu": "^3.1.0",
"eslint-plugin-jsdoc": "^50.6.3",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unused-imports": "^4.1.4",
@@ -2816,6 +2817,19 @@
}
}
},
"node_modules/eslint-plugin-antfu": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-antfu/-/eslint-plugin-antfu-3.1.0.tgz",
"integrity": "sha512-BKlJcpIG8OGyU5JwQCdyTGaLuRgItheEYinhNroCx3bcuz2bCSYK0eNzJvPy2TY8yyz0uSSRxr5KHuQ1WOdOKg==",
"dev": true,
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/antfu"
},
"peerDependencies": {
"eslint": "*"
}
},
"node_modules/eslint-plugin-jsdoc": {
"version": "50.6.3",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.6.3.tgz",

View File

@@ -51,6 +51,7 @@
"@types/eslint__js": "^8.42.3",
"@types/node": "^22.1.0",
"eslint": "^9.14.0",
"eslint-plugin-antfu": "^3.1.0",
"eslint-plugin-jsdoc": "^50.6.3",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unused-imports": "^4.1.4",

View File

@@ -2138,8 +2138,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
// Empty string and * match anything (type: 0)
if (type == "" || type == "*") type = 0
const sourceTypes = String(type).toLowerCase()
.split(",")
const sourceTypes = String(type).toLowerCase().split(",")
// Run the search
let occupiedSlot: number | TSlot | null = null
@@ -2147,8 +2146,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
const slot: TSlot & IGenericLinkOrLinks = slots[i]
const destTypes = slot.type == "0" || slot.type == "*"
? ["0"]
: String(slot.type).toLowerCase()
.split(",")
: String(slot.type).toLowerCase().split(",")
for (const sourceType of sourceTypes) {
// TODO: Remove _event_ entirely.

View File

@@ -100,8 +100,10 @@ export class Reroute implements Positionable, LinkSegment, Serialisable<Serialis
const nextId = this.linkIds.values().next().value
return nextId === undefined
? undefined
: this.#network.deref()
?.links.get(nextId)
: this.#network
.deref()
?.links
.get(nextId)
?.origin_id
}
@@ -110,8 +112,10 @@ export class Reroute implements Positionable, LinkSegment, Serialisable<Serialis
const nextId = this.linkIds.values().next().value
return nextId === undefined
? undefined
: this.#network.deref()
?.links.get(nextId)
: this.#network
.deref()
?.links
.get(nextId)
?.origin_slot
}
@@ -209,7 +213,8 @@ export class Reroute implements Positionable, LinkSegment, Serialisable<Serialis
return this.#network
.deref()
?.reroutes.get(this.#parentId)
?.reroutes
.get(this.#parentId)
?.findNextReroute(withParentId, visited)
}