Add Prettier

This adds Prettier and makes it replace tsfmt. VSCode is set to use
Prettier for formatting TypeScript/TSX files and format on save since
Prettier is very fast and does not cause any noticeable delay.
This commit is contained in:
Koen Vlaswinkel
2022-10-25 17:10:19 +02:00
parent 6219b43051
commit f41ca1a330
10 changed files with 1639 additions and 1506 deletions

3
.gitattributes vendored
View File

@@ -23,3 +23,6 @@ CHANGELOG.md merge=union
# Mark some JSON files containing test data as generated so they are not included # Mark some JSON files containing test data as generated so they are not included
# as part of diffs or language statistics. # as part of diffs or language statistics.
extensions/ql-vscode/src/stories/remote-queries/data/*.json linguist-generated extensions/ql-vscode/src/stories/remote-queries/data/*.json linguist-generated
# Always use LF line endings, also on Windows
* text=auto eol=lf

View File

@@ -5,7 +5,7 @@
"recommendations": [ "recommendations": [
"amodio.tsl-problem-matcher", "amodio.tsl-problem-matcher",
"dbaeumer.vscode-eslint", "dbaeumer.vscode-eslint",
"eternalphane.tsfmt-vscode" "esbenp.prettier-vscode"
], ],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace. // List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [] "unwantedRecommendations": []

10
.vscode/settings.json vendored
View File

@@ -36,5 +36,13 @@
"typescript.preferences.quoteStyle": "single", "typescript.preferences.quoteStyle": "single",
"javascript.preferences.quoteStyle": "single", "javascript.preferences.quoteStyle": "single",
"editor.wordWrapColumn": 100, "editor.wordWrapColumn": 100,
"jest.rootPath": "./extensions/ql-vscode" "jest.rootPath": "./extensions/ql-vscode",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
},
} }

View File

@@ -10,7 +10,12 @@ module.exports = {
node: true, node: true,
es6: true, es6: true,
}, },
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:jest-dom/recommended"], extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest-dom/recommended",
"plugin:prettier/recommended"
],
rules: { rules: {
"@typescript-eslint/no-use-before-define": 0, "@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/no-unused-vars": [ "@typescript-eslint/no-unused-vars": [
@@ -27,11 +32,7 @@ module.exports = {
"@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-floating-promises": [ "error", { ignoreVoid: true } ], "@typescript-eslint/no-floating-promises": [ "error", { ignoreVoid: true } ],
"prefer-const": ["warn", { destructuring: "all" }], "prefer-const": ["warn", { destructuring: "all" }],
indent: "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/no-throw-literal": "error", "@typescript-eslint/no-throw-literal": "error",
"no-useless-escape": 0, "no-useless-escape": 0,
semi: 2,
quotes: ["warn", "single"]
}, },
}; };

View File

@@ -0,0 +1,6 @@
.vscode-test/
node_modules/
out/
# Include the Storybook config
!.storybook

View File

@@ -0,0 +1,3 @@
{
"trailingComma": "all"
}

View File

@@ -12,5 +12,5 @@ src/**
.gitignore .gitignore
gulpfile.js/** gulpfile.js/**
tsconfig.json tsconfig.json
tsfmt.json .prettierrc
vsc-extension-quickstart.md vsc-extension-quickstart.md

File diff suppressed because it is too large Load Diff

View File

@@ -1277,7 +1277,7 @@
"integration:minimal-workspace": "node ./out/vscode-tests/run-integration-tests.js minimal-workspace", "integration:minimal-workspace": "node ./out/vscode-tests/run-integration-tests.js minimal-workspace",
"cli-integration": "node ./out/vscode-tests/run-integration-tests.js cli-integration", "cli-integration": "node ./out/vscode-tests/run-integration-tests.js cli-integration",
"update-vscode": "node ./node_modules/vscode/bin/install", "update-vscode": "node ./node_modules/vscode/bin/install",
"format": "tsfmt -r && eslint . --ext .ts,.tsx --fix", "format": "prettier --write **/*.{ts,tsx} && eslint . --ext .ts,.tsx --fix",
"lint": "eslint . --ext .ts,.tsx --max-warnings=0", "lint": "eslint . --ext .ts,.tsx --max-warnings=0",
"format-staged": "lint-staged", "format-staged": "lint-staged",
"storybook": "start-storybook -p 6006", "storybook": "start-storybook -p 6006",
@@ -1380,8 +1380,8 @@
"@types/webpack": "^5.28.0", "@types/webpack": "^5.28.0",
"@types/webpack-env": "^1.18.0", "@types/webpack-env": "^1.18.0",
"@types/xml2js": "~0.4.4", "@types/xml2js": "~0.4.4",
"@typescript-eslint/eslint-plugin": "^4.26.0", "@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^4.26.0", "@typescript-eslint/parser": "^5.38.0",
"@vscode/test-electron": "^2.2.0", "@vscode/test-electron": "^2.2.0",
"ansi-colors": "^4.1.1", "ansi-colors": "^4.1.1",
"applicationinsights": "^2.3.5", "applicationinsights": "^2.3.5",
@@ -1390,9 +1390,11 @@
"chai-as-promised": "~7.1.1", "chai-as-promised": "~7.1.1",
"css-loader": "~3.1.0", "css-loader": "~3.1.0",
"del": "^6.0.0", "del": "^6.0.0",
"eslint": "~6.8.0", "eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest-dom": "^4.0.2", "eslint-plugin-jest-dom": "^4.0.2",
"eslint-plugin-react": "~7.19.0", "eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.8",
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-storybook": "^0.6.4", "eslint-plugin-storybook": "^0.6.4",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",
@@ -1409,7 +1411,7 @@
"mocha": "^10.0.0", "mocha": "^10.0.0",
"mocha-sinon": "~2.1.2", "mocha-sinon": "~2.1.2",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "~2.0.5", "prettier": "^2.7.1",
"proxyquire": "~2.1.3", "proxyquire": "~2.1.3",
"sinon": "~14.0.0", "sinon": "~14.0.0",
"sinon-chai": "~3.5.0", "sinon-chai": "~3.5.0",
@@ -1421,7 +1423,6 @@
"ts-node": "^10.7.0", "ts-node": "^10.7.0",
"ts-protoc-gen": "^0.9.0", "ts-protoc-gen": "^0.9.0",
"typescript": "^4.5.5", "typescript": "^4.5.5",
"typescript-formatter": "^7.2.2",
"vsce": "^2.7.0", "vsce": "^2.7.0",
"webpack": "^5.62.2", "webpack": "^5.62.2",
"webpack-cli": "^4.6.0" "webpack-cli": "^4.6.0"
@@ -1437,7 +1438,7 @@
"prettier --write" "prettier --write"
], ],
"./**/*.{ts,tsx}": [ "./**/*.{ts,tsx}": [
"tsfmt -r", "prettier --write",
"eslint --fix" "eslint --fix"
] ]
}, },

View File

@@ -1,20 +0,0 @@
{
"newLineCharacter": "\n",
"convertTabsToSpaces": true,
"indentStyle": 2,
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": true,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterConstructor": false,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
"insertSpaceAfterTypeAssertion": false,
"insertSpaceBeforeFunctionParenthesis": false,
"placeOpenBraceOnNewLineForFunctions": false,
"placeOpenBraceOnNewLineForControlBlocks": false
}