This commit is contained in:
lin onetwo 2025-12-02 13:37:02 +01:00 committed by GitHub
commit 92492b40c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 94 additions and 9 deletions

44
dprint.json Normal file
View file

@ -0,0 +1,44 @@
{
"$schema": "https://dprint.dev/schemas/v0.json",
"lineWidth": 120,
"indentWidth": 1,
"useTabs": true,
"typescript": {
"quoteStyle": "alwaysDouble",
"quoteProps": "asNeeded",
"useBraces": "always",
"singleBodyPosition": "sameLine",
"nextControlFlowPosition": "sameLine",
"arrowFunction.useParentheses": "preferNone",
"binaryExpression.operatorPosition": "sameLine",
"parameters.preferSingleLine": true,
"parameters.trailingCommas": "never",
"arguments.preferSingleLine": true,
"arguments.trailingCommas": "never",
"arrayExpression.preferSingleLine": true,
"arrayPattern.preferSingleLine": true,
"objectExpression.preferSingleLine": true,
"objectPattern.preferSingleLine": true,
"typeLiteral.preferSingleLine": true,
"tupleType.preferSingleLine": true,
"unionAndIntersectionType.preferSingleLine": false,
"variableStatement.preferSingleLine": false,
"ifStatement.spaceAfterIfKeyword": false,
"ifStatement.singleBodyPosition": "sameLine",
"ifStatement.nextControlFlowPosition": "sameLine",
"ifStatement.useBraces": "always",
"forStatement.spaceAfterForKeyword": false,
"forStatement.useBraces": "always",
"forInStatement.spaceAfterForKeyword": false,
"forInStatement.useBraces": "always",
"forOfStatement.spaceAfterForKeyword": false,
"forOfStatement.useBraces": "always",
"whileStatement.spaceAfterWhileKeyword": false,
"whileStatement.useBraces": "always"
},
"json": {},
"plugins": [
"https://plugins.dprint.dev/typescript-0.95.0.wasm",
"https://plugins.dprint.dev/json-0.19.4.wasm"
]
}

View file

@ -0,0 +1,8 @@
title: $:/changenotes/5.4.0/#9431
description: Add dprint formatter configuration via eslint-plugin-format
release: 5.4.0
tags: $:/tags/ChangeNote
change-type: enhancement
change-category: developer
github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/9431
github-contributors: linonetwo

View file

@ -5,6 +5,17 @@ import js from "@eslint/js";
import eslint from "eslint";
import stylistic from "@stylistic/eslint-plugin";
import esx from "eslint-plugin-es-x";
import format from "eslint-plugin-format";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Read dprint configuration
const dprintConfigPath = path.join(__dirname, "dprint.json");
const dprintConfig = JSON.parse(fs.readFileSync(dprintConfigPath, "utf-8"));
/** @type {import("eslint").Linter.Config} */
const es2017rules = {
@ -12,7 +23,8 @@ const es2017rules = {
plugins: esx.configs["flat/restrict-to-es2017"].plugins,
//@ts-ignore
rules: esx.configs["flat/restrict-to-es2017"].rules,
ignores: ["bin/**/*", "core-server/**/*"],
files: ["**/*.js", "**/*.mjs"],
ignores: ["bin/**/*", "core-server/**/*", "tiddlywiki.js"],
};
/** @type {import("eslint").Linter.Config} */
const es2023rules = {
@ -20,7 +32,7 @@ const es2023rules = {
plugins: esx.configs["flat/restrict-to-es2023"].plugins,
//@ts-ignore
rules: esx.configs["flat/restrict-to-es2023"].rules,
files: ["bin/**/*", "core-server/**/*"],
files: ["bin/**/*", "core-server/**/*", "tiddlywiki.js"],
};
@ -37,7 +49,8 @@ export default defineConfig([{
"plugins/tiddlywiki/*/files/",
"eslint.config.mjs",
"playwright.config.js",
"**/output/**"
"**/output/**",
"**/*.min.js"
],
},
@ -49,7 +62,8 @@ js.configs.recommended,
},
plugins: {
"@stylistic": stylistic
"@stylistic": stylistic,
"format": format
},
rules: {
@ -308,5 +322,21 @@ js.configs.recommended,
},
es2017rules,
es2023rules
es2023rules,
// DPrint formatting for JavaScript files
{
files: ["**/*.js", "**/*.mjs"],
plugins: { format },
rules: {
"format/dprint": ["warn", {
language: "typescript",
languageOptions: dprintConfig.typescript,
lineWidth: dprintConfig.lineWidth,
indentWidth: dprintConfig.indentWidth,
useTabs: dprintConfig.useTabs,
}],
// Disable conflicting stylistic rules
"@stylistic/keyword-spacing": "off",
}
}
]);

View file

@ -24,10 +24,13 @@
"wiki"
],
"devDependencies": {
"@eslint/js": "9.36.0",
"eslint": "9.36.0",
"eslint-plugin-es-x": "9.1.0",
"@stylistic/eslint-plugin": "5.4.0",
"@dprint/typescript": "0.93.4",
"@eslint/js": "9.39.1",
"@stylistic/eslint-plugin": "5.5.0",
"dprint": "0.50.2",
"eslint": "9.39.1",
"eslint-plugin-es-x": "9.1.2",
"eslint-plugin-format": "1.0.2",
"globals": "16.4.0"
},
"license": "BSD",