-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add import order sorting via prettier #1392
Merged
juliusmarminge
merged 26 commits into
t3-oss:finn/prettier
from
FinnDore:prettier-import-order
May 17, 2023
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b0f3b8b
added import order sorting
FinnDore d816992
cli format
FinnDore 1149c08
format www
FinnDore 882177e
.
FinnDore 760614a
done?
FinnDore d955bc2
lint
FinnDore 28ced02
we do a little reverse
FinnDore ff5643f
fixed format:check writing
FinnDore 75f09f9
smoll changes
FinnDore 8fbb67d
Merge commit '1e4c2d352e9b42e0f48c98980714c5334bfd06d7' into prettier…
FinnDore 68bd141
split out installers
FinnDore 4ee772f
removed eslint from base project
FinnDore 01de8cd
added eslint back
FinnDore aa79698
formatting
FinnDore c14ca2a
fixed linting
FinnDore 86d07ed
fixed base project
FinnDore d37d813
rip ci time
FinnDore f0b4089
Update cli/template/extras/config/_prettier.config.cjs
juliusmarminge a665f39
need to test this but.
FinnDore 976d21d
Merge branch 'prettier-import-order' of https://github.com/FinnDore/c…
FinnDore db03947
removed uneeded resolve
FinnDore 63fad92
docs update
FinnDore 02b64de
Moved over to a seperate prompt
FinnDore 7e77640
yuh
FinnDore f16ce44
spelling
FinnDore ab01b4d
this?
FinnDore File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
done?
- Loading branch information
commit 760614aa85d368dfb8c257ecfd597a708be05b47
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
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
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,74 +1,41 @@ | ||
import { type Installer } from "../installers/index.js"; | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { PKG_ROOT } from "~/consts"; | ||
import { type Installer } from "~/installers/index"; | ||
|
||
// import defaultESlintConfig from "~/tesmplate/base/_eslintrc.cjs"; | ||
// import { addPackageDependency } from "~/utils/addPackageDependency.js"; | ||
import { PKG_ROOT } from "~/consts.js"; | ||
import { addPackageDependency } from "~/utils/addPackageDependency.js"; | ||
|
||
export const strictEsLintAndPrettier: Installer = ({ | ||
projectDir, | ||
packages, | ||
}) => { | ||
const usingTailwind = packages?.prisma.inUse; | ||
console.log(defaultESlintConfig); | ||
addPackageDependency({ | ||
projectDir, | ||
dependencies: ["prettier", "@types/prettier"], | ||
dependencies: [ | ||
"prettier", | ||
"@types/prettier", | ||
"@ianvs/prettier-plugin-sort-imports", | ||
], | ||
devMode: true, | ||
}); | ||
|
||
const eslintExtra = path.join(PKG_ROOT, "template/extras/src/.eslintrc.js"); | ||
fs.copySync(eslintExtra, projectDir); | ||
}; | ||
const configDir = path.join(PKG_ROOT, "template/extras/config"); | ||
|
||
// const getEnvContent = (usingAuth: boolean, usingPrisma: boolean) => { | ||
// let content = ` | ||
// # When adding additional environment variables, the schema in "/src/env.mjs" | ||
// # should be updated accordingly. | ||
// ` | ||
// .trim() | ||
// .concat("\n"); | ||
// | ||
// if (usingPrisma) | ||
// content += ` | ||
// # Prisma | ||
// # https://www.prisma.io/docs/reference/database-reference/connection-urls#env | ||
// DATABASE_URL="file:./db.sqlite" | ||
// `; | ||
// | ||
// if (usingAuth) | ||
// content += ` | ||
// # Next Auth | ||
// # You can generate a new secret on the command line with: | ||
// # openssl rand -base64 32 | ||
// # https://next-auth.js.org/configuration/options#secret | ||
// # NEXTAUTH_SECRET="" | ||
// NEXTAUTH_URL="http:https://localhost:3000" | ||
// | ||
// # Next Auth Discord Provider | ||
// DISCORD_CLIENT_ID="" | ||
// DISCORD_CLIENT_SECRET="" | ||
// `; | ||
// | ||
// if (!usingAuth && !usingPrisma) | ||
// content += ` | ||
// # Example: | ||
// # SERVERVAR="foo" | ||
// # NEXT_PUBLIC_CLIENTVAR="bar" | ||
// `; | ||
// | ||
// return content; | ||
// }; | ||
// | ||
// const exampleEnvContent = ` | ||
// # Since the ".env" file is gitignored, you can use the ".env.example" file to | ||
// # build a new ".env" file when you clone the repo. Keep this file up-to-date | ||
// # when you add new variables to \`.env\`. | ||
// | ||
// # This file will be committed to version control, so make sure not to have any | ||
// # secrets in it. If you are cloning this repo, create a copy of this file named | ||
// # ".env" and populate it with your secrets. | ||
// ` | ||
// .trim() | ||
// | ||
fs.rmSync(path.join(projectDir, "_eslintrc.cjs")); | ||
fs.copySync( | ||
path.join(configDir, "_strict-eslintrc.cjs"), | ||
path.join(projectDir, "_eslintrc.cjs"), | ||
); | ||
|
||
if (packages?.tailwind.inUse) { | ||
// Include the congig with tailwind class ordering | ||
fs.copySync( | ||
path.join(configDir, "strict-prettier-with-tailwind.config.cjs"), | ||
path.join(projectDir, "prettier.config.cjs"), | ||
); | ||
} else { | ||
fs.copySync( | ||
path.join(configDir, "prettier.config.cjs"), | ||
path.join(projectDir, "prettier.config.cjs"), | ||
); | ||
} | ||
}; |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ import { PKG_ROOT } from "~/consts.js"; | |
import { type Installer } from "~/installers/index.js"; | ||
import { addPackageDependency } from "~/utils/addPackageDependency.js"; | ||
|
||
export const tailwindInstaller: Installer = ({ projectDir }) => { | ||
export const tailwindInstaller: Installer = ({ projectDir, packages }) => { | ||
addPackageDependency({ | ||
projectDir, | ||
dependencies: [ | ||
|
@@ -26,7 +26,10 @@ export const tailwindInstaller: Installer = ({ projectDir }) => { | |
const postcssCfgSrc = path.join(extrasDir, "config/postcss.config.cjs"); | ||
const postcssCfgDest = path.join(projectDir, "postcss.config.cjs"); | ||
|
||
const prettierSrc = path.join(extrasDir, "config/prettier.config.cjs"); | ||
const prettierSrc = path.join( | ||
extrasDir, | ||
"config/prettier-with-tailwind.config.cjs", | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can then remove prettier from here - keep all the prettier logic in the prettier-eslint installer. |
||
const prettierDest = path.join(projectDir, "prettier.config.cjs"); | ||
|
||
const cssSrc = path.join(extrasDir, "src/styles/globals.css"); | ||
|
@@ -35,7 +38,11 @@ export const tailwindInstaller: Installer = ({ projectDir }) => { | |
fs.copySync(twCfgSrc, twCfgDest); | ||
fs.copySync(postcssCfgSrc, postcssCfgDest); | ||
fs.copySync(cssSrc, cssDest); | ||
fs.copySync(prettierSrc, prettierDest); | ||
|
||
// Let strictEslintAndPrettier install the prettier config | ||
if (!packages?.strictEslintAndPrettier.inUse) { | ||
fs.copySync(prettierSrc, prettierDest); | ||
} | ||
|
||
// Remove vanilla css file | ||
const indexModuleCss = path.join(projectDir, "src/pages/index.module.css"); | ||
|
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,6 @@ | ||
/** @type {import("prettier").Config} */ | ||
const config = { | ||
plugins: [require.resolve("prettier-plugin-tailwindcss")], | ||
}; | ||
|
||
module.exports = config; |
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,9 +1,6 @@ | ||
/** @type {import("prettier").Config} */ | ||
const config = { | ||
plugins: [ | ||
require.resolve("prettier-plugin-tailwindcss"), | ||
require.resolve("@ianvs/prettier-plugin-sort-imports"), | ||
], | ||
plugins: [require.resolve("@ianvs/prettier-plugin-sort-import")], | ||
}; | ||
|
||
module.exports = config; |
9 changes: 9 additions & 0 deletions
9
cli/template/extras/config/strict-prettier-with-tailwind.config.cjs
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,9 @@ | ||
/** @type {import("prettier").Config} */ | ||
const config = { | ||
plugins: [ | ||
require.resolve("prettier-plugin-tailwindcss"), | ||
require.resolve("@ianvs/prettier-plugin-sort-import"), | ||
], | ||
}; | ||
|
||
module.exports = config; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo we should have all or nothing, so if the installer isn't selected, no linter will be setup?