Edit prettier config (#10648)

This commit is contained in:
somebody1234 2024-07-24 18:47:05 +10:00
parent 46e8bab429
commit 4b96be8ef8
7 changed files with 34 additions and 104 deletions

View File

@ -5,12 +5,15 @@ overrides:
- "*.m[j|t]s" - "*.m[j|t]s"
- "*.c[j|t]s" - "*.c[j|t]s"
options: options:
printWidth: 100 plugins: ["prettier-plugin-organize-imports"]
tabWidth: 4
semi: false semi: false
tabWidth: 2
singleQuote: true singleQuote: true
trailingComma: "es5" printWidth: 100
trailingComma: "all"
arrowParens: "avoid" arrowParens: "avoid"
organizeImportsSkipDestructiveCodeActions: true
experimentalTernaries: true
- files: "*.md" - files: "*.md"
options: options:

View File

@ -1,63 +0,0 @@
/** @file Prettier configuration. */
// @ts-check
/** @type {import("@ianvs/prettier-plugin-sort-imports").PrettierConfig} */
module.exports = {
overrides: [
{
files: ['*.[j|t]s', '*.[j|t]sx', '*.m[j|t]s', '*.c[j|t]s'],
options: {
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
printWidth: 100,
tabWidth: 2,
semi: false,
singleQuote: true,
trailingComma: 'es5',
arrowParens: 'avoid',
plugins: ['@ianvs/prettier-plugin-sort-imports', 'prettier-plugin-tailwindcss'],
// This plugin's options
importOrder: [
'^react$',
'',
'<THIRD_PARTY_MODULES>',
'',
'^enso-',
'',
'^#[/]assets',
'',
'^#[/]App',
'^#[/]appUtils',
'^#[/]text',
'^#[/]reactQueryClient',
'',
'^#[/]configurations[/]',
'',
'^#[/]data[/]',
'',
'^#[/]hooks[/]',
'',
'^#[/]providers[/]',
'',
'^#[/]events[/]',
'',
'^#[/]pages[/]',
'',
'^#[/]layouts[/]',
'',
'^#[/]components[/]',
'',
'^#[/]modals[/]',
'',
'^#[/]services[/]',
'',
'^#[/]utilities[/]',
'',
'^#[/]authentication[/]',
'',
'^[.]',
],
importOrderParserPlugins: ['typescript', 'jsx', 'importAssertions'],
importOrderTypeScriptVersion: '5.0.0',
},
},
],
}

View File

@ -0,0 +1,11 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"plugins": ["prettier-plugin-organize-imports", "prettier-plugin-tailwindcss"],
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "all",
"organizeImportsSkipDestructiveCodeActions": true,
"experimentalTernaries": true
}

View File

