Skip to content

Commit

Permalink
fix: json parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
yxw007 committed Oct 31, 2024
1 parent a842226 commit f9267b2
Show file tree
Hide file tree
Showing 7 changed files with 6,683 additions and 2,145 deletions.
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no-install commitlint --edit "$1"
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run lint
1 change: 1 addition & 0 deletions commitlint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { extends: ["@commitlint/config-conventional"] };
8 changes: 4 additions & 4 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const JSON5 = require('json5');

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
Expand All @@ -11,7 +12,7 @@ function getType(p) {
return type;
}

function isObjectOrArray(type) {
function isObjectOrArray(type) {
return type == "object" || type == "array";
}

Expand Down Expand Up @@ -92,9 +93,8 @@ function activate(context) {
let json = "";
try {
let text = activeText.replace(/[\r\n\t\s]/g, "");
text = text.replace(/(,)((\\r)|(\\n)|(\\t)|(\\b))*(})/g, "$7");
text = text.replace(/([\w0-9]+)(\s*:)/g, `"$1"$2`);
json = JSON.parse(text);
console.log(text);
json = JSON5.parse(text);
} catch (error) {
vscode.window.showErrorMessage("选中文本非JSON文本, 请重新选择");
return;
Expand Down
Loading

0 comments on commit f9267b2

Please sign in to comment.