-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tidbcloud/chore/extensions-linter
chore: add extension database-linter
- Loading branch information
Showing
12 changed files
with
1,810 additions
and
2,094 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "@tidbcloud/tisqleditor-extensions-database-linter", | ||
"version": "1.0.0", | ||
"description": "tisqleditor extensions", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/*.js", | ||
"dist/*.ts", | ||
"package.json", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"tsc:watch": "tsc --watch", | ||
"rollup:watch": "rollup -c --watch", | ||
"dev": "concurrently --kill-others \"pnpm tsc:watch\" \"pnpm rollup:watch\"", | ||
"build": "tsc && rollup -c" | ||
}, | ||
"keywords": [ | ||
"tidbcloud", | ||
"sql", | ||
"editor", | ||
"extensions", | ||
"database linter" | ||
], | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@codemirror/lint": "^6.8.0", | ||
"@codemirror/state": "^6.4.1", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"rollup": "^4.18.0", | ||
"tslib": "^2.6.3", | ||
"typescript": "^5.4.5" | ||
}, | ||
"peerDependencies": { | ||
"@codemirror/lint": "^6.8.0", | ||
"@codemirror/state": "^6.4.1", | ||
"@codemirror/view": "^6.26.3" | ||
}, | ||
"dependencies": { | ||
"@tidbcloud/tisqleditor-extensions-sql-parser": "workspace:^", | ||
"@tidbcloud/tisqleditor-extensions-grammer-linter": "workspace:^" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { linter, Diagnostic } from '@codemirror/lint' | ||
|
||
import { getSqlStatements } from '@tidbcloud/tisqleditor-extensions-sql-parser' | ||
import { | ||
hintEle, | ||
linterBaseTheme | ||
} from '@tidbcloud/tisqleditor-extensions-grammer-linter' | ||
|
||
export type DBLinterOptions = { | ||
level?: 'error' | 'warning' | ||
title?: string | ||
message?: string | ||
preCheck?: () => string | ||
} | ||
|
||
const databaseLinter = (config: DBLinterOptions) => | ||
linter((view) => { | ||
const diagnostics: Diagnostic[] = [] | ||
|
||
if (config.preCheck && config.preCheck()) { | ||
return diagnostics | ||
} | ||
|
||
getSqlStatements(view.state).forEach((statement) => { | ||
if (statement.database === '' && statement.type !== 'ddl') { | ||
diagnostics.push({ | ||
from: statement.from, | ||
to: statement.to, | ||
severity: config.level || 'warning', | ||
message: '', | ||
renderMessage: () => { | ||
return hintEle( | ||
config.title || '', | ||
config.message || | ||
'No database selected by using `USE {database}` statement, this statement may run failed.' | ||
) | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
return diagnostics | ||
}) | ||
|
||
export function dbLinter(config: DBLinterOptions) { | ||
return [databaseLinter(config), linterBaseTheme] | ||
} |
2 changes: 1 addition & 1 deletion
2
...es/extensions/grammer-check/tsconfig.json → .../extensions/database-linter/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typescript from '@rollup/plugin-typescript' | ||
|
||
export default { | ||
input: './src/index.ts', | ||
output: { | ||
dir: './dist', | ||
format: 'es' | ||
}, | ||
plugins: [typescript()] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist" | ||
}, | ||
"include": ["./src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.