@ -61,7 +61,6 @@
}, },
"devDependencies": { "devDependencies": {
"@fast-check/vitest": "^0.0.8", "@fast-check/vitest": "^0.0.8",
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
"@modyfi/vite-plugin-yaml": "^1.0.4", "@modyfi/vite-plugin-yaml": "^1.0.4",
"@playwright/test": "^1.40.0", "@playwright/test": "^1.40.0",
"@react-types/shared": "^3.22.1", "@react-types/shared": "^3.22.1",
@ -82,6 +81,7 @@
"fast-check": "^3.15.0", "fast-check": "^3.15.0",
"playwright": "^1.38.0", "playwright": "^1.38.0",
"postcss": "^8.4.29", "postcss": "^8.4.29",
"prettier-plugin-organize-imports": "^4.0.0",
"prettier-plugin-tailwindcss": "^0.5.11", "prettier-plugin-tailwindcss": "^0.5.11",
"react-toastify": "^9.1.3", "react-toastify": "^9.1.3",
"tailwindcss": "^3.4.1", "tailwindcss": "^3.4.1",

View File

@ -8,12 +8,12 @@ import * as url from 'node:url'
// This is specialcased in other files, but these modules shouldn't be used in other files anyway. // This is specialcased in other files, but these modules shouldn't be used in other files anyway.
/* eslint-disable no-restricted-syntax */ /* eslint-disable no-restricted-syntax */
import eslintJs from '@eslint/js' import eslintJs from '@eslint/js'
import globals from 'globals' import tsEslint from '@typescript-eslint/eslint-plugin'
import tsEslintParser from '@typescript-eslint/parser'
import jsdoc from 'eslint-plugin-jsdoc' import jsdoc from 'eslint-plugin-jsdoc'
import react from 'eslint-plugin-react' import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks' import reactHooks from 'eslint-plugin-react-hooks'
import tsEslint from '@typescript-eslint/eslint-plugin' import globals from 'globals'
import tsEslintParser from '@typescript-eslint/parser'
/* eslint-enable no-restricted-syntax */ /* eslint-enable no-restricted-syntax */
// ================= // =================
@ -32,7 +32,6 @@ const NAME = 'enso'
* `node:process` is here because `process.on` does not exist on the namespace import. */ * `node:process` is here because `process.on` does not exist on the namespace import. */
const DEFAULT_IMPORT_ONLY_MODULES = const DEFAULT_IMPORT_ONLY_MODULES =
'@vitejs\\u002Fplugin-react|node:process|chalk|string-length|yargs|yargs\\u002Fyargs|sharp|to-ico|connect|morgan|serve-static|tiny-invariant|clsx|create-servers|electron-is-dev|fast-glob|esbuild-plugin-.+|opener|tailwindcss.*|@modyfi\\u002Fvite-plugin-yaml|build-info|is-network-error|validator.+|.*[.]json$' '@vitejs\\u002Fplugin-react|node:process|chalk|string-length|yargs|yargs\\u002Fyargs|sharp|to-ico|connect|morgan|serve-static|tiny-invariant|clsx|create-servers|electron-is-dev|fast-glob|esbuild-plugin-.+|opener|tailwindcss.*|@modyfi\\u002Fvite-plugin-yaml|build-info|is-network-error|validator.+|.*[.]json$'
const OUR_MODULES = 'enso-.*'
const RELATIVE_MODULES = const RELATIVE_MODULES =
'bin\\u002Fproject-manager|bin\\u002Fserver|config\\u002Fparser|authentication|config|debug|detect|file-associations|index|ipc|log|naming|paths|preload|project-management|security|url-associations|content-config|desktop-environment|#\\u002F.*' 'bin\\u002Fproject-manager|bin\\u002Fserver|config\\u002Fparser|authentication|config|debug|detect|file-associations|index|ipc|log|naming|paths|preload|project-management|security|url-associations|content-config|desktop-environment|#\\u002F.*'
const ALLOWED_DEFAULT_IMPORT_MODULES = `${DEFAULT_IMPORT_ONLY_MODULES}|postcss|ajv\\u002Fdist\\u002F2020|${RELATIVE_MODULES}` const ALLOWED_DEFAULT_IMPORT_MODULES = `${DEFAULT_IMPORT_ONLY_MODULES}|postcss|ajv\\u002Fdist\\u002F2020|${RELATIVE_MODULES}`
@ -147,29 +146,6 @@ const RESTRICTED_SYNTAXES = [
selector: 'TSEnumDeclaration:not(:has(TSEnumMember))', selector: 'TSEnumDeclaration:not(:has(TSEnumMember))',
message: 'Enums must not be empty', message: 'Enums must not be empty',
}, },
{
selector:
'ImportDeclaration[source.value=/^(?!node:)/] ~ ImportDeclaration[source.value=/^node:/]',
message:
'Import node modules before npm modules, our modules, and relative imports, separated by a blank line',
},
{
selector: `ImportDeclaration[source.value=/^(?:${OUR_MODULES}|${RELATIVE_MODULES})$/] ~ ImportDeclaration[source.value=/^(?!(|${OUR_MODULES}|${RELATIVE_MODULES})$|\\.)/]`,
message:
'Import npm modules before our modules and relative imports, separated by a blank line',
},
{
selector: `ImportDeclaration[source.value=/^(?:${RELATIVE_MODULES})$/] ~ ImportDeclaration[source.value=/^(?:${OUR_MODULES})$/]`,
message: 'Import our modules before relative imports, separated by a blank line',
},
{
selector: `ImportDeclaration[source.value=/^\\./] ~ ImportDeclaration[source.value=/^[^.]/]`,
message: 'Import relative imports last',
},
{
selector: `ImportDeclaration[source.value=/^\\..+\\.(?:json|yml|yaml)$/] ~ ImportDeclaration[source.value=/^\\..+\\.(?!json|yml|yaml)[^.]+$/]`,
message: 'Import data files after other relative imports',
},
{ {
selector: selector:
'TSAsExpression:has(TSUnknownKeyword, TSNeverKeyword, TSAnyKeyword) > TSAsExpression', 'TSAsExpression:has(TSUnknownKeyword, TSNeverKeyword, TSAnyKeyword) > TSAsExpression',

View File

@ -4,7 +4,8 @@
"eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-hooks": "^4.6.2",
"globals": "^15.8.0", "globals": "^15.8.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^3.3.2" "prettier": "^3.3.2",
"prettier-plugin-organize-imports": "^4.0.0"
}, },
"dependencies": { "dependencies": {
"tslib": "^2.6.3", "tslib": "^2.6.3",

View File

@ -40,6 +40,9 @@ importers:
prettier: prettier:
specifier: ^3.3.2 specifier: ^3.3.2
version: 3.3.2 version: 3.3.2
prettier-plugin-organize-imports:
specifier: ^4.0.0
version: 4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3))
app/dashboard: app/dashboard:
dependencies: dependencies:
@ -140,9 +143,6 @@ importers:
'@fast-check/vitest': '@fast-check/vitest':
specifier: ^0.0.8 specifier: ^0.0.8
version: 0.0.8(vitest@1.6.0(@types/node@20.11.21)(jsdom@24.1.0)(lightningcss@1.25.1)) version: 0.0.8(vitest@1.6.0(@types/node@20.11.21)(jsdom@24.1.0)(lightningcss@1.25.1))
'@ianvs/prettier-plugin-sort-imports':
specifier: ^4.1.1
version: 4.3.0(@vue/compiler-sfc@3.4.31)(prettier@3.3.2)
'@modyfi/vite-plugin-yaml': '@modyfi/vite-plugin-yaml':
specifier: ^1.0.4 specifier: ^1.0.4
version: 1.1.0(rollup@4.18.1)(vite@5.3.3(@types/node@20.11.21)(lightningcss@1.25.1)) version: 1.1.0(rollup@4.18.1)(vite@5.3.3(@types/node@20.11.21)(lightningcss@1.25.1))
@ -203,9 +203,12 @@ importers:
postcss: postcss:
specifier: ^8.4.29 specifier: ^8.4.29
version: 8.4.39 version: 8.4.39
prettier-plugin-organize-imports:
specifier: ^4.0.0
version: 4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3))
prettier-plugin-tailwindcss: prettier-plugin-tailwindcss:
specifier: ^0.5.11 specifier: ^0.5.11
version: 0.5.14(@ianvs/prettier-plugin-sort-imports@4.3.0(@vue/compiler-sfc@3.4.31)(prettier@3.3.2))(prettier-plugin-organize-imports@4.0.0(prettier@3.3.2)(typescript@5.5.3))(prettier@3.3.2) version: 0.5.14(@ianvs/prettier-plugin-sort-imports@4.3.0(prettier@3.3.2))(prettier-plugin-organize-imports@4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3)))(prettier@3.3.2)
tailwindcss: tailwindcss:
specifier: ^3.4.1 specifier: ^3.4.1
version: 3.4.4 version: 3.4.4
@ -8416,7 +8419,7 @@ snapshots:
'@humanwhocodes/object-schema@2.0.3': {} '@humanwhocodes/object-schema@2.0.3': {}
'@ianvs/prettier-plugin-sort-imports@4.3.0(@vue/compiler-sfc@3.4.31)(prettier@3.3.2)': '@ianvs/prettier-plugin-sort-imports@4.3.0(prettier@3.3.2)':
dependencies: dependencies:
'@babel/core': 7.24.7 '@babel/core': 7.24.7
'@babel/generator': 7.24.7 '@babel/generator': 7.24.7
@ -8425,10 +8428,9 @@ snapshots:
'@babel/types': 7.24.7 '@babel/types': 7.24.7
prettier: 3.3.2 prettier: 3.3.2
semver: 7.6.2 semver: 7.6.2
optionalDependencies:
'@vue/compiler-sfc': 3.4.31
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
optional: true
'@internationalized/date@3.5.4': '@internationalized/date@3.5.4':
dependencies: dependencies:
@ -13727,11 +13729,11 @@ snapshots:
optionalDependencies: optionalDependencies:
vue-tsc: 2.0.24(typescript@5.5.3) vue-tsc: 2.0.24(typescript@5.5.3)
prettier-plugin-tailwindcss@0.5.14(@ianvs/prettier-plugin-sort-imports@4.3.0(@vue/compiler-sfc@3.4.31)(prettier@3.3.2))(prettier-plugin-organize-imports@4.0.0(prettier@3.3.2)(typescript@5.5.3))(prettier@3.3.2): prettier-plugin-tailwindcss@0.5.14(@ianvs/prettier-plugin-sort-imports@4.3.0(prettier@3.3.2))(prettier-plugin-organize-imports@4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3)))(prettier@3.3.2):
dependencies: dependencies:
prettier: 3.3.2 prettier: 3.3.2
optionalDependencies: optionalDependencies:
'@ianvs/prettier-plugin-sort-imports': 4.3.0(@vue/compiler-sfc@3.4.31)(prettier@3.3.2) '@ianvs/prettier-plugin-sort-imports': 4.3.0(prettier@3.3.2)
prettier-plugin-organize-imports: 4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3)) prettier-plugin-organize-imports: 4.0.0(prettier@3.3.2)(typescript@5.5.3)(vue-tsc@2.0.24(typescript@5.5.3))
prettier@3.3.2: {} prettier@3.3.2: {}