diff --git a/.eslintignore b/.eslintignore new file mode 120000 index 0000000000..656b796249 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +.prettierignore \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index 23bfac2c82..36c5262375 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,33 +1,72 @@ module.exports = { - "env": { - "browser": true, - "es2021": true - }, - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:@typescript-eslint/recommended", - "prettier" - ], - "overrides": [], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "plugins": ["react", "@typescript-eslint"], - "rules": { - "member-access": 0, - "ordered-imports": 0, - "quotemark": 0, - "no-console": 0, - "semicolon": 0, - "jsx-no-lambda": 0, - "jsx-no-multiline-js": 0 - }, - "settings": { - "react": { - "version": "detect" - } - } -} + env: { + browser: true, + es2021: true, + node: true, + }, + extends: [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:@typescript-eslint/recommended", + "prettier", + ], + overrides: [], + parser: "@typescript-eslint/parser", + parserOptions: { + ecmaVersion: "latest", + sourceType: "module", + }, + plugins: ["react", "@typescript-eslint"], + rules: { + "member-access": 0, + "prefer-const": "warn", + "no-useless-escape": "warn", + "ordered-imports": 0, + "no-empty": "off", + quotemark: 0, + "no-fallthrough": "off", + "no-console": 0, + semicolon: 0, + + // unused vars + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": [ + "warn", + { + argsIgnorePattern: "^_", + varsIgnorePattern: "^_", + caughtErrorsIgnorePattern: "^_", + }, + ], + + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-inferrable-types": "off", + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-empty-interface": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/ban-types": [ + "error", + { + extendDefaults: true, + types: { + "{}": false, + }, + }, + ], + + // react, JSX related + "react/jsx-key": "off", + "react/no-find-dom-node": "off", + "no-case-declarations": "off", + "react/no-unescaped-entities": "off", + "react/no-direct-mutation-state": "off", + "react/display-name": "off", + "jsx-no-lambda": 0, + "jsx-no-multiline-js": 0, + }, + settings: { + react: { + version: "detect", + }, + }, +}; diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000000..07345cd23f --- /dev/null +++ b/.prettierignore @@ -0,0 +1,21 @@ +tools/ +electron/env.json +src/json/schema +licenses.json +**/*.min.js + +# generated by update.sh +*-arm64/ +windows/ + +# ignore everything in dist +/dist/* +# except... +!/dist/css +!/dist/js/export.js +!/dist/index.html +!/dist/index.web.html +!/dist/polyfill.js +!/dist/run.js +!/dist/workers/graph.js +!/dist/workers/lib/util.js diff --git a/.prettierrc.json b/.prettierrc.json index 3f148b08a2..fdb2e5d719 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,36 +1,58 @@ { - "parser": "typescript", - "trailingComma": "es5", - "tabWidth": 4, - "useTabs": true, - "semi": true, - "singleQuote": true, - "overrides": [ - { - "files": "*.json", - "options": { "parser": "json" } - }, - { - "files": "*.{ts,tsx}", - "options": { "parser": "typescript" } - }, - { - "files": "*.scss", - "options": { "parser": "scss" } - }, - { - "files": "*.md", - "options": { "parser": "markdown" } - }, - { - "files": "*.{svg,html}", - "options": { "parser": "html" } - }, - { - "files": ["*.code-workspace"], - "options": { - "parser": "json" - } - } - ] + "parser": "typescript", + "trailingComma": "es5", + "tabWidth": 4, + "useTabs": false, + "arrowParens": "avoid", + "semi": true, + "singleQuote": false, + + "plugins": ["@trivago/prettier-plugin-sort-imports"], + "importOrderSeparation": true, + "importOrderSortSpecifiers": true, + + "overrides": [ + { + "files": "*.{yml,yaml}", + "options": { + "semi": false, + "tabWidth": 2, + "parser": "yaml" + } + }, + { + "files": "*.md", + "options": { + "tabWidth": 2, + "parser": "markdown" + } + }, + { + "files": "*.json", + "options": { "parser": "json" } + }, + { + "files": "*.{ts,tsx}", + "options": { + "singleQuote": false, + "parser": "typescript" + } + }, + { + "files": "*.css", + "options": { "parser": "css" } + }, + { + "files": "*.scss", + "options": { "parser": "scss" } + }, + { + "files": "*.{svg,html}", + "options": { "parser": "html" } + }, + { + "files": ["*.code-workspace"], + "options": { "parser": "json" } + } + ] } diff --git a/electron/about/about.js b/electron/about/about.js index d89638195c..b2fcbb93da 100644 --- a/electron/about/about.js +++ b/electron/about/about.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line no-undef var param = getParam(); var year = document.getElementById('year'); var closeButton = document.getElementById('close'); diff --git a/electron/js/window.js b/electron/js/window.js index 8e268ead64..8b2916fb42 100644 --- a/electron/js/window.js +++ b/electron/js/window.js @@ -150,11 +150,13 @@ class WindowManager { win.webContents.on('will-navigate', (e, url) => { e.preventDefault(); + // eslint-disable-next-line no-undef shell.openExternal(url); }); win.webContents.on('new-window', (e, url) => { e.preventDefault(); + // eslint-disable-next-line no-undef shell.openExternal(url); }); diff --git a/js-anytype.code-workspace b/js-anytype.code-workspace index 4e21de7745..6dde4b266a 100644 --- a/js-anytype.code-workspace +++ b/js-anytype.code-workspace @@ -1,28 +1,21 @@ { - "folders": [ - { - "path": "." - } - ], - "extensions": { - "recommendations": [ - "esbenp.prettier-vscode", - "aaron-bond.better-comments", - "github.copilot", - "eamodio.gitlens", - "timonwong.shellcheck", - "dbaeumer.vscode-eslint" - ] - }, - "settings": { - "prettier.enable": true, - "editor.formatOnSave": false, - "editor.codeActionsOnSave": { - "source.fixAll": false, - "source.organizeImports": false - }, - "prettier.documentSelectors": ["**/*.svg"], - "editor.defaultFormatter": "esbenp.prettier-vscode", - "debug.inlineValues": "on" - } + "folders": [ + { + "path": "." + } + ], + "extensions": { + "recommendations": [ + "esbenp.prettier-vscode", + "aaron-bond.better-comments", + "github.copilot", + "eamodio.gitlens", + "timonwong.shellcheck", + "dbaeumer.vscode-eslint" + ] + }, + "settings": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "debug.inlineValues": "on" + } } diff --git a/package-lock.json b/package-lock.json index e220352677..f6aba05b44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,6 +61,7 @@ "sha1": "^1.1.1" }, "devDependencies": { + "@trivago/prettier-plugin-sort-imports": "^4.2.0", "@types/history": "^4.7.8", "@types/jquery": "^3.5.14", "@types/katex": "^0.14.0", @@ -114,30 +115,153 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.18.6", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.5.tgz", + "integrity": "sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ==", "dev": true, - "license": "MIT", "dependencies": { - "@babel/highlight": "^7.18.6" + "@babel/highlight": "^7.22.5" }, "engines": { "node": ">=6.9.0" } }, + "node_modules/@babel/generator": { + "version": "7.17.7", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.17.7.tgz", + "integrity": "sha512-oLcVCTeIFadUoArDTwpluncplrYBmTCCZZgXCbgNGvOBBiSDDK3eWO4b/+eOTli5tKv1lg+a5/NAXg+nTcei1w==", + "dev": true, + "dependencies": { + "@babel/types": "^7.17.0", + "jsesc": "^2.5.1", + "source-map": "^0.5.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/generator/node_modules/source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/@babel/helper-environment-visitor": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.5.tgz", + "integrity": "sha512-XGmhECfVA/5sAt+H+xpSg0mfrHq6FzNr9Oxh7PSEBBRUb/mL7Kz3NICXb194rCqAEdxkhPT1a88teizAFyvk8Q==", + "dev": true, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-function-name": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.22.5.tgz", + "integrity": "sha512-wtHSq6jMRE3uF2otvfuD3DIvVhOsSNshQl0Qrd7qC9oQJzHvOL4qQXlQn2916+CXGywIjpGuIkoyZRRxHPiNQQ==", + "dev": true, + "dependencies": { + "@babel/template": "^7.22.5", + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-function-name/node_modules/@babel/types": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.5.tgz", + "integrity": "sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==", + "dev": true, + "dependencies": { + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.5", + "to-fast-properties": "^2.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-hoist-variables": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", + "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", + "dev": true, + "dependencies": { + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-hoist-variables/node_modules/@babel/types": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.5.tgz", + "integrity": "sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==", + "dev": true, + "dependencies": { + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.5", + "to-fast-properties": "^2.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-split-export-declaration": { + "version": "7.22.6", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", + "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", + "dev": true, + "dependencies": { + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-split-export-declaration/node_modules/@babel/types": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.5.tgz", + "integrity": "sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==", + "dev": true, + "dependencies": { + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.5", + "to-fast-properties": "^2.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-string-parser": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", + "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", + "dev": true, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.18.6", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz", + "integrity": "sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==", "dev": true, - "license": "MIT", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { - "version": "7.18.6", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.5.tgz", + "integrity": "sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==", "dev": true, - "license": "MIT", "dependencies": { - "@babel/helper-validator-identifier": "^7.18.6", + "@babel/helper-validator-identifier": "^7.22.5", "chalk": "^2.0.0", "js-tokens": "^4.0.0" }, @@ -145,6 +269,18 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/parser": { + "version": "7.22.7", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.22.7.tgz", + "integrity": "sha512-7NF8pOkHP5o2vpmGgNGcfAeCvOYhGLyA3Z4eBQkT1RJlWu47n63bCs93QfJ2hIAFCil7L5P2IWhs1oToVgrL0Q==", + "dev": true, + "bin": { + "parser": "bin/babel-parser.js" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/@babel/runtime": { "version": "7.18.6", "license": "MIT", @@ -159,6 +295,68 @@ "version": "0.13.9", "license": "MIT" }, + "node_modules/@babel/template": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.5.tgz", + "integrity": "sha512-X7yV7eiwAxdj9k94NEylvbVHLiVG1nvzCV2EAowhxLTwODV1jl9UzZ48leOC0sH7OnuHrIkllaBgneUykIcZaw==", + "dev": true, + "dependencies": { + "@babel/code-frame": "^7.22.5", + "@babel/parser": "^7.22.5", + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/template/node_modules/@babel/types": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.5.tgz", + "integrity": "sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==", + "dev": true, + "dependencies": { + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.5", + "to-fast-properties": "^2.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/traverse": { + "version": "7.17.3", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.17.3.tgz", + "integrity": "sha512-5irClVky7TxRWIRtxlh2WPUUOLhcPN06AGgaQSB8AEwuyEBgJVuJ5imdHm5zxk8w0QS5T+tDfnDxAlhWjpb7cw==", + "dev": true, + "dependencies": { + "@babel/code-frame": "^7.16.7", + "@babel/generator": "^7.17.3", + "@babel/helper-environment-visitor": "^7.16.7", + "@babel/helper-function-name": "^7.16.7", + "@babel/helper-hoist-variables": "^7.16.7", + "@babel/helper-split-export-declaration": "^7.16.7", + "@babel/parser": "^7.17.3", + "@babel/types": "^7.17.0", + "debug": "^4.1.0", + "globals": "^11.1.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/types": { + "version": "7.17.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.17.0.tgz", + "integrity": "sha512-TmKSNO4D5rzhL5bjWFcVHHLETzfQ/AmbKpKPOSjlP0WoHZ6L911fgoOKY4Alp/emzG4cHJdyN49zpgkbXFEHHw==", + "dev": true, + "dependencies": { + "@babel/helper-validator-identifier": "^7.16.7", + "to-fast-properties": "^2.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@develar/schema-utils": { "version": "2.6.5", "resolved": "https://registry.npmjs.org/@develar/schema-utils/-/schema-utils-2.6.5.tgz", @@ -821,6 +1019,29 @@ "node": ">= 10" } }, + "node_modules/@trivago/prettier-plugin-sort-imports": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@trivago/prettier-plugin-sort-imports/-/prettier-plugin-sort-imports-4.2.0.tgz", + "integrity": "sha512-YBepjbt+ZNBVmN3ev1amQH3lWCmHyt5qTbLCp/syXJRu/Kw2koXh44qayB1gMRxcL/gV8egmjN5xWSrYyfUtyw==", + "dev": true, + "dependencies": { + "@babel/generator": "7.17.7", + "@babel/parser": "^7.20.5", + "@babel/traverse": "7.17.3", + "@babel/types": "7.17.0", + "javascript-natural-sort": "0.7.1", + "lodash": "^4.17.21" + }, + "peerDependencies": { + "@vue/compiler-sfc": "3.x", + "prettier": "2.x - 3.x" + }, + "peerDependenciesMeta": { + "@vue/compiler-sfc": { + "optional": true + } + } + }, "node_modules/@types/body-parser": { "version": "1.19.2", "dev": true, @@ -5770,6 +5991,15 @@ "node": ">=10" } }, + "node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/globalthis": { "version": "1.0.3", "license": "MIT", @@ -6750,6 +6980,12 @@ "node": ">=8" } }, + "node_modules/javascript-natural-sort": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/javascript-natural-sort/-/javascript-natural-sort-0.7.1.tgz", + "integrity": "sha512-nO6jcEfZWQXDhOiBtG2KvKyEptz7RVbpGP4vTD2hLBdmNQSsCiicO2Ioinv6UI4y9ukqnBpy+XZ9H6uLNgJTlw==", + "dev": true + }, "node_modules/jest-worker": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz", @@ -6815,6 +7051,18 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsesc": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", + "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "dev": true, + "bin": { + "jsesc": "bin/jsesc" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/json-buffer": { "version": "3.0.1", "license": "MIT" @@ -14276,6 +14524,15 @@ "node": ">=8.17.0" } }, + "node_modules/to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "dev": true, diff --git a/package.json b/package.json index 6f2642fd03..aaf721d464 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "main": "electron.js", "scripts": { "precommit": "npx lint-staged", + "lint": "eslint .", + "format": "prettier . --write", "electron": "npx electron .", "electron-win": "npx electron.cmd .", "start:watch": "cross-env-shell webpack-dev-server --progress --mode=development --node-env=development --env SERVER_PORT=$SERVER_PORT --env DATA_PATH=$DATA_PATH --history-api-fallback --cache", diff --git a/src/ts/component/widget/index.tsx b/src/ts/component/widget/index.tsx index 60cd1a6d43..389a6883c2 100644 --- a/src/ts/component/widget/index.tsx +++ b/src/ts/component/widget/index.tsx @@ -331,6 +331,7 @@ const WidgetIndex = observer(class WidgetIndex extends React.Component { getData (subId: string, callBack?: () => void) { const { block, isPreview } = this.props; const child = this.getTargetBlock(); + // eslint-disable-next-line no-unsafe-optional-chaining const { targetBlockId } = child?.content; const sorts = []; const filters: I.Filter[] = [