✨ Added sql prettier plugin
This commit is contained in:
83
frontend/package-lock.json
generated
83
frontend/package-lock.json
generated
@@ -51,6 +51,7 @@
|
|||||||
"prettier": "^3.6.2",
|
"prettier": "^3.6.2",
|
||||||
"remarkable": "^2.0.1",
|
"remarkable": "^2.0.1",
|
||||||
"sass": "^1.92.1",
|
"sass": "^1.92.1",
|
||||||
|
"sql-formatter": "^15.6.9",
|
||||||
"vue": "^3.5.21",
|
"vue": "^3.5.21",
|
||||||
"vue-i18n": "^11.1.12",
|
"vue-i18n": "^11.1.12",
|
||||||
"vue-pick-colors": "^1.8.0",
|
"vue-pick-colors": "^1.8.0",
|
||||||
@@ -2700,7 +2701,6 @@
|
|||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmmirror.com/argparse/-/argparse-2.0.1.tgz",
|
"resolved": "https://registry.npmmirror.com/argparse/-/argparse-2.0.1.tgz",
|
||||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
||||||
"dev": true,
|
|
||||||
"license": "Python-2.0"
|
"license": "Python-2.0"
|
||||||
},
|
},
|
||||||
"node_modules/autolinker": {
|
"node_modules/autolinker": {
|
||||||
@@ -2933,6 +2933,12 @@
|
|||||||
"url": "https://jaywcjlove.github.io/#/sponsor"
|
"url": "https://jaywcjlove.github.io/#/sponsor"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/commander": {
|
||||||
|
"version": "2.20.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/commander/-/commander-2.20.3.tgz",
|
||||||
|
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/concat-map": {
|
"node_modules/concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmmirror.com/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmmirror.com/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
@@ -3076,6 +3082,12 @@
|
|||||||
"node": ">=0.10"
|
"node": ">=0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/discontinuous-range": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/discontinuous-range/-/discontinuous-range-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-c68LpLbO+7kP/b1Hr1qs8/BJ09F5khZGTxqxZuhzxpmwJKOgRFHJWIb9/KmqnqHhLdO55aOxFH/EGBvUQbL/RQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/dotenv": {
|
"node_modules/dotenv": {
|
||||||
"version": "16.5.0",
|
"version": "16.5.0",
|
||||||
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-16.5.0.tgz",
|
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-16.5.0.tgz",
|
||||||
@@ -3958,6 +3970,12 @@
|
|||||||
"pathe": "^2.0.1"
|
"pathe": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/moo": {
|
||||||
|
"version": "0.5.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/moo/-/moo-0.5.2.tgz",
|
||||||
|
"integrity": "sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==",
|
||||||
|
"license": "BSD-3-Clause"
|
||||||
|
},
|
||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
"version": "2.1.3",
|
"version": "2.1.3",
|
||||||
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz",
|
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz",
|
||||||
@@ -4007,6 +4025,28 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/nearley": {
|
||||||
|
"version": "2.20.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/nearley/-/nearley-2.20.1.tgz",
|
||||||
|
"integrity": "sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"commander": "^2.19.0",
|
||||||
|
"moo": "^0.5.0",
|
||||||
|
"railroad-diagrams": "^1.0.0",
|
||||||
|
"randexp": "0.4.6"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"nearley-railroad": "bin/nearley-railroad.js",
|
||||||
|
"nearley-test": "bin/nearley-test.js",
|
||||||
|
"nearley-unparse": "bin/nearley-unparse.js",
|
||||||
|
"nearleyc": "bin/nearleyc.js"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://nearley.js.org/#give-to-nearley"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/node-addon-api": {
|
"node_modules/node-addon-api": {
|
||||||
"version": "7.1.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmmirror.com/node-addon-api/-/node-addon-api-7.1.1.tgz",
|
"resolved": "https://registry.npmmirror.com/node-addon-api/-/node-addon-api-7.1.1.tgz",
|
||||||
@@ -4371,6 +4411,25 @@
|
|||||||
],
|
],
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/railroad-diagrams": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-cz93DjNeLY0idrCNOH6PviZGRN9GJhsdm9hpn1YCS879fj4W+x5IFJhhkRZcwVgMmFF7R82UA/7Oh+R8lLZg6A==",
|
||||||
|
"license": "CC0-1.0"
|
||||||
|
},
|
||||||
|
"node_modules/randexp": {
|
||||||
|
"version": "0.4.6",
|
||||||
|
"resolved": "https://registry.npmmirror.com/randexp/-/randexp-0.4.6.tgz",
|
||||||
|
"integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"discontinuous-range": "1.0.0",
|
||||||
|
"ret": "~0.1.10"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/rc9": {
|
"node_modules/rc9": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmmirror.com/rc9/-/rc9-2.1.2.tgz",
|
"resolved": "https://registry.npmmirror.com/rc9/-/rc9-2.1.2.tgz",
|
||||||
@@ -4431,6 +4490,15 @@
|
|||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/ret": {
|
||||||
|
"version": "0.1.15",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ret/-/ret-0.1.15.tgz",
|
||||||
|
"integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/reusify": {
|
"node_modules/reusify": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmmirror.com/reusify/-/reusify-1.1.0.tgz",
|
"resolved": "https://registry.npmmirror.com/reusify/-/reusify-1.1.0.tgz",
|
||||||
@@ -4600,6 +4668,19 @@
|
|||||||
"integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==",
|
"integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==",
|
||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause"
|
||||||
},
|
},
|
||||||
|
"node_modules/sql-formatter": {
|
||||||
|
"version": "15.6.9",
|
||||||
|
"resolved": "https://registry.npmmirror.com/sql-formatter/-/sql-formatter-15.6.9.tgz",
|
||||||
|
"integrity": "sha512-r9VKnkRfKW7jbhTgytwbM+JqmFclQYN9L58Z3UTktuy9V1f1Y+rGK3t70Truh2wIOJzvZkzobAQ2PwGjjXsr6Q==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"argparse": "^2.0.1",
|
||||||
|
"nearley": "^2.20.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"sql-formatter": "bin/sql-formatter-cli.cjs"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/std-env": {
|
"node_modules/std-env": {
|
||||||
"version": "3.9.0",
|
"version": "3.9.0",
|
||||||
"resolved": "https://registry.npmmirror.com/std-env/-/std-env-3.9.0.tgz",
|
"resolved": "https://registry.npmmirror.com/std-env/-/std-env-3.9.0.tgz",
|
||||||
|
|||||||
@@ -55,6 +55,7 @@
|
|||||||
"prettier": "^3.6.2",
|
"prettier": "^3.6.2",
|
||||||
"remarkable": "^2.0.1",
|
"remarkable": "^2.0.1",
|
||||||
"sass": "^1.92.1",
|
"sass": "^1.92.1",
|
||||||
|
"sql-formatter": "^15.6.9",
|
||||||
"vue": "^3.5.21",
|
"vue": "^3.5.21",
|
||||||
"vue-i18n": "^11.1.12",
|
"vue-i18n": "^11.1.12",
|
||||||
"vue-pick-colors": "^1.8.0",
|
"vue-pick-colors": "^1.8.0",
|
||||||
|
|||||||
1180
frontend/src/utils/prettier/plugins/sql/detect.mjs
Normal file
1180
frontend/src/utils/prettier/plugins/sql/detect.mjs
Normal file
File diff suppressed because it is too large
Load Diff
11
frontend/src/utils/prettier/plugins/sql/sql.d.ts
vendored
Normal file
11
frontend/src/utils/prettier/plugins/sql/sql.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Parser, Plugin } from "prettier";
|
||||||
|
|
||||||
|
export declare const languages: Plugin["languages"];
|
||||||
|
export declare const parsers: {
|
||||||
|
sql: Parser;
|
||||||
|
};
|
||||||
|
export declare const printers: Plugin["printers"];
|
||||||
|
export declare const options: Plugin["options"];
|
||||||
|
|
||||||
|
declare const plugin: Plugin;
|
||||||
|
export default plugin;
|
||||||
60
frontend/src/utils/prettier/plugins/sql/sql.mjs
Normal file
60
frontend/src/utils/prettier/plugins/sql/sql.mjs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { format } from 'sql-formatter';
|
||||||
|
import { detectDialect } from './detect.mjs';
|
||||||
|
|
||||||
|
// Languages
|
||||||
|
export const languages = [{
|
||||||
|
name: "SQL",
|
||||||
|
parsers: ["sql"],
|
||||||
|
extensions: [".sql"]
|
||||||
|
}];
|
||||||
|
|
||||||
|
// Parsers
|
||||||
|
export const parsers = {
|
||||||
|
sql: {
|
||||||
|
parse: (text) => text,
|
||||||
|
astFormat: "sql-format",
|
||||||
|
locStart: (node) => 0,
|
||||||
|
locEnd: (node) => node.length
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Printers
|
||||||
|
export const printers = {
|
||||||
|
"sql-format": {
|
||||||
|
print: (path) => {
|
||||||
|
const text = path.getValue();
|
||||||
|
|
||||||
|
if (!text || typeof text !== 'string') {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 自动检测SQL方言
|
||||||
|
const dialect = detectDialect(text);
|
||||||
|
|
||||||
|
// 格式化配置 - 使用固定的最佳实践配置
|
||||||
|
const formatOptions = {
|
||||||
|
language: dialect,
|
||||||
|
tabWidth: 2,
|
||||||
|
useTabs: true,
|
||||||
|
keywordCase: 'upper',
|
||||||
|
dataTypeCase: 'upper',
|
||||||
|
functionCase: 'upper',
|
||||||
|
identifierCase: 'preserve'
|
||||||
|
};
|
||||||
|
|
||||||
|
return format(text, formatOptions);
|
||||||
|
} catch (error) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Default export
|
||||||
|
export default {
|
||||||
|
languages,
|
||||||
|
parsers,
|
||||||
|
printers
|
||||||
|
};
|
||||||
@@ -37,6 +37,7 @@ import cssPrettierPlugin from "prettier/plugins/postcss"
|
|||||||
import markdownPrettierPlugin from "prettier/plugins/markdown"
|
import markdownPrettierPlugin from "prettier/plugins/markdown"
|
||||||
import yamlPrettierPlugin from "prettier/plugins/yaml"
|
import yamlPrettierPlugin from "prettier/plugins/yaml"
|
||||||
import goPrettierPlugin from "@/utils/prettier/plugins/go/go"
|
import goPrettierPlugin from "@/utils/prettier/plugins/go/go"
|
||||||
|
import sqlPrettierPlugin from "@/utils/prettier/plugins/sql/sql"
|
||||||
import * as prettierPluginEstree from "prettier/plugins/estree";
|
import * as prettierPluginEstree from "prettier/plugins/estree";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +51,8 @@ export class LanguageInfo {
|
|||||||
public prettier?: {
|
public prettier?: {
|
||||||
parser: string;
|
parser: string;
|
||||||
plugins: any[];
|
plugins: any[];
|
||||||
}) {}
|
}) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +69,10 @@ export const LANGUAGES: LanguageInfo[] = [
|
|||||||
parser: "html",
|
parser: "html",
|
||||||
plugins: [htmlPrettierPlugin]
|
plugins: [htmlPrettierPlugin]
|
||||||
}),
|
}),
|
||||||
new LanguageInfo("sql", "SQL", StandardSQL.language.parser),
|
new LanguageInfo("sql", "SQL", StandardSQL.language.parser, {
|
||||||
|
parser: "sql",
|
||||||
|
plugins: [sqlPrettierPlugin]
|
||||||
|
}),
|
||||||
new LanguageInfo("md", "Markdown", markdownLanguage.parser, {
|
new LanguageInfo("md", "Markdown", markdownLanguage.parser, {
|
||||||
parser: "markdown",
|
parser: "markdown",
|
||||||
plugins: [markdownPrettierPlugin]
|
plugins: [markdownPrettierPlugin]
|
||||||
|
|||||||
Reference in New Issue
Block a